2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
23 import java.awt.event.*;
25 import jalview.datamodel.*;
26 import jalview.schemes.*;
28 public class UserDefinedColours extends Panel implements ActionListener,
34 SequenceGroup seqGroup;
36 Button selectedButton;
38 Vector oldColours = new Vector();
40 ColourSchemeI oldColourScheme;
44 MCview.AppletPDBCanvas pdbcanvas;
54 Object originalColour;
56 int R = 0, G = 0, B = 0;
58 public ColourSchemeI loadDefaultColours()
60 // NOT IMPLEMENTED YET IN APPLET VERSION
64 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
71 oldColourScheme = seqGroup.cs;
75 oldColourScheme = ap.av.getGlobalColourScheme();
81 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
87 public UserDefinedColours(AppletJmol jmol)
93 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
96 originalColour = fr.colourPanel.getBackground();
97 originalLabel = "Feature Colour";
98 setForDialog("Select Feature Colour", alignframe);
99 setTargetColour(fr.colourPanel.getBackground());
100 dialog.setVisible(true);
103 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
105 this(caller, col1, alignframe, "Select Colour");
109 * Makes a dialog to choose the colour
116 * - the parent Frame for the dialog
120 public UserDefinedColours(Component caller, Color col1, Frame alignframe,
123 this.caller = caller;
124 originalColour = col1;
125 originalLabel = title;
126 setForDialog(title, alignframe);
127 setTargetColour(col1);
128 dialog.setVisible(true);
132 * feature colour chooser
138 public UserDefinedColours(Object caller, String label, Color colour)
140 this(caller, label, colour, colour);
144 * feature colour chooser when changing style to single color
148 * @param graduatedColor
150 public UserDefinedColours(FeatureSettings me, String type,
151 GraduatedColor graduatedColor)
153 this(me, type, graduatedColor, graduatedColor.getMaxColor());
156 private UserDefinedColours(Object caller, String label, Object ocolour,
159 this.caller = caller;
160 originalColour = ocolour;
161 originalLabel = label;
165 setTargetColour(colour);
167 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
168 frame.setTitle("User Defined Colours - " + label);
169 frame.setSize(420, 200);
172 void setForDialog(String title, Container alignframe)
175 frame.setVisible(false);
177 if (alignframe instanceof Frame)
179 dialog = new Dialog((Frame) alignframe, title, true);
183 // if (alignframe instanceof JVDialog){
184 // // not 1.1 compatible!
185 // dialog = new Dialog(((JVDialog)alignframe), title, true);
187 throw new Error("Unsupported owner for User Colour scheme dialog.");
191 this.setSize(400, 123);
192 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
193 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
196 dialog.setBounds(alignframe.getBounds().x
197 + (alignframe.getSize().width - width) / 2,
198 alignframe.getBounds().y
199 + (alignframe.getSize().height - height) / 2, width,
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);