From: gmungoc Date: Thu, 18 Sep 2014 13:16:21 +0000 (+0100) Subject: Merge branch 'JAL-1360_Branch' into Release_2_8_2_Branch X-Git-Tag: Release_2_8_2b1^2~53 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=55fc8f004dac252b5b89ac91cf506e4844a6b1da;hp=2e77b309193604aed37d838e916ae6b454be3431;p=jalview.git Merge branch 'JAL-1360_Branch' into Release_2_8_2_Branch --- diff --git a/help/html/calculations/consensus.html b/help/html/calculations/consensus.html index 6df11da..bc42278 100644 --- a/help/html/calculations/consensus.html +++ b/help/html/calculations/consensus.html @@ -37,7 +37,7 @@ clipboard.

Sequence logo

By clicking on the label you can also activate the sequence logo. It indicates the relative amount of residues per column which can be - estimated by it's size in the logo. The tooltip of a column gives the + estimated by its size in the logo. The tooltip of a column gives the exact numbers for all occuring residues.
If columns of the alignment are very diverse, then it can sometimes be difficult to see the sequence logo - in this case, right diff --git a/help/html/calculations/structureconsensus.html b/help/html/calculations/structureconsensus.html index 097068d..6e797b1 100755 --- a/help/html/calculations/structureconsensus.html +++ b/help/html/calculations/structureconsensus.html @@ -40,7 +40,7 @@ similar to a sequence logo but counts the numbers of base pairs. There are two residues per column, the actual column and the interacting base. The opening bracket is always the one on the left side.
Like sequence logos the relative amount of a specific base pair can be -estimated by it's size in the logo. The tool tip of a column gives the +estimated by its size in the logo. The tool tip of a column gives the exact numbers for all occurring valid base pairs.

diff --git a/help/html/colourSchemes/abovePID.html b/help/html/colourSchemes/abovePID.html index e609972..74dd665 100755 --- a/help/html/colourSchemes/abovePID.html +++ b/help/html/colourSchemes/abovePID.html @@ -30,7 +30,7 @@ td { -

Colouring above a percentage identity threshold

+

Colouring above a percentage identity threshold

Selecting this option causes the colour scheme to be applied to only those residues that occur in that column more than a certain percentage of the time. For instance selecting the threshold to be 100 will only colour those columns diff --git a/help/html/colourSchemes/blosum.html b/help/html/colourSchemes/blosum.html index 6749d4e..338ca55 100755 --- a/help/html/colourSchemes/blosum.html +++ b/help/html/colourSchemes/blosum.html @@ -31,7 +31,7 @@ td { -

Blosum62

+

Blosum62

Gaps are coloured white. If a residue matches the consensus sequence residue at that position it is coloured dark blue. If it does not match the consensus residue but the 2 residues have a positive Blosum62 score, it is coloured light diff --git a/help/html/colourSchemes/buried.html b/help/html/colourSchemes/buried.html index 1373404..5943d36 100755 --- a/help/html/colourSchemes/buried.html +++ b/help/html/colourSchemes/buried.html @@ -30,7 +30,7 @@ td { -

Buried index

+

Buried index

diff --git a/help/html/colourSchemes/clustal.html b/help/html/colourSchemes/clustal.html index b95a348..33455dc 100755 --- a/help/html/colourSchemes/clustal.html +++ b/help/html/colourSchemes/clustal.html @@ -30,7 +30,7 @@ td { -

Clustal X Colour Scheme

+

Clustal X Colour Scheme

This is an emulation of the default colourscheme used for alignments in Clustal X, a graphical interface for the ClustalW multiple sequence alignment program. Each residue in the alignment is assigned a colour if the diff --git a/help/html/colourSchemes/conservation.html b/help/html/colourSchemes/conservation.html index 8866435..5ceba85 100755 --- a/help/html/colourSchemes/conservation.html +++ b/help/html/colourSchemes/conservation.html @@ -21,7 +21,7 @@ --> Colouring by Conservation -

Colouring by Conservation

+

Colouring by Conservation

This is an approach to alignment colouring which highlights regions of an alignment where physicochemical properties are conserved. It is based on the one used in diff --git a/help/html/colourSchemes/helix.html b/help/html/colourSchemes/helix.html index e4142c1..8c698c0 100755 --- a/help/html/colourSchemes/helix.html +++ b/help/html/colourSchemes/helix.html @@ -30,7 +30,7 @@ td { -

Helix Propensity

+

Helix Propensity

diff --git a/help/html/colourSchemes/hydrophobic.html b/help/html/colourSchemes/hydrophobic.html index 288a2d1..6b4cf2d 100755 --- a/help/html/colourSchemes/hydrophobic.html +++ b/help/html/colourSchemes/hydrophobic.html @@ -30,7 +30,7 @@ td { -

Hydrophobicity

+

Hydrophobicity

According to the hydrophobicity table of Kyte, J., and Doolittle, R.F., J. Mol. Biol. 1157, 105-132, 1982. The most hydrophobic residues according to this table are coloured red and the most hydrophilic ones are coloured blue.

diff --git a/help/html/colourSchemes/nucleotide.html b/help/html/colourSchemes/nucleotide.html index 601230b..065c818 100755 --- a/help/html/colourSchemes/nucleotide.html +++ b/help/html/colourSchemes/nucleotide.html @@ -30,7 +30,7 @@ td { -

Nucleotide Colours

+

Nucleotide Colours

diff --git a/help/html/colourSchemes/pid.html b/help/html/colourSchemes/pid.html index f90fde9..47b992a 100755 --- a/help/html/colourSchemes/pid.html +++ b/help/html/colourSchemes/pid.html @@ -30,7 +30,7 @@ td { -

PID Colours
+

PID Colours

The PID option colours the residues (boxes and/or text) according to the percentage of the residues in each column that agree with the consensus sequence. Only diff --git a/help/html/colourSchemes/purinepyrimidine.html b/help/html/colourSchemes/purinepyrimidine.html index 6655392..4337d48 100644 --- a/help/html/colourSchemes/purinepyrimidine.html +++ b/help/html/colourSchemes/purinepyrimidine.html @@ -30,7 +30,7 @@ td { -

Purine/Pyrimidine Colours

+

Purine/Pyrimidine Colours

diff --git a/help/html/colourSchemes/strand.html b/help/html/colourSchemes/strand.html index a653c8e..fe7c469 100755 --- a/help/html/colourSchemes/strand.html +++ b/help/html/colourSchemes/strand.html @@ -30,7 +30,7 @@ td { -

Strand propensity

+

Strand propensity

diff --git a/help/html/colourSchemes/taylor.html b/help/html/colourSchemes/taylor.html index 268915d..a5c4f05 100755 --- a/help/html/colourSchemes/taylor.html +++ b/help/html/colourSchemes/taylor.html @@ -30,7 +30,7 @@ td { -

Taylor

+

Taylor

These colours were invented by Willie Taylor and an entertaining description of their birth can be found in Protein Engineering, Vol 10 , 743-746 (1997)

diff --git a/help/html/colourSchemes/turn.html b/help/html/colourSchemes/turn.html index ec65d6f..87dbe37 100755 --- a/help/html/colourSchemes/turn.html +++ b/help/html/colourSchemes/turn.html @@ -30,7 +30,7 @@ td { -

Turn propensity

+

Turn propensity

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)); + } +}