From 184c6c3769f287e95f2177809d07e271398d2374 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 17 Sep 2014 13:42:25 +0100 Subject: [PATCH] JAL-1360 refactored for consistent lighter/darker for selected/unselected button foreground --- src/jalview/gui/UserDefinedColours.java | 42 +++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index 50108e7..3c87e4c 100755 --- a/src/jalview/gui/UserDefinedColours.java +++ b/src/jalview/gui/UserDefinedColours.java @@ -250,12 +250,11 @@ AlignmentPanel ap; if (selectedButtons != null) { JButton button = null; - for (int i = 0; i < selectedButtons.size(); i++) + 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.setForeground(brighterThan(button.getBackground())); } if (button == lcaseColour) { @@ -263,8 +262,7 @@ AlignmentPanel ap; { button = (JButton) lowerCaseButtons.elementAt(i); button.setBackground(colorChooser.getColor()); - button.setForeground(button.getBackground().brighter().brighter() - .brighter()); + button.setForeground(brighterThan(button.getBackground())); } } } @@ -323,7 +321,7 @@ AlignmentPanel ap; JButton button = (JButton) buttonPanel.getComponent(b); if (!selectedButtons.contains(button)) { - button.setForeground(button.getBackground().brighter().brighter()); + button.setForeground(brighterThan(button.getBackground())); selectedButtons.add(button); } } @@ -333,10 +331,10 @@ AlignmentPanel ap; for (int b = 0; b < selectedButtons.size(); b++) { JButton button = (JButton) selectedButtons.elementAt(b); - button.setForeground(button.getBackground().darker().darker()); + button.setForeground(darkerThan(button.getBackground())); } selectedButtons.clear(); - pressed.setForeground(pressed.getBackground().brighter().brighter()); + pressed.setForeground(brighterThan(pressed.getBackground())); selectedButtons.addElement(pressed); } @@ -344,12 +342,12 @@ AlignmentPanel ap; { if (selectedButtons.contains(pressed)) { - pressed.setForeground(pressed.getBackground().darker().darker()); + pressed.setForeground(darkerThan(pressed.getBackground())); selectedButtons.remove(pressed); } else { - pressed.setForeground(pressed.getBackground().brighter().brighter()); + pressed.setForeground(brighterThan(pressed.getBackground())); selectedButtons.addElement(pressed); } } @@ -417,13 +415,35 @@ AlignmentPanel ap; 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(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 -- 1.7.10.2