2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
23 import java.awt.event.*;
25 import javax.swing.event.*;
27 import jalview.datamodel.*;
29 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);
71 "<html><i>Select a dark and light text colour, then set the threshold to"
72 + "<br>switch between colours, based on background colour</i></html>"),
78 col1.addMouseListener(new MouseAdapter()
80 public void mousePressed(MouseEvent e)
82 Color col = JColorChooser.showDialog(bigpanel,
83 "Select Colour for Text", col1.getBackground());
87 col1.setBackground(col);
92 col2.addMouseListener(new MouseAdapter()
94 public void mousePressed(MouseEvent e)
96 Color col = JColorChooser.showDialog(bigpanel,
97 "Select Colour for Text", 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(ap, bigpanel,
115 "Adjust Foreground Text Colour Threshold",
116 JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
119 if (reply == JOptionPane.CANCEL_OPTION)
123 ap.av.textColour = new Color(original1);
124 ap.av.textColour2 = new Color(original2);
125 ap.av.thresholdTextColour = originalThreshold;
129 sg.textColour = new Color(original1);
130 sg.textColour2 = new Color(original2);
131 sg.thresholdTextColour = originalThreshold;
136 void colour1Changed(Color col)
140 ap.av.textColour = col;
141 if (ap.av.colourAppliesToAllGroups)
143 setGroupTextColour();
151 ap.paintAlignment(true);
154 void colour2Changed(Color col)
158 ap.av.textColour2 = col;
159 if (ap.av.colourAppliesToAllGroups)
161 setGroupTextColour();
166 sg.textColour2 = col;
169 ap.paintAlignment(true);
172 void thresholdChanged(int value)
176 ap.av.thresholdTextColour = value;
177 if (ap.av.colourAppliesToAllGroups)
179 setGroupTextColour();
184 sg.thresholdTextColour = value;
187 ap.paintAlignment(true);
190 void setGroupTextColour()
192 if (ap.av.alignment.getGroups() == null)
197 Vector groups = ap.av.alignment.getGroups();
199 for (int i = 0; i < groups.size(); i++)
201 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
202 sg.textColour = ap.av.textColour;
203 sg.textColour2 = ap.av.textColour2;
204 sg.thresholdTextColour = ap.av.thresholdTextColour;