From 89f5f42442afb17c02f59d3b3c30e2bab314987c Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Tue, 14 Sep 2021 10:52:42 +0100 Subject: [PATCH] JAL-2422 More helpful highlighting/user guidance of missing structure viewer path --- src/jalview/bin/Cache.java | 27 ++++++++-------- src/jalview/gui/Preferences.java | 61 ++++++++++++++++++++++++++--------- src/jalview/jbgui/GPreferences.java | 20 ++++++++---- 3 files changed, 71 insertions(+), 37 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 353f449..216b498 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -370,8 +370,8 @@ public class Cache } /** - * Loads properties from the given properties file. Any existing properties - * are first cleared. + * Loads properties from the given properties file. Any existing properties are + * first cleared. */ public static void loadProperties(String propsFile) { @@ -710,11 +710,10 @@ public class Cache } /** - * Gets Jalview application property of given key. Returns null if key not - * found + * Gets Jalview application property of given key. Returns null if key not found * * @param key - * Name of property + * Name of property * * @return Property value */ @@ -730,8 +729,8 @@ public class Cache } /** - * These methods are used when checking if the saved preference is different - * to the default setting + * These methods are used when checking if the saved preference is different to + * the default setting */ public static boolean getDefault(String property, boolean def) @@ -764,8 +763,8 @@ public class Cache } /** - * Answers the value of the given property, or the supplied default value if - * the property is not set + * Answers the value of the given property, or the supplied default value if the + * property is not set */ public static String getDefault(String property, String def) { @@ -777,9 +776,9 @@ public class Cache * Stores property in the file "HOME_DIR/.jalview_properties" * * @param key - * Name of object + * Name of object * @param obj - * String value of property + * String value of property * * @return previous value of property (or null) */ @@ -1167,7 +1166,7 @@ public class Cache * Loads in user colour schemes from files. * * @param files - * a '|'-delimited list of file paths + * a '|'-delimited list of file paths */ public static void initUserColourSchemes(String files) { @@ -1476,8 +1475,8 @@ public class Cache // open Preferences -> Connections String message = MessageManager .getString("label.proxy_password_required"); - Preferences.openPreferences(Preferences.CONNECTIONS_TAB, - message); + Preferences.openPreferences( + Preferences.TabRef.CONNECTIONS_TAB, message); Preferences.getInstance() .proxyAuthPasswordCheckHighlight(true, true); } diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index 6972657..834d779 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -31,6 +31,7 @@ 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; @@ -145,10 +146,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; @@ -219,19 +220,27 @@ public class Preferences extends GPreferences public static void openPreferences() { - openPreferences(0, null); + openPreferences(null, null); } - public static void openPreferences(int selectTab, String message) + public static void openPreferences(TabRef selectTab, String message) { Preferences p = getInstance(); - p.selectTab(selectTab); - p.setMessage(message); + 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. */ @@ -1009,8 +1018,8 @@ public class Preferences extends GPreferences } /** - * Do any necessary validation before saving settings. Return focus to the - * first tab which fails validation. + * Do any necessary validation before saving settings. Return focus to the first + * tab which fails validation. * * @return */ @@ -1064,7 +1073,7 @@ public class Preferences extends GPreferences * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ @Override public void cancel_actionPerformed(ActionEvent e) @@ -1086,7 +1095,7 @@ public class Preferences extends GPreferences * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ @Override public void annotations_actionPerformed(ActionEvent e) @@ -1349,8 +1358,8 @@ public class Preferences extends GPreferences } /** - * 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 + * 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 validateViewerPath() @@ -1371,8 +1380,8 @@ public class Preferences extends GPreferences } /** - * 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 + * 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) @@ -1439,8 +1448,10 @@ public class Preferences extends GPreferences 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); @@ -1449,6 +1460,24 @@ 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) + { + } + }); + } } } diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index 1a4a44b..e6efed6 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -510,9 +510,12 @@ public class GPreferences extends JPanel } } - public final static int CONNECTIONS_TAB = 5; + public static enum TabRef + { + CONNECTIONS_TAB, STRUCTURE_TAB + }; - public void selectTab(int selectTab) + public void selectTab(TabRef selectTab) { // select a given tab - currently only for Connections switch (selectTab) @@ -520,6 +523,9 @@ public class GPreferences extends JPanel case CONNECTIONS_TAB: tabbedPane.setSelectedComponent(connectTab); break; + case STRUCTURE_TAB: + tabbedPane.setSelectedComponent(structureTab); + break; default: } } @@ -1789,8 +1795,8 @@ public class GPreferences extends JPanel } /** - * Show a dialog for the user to choose a file. Returns the chosen path, or - * null on Cancel. + * Show a dialog for the user to choose a file. Returns the chosen path, or null + * on Cancel. * * @return */ @@ -3166,7 +3172,7 @@ public class GPreferences extends JPanel * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ public void ok_actionPerformed(ActionEvent e) { @@ -3176,7 +3182,7 @@ public class GPreferences extends JPanel * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ public void cancel_actionPerformed(ActionEvent e) { @@ -3186,7 +3192,7 @@ public class GPreferences extends JPanel * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ public void annotations_actionPerformed(ActionEvent e) { -- 1.7.10.2