2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
25 import java.awt.event.*;
\r
27 import jalview.datamodel.*;
\r
28 import jalview.jbappletgui.*;
\r
29 import jalview.schemes.*;
\r
31 public class UserDefinedColours
\r
32 extends GUserDefinedColours
\r
36 SequenceGroup seqGroup;
\r
37 Button selectedButton;
\r
38 Vector oldColours = new Vector();
\r
39 ColourSchemeI oldColourScheme;
\r
42 int R = 0, G = 0, B = 0;
\r
44 public ColourSchemeI loadDefaultColours()
\r
46 // NOT IMPLEMENTED YET IN APPLET VERSION
\r
50 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
\r
53 frame = new Frame();
\r
55 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420, 345);
\r
59 frame.setTitle(frame.getTitle() + " (" + sg.getName() + ")");
\r
65 if (seqGroup != null)
\r
67 oldColourScheme = seqGroup.cs;
\r
71 oldColourScheme = ap.av.getGlobalColourScheme();
\r
74 for (int i = 0; i < 20; i++)
\r
76 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +
\r
77 "", ResidueProperties.aa[i]);
\r
80 makeButton("B", "B");
\r
81 makeButton("Z", "Z");
\r
82 makeButton("X", "X");
\r
83 makeButton("Gap", "'.','-',' '");
\r
89 protected void rText_actionPerformed(ActionEvent e)
\r
93 int i = Integer.parseInt(rText.getText());
\r
94 rScroller.setValue(i);
\r
95 rScroller_adjustmentValueChanged(null);
\r
97 catch (NumberFormatException ex)
\r
101 protected void gText_actionPerformed(ActionEvent e)
\r
105 int i = Integer.parseInt(gText.getText());
\r
106 gScroller.setValue(i);
\r
107 gScroller_adjustmentValueChanged(null);
\r
109 catch (NumberFormatException ex)
\r
114 protected void bText_actionPerformed(ActionEvent e)
\r
118 int i = Integer.parseInt(bText.getText());
\r
119 bScroller.setValue(i);
\r
120 bScroller_adjustmentValueChanged(null);
\r
122 catch (NumberFormatException ex)
\r
127 protected void rScroller_adjustmentValueChanged(AdjustmentEvent e)
\r
129 R = rScroller.getValue();
\r
130 rText.setText(R + "");
\r
134 protected void gScroller_adjustmentValueChanged(AdjustmentEvent e)
\r
136 G = gScroller.getValue();
\r
137 gText.setText(G + "");
\r
141 protected void bScroller_adjustmentValueChanged(AdjustmentEvent e)
\r
143 B = bScroller.getValue();
\r
144 bText.setText(B + "");
\r
148 public void colourChanged()
\r
150 Color col = new Color(R, G, B);
\r
151 target.setBackground(col);
\r
154 if (selectedButton != null)
\r
156 selectedButton.setBackground(col);
\r
157 selectedButton.repaint();
\r
161 public void colourButtonPressed(MouseEvent e)
\r
163 selectedButton = (Button) e.getSource();
\r
164 Color col = selectedButton.getBackground();
\r
166 G = col.getGreen();
\r
168 rScroller.setValue(R);
\r
169 gScroller.setValue(G);
\r
170 bScroller.setValue(B);
\r
171 rText.setText(R + "");
\r
172 gText.setText(G + "");
\r
173 bText.setText(B + "");
\r
178 void makeButton(String label, String aa)
\r
180 final Button button = new Button();
\r
181 Color col = Color.white;
\r
185 col = oldColourScheme.findColour(aa, -1);
\r
187 catch (Exception ex)
\r
190 button.setBackground(col);
\r
191 oldColours.addElement(col);
\r
192 button.setLabel(label);
\r
193 button.setForeground(col.darker().darker().darker());
\r
194 button.setFont(new java.awt.Font("Verdana", 1, 10));
\r
195 button.addMouseListener(new java.awt.event.MouseAdapter()
\r
197 public void mousePressed(MouseEvent e)
\r
199 colourButtonPressed(e);
\r
203 buttonPanel.add(button, null);
\r
206 protected void okButton_actionPerformed(ActionEvent e)
\r
208 applyButton_actionPerformed(null);
\r
209 frame.setVisible(false);
\r
212 protected void applyButton_actionPerformed(ActionEvent e)
\r
215 Color[] newColours = new Color[24];
\r
216 for (int i = 0; i < 24; i++)
\r
218 Button button = (Button) buttonPanel.getComponent(i);
\r
219 newColours[i] = button.getBackground();
\r
222 UserColourScheme ucs = new UserColourScheme(newColours);
\r
223 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
\r
225 if (seqGroup != null)
\r
231 ap.av.setGlobalColourScheme(ucs);
\r
234 ap.seqPanel.seqCanvas.img = null;
\r
239 protected void cancelButton_actionPerformed(ActionEvent e)
\r
242 Color[] newColours = new Color[24];
\r
243 for (int i = 0; i < 24; i++)
\r
245 newColours[i] = (Color) oldColours.elementAt(i);
\r
246 buttonPanel.getComponent(i).setBackground(newColours[i]);
\r
249 UserColourScheme ucs = new UserColourScheme(newColours);
\r
251 if (seqGroup != null)
\r
257 ap.av.setGlobalColourScheme(ucs);
\r
262 frame.setVisible(false);
\r