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
45 String originalLabel;
\r
46 Color originalColour;
\r
48 int R = 0, G = 0, B = 0;
\r
50 public ColourSchemeI loadDefaultColours()
\r
52 // NOT IMPLEMENTED YET IN APPLET VERSION
\r
56 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
\r
61 if (seqGroup != null)
\r
63 oldColourScheme = seqGroup.cs;
\r
67 oldColourScheme = ap.av.getGlobalColourScheme();
\r
73 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
\r
75 this.pdbcanvas = pdb;
\r
79 public UserDefinedColours(AppletJmol jmol)
\r
85 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
\r
88 originalColour = fr.colourPanel.getBackground();
\r
89 originalLabel = "Feature Colour";
\r
90 setForDialog("Select Feature Colour", alignframe);
\r
91 setTargetColour(fr.colourPanel.getBackground());
\r
92 dialog.setVisible(true);
\r
95 public UserDefinedColours(Component caller,
\r
99 this.caller = caller;
\r
100 originalColour = col1;
\r
101 originalLabel = "Select Colour";
\r
102 setForDialog("Select Colour", alignframe);
\r
103 setTargetColour(col1);
\r
104 dialog.setVisible(true);
\r
108 public UserDefinedColours(Object caller,
\r
112 this.caller = caller;
\r
113 originalColour = colour;
\r
114 originalLabel = label;
\r
116 remove(buttonPanel);
\r
118 setTargetColour(colour);
\r
120 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
\r
121 frame.setTitle("User Defined Colours - " + label);
\r
122 frame.setSize(420, 200);
\r
125 void setForDialog(String title, Frame alignframe)
\r
128 frame.setVisible(false);
\r
129 remove(buttonPanel);
\r
130 dialog = new Dialog(alignframe, title, true);
\r
133 this.setSize(400,123);
\r
134 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
\r
135 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
\r
138 dialog.setBounds(alignframe.getBounds().x
\r
139 + (alignframe.getSize().width - width) / 2,
\r
140 alignframe.getBounds().y
\r
141 + (alignframe.getSize().height - height) / 2,
\r
146 public void actionPerformed(ActionEvent evt)
\r
148 if (evt.getSource() == okButton)
\r
150 okButton_actionPerformed();
\r
152 else if (evt.getSource() == applyButton)
\r
154 applyButton_actionPerformed();
\r
156 else if (evt.getSource() == cancelButton)
\r
158 cancelButton_actionPerformed();
\r
160 else if (evt.getSource() == rText)
\r
162 rText_actionPerformed();
\r
164 else if (evt.getSource() == gText)
\r
166 gText_actionPerformed();
\r
168 else if (evt.getSource() == bText)
\r
170 bText_actionPerformed();
\r
174 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
176 if (evt.getSource() == rScroller)
\r
178 rScroller_adjustmentValueChanged();
\r
180 else if (evt.getSource() == gScroller)
\r
182 gScroller_adjustmentValueChanged();
\r
184 else if (evt.getSource() == bScroller)
\r
186 bScroller_adjustmentValueChanged();
\r
196 catch (Exception e)
\r
198 e.printStackTrace();
\r
200 frame = new Frame();
\r
202 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420, 345);
\r
204 if (seqGroup != null)
\r
206 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
\r
209 for (int i = 0; i < 20; i++)
\r
211 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +
\r
212 "", ResidueProperties.aa[i]);
\r
215 makeButton("B", "B");
\r
216 makeButton("Z", "Z");
\r
217 makeButton("X", "X");
\r
218 makeButton("Gap", "'.','-',' '");
\r
223 protected void rText_actionPerformed()
\r
227 int i = Integer.parseInt(rText.getText());
\r
228 rScroller.setValue(i);
\r
229 rScroller_adjustmentValueChanged();
\r
231 catch (NumberFormatException ex)
\r
235 protected void gText_actionPerformed()
\r
239 int i = Integer.parseInt(gText.getText());
\r
240 gScroller.setValue(i);
\r
241 gScroller_adjustmentValueChanged();
\r
243 catch (NumberFormatException ex)
\r
248 protected void bText_actionPerformed()
\r
252 int i = Integer.parseInt(bText.getText());
\r
253 bScroller.setValue(i);
\r
254 bScroller_adjustmentValueChanged();
\r
256 catch (NumberFormatException ex)
\r
261 protected void rScroller_adjustmentValueChanged()
\r
263 R = rScroller.getValue();
\r
264 rText.setText(R + "");
\r
268 protected void gScroller_adjustmentValueChanged()
\r
270 G = gScroller.getValue();
\r
271 gText.setText(G + "");
\r
275 protected void bScroller_adjustmentValueChanged()
\r
277 B = bScroller.getValue();
\r
278 bText.setText(B + "");
\r
282 public void colourChanged()
\r
284 Color col = new Color(R, G, B);
\r
285 target.setBackground(col);
\r
288 if (selectedButton != null)
\r
290 selectedButton.setBackground(col);
\r
291 selectedButton.repaint();
\r
295 void setTargetColour(Color col)
\r
298 G = col.getGreen();
\r
301 rScroller.setValue(R);
\r
302 gScroller.setValue(G);
\r
303 bScroller.setValue(B);
\r
304 rText.setText(R + "");
\r
305 gText.setText(G + "");
\r
306 bText.setText(B + "");
\r
310 public void colourButtonPressed(MouseEvent e)
\r
312 selectedButton = (Button) e.getSource();
\r
313 setTargetColour(selectedButton.getBackground());
\r
316 void makeButton(String label, String aa)
\r
318 final Button button = new Button();
\r
319 Color col = Color.white;
\r
323 col = oldColourScheme.findColour(aa.charAt(0), -1);
\r
325 catch (Exception ex)
\r
328 button.setBackground(col);
\r
329 oldColours.addElement(col);
\r
330 button.setLabel(label);
\r
331 button.setForeground(col.darker().darker().darker());
\r
332 button.setFont(new java.awt.Font("Verdana", 1, 10));
\r
333 button.addMouseListener(new java.awt.event.MouseAdapter()
\r
335 public void mousePressed(MouseEvent e)
\r
337 colourButtonPressed(e);
\r
341 buttonPanel.add(button, null);
\r
344 protected void okButton_actionPerformed()
\r
346 applyButton_actionPerformed();
\r
347 if (dialog != null)
\r
348 dialog.setVisible(false);
\r
350 frame.setVisible(false);
\r
353 public Color getColor()
\r
355 return new Color(R, G, B);
\r
358 protected void applyButton_actionPerformed()
\r
360 if (caller != null)
\r
362 if (caller instanceof FeatureSettings)
\r
364 ( (FeatureSettings) caller).setUserColour
\r
365 (originalLabel, getColor());
\r
367 else if (caller instanceof AnnotationColourChooser)
\r
369 if (originalLabel.equals("Min Colour"))
\r
371 ( (AnnotationColourChooser) caller).minColour_actionPerformed
\r
376 ( (AnnotationColourChooser) caller).maxColour_actionPerformed
\r
380 else if(caller instanceof FeatureRenderer)
\r
382 ((FeatureRenderer)caller).colourPanel.setBackground(getColor());
\r
388 Color[] newColours = new Color[24];
\r
389 for (int i = 0; i < 24; i++)
\r
391 Button button = (Button) buttonPanel.getComponent(i);
\r
392 newColours[i] = button.getBackground();
\r
395 UserColourScheme ucs = new UserColourScheme(newColours);
\r
398 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
\r
403 if (seqGroup != null)
\r
409 ap.av.setGlobalColourScheme(ucs);
\r
411 ap.seqPanel.seqCanvas.img = null;
\r
412 ap.paintAlignment(true);
\r
414 else if(jmol!=null)
\r
416 jmol.setJalviewColourScheme(ucs);
\r
418 else if (pdbcanvas != null)
\r
420 pdbcanvas.setColours(ucs);
\r
424 protected void cancelButton_actionPerformed()
\r
426 if (caller != null)
\r
428 if (caller instanceof FeatureSettings)
\r
430 ( (FeatureSettings) caller).setUserColour
\r
431 (originalLabel, originalColour);
\r
433 else if (caller instanceof AnnotationColourChooser)
\r
435 if (originalLabel.equals("Min Colour"))
\r
437 ( (AnnotationColourChooser) caller).minColour_actionPerformed
\r
442 ( (AnnotationColourChooser) caller).maxColour_actionPerformed
\r
446 else if (caller instanceof FeatureRenderer)
\r
448 ( (FeatureRenderer) caller).colourPanel.setBackground(originalColour);
\r
453 dialog.setVisible(false);
\r
455 frame.setVisible(false);
\r
459 Color[] newColours = new Color[24];
\r
460 for (int i = 0; i < 24; i++)
\r
462 newColours[i] = (Color) oldColours.elementAt(i);
\r
463 buttonPanel.getComponent(i).setBackground(newColours[i]);
\r
466 UserColourScheme ucs = new UserColourScheme(newColours);
\r
470 if (seqGroup != null)
\r
476 ap.av.setGlobalColourScheme(ucs);
\r
478 ap.paintAlignment(true);
\r
480 else if(jmol !=null)
\r
482 jmol.setJalviewColourScheme(ucs);
\r
484 else if (pdbcanvas != null)
\r
486 pdbcanvas.pdb.setColours(ucs);
\r
489 frame.setVisible(false);
\r
492 protected Panel buttonPanel = new Panel();
\r
493 protected GridLayout gridLayout = new GridLayout();
\r
494 Panel okcancelPanel = new Panel();
\r
495 protected Button okButton = new Button();
\r
496 protected Button applyButton = new Button();
\r
497 protected Button cancelButton = new Button();
\r
498 protected Scrollbar rScroller = new Scrollbar();
\r
499 Label label1 = new Label();
\r
500 protected TextField rText = new TextField();
\r
501 Label label4 = new Label();
\r
502 protected Scrollbar gScroller = new Scrollbar();
\r
503 protected TextField gText = new TextField();
\r
504 Label label5 = new Label();
\r
505 protected Scrollbar bScroller = new Scrollbar();
\r
506 protected TextField bText = new TextField();
\r
507 protected Panel target = new Panel();
\r
509 private void jbInit()
\r
512 this.setLayout(null);
\r
513 buttonPanel.setLayout(gridLayout);
\r
514 gridLayout.setColumns(6);
\r
515 gridLayout.setRows(4);
\r
516 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
517 okButton.setLabel("OK");
\r
518 okButton.addActionListener(this);
\r
519 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
520 applyButton.setLabel("Apply");
\r
521 applyButton.addActionListener(this);
\r
522 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
523 cancelButton.setLabel("Cancel");
\r
524 cancelButton.addActionListener(this);
\r
525 this.setBackground(new Color(212, 208, 223));
\r
526 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
\r
527 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
\r
528 rScroller.setMaximum(256);
\r
529 rScroller.setMinimum(0);
\r
530 rScroller.setOrientation(0);
\r
531 rScroller.setUnitIncrement(1);
\r
532 rScroller.setVisibleAmount(1);
\r
533 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
\r
534 rScroller.addAdjustmentListener(this);
\r
535 label1.setAlignment(Label.RIGHT);
\r
536 label1.setText("R");
\r
537 label1.setBounds(new Rectangle(19, 30, 16, 15));
\r
538 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
539 rText.setText("0 ");
\r
540 rText.setBounds(new Rectangle(156, 27, 53, 19));
\r
541 rText.addActionListener(this);
\r
542 label4.setAlignment(Label.RIGHT);
\r
543 label4.setText("G");
\r
544 label4.setBounds(new Rectangle(15, 56, 20, 15));
\r
545 gScroller.setMaximum(256);
\r
546 gScroller.setMinimum(0);
\r
547 gScroller.setOrientation(0);
\r
548 gScroller.setUnitIncrement(1);
\r
549 gScroller.setVisibleAmount(1);
\r
550 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
\r
551 gScroller.addAdjustmentListener(this);
\r
552 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
553 gText.setText("0 ");
\r
554 gText.setBounds(new Rectangle(156, 52, 53, 20));
\r
555 gText.addActionListener(this);
\r
556 label5.setAlignment(Label.RIGHT);
\r
557 label5.setText("B");
\r
558 label5.setBounds(new Rectangle(14, 82, 20, 15));
\r
559 bScroller.setMaximum(256);
\r
560 bScroller.setMinimum(0);
\r
561 bScroller.setOrientation(0);
\r
562 bScroller.setUnitIncrement(1);
\r
563 bScroller.setVisibleAmount(1);
\r
564 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
\r
565 bScroller.addAdjustmentListener(this);
\r
566 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
567 bText.setText("0 ");
\r
568 bText.setBounds(new Rectangle(157, 78, 52, 20));
\r
569 bText.addActionListener(this);
\r
570 target.setBackground(Color.black);
\r
571 target.setBounds(new Rectangle(229, 26, 134, 79));
\r
572 this.add(okcancelPanel, null);
\r
573 okcancelPanel.add(okButton, null);
\r
574 okcancelPanel.add(applyButton, null);
\r
575 okcancelPanel.add(cancelButton, null);
\r
576 this.add(buttonPanel, null);
\r
577 this.add(target, null);
\r
578 this.add(gScroller);
\r
579 this.add(rScroller);
\r
580 this.add(bScroller);
\r