From b369b306448bbec72f29b33ebe2f654589845103 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 18 Sep 2014 09:31:00 +0100 Subject: [PATCH] JAL-1360 refactored utility method to ColorUtils class --- src/jalview/gui/UserDefinedColours.java | 39 +++++++------------------------ src/jalview/util/ColorUtils.java | 25 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index fec36e5..1f23338 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; @@ -255,7 +256,7 @@ AlignmentPanel ap; { button = (JButton) selectedButtons.elementAt(i); button.setBackground(newColour); - button.setForeground(brighterThan(newColour)); + button.setForeground(ColorUtils.brighterThan(newColour)); } if (button == lcaseColour) { @@ -263,7 +264,7 @@ AlignmentPanel ap; { button = (JButton) lowerCaseButtons.elementAt(i); button.setBackground(newColour); - button.setForeground(brighterThan(button.getBackground())); + button.setForeground(ColorUtils.brighterThan(button.getBackground())); } } } @@ -322,7 +323,7 @@ AlignmentPanel ap; JButton button = (JButton) buttonPanel.getComponent(b); if (!selectedButtons.contains(button)) { - button.setForeground(brighterThan(button.getBackground())); + button.setForeground(ColorUtils.brighterThan(button.getBackground())); selectedButtons.add(button); } } @@ -332,10 +333,10 @@ AlignmentPanel ap; for (int b = 0; b < selectedButtons.size(); b++) { JButton button = (JButton) selectedButtons.elementAt(b); - button.setForeground(darkerThan(button.getBackground())); + button.setForeground(ColorUtils.darkerThan(button.getBackground())); } selectedButtons.clear(); - pressed.setForeground(brighterThan(pressed.getBackground())); + pressed.setForeground(ColorUtils.brighterThan(pressed.getBackground())); selectedButtons.addElement(pressed); } @@ -343,12 +344,12 @@ AlignmentPanel ap; { if (selectedButtons.contains(pressed)) { - pressed.setForeground(darkerThan(pressed.getBackground())); + pressed.setForeground(ColorUtils.darkerThan(pressed.getBackground())); selectedButtons.remove(pressed); } else { - pressed.setForeground(brighterThan(pressed.getBackground())); + pressed.setForeground(ColorUtils.brighterThan(pressed.getBackground())); selectedButtons.addElement(pressed); } } @@ -416,35 +417,13 @@ AlignmentPanel ap; button.setOpaque(true); // required for the next line to have effect button.setBackground(col); button.setText(label); - button.setForeground(darkerThan(col)); + button.setForeground(ColorUtils.darkerThan(col)); button.setFont(new java.awt.Font("Verdana", Font.BOLD, 10)); return button; } /** - * Returns a colour three shades darker. - * - * We use darker text to indicate unselected buttons, lighter text for selected. - * @param col - * @return - */ - public static Color darkerThan(Color col) { - return col.darker().darker().darker(); - } - - /** - * Returns a colour three shades brighter. - * - * We use darker text to indicate unselected buttons, lighter text for selected. - * @param col - * @return - */ - public static Color brighterThan(Color col) { - return col.brighter().brighter().brighter(); - } - - /** * DOCUMENT ME! * * @param e diff --git a/src/jalview/util/ColorUtils.java b/src/jalview/util/ColorUtils.java index f108da1..0d726a2 100644 --- a/src/jalview/util/ColorUtils.java +++ b/src/jalview/util/ColorUtils.java @@ -59,4 +59,29 @@ public class ColorUtils } +/** + * Returns a colour three shades darker. + * + * We use darker text to indicate unselected buttons, lighter text for selected. Note you can't + * guarantee that darkerThan/brighterThan undo each other, as they may result in black/white. + * + * @param col + * @return + */ + public static Color darkerThan(Color col) { + return col.darker().darker().darker(); + } + +/** + * Returns a colour three shades brighter. + * + * We use darker text to indicate unselected buttons, lighter text for selected. Note you can't + * guarantee that darkerThan/brighterThan undo each other, as they may result in black/white. + * @param col + * @return + */ + public static Color brighterThan(Color col) { + return col.brighter().brighter().brighter(); + } + } -- 1.7.10.2