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.schemes.*;
\r
30 public class UserDefinedColours
\r
31 extends Panel implements ActionListener, AdjustmentListener
\r
35 SequenceGroup seqGroup;
\r
36 Button selectedButton;
\r
37 Vector oldColours = new Vector();
\r
38 ColourSchemeI oldColourScheme;
\r
40 MCview.AppletPDBCanvas pdbcanvas;
\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
55 if (seqGroup != null)
\r
57 oldColourScheme = seqGroup.cs;
\r
61 oldColourScheme = ap.av.getGlobalColourScheme();
\r
67 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
\r
69 this.pdbcanvas = pdb;
\r
73 public void actionPerformed(ActionEvent evt)
\r
75 if(evt.getSource()==okButton)
\r
76 okButton_actionPerformed();
\r
77 else if(evt.getSource()==applyButton)
\r
78 applyButton_actionPerformed();
\r
79 else if(evt.getSource()==cancelButton)
\r
80 cancelButton_actionPerformed();
\r
81 else if(evt.getSource()==rText)
\r
82 rText_actionPerformed();
\r
83 else if (evt.getSource() == gText)
\r
84 gText_actionPerformed();
\r
85 else if (evt.getSource() == bText)
\r
86 bText_actionPerformed();
\r
89 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
91 if(evt.getSource()==rScroller)
\r
92 rScroller_adjustmentValueChanged();
\r
93 else if(evt.getSource()==gScroller)
\r
94 gScroller_adjustmentValueChanged();
\r
95 else if(evt.getSource()==bScroller)
\r
96 bScroller_adjustmentValueChanged();
\r
105 catch (Exception e)
\r
107 e.printStackTrace();
\r
109 frame = new Frame();
\r
111 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420, 345);
\r
113 if (seqGroup != null)
\r
115 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
\r
118 for (int i = 0; i < 20; i++)
\r
120 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +
\r
121 "", ResidueProperties.aa[i]);
\r
124 makeButton("B", "B");
\r
125 makeButton("Z", "Z");
\r
126 makeButton("X", "X");
\r
127 makeButton("Gap", "'.','-',' '");
\r
131 protected void rText_actionPerformed()
\r
135 int i = Integer.parseInt(rText.getText());
\r
136 rScroller.setValue(i);
\r
137 rScroller_adjustmentValueChanged();
\r
139 catch (NumberFormatException ex)
\r
143 protected void gText_actionPerformed()
\r
147 int i = Integer.parseInt(gText.getText());
\r
148 gScroller.setValue(i);
\r
149 gScroller_adjustmentValueChanged();
\r
151 catch (NumberFormatException ex)
\r
156 protected void bText_actionPerformed()
\r
160 int i = Integer.parseInt(bText.getText());
\r
161 bScroller.setValue(i);
\r
162 bScroller_adjustmentValueChanged();
\r
164 catch (NumberFormatException ex)
\r
169 protected void rScroller_adjustmentValueChanged()
\r
171 R = rScroller.getValue();
\r
172 rText.setText(R + "");
\r
176 protected void gScroller_adjustmentValueChanged()
\r
178 G = gScroller.getValue();
\r
179 gText.setText(G + "");
\r
183 protected void bScroller_adjustmentValueChanged()
\r
185 B = bScroller.getValue();
\r
186 bText.setText(B + "");
\r
190 public void colourChanged()
\r
192 Color col = new Color(R, G, B);
\r
193 target.setBackground(col);
\r
196 if (selectedButton != null)
\r
198 selectedButton.setBackground(col);
\r
199 selectedButton.repaint();
\r
203 public void colourButtonPressed(MouseEvent e)
\r
205 selectedButton = (Button) e.getSource();
\r
206 Color col = selectedButton.getBackground();
\r
208 G = col.getGreen();
\r
210 rScroller.setValue(R);
\r
211 gScroller.setValue(G);
\r
212 bScroller.setValue(B);
\r
213 rText.setText(R + "");
\r
214 gText.setText(G + "");
\r
215 bText.setText(B + "");
\r
220 void makeButton(String label, String aa)
\r
222 final Button button = new Button();
\r
223 Color col = Color.white;
\r
227 col = oldColourScheme.findColour(aa, -1);
\r
229 catch (Exception ex)
\r
232 button.setBackground(col);
\r
233 oldColours.addElement(col);
\r
234 button.setLabel(label);
\r
235 button.setForeground(col.darker().darker().darker());
\r
236 button.setFont(new java.awt.Font("Verdana", 1, 10));
\r
237 button.addMouseListener(new java.awt.event.MouseAdapter()
\r
239 public void mousePressed(MouseEvent e)
\r
241 colourButtonPressed(e);
\r
245 buttonPanel.add(button, null);
\r
248 protected void okButton_actionPerformed()
\r
250 applyButton_actionPerformed();
\r
251 frame.setVisible(false);
\r
254 protected void applyButton_actionPerformed()
\r
256 Color[] newColours = new Color[24];
\r
257 for (int i = 0; i < 24; i++)
\r
259 Button button = (Button) buttonPanel.getComponent(i);
\r
260 newColours[i] = button.getBackground();
\r
263 UserColourScheme ucs = new UserColourScheme(newColours);
\r
265 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
\r
269 if (seqGroup != null)
\r
275 ap.av.setGlobalColourScheme(ucs);
\r
277 ap.seqPanel.seqCanvas.img = null;
\r
280 else if(pdbcanvas!=null)
\r
282 pdbcanvas.pdb.setColours(ucs);
\r
283 pdbcanvas.updateSeqColours();
\r
288 protected void cancelButton_actionPerformed()
\r
291 Color[] newColours = new Color[24];
\r
292 for (int i = 0; i < 24; i++)
\r
294 newColours[i] = (Color) oldColours.elementAt(i);
\r
295 buttonPanel.getComponent(i).setBackground(newColours[i]);
\r
298 UserColourScheme ucs = new UserColourScheme(newColours);
\r
302 if (seqGroup != null)
\r
308 ap.av.setGlobalColourScheme(ucs);
\r
312 else if(pdbcanvas!=null)
\r
314 pdbcanvas.pdb.setColours(ucs);
\r
317 frame.setVisible(false);
\r
321 protected Panel buttonPanel = new Panel();
\r
322 protected GridLayout gridLayout = new GridLayout();
\r
323 Panel jPanel2 = new Panel();
\r
324 protected Button okButton = new Button();
\r
325 protected Button applyButton = new Button();
\r
326 protected Button cancelButton = new Button();
\r
327 protected Scrollbar rScroller = new Scrollbar();
\r
328 Label label1 = new Label();
\r
329 protected TextField rText = new TextField();
\r
330 Label label4 = new Label();
\r
331 protected Scrollbar gScroller = new Scrollbar();
\r
332 protected TextField gText = new TextField();
\r
333 Label label5 = new Label();
\r
334 protected Scrollbar bScroller = new Scrollbar();
\r
335 protected TextField bText = new TextField();
\r
336 protected Panel target = new Panel();
\r
338 private void jbInit() throws Exception {
\r
339 this.setLayout(null);
\r
340 buttonPanel.setLayout(gridLayout);
\r
341 gridLayout.setColumns(6);
\r
342 gridLayout.setRows(4);
\r
343 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
344 okButton.setLabel("OK");
\r
345 okButton.addActionListener(this);
\r
346 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
347 applyButton.setLabel("Apply");
\r
348 applyButton.addActionListener(this);
\r
349 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
350 cancelButton.setLabel("Cancel");
\r
351 cancelButton.addActionListener(this);
\r
352 this.setBackground(new Color(212, 208, 223));
\r
353 jPanel2.setBounds(new Rectangle(0, 265, 400, 35));
\r
354 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
\r
355 rScroller.setMaximum(256);
\r
356 rScroller.setMinimum(0);
\r
357 rScroller.setOrientation(0);
\r
358 rScroller.setUnitIncrement(1);
\r
359 rScroller.setVisibleAmount(1);
\r
360 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
\r
361 rScroller.addAdjustmentListener(this);
\r
362 label1.setAlignment(Label.RIGHT);
\r
363 label1.setText("R");
\r
364 label1.setBounds(new Rectangle(19, 30, 16, 15));
\r
365 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
366 rText.setText("0 ");
\r
367 rText.setBounds(new Rectangle(156, 27, 53, 19));
\r
368 rText.addActionListener(this);
\r
369 label4.setAlignment(Label.RIGHT);
\r
370 label4.setText("G");
\r
371 label4.setBounds(new Rectangle(15, 56, 20, 15));
\r
372 gScroller.setMaximum(256);
\r
373 gScroller.setMinimum(0);
\r
374 gScroller.setOrientation(0);
\r
375 gScroller.setUnitIncrement(1);
\r
376 gScroller.setVisibleAmount(1);
\r
377 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
\r
378 gScroller.addAdjustmentListener(this);
\r
379 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
380 gText.setText("0 ");
\r
381 gText.setBounds(new Rectangle(156, 52, 53, 20));
\r
382 gText.addActionListener(this);
\r
383 label5.setAlignment(Label.RIGHT);
\r
384 label5.setText("B");
\r
385 label5.setBounds(new Rectangle(14, 82, 20, 15));
\r
386 bScroller.setMaximum(256);
\r
387 bScroller.setMinimum(0);
\r
388 bScroller.setOrientation(0);
\r
389 bScroller.setUnitIncrement(1);
\r
390 bScroller.setVisibleAmount(1);
\r
391 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
\r
392 bScroller.addAdjustmentListener(this);
\r
393 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
394 bText.setText("0 ");
\r
395 bText.setBounds(new Rectangle(157, 78, 52, 20));
\r
396 bText.addActionListener(this);
\r
397 target.setBackground(Color.black);
\r
398 target.setBounds(new Rectangle(229, 26, 134, 79));
\r
399 this.add(jPanel2, null);
\r
400 jPanel2.add(okButton, null);
\r
401 jPanel2.add(applyButton, null);
\r
402 jPanel2.add(cancelButton, null);
\r
403 this.add(buttonPanel, null);
\r
404 this.add(target, null);
\r
405 this.add(gScroller);
\r
406 this.add(rScroller);
\r
407 this.add(bScroller);
\r