2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
22 import java.awt.BorderLayout;
\r
23 import java.awt.event.MouseAdapter;
\r
24 import javax.swing.JOptionPane;
\r
25 import jalview.datamodel.SequenceGroup;
\r
26 import javax.swing.BorderFactory;
\r
27 import javax.swing.JColorChooser;
\r
28 import javax.swing.JPanel;
\r
29 import javax.swing.event.ChangeEvent;
\r
30 import java.awt.Color;
\r
31 import java.awt.event.MouseEvent;
\r
32 import java.awt.Dimension;
\r
33 import javax.swing.JSlider;
\r
34 import javax.swing.event.ChangeListener;
\r
35 import javax.swing.JLabel;
\r
36 import java.util.Vector;
\r
38 public class TextColourChooser
\r
43 public void chooseColour(AlignmentPanel ap, SequenceGroup sg )
\r
48 int original1,original2, originalThreshold;
\r
51 original1 = ap.av.textColour.getRGB();
\r
52 original2 = ap.av.textColour2.getRGB();
\r
53 originalThreshold = ap.av.thresholdTextColour;
\r
57 original1 = sg.textColour.getRGB();
\r
58 original2 = sg.textColour2.getRGB();
\r
59 originalThreshold = sg.thresholdTextColour;
\r
62 final JSlider slider = new JSlider(0, 750, originalThreshold);
\r
63 final JPanel col1 = new JPanel();
\r
64 col1.setPreferredSize(new Dimension(40, 20));
\r
65 col1.setBorder(BorderFactory.createEtchedBorder());
\r
66 col1.setToolTipText("Dark Colour");
\r
67 col1.setBackground(new Color(original1));
\r
68 final JPanel col2 = new JPanel();
\r
69 col2.setPreferredSize(new Dimension(40, 20));
\r
70 col2.setBorder(BorderFactory.createEtchedBorder());
\r
71 col2.setToolTipText("Light Colour");
\r
72 col2.setBackground(new Color(original2));
\r
73 final JPanel bigpanel = new JPanel(new BorderLayout());
\r
74 JPanel panel = new JPanel();
\r
75 bigpanel.add(panel, BorderLayout.CENTER);
\r
76 bigpanel.add(new JLabel(
\r
77 "<html><i>Select a dark and light text colour, then set the threshold to"
\r
78 + "<br>switch between colours, based on background colour</i></html>"),
\r
79 BorderLayout.NORTH);
\r
84 col1.addMouseListener(new MouseAdapter()
\r
86 public void mousePressed(MouseEvent e)
\r
88 Color col = JColorChooser.showDialog(bigpanel,
\r
89 "Select Colour for Text",
\r
90 col1.getBackground());
\r
93 colour1Changed(col);
\r
94 col1.setBackground(col);
\r
99 col2.addMouseListener(new MouseAdapter()
\r
101 public void mousePressed(MouseEvent e)
\r
103 Color col = JColorChooser.showDialog(bigpanel,
\r
104 "Select Colour for Text",
\r
105 col2.getBackground());
\r
108 colour2Changed(col);
\r
109 col2.setBackground(col);
\r
114 slider.addChangeListener(new ChangeListener()
\r
116 public void stateChanged(ChangeEvent evt)
\r
118 thresholdChanged(slider.getValue());
\r
122 int reply = JOptionPane.showInternalOptionDialog(
\r
125 "Adjust Foreground Text Colour Threshold",
\r
126 JOptionPane.OK_CANCEL_OPTION,
\r
127 JOptionPane.QUESTION_MESSAGE,
\r
131 if (reply == JOptionPane.CANCEL_OPTION)
\r
135 ap.av.textColour = new Color(original1);
\r
136 ap.av.textColour2 = new Color(original2);
\r
137 ap.av.thresholdTextColour = originalThreshold;
\r
141 sg.textColour = new Color(original1);
\r
142 sg.textColour2 = new Color(original2);
\r
143 sg.thresholdTextColour = originalThreshold;
\r
148 void colour1Changed(Color col)
\r
152 ap.av.textColour = col;
\r
153 if (ap.av.colourAppliesToAllGroups)
\r
154 setGroupTextColour();
\r
157 sg.textColour = col;
\r
162 void colour2Changed(Color col)
\r
166 ap.av.textColour2 = col;
\r
167 if (ap.av.colourAppliesToAllGroups)
\r
168 setGroupTextColour();
\r
171 sg.textColour2 = col;
\r
176 void thresholdChanged(int value)
\r
180 ap.av.thresholdTextColour = value;
\r
181 if (ap.av.colourAppliesToAllGroups)
\r
182 setGroupTextColour();
\r
185 sg.thresholdTextColour = value;
\r
192 void setGroupTextColour()
\r
194 if (ap.av.alignment.getGroups() == null)
\r
197 Vector groups = ap.av.alignment.getGroups();
\r
199 for (int i = 0; i < groups.size(); i++)
\r
201 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
\r
202 sg.textColour = ap.av.textColour;
\r
203 sg.textColour2 = ap.av.textColour2;
\r
204 sg.thresholdTextColour = ap.av.thresholdTextColour;
\r