2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 import java.awt.event.*;
26 import javax.swing.event.*;
28 import jalview.datamodel.*;
30 public class TextColourChooser
35 public void chooseColour(AlignmentPanel ap, SequenceGroup sg)
40 int original1, original2, originalThreshold;
43 original1 = ap.av.textColour.getRGB();
44 original2 = ap.av.textColour2.getRGB();
45 originalThreshold = ap.av.thresholdTextColour;
49 original1 = sg.textColour.getRGB();
50 original2 = sg.textColour2.getRGB();
51 originalThreshold = sg.thresholdTextColour;
54 final JSlider slider = new JSlider(0, 750, originalThreshold);
55 final JPanel col1 = new JPanel();
56 col1.setPreferredSize(new Dimension(40, 20));
57 col1.setBorder(BorderFactory.createEtchedBorder());
58 col1.setToolTipText("Dark Colour");
59 col1.setBackground(new Color(original1));
60 final JPanel col2 = new JPanel();
61 col2.setPreferredSize(new Dimension(40, 20));
62 col2.setBorder(BorderFactory.createEtchedBorder());
63 col2.setToolTipText("Light Colour");
64 col2.setBackground(new Color(original2));
65 final JPanel bigpanel = new JPanel(new BorderLayout());
66 JPanel panel = new JPanel();
67 bigpanel.add(panel, BorderLayout.CENTER);
68 bigpanel.add(new JLabel(
69 "<html><i>Select a dark and light text colour, then set the threshold to"
70 + "<br>switch between colours, based on background colour</i></html>"),
76 col1.addMouseListener(new MouseAdapter()
78 public void mousePressed(MouseEvent e)
80 Color col = JColorChooser.showDialog(bigpanel,
81 "Select Colour for Text",
82 col1.getBackground());
86 col1.setBackground(col);
91 col2.addMouseListener(new MouseAdapter()
93 public void mousePressed(MouseEvent e)
95 Color col = JColorChooser.showDialog(bigpanel,
96 "Select Colour for Text",
97 col2.getBackground());
101 col2.setBackground(col);
106 slider.addChangeListener(new ChangeListener()
108 public void stateChanged(ChangeEvent evt)
110 thresholdChanged(slider.getValue());
114 int reply = JOptionPane.showInternalOptionDialog(
117 "Adjust Foreground Text Colour Threshold",
118 JOptionPane.OK_CANCEL_OPTION,
119 JOptionPane.QUESTION_MESSAGE,
123 if (reply == JOptionPane.CANCEL_OPTION)
127 ap.av.textColour = new Color(original1);
128 ap.av.textColour2 = new Color(original2);
129 ap.av.thresholdTextColour = originalThreshold;
133 sg.textColour = new Color(original1);
134 sg.textColour2 = new Color(original2);
135 sg.thresholdTextColour = originalThreshold;
140 void colour1Changed(Color col)
144 ap.av.textColour = col;
145 if (ap.av.colourAppliesToAllGroups)
147 setGroupTextColour();
155 ap.paintAlignment(true);
158 void colour2Changed(Color col)
162 ap.av.textColour2 = col;
163 if (ap.av.colourAppliesToAllGroups)
165 setGroupTextColour();
170 sg.textColour2 = col;
173 ap.paintAlignment(true);
176 void thresholdChanged(int value)
180 ap.av.thresholdTextColour = value;
181 if (ap.av.colourAppliesToAllGroups)
183 setGroupTextColour();
188 sg.thresholdTextColour = value;
191 ap.paintAlignment(true);
194 void setGroupTextColour()
196 if (ap.av.alignment.getGroups() == null)
201 Vector groups = ap.av.alignment.getGroups();
203 for (int i = 0; i < groups.size(); i++)
205 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
206 sg.textColour = ap.av.textColour;
207 sg.textColour2 = ap.av.textColour2;
208 sg.thresholdTextColour = ap.av.thresholdTextColour;