diff --git a/help/html/colourSchemes/user.html b/help/html/colourSchemes/user.html
index 5774306..5eacca9 100755
--- a/help/html/colourSchemes/user.html
+++ b/help/html/colourSchemes/user.html
@@ -21,22 +21,31 @@
-->
User Defined Colours
-User Defined Colours
-
+User Defined Colours
+
You may define any number of new colour schemes, each with a unique name.
- Each of the residues in a new colour scheme may be assigned a new user defined
- colour.
-
- Click "Apply" or "OK" to set your new colours on the active
- alignment window.
-Click "Cancel" to undo your changes if you pressed the "Apply"
- button.
-
- If you save your colour scheme with a unique name the colour scheme name will
- be added to the "Colour" menu on each new alignment window.
+ Each of the residues in a colour scheme may be assigned any chosen colour.
+ Select one or more residues, then select the desired colour.
+ Use Ctrl-click to select multiple residues, or click then Shift-click to select a block.
+ Note that the currently selected buttons are highlighted by a lighter text colour.
+
+ The Case Sensitive option allows you to choose distinct colours for upper and
+ lower case residue codes.
+
+ Click Apply or OK to set your new colours on the active
+ alignment window.
+ Click Cancel to undo your changes if you pressed the Apply
+ button.
+
+ If you save your colour scheme with a unique name, the colour scheme name will
+ be added to the Colour menu on each new alignment window.
Any saved colour schemes will be automatically loaded the next time you use
- Jalview.
+ Jalview.
+
+ Note: the screenshot shows the appearance when running Java version 6. For Java 7 (from Jalview 2.8.2) only the Swatches colour chooser is
+ currently supported (for reasons of available screen space).
+
diff --git a/help/html/colourSchemes/userDefined_java6.gif b/help/html/colourSchemes/userDefined_java6.gif
new file mode 100644
index 0000000..d737e80
Binary files /dev/null and b/help/html/colourSchemes/userDefined_java6.gif differ
diff --git a/help/html/colourSchemes/userDefined_java7.gif b/help/html/colourSchemes/userDefined_java7.gif
new file mode 100644
index 0000000..f0ced11
Binary files /dev/null and b/help/html/colourSchemes/userDefined_java7.gif differ
diff --git a/help/html/colourSchemes/zappo.html b/help/html/colourSchemes/zappo.html
index 01d2b37..db025c0 100755
--- a/help/html/colourSchemes/zappo.html
+++ b/help/html/colourSchemes/zappo.html
@@ -30,7 +30,7 @@ td {
-Zappo Colours
+
Zappo Colours
The residues are coloured according to their physicochemical properties as
follows:
diff --git a/help/html/features/groovy.html b/help/html/features/groovy.html
index 4185cc7..6559fd1 100644
--- a/help/html/features/groovy.html
+++ b/help/html/features/groovy.html
@@ -44,7 +44,7 @@
The jars are obtained from the embedded directory within the
groovy
distribution. The easiest way of adding them to the Jalview classpath
- is to download and build jalview from it's source distribution, and
+ is to download and build jalview from its source distribution, and
then add the groovy-all-*.jar to the lib directory whose path is given
in the java.ext.dirs property.
diff --git a/help/html/webServices/dbreffetcher.html b/help/html/webServices/dbreffetcher.html
index 382991b..ad42153 100644
--- a/help/html/webServices/dbreffetcher.html
+++ b/help/html/webServices/dbreffetcher.html
@@ -45,7 +45,7 @@ of ID queries from the ID string of each sequence in the alignment. It
then tries to query a subset of all the databases it can access in order to match
the alignment sequence to any records retrieved from the database. If a
match is found, then the sequence is annotated with that database's
-reference, and any cross-references that it's records contain.
+reference, and any cross-references that its records contain.
The Sequence Identification Process
The method of accession id discovery is derived from the method which
earlier Jalview versions used for Uniprot sequence feature retrieval,
diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java
index f719d27..43c648e 100755
--- a/src/jalview/gui/UserDefinedColours.java
+++ b/src/jalview/gui/UserDefinedColours.java
@@ -27,6 +27,7 @@ import jalview.jbgui.GUserDefinedColours;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ResidueProperties;
import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
import jalview.util.MessageManager;
import java.awt.Color;
@@ -39,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;
@@ -50,19 +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;
SequenceGroup seqGroup;
- Vector selectedButtons;
+ ArrayList selectedButtons;
ColourSchemeI oldColourScheme;
@@ -70,9 +78,9 @@ public class UserDefinedColours extends GUserDefinedColours implements
JalviewStructureDisplayI jmol;
- Vector upperCaseButtons;
+ ArrayList upperCaseButtons;
- Vector lowerCaseButtons;
+ ArrayList lowerCaseButtons;
/**
* Creates a new UserDefinedColours object.
@@ -122,7 +130,8 @@ public class UserDefinedColours extends GUserDefinedColours implements
showFrame();
}
- public UserDefinedColours(JalviewStructureDisplayI jmol, ColourSchemeI oldcs)
+ public UserDefinedColours(JalviewStructureDisplayI jmol,
+ ColourSchemeI oldcs)
{
super();
this.jmol = jmol;
@@ -148,18 +157,13 @@ public class UserDefinedColours extends GUserDefinedColours implements
frame = new JInternalFrame();
frame.setContentPane(this);
Desktop.addInternalFrame(frame,
- MessageManager.getString("label.user_defined_colours"), 720,
- 370, true);
+ MessageManager.getString("label.user_defined_colours"),
+ MY_FRAME_WIDTH, MY_FRAME_HEIGHT, true);
if (seqGroup != null)
{
frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
}
-
- if (new jalview.util.Platform().isAMac())
- {
- frame.setSize(760, 370);
- }
}
void resetButtonPanel(boolean caseSensitive)
@@ -168,7 +172,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
if (upperCaseButtons == null)
{
- upperCaseButtons = new Vector();
+ upperCaseButtons = new ArrayList();
}
JButton button;
@@ -209,7 +213,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
if (lowerCaseButtons == null)
{
- lowerCaseButtons = new Vector();
+ lowerCaseButtons = new ArrayList();
}
for (int i = 0; i < 20; i++)
@@ -230,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();
}
@@ -240,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();
@@ -285,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
{
@@ -318,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);
}
}
@@ -327,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());
}
}
@@ -364,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
@@ -380,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)
@@ -409,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;
@@ -423,6 +451,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void okButton_actionPerformed(ActionEvent e)
{
applyButton_actionPerformed(null);
@@ -441,6 +470,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void applyButton_actionPerformed(ActionEvent e)
{
UserColourScheme ucs = getSchemeFromButtons();
@@ -468,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();
}
@@ -479,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);
@@ -499,10 +529,11 @@ 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[]
@@ -540,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]);
}
@@ -554,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]);
}
@@ -679,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()];
@@ -713,6 +744,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void savebutton_actionPerformed(ActionEvent e)
{
if (schemeName.getText().trim().length() < 1)
@@ -729,7 +761,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
{
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);
@@ -804,6 +836,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
* @param e
* DOCUMENT ME!
*/
+ @Override
protected void cancelButton_actionPerformed(ActionEvent e)
{
if (ap != null)
@@ -933,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
{
@@ -951,5 +986,4 @@ public class UserDefinedColours extends GUserDefinedColours implements
}
selectedButtons.add(lcaseColour);
}
-
}
diff --git a/src/jalview/jbgui/GUserDefinedColours.java b/src/jalview/jbgui/GUserDefinedColours.java
index 1cc1f11..7a485fd 100755
--- a/src/jalview/jbgui/GUserDefinedColours.java
+++ b/src/jalview/jbgui/GUserDefinedColours.java
@@ -25,7 +25,9 @@ import jalview.util.MessageManager;
import java.awt.*;
import java.awt.event.*;
+
import javax.swing.*;
+import javax.swing.colorchooser.AbstractColorChooserPanel;
/**
* DOCUMENT ME!
@@ -227,6 +229,13 @@ public class GUserDefinedColours extends JPanel
jPanel4.add(panel1, java.awt.BorderLayout.CENTER);
this.add(jPanel4, java.awt.BorderLayout.CENTER);
this.add(colorChooser, java.awt.BorderLayout.EAST);
+
+ AbstractColorChooserPanel[] choosers = colorChooser.getChooserPanels();
+ // JAL-1360 larger JColorChooser in Java 7 overwrites AA panel; restrict to swatch picker only
+ if (choosers.length > 3) {
+ // Java 7 default has 5 options rather than 3 for choosing colours; keep the first only
+ colorChooser.setChooserPanels(new AbstractColorChooserPanel[]{choosers[0]});
+ }
}
/**
diff --git a/src/jalview/util/ColorUtils.java b/src/jalview/util/ColorUtils.java
index f108da1..fd76086 100644
--- a/src/jalview/util/ColorUtils.java
+++ b/src/jalview/util/ColorUtils.java
@@ -59,4 +59,28 @@ public class ColorUtils
}
+ /**
+ * Returns a colour three shades darker. Note you can't guarantee that
+ * brighterThan reverses this, as darkerThan may result in black.
+ *
+ * @param col
+ * @return
+ */
+ public static Color darkerThan(Color col)
+ {
+ return col == null ? null : col.darker().darker().darker();
+ }
+
+ /**
+ * Returns a colour three shades brighter. Note you can't guarantee that
+ * darkerThan reverses this, as brighterThan may result in white.
+ *
+ * @param col
+ * @return
+ */
+ public static Color brighterThan(Color col)
+ {
+ return col == null ? null : col.brighter().brighter().brighter();
+ }
+
}
diff --git a/test/jalview/util/ColorUtilsTest.java b/test/jalview/util/ColorUtilsTest.java
new file mode 100644
index 0000000..da2e6ca
--- /dev/null
+++ b/test/jalview/util/ColorUtilsTest.java
@@ -0,0 +1,42 @@
+package jalview.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.awt.Color;
+
+import org.junit.Test;
+
+public class ColorUtilsTest
+{
+
+ Color paleColour = new Color(97, 203, 111); // pale green
+
+ Color midColour = new Color(135, 57, 41); // mid red
+
+ Color darkColour = new Color(11, 30, 50); // dark blue
+
+ @Test
+ public void testDarkerThan()
+ {
+ assertEquals("Wrong darker shade", new Color(32, 69, 37),
+ ColorUtils.darkerThan(paleColour));
+ assertEquals("Wrong darker shade", new Color(45, 18, 13),
+ ColorUtils.darkerThan(midColour));
+ assertEquals("Wrong darker shade", new Color(2, 9, 16),
+ ColorUtils.darkerThan(darkColour));
+ assertNull(ColorUtils.darkerThan(null));
+ }
+
+ @Test
+ public void testBrighterThan()
+ {
+ assertEquals("Wrong brighter shade", new Color(255, 255, 255), // white
+ ColorUtils.brighterThan(paleColour));
+ assertEquals("Wrong brighter shade", new Color(255, 164, 117),
+ ColorUtils.brighterThan(midColour));
+ assertEquals("Wrong brighter shade", new Color(30, 85, 144),
+ ColorUtils.brighterThan(darkColour));
+ assertNull(ColorUtils.brighterThan(null));
+ }
+}