X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fjbgui%2FGPreferences.java;h=1d35477244f18cb0384a47855c7b6855d9958efa;hb=cf491d18e6affbfacfc67eda7c6bceedd457982f;hp=a2323778999d2aa332e63fa2ae7863039f55cf40;hpb=4167762603a83df3e00713307e6522bb027bdd59;p=jalview.git diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index a232377..1d35477 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.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. * @@ -21,11 +21,13 @@ package jalview.jbgui; import jalview.gui.JvSwingUtils; -import jalview.gui.StructureViewer.Viewer; +import jalview.gui.StructureViewer.ViewerType; +import jalview.jbgui.PDBDocFieldPreferences.PreferenceSource; 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 +38,7 @@ import java.awt.Insets; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +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(); @@ -142,6 +150,7 @@ public class GPreferences extends JPanel protected JTextField chimeraPath = new JTextField(); + /* * Colours tab components */ @@ -149,7 +158,9 @@ public class GPreferences extends JPanel protected JPanel maxColour = new JPanel(); - protected JComboBox colour = new JComboBox(); + protected JComboBox protColour = new JComboBox(); + + protected JComboBox nucColour = new JComboBox(); /* * Connections tab components @@ -239,7 +250,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 +284,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(); + } + + }); } /** @@ -660,16 +696,30 @@ public class GPreferences extends JPanel maxColour_actionPerformed(maxColour); } }); - colour.setFont(verdana11); - colour.setBounds(new Rectangle(172, 225, 155, 21)); - JLabel colourLabel = new JLabel(); - colourLabel.setFont(verdana11); - colourLabel.setHorizontalAlignment(SwingConstants.RIGHT); - colourLabel.setText(MessageManager.getString("label.alignment_colour") + + protColour.setFont(verdana11); + protColour.setBounds(new Rectangle(172, 225, 155, 21)); + JLabel protColourLabel = new JLabel(); + protColourLabel.setFont(verdana11); + protColourLabel.setHorizontalAlignment(SwingConstants.LEFT); + protColourLabel.setText(MessageManager + .getString("label.prot_alignment_colour") + " "); + JvSwingUtils.addtoLayout(coloursTab, MessageManager + .getString("label.default_colour_scheme_for_alignment"), + protColourLabel, protColour); + + nucColour.setFont(verdana11); + nucColour.setBounds(new Rectangle(172, 240, 155, 21)); + JLabel nucColourLabel = new JLabel(); + nucColourLabel.setFont(verdana11); + nucColourLabel.setHorizontalAlignment(SwingConstants.LEFT); + nucColourLabel.setText(MessageManager + .getString("label.nuc_alignment_colour") + " "); JvSwingUtils.addtoLayout(coloursTab, MessageManager .getString("label.default_colour_scheme_for_alignment"), - colourLabel, colour); + nucColourLabel, nucColour); + JPanel annotationShding = new JPanel(); annotationShding.setBorder(new TitledBorder(MessageManager .getString("label.annotation_shading_default"))); @@ -691,13 +741,14 @@ 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); final int width = 400; - final int height = 23; - final int lineSpacing = 30; + final int height = 22; + final int lineSpacing = 25; int ypos = 30; structFromPdb.setFont(verdana11); @@ -747,8 +798,17 @@ public class GPreferences extends JPanel structViewer.setFont(verdana11); structViewer.setBounds(new Rectangle(160, ypos, 120, height)); - structViewer.addItem(Viewer.JMOL.name()); - structViewer.addItem(Viewer.CHIMERA.name()); + structViewer.addItem(ViewerType.JMOL.name()); + structViewer.addItem(ViewerType.CHIMERA.name()); + structViewer.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + structureViewer_actionPerformed((String) structViewer + .getSelectedItem()); + } + }); structureTab.add(structViewer); ypos += lineSpacing; @@ -756,19 +816,103 @@ public class GPreferences extends JPanel pathLabel.setFont(new java.awt.Font("SansSerif", 0, 11)); pathLabel.setHorizontalAlignment(SwingConstants.LEFT); pathLabel.setText(MessageManager.getString("label.chimera_path")); - pathLabel.setToolTipText(MessageManager - .getString("label.chimera_path_tip")); + final String tooltip = JvSwingUtils.wrapTooltip(true, + MessageManager.getString("label.chimera_path_tip")); + pathLabel.setToolTipText(tooltip); pathLabel.setBounds(new Rectangle(10, ypos, 140, height)); structureTab.add(pathLabel); 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); + ypos += lineSpacing; + // scrl_pdbDocFieldConfig.setPreferredSize(new Dimension(450, 100)); + // scrl_pdbDocFieldConfig + // .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + // scrl_pdbDocFieldConfig.setBounds(); + PDBDocFieldPreferences docFieldPref = new PDBDocFieldPreferences( + PreferenceSource.PREFERENCES); + docFieldPref.setBounds(new Rectangle(10, ypos + 5, 450, 120)); + structureTab.add(docFieldPref); + + + + return structureTab; } + + /** + * Action on choosing a structure viewer from combobox options. + * + * @param selectedItem + */ + protected void structureViewer_actionPerformed(String selectedItem) + { + } + + /** + * 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. *