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.util.MessageManager;
26 import java.awt.BorderLayout;
27 import java.awt.Color;
28 import java.awt.Dimension;
29 import java.awt.event.MouseAdapter;
30 import java.awt.event.MouseEvent;
32 import javax.swing.BorderFactory;
33 import javax.swing.JColorChooser;
34 import javax.swing.JLabel;
35 import javax.swing.JOptionPane;
36 import javax.swing.JPanel;
37 import javax.swing.JSlider;
38 import javax.swing.event.ChangeEvent;
39 import javax.swing.event.ChangeListener;
41 public class TextColourChooser
47 public void chooseColour(AlignmentPanel ap, SequenceGroup sg)
52 int original1, original2, originalThreshold;
55 original1 = ap.av.getTextColour().getRGB();
56 original2 = ap.av.getTextColour2().getRGB();
57 originalThreshold = ap.av.getThresholdTextColour();
61 original1 = sg.textColour.getRGB();
62 original2 = sg.textColour2.getRGB();
63 originalThreshold = sg.thresholdTextColour;
66 final JSlider slider = new JSlider(0, 750, originalThreshold);
67 final JPanel col1 = new JPanel();
68 col1.setPreferredSize(new Dimension(40, 20));
69 col1.setBorder(BorderFactory.createEtchedBorder());
70 col1.setToolTipText(MessageManager.getString("label.dark_colour"));
71 col1.setBackground(new Color(original1));
72 final JPanel col2 = new JPanel();
73 col2.setPreferredSize(new Dimension(40, 20));
74 col2.setBorder(BorderFactory.createEtchedBorder());
75 col2.setToolTipText(MessageManager.getString("label.ligth_colour"));
76 col2.setBackground(new Color(original2));
77 final JPanel bigpanel = new JPanel(new BorderLayout());
78 JPanel panel = new JPanel();
79 bigpanel.add(panel, BorderLayout.CENTER);
84 .getString("label.select_dark_light_set_thereshold")
85 + "</html>"), BorderLayout.NORTH);
90 col1.addMouseListener(new MouseAdapter()
92 public void mousePressed(MouseEvent e)
94 Color col = JColorChooser.showDialog(bigpanel,
95 MessageManager.getString("label.select_colour_for_text"),
96 col1.getBackground());
100 col1.setBackground(col);
105 col2.addMouseListener(new MouseAdapter()
107 public void mousePressed(MouseEvent e)
109 Color col = JColorChooser.showDialog(bigpanel,
110 MessageManager.getString("label.select_colour_for_text"),
111 col2.getBackground());
115 col2.setBackground(col);
120 slider.addChangeListener(new ChangeListener()
122 public void stateChanged(ChangeEvent evt)
124 thresholdChanged(slider.getValue());
128 int reply = JOptionPane
129 .showInternalOptionDialog(
133 .getString("label.adjunst_foreground_text_colour_thereshold"),
134 JOptionPane.OK_CANCEL_OPTION,
135 JOptionPane.QUESTION_MESSAGE, null, null, null);
137 if (reply == JOptionPane.CANCEL_OPTION)
141 ap.av.setTextColour(new Color(original1));
142 ap.av.setTextColour2(new Color(original2));
143 ap.av.setThresholdTextColour(originalThreshold);
147 sg.textColour = new Color(original1);
148 sg.textColour2 = new Color(original2);
149 sg.thresholdTextColour = originalThreshold;
154 void colour1Changed(Color col)
158 ap.av.setTextColour(col);
159 if (ap.av.getColourAppliesToAllGroups())
161 setGroupTextColour();
169 ap.paintAlignment(true);
172 void colour2Changed(Color col)
176 ap.av.setTextColour2(col);
177 if (ap.av.getColourAppliesToAllGroups())
179 setGroupTextColour();
184 sg.textColour2 = col;
187 ap.paintAlignment(true);
190 void thresholdChanged(int value)
194 ap.av.setThresholdTextColour(value);
195 if (ap.av.getColourAppliesToAllGroups())
197 setGroupTextColour();
202 sg.thresholdTextColour = value;
205 ap.paintAlignment(true);
208 void setGroupTextColour()
210 if (ap.av.getAlignment().getGroups() == null)
215 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
217 sg.textColour = ap.av.getTextColour();
218 sg.textColour2 = ap.av.getTextColour2();
219 sg.thresholdTextColour = ap.av.getThresholdTextColour();