2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
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.
24 import java.awt.event.*;
26 import javax.swing.event.*;
28 import jalview.datamodel.*;
29 import jalview.util.MessageManager;
31 public class TextColourChooser
37 public void chooseColour(AlignmentPanel ap, SequenceGroup sg)
42 int original1, original2, originalThreshold;
45 original1 = ap.av.textColour.getRGB();
46 original2 = ap.av.textColour2.getRGB();
47 originalThreshold = ap.av.thresholdTextColour;
51 original1 = sg.textColour.getRGB();
52 original2 = sg.textColour2.getRGB();
53 originalThreshold = sg.thresholdTextColour;
56 final JSlider slider = new JSlider(0, 750, originalThreshold);
57 final JPanel col1 = new JPanel();
58 col1.setPreferredSize(new Dimension(40, 20));
59 col1.setBorder(BorderFactory.createEtchedBorder());
60 col1.setToolTipText(MessageManager.getString("label.dark_colour"));
61 col1.setBackground(new Color(original1));
62 final JPanel col2 = new JPanel();
63 col2.setPreferredSize(new Dimension(40, 20));
64 col2.setBorder(BorderFactory.createEtchedBorder());
65 col2.setToolTipText(MessageManager.getString("label.ligth_colour"));
66 col2.setBackground(new Color(original2));
67 final JPanel bigpanel = new JPanel(new BorderLayout());
68 JPanel panel = new JPanel();
69 bigpanel.add(panel, BorderLayout.CENTER);
72 "<html><i>Select a dark and light text colour, then set the threshold to"
73 + "<br>switch between colours, based on background colour</i></html>"),
79 col1.addMouseListener(new MouseAdapter()
81 public void mousePressed(MouseEvent e)
83 Color col = JColorChooser.showDialog(bigpanel,
84 "Select Colour for Text", col1.getBackground());
88 col1.setBackground(col);
93 col2.addMouseListener(new MouseAdapter()
95 public void mousePressed(MouseEvent e)
97 Color col = JColorChooser.showDialog(bigpanel,
98 "Select Colour for Text", col2.getBackground());
102 col2.setBackground(col);
107 slider.addChangeListener(new ChangeListener()
109 public void stateChanged(ChangeEvent evt)
111 thresholdChanged(slider.getValue());
115 int reply = JOptionPane.showInternalOptionDialog(ap, bigpanel,
116 "Adjust Foreground Text Colour Threshold",
117 JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
120 if (reply == JOptionPane.CANCEL_OPTION)
124 ap.av.textColour = new Color(original1);
125 ap.av.textColour2 = new Color(original2);
126 ap.av.thresholdTextColour = originalThreshold;
130 sg.textColour = new Color(original1);
131 sg.textColour2 = new Color(original2);
132 sg.thresholdTextColour = originalThreshold;
137 void colour1Changed(Color col)
141 ap.av.textColour = col;
142 if (ap.av.getColourAppliesToAllGroups())
144 setGroupTextColour();
152 ap.paintAlignment(true);
155 void colour2Changed(Color col)
159 ap.av.textColour2 = col;
160 if (ap.av.getColourAppliesToAllGroups())
162 setGroupTextColour();
167 sg.textColour2 = col;
170 ap.paintAlignment(true);
173 void thresholdChanged(int value)
177 ap.av.thresholdTextColour = value;
178 if (ap.av.getColourAppliesToAllGroups())
180 setGroupTextColour();
185 sg.thresholdTextColour = value;
188 ap.paintAlignment(true);
191 void setGroupTextColour()
193 if (ap.av.getAlignment().getGroups() == null)
198 for (SequenceGroup sg : ap.av.getAlignment().getGroups())
200 sg.textColour = ap.av.textColour;
201 sg.textColour2 = ap.av.textColour2;
202 sg.thresholdTextColour = ap.av.thresholdTextColour;