2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.datamodel.*;
27 import jalview.schemes.*;
29 public class UserDefinedColours extends Panel implements ActionListener,
35 SequenceGroup seqGroup;
37 Button selectedButton;
39 Vector oldColours = new Vector();
41 ColourSchemeI oldColourScheme;
45 MCview.AppletPDBCanvas pdbcanvas;
55 Object originalColour;
57 int R = 0, G = 0, B = 0;
59 public ColourSchemeI loadDefaultColours()
61 // NOT IMPLEMENTED YET IN APPLET VERSION
65 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
72 oldColourScheme = seqGroup.cs;
76 oldColourScheme = ap.av.getGlobalColourScheme();
82 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
88 public UserDefinedColours(AppletJmol jmol)
94 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
97 originalColour = fr.colourPanel.getBackground();
98 originalLabel = "Feature Colour";
99 setForDialog("Select Feature Colour", alignframe);
100 setTargetColour(fr.colourPanel.getBackground());
101 dialog.setVisible(true);
104 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
106 this(caller, col1, alignframe, "Select Colour");
110 * Makes a dialog to choose the colour
117 * - the parent Frame for the dialog
121 public UserDefinedColours(Component caller, Color col1, Frame alignframe,
124 this.caller = caller;
125 originalColour = col1;
126 originalLabel = title;
127 setForDialog(title, alignframe);
128 setTargetColour(col1);
129 dialog.setVisible(true);
133 * feature colour chooser
139 public UserDefinedColours(Object caller, String label, Color colour)
141 this(caller, label, colour, colour);
145 * feature colour chooser when changing style to single color
149 * @param graduatedColor
151 public UserDefinedColours(FeatureSettings me, String type,
152 GraduatedColor graduatedColor)
154 this(me, type, graduatedColor, graduatedColor.getMaxColor());
157 private UserDefinedColours(Object caller, String label, Object ocolour,
160 this.caller = caller;
161 originalColour = ocolour;
162 originalLabel = label;
166 setTargetColour(colour);
168 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
169 frame.setTitle("User Defined Colours - " + label);
170 frame.setSize(420, 200);
173 void setForDialog(String title, Container alignframe)
176 frame.setVisible(false);
178 if (alignframe instanceof Frame)
180 dialog = new Dialog((Frame) alignframe, title, true);
184 // if (alignframe instanceof JVDialog){
185 // // not 1.1 compatible!
186 // dialog = new Dialog(((JVDialog)alignframe), title, true);
188 throw new Error("Unsupported owner for User Colour scheme dialog.");
192 this.setSize(400, 123);
193 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
194 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
197 dialog.setBounds(alignframe.getBounds().x
198 + (alignframe.getSize().width - width) / 2, alignframe
200 + (alignframe.getSize().height - height) / 2, width, height);
204 public void actionPerformed(ActionEvent evt)
206 if (evt.getSource() == okButton)
208 okButton_actionPerformed();
210 else if (evt.getSource() == applyButton)
212 applyButton_actionPerformed();
214 else if (evt.getSource() == cancelButton)
216 cancelButton_actionPerformed();
218 else if (evt.getSource() == rText)
220 rText_actionPerformed();
222 else if (evt.getSource() == gText)
224 gText_actionPerformed();
226 else if (evt.getSource() == bText)
228 bText_actionPerformed();
232 public void adjustmentValueChanged(AdjustmentEvent evt)
234 if (evt.getSource() == rScroller)
236 rScroller_adjustmentValueChanged();
238 else if (evt.getSource() == gScroller)
240 gScroller_adjustmentValueChanged();
242 else if (evt.getSource() == bScroller)
244 bScroller_adjustmentValueChanged();
253 } catch (Exception e)
259 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420,
262 if (seqGroup != null)
264 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
267 for (int i = 0; i < 20; i++)
269 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
270 + "", ResidueProperties.aa[i]);
273 makeButton("B", "B");
274 makeButton("Z", "Z");
275 makeButton("X", "X");
276 makeButton("Gap", "'.','-',' '");
281 protected void rText_actionPerformed()
285 int i = Integer.parseInt(rText.getText());
286 rScroller.setValue(i);
287 rScroller_adjustmentValueChanged();
288 } catch (NumberFormatException ex)
293 protected void gText_actionPerformed()
297 int i = Integer.parseInt(gText.getText());
298 gScroller.setValue(i);
299 gScroller_adjustmentValueChanged();
300 } catch (NumberFormatException ex)
306 protected void bText_actionPerformed()
310 int i = Integer.parseInt(bText.getText());
311 bScroller.setValue(i);
312 bScroller_adjustmentValueChanged();
313 } catch (NumberFormatException ex)
319 protected void rScroller_adjustmentValueChanged()
321 R = rScroller.getValue();
322 rText.setText(R + "");
326 protected void gScroller_adjustmentValueChanged()
328 G = gScroller.getValue();
329 gText.setText(G + "");
333 protected void bScroller_adjustmentValueChanged()
335 B = bScroller.getValue();
336 bText.setText(B + "");
340 public void colourChanged()
342 Color col = new Color(R, G, B);
343 target.setBackground(col);
346 if (selectedButton != null)
348 selectedButton.setBackground(col);
349 selectedButton.repaint();
353 void setTargetColour(Color col)
359 rScroller.setValue(R);
360 gScroller.setValue(G);
361 bScroller.setValue(B);
362 rText.setText(R + "");
363 gText.setText(G + "");
364 bText.setText(B + "");
368 public void colourButtonPressed(MouseEvent e)
370 selectedButton = (Button) e.getSource();
371 setTargetColour(selectedButton.getBackground());
374 void makeButton(String label, String aa)
376 final Button button = new Button();
377 Color col = Color.white;
378 if (oldColourScheme != null)
382 col = oldColourScheme.findColour(aa.charAt(0), -1);
383 } catch (Exception ex)
387 button.setBackground(col);
388 oldColours.addElement(col);
389 button.setLabel(label);
390 button.setForeground(col.darker().darker().darker());
391 button.setFont(new java.awt.Font("Verdana", 1, 10));
392 button.addMouseListener(new java.awt.event.MouseAdapter()
394 public void mousePressed(MouseEvent e)
396 colourButtonPressed(e);
400 buttonPanel.add(button, null);
403 protected void okButton_actionPerformed()
405 applyButton_actionPerformed();
407 dialog.setVisible(false);
409 frame.setVisible(false);
412 public Color getColor()
414 return new Color(R, G, B);
417 protected void applyButton_actionPerformed()
421 if (caller instanceof FeatureSettings)
423 ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
425 else if (caller instanceof AnnotationColourChooser)
427 if (originalLabel.equals("Min Colour"))
429 ((AnnotationColourChooser) caller)
430 .minColour_actionPerformed(getColor());
434 ((AnnotationColourChooser) caller)
435 .maxColour_actionPerformed(getColor());
438 else if (caller instanceof FeatureRenderer)
440 ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
442 else if (caller instanceof FeatureColourChooser)
444 if (originalLabel.indexOf("inimum") > -1)
446 ((FeatureColourChooser) caller)
447 .minColour_actionPerformed(getColor());
451 ((FeatureColourChooser) caller)
452 .maxColour_actionPerformed(getColor());
459 Color[] newColours = new Color[24];
460 for (int i = 0; i < 24; i++)
462 Button button = (Button) buttonPanel.getComponent(i);
463 newColours[i] = button.getBackground();
466 UserColourScheme ucs = new UserColourScheme(newColours);
469 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
474 if (seqGroup != null)
480 ap.av.setGlobalColourScheme(ucs);
482 ap.seqPanel.seqCanvas.img = null;
483 ap.paintAlignment(true);
485 else if (jmol != null)
487 jmol.setJalviewColourScheme(ucs);
489 else if (pdbcanvas != null)
491 pdbcanvas.setColours(ucs);
495 protected void cancelButton_actionPerformed()
499 if (caller instanceof FeatureSettings)
501 ((FeatureSettings) caller).setUserColour(originalLabel,
504 else if (caller instanceof AnnotationColourChooser)
506 if (originalLabel.equals("Min Colour"))
508 ((AnnotationColourChooser) caller)
509 .minColour_actionPerformed((Color) originalColour);
513 ((AnnotationColourChooser) caller)
514 .maxColour_actionPerformed((Color) originalColour);
517 else if (caller instanceof FeatureRenderer)
519 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
523 else if (caller instanceof FeatureColourChooser)
525 if (originalLabel.indexOf("inimum") > -1)
527 ((FeatureColourChooser) caller)
528 .minColour_actionPerformed((Color) originalColour);
532 ((FeatureColourChooser) caller)
533 .maxColour_actionPerformed((Color) originalColour);
537 dialog.setVisible(false);
539 frame.setVisible(false);
543 Color[] newColours = new Color[24];
544 for (int i = 0; i < 24; i++)
546 newColours[i] = (Color) oldColours.elementAt(i);
547 buttonPanel.getComponent(i).setBackground(newColours[i]);
550 UserColourScheme ucs = new UserColourScheme(newColours);
554 if (seqGroup != null)
560 ap.av.setGlobalColourScheme(ucs);
562 ap.paintAlignment(true);
564 else if (jmol != null)
566 jmol.setJalviewColourScheme(ucs);
568 else if (pdbcanvas != null)
570 pdbcanvas.pdb.setColours(ucs);
573 frame.setVisible(false);
576 protected Panel buttonPanel = new Panel();
578 protected GridLayout gridLayout = new GridLayout();
580 Panel okcancelPanel = new Panel();
582 protected Button okButton = new Button();
584 protected Button applyButton = new Button();
586 protected Button cancelButton = new Button();
588 protected Scrollbar rScroller = new Scrollbar();
590 Label label1 = new Label();
592 protected TextField rText = new TextField();
594 Label label4 = new Label();
596 protected Scrollbar gScroller = new Scrollbar();
598 protected TextField gText = new TextField();
600 Label label5 = new Label();
602 protected Scrollbar bScroller = new Scrollbar();
604 protected TextField bText = new TextField();
606 protected Panel target = new Panel();
608 private void jbInit() throws Exception
610 this.setLayout(null);
611 buttonPanel.setLayout(gridLayout);
612 gridLayout.setColumns(6);
613 gridLayout.setRows(4);
614 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
615 okButton.setLabel("OK");
616 okButton.addActionListener(this);
617 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
618 applyButton.setLabel("Apply");
619 applyButton.addActionListener(this);
620 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
621 cancelButton.setLabel("Cancel");
622 cancelButton.addActionListener(this);
623 this.setBackground(new Color(212, 208, 223));
624 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
625 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
626 rScroller.setMaximum(256);
627 rScroller.setMinimum(0);
628 rScroller.setOrientation(0);
629 rScroller.setUnitIncrement(1);
630 rScroller.setVisibleAmount(1);
631 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
632 rScroller.addAdjustmentListener(this);
633 label1.setAlignment(Label.RIGHT);
635 label1.setBounds(new Rectangle(19, 30, 16, 15));
636 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
638 rText.setBounds(new Rectangle(156, 27, 53, 19));
639 rText.addActionListener(this);
640 label4.setAlignment(Label.RIGHT);
642 label4.setBounds(new Rectangle(15, 56, 20, 15));
643 gScroller.setMaximum(256);
644 gScroller.setMinimum(0);
645 gScroller.setOrientation(0);
646 gScroller.setUnitIncrement(1);
647 gScroller.setVisibleAmount(1);
648 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
649 gScroller.addAdjustmentListener(this);
650 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
652 gText.setBounds(new Rectangle(156, 52, 53, 20));
653 gText.addActionListener(this);
654 label5.setAlignment(Label.RIGHT);
656 label5.setBounds(new Rectangle(14, 82, 20, 15));
657 bScroller.setMaximum(256);
658 bScroller.setMinimum(0);
659 bScroller.setOrientation(0);
660 bScroller.setUnitIncrement(1);
661 bScroller.setVisibleAmount(1);
662 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
663 bScroller.addAdjustmentListener(this);
664 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
666 bText.setBounds(new Rectangle(157, 78, 52, 20));
667 bText.addActionListener(this);
668 target.setBackground(Color.black);
669 target.setBounds(new Rectangle(229, 26, 134, 79));
670 this.add(okcancelPanel, null);
671 okcancelPanel.add(okButton, null);
672 okcancelPanel.add(applyButton, null);
673 okcancelPanel.add(cancelButton, null);
674 this.add(buttonPanel, null);
675 this.add(target, null);