From bb52d658918ad82afa41cdcd5da3e72716f111e9 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 18 Sep 2014 11:21:04 +0100 Subject: [PATCH] JAL-1360 Javadoc, Vector replaced with ArrayList, code formatted --- src/jalview/gui/UserDefinedColours.java | 130 +++++++++++++++++++------------ 1 file changed, 79 insertions(+), 51 deletions(-) diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index 1f23338..43c648e 100755 --- a/src/jalview/gui/UserDefinedColours.java +++ b/src/jalview/gui/UserDefinedColours.java @@ -40,9 +40,9 @@ import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; +import java.util.ArrayList; import java.util.Hashtable; import java.util.StringTokenizer; -import java.util.Vector; import javax.swing.JButton; import javax.swing.JInternalFrame; @@ -51,23 +51,26 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; /** - * DOCUMENT ME! + * This panel allows the user to assign colours to Amino Acid residue codes, and + * save the colour scheme. * - * @author $author$ - * @version $Revision$ + * @author Andrew Waterhouse + * @author Mungo Carstairs */ public class UserDefinedColours extends GUserDefinedColours implements ChangeListener { private static final int MY_FRAME_HEIGHT = 420; + private static final int MY_FRAME_WIDTH = 810; + private static final int MY_FRAME_WIDTH_CASE_SENSITIVE = 970; -AlignmentPanel ap; + AlignmentPanel ap; SequenceGroup seqGroup; - Vector selectedButtons; + ArrayList selectedButtons; ColourSchemeI oldColourScheme; @@ -75,9 +78,9 @@ AlignmentPanel ap; JalviewStructureDisplayI jmol; - Vector upperCaseButtons; + ArrayList upperCaseButtons; - Vector lowerCaseButtons; + ArrayList lowerCaseButtons; /** * Creates a new UserDefinedColours object. @@ -127,7 +130,8 @@ AlignmentPanel ap; showFrame(); } - public UserDefinedColours(JalviewStructureDisplayI jmol, ColourSchemeI oldcs) + public UserDefinedColours(JalviewStructureDisplayI jmol, + ColourSchemeI oldcs) { super(); this.jmol = jmol; @@ -152,9 +156,9 @@ AlignmentPanel ap; colorChooser.getSelectionModel().addChangeListener(this); frame = new JInternalFrame(); frame.setContentPane(this); - Desktop.addInternalFrame(frame, - MessageManager.getString("label.user_defined_colours"), MY_FRAME_WIDTH, - MY_FRAME_HEIGHT, true); + Desktop.addInternalFrame(frame, + MessageManager.getString("label.user_defined_colours"), + MY_FRAME_WIDTH, MY_FRAME_HEIGHT, true); if (seqGroup != null) { @@ -168,7 +172,7 @@ AlignmentPanel ap; if (upperCaseButtons == null) { - upperCaseButtons = new Vector(); + upperCaseButtons = new ArrayList(); } JButton button; @@ -209,7 +213,7 @@ AlignmentPanel ap; if (lowerCaseButtons == null) { - lowerCaseButtons = new Vector(); + lowerCaseButtons = new ArrayList(); } for (int i = 0; i < 20; i++) @@ -230,12 +234,15 @@ AlignmentPanel ap; buttonPanel.add(makeButton("x", "x", lowerCaseButtons, 22)); } - // JAL-1360 widen the frame dynamically to accommodate case-sensitive AA codes - if (this.frame != null) { - int newWidth = caseSensitive ? MY_FRAME_WIDTH_CASE_SENSITIVE : MY_FRAME_WIDTH; - this.frame.setSize(newWidth, this.frame.getHeight()); + // JAL-1360 widen the frame dynamically to accommodate case-sensitive AA + // codes + if (this.frame != null) + { + int newWidth = caseSensitive ? MY_FRAME_WIDTH_CASE_SENSITIVE + : MY_FRAME_WIDTH; + this.frame.setSize(newWidth, this.frame.getHeight()); } - + buttonPanel.validate(); validate(); } @@ -246,15 +253,16 @@ AlignmentPanel ap; * @param evt * DOCUMENT ME! */ + @Override public void stateChanged(ChangeEvent evt) { if (selectedButtons != null) { JButton button = null; - final Color newColour = colorChooser.getColor(); - for (int i = 0; i < selectedButtons.size(); i++) + final Color newColour = colorChooser.getColor(); + for (int i = 0; i < selectedButtons.size(); i++) { - button = (JButton) selectedButtons.elementAt(i); + button = selectedButtons.get(i); button.setBackground(newColour); button.setForeground(ColorUtils.brighterThan(newColour)); } @@ -262,25 +270,38 @@ AlignmentPanel ap; { for (int i = 0; i < lowerCaseButtons.size(); i++) { - button = (JButton) lowerCaseButtons.elementAt(i); + button = lowerCaseButtons.get(i); button.setBackground(newColour); - button.setForeground(ColorUtils.brighterThan(button.getBackground())); + button.setForeground(ColorUtils.brighterThan(button + .getBackground())); } } } } /** - * DOCUMENT ME! + * Performs actions when a residue button is clicked. This manages the button + * selection set (highlighted by brighter foreground text). + *

+ * On select button(s) with Ctrl/click or Shift/click: set button foreground + * text to brighter than background. + *

+ * On unselect button(s) with Ctrl/click on selected, or click to release + * current selection: reset foreground text to darker than background. + *

+ * Simple click: clear selection (resetting foreground to darker); set clicked + * button foreground to brighter + *

+ * Finally, synchronize the colour chooser to the colour of the first button + * in the selected set. * * @param e - * DOCUMENT ME! */ public void colourButtonPressed(MouseEvent e) { if (selectedButtons == null) { - selectedButtons = new Vector(); + selectedButtons = new ArrayList(); } JButton pressed = (JButton) e.getSource(); @@ -290,8 +311,7 @@ AlignmentPanel ap; JButton start, end = (JButton) e.getSource(); if (selectedButtons.size() > 0) { - start = (JButton) selectedButtons - .elementAt(selectedButtons.size() - 1); + start = selectedButtons.get(selectedButtons.size() - 1); } else { @@ -323,7 +343,8 @@ AlignmentPanel ap; JButton button = (JButton) buttonPanel.getComponent(b); if (!selectedButtons.contains(button)) { - button.setForeground(ColorUtils.brighterThan(button.getBackground())); + button.setForeground(ColorUtils.brighterThan(button + .getBackground())); selectedButtons.add(button); } } @@ -332,12 +353,12 @@ AlignmentPanel ap; { for (int b = 0; b < selectedButtons.size(); b++) { - JButton button = (JButton) selectedButtons.elementAt(b); + JButton button = selectedButtons.get(b); button.setForeground(ColorUtils.darkerThan(button.getBackground())); } selectedButtons.clear(); pressed.setForeground(ColorUtils.brighterThan(pressed.getBackground())); - selectedButtons.addElement(pressed); + selectedButtons.add(pressed); } else if (e.isControlDown()) @@ -349,15 +370,15 @@ AlignmentPanel ap; } else { - pressed.setForeground(ColorUtils.brighterThan(pressed.getBackground())); - selectedButtons.addElement(pressed); + pressed.setForeground(ColorUtils.brighterThan(pressed + .getBackground())); + selectedButtons.add(pressed); } } if (selectedButtons.size() > 0) { - colorChooser.setColor(((JButton) selectedButtons.elementAt(0)) - .getBackground()); + colorChooser.setColor((selectedButtons.get(0)).getBackground()); } } @@ -369,15 +390,15 @@ AlignmentPanel ap; * @param aa * DOCUMENT ME! */ - JButton makeButton(String label, String aa, Vector caseSensitiveButtons, - int buttonIndex) + JButton makeButton(String label, String aa, + ArrayList caseSensitiveButtons, int buttonIndex) { final JButton button; Color col; if (buttonIndex < caseSensitiveButtons.size()) { - button = (JButton) caseSensitiveButtons.elementAt(buttonIndex); + button = caseSensitiveButtons.get(buttonIndex); col = button.getBackground(); } else @@ -385,13 +406,14 @@ AlignmentPanel ap; button = new JButton(); button.addMouseListener(new java.awt.event.MouseAdapter() { + @Override public void mouseClicked(MouseEvent e) { colourButtonPressed(e); } }); - caseSensitiveButtons.addElement(button); + caseSensitiveButtons.add(button); col = Color.white; if (oldColourScheme != null) @@ -414,7 +436,7 @@ AlignmentPanel ap; button.setMargin(new java.awt.Insets(2, 14, 2, 14)); } - button.setOpaque(true); // required for the next line to have effect + button.setOpaque(true); // required for the next line to have effect button.setBackground(col); button.setText(label); button.setForeground(ColorUtils.darkerThan(col)); @@ -429,6 +451,7 @@ AlignmentPanel ap; * @param e * DOCUMENT ME! */ + @Override protected void okButton_actionPerformed(ActionEvent e) { applyButton_actionPerformed(null); @@ -447,6 +470,7 @@ AlignmentPanel ap; * @param e * DOCUMENT ME! */ + @Override protected void applyButton_actionPerformed(ActionEvent e) { UserColourScheme ucs = getSchemeFromButtons(); @@ -474,7 +498,7 @@ AlignmentPanel ap; for (int i = 0; i < 24; i++) { - JButton button = (JButton) upperCaseButtons.elementAt(i); + JButton button = upperCaseButtons.get(i); newColours[i] = button.getBackground(); } @@ -485,7 +509,7 @@ AlignmentPanel ap; newColours = new Color[23]; for (int i = 0; i < 23; i++) { - JButton button = (JButton) lowerCaseButtons.elementAt(i); + JButton button = lowerCaseButtons.get(i); newColours[i] = button.getBackground(); } ucs.setLowerCaseColours(newColours); @@ -505,10 +529,11 @@ AlignmentPanel ap; * @param e * DOCUMENT ME! */ + @Override protected void loadbutton_actionPerformed(ActionEvent e) { - upperCaseButtons = new Vector(); - lowerCaseButtons = new Vector(); + upperCaseButtons = new ArrayList(); + lowerCaseButtons = new ArrayList(); JalviewFileChooser chooser = new JalviewFileChooser( jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] @@ -546,7 +571,7 @@ AlignmentPanel ap; resetButtonPanel(true); for (int i = 0; i < lowerCaseButtons.size(); i++) { - JButton button = (JButton) lowerCaseButtons.elementAt(i); + JButton button = lowerCaseButtons.get(i); button.setBackground(ucs.getLowerCaseColours()[i]); } @@ -560,7 +585,7 @@ AlignmentPanel ap; for (int i = 0; i < upperCaseButtons.size(); i++) { - JButton button = (JButton) upperCaseButtons.elementAt(i); + JButton button = upperCaseButtons.get(i); button.setBackground(colors[i]); } @@ -685,7 +710,7 @@ AlignmentPanel ap; jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours(); - jucs = (jalview.binding.JalviewUserColours) jucs.unmarshal(in); + jucs = jucs.unmarshal(in); newColours = new Color[jucs.getColourCount()]; @@ -719,6 +744,7 @@ AlignmentPanel ap; * @param e * DOCUMENT ME! */ + @Override protected void savebutton_actionPerformed(ActionEvent e) { if (schemeName.getText().trim().length() < 1) @@ -735,7 +761,7 @@ AlignmentPanel ap; { int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop, MessageManager.formatMessage( - "label.colour_scheme_exists_overwrite", new String[] + "label.colour_scheme_exists_overwrite", new Object[] { schemeName.getText(), schemeName.getText() }), MessageManager.getString("label.duplicate_scheme_name"), JOptionPane.YES_NO_OPTION); @@ -810,6 +836,7 @@ AlignmentPanel ap; * @param e * DOCUMENT ME! */ + @Override protected void cancelButton_actionPerformed(ActionEvent e) { if (ap != null) @@ -939,17 +966,19 @@ AlignmentPanel ap; } + @Override public void caseSensitive_actionPerformed(ActionEvent e) { resetButtonPanel(caseSensitive.isSelected()); lcaseColour.setEnabled(caseSensitive.isSelected()); } + @Override public void lcaseColour_actionPerformed(ActionEvent e) { if (selectedButtons == null) { - selectedButtons = new Vector(); + selectedButtons = new ArrayList(); } else { @@ -957,5 +986,4 @@ AlignmentPanel ap; } selectedButtons.add(lcaseColour); } - } -- 1.7.10.2