2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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;
20 import jalview.datamodel.SequenceGroup;
21 import jalview.schemes.ColourSchemeI;
22 import jalview.schemes.GraduatedColor;
23 import jalview.schemes.ResidueProperties;
24 import jalview.schemes.UserColourScheme;
26 import java.awt.Button;
27 import java.awt.Color;
28 import java.awt.Component;
29 import java.awt.Container;
30 import java.awt.Dialog;
32 import java.awt.Frame;
33 import java.awt.GridLayout;
34 import java.awt.Label;
35 import java.awt.Panel;
36 import java.awt.Rectangle;
37 import java.awt.Scrollbar;
38 import java.awt.TextField;
39 import java.awt.event.ActionEvent;
40 import java.awt.event.ActionListener;
41 import java.awt.event.AdjustmentEvent;
42 import java.awt.event.AdjustmentListener;
43 import java.awt.event.MouseEvent;
44 import java.util.Vector;
46 public class UserDefinedColours extends Panel implements ActionListener,
52 SequenceGroup seqGroup;
54 Button selectedButton;
56 Vector oldColours = new Vector();
58 ColourSchemeI oldColourScheme;
62 MCview.AppletPDBCanvas pdbcanvas;
72 Object originalColour;
74 int R = 0, G = 0, B = 0;
76 public ColourSchemeI loadDefaultColours()
78 // NOT IMPLEMENTED YET IN APPLET VERSION
82 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
89 oldColourScheme = seqGroup.cs;
93 oldColourScheme = ap.av.getGlobalColourScheme();
99 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
101 this.pdbcanvas = pdb;
105 public UserDefinedColours(AppletJmol jmol)
111 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
114 originalColour = fr.colourPanel.getBackground();
115 originalLabel = "Feature Colour";
116 setForDialog("Select Feature Colour", alignframe);
117 setTargetColour(fr.colourPanel.getBackground());
118 dialog.setVisible(true);
121 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
123 this(caller, col1, alignframe, "Select Colour");
127 * Makes a dialog to choose the colour
134 * - the parent Frame for the dialog
138 public UserDefinedColours(Component caller, Color col1, Frame alignframe,
141 this.caller = caller;
142 originalColour = col1;
143 originalLabel = title;
144 setForDialog(title, alignframe);
145 setTargetColour(col1);
146 dialog.setVisible(true);
150 * feature colour chooser
156 public UserDefinedColours(Object caller, String label, Color colour)
158 this(caller, label, colour, colour);
162 * feature colour chooser when changing style to single color
166 * @param graduatedColor
168 public UserDefinedColours(FeatureSettings me, String type,
169 GraduatedColor graduatedColor)
171 this(me, type, graduatedColor, graduatedColor.getMaxColor());
174 private UserDefinedColours(Object caller, String label, Object ocolour,
177 this.caller = caller;
178 originalColour = ocolour;
179 originalLabel = label;
183 setTargetColour(colour);
185 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
186 frame.setTitle("User Defined Colours - " + label);
187 frame.setSize(420, 200);
190 void setForDialog(String title, Container alignframe)
193 frame.setVisible(false);
195 if (alignframe instanceof Frame)
197 dialog = new Dialog((Frame) alignframe, title, true);
201 // if (alignframe instanceof JVDialog){
202 // // not 1.1 compatible!
203 // dialog = new Dialog(((JVDialog)alignframe), title, true);
205 throw new Error("Unsupported owner for User Colour scheme dialog.");
209 this.setSize(400, 123);
210 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
211 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
214 dialog.setBounds(alignframe.getBounds().x
215 + (alignframe.getSize().width - width) / 2,
216 alignframe.getBounds().y
217 + (alignframe.getSize().height - height) / 2, width,
222 public void actionPerformed(ActionEvent evt)
224 if (evt.getSource() == okButton)
226 okButton_actionPerformed();
228 else if (evt.getSource() == applyButton)
230 applyButton_actionPerformed();
232 else if (evt.getSource() == cancelButton)
234 cancelButton_actionPerformed();
236 else if (evt.getSource() == rText)
238 rText_actionPerformed();
240 else if (evt.getSource() == gText)
242 gText_actionPerformed();
244 else if (evt.getSource() == bText)
246 bText_actionPerformed();
250 public void adjustmentValueChanged(AdjustmentEvent evt)
252 if (evt.getSource() == rScroller)
254 rScroller_adjustmentValueChanged();
256 else if (evt.getSource() == gScroller)
258 gScroller_adjustmentValueChanged();
260 else if (evt.getSource() == bScroller)
262 bScroller_adjustmentValueChanged();
271 } catch (Exception e)
277 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420,
280 if (seqGroup != null)
282 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
285 for (int i = 0; i < 20; i++)
287 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
288 + "", ResidueProperties.aa[i]);
291 makeButton("B", "B");
292 makeButton("Z", "Z");
293 makeButton("X", "X");
294 makeButton("Gap", "'.','-',' '");
299 protected void rText_actionPerformed()
303 int i = Integer.parseInt(rText.getText());
304 rScroller.setValue(i);
305 rScroller_adjustmentValueChanged();
306 } catch (NumberFormatException ex)
311 protected void gText_actionPerformed()
315 int i = Integer.parseInt(gText.getText());
316 gScroller.setValue(i);
317 gScroller_adjustmentValueChanged();
318 } catch (NumberFormatException ex)
324 protected void bText_actionPerformed()
328 int i = Integer.parseInt(bText.getText());
329 bScroller.setValue(i);
330 bScroller_adjustmentValueChanged();
331 } catch (NumberFormatException ex)
337 protected void rScroller_adjustmentValueChanged()
339 R = rScroller.getValue();
340 rText.setText(R + "");
344 protected void gScroller_adjustmentValueChanged()
346 G = gScroller.getValue();
347 gText.setText(G + "");
351 protected void bScroller_adjustmentValueChanged()
353 B = bScroller.getValue();
354 bText.setText(B + "");
358 public void colourChanged()
360 Color col = new Color(R, G, B);
361 target.setBackground(col);
364 if (selectedButton != null)
366 selectedButton.setBackground(col);
367 selectedButton.repaint();
371 void setTargetColour(Color col)
377 rScroller.setValue(R);
378 gScroller.setValue(G);
379 bScroller.setValue(B);
380 rText.setText(R + "");
381 gText.setText(G + "");
382 bText.setText(B + "");
386 public void colourButtonPressed(MouseEvent e)
388 selectedButton = (Button) e.getSource();
389 setTargetColour(selectedButton.getBackground());
392 void makeButton(String label, String aa)
394 final Button button = new Button();
395 Color col = Color.white;
396 if (oldColourScheme != null)
400 col = oldColourScheme.findColour(aa.charAt(0), -1, null);
401 } catch (Exception ex)
405 button.setBackground(col);
406 oldColours.addElement(col);
407 button.setLabel(label);
408 button.setForeground(col.darker().darker().darker());
409 button.setFont(new java.awt.Font("Verdana", 1, 10));
410 button.addMouseListener(new java.awt.event.MouseAdapter()
412 public void mousePressed(MouseEvent e)
414 colourButtonPressed(e);
418 buttonPanel.add(button, null);
421 protected void okButton_actionPerformed()
423 applyButton_actionPerformed();
425 dialog.setVisible(false);
427 frame.setVisible(false);
430 public Color getColor()
432 return new Color(R, G, B);
435 protected void applyButton_actionPerformed()
439 if (caller instanceof FeatureSettings)
441 ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
443 else if (caller instanceof AnnotationColourChooser)
445 if (originalLabel.equals("Min Colour"))
447 ((AnnotationColourChooser) caller)
448 .minColour_actionPerformed(getColor());
452 ((AnnotationColourChooser) caller)
453 .maxColour_actionPerformed(getColor());
456 else if (caller instanceof FeatureRenderer)
458 ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
460 else if (caller instanceof FeatureColourChooser)
462 if (originalLabel.indexOf("inimum") > -1)
464 ((FeatureColourChooser) caller)
465 .minColour_actionPerformed(getColor());
469 ((FeatureColourChooser) caller)
470 .maxColour_actionPerformed(getColor());
477 Color[] newColours = new Color[24];
478 for (int i = 0; i < 24; i++)
480 Button button = (Button) buttonPanel.getComponent(i);
481 newColours[i] = button.getBackground();
484 UserColourScheme ucs = new UserColourScheme(newColours);
487 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
492 if (seqGroup != null)
498 ap.av.setGlobalColourScheme(ucs);
500 ap.seqPanel.seqCanvas.img = null;
501 ap.paintAlignment(true);
503 else if (jmol != null)
505 jmol.setJalviewColourScheme(ucs);
507 else if (pdbcanvas != null)
509 pdbcanvas.setColours(ucs);
513 protected void cancelButton_actionPerformed()
517 if (caller instanceof FeatureSettings)
519 ((FeatureSettings) caller).setUserColour(originalLabel,
522 else if (caller instanceof AnnotationColourChooser)
524 if (originalLabel.equals("Min Colour"))
526 ((AnnotationColourChooser) caller)
527 .minColour_actionPerformed((Color) originalColour);
531 ((AnnotationColourChooser) caller)
532 .maxColour_actionPerformed((Color) originalColour);
535 else if (caller instanceof FeatureRenderer)
537 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
541 else if (caller instanceof FeatureColourChooser)
543 if (originalLabel.indexOf("inimum") > -1)
545 ((FeatureColourChooser) caller)
546 .minColour_actionPerformed((Color) originalColour);
550 ((FeatureColourChooser) caller)
551 .maxColour_actionPerformed((Color) originalColour);
555 dialog.setVisible(false);
557 frame.setVisible(false);
561 Color[] newColours = new Color[24];
562 for (int i = 0; i < 24; i++)
564 newColours[i] = (Color) oldColours.elementAt(i);
565 buttonPanel.getComponent(i).setBackground(newColours[i]);
568 UserColourScheme ucs = new UserColourScheme(newColours);
572 if (seqGroup != null)
578 ap.av.setGlobalColourScheme(ucs);
580 ap.paintAlignment(true);
582 else if (jmol != null)
584 jmol.setJalviewColourScheme(ucs);
586 else if (pdbcanvas != null)
588 pdbcanvas.pdb.setColours(ucs);
591 frame.setVisible(false);
594 protected Panel buttonPanel = new Panel();
596 protected GridLayout gridLayout = new GridLayout();
598 Panel okcancelPanel = new Panel();
600 protected Button okButton = new Button();
602 protected Button applyButton = new Button();
604 protected Button cancelButton = new Button();
606 protected Scrollbar rScroller = new Scrollbar();
608 Label label1 = new Label();
610 protected TextField rText = new TextField();
612 Label label4 = new Label();
614 protected Scrollbar gScroller = new Scrollbar();
616 protected TextField gText = new TextField();
618 Label label5 = new Label();
620 protected Scrollbar bScroller = new Scrollbar();
622 protected TextField bText = new TextField();
624 protected Panel target = new Panel();
626 private void jbInit() throws Exception
628 this.setLayout(null);
629 buttonPanel.setLayout(gridLayout);
630 gridLayout.setColumns(6);
631 gridLayout.setRows(4);
632 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
633 okButton.setLabel("OK");
634 okButton.addActionListener(this);
635 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
636 applyButton.setLabel("Apply");
637 applyButton.addActionListener(this);
638 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
639 cancelButton.setLabel("Cancel");
640 cancelButton.addActionListener(this);
641 this.setBackground(new Color(212, 208, 223));
642 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
643 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
644 rScroller.setMaximum(256);
645 rScroller.setMinimum(0);
646 rScroller.setOrientation(0);
647 rScroller.setUnitIncrement(1);
648 rScroller.setVisibleAmount(1);
649 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
650 rScroller.addAdjustmentListener(this);
651 label1.setAlignment(Label.RIGHT);
653 label1.setBounds(new Rectangle(19, 30, 16, 15));
654 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
656 rText.setBounds(new Rectangle(156, 27, 53, 19));
657 rText.addActionListener(this);
658 label4.setAlignment(Label.RIGHT);
660 label4.setBounds(new Rectangle(15, 56, 20, 15));
661 gScroller.setMaximum(256);
662 gScroller.setMinimum(0);
663 gScroller.setOrientation(0);
664 gScroller.setUnitIncrement(1);
665 gScroller.setVisibleAmount(1);
666 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
667 gScroller.addAdjustmentListener(this);
668 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
670 gText.setBounds(new Rectangle(156, 52, 53, 20));
671 gText.addActionListener(this);
672 label5.setAlignment(Label.RIGHT);
674 label5.setBounds(new Rectangle(14, 82, 20, 15));
675 bScroller.setMaximum(256);
676 bScroller.setMinimum(0);
677 bScroller.setOrientation(0);
678 bScroller.setUnitIncrement(1);
679 bScroller.setVisibleAmount(1);
680 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
681 bScroller.addAdjustmentListener(this);
682 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
684 bText.setBounds(new Rectangle(157, 78, 52, 20));
685 bText.addActionListener(this);
686 target.setBackground(Color.black);
687 target.setBounds(new Rectangle(229, 26, 134, 79));
688 this.add(okcancelPanel, null);
689 okcancelPanel.add(okButton, null);
690 okcancelPanel.add(applyButton, null);
691 okcancelPanel.add(cancelButton, null);
692 this.add(buttonPanel, null);
693 this.add(target, null);