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
44 String originalLabel;
\r
45 Color originalColour;
\r
47 int R = 0, G = 0, B = 0;
\r
49 public ColourSchemeI loadDefaultColours()
\r
51 // NOT IMPLEMENTED YET IN APPLET VERSION
\r
55 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
\r
60 if (seqGroup != null)
\r
62 oldColourScheme = seqGroup.cs;
\r
66 oldColourScheme = ap.av.getGlobalColourScheme();
\r
72 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
\r
74 this.pdbcanvas = pdb;
\r
78 public UserDefinedColours(AppletJmol jmol)
\r
84 public UserDefinedColours(Object caller,
\r
88 this.caller = caller;
\r
89 originalColour = colour;
\r
90 originalLabel = label;
\r
92 remove(buttonPanel);
\r
94 setTargetColour(colour);
\r
96 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
\r
97 frame.setTitle("User Defined Colours - " + label);
\r
98 frame.setSize(420, 200);
\r
101 public void actionPerformed(ActionEvent evt)
\r
103 if (evt.getSource() == okButton)
\r
105 okButton_actionPerformed();
\r
107 else if (evt.getSource() == applyButton)
\r
109 applyButton_actionPerformed();
\r
111 else if (evt.getSource() == cancelButton)
\r
113 cancelButton_actionPerformed();
\r
115 else if (evt.getSource() == rText)
\r
117 rText_actionPerformed();
\r
119 else if (evt.getSource() == gText)
\r
121 gText_actionPerformed();
\r
123 else if (evt.getSource() == bText)
\r
125 bText_actionPerformed();
\r
129 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
131 if (evt.getSource() == rScroller)
\r
133 rScroller_adjustmentValueChanged();
\r
135 else if (evt.getSource() == gScroller)
\r
137 gScroller_adjustmentValueChanged();
\r
139 else if (evt.getSource() == bScroller)
\r
141 bScroller_adjustmentValueChanged();
\r
151 catch (Exception e)
\r
153 e.printStackTrace();
\r
155 frame = new Frame();
\r
157 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420, 345);
\r
159 if (seqGroup != null)
\r
161 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
\r
164 for (int i = 0; i < 20; i++)
\r
166 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +
\r
167 "", ResidueProperties.aa[i]);
\r
170 makeButton("B", "B");
\r
171 makeButton("Z", "Z");
\r
172 makeButton("X", "X");
\r
173 makeButton("Gap", "'.','-',' '");
\r
178 protected void rText_actionPerformed()
\r
182 int i = Integer.parseInt(rText.getText());
\r
183 rScroller.setValue(i);
\r
184 rScroller_adjustmentValueChanged();
\r
186 catch (NumberFormatException ex)
\r
190 protected void gText_actionPerformed()
\r
194 int i = Integer.parseInt(gText.getText());
\r
195 gScroller.setValue(i);
\r
196 gScroller_adjustmentValueChanged();
\r
198 catch (NumberFormatException ex)
\r
203 protected void bText_actionPerformed()
\r
207 int i = Integer.parseInt(bText.getText());
\r
208 bScroller.setValue(i);
\r
209 bScroller_adjustmentValueChanged();
\r
211 catch (NumberFormatException ex)
\r
216 protected void rScroller_adjustmentValueChanged()
\r
218 R = rScroller.getValue();
\r
219 rText.setText(R + "");
\r
223 protected void gScroller_adjustmentValueChanged()
\r
225 G = gScroller.getValue();
\r
226 gText.setText(G + "");
\r
230 protected void bScroller_adjustmentValueChanged()
\r
232 B = bScroller.getValue();
\r
233 bText.setText(B + "");
\r
237 public void colourChanged()
\r
239 Color col = new Color(R, G, B);
\r
240 target.setBackground(col);
\r
243 if (selectedButton != null)
\r
245 selectedButton.setBackground(col);
\r
246 selectedButton.repaint();
\r
250 void setTargetColour(Color col)
\r
253 G = col.getGreen();
\r
255 rScroller.setValue(R);
\r
256 gScroller.setValue(G);
\r
257 bScroller.setValue(B);
\r
258 rText.setText(R + "");
\r
259 gText.setText(G + "");
\r
260 bText.setText(B + "");
\r
264 public void colourButtonPressed(MouseEvent e)
\r
266 selectedButton = (Button) e.getSource();
\r
267 setTargetColour(selectedButton.getBackground());
\r
270 void makeButton(String label, String aa)
\r
272 final Button button = new Button();
\r
273 Color col = Color.white;
\r
277 col = oldColourScheme.findColour(aa.charAt(0), -1);
\r
279 catch (Exception ex)
\r
282 button.setBackground(col);
\r
283 oldColours.addElement(col);
\r
284 button.setLabel(label);
\r
285 button.setForeground(col.darker().darker().darker());
\r
286 button.setFont(new java.awt.Font("Verdana", 1, 10));
\r
287 button.addMouseListener(new java.awt.event.MouseAdapter()
\r
289 public void mousePressed(MouseEvent e)
\r
291 colourButtonPressed(e);
\r
295 buttonPanel.add(button, null);
\r
298 protected void okButton_actionPerformed()
\r
300 applyButton_actionPerformed();
\r
301 frame.setVisible(false);
\r
304 protected void applyButton_actionPerformed()
\r
306 if (caller != null)
\r
308 if (caller instanceof FeatureSettings)
\r
310 ( (FeatureSettings) caller).setUserColour
\r
311 (originalLabel, new Color(R, G, B));
\r
313 else if (caller instanceof AnnotationColourChooser)
\r
315 if (originalLabel.equals("Min Colour"))
\r
317 ( (AnnotationColourChooser) caller).minColour_actionPerformed
\r
318 (new Color(R, G, B));
\r
322 ( (AnnotationColourChooser) caller).maxColour_actionPerformed
\r
323 (new Color(R, G, B));
\r
329 Color[] newColours = new Color[24];
\r
330 for (int i = 0; i < 24; i++)
\r
332 Button button = (Button) buttonPanel.getComponent(i);
\r
333 newColours[i] = button.getBackground();
\r
336 UserColourScheme ucs = new UserColourScheme(newColours);
\r
339 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
\r
344 if (seqGroup != null)
\r
350 ap.av.setGlobalColourScheme(ucs);
\r
352 ap.seqPanel.seqCanvas.img = null;
\r
353 ap.paintAlignment(true);
\r
355 else if(jmol!=null)
\r
357 jmol.setJalviewColourScheme(ucs);
\r
359 else if (pdbcanvas != null)
\r
361 pdbcanvas.setColours(ucs);
\r
365 protected void cancelButton_actionPerformed()
\r
367 if (caller != null)
\r
369 if (caller instanceof FeatureSettings)
\r
371 ( (FeatureSettings) caller).setUserColour
\r
372 (originalLabel, originalColour);
\r
374 else if (caller instanceof AnnotationColourChooser)
\r
376 if (originalLabel.equals("Min Colour"))
\r
378 ( (AnnotationColourChooser) caller).minColour_actionPerformed
\r
383 ( (AnnotationColourChooser) caller).maxColour_actionPerformed
\r
387 frame.setVisible(false);
\r
391 Color[] newColours = new Color[24];
\r
392 for (int i = 0; i < 24; i++)
\r
394 newColours[i] = (Color) oldColours.elementAt(i);
\r
395 buttonPanel.getComponent(i).setBackground(newColours[i]);
\r
398 UserColourScheme ucs = new UserColourScheme(newColours);
\r
402 if (seqGroup != null)
\r
408 ap.av.setGlobalColourScheme(ucs);
\r
410 ap.paintAlignment(true);
\r
412 else if(jmol !=null)
\r
414 jmol.setJalviewColourScheme(ucs);
\r
416 else if (pdbcanvas != null)
\r
418 pdbcanvas.pdb.setColours(ucs);
\r
421 frame.setVisible(false);
\r
424 protected Panel buttonPanel = new Panel();
\r
425 protected GridLayout gridLayout = new GridLayout();
\r
426 Panel okcancelPanel = new Panel();
\r
427 protected Button okButton = new Button();
\r
428 protected Button applyButton = new Button();
\r
429 protected Button cancelButton = new Button();
\r
430 protected Scrollbar rScroller = new Scrollbar();
\r
431 Label label1 = new Label();
\r
432 protected TextField rText = new TextField();
\r
433 Label label4 = new Label();
\r
434 protected Scrollbar gScroller = new Scrollbar();
\r
435 protected TextField gText = new TextField();
\r
436 Label label5 = new Label();
\r
437 protected Scrollbar bScroller = new Scrollbar();
\r
438 protected TextField bText = new TextField();
\r
439 protected Panel target = new Panel();
\r
441 private void jbInit()
\r
444 this.setLayout(null);
\r
445 buttonPanel.setLayout(gridLayout);
\r
446 gridLayout.setColumns(6);
\r
447 gridLayout.setRows(4);
\r
448 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
449 okButton.setLabel("OK");
\r
450 okButton.addActionListener(this);
\r
451 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
452 applyButton.setLabel("Apply");
\r
453 applyButton.addActionListener(this);
\r
454 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
455 cancelButton.setLabel("Cancel");
\r
456 cancelButton.addActionListener(this);
\r
457 this.setBackground(new Color(212, 208, 223));
\r
458 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
\r
459 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
\r
460 rScroller.setMaximum(256);
\r
461 rScroller.setMinimum(0);
\r
462 rScroller.setOrientation(0);
\r
463 rScroller.setUnitIncrement(1);
\r
464 rScroller.setVisibleAmount(1);
\r
465 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
\r
466 rScroller.addAdjustmentListener(this);
\r
467 label1.setAlignment(Label.RIGHT);
\r
468 label1.setText("R");
\r
469 label1.setBounds(new Rectangle(19, 30, 16, 15));
\r
470 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
471 rText.setText("0 ");
\r
472 rText.setBounds(new Rectangle(156, 27, 53, 19));
\r
473 rText.addActionListener(this);
\r
474 label4.setAlignment(Label.RIGHT);
\r
475 label4.setText("G");
\r
476 label4.setBounds(new Rectangle(15, 56, 20, 15));
\r
477 gScroller.setMaximum(256);
\r
478 gScroller.setMinimum(0);
\r
479 gScroller.setOrientation(0);
\r
480 gScroller.setUnitIncrement(1);
\r
481 gScroller.setVisibleAmount(1);
\r
482 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
\r
483 gScroller.addAdjustmentListener(this);
\r
484 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
485 gText.setText("0 ");
\r
486 gText.setBounds(new Rectangle(156, 52, 53, 20));
\r
487 gText.addActionListener(this);
\r
488 label5.setAlignment(Label.RIGHT);
\r
489 label5.setText("B");
\r
490 label5.setBounds(new Rectangle(14, 82, 20, 15));
\r
491 bScroller.setMaximum(256);
\r
492 bScroller.setMinimum(0);
\r
493 bScroller.setOrientation(0);
\r
494 bScroller.setUnitIncrement(1);
\r
495 bScroller.setVisibleAmount(1);
\r
496 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
\r
497 bScroller.addAdjustmentListener(this);
\r
498 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
499 bText.setText("0 ");
\r
500 bText.setBounds(new Rectangle(157, 78, 52, 20));
\r
501 bText.addActionListener(this);
\r
502 target.setBackground(Color.black);
\r
503 target.setBounds(new Rectangle(229, 26, 134, 79));
\r
504 this.add(okcancelPanel, null);
\r
505 okcancelPanel.add(okButton, null);
\r
506 okcancelPanel.add(applyButton, null);
\r
507 okcancelPanel.add(cancelButton, null);
\r
508 this.add(buttonPanel, null);
\r
509 this.add(target, null);
\r
510 this.add(gScroller);
\r
511 this.add(rScroller);
\r
512 this.add(bScroller);
\r