X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPreferences.java;h=67e0f831b676d133a07b9363cc6b0c2ccd629803;hb=43a0d0608b026a8a1dac00d9d8b28c0bf2153621;hp=ab4f94fc4254bfe13ba1250189a220019c2fbcba;hpb=4167762603a83df3e00713307e6522bb027bdd59;p=jalview.git diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index ab4f94f..67e0f83 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) - * Copyright (C) 2014 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -20,16 +20,6 @@ */ package jalview.gui; -import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; -import jalview.bin.Cache; -import jalview.gui.StructureViewer.Viewer; -import jalview.io.JalviewFileChooser; -import jalview.io.JalviewFileView; -import jalview.jbgui.GPreferences; -import jalview.jbgui.GSequenceLink; -import jalview.schemes.ColourSchemeProperty; -import jalview.util.MessageManager; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -39,15 +29,30 @@ import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.io.File; import java.util.Collection; +import java.util.List; import java.util.StringTokenizer; import java.util.Vector; +import javax.help.HelpSetException; import javax.swing.JColorChooser; import javax.swing.JFileChooser; import javax.swing.JInternalFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; +import ext.edu.ucsf.rbvi.strucviz2.StructureManager; + +import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; +import jalview.bin.Cache; +import jalview.gui.Help.HelpId; +import jalview.gui.StructureViewer.ViewerType; +import jalview.io.JalviewFileChooser; +import jalview.io.JalviewFileView; +import jalview.jbgui.GPreferences; +import jalview.jbgui.GSequenceLink; +import jalview.schemes.ColourSchemeProperty; +import jalview.util.MessageManager; + /** * DOCUMENT ME! * @@ -56,6 +61,15 @@ import javax.swing.JPanel; */ public class Preferences extends GPreferences { + public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME"; + + public static final String SCALE_PROTEIN_TO_CDNA = "SCALE_PROTEIN_TO_CDNA"; + + public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR"; + + public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT"; + + public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC"; public static final String ADD_TEMPFACT_ANN = "ADD_TEMPFACT_ANN"; @@ -160,11 +174,11 @@ public class Preferences extends GPreferences dasTab.add(dasSource, BorderLayout.CENTER); wsPrefs = new WsPreferences(); wsTab.add(wsPrefs, BorderLayout.CENTER); - int width = 500, height = 420; + int width = 500, height = 450; if (new jalview.util.Platform().isAMac()) { width = 570; - height = 460; + height = 480; } Desktop.addInternalFrame(frame, @@ -220,6 +234,8 @@ public class Preferences extends GPreferences + "")); smoothFont.setSelected(Cache.getDefault("ANTI_ALIAS", false)); + scaleProteinToCdna.setSelected(Cache.getDefault(SCALE_PROTEIN_TO_CDNA, + false)); idItalics.setSelected(Cache.getDefault("ID_ITALICS", true)); @@ -262,10 +278,14 @@ public class Preferences extends GPreferences */ for (int i = ColourSchemeProperty.FIRST_COLOUR; i <= ColourSchemeProperty.LAST_COLOUR; i++) { - colour.addItem(ColourSchemeProperty.getColourName(i)); + protColour.addItem(ColourSchemeProperty.getColourName(i)); + nucColour.addItem(ColourSchemeProperty.getColourName(i)); } - String string = Cache.getDefault("DEFAULT_COLOUR", "None"); - colour.setSelectedItem(string); + String oldProp = Cache.getDefault(DEFAULT_COLOUR, "None"); + String newProp = Cache.getDefault(DEFAULT_COLOUR_PROT, null); + protColour.setSelectedItem(newProp != null ? newProp : oldProp); + newProp = Cache.getDefault(DEFAULT_COLOUR_NUC, null); + nucColour.setSelectedItem(newProp != null ? newProp : oldProp); minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange)); maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", @@ -284,24 +304,14 @@ public class Preferences extends GPreferences addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false)); addTempFactor.setEnabled(structSelected); structViewer.setSelectedItem(Cache.getDefault(STRUCTURE_DISPLAY, - Viewer.JMOL.name())); + ViewerType.JMOL.name())); chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, "")); chimeraPath.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if (chimeraPath.getText().trim().length() > 0) - { - File f = new File(chimeraPath.getText()); - if (!f.canExecute()) - { - JOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString("label.invalid_path"), - MessageManager.getString("label.invalid_name"), - JOptionPane.ERROR_MESSAGE); - } - } + validateChimeraPath(); } }); @@ -376,6 +386,11 @@ public class Preferences extends GPreferences */ public void ok_actionPerformed(ActionEvent e) { + if (!validateSettings()) + { + return; + } + /* * Save Visual settings */ @@ -420,6 +435,8 @@ public class Preferences extends GPreferences Boolean.toString(showConsensLogo.isSelected())); Cache.applicationProperties.setProperty("ANTI_ALIAS", Boolean.toString(smoothFont.isSelected())); + Cache.applicationProperties.setProperty(SCALE_PROTEIN_TO_CDNA, + Boolean.toString(scaleProteinToCdna.isSelected())); Cache.applicationProperties.setProperty("SHOW_NPFEATS_TOOLTIP", Boolean.toString(showNpTooltip.isSelected())); Cache.applicationProperties.setProperty("SHOW_DBREFS_TOOLTIP", @@ -452,7 +469,9 @@ public class Preferences extends GPreferences /* * Save Colours settings */ - Cache.applicationProperties.setProperty("DEFAULT_COLOUR", colour + Cache.applicationProperties.setProperty(DEFAULT_COLOUR_PROT, protColour + .getSelectedItem().toString()); + Cache.applicationProperties.setProperty(DEFAULT_COLOUR_NUC, nucColour .getSelectedItem().toString()); Cache.setColourProperty("ANNOTATIONCOLOUR_MIN", minColour.getBackground()); @@ -590,9 +609,8 @@ public class Preferences extends GPreferences dasSource.saveProperties(Cache.applicationProperties); wsPrefs.updateAndRefreshWsMenuConfig(false); - Cache.saveProperties(); - + Desktop.instance.doConfigureStructurePrefs(); try { frame.setClosed(true); @@ -602,6 +620,28 @@ public class Preferences extends GPreferences } /** + * Do any necessary validation before saving settings. Return focus to the + * first tab which fails validation. + * + * @return + */ + private boolean validateSettings() + { + if (!validateStructure()) + { + structureTab.requestFocusInWindow(); + return false; + } + return true; + } + + @Override + protected boolean validateStructure() + { + return validateChimeraPath(); + + } + /** * DOCUMENT ME! */ public void startupFileTextfield_mouseClicked() @@ -843,4 +883,74 @@ public class Preferences extends GPreferences userIdWidthlabel.setEnabled(!autoIdWidth.isSelected()); } + /** + * Returns true if chimera path is to a valid executable, else show an error + * dialog. + */ + private boolean validateChimeraPath() + { + if (chimeraPath.getText().trim().length() > 0) + { + File f = new File(chimeraPath.getText()); + if (!f.canExecute()) + { + JOptionPane.showInternalMessageDialog(Desktop.desktop, + MessageManager.getString("label.invalid_chimera_path"), + MessageManager.getString("label.invalid_name"), + JOptionPane.ERROR_MESSAGE); + return false; + } + } + return true; + } + + /** + * If Chimera is selected, check it can be found on default or user-specified + * path, if not show a warning/help dialog. + */ + @Override + protected void structureViewer_actionPerformed(String selectedItem) + { + if (!selectedItem.equals(ViewerType.CHIMERA.name())) + { + return; + } + boolean found = false; + + /* + * Try user-specified and standard paths for Chimera executable. + */ + List paths = StructureManager.getChimeraPaths(); + paths.add(0, chimeraPath.getText()); + for (String path : paths) + { + if (new File(path.trim()).canExecute()) + { + found = true; + break; + } + } + if (!found) + { + String[] options = + { "OK", "Help" }; + int showHelp = JOptionPane.showInternalOptionDialog( + Desktop.desktop, + JvSwingUtils.wrapTooltip(true, + MessageManager.getString("label.chimera_missing")), + "", JOptionPane.YES_NO_OPTION, + JOptionPane.WARNING_MESSAGE, null, options, options[0]); + if (showHelp == JOptionPane.NO_OPTION) + { + try + { + Help.showHelpWindow(HelpId.StructureViewer); + } catch (HelpSetException e) + { + e.printStackTrace(); + } + } + } + } + }