2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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/>.
21 import java.awt.event.*;
23 import javax.swing.event.*;
25 import jalview.datamodel.*;
27 public class TextColourChooser
33 public void chooseColour(AlignmentPanel ap, SequenceGroup sg)
38 int original1, original2, originalThreshold;
41 original1 = ap.av.textColour.getRGB();
42 original2 = ap.av.textColour2.getRGB();
43 originalThreshold = ap.av.thresholdTextColour;
47 original1 = sg.textColour.getRGB();
48 original2 = sg.textColour2.getRGB();
49 originalThreshold = sg.thresholdTextColour;
52 final JSlider slider = new JSlider(0, 750, originalThreshold);
53 final JPanel col1 = new JPanel();
54 col1.setPreferredSize(new Dimension(40, 20));
55 col1.setBorder(BorderFactory.createEtchedBorder());
56 col1.setToolTipText("Dark Colour");
57 col1.setBackground(new Color(original1));
58 final JPanel col2 = new JPanel();
59 col2.setPreferredSize(new Dimension(40, 20));
60 col2.setBorder(BorderFactory.createEtchedBorder());
61 col2.setToolTipText("Light Colour");
62 col2.setBackground(new Color(original2));
63 final JPanel bigpanel = new JPanel(new BorderLayout());
64 JPanel panel = new JPanel();
65 bigpanel.add(panel, BorderLayout.CENTER);
68 "<html><i>Select a dark and light text colour, then set the threshold to"
69 + "<br>switch between colours, based on background colour</i></html>"),
75 col1.addMouseListener(new MouseAdapter()
77 public void mousePressed(MouseEvent e)
79 Color col = JColorChooser.showDialog(bigpanel,
80 "Select Colour for Text", col1.getBackground());
84 col1.setBackground(col);
89 col2.addMouseListener(new MouseAdapter()
91 public void mousePressed(MouseEvent e)
93 Color col = JColorChooser.showDialog(bigpanel,
94 "Select Colour for Text", col2.getBackground());
98 col2.setBackground(col);
103 slider.addChangeListener(new ChangeListener()
105 public void stateChanged(ChangeEvent evt)
107 thresholdChanged(slider.getValue());
111 int reply = JOptionPane.showInternalOptionDialog(ap, bigpanel,
112 "Adjust Foreground Text Colour Threshold",
113 JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
116 if (reply == JOptionPane.CANCEL_OPTION)
120 ap.av.textColour = new Color(original1);
121 ap.av.textColour2 = new Color(original2);
122 ap.av.thresholdTextColour = originalThreshold;
126 sg.textColour = new Color(original1);
127 sg.textColour2 = new Color(original2);
128 sg.thresholdTextColour = originalThreshold;
133 void colour1Changed(Color col)
137 ap.av.textColour = col;
138 if (ap.av.getColourAppliesToAllGroups())
140 setGroupTextColour();
148 ap.paintAlignment(true);
151 void colour2Changed(Color col)
155 ap.av.textColour2 = col;
156 if (ap.av.getColourAppliesToAllGroups())
158 setGroupTextColour();
163 sg.textColour2 = col;
166 ap.paintAlignment(true);
169 void thresholdChanged(int value)
173 ap.av.thresholdTextColour = value;
174 if (ap.av.getColourAppliesToAllGroups())
176 setGroupTextColour();
181 sg.thresholdTextColour = value;
184 ap.paintAlignment(true);
187 void setGroupTextColour()
189 if (ap.av.getAlignment().getGroups() == null)
194 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
196 sg.textColour = ap.av.textColour;
197 sg.textColour2 = ap.av.textColour2;
198 sg.thresholdTextColour = ap.av.thresholdTextColour;