From 1aa21d01e983854e9dbb1628350ac6976c52430a Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 17 Nov 2014 12:57:39 +0000 Subject: [PATCH] JAL-1586 chimera file chooser added, validate on OK/change tab --- help/html/features/preferences.html | 3 +- resources/lang/Messages.properties | 2 +- src/jalview/gui/Preferences.java | 59 +++++++++++++++---- src/jalview/jbgui/GPreferences.java | 109 ++++++++++++++++++++++++++++++++++- 4 files changed, 157 insertions(+), 16 deletions(-) diff --git a/help/html/features/preferences.html b/help/html/features/preferences.html index b2d8b93..0744c51 100755 --- a/help/html/features/preferences.html +++ b/help/html/features/preferences.html @@ -122,7 +122,8 @@ annotation will be shown on the alignment when available. annotation will be shown on the alignment when available.

Default structure viewer - choose JMOL or CHIMERA for viewing 3D structures.

Path to Chimera program - Optional, as Jalview will search standard installation paths for Windows, Linux or MacOS. -If you have installed Chimera in a non-standard location, you can specify it here. Enter the full path to the Chimera executable program. +If you have installed Chimera in a non-standard location, you can specify it here, by entering the full path to the Chimera executable program. +Double-click this field to open a file chooser dialog.

"Connections" Preferences tab

diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 511e5e9..c3ef580 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -250,7 +250,7 @@ label.autoadd_temp = Add Temperature Factor annotation to alignment label.structure_viewer = Default structure viewer label.chimera_path = Path to Chimera program label.chimera_path_tip = Jalview will try standard locations, plus any path entered here. -label.invalid_path = File not found or not executable +label.invalid_chimera_path = Chimera path not found or not executable label.min_colour = Minimum Colour label.max_colour = Maximum Colour label.use_original_colours = Use Original Colours diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index ab4f94f..ad3c072 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -291,17 +291,7 @@ public class Preferences extends GPreferences @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 +366,11 @@ public class Preferences extends GPreferences */ public void ok_actionPerformed(ActionEvent e) { + if (!validateSettings()) + { + return; + } + /* * Save Visual settings */ @@ -602,6 +597,27 @@ public class Preferences extends GPreferences } /** + * Do any necessary validation before saving settings. + * + * @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 +859,25 @@ 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; + } + } diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index a232377..9d691ca 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -26,6 +26,7 @@ import jalview.util.MessageManager; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; @@ -36,6 +37,8 @@ import java.awt.Insets; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; @@ -45,6 +48,7 @@ import javax.swing.DefaultListCellRenderer; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; +import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; @@ -56,6 +60,8 @@ import javax.swing.SwingConstants; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; import javax.swing.border.TitledBorder; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @@ -128,8 +134,10 @@ public class GPreferences extends JPanel protected JCheckBox showNpTooltip = new JCheckBox(); /* - * Annotations tab components + * Structure tab and components */ + protected JPanel structureTab; + protected JCheckBox structFromPdb = new JCheckBox(); protected JCheckBox useRnaView = new JCheckBox(); @@ -239,7 +247,7 @@ public class GPreferences extends JPanel */ private void jbInit() throws Exception { - JTabbedPane tabbedPane = new JTabbedPane(); + final JTabbedPane tabbedPane = new JTabbedPane(); this.setLayout(new BorderLayout()); JPanel okCancelPanel = initOkCancelPanel(); this.add(tabbedPane, BorderLayout.CENTER); @@ -273,6 +281,31 @@ public class GPreferences extends JPanel */ wsTab.setLayout(new BorderLayout()); tabbedPane.add(wsTab, MessageManager.getString("label.web_services")); + + /* + * Handler to validate a tab before leaving it - currently only for + * Structure. + */ + tabbedPane.addChangeListener(new ChangeListener() + { + private Component lastTab; + + @Override + public void stateChanged(ChangeEvent e) + { + if (lastTab == structureTab + && tabbedPane.getSelectedComponent() != structureTab) + { + if (!validateStructure()) + { + tabbedPane.setSelectedComponent(structureTab); + return; + } + } + lastTab = tabbedPane.getSelectedComponent(); + } + + }); } /** @@ -691,7 +724,8 @@ public class GPreferences extends JPanel */ private JPanel initStructureTab() { - JPanel structureTab = new JPanel(); + structureTab = new JPanel(); + structureTab.setBorder(new TitledBorder(MessageManager .getString("label.structure_options"))); structureTab.setLayout(null); @@ -764,12 +798,81 @@ public class GPreferences extends JPanel chimeraPath.setFont(verdana11); chimeraPath.setText(""); chimeraPath.setBounds(new Rectangle(160, ypos, 300, height)); + chimeraPath.addMouseListener(new MouseAdapter() + { + @Override + public void mouseClicked(MouseEvent e) + { + if (e.getClickCount() == 2) + { + String chosen = openFileChooser(); + if (chosen != null) + { + chimeraPath.setText(chosen); + } + } + } + }); structureTab.add(chimeraPath); + structureTab.addFocusListener(new FocusAdapter() + { + @Override + public void focusLost(FocusEvent e) + { + validateStructure(e); + } + + }); return structureTab; } /** + * Show a dialog for the user to choose a file. Returns the chosen path, or + * null on Cancel. + * + * @return + */ + protected String openFileChooser() + { + String choice = null; + JFileChooser chooser = new JFileChooser(); + + // chooser.setFileView(new JalviewFileView()); + chooser.setDialogTitle(MessageManager + .getString("label.open_local_file")); + chooser.setToolTipText(MessageManager.getString("action.open")); + + int value = chooser.showOpenDialog(this); + + if (value == JFileChooser.APPROVE_OPTION) + { + choice = chooser.getSelectedFile().getPath(); + } + return choice; + } + + /** + * Validate the structure tab preferences; if invalid, set focus on this tab. + * + * @param e + */ + protected boolean validateStructure(FocusEvent e) + { + if (!validateStructure()) + { + e.getComponent().requestFocusInWindow(); + return false; + } + return true; + } + + protected boolean validateStructure() + { + return false; + } + + /** * Initialises the Visual tabbed panel. * * @return -- 1.7.10.2