();
}
for (int i = 0; i < 20; i++)
@@ -224,6 +234,15 @@ public class UserDefinedColours extends GUserDefinedColours implements
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());
+ }
+
buttonPanel.validate();
validate();
}
@@ -234,42 +253,55 @@ public class UserDefinedColours extends GUserDefinedColours implements
* @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++)
{
- button = (JButton) selectedButtons.elementAt(i);
- button.setBackground(colorChooser.getColor());
- button.setForeground(button.getBackground().brighter().brighter()
- .brighter());
+ button = selectedButtons.get(i);
+ button.setBackground(newColour);
+ button.setForeground(ColorUtils.brighterThan(newColour));
}
if (button == lcaseColour)
{
for (int i = 0; i < lowerCaseButtons.size(); i++)
{
- button = (JButton) lowerCaseButtons.elementAt(i);
- button.setBackground(colorChooser.getColor());
- button.setForeground(button.getBackground().brighter().brighter()
- .brighter());
+ button = lowerCaseButtons.get(i);
+ button.setBackground(newColour);
+ 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();
@@ -279,8 +311,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
JButton start, end = (JButton) e.getSource();
if (selectedButtons.size() > 0)
{
- start = (JButton) selectedButtons
- .elementAt(selectedButtons.size() - 1);
+ start = selectedButtons.get(selectedButtons.size() - 1);
}
else
{
@@ -312,7 +343,8 @@ public class UserDefinedColours extends GUserDefinedColours implements
JButton button = (JButton) buttonPanel.getComponent(b);
if (!selectedButtons.contains(button))
{
- button.setForeground(button.getBackground().brighter().brighter());
+ button.setForeground(ColorUtils.brighterThan(button
+ .getBackground()));
selectedButtons.add(button);
}
}
@@ -321,32 +353,32 @@ public class UserDefinedColours extends GUserDefinedColours implements
{
for (int b = 0; b < selectedButtons.size(); b++)
{
- JButton button = (JButton) selectedButtons.elementAt(b);
- button.setForeground(button.getBackground().darker().darker());
+ JButton button = selectedButtons.get(b);
+ button.setForeground(ColorUtils.darkerThan(button.getBackground()));
}
selectedButtons.clear();
- pressed.setForeground(pressed.getBackground().brighter().brighter());
- selectedButtons.addElement(pressed);
+ pressed.setForeground(ColorUtils.brighterThan(pressed.getBackground()));
+ selectedButtons.add(pressed);
}
else if (e.isControlDown())
{
if (selectedButtons.contains(pressed))
{
- pressed.setForeground(pressed.getBackground().darker().darker());
+ pressed.setForeground(ColorUtils.darkerThan(pressed.getBackground()));
selectedButtons.remove(pressed);
}
else
{
- pressed.setForeground(pressed.getBackground().brighter().brighter());
- 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());
}
}
@@ -358,15 +390,15 @@ public class UserDefinedColours extends GUserDefinedColours implements
* @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
@@ -374,13 +406,14 @@ public class UserDefinedColours extends GUserDefinedColours implements
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)
@@ -403,9 +436,10 @@ public class UserDefinedColours extends GUserDefinedColours implements
button.setMargin(new java.awt.Insets(2, 14, 2, 14));
}
+ button.setOpaque(true); // required for the next line to have effect
button.setBackground(col);
button.setText(label);
- button.setForeground(col.darker().darker().darker());
+ button.setForeground(ColorUtils.darkerThan(col));
button.setFont(new java.awt.Font("Verdana", Font.BOLD, 10));
return button;
@@ -417,6 +451,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void okButton_actionPerformed(ActionEvent e)
{
applyButton_actionPerformed(null);
@@ -435,6 +470,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void applyButton_actionPerformed(ActionEvent e)
{
UserColourScheme ucs = getSchemeFromButtons();
@@ -462,7 +498,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
for (int i = 0; i < 24; i++)
{
- JButton button = (JButton) upperCaseButtons.elementAt(i);
+ JButton button = upperCaseButtons.get(i);
newColours[i] = button.getBackground();
}
@@ -473,7 +509,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
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);
@@ -493,18 +529,20 @@ public class UserDefinedColours extends GUserDefinedColours implements
* @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[]
{ "jc" }, new String[]
{ "Jalview User Colours" }, "Jalview User Colours");
chooser.setFileView(new jalview.io.JalviewFileView());
- chooser.setDialogTitle("Load colour scheme");
- chooser.setToolTipText("Load");
+ chooser.setDialogTitle(MessageManager
+ .getString("label.load_colour_scheme"));
+ chooser.setToolTipText(MessageManager.getString("action.load"));
int value = chooser.showOpenDialog(this);
@@ -533,7 +571,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
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]);
}
@@ -547,7 +585,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
for (int i = 0; i < upperCaseButtons.size(); i++)
{
- JButton button = (JButton) upperCaseButtons.elementAt(i);
+ JButton button = upperCaseButtons.get(i);
button.setBackground(colors[i]);
}
@@ -672,7 +710,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours();
- jucs = (jalview.binding.JalviewUserColours) jucs.unmarshal(in);
+ jucs = jucs.unmarshal(in);
newColours = new Color[jucs.getColourCount()];
@@ -706,25 +744,27 @@ public class UserDefinedColours extends GUserDefinedColours implements
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void savebutton_actionPerformed(ActionEvent e)
{
if (schemeName.getText().trim().length() < 1)
{
- JOptionPane.showInternalMessageDialog(Desktop.desktop,
- "User colour scheme must have a name!",
- "No name for colour scheme", JOptionPane.WARNING_MESSAGE);
+ JOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
+ .getString("label.user_colour_scheme_must_have_name"),
+ MessageManager.getString("label.no_name_colour_scheme"),
+ JOptionPane.WARNING_MESSAGE);
return;
}
if (userColourSchemes != null
&& userColourSchemes.containsKey(schemeName.getText()))
{
- int reply = JOptionPane.showInternalConfirmDialog(
- Desktop.desktop,
- "Colour scheme " + schemeName.getText() + " exists."
- + "\nContinue saving colour scheme as "
- + schemeName.getText() + "?",
- "Duplicate scheme name", JOptionPane.YES_NO_OPTION);
+ int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
+ MessageManager.formatMessage(
+ "label.colour_scheme_exists_overwrite", new Object[]
+ { schemeName.getText(), schemeName.getText() }),
+ MessageManager.getString("label.duplicate_scheme_name"),
+ JOptionPane.YES_NO_OPTION);
if (reply != JOptionPane.YES_OPTION)
{
return;
@@ -738,8 +778,8 @@ public class UserDefinedColours extends GUserDefinedColours implements
{ "Jalview User Colours" }, "Jalview User Colours");
chooser.setFileView(new jalview.io.JalviewFileView());
- chooser.setDialogTitle("Save colour scheme");
- chooser.setToolTipText("Save");
+ chooser.setDialogTitle(MessageManager.getString("label.save_colour_scheme"));
+ chooser.setToolTipText(MessageManager.getString("action.save"));
int value = chooser.showSaveDialog(this);
@@ -796,6 +836,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void cancelButton_actionPerformed(ActionEvent e)
{
if (ap != null)
@@ -925,17 +966,19 @@ public class UserDefinedColours extends GUserDefinedColours implements
}
+ @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
{
@@ -943,5 +986,4 @@ public class UserDefinedColours extends GUserDefinedColours implements
}
selectedButtons.add(lcaseColour);
}
-
}