2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.datamodel.SequenceGroup;
24 import jalview.schemes.Colour;
25 import jalview.util.MessageManager;
27 import java.awt.BorderLayout;
28 import java.awt.Color;
29 import java.awt.Dimension;
30 import java.awt.event.MouseAdapter;
31 import java.awt.event.MouseEvent;
33 import javax.swing.BorderFactory;
34 import javax.swing.JColorChooser;
35 import javax.swing.JLabel;
36 import javax.swing.JOptionPane;
37 import javax.swing.JPanel;
38 import javax.swing.JSlider;
39 import javax.swing.event.ChangeEvent;
40 import javax.swing.event.ChangeListener;
42 public class TextColourChooser
48 public void chooseColour(AlignmentPanel ap, SequenceGroup sg)
53 int original1, original2, originalThreshold;
56 original1 = ap.av.getTextColour().getRGB();
57 original2 = ap.av.getTextColour2().getRGB();
58 originalThreshold = ap.av.getThresholdTextColour();
62 original1 = sg.textColour.getRGB();
63 original2 = sg.textColour2.getRGB();
64 originalThreshold = sg.thresholdTextColour;
67 final JSlider slider = new JSlider(0, 750, originalThreshold);
68 final JPanel col1 = new JPanel();
69 col1.setPreferredSize(new Dimension(40, 20));
70 col1.setBorder(BorderFactory.createEtchedBorder());
71 col1.setToolTipText(MessageManager.getString("label.dark_colour"));
72 col1.setBackground(new Color(original1));
73 final JPanel col2 = new JPanel();
74 col2.setPreferredSize(new Dimension(40, 20));
75 col2.setBorder(BorderFactory.createEtchedBorder());
76 col2.setToolTipText(MessageManager.getString("label.ligth_colour"));
77 col2.setBackground(new Color(original2));
78 final JPanel bigpanel = new JPanel(new BorderLayout());
79 JPanel panel = new JPanel();
80 bigpanel.add(panel, BorderLayout.CENTER);
85 .getString("label.select_dark_light_set_thereshold")
86 + "</html>"), BorderLayout.NORTH);
91 col1.addMouseListener(new MouseAdapter()
94 public void mousePressed(MouseEvent e)
96 Color col = JColorChooser.showDialog(bigpanel,
97 MessageManager.getString("label.select_colour_for_text"),
98 col1.getBackground());
102 col1.setBackground(col);
107 col2.addMouseListener(new MouseAdapter()
110 public void mousePressed(MouseEvent e)
112 Color col = JColorChooser.showDialog(bigpanel,
113 MessageManager.getString("label.select_colour_for_text"),
114 col2.getBackground());
118 col2.setBackground(col);
123 slider.addChangeListener(new ChangeListener()
126 public void stateChanged(ChangeEvent evt)
128 thresholdChanged(slider.getValue());
132 int reply = JOptionPane
133 .showInternalOptionDialog(
137 .getString("label.adjunst_foreground_text_colour_thereshold"),
138 JOptionPane.OK_CANCEL_OPTION,
139 JOptionPane.QUESTION_MESSAGE, null, null, null);
141 if (reply == JOptionPane.CANCEL_OPTION)
145 ap.av.setTextColour(new Colour(original1));
146 ap.av.setTextColour2(new Colour(original2));
147 ap.av.setThresholdTextColour(originalThreshold);
151 sg.textColour = new Colour(original1);
152 sg.textColour2 = new Colour(original2);
153 sg.thresholdTextColour = originalThreshold;
158 void colour1Changed(Color col)
162 ap.av.setTextColour(new Colour(col));
163 if (ap.av.getColourAppliesToAllGroups())
165 setGroupTextColour();
170 sg.textColour = new Colour(col);
173 ap.paintAlignment(true);
176 void colour2Changed(Color col)
180 ap.av.setTextColour2(new Colour(col));
181 if (ap.av.getColourAppliesToAllGroups())
183 setGroupTextColour();
188 sg.textColour2 = new Colour(col);
191 ap.paintAlignment(true);
194 void thresholdChanged(int value)
198 ap.av.setThresholdTextColour(value);
199 if (ap.av.getColourAppliesToAllGroups())
201 setGroupTextColour();
206 sg.thresholdTextColour = value;
209 ap.paintAlignment(true);
212 void setGroupTextColour()
214 if (ap.av.getAlignment().getGroups() == null)
219 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
221 sg.textColour = ap.av.getTextColour();
222 sg.textColour2 = ap.av.getTextColour2();
223 sg.thresholdTextColour = ap.av.getThresholdTextColour();