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;
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<JButton> selectedButtons;
ColourSchemeI oldColourScheme;
JalviewStructureDisplayI jmol;
- Vector upperCaseButtons;
+ ArrayList<JButton> upperCaseButtons;
- Vector lowerCaseButtons;
+ ArrayList<JButton> lowerCaseButtons;
/**
* Creates a new UserDefinedColours object.
showFrame();
}
- public UserDefinedColours(JalviewStructureDisplayI jmol, ColourSchemeI oldcs)
+ public UserDefinedColours(JalviewStructureDisplayI jmol,
+ ColourSchemeI oldcs)
{
super();
this.jmol = jmol;
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)
{
if (upperCaseButtons == null)
{
- upperCaseButtons = new Vector();
+ upperCaseButtons = new ArrayList<JButton>();
}
JButton button;
if (lowerCaseButtons == null)
{
- lowerCaseButtons = new Vector();
+ lowerCaseButtons = new ArrayList<JButton>();
}
for (int i = 0; i < 20; i++)
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();
}
* @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));
}
{
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).
+ * <p>
+ * On select button(s) with Ctrl/click or Shift/click: set button foreground
+ * text to brighter than background.
+ * <p>
+ * On unselect button(s) with Ctrl/click on selected, or click to release
+ * current selection: reset foreground text to darker than background.
+ * <p>
+ * Simple click: clear selection (resetting foreground to darker); set clicked
+ * button foreground to brighter
+ * <p>
+ * 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>();
}
JButton pressed = (JButton) e.getSource();
JButton start, end = (JButton) e.getSource();
if (selectedButtons.size() > 0)
{
- start = (JButton) selectedButtons
- .elementAt(selectedButtons.size() - 1);
+ start = selectedButtons.get(selectedButtons.size() - 1);
}
else
{
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);
}
}
{
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())
}
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());
}
}
* @param aa
* DOCUMENT ME!
*/
- JButton makeButton(String label, String aa, Vector caseSensitiveButtons,
- int buttonIndex)
+ JButton makeButton(String label, String aa,
+ ArrayList<JButton> 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
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)
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));
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void okButton_actionPerformed(ActionEvent e)
{
applyButton_actionPerformed(null);
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void applyButton_actionPerformed(ActionEvent e)
{
UserColourScheme ucs = getSchemeFromButtons();
for (int i = 0; i < 24; i++)
{
- JButton button = (JButton) upperCaseButtons.elementAt(i);
+ JButton button = upperCaseButtons.get(i);
newColours[i] = button.getBackground();
}
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);
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void loadbutton_actionPerformed(ActionEvent e)
{
- upperCaseButtons = new Vector();
- lowerCaseButtons = new Vector();
+ upperCaseButtons = new ArrayList<JButton>();
+ lowerCaseButtons = new ArrayList<JButton>();
JalviewFileChooser chooser = new JalviewFileChooser(
jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
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]);
}
for (int i = 0; i < upperCaseButtons.size(); i++)
{
- JButton button = (JButton) upperCaseButtons.elementAt(i);
+ JButton button = upperCaseButtons.get(i);
button.setBackground(colors[i]);
}
jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours();
- jucs = (jalview.binding.JalviewUserColours) jucs.unmarshal(in);
+ jucs = jucs.unmarshal(in);
newColours = new Color[jucs.getColourCount()];
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void savebutton_actionPerformed(ActionEvent e)
{
if (schemeName.getText().trim().length() < 1)
{
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);
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void cancelButton_actionPerformed(ActionEvent e)
{
if (ap != null)
}
+ @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<JButton>();
}
else
{
}
selectedButtons.add(lcaseColour);
}
-
}