2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.gui;
\r
25 import java.awt.event.*;
\r
26 import javax.swing.*;
\r
27 import javax.swing.event.*;
\r
29 import jalview.datamodel.*;
\r
31 public class TextColourChooser
\r
36 public void chooseColour(AlignmentPanel ap, SequenceGroup sg)
\r
41 int original1, original2, originalThreshold;
\r
44 original1 = ap.av.textColour.getRGB();
\r
45 original2 = ap.av.textColour2.getRGB();
\r
46 originalThreshold = ap.av.thresholdTextColour;
\r
50 original1 = sg.textColour.getRGB();
\r
51 original2 = sg.textColour2.getRGB();
\r
52 originalThreshold = sg.thresholdTextColour;
\r
55 final JSlider slider = new JSlider(0, 750, originalThreshold);
\r
56 final JPanel col1 = new JPanel();
\r
57 col1.setPreferredSize(new Dimension(40, 20));
\r
58 col1.setBorder(BorderFactory.createEtchedBorder());
\r
59 col1.setToolTipText("Dark Colour");
\r
60 col1.setBackground(new Color(original1));
\r
61 final JPanel col2 = new JPanel();
\r
62 col2.setPreferredSize(new Dimension(40, 20));
\r
63 col2.setBorder(BorderFactory.createEtchedBorder());
\r
64 col2.setToolTipText("Light Colour");
\r
65 col2.setBackground(new Color(original2));
\r
66 final JPanel bigpanel = new JPanel(new BorderLayout());
\r
67 JPanel panel = new JPanel();
\r
68 bigpanel.add(panel, BorderLayout.CENTER);
\r
69 bigpanel.add(new JLabel(
\r
70 "<html><i>Select a dark and light text colour, then set the threshold to"
\r
71 + "<br>switch between colours, based on background colour</i></html>"),
\r
72 BorderLayout.NORTH);
\r
77 col1.addMouseListener(new MouseAdapter()
\r
79 public void mousePressed(MouseEvent e)
\r
81 Color col = JColorChooser.showDialog(bigpanel,
\r
82 "Select Colour for Text",
\r
83 col1.getBackground());
\r
86 colour1Changed(col);
\r
87 col1.setBackground(col);
\r
92 col2.addMouseListener(new MouseAdapter()
\r
94 public void mousePressed(MouseEvent e)
\r
96 Color col = JColorChooser.showDialog(bigpanel,
\r
97 "Select Colour for Text",
\r
98 col2.getBackground());
\r
101 colour2Changed(col);
\r
102 col2.setBackground(col);
\r
107 slider.addChangeListener(new ChangeListener()
\r
109 public void stateChanged(ChangeEvent evt)
\r
111 thresholdChanged(slider.getValue());
\r
115 int reply = JOptionPane.showInternalOptionDialog(
\r
118 "Adjust Foreground Text Colour Threshold",
\r
119 JOptionPane.OK_CANCEL_OPTION,
\r
120 JOptionPane.QUESTION_MESSAGE,
\r
124 if (reply == JOptionPane.CANCEL_OPTION)
\r
128 ap.av.textColour = new Color(original1);
\r
129 ap.av.textColour2 = new Color(original2);
\r
130 ap.av.thresholdTextColour = originalThreshold;
\r
134 sg.textColour = new Color(original1);
\r
135 sg.textColour2 = new Color(original2);
\r
136 sg.thresholdTextColour = originalThreshold;
\r
141 void colour1Changed(Color col)
\r
145 ap.av.textColour = col;
\r
146 if (ap.av.colourAppliesToAllGroups)
\r
148 setGroupTextColour();
\r
153 sg.textColour = col;
\r
156 ap.paintAlignment(true);
\r
159 void colour2Changed(Color col)
\r
163 ap.av.textColour2 = col;
\r
164 if (ap.av.colourAppliesToAllGroups)
\r
166 setGroupTextColour();
\r
171 sg.textColour2 = col;
\r
174 ap.paintAlignment(true);
\r
177 void thresholdChanged(int value)
\r
181 ap.av.thresholdTextColour = value;
\r
182 if (ap.av.colourAppliesToAllGroups)
\r
184 setGroupTextColour();
\r
189 sg.thresholdTextColour = value;
\r
192 ap.paintAlignment(true);
\r
195 void setGroupTextColour()
\r
197 if (ap.av.alignment.getGroups() == null)
\r
202 Vector groups = ap.av.alignment.getGroups();
\r
204 for (int i = 0; i < groups.size(); i++)
\r
206 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
\r
207 sg.textColour = ap.av.textColour;
\r
208 sg.textColour2 = ap.av.textColour2;
\r
209 sg.thresholdTextColour = ap.av.thresholdTextColour;
\r