2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.appletgui;
21 import jalview.datamodel.SequenceGroup;
22 import jalview.schemes.ColourSchemeI;
23 import jalview.schemes.GraduatedColor;
24 import jalview.schemes.ResidueProperties;
25 import jalview.schemes.UserColourScheme;
26 import jalview.util.MessageManager;
28 import java.awt.Button;
29 import java.awt.Color;
30 import java.awt.Component;
31 import java.awt.Container;
32 import java.awt.Dialog;
34 import java.awt.Frame;
35 import java.awt.GridLayout;
36 import java.awt.Label;
37 import java.awt.Panel;
38 import java.awt.Rectangle;
39 import java.awt.Scrollbar;
40 import java.awt.TextField;
41 import java.awt.event.ActionEvent;
42 import java.awt.event.ActionListener;
43 import java.awt.event.AdjustmentEvent;
44 import java.awt.event.AdjustmentListener;
45 import java.awt.event.MouseEvent;
46 import java.util.Vector;
48 public class UserDefinedColours extends Panel implements ActionListener,
54 SequenceGroup seqGroup;
56 Button selectedButton;
58 Vector oldColours = new Vector();
60 ColourSchemeI oldColourScheme;
64 MCview.AppletPDBCanvas pdbcanvas;
74 Object originalColour;
76 int R = 0, G = 0, B = 0;
78 public ColourSchemeI loadDefaultColours()
80 // NOT IMPLEMENTED YET IN APPLET VERSION
84 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
91 oldColourScheme = seqGroup.cs;
95 oldColourScheme = ap.av.getGlobalColourScheme();
101 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
103 this.pdbcanvas = pdb;
107 public UserDefinedColours(AppletJmol jmol)
113 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
116 originalColour = fr.colourPanel.getBackground();
117 originalLabel = "Feature Colour";
118 setForDialog("Select Feature Colour", alignframe);
119 setTargetColour(fr.colourPanel.getBackground());
120 dialog.setVisible(true);
123 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
125 this(caller, col1, alignframe, "Select Colour");
129 * Makes a dialog to choose the colour
136 * - the parent Frame for the dialog
140 public UserDefinedColours(Component caller, Color col1, Frame alignframe,
143 this.caller = caller;
144 originalColour = col1;
145 originalLabel = title;
146 setForDialog(title, alignframe);
147 setTargetColour(col1);
148 dialog.setVisible(true);
152 * feature colour chooser
158 public UserDefinedColours(Object caller, String label, Color colour)
160 this(caller, label, colour, colour);
164 * feature colour chooser when changing style to single color
168 * @param graduatedColor
170 public UserDefinedColours(FeatureSettings me, String type,
171 GraduatedColor graduatedColor)
173 this(me, type, graduatedColor, graduatedColor.getMaxColor());
176 private UserDefinedColours(Object caller, String label, Object ocolour,
179 this.caller = caller;
180 originalColour = ocolour;
181 originalLabel = label;
185 setTargetColour(colour);
187 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
188 frame.setTitle("User Defined Colours - " + label);
189 frame.setSize(420, 200);
192 void setForDialog(String title, Container alignframe)
195 frame.setVisible(false);
197 if (alignframe instanceof Frame)
199 dialog = new Dialog((Frame) alignframe, title, true);
203 // if (alignframe instanceof JVDialog){
204 // // not 1.1 compatible!
205 // dialog = new Dialog(((JVDialog)alignframe), title, true);
207 throw new Error("Unsupported owner for User Colour scheme dialog.");
211 this.setSize(400, 123);
212 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
213 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
216 dialog.setBounds(alignframe.getBounds().x
217 + (alignframe.getSize().width - width) / 2,
218 alignframe.getBounds().y
219 + (alignframe.getSize().height - height) / 2, width,
224 public void actionPerformed(ActionEvent evt)
226 if (evt.getSource() == okButton)
228 okButton_actionPerformed();
230 else if (evt.getSource() == applyButton)
232 applyButton_actionPerformed();
234 else if (evt.getSource() == cancelButton)
236 cancelButton_actionPerformed();
238 else if (evt.getSource() == rText)
240 rText_actionPerformed();
242 else if (evt.getSource() == gText)
244 gText_actionPerformed();
246 else if (evt.getSource() == bText)
248 bText_actionPerformed();
252 public void adjustmentValueChanged(AdjustmentEvent evt)
254 if (evt.getSource() == rScroller)
256 rScroller_adjustmentValueChanged();
258 else if (evt.getSource() == gScroller)
260 gScroller_adjustmentValueChanged();
262 else if (evt.getSource() == bScroller)
264 bScroller_adjustmentValueChanged();
273 } catch (Exception e)
279 jalview.bin.JalviewLite.addFrame(frame, MessageManager.getString("label.user_defined_colours"), 420,
282 if (seqGroup != null)
284 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
287 for (int i = 0; i < 20; i++)
289 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
290 + "", ResidueProperties.aa[i]);
293 makeButton("B", "B");
294 makeButton("Z", "Z");
295 makeButton("X", "X");
296 makeButton("Gap", "'.','-',' '");
301 protected void rText_actionPerformed()
305 int i = Integer.parseInt(rText.getText());
306 rScroller.setValue(i);
307 rScroller_adjustmentValueChanged();
308 } catch (NumberFormatException ex)
313 protected void gText_actionPerformed()
317 int i = Integer.parseInt(gText.getText());
318 gScroller.setValue(i);
319 gScroller_adjustmentValueChanged();
320 } catch (NumberFormatException ex)
326 protected void bText_actionPerformed()
330 int i = Integer.parseInt(bText.getText());
331 bScroller.setValue(i);
332 bScroller_adjustmentValueChanged();
333 } catch (NumberFormatException ex)
339 protected void rScroller_adjustmentValueChanged()
341 R = rScroller.getValue();
342 rText.setText(R + "");
346 protected void gScroller_adjustmentValueChanged()
348 G = gScroller.getValue();
349 gText.setText(G + "");
353 protected void bScroller_adjustmentValueChanged()
355 B = bScroller.getValue();
356 bText.setText(B + "");
360 public void colourChanged()
362 Color col = new Color(R, G, B);
363 target.setBackground(col);
366 if (selectedButton != null)
368 selectedButton.setBackground(col);
369 selectedButton.repaint();
373 void setTargetColour(Color col)
379 rScroller.setValue(R);
380 gScroller.setValue(G);
381 bScroller.setValue(B);
382 rText.setText(R + "");
383 gText.setText(G + "");
384 bText.setText(B + "");
388 public void colourButtonPressed(MouseEvent e)
390 selectedButton = (Button) e.getSource();
391 setTargetColour(selectedButton.getBackground());
394 void makeButton(String label, String aa)
396 final Button button = new Button();
397 Color col = Color.white;
398 if (oldColourScheme != null)
402 col = oldColourScheme.findColour(aa.charAt(0), -1, null);
403 } catch (Exception ex)
407 button.setBackground(col);
408 oldColours.addElement(col);
409 button.setLabel(label);
410 button.setForeground(col.darker().darker().darker());
411 button.setFont(new java.awt.Font("Verdana", 1, 10));
412 button.addMouseListener(new java.awt.event.MouseAdapter()
414 public void mousePressed(MouseEvent e)
416 colourButtonPressed(e);
420 buttonPanel.add(button, null);
423 protected void okButton_actionPerformed()
425 applyButton_actionPerformed();
427 dialog.setVisible(false);
429 frame.setVisible(false);
432 public Color getColor()
434 return new Color(R, G, B);
437 protected void applyButton_actionPerformed()
441 if (caller instanceof FeatureSettings)
443 ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
445 else if (caller instanceof AnnotationColourChooser)
447 if (originalLabel.equals("Min Colour"))
449 ((AnnotationColourChooser) caller)
450 .minColour_actionPerformed(getColor());
454 ((AnnotationColourChooser) caller)
455 .maxColour_actionPerformed(getColor());
458 else if (caller instanceof FeatureRenderer)
460 ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
462 else if (caller instanceof FeatureColourChooser)
464 if (originalLabel.indexOf("inimum") > -1)
466 ((FeatureColourChooser) caller)
467 .minColour_actionPerformed(getColor());
471 ((FeatureColourChooser) caller)
472 .maxColour_actionPerformed(getColor());
479 Color[] newColours = new Color[24];
480 for (int i = 0; i < 24; i++)
482 Button button = (Button) buttonPanel.getComponent(i);
483 newColours[i] = button.getBackground();
486 UserColourScheme ucs = new UserColourScheme(newColours);
489 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
494 if (seqGroup != null)
500 ap.av.setGlobalColourScheme(ucs);
502 ap.seqPanel.seqCanvas.img = null;
503 ap.paintAlignment(true);
505 else if (jmol != null)
507 jmol.setJalviewColourScheme(ucs);
509 else if (pdbcanvas != null)
511 pdbcanvas.setColours(ucs);
515 protected void cancelButton_actionPerformed()
519 if (caller instanceof FeatureSettings)
521 ((FeatureSettings) caller).setUserColour(originalLabel,
524 else if (caller instanceof AnnotationColourChooser)
526 if (originalLabel.equals("Min Colour"))
528 ((AnnotationColourChooser) caller)
529 .minColour_actionPerformed((Color) originalColour);
533 ((AnnotationColourChooser) caller)
534 .maxColour_actionPerformed((Color) originalColour);
537 else if (caller instanceof FeatureRenderer)
539 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
543 else if (caller instanceof FeatureColourChooser)
545 if (originalLabel.indexOf("inimum") > -1)
547 ((FeatureColourChooser) caller)
548 .minColour_actionPerformed((Color) originalColour);
552 ((FeatureColourChooser) caller)
553 .maxColour_actionPerformed((Color) originalColour);
557 dialog.setVisible(false);
559 frame.setVisible(false);
563 Color[] newColours = new Color[24];
564 for (int i = 0; i < 24; i++)
566 newColours[i] = (Color) oldColours.elementAt(i);
567 buttonPanel.getComponent(i).setBackground(newColours[i]);
570 UserColourScheme ucs = new UserColourScheme(newColours);
574 if (seqGroup != null)
580 ap.av.setGlobalColourScheme(ucs);
582 ap.paintAlignment(true);
584 else if (jmol != null)
586 jmol.setJalviewColourScheme(ucs);
588 else if (pdbcanvas != null)
590 pdbcanvas.pdb.setColours(ucs);
593 frame.setVisible(false);
596 protected Panel buttonPanel = new Panel();
598 protected GridLayout gridLayout = new GridLayout();
600 Panel okcancelPanel = new Panel();
602 protected Button okButton = new Button();
604 protected Button applyButton = new Button();
606 protected Button cancelButton = new Button();
608 protected Scrollbar rScroller = new Scrollbar();
610 Label label1 = new Label();
612 protected TextField rText = new TextField();
614 Label label4 = new Label();
616 protected Scrollbar gScroller = new Scrollbar();
618 protected TextField gText = new TextField();
620 Label label5 = new Label();
622 protected Scrollbar bScroller = new Scrollbar();
624 protected TextField bText = new TextField();
626 protected Panel target = new Panel();
628 private void jbInit() throws Exception
630 this.setLayout(null);
631 buttonPanel.setLayout(gridLayout);
632 gridLayout.setColumns(6);
633 gridLayout.setRows(4);
634 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
635 okButton.setLabel(MessageManager.getString("action.ok"));
636 okButton.addActionListener(this);
637 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
638 applyButton.setLabel(MessageManager.getString("action.apply"));
639 applyButton.addActionListener(this);
640 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
641 cancelButton.setLabel(MessageManager.getString("action.cancel"));
642 cancelButton.addActionListener(this);
643 this.setBackground(new Color(212, 208, 223));
644 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
645 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
646 rScroller.setMaximum(256);
647 rScroller.setMinimum(0);
648 rScroller.setOrientation(0);
649 rScroller.setUnitIncrement(1);
650 rScroller.setVisibleAmount(1);
651 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
652 rScroller.addAdjustmentListener(this);
653 label1.setAlignment(Label.RIGHT);
655 label1.setBounds(new Rectangle(19, 30, 16, 15));
656 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
658 rText.setBounds(new Rectangle(156, 27, 53, 19));
659 rText.addActionListener(this);
660 label4.setAlignment(Label.RIGHT);
662 label4.setBounds(new Rectangle(15, 56, 20, 15));
663 gScroller.setMaximum(256);
664 gScroller.setMinimum(0);
665 gScroller.setOrientation(0);
666 gScroller.setUnitIncrement(1);
667 gScroller.setVisibleAmount(1);
668 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
669 gScroller.addAdjustmentListener(this);
670 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
672 gText.setBounds(new Rectangle(156, 52, 53, 20));
673 gText.addActionListener(this);
674 label5.setAlignment(Label.RIGHT);
676 label5.setBounds(new Rectangle(14, 82, 20, 15));
677 bScroller.setMaximum(256);
678 bScroller.setMinimum(0);
679 bScroller.setOrientation(0);
680 bScroller.setUnitIncrement(1);
681 bScroller.setVisibleAmount(1);
682 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
683 bScroller.addAdjustmentListener(this);
684 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
686 bText.setBounds(new Rectangle(157, 78, 52, 20));
687 bText.addActionListener(this);
688 target.setBackground(Color.black);
689 target.setBounds(new Rectangle(229, 26, 134, 79));
690 this.add(okcancelPanel, null);
691 okcancelPanel.add(okButton, null);
692 okcancelPanel.add(applyButton, null);
693 okcancelPanel.add(cancelButton, null);
694 this.add(buttonPanel, null);
695 this.add(target, null);