2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
22 import java.awt.event.*;
24 import javax.swing.event.*;
26 import jalview.datamodel.*;
28 public class TextColourChooser
34 public void chooseColour(AlignmentPanel ap, SequenceGroup sg)
39 int original1, original2, originalThreshold;
42 original1 = ap.av.textColour.getRGB();
43 original2 = ap.av.textColour2.getRGB();
44 originalThreshold = ap.av.thresholdTextColour;
48 original1 = sg.textColour.getRGB();
49 original2 = sg.textColour2.getRGB();
50 originalThreshold = sg.thresholdTextColour;
53 final JSlider slider = new JSlider(0, 750, originalThreshold);
54 final JPanel col1 = new JPanel();
55 col1.setPreferredSize(new Dimension(40, 20));
56 col1.setBorder(BorderFactory.createEtchedBorder());
57 col1.setToolTipText("Dark Colour");
58 col1.setBackground(new Color(original1));
59 final JPanel col2 = new JPanel();
60 col2.setPreferredSize(new Dimension(40, 20));
61 col2.setBorder(BorderFactory.createEtchedBorder());
62 col2.setToolTipText("Light Colour");
63 col2.setBackground(new Color(original2));
64 final JPanel bigpanel = new JPanel(new BorderLayout());
65 JPanel panel = new JPanel();
66 bigpanel.add(panel, BorderLayout.CENTER);
69 "<html><i>Select a dark and light text colour, then set the threshold to"
70 + "<br>switch between colours, based on background colour</i></html>"),
76 col1.addMouseListener(new MouseAdapter()
78 public void mousePressed(MouseEvent e)
80 Color col = JColorChooser.showDialog(bigpanel,
81 "Select Colour for Text", col1.getBackground());
85 col1.setBackground(col);
90 col2.addMouseListener(new MouseAdapter()
92 public void mousePressed(MouseEvent e)
94 Color col = JColorChooser.showDialog(bigpanel,
95 "Select Colour for Text", col2.getBackground());
99 col2.setBackground(col);
104 slider.addChangeListener(new ChangeListener()
106 public void stateChanged(ChangeEvent evt)
108 thresholdChanged(slider.getValue());
112 int reply = JOptionPane.showInternalOptionDialog(ap, bigpanel,
113 "Adjust Foreground Text Colour Threshold",
114 JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
117 if (reply == JOptionPane.CANCEL_OPTION)
121 ap.av.textColour = new Color(original1);
122 ap.av.textColour2 = new Color(original2);
123 ap.av.thresholdTextColour = originalThreshold;
127 sg.textColour = new Color(original1);
128 sg.textColour2 = new Color(original2);
129 sg.thresholdTextColour = originalThreshold;
134 void colour1Changed(Color col)
138 ap.av.textColour = col;
139 if (ap.av.getColourAppliesToAllGroups())
141 setGroupTextColour();
149 ap.paintAlignment(true);
152 void colour2Changed(Color col)
156 ap.av.textColour2 = col;
157 if (ap.av.getColourAppliesToAllGroups())
159 setGroupTextColour();
164 sg.textColour2 = col;
167 ap.paintAlignment(true);
170 void thresholdChanged(int value)
174 ap.av.thresholdTextColour = value;
175 if (ap.av.getColourAppliesToAllGroups())
177 setGroupTextColour();
182 sg.thresholdTextColour = value;
185 ap.paintAlignment(true);
188 void setGroupTextColour()
190 if (ap.av.getAlignment().getGroups() == null)
195 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
197 sg.textColour = ap.av.textColour;
198 sg.textColour2 = ap.av.textColour2;
199 sg.thresholdTextColour = ap.av.thresholdTextColour;