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.*;
27 import jalview.util.MessageManager;
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(MessageManager.getString("label.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(MessageManager.getString("label.ligth_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);
70 "<html><i>Select a dark and light text colour, then set the threshold to"
71 + "<br>switch between colours, based on background colour</i></html>"),
77 col1.addMouseListener(new MouseAdapter()
79 public void mousePressed(MouseEvent e)
81 Color col = JColorChooser.showDialog(bigpanel,
82 "Select Colour for Text", col1.getBackground());
86 col1.setBackground(col);
91 col2.addMouseListener(new MouseAdapter()
93 public void mousePressed(MouseEvent e)
95 Color col = JColorChooser.showDialog(bigpanel,
96 "Select Colour for Text", col2.getBackground());
100 col2.setBackground(col);
105 slider.addChangeListener(new ChangeListener()
107 public void stateChanged(ChangeEvent evt)
109 thresholdChanged(slider.getValue());
113 int reply = JOptionPane.showInternalOptionDialog(ap, bigpanel,
114 "Adjust Foreground Text Colour Threshold",
115 JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
118 if (reply == JOptionPane.CANCEL_OPTION)
122 ap.av.textColour = new Color(original1);
123 ap.av.textColour2 = new Color(original2);
124 ap.av.thresholdTextColour = originalThreshold;
128 sg.textColour = new Color(original1);
129 sg.textColour2 = new Color(original2);
130 sg.thresholdTextColour = originalThreshold;
135 void colour1Changed(Color col)
139 ap.av.textColour = col;
140 if (ap.av.getColourAppliesToAllGroups())
142 setGroupTextColour();
150 ap.paintAlignment(true);
153 void colour2Changed(Color col)
157 ap.av.textColour2 = col;
158 if (ap.av.getColourAppliesToAllGroups())
160 setGroupTextColour();
165 sg.textColour2 = col;
168 ap.paintAlignment(true);
171 void thresholdChanged(int value)
175 ap.av.thresholdTextColour = value;
176 if (ap.av.getColourAppliesToAllGroups())
178 setGroupTextColour();
183 sg.thresholdTextColour = value;
186 ap.paintAlignment(true);
189 void setGroupTextColour()
191 if (ap.av.getAlignment().getGroups() == null)
196 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
198 sg.textColour = ap.av.textColour;
199 sg.textColour2 = ap.av.textColour2;
200 sg.thresholdTextColour = ap.av.thresholdTextColour;