X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FPreferences.java;h=19d929e5af8151d737631766625376a732883b5e;hb=747167089ecf8d6afc70d417f5a20352e029bd95;hp=23540725d1ba258fbe212b533ad086c78dcd1657;hpb=8d25e88f6a9d1bea9569c23e425df7b1b498fd14;p=jalview.git diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 2354072..19d929e 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -27,16 +27,20 @@ import java.awt.Dimension; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; import java.awt.event.MouseEvent; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CompletableFuture; import javax.help.HelpSetException; import javax.swing.JComboBox; import javax.swing.JFileChooser; import javax.swing.JInternalFrame; import javax.swing.JPanel; +import javax.swing.JTextField; import javax.swing.ListSelectionModel; import javax.swing.RowFilter; import javax.swing.RowSorter; @@ -50,9 +54,16 @@ import javax.swing.table.TableColumn; import javax.swing.table.TableModel; import javax.swing.table.TableRowSorter; +import jalview.hmmer.HmmerCommand; +import jalview.util.FileUtils; import ext.edu.ucsf.rbvi.strucviz2.StructureManager; import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder; +import jalview.bin.ApplicationSingletonProvider; +import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; import jalview.bin.Cache; +import jalview.bin.Console; +import jalview.bin.MemorySetting; +import jalview.ext.pymol.PymolManager; import jalview.gui.Help.HelpId; import jalview.gui.StructureViewer.ViewerType; import jalview.io.BackupFiles; @@ -80,8 +91,16 @@ import jalview.ws.sifts.SiftsSettings; * @author $author$ * @version $Revision$ */ -public class Preferences extends GPreferences +public class Preferences extends GPreferences implements ApplicationSingletonI { + // suggested list delimiter character + public static final String COMMA = ","; + + public static final String HMMSEARCH_SEQCOUNT = "HMMSEARCH_SEQCOUNT"; + + public static final String HMMINFO_GLOBAL_BACKGROUND = "HMMINFO_GLOBAL_BACKGROUND"; + + public static final String HMMALIGN_TRIM_TERMINI = "HMMALIGN_TRIM_TERMINI"; public static final String ADD_SS_ANN = "ADD_SS_ANN"; @@ -105,12 +124,13 @@ public class Preferences extends GPreferences public static final String CHIMERA_PATH = "CHIMERA_PATH"; + public static final String CHIMERAX_PATH = "CHIMERAX_PATH"; + public static final String DBREFFETCH_USEPICR = "DBREFFETCH_USEPICR"; public static final String DEFAULT_COLOUR = "DEFAULT_COLOUR"; public static final String DEFAULT_COLOUR_NUC = "DEFAULT_COLOUR_NUC"; - public static final String DEFAULT_COLOUR_PROT = "DEFAULT_COLOUR_PROT"; public static final String ENABLE_SPLIT_FRAME = "ENABLE_SPLIT_FRAME"; @@ -126,6 +146,12 @@ public class Preferences extends GPreferences public static final String FONT_SIZE = "FONT_SIZE"; public static final String FONT_STYLE = "FONT_STYLE"; + + public static final String HMMER_PATH = "HMMER_PATH"; + + public static final String CYGWIN_PATH = "CYGWIN_PATH"; + + public static final String HMMSEARCH_DBS = "HMMSEARCH_DBS"; public static final String GAP_COLOUR = "GAP_COLOUR"; @@ -150,6 +176,7 @@ public class Preferences extends GPreferences public static final String PAD_GAPS = "PAD_GAPS"; public static final String PDB_DOWNLOAD_FORMAT = "PDB_DOWNLOAD_FORMAT"; + public static final String PYMOL_PATH = "PYMOL_PATH"; public static final String QUESTIONNAIRE = "QUESTIONNAIRE"; @@ -180,7 +207,6 @@ public class Preferences extends GPreferences public static final String SHOW_JVSUFFIX = "SHOW_JVSUFFIX"; public static final String SHOW_NPFEATS_TOOLTIP = "SHOW_NPFEATS_TOOLTIP"; - public static final String SHOW_OCCUPANCY = "SHOW_OCCUPANCY"; public static final String SHOW_OV_HIDDEN_AT_START = "SHOW_OV_HIDDEN_AT_START"; @@ -206,7 +232,6 @@ public class Preferences extends GPreferences public static final String UNIPROT_DOMAIN = "UNIPROT_DOMAIN"; public static final String USE_FULL_SO = "USE_FULL_SO"; - public static final String USE_LEGACY_GAP = "USE_LEGACY_GAP"; public static final String USE_RNAVIEW = "USE_RNAVIEW"; @@ -215,11 +240,14 @@ public class Preferences extends GPreferences public static final String WRAP_ALIGNMENT = "WRAP_ALIGNMENT"; - private static final int MIN_FONT_SIZE = 1; private static final int MAX_FONT_SIZE = 30; + private String previousProxyType; + + private static Preferences INSTANCE = null; // add "final" + /** * Holds name and link separated with | character. Sequence ID must be * $SEQUENCE_ID$ or $SEQUENCE_ID=/.possible | chars ./=$ @@ -230,10 +258,10 @@ public class Preferences extends GPreferences /** * Holds name and link separated with | character. Sequence IDS and Sequences - * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and - * $SEQUENCES$ or $SEQUENCES=/.possible | chars ./=$ and separation character - * for first and second token specified after a pipe character at end |,|. - * (TODO: proper escape for using | to separate ids or sequences + * must be $SEQUENCEIDS$ or $SEQUENCEIDS=/.possible | chars ./=$ and $SEQUENCES$ + * or $SEQUENCES=/.possible | chars ./=$ and separation character for first and + * second token specified after a pipe character at end |,|. (TODO: proper + * escape for using | to separate ids or sequences */ public static List groupURLLinks; @@ -269,6 +297,7 @@ public class Preferences extends GPreferences private WsPreferences wsPrefs; + private SlivkaPreferences slivkaPrefs; private OptionsParam promptEachTimeOpt = new OptionsParam( MessageManager.getString("label.prompt_each_time"), "Prompt each time"); @@ -279,10 +308,56 @@ public class Preferences extends GPreferences private OptionsParam textOpt = new OptionsParam( MessageManager.getString("action.text"), "Text"); + // get singleton Preferences instance + public static Preferences getInstance() + { + if (INSTANCE == null || INSTANCE.frame == null + || INSTANCE.frame.isClosed()) + { + INSTANCE = new Preferences(); + } + return INSTANCE; + + /* + * Replace code with the following for Jalvew-JS + Preferences INSTANCE = ApplicationSingletonProvider.getInstance(Preferences.class); + if (INSTANCE == null || INSTANCE.frame == null + || INSTANCE.frame.isClosed()) + { + ApplicationSingletonProvider.remove(Preferences.class); + INSTANCE = ApplicationSingletonProvider.getInstance(Preferences.class); + } + return INSTANCE; + */ + } + + public static void openPreferences() + { + openPreferences(null, null); + } + + public static void openPreferences(TabRef selectTab, String message) + { + Preferences p = getInstance(); + if (selectTab != null) + p.selectTab(selectTab, message); + p.frame.show(); + p.frame.moveToFront(); + p.frame.grabFocus(); + } + + public void selectTab(TabRef selectTab, String message) + { + this.selectTab(selectTab); + if (message != null) + this.setMessage(message); + this.frame.show(); + } + /** * Creates a new Preferences object. */ - public Preferences() + private Preferences() { super(); frame = new JInternalFrame(); @@ -297,6 +372,10 @@ public class Preferences extends GPreferences wsPrefs = new WsPreferences(); wsTab.add(wsPrefs, BorderLayout.CENTER); } + + slivkaPrefs = new SlivkaPreferences(); + slivkaTab.add(slivkaPrefs, BorderLayout.CENTER); + int width = 500, height = 450; if (Platform.isAMacAndNotJS()) { @@ -309,6 +388,63 @@ public class Preferences extends GPreferences frame.setMinimumSize(new Dimension(width, height)); /* + * Set HMMER tab defaults + */ + hmmrTrimTermini.setSelected(Cache.getDefault(HMMALIGN_TRIM_TERMINI, false)); + if (Cache.getDefault(HMMINFO_GLOBAL_BACKGROUND, false)) + { + hmmerBackgroundUniprot.setSelected(true); + } + else + { + hmmerBackgroundAlignment.setSelected(true); + } + hmmerSequenceCount + .setText(Cache.getProperty(HMMSEARCH_SEQCOUNT)); + hmmerPath.setText(Cache.getProperty(HMMER_PATH)); + hmmerPath.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + validateHmmerPath(); + } + }); + hmmerPath.addFocusListener(new FocusAdapter() + { + @Override + public void focusLost(FocusEvent e) + { + validateHmmerPath(); + } + }); + if (cygwinPath != null) + { + String path = Cache.getProperty(CYGWIN_PATH); + if (path == null) + { + path = FileUtils.getPathTo("bash"); + } + cygwinPath.setText(path); + cygwinPath.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + validateCygwinPath(); + } + }); + cygwinPath.addFocusListener(new FocusAdapter() + { + @Override + public void focusLost(FocusEvent e) + { + validateCygwinPath(); + } + }); + } + + /* * Set Visual tab defaults */ seqLimit.setSelected(Cache.getDefault("SHOW_JVSUFFIX", true)); @@ -331,6 +467,9 @@ public class Preferences extends GPreferences Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM", true)); showConsensLogo .setSelected(Cache.getDefault("SHOW_CONSENSUS_LOGO", false)); + showInformationHistogram.setSelected( + Cache.getDefault("SHOW_INFORMATION_HISTOGRAM", true)); + showHMMLogo.setSelected(Cache.getDefault("SHOW_HMM_LOGO", false)); showNpTooltip .setSelected(Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true)); showDbRefTooltip @@ -393,8 +532,8 @@ public class Preferences extends GPreferences startupCheckbox .setSelected(Cache.getDefault("SHOW_STARTUP_FILE", true)); startupFileTextfield.setText(Cache.getDefault("STARTUP_FILE", - Cache.getDefault("www.jalview.org", "http://www.jalview.org") - + "/examples/exampleFile_2_3.jar")); + Cache.getDefault("www.jalview.org", "https://www.jalview.org") + + "/examples/exampleFile_2_7.jvp")); /* * Set Colours tab defaults @@ -421,12 +560,10 @@ public class Preferences extends GPreferences /* * Set overview panel defaults */ - gapColour.setBackground( - Cache.getDefaultColour(GAP_COLOUR, - jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP)); - hiddenColour.setBackground( - Cache.getDefaultColour(HIDDEN_COLOUR, - jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN)); + gapColour.setBackground(Cache.getDefaultColour(GAP_COLOUR, + jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_GAP)); + hiddenColour.setBackground(Cache.getDefaultColour(HIDDEN_COLOUR, + jalview.renderer.OverviewResColourFinder.OVERVIEW_DEFAULT_HIDDEN)); useLegacyGap.setSelected(Cache.getDefault(USE_LEGACY_GAP, false)); gapLabel.setEnabled(!useLegacyGap.isSelected()); gapColour.setEnabled(!useLegacyGap.isSelected()); @@ -434,28 +571,84 @@ public class Preferences extends GPreferences .setSelected(Cache.getDefault(SHOW_OV_HIDDEN_AT_START, false)); /* - * Set Structure tab defaults. + * Set Structure tab defaults */ - final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, false); + final boolean structSelected = Cache.getDefault(STRUCT_FROM_PDB, true); structFromPdb.setSelected(structSelected); - useRnaView.setSelected(Cache.getDefault(USE_RNAVIEW, false)); - useRnaView.setEnabled(structSelected); - addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, false)); + addSecondaryStructure.setSelected(Cache.getDefault(ADD_SS_ANN, true)); addSecondaryStructure.setEnabled(structSelected); - addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, false)); + addTempFactor.setSelected(Cache.getDefault(ADD_TEMPFACT_ANN, true)); addTempFactor.setEnabled(structSelected); + + /* + * set choice of structure viewer, and path if saved as a preference; + * default to Jmol (first choice) if an unexpected value is found + */ + String viewerType = ViewerType.JMOL.name(); if (!Platform.isJS()) { - structViewer.setSelectedItem( - Cache.getDefault(STRUCTURE_DISPLAY, ViewerType.JMOL.name())); + Cache.getDefault(STRUCTURE_DISPLAY, + ViewerType.JMOL.name()); } - chimeraPath.setText(Cache.getDefault(CHIMERA_PATH, "")); - chimeraPath.addActionListener(new ActionListener() + // TODO - disable external viewers for JS + structViewer.setSelectedItem(viewerType); + String viewerPath = ""; + ViewerType type = null; + try + { + type = ViewerType.valueOf(viewerType); + switch (type) + { + case JMOL: + break; + case CHIMERA: + viewerPath = Cache.getDefault(CHIMERA_PATH, ""); + break; + case CHIMERAX: + viewerPath = Cache.getDefault(CHIMERAX_PATH, ""); + break; + case PYMOL: + viewerPath = Cache.getDefault(PYMOL_PATH, ""); + break; + } + } catch (IllegalArgumentException e) + { + Console.error("Unknown structure viewer type: " + viewerType + + ", defaulting to Jmol"); + type = ViewerType.JMOL; + } + structureViewerPath.setText(viewerPath); + + structureViewerPath.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - validateChimeraPath(); + if (validateViewerPath()) + { + String path = structureViewerPath.getText(); + try + { + ViewerType type = ViewerType.valueOf(viewerType); + switch (type) + { + case JMOL: + break; + case CHIMERA: + Cache.setProperty(CHIMERA_PATH, path); + break; + case CHIMERAX: + Cache.setProperty(CHIMERAX_PATH, path); + break; + case PYMOL: + Cache.setProperty(PYMOL_PATH, path); + break; + } + } catch (IllegalArgumentException x) + { + Console.error("Failed to set path - unknown viewer type", x); + } + } } }); @@ -595,10 +788,36 @@ public class Preferences extends GPreferences } } - useProxy.setSelected(Cache.getDefault("USE_PROXY", false)); - useProxy_actionPerformed(); // make sure useProxy is correctly initialised - proxyServerTB.setText(Cache.getDefault("PROXY_SERVER", "")); - proxyPortTB.setText(Cache.getDefault("PROXY_PORT", "")); + String proxyTypeString = Cache.getDefault("USE_PROXY", "false"); + previousProxyType = proxyTypeString; + switch (proxyTypeString) + { + case Cache.PROXYTYPE_NONE: + proxyType.setSelected(noProxy.getModel(), true); + break; + case Cache.PROXYTYPE_SYSTEM: + proxyType.setSelected(systemProxy.getModel(), true); + break; + case Cache.PROXYTYPE_CUSTOM: + proxyType.setSelected(customProxy.getModel(), true); + break; + default: + Console.warn( + "Incorrect PROXY_TYPE - should be 'none' (clear proxy properties), 'false' (system settings), 'true' (custom settings): " + + proxyTypeString); + } + proxyServerHttpTB.setText(Cache.getDefault("PROXY_SERVER", "")); + proxyPortHttpTB.setText(Cache.getDefault("PROXY_PORT", "")); + proxyServerHttpsTB.setText(Cache.getDefault("PROXY_SERVER_HTTPS", "")); + proxyPortHttpsTB.setText(Cache.getDefault("PROXY_PORT_HTTPS", "")); + proxyAuth.setSelected(Cache.getDefault("PROXY_AUTH", false)); + proxyAuthUsernameTB + .setText(Cache.getDefault("PROXY_AUTH_USERNAME", "")); + // we are not storing or retrieving proxy password from .jalview_properties + proxyAuthPasswordPB.setText(Cache.proxyAuthPassword == null ? "" + : new String(Cache.proxyAuthPassword)); + setCustomProxyEnabled(); + applyProxyButtonEnabled(false); defaultBrowser.setText(Cache.getDefault("DEFAULT_BROWSER", "")); @@ -642,6 +861,7 @@ public class Preferences extends GPreferences annotations_actionPerformed(null); // update the display of the annotation // settings + /* @@ -663,6 +883,7 @@ public class Preferences extends GPreferences comboBox.addItem(promptEachTimeOpt); comboBox.addItem(lineArtOpt); comboBox.addItem(textOpt); + /* * JalviewJS doesn't support Lineart so force it to Text @@ -697,6 +918,11 @@ public class Preferences extends GPreferences return; } + /* + * Set proxy settings first (to be before web services refresh) + */ + saveProxySettings(); + /* * Save Visual settings */ @@ -741,6 +967,10 @@ public class Preferences extends GPreferences Boolean.toString(showConsensHistogram.isSelected())); Cache.setPropertyNoSave("SHOW_CONSENSUS_LOGO", Boolean.toString(showConsensLogo.isSelected())); + Cache.setPropertyNoSave("SHOW_INFORMATION_HISTOGRAM", + Boolean.toString(showConsensHistogram.isSelected())); + Cache.setPropertyNoSave("SHOW_HMM_LOGO", + Boolean.toString(showHMMLogo.isSelected())); Cache.setPropertyNoSave("ANTI_ALIAS", Boolean.toString(smoothFont.isSelected())); Cache.setPropertyNoSave(SCALE_PROTEIN_TO_CDNA, @@ -787,6 +1017,42 @@ public class Preferences extends GPreferences maxColour.getBackground()); /* + * Save HMMER settings + */ + Cache.setPropertyNoSave(HMMALIGN_TRIM_TERMINI, + Boolean.toString(hmmrTrimTermini.isSelected())); + Cache.setPropertyNoSave(HMMINFO_GLOBAL_BACKGROUND, + Boolean.toString(hmmerBackgroundUniprot.isSelected())); + Cache.setPropertyNoSave(HMMSEARCH_SEQCOUNT, + hmmerSequenceCount.getText()); + Cache.setOrRemove(HMMER_PATH, hmmerPath.getText()); + if (cygwinPath != null) + { + Cache.setOrRemove(CYGWIN_PATH, cygwinPath.getText()); + } + AlignFrame[] frames = Desktop.getAlignFrames(); + if (frames != null && frames.length > 0) + { + for (AlignFrame f : frames) + { + f.updateHMMERStatus(); + } + } + + hmmrTrimTermini.setSelected(Cache.getDefault(HMMALIGN_TRIM_TERMINI, false)); + if (Cache.getDefault(HMMINFO_GLOBAL_BACKGROUND, false)) + { + hmmerBackgroundUniprot.setSelected(true); + } + else + { + hmmerBackgroundAlignment.setSelected(true); + } + hmmerSequenceCount + .setText(Cache.getProperty(HMMSEARCH_SEQCOUNT)); + hmmerPath.setText(Cache.getProperty(HMMER_PATH)); + + /* * Save Overview settings */ Cache.setColourPropertyNoSave(GAP_COLOUR, gapColour.getBackground()); @@ -803,16 +1069,25 @@ public class Preferences extends GPreferences Boolean.toString(addTempFactor.isSelected())); Cache.setPropertyNoSave(ADD_SS_ANN, Boolean.toString(addSecondaryStructure.isSelected())); - Cache.setPropertyNoSave(USE_RNAVIEW, - Boolean.toString(useRnaView.isSelected())); Cache.setPropertyNoSave(STRUCT_FROM_PDB, Boolean.toString(structFromPdb.isSelected())); - if (!Platform.isJS()) + if (!Platform.isJS()) { + String viewer = structViewer.getSelectedItem().toString(); + String viewerPath = structureViewerPath.getText(); + Cache.setPropertyNoSave(STRUCTURE_DISPLAY, viewer); + if (viewer.equals(ViewerType.CHIMERA.name())) + { + Cache.setOrRemove(CHIMERA_PATH, viewerPath); + } + else if (viewer.equals(ViewerType.CHIMERAX.name())) + { + Cache.setOrRemove(CHIMERAX_PATH, viewerPath); + } + else if (viewer.equals(ViewerType.PYMOL.name())) { - Cache.setPropertyNoSave(STRUCTURE_DISPLAY, - structViewer.getSelectedItem().toString()); + Cache.setOrRemove(PYMOL_PATH, viewerPath); } - Cache.setOrRemove(CHIMERA_PATH, chimeraPath.getText()); + } // nojs Cache.setPropertyNoSave("MAP_WITH_SIFTS", Boolean.toString(siftsMapping.isSelected())); SiftsSettings.setMapWithSifts(siftsMapping.isSelected()); @@ -830,6 +1105,7 @@ public class Preferences extends GPreferences /* * Save Connections settings */ + // Proxy settings were already set first (to catch web services) Cache.setOrRemove("DEFAULT_BROWSER", defaultBrowser.getText()); jalview.util.BrowserLauncher.resetBrowser(); @@ -860,23 +1136,6 @@ public class Preferences extends GPreferences Cache.setPropertyNoSave("DEFAULT_URL", sequenceUrlLinks.getPrimaryUrlId()); - Cache.setPropertyNoSave("USE_PROXY", - Boolean.toString(useProxy.isSelected())); - - Cache.setOrRemove("PROXY_SERVER", proxyServerTB.getText()); - - Cache.setOrRemove("PROXY_PORT", proxyPortTB.getText()); - - if (useProxy.isSelected()) - { - System.setProperty("http.proxyHost", proxyServerTB.getText()); - System.setProperty("http.proxyPort", proxyPortTB.getText()); - } - else - { - System.setProperty("http.proxyHost", ""); - System.setProperty("http.proxyPort", ""); - } Cache.setProperty("VERSION_CHECK", Boolean.toString(versioncheck.isSelected())); if (Cache.getProperty("USAGESTATS") != null || usagestats.isSelected()) @@ -962,8 +1221,22 @@ public class Preferences extends GPreferences Cache.setPropertyNoSave( BackupFilesPresetEntry.SAVEDCONFIG, savedBFPE.toString()); + /* + * Save Memory Settings + */ + Cache.setPropertyNoSave( + MemorySetting.CUSTOMISED_SETTINGS, + Boolean.toString(customiseMemorySetting.isSelected())); + Cache.setPropertyNoSave(MemorySetting.MEMORY_JVMMEMPC, + Integer.toString(jvmMemoryPercentSlider.getValue())); + Cache.setPropertyNoSave(MemorySetting.MEMORY_JVMMEMMAX, + jvmMemoryMaxTextField.getText()); + + /* + * save and close Preferences + */ Cache.saveProperties(); - Desktop.instance.doConfigureStructurePrefs(); + Desktop.getInstance().doConfigureStructurePrefs(); try { frame.setClosed(true); @@ -972,6 +1245,30 @@ public class Preferences extends GPreferences } } + public void saveProxySettings() + { + String newProxyType = customProxy.isSelected() ? Cache.PROXYTYPE_CUSTOM + : noProxy.isSelected() ? Cache.PROXYTYPE_NONE + : Cache.PROXYTYPE_SYSTEM; + Cache.setPropertyNoSave("USE_PROXY", newProxyType); + Cache.setOrRemove("PROXY_SERVER", proxyServerHttpTB.getText()); + Cache.setOrRemove("PROXY_PORT", proxyPortHttpTB.getText()); + Cache.setOrRemove("PROXY_SERVER_HTTPS", proxyServerHttpsTB.getText()); + Cache.setOrRemove("PROXY_PORT_HTTPS", proxyPortHttpsTB.getText()); + Cache.setOrRemove("PROXY_AUTH", + Boolean.toString(proxyAuth.isSelected())); + Cache.setOrRemove("PROXY_AUTH_USERNAME", proxyAuthUsernameTB.getText()); + Cache.proxyAuthPassword = proxyAuthPasswordPB.getPassword(); + Cache.setProxyPropertiesFromPreferences(previousProxyType); + if (newProxyType.equals(Cache.PROXYTYPE_CUSTOM) + || !newProxyType.equals(previousProxyType)) + { + // force a re-lookup of ws if proxytype is custom or has changed + wsPrefs.refreshWs_actionPerformed(null); + } + previousProxyType = newProxyType; + } + public static void setAppletDefaults() { @@ -1027,7 +1324,7 @@ public class Preferences extends GPreferences @Override protected boolean validateStructure() { - return validateChimeraPath(); + return validateViewerPath(); } @@ -1101,6 +1398,8 @@ public class Preferences extends GPreferences && (identity.isSelected() || showGroupConsensus.isSelected())); showConsensLogo.setEnabled(annotations.isSelected() && (identity.isSelected() || showGroupConsensus.isSelected())); + showInformationHistogram.setEnabled(annotations.isSelected()); + showHMMLogo.setEnabled(annotations.isSelected()); } @Override @@ -1110,7 +1409,7 @@ public class Preferences extends GPreferences boolean valid = false; while (!valid) { - if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link, + if (JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(), link, MessageManager.getString("label.new_sequence_url_link"), JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION) @@ -1147,7 +1446,7 @@ public class Preferences extends GPreferences if (index == -1) { // button no longer enabled if row is not selected - Cache.log.debug("Edit with no row selected in linkUrlTable"); + Console.debug("Edit with no row selected in linkUrlTable"); return; } @@ -1162,7 +1461,7 @@ public class Preferences extends GPreferences boolean valid = false; while (!valid) { - if (JvOptionPane.showInternalConfirmDialog(Desktop.desktop, link, + if (JvOptionPane.showInternalConfirmDialog(Desktop.getDesktopPane(), link, MessageManager.getString("label.edit_sequence_url_link"), JvOptionPane.OK_CANCEL_OPTION, -1, null) == JvOptionPane.OK_OPTION) @@ -1199,7 +1498,7 @@ public class Preferences extends GPreferences if (index == -1) { // button no longer enabled if row is not selected - Cache.log.debug("Delete with no row selected in linkUrlTable"); + Console.debug("Delete with no row selected in linkUrlTable"); return; } else @@ -1335,7 +1634,7 @@ public class Preferences extends GPreferences } catch (NumberFormatException x) { userIdWidth.setText(""); - JvOptionPane.showInternalMessageDialog(Desktop.desktop, + JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), MessageManager .getString("warn.user_defined_width_requirements"), MessageManager.getString("label.invalid_id_column_width"), @@ -1351,44 +1650,130 @@ public class Preferences extends GPreferences } /** - * Returns true if chimera path is to a valid executable, else show an error - * dialog. + * Returns true if structure viewer path is to a valid executable, else shows an + * error dialog. Does nothing if the path is empty, as is the case for Jmol + * (built in to Jalview) or when Jalview is left to try default paths. */ - private boolean validateChimeraPath() + private boolean validateViewerPath() { - if (chimeraPath.getText().trim().length() > 0) + if (structureViewerPath.getText().trim().length() > 0) { - File f = new File(chimeraPath.getText()); + File f = new File(structureViewerPath.getText()); if (!f.canExecute()) { - JvOptionPane.showInternalMessageDialog(Desktop.desktop, - MessageManager.getString("label.invalid_chimera_path"), - MessageManager.getString("label.invalid_name"), + JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(), + MessageManager.getString("label.invalid_viewer_path"), + MessageManager.getString("label.invalid_viewer_path"), JvOptionPane.ERROR_MESSAGE); return false; } } return true; } + + /** + * Returns true if the given text field contains a path to a folder that + * contains an executable with the given name, else false (after showing a + * warning dialog). The executable name will be tried with .exe appended if not + * found. + * + * @param textField + * @param executable + */ + protected boolean validateExecutablePath(JTextField textField, String executable) + { + String folder = textField.getText().trim(); + + if (FileUtils.getExecutable(executable, folder) != null) + { + return true; + } + if (folder.length() > 0) + { + JvOptionPane.showInternalMessageDialog(Desktop.getInstance(), + MessageManager.formatMessage("label.executable_not_found", + executable), + MessageManager.getString("label.invalid_folder"), + JvOptionPane.ERROR_MESSAGE); + } + return false; + } + + /** + * Checks if a file can be executed + * + * @param path + * the path to the file + * @return + */ + public boolean canExecute(String path) + { + File file = new File(path); + if (!file.canExecute()) + { + file = new File(path + ".exe"); + { + if (!file.canExecute()) + { + 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. + * If Chimera or ChimeraX or Pymol 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())) + if (selectedItem.equals(ViewerType.JMOL.name())) { + structureViewerPath.setEnabled(false); + structureViewerPathLabel.setEnabled(false); return; } boolean found = false; + structureViewerPath.setEnabled(true); + structureViewerPathLabel.setEnabled(true); + structureViewerPathLabel.setText(MessageManager + .formatMessage("label.viewer_path", selectedItem)); /* - * Try user-specified and standard paths for Chimera executable. + * Try user-specified and standard paths for structure viewer executable */ - List paths = StructureManager.getChimeraPaths(); - paths.add(0, chimeraPath.getText()); + String viewerPath = ""; + List paths = null; + try + { + ViewerType viewerType = ViewerType.valueOf(selectedItem); + switch (viewerType) + { + case JMOL: + // dealt with above + break; + case CHIMERA: + viewerPath = Cache.getDefault(CHIMERA_PATH, ""); + paths = StructureManager.getChimeraPaths(false); + break; + case CHIMERAX: + viewerPath = Cache.getDefault(CHIMERAX_PATH, ""); + paths = StructureManager.getChimeraPaths(true); + break; + case PYMOL: + viewerPath = Cache.getDefault(PYMOL_PATH, ""); + paths = PymolManager.getPymolPaths(); + break; + } + } catch (IllegalArgumentException e) + { + // only valid entries should be in the drop-down + } + structureViewerPath.setText(viewerPath); + + paths.add(0, structureViewerPath.getText()); for (String path : paths) { if (new File(path.trim()).canExecute()) @@ -1397,16 +1782,19 @@ public class Preferences extends GPreferences break; } } + if (!found) { String[] options = { "OK", "Help" }; - int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.desktop, + int showHelp = JvOptionPane.showInternalOptionDialog(Desktop.getDesktopPane(), JvSwingUtils.wrapTooltip(true, - MessageManager.getString("label.chimera_missing")), + MessageManager.getString("label.viewer_missing")), "", JvOptionPane.YES_NO_OPTION, JvOptionPane.WARNING_MESSAGE, null, options, options[0]); + if (showHelp == JvOptionPane.NO_OPTION) { + this.selectTab(Preferences.TabRef.STRUCTURE_TAB, null); try { Help.showHelpWindow(HelpId.StructureViewer); @@ -1415,7 +1803,37 @@ public class Preferences extends GPreferences e.printStackTrace(); } } - } + else if (showHelp == JvOptionPane.OK_OPTION) + { + this.selectTab(Preferences.TabRef.STRUCTURE_TAB, null); + CompletableFuture cf = CompletableFuture.runAsync(() -> { + try + { + for (int i = 0; i < 3; i++) + { + structureViewerPath.setBackground(Color.PINK); + Thread.sleep(500); + structureViewerPath.setBackground(Color.WHITE); + Thread.sleep(500); + } + } catch (InterruptedException e) + { + } + }); + } + } + } + + @Override + protected void validateHmmerPath() + { + validateExecutablePath(hmmerPath, HmmerCommand.HMMBUILD); + } + + @Override + protected void validateCygwinPath() + { + validateExecutablePath(cygwinPath, "run"); } public class OptionsParam