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
26 import java.awt.event.*;
\r
28 import jalview.datamodel.*;
\r
29 import jalview.jbappletgui.*;
\r
30 import jalview.schemes.*;
\r
32 public class UserDefinedColours
\r
33 extends GUserDefinedColours
\r
37 SequenceGroup seqGroup;
\r
38 Button selectedButton;
\r
39 Vector oldColours = new Vector();
\r
40 ColourSchemeI oldColourScheme;
\r
43 int R = 0, G = 0, B = 0;
\r
45 public ColourSchemeI loadDefaultColours()
\r
47 // NOT IMPLEMENTED YET IN APPLET VERSION
\r
51 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
\r
54 frame = new Frame();
\r
56 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420, 345);
\r
60 frame.setTitle(frame.getTitle() + " (" + sg.getName() + ")");
\r
66 if (seqGroup != null)
\r
68 oldColourScheme = seqGroup.cs;
\r
72 oldColourScheme = ap.av.getGlobalColourScheme();
\r
75 for (int i = 0; i < 20; i++)
\r
77 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +
\r
78 "", ResidueProperties.aa[i]);
\r
81 makeButton("B", "B");
\r
82 makeButton("Z", "Z");
\r
83 makeButton("X", "X");
\r
84 makeButton("Gap", "'.','-',' '");
\r
88 protected void rText_actionPerformed(ActionEvent e)
\r
92 int i = Integer.parseInt(rText.getText());
\r
93 rScroller.setValue(i);
\r
95 catch (NumberFormatException ex)
\r
99 protected void gText_actionPerformed(ActionEvent e)
\r
103 int i = Integer.parseInt(gText.getText());
\r
104 gScroller.setValue(i);
\r
106 catch (NumberFormatException ex)
\r
111 protected void bText_actionPerformed(ActionEvent e)
\r
115 int i = Integer.parseInt(bText.getText());
\r
116 bScroller.setValue(i);
\r
118 catch (NumberFormatException ex)
\r
123 protected void rScroller_adjustmentValueChanged(AdjustmentEvent e)
\r
125 R = rScroller.getValue();
\r
126 rText.setText(R + "");
\r
130 protected void gScroller_adjustmentValueChanged(AdjustmentEvent e)
\r
132 G = gScroller.getValue();
\r
133 gText.setText(G + "");
\r
137 protected void bScroller_adjustmentValueChanged(AdjustmentEvent e)
\r
139 B = bScroller.getValue();
\r
140 bText.setText(B + "");
\r
144 public void colourChanged()
\r
146 Color col = new Color(R, G, B);
\r
147 target.setBackground(col);
\r
149 if (selectedButton != null)
\r
151 selectedButton.setBackground(col);
\r
155 public void colourButtonPressed(MouseEvent e)
\r
157 selectedButton = (Button) e.getSource();
\r
158 Color col = selectedButton.getBackground();
\r
160 G = col.getGreen();
\r
162 rScroller.setValue(R);
\r
163 gScroller.setValue(G);
\r
164 bScroller.setValue(B);
\r
165 rText.setText(R + "");
\r
166 gText.setText(G + "");
\r
167 bText.setText(B + "");
\r
172 void makeButton(String label, String aa)
\r
174 final Button button = new Button();
\r
175 Color col = Color.white;
\r
179 col = oldColourScheme.findColour(aa, -1);
\r
181 catch (Exception ex)
\r
184 button.setBackground(col);
\r
185 oldColours.addElement(col);
\r
186 button.setLabel(label);
\r
187 button.setForeground(col.darker().darker().darker());
\r
188 button.setFont(new java.awt.Font("Verdana", 1, 10));
\r
189 button.addMouseListener(new java.awt.event.MouseAdapter()
\r
191 public void mouseClicked(MouseEvent e)
\r
193 colourButtonPressed(e);
\r
197 buttonPanel.add(button, null);
\r
200 protected void okButton_actionPerformed(ActionEvent e)
\r
202 applyButton_actionPerformed(null);
\r
203 frame.setVisible(false);
\r
206 protected void applyButton_actionPerformed(ActionEvent e)
\r
209 Color[] newColours = new Color[24];
\r
210 for (int i = 0; i < 24; i++)
\r
212 Button button = (Button) buttonPanel.getComponent(i);
\r
213 newColours[i] = button.getBackground();
\r
216 UserColourScheme ucs = new UserColourScheme(newColours);
\r
217 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
\r
219 if (seqGroup != null)
\r
225 ap.av.setGlobalColourScheme(ucs);
\r
232 protected void cancelButton_actionPerformed(ActionEvent e)
\r
235 Color[] newColours = new Color[24];
\r
236 for (int i = 0; i < 24; i++)
\r
238 newColours[i] = (Color) oldColours.elementAt(i);
\r
239 buttonPanel.getComponent(i).setBackground(newColours[i]);
\r
242 UserColourScheme ucs = new UserColourScheme(newColours);
\r
244 if (seqGroup != null)
\r
250 ap.av.setGlobalColourScheme(ucs);
\r
255 frame.setVisible(false);
\r