2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
43 String originalLabel;
\r
44 Color originalColour;
\r
46 int R = 0, G = 0, B = 0;
\r
48 public ColourSchemeI loadDefaultColours()
\r
50 // NOT IMPLEMENTED YET IN APPLET VERSION
\r
54 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
\r
59 if (seqGroup != null)
\r
61 oldColourScheme = seqGroup.cs;
\r
65 oldColourScheme = ap.av.getGlobalColourScheme();
\r
71 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
\r
73 this.pdbcanvas = pdb;
\r
77 public UserDefinedColours(Component caller,
\r
81 this.caller = caller;
\r
82 originalColour = colour;
\r
83 originalLabel = label;
\r
85 remove(buttonPanel);
\r
87 setTargetColour(colour);
\r
89 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
\r
90 frame.setTitle("User Defined Colours - " + label);
\r
91 frame.setSize(420, 200);
\r
94 public void actionPerformed(ActionEvent evt)
\r
96 if (evt.getSource() == okButton)
\r
98 okButton_actionPerformed();
\r
100 else if (evt.getSource() == applyButton)
\r
102 applyButton_actionPerformed();
\r
104 else if (evt.getSource() == cancelButton)
\r
106 cancelButton_actionPerformed();
\r
108 else if (evt.getSource() == rText)
\r
110 rText_actionPerformed();
\r
112 else if (evt.getSource() == gText)
\r
114 gText_actionPerformed();
\r
116 else if (evt.getSource() == bText)
\r
118 bText_actionPerformed();
\r
122 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
124 if (evt.getSource() == rScroller)
\r
126 rScroller_adjustmentValueChanged();
\r
128 else if (evt.getSource() == gScroller)
\r
130 gScroller_adjustmentValueChanged();
\r
132 else if (evt.getSource() == bScroller)
\r
134 bScroller_adjustmentValueChanged();
\r
144 catch (Exception e)
\r
146 e.printStackTrace();
\r
148 frame = new Frame();
\r
150 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420, 345);
\r
152 if (seqGroup != null)
\r
154 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
\r
157 for (int i = 0; i < 20; i++)
\r
159 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +
\r
160 "", ResidueProperties.aa[i]);
\r
163 makeButton("B", "B");
\r
164 makeButton("Z", "Z");
\r
165 makeButton("X", "X");
\r
166 makeButton("Gap", "'.','-',' '");
\r
171 protected void rText_actionPerformed()
\r
175 int i = Integer.parseInt(rText.getText());
\r
176 rScroller.setValue(i);
\r
177 rScroller_adjustmentValueChanged();
\r
179 catch (NumberFormatException ex)
\r
183 protected void gText_actionPerformed()
\r
187 int i = Integer.parseInt(gText.getText());
\r
188 gScroller.setValue(i);
\r
189 gScroller_adjustmentValueChanged();
\r
191 catch (NumberFormatException ex)
\r
196 protected void bText_actionPerformed()
\r
200 int i = Integer.parseInt(bText.getText());
\r
201 bScroller.setValue(i);
\r
202 bScroller_adjustmentValueChanged();
\r
204 catch (NumberFormatException ex)
\r
209 protected void rScroller_adjustmentValueChanged()
\r
211 R = rScroller.getValue();
\r
212 rText.setText(R + "");
\r
216 protected void gScroller_adjustmentValueChanged()
\r
218 G = gScroller.getValue();
\r
219 gText.setText(G + "");
\r
223 protected void bScroller_adjustmentValueChanged()
\r
225 B = bScroller.getValue();
\r
226 bText.setText(B + "");
\r
230 public void colourChanged()
\r
232 Color col = new Color(R, G, B);
\r
233 target.setBackground(col);
\r
236 if (selectedButton != null)
\r
238 selectedButton.setBackground(col);
\r
239 selectedButton.repaint();
\r
243 void setTargetColour(Color col)
\r
246 G = col.getGreen();
\r
248 rScroller.setValue(R);
\r
249 gScroller.setValue(G);
\r
250 bScroller.setValue(B);
\r
251 rText.setText(R + "");
\r
252 gText.setText(G + "");
\r
253 bText.setText(B + "");
\r
257 public void colourButtonPressed(MouseEvent e)
\r
259 selectedButton = (Button) e.getSource();
\r
260 setTargetColour(selectedButton.getBackground());
\r
263 void makeButton(String label, String aa)
\r
265 final Button button = new Button();
\r
266 Color col = Color.white;
\r
270 col = oldColourScheme.findColour(aa.charAt(0), -1);
\r
272 catch (Exception ex)
\r
275 button.setBackground(col);
\r
276 oldColours.addElement(col);
\r
277 button.setLabel(label);
\r
278 button.setForeground(col.darker().darker().darker());
\r
279 button.setFont(new java.awt.Font("Verdana", 1, 10));
\r
280 button.addMouseListener(new java.awt.event.MouseAdapter()
\r
282 public void mousePressed(MouseEvent e)
\r
284 colourButtonPressed(e);
\r
288 buttonPanel.add(button, null);
\r
291 protected void okButton_actionPerformed()
\r
293 applyButton_actionPerformed();
\r
294 frame.setVisible(false);
\r
297 protected void applyButton_actionPerformed()
\r
299 if (caller != null)
\r
301 if (caller instanceof FeatureSettings)
\r
303 ( (FeatureSettings) caller).setUserColour
\r
304 (originalLabel, new Color(R, G, B));
\r
306 else if (caller instanceof AnnotationColourChooser)
\r
308 if (originalLabel.equals("Min Colour"))
\r
310 ( (AnnotationColourChooser) caller).minColour_actionPerformed
\r
311 (new Color(R, G, B));
\r
315 ( (AnnotationColourChooser) caller).maxColour_actionPerformed
\r
316 (new Color(R, G, B));
\r
322 Color[] newColours = new Color[24];
\r
323 for (int i = 0; i < 24; i++)
\r
325 Button button = (Button) buttonPanel.getComponent(i);
\r
326 newColours[i] = button.getBackground();
\r
329 UserColourScheme ucs = new UserColourScheme(newColours);
\r
332 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
\r
337 if (seqGroup != null)
\r
343 ap.av.setGlobalColourScheme(ucs);
\r
345 ap.seqPanel.seqCanvas.img = null;
\r
346 ap.paintAlignment(true);
\r
348 else if (pdbcanvas != null)
\r
350 pdbcanvas.setColours(ucs);
\r
354 protected void cancelButton_actionPerformed()
\r
356 if (caller != null)
\r
358 if (caller instanceof FeatureSettings)
\r
360 ( (FeatureSettings) caller).setUserColour
\r
361 (originalLabel, originalColour);
\r
363 else if (caller instanceof AnnotationColourChooser)
\r
365 if (originalLabel.equals("Min Colour"))
\r
367 ( (AnnotationColourChooser) caller).minColour_actionPerformed
\r
372 ( (AnnotationColourChooser) caller).maxColour_actionPerformed
\r
376 frame.setVisible(false);
\r
380 Color[] newColours = new Color[24];
\r
381 for (int i = 0; i < 24; i++)
\r
383 newColours[i] = (Color) oldColours.elementAt(i);
\r
384 buttonPanel.getComponent(i).setBackground(newColours[i]);
\r
387 UserColourScheme ucs = new UserColourScheme(newColours);
\r
391 if (seqGroup != null)
\r
397 ap.av.setGlobalColourScheme(ucs);
\r
399 ap.paintAlignment(true);
\r
401 else if (pdbcanvas != null)
\r
403 pdbcanvas.pdb.setColours(ucs);
\r
406 frame.setVisible(false);
\r
409 protected Panel buttonPanel = new Panel();
\r
410 protected GridLayout gridLayout = new GridLayout();
\r
411 Panel okcancelPanel = new Panel();
\r
412 protected Button okButton = new Button();
\r
413 protected Button applyButton = new Button();
\r
414 protected Button cancelButton = new Button();
\r
415 protected Scrollbar rScroller = new Scrollbar();
\r
416 Label label1 = new Label();
\r
417 protected TextField rText = new TextField();
\r
418 Label label4 = new Label();
\r
419 protected Scrollbar gScroller = new Scrollbar();
\r
420 protected TextField gText = new TextField();
\r
421 Label label5 = new Label();
\r
422 protected Scrollbar bScroller = new Scrollbar();
\r
423 protected TextField bText = new TextField();
\r
424 protected Panel target = new Panel();
\r
426 private void jbInit()
\r
429 this.setLayout(null);
\r
430 buttonPanel.setLayout(gridLayout);
\r
431 gridLayout.setColumns(6);
\r
432 gridLayout.setRows(4);
\r
433 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
434 okButton.setLabel("OK");
\r
435 okButton.addActionListener(this);
\r
436 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
437 applyButton.setLabel("Apply");
\r
438 applyButton.addActionListener(this);
\r
439 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
440 cancelButton.setLabel("Cancel");
\r
441 cancelButton.addActionListener(this);
\r
442 this.setBackground(new Color(212, 208, 223));
\r
443 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
\r
444 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
\r
445 rScroller.setMaximum(256);
\r
446 rScroller.setMinimum(0);
\r
447 rScroller.setOrientation(0);
\r
448 rScroller.setUnitIncrement(1);
\r
449 rScroller.setVisibleAmount(1);
\r
450 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
\r
451 rScroller.addAdjustmentListener(this);
\r
452 label1.setAlignment(Label.RIGHT);
\r
453 label1.setText("R");
\r
454 label1.setBounds(new Rectangle(19, 30, 16, 15));
\r
455 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
456 rText.setText("0 ");
\r
457 rText.setBounds(new Rectangle(156, 27, 53, 19));
\r
458 rText.addActionListener(this);
\r
459 label4.setAlignment(Label.RIGHT);
\r
460 label4.setText("G");
\r
461 label4.setBounds(new Rectangle(15, 56, 20, 15));
\r
462 gScroller.setMaximum(256);
\r
463 gScroller.setMinimum(0);
\r
464 gScroller.setOrientation(0);
\r
465 gScroller.setUnitIncrement(1);
\r
466 gScroller.setVisibleAmount(1);
\r
467 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
\r
468 gScroller.addAdjustmentListener(this);
\r
469 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
470 gText.setText("0 ");
\r
471 gText.setBounds(new Rectangle(156, 52, 53, 20));
\r
472 gText.addActionListener(this);
\r
473 label5.setAlignment(Label.RIGHT);
\r
474 label5.setText("B");
\r
475 label5.setBounds(new Rectangle(14, 82, 20, 15));
\r
476 bScroller.setMaximum(256);
\r
477 bScroller.setMinimum(0);
\r
478 bScroller.setOrientation(0);
\r
479 bScroller.setUnitIncrement(1);
\r
480 bScroller.setVisibleAmount(1);
\r
481 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
\r
482 bScroller.addAdjustmentListener(this);
\r
483 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
484 bText.setText("0 ");
\r
485 bText.setBounds(new Rectangle(157, 78, 52, 20));
\r
486 bText.addActionListener(this);
\r
487 target.setBackground(Color.black);
\r
488 target.setBounds(new Rectangle(229, 26, 134, 79));
\r
489 this.add(okcancelPanel, null);
\r
490 okcancelPanel.add(okButton, null);
\r
491 okcancelPanel.add(applyButton, null);
\r
492 okcancelPanel.add(cancelButton, null);
\r
493 this.add(buttonPanel, null);
\r
494 this.add(target, null);
\r
495 this.add(gScroller);
\r
496 this.add(rScroller);
\r
497 this.add(bScroller);
\r