2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.datamodel.SequenceGroup;
24 import jalview.schemes.ColourSchemeI;
25 import jalview.schemes.GraduatedColor;
26 import jalview.schemes.ResidueProperties;
27 import jalview.schemes.UserColourScheme;
28 import jalview.util.MessageManager;
30 import java.awt.Button;
31 import java.awt.Color;
32 import java.awt.Component;
33 import java.awt.Container;
34 import java.awt.Dialog;
36 import java.awt.Frame;
37 import java.awt.GridLayout;
38 import java.awt.Label;
39 import java.awt.Panel;
40 import java.awt.Rectangle;
41 import java.awt.Scrollbar;
42 import java.awt.TextField;
43 import java.awt.event.ActionEvent;
44 import java.awt.event.ActionListener;
45 import java.awt.event.AdjustmentEvent;
46 import java.awt.event.AdjustmentListener;
47 import java.awt.event.MouseEvent;
48 import java.util.Vector;
50 public class UserDefinedColours extends Panel implements ActionListener,
56 SequenceGroup seqGroup;
58 Button selectedButton;
60 Vector oldColours = new Vector();
62 ColourSchemeI oldColourScheme;
66 MCview.AppletPDBCanvas pdbcanvas;
76 Object originalColour;
78 int R = 0, G = 0, B = 0;
80 public ColourSchemeI loadDefaultColours()
82 // NOT IMPLEMENTED YET IN APPLET VERSION
86 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
93 oldColourScheme = seqGroup.cs;
97 oldColourScheme = ap.av.getGlobalColourScheme();
103 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
105 this.pdbcanvas = pdb;
109 public UserDefinedColours(AppletJmol jmol)
115 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
118 originalColour = fr.colourPanel.getBackground();
119 originalLabel = "Feature Colour";
120 setForDialog("Select Feature Colour", alignframe);
121 setTargetColour(fr.colourPanel.getBackground());
122 dialog.setVisible(true);
125 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
127 this(caller, col1, alignframe, "Select Colour");
131 * Makes a dialog to choose the colour
138 * - the parent Frame for the dialog
142 public UserDefinedColours(Component caller, Color col1, Frame alignframe,
145 this.caller = caller;
146 originalColour = col1;
147 originalLabel = title;
148 setForDialog(title, alignframe);
149 setTargetColour(col1);
150 dialog.setVisible(true);
154 * feature colour chooser
160 public UserDefinedColours(Object caller, String label, Color colour)
162 this(caller, label, colour, colour);
166 * feature colour chooser when changing style to single color
170 * @param graduatedColor
172 public UserDefinedColours(FeatureSettings me, String type,
173 GraduatedColor graduatedColor)
175 this(me, type, graduatedColor, graduatedColor.getMaxColor());
178 private UserDefinedColours(Object caller, String label, Object ocolour,
181 this.caller = caller;
182 originalColour = ocolour;
183 originalLabel = label;
187 setTargetColour(colour);
189 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
190 frame.setTitle(MessageManager.getString("label.user_defined_colours") + " - " + label);
191 frame.setSize(420, 200);
194 void setForDialog(String title, Container alignframe)
197 frame.setVisible(false);
199 if (alignframe instanceof Frame)
201 dialog = new Dialog((Frame) alignframe, title, true);
205 // if (alignframe instanceof JVDialog){
206 // // not 1.1 compatible!
207 // dialog = new Dialog(((JVDialog)alignframe), title, true);
209 throw new Error(MessageManager.getString("label.error_unsupported_owwner_user_colour_scheme"));
213 this.setSize(400, 123);
214 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
215 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
218 dialog.setBounds(alignframe.getBounds().x
219 + (alignframe.getSize().width - width) / 2,
220 alignframe.getBounds().y
221 + (alignframe.getSize().height - height) / 2, width,
226 public void actionPerformed(ActionEvent evt)
228 if (evt.getSource() == okButton)
230 okButton_actionPerformed();
232 else if (evt.getSource() == applyButton)
234 applyButton_actionPerformed();
236 else if (evt.getSource() == cancelButton)
238 cancelButton_actionPerformed();
240 else if (evt.getSource() == rText)
242 rText_actionPerformed();
244 else if (evt.getSource() == gText)
246 gText_actionPerformed();
248 else if (evt.getSource() == bText)
250 bText_actionPerformed();
254 public void adjustmentValueChanged(AdjustmentEvent evt)
256 if (evt.getSource() == rScroller)
258 rScroller_adjustmentValueChanged();
260 else if (evt.getSource() == gScroller)
262 gScroller_adjustmentValueChanged();
264 else if (evt.getSource() == bScroller)
266 bScroller_adjustmentValueChanged();
275 } catch (Exception e)
281 jalview.bin.JalviewLite.addFrame(frame,
282 MessageManager.getString("label.user_defined_colours"), 420,
285 if (seqGroup != null)
287 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
290 for (int i = 0; i < 20; i++)
292 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
293 + "", ResidueProperties.aa[i]);
296 makeButton("B", "B");
297 makeButton("Z", "Z");
298 makeButton("X", "X");
299 makeButton("Gap", "'.','-',' '");
304 protected void rText_actionPerformed()
308 int i = Integer.parseInt(rText.getText());
309 rScroller.setValue(i);
310 rScroller_adjustmentValueChanged();
311 } catch (NumberFormatException ex)
316 protected void gText_actionPerformed()
320 int i = Integer.parseInt(gText.getText());
321 gScroller.setValue(i);
322 gScroller_adjustmentValueChanged();
323 } catch (NumberFormatException ex)
329 protected void bText_actionPerformed()
333 int i = Integer.parseInt(bText.getText());
334 bScroller.setValue(i);
335 bScroller_adjustmentValueChanged();
336 } catch (NumberFormatException ex)
342 protected void rScroller_adjustmentValueChanged()
344 R = rScroller.getValue();
345 rText.setText(R + "");
349 protected void gScroller_adjustmentValueChanged()
351 G = gScroller.getValue();
352 gText.setText(G + "");
356 protected void bScroller_adjustmentValueChanged()
358 B = bScroller.getValue();
359 bText.setText(B + "");
363 public void colourChanged()
365 Color col = new Color(R, G, B);
366 target.setBackground(col);
369 if (selectedButton != null)
371 selectedButton.setBackground(col);
372 selectedButton.repaint();
376 void setTargetColour(Color col)
382 rScroller.setValue(R);
383 gScroller.setValue(G);
384 bScroller.setValue(B);
385 rText.setText(R + "");
386 gText.setText(G + "");
387 bText.setText(B + "");
391 public void colourButtonPressed(MouseEvent e)
393 selectedButton = (Button) e.getSource();
394 setTargetColour(selectedButton.getBackground());
397 void makeButton(String label, String aa)
399 final Button button = new Button();
400 Color col = Color.white;
401 if (oldColourScheme != null)
405 col = oldColourScheme.findColour(aa.charAt(0), -1, null);
406 } catch (Exception ex)
410 button.setBackground(col);
411 oldColours.addElement(col);
412 button.setLabel(label);
413 button.setForeground(col.darker().darker().darker());
414 button.setFont(new java.awt.Font("Verdana", 1, 10));
415 button.addMouseListener(new java.awt.event.MouseAdapter()
417 public void mousePressed(MouseEvent e)
419 colourButtonPressed(e);
423 buttonPanel.add(button, null);
426 protected void okButton_actionPerformed()
428 applyButton_actionPerformed();
430 dialog.setVisible(false);
432 frame.setVisible(false);
435 public Color getColor()
437 return new Color(R, G, B);
440 protected void applyButton_actionPerformed()
444 if (caller instanceof FeatureSettings)
446 ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
448 else if (caller instanceof AnnotationColourChooser)
450 if (originalLabel.equals("Min Colour"))
452 ((AnnotationColourChooser) caller)
453 .minColour_actionPerformed(getColor());
457 ((AnnotationColourChooser) caller)
458 .maxColour_actionPerformed(getColor());
461 else if (caller instanceof FeatureRenderer)
463 ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
465 else if (caller instanceof FeatureColourChooser)
467 if (originalLabel.indexOf("inimum") > -1)
469 ((FeatureColourChooser) caller)
470 .minColour_actionPerformed(getColor());
474 ((FeatureColourChooser) caller)
475 .maxColour_actionPerformed(getColor());
482 Color[] newColours = new Color[24];
483 for (int i = 0; i < 24; i++)
485 Button button = (Button) buttonPanel.getComponent(i);
486 newColours[i] = button.getBackground();
489 UserColourScheme ucs = new UserColourScheme(newColours);
492 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
497 if (seqGroup != null)
503 ap.av.setGlobalColourScheme(ucs);
505 ap.seqPanel.seqCanvas.img = null;
506 ap.paintAlignment(true);
508 else if (jmol != null)
510 jmol.setJalviewColourScheme(ucs);
512 else if (pdbcanvas != null)
514 pdbcanvas.setColours(ucs);
518 protected void cancelButton_actionPerformed()
522 if (caller instanceof FeatureSettings)
524 ((FeatureSettings) caller).setUserColour(originalLabel,
527 else if (caller instanceof AnnotationColourChooser)
529 if (originalLabel.equals("Min Colour"))
531 ((AnnotationColourChooser) caller)
532 .minColour_actionPerformed((Color) originalColour);
536 ((AnnotationColourChooser) caller)
537 .maxColour_actionPerformed((Color) originalColour);
540 else if (caller instanceof FeatureRenderer)
542 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
546 else if (caller instanceof FeatureColourChooser)
548 if (originalLabel.indexOf("inimum") > -1)
550 ((FeatureColourChooser) caller)
551 .minColour_actionPerformed((Color) originalColour);
555 ((FeatureColourChooser) caller)
556 .maxColour_actionPerformed((Color) originalColour);
560 dialog.setVisible(false);
562 frame.setVisible(false);
566 Color[] newColours = new Color[24];
567 for (int i = 0; i < 24; i++)
569 newColours[i] = (Color) oldColours.elementAt(i);
570 buttonPanel.getComponent(i).setBackground(newColours[i]);
573 UserColourScheme ucs = new UserColourScheme(newColours);
577 if (seqGroup != null)
583 ap.av.setGlobalColourScheme(ucs);
585 ap.paintAlignment(true);
587 else if (jmol != null)
589 jmol.setJalviewColourScheme(ucs);
591 else if (pdbcanvas != null)
593 pdbcanvas.pdb.setColours(ucs);
596 frame.setVisible(false);
599 protected Panel buttonPanel = new Panel();
601 protected GridLayout gridLayout = new GridLayout();
603 Panel okcancelPanel = new Panel();
605 protected Button okButton = new Button();
607 protected Button applyButton = new Button();
609 protected Button cancelButton = new Button();
611 protected Scrollbar rScroller = new Scrollbar();
613 Label label1 = new Label();
615 protected TextField rText = new TextField();
617 Label label4 = new Label();
619 protected Scrollbar gScroller = new Scrollbar();
621 protected TextField gText = new TextField();
623 Label label5 = new Label();
625 protected Scrollbar bScroller = new Scrollbar();
627 protected TextField bText = new TextField();
629 protected Panel target = new Panel();
631 private void jbInit() throws Exception
633 this.setLayout(null);
634 buttonPanel.setLayout(gridLayout);
635 gridLayout.setColumns(6);
636 gridLayout.setRows(4);
637 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
638 okButton.setLabel(MessageManager.getString("action.ok"));
639 okButton.addActionListener(this);
640 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
641 applyButton.setLabel(MessageManager.getString("action.apply"));
642 applyButton.addActionListener(this);
643 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
644 cancelButton.setLabel(MessageManager.getString("action.cancel"));
645 cancelButton.addActionListener(this);
646 this.setBackground(new Color(212, 208, 223));
647 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
648 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
649 rScroller.setMaximum(256);
650 rScroller.setMinimum(0);
651 rScroller.setOrientation(0);
652 rScroller.setUnitIncrement(1);
653 rScroller.setVisibleAmount(1);
654 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
655 rScroller.addAdjustmentListener(this);
656 label1.setAlignment(Label.RIGHT);
658 label1.setBounds(new Rectangle(19, 30, 16, 15));
659 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
661 rText.setBounds(new Rectangle(156, 27, 53, 19));
662 rText.addActionListener(this);
663 label4.setAlignment(Label.RIGHT);
665 label4.setBounds(new Rectangle(15, 56, 20, 15));
666 gScroller.setMaximum(256);
667 gScroller.setMinimum(0);
668 gScroller.setOrientation(0);
669 gScroller.setUnitIncrement(1);
670 gScroller.setVisibleAmount(1);
671 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
672 gScroller.addAdjustmentListener(this);
673 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
675 gText.setBounds(new Rectangle(156, 52, 53, 20));
676 gText.addActionListener(this);
677 label5.setAlignment(Label.RIGHT);
679 label5.setBounds(new Rectangle(14, 82, 20, 15));
680 bScroller.setMaximum(256);
681 bScroller.setMinimum(0);
682 bScroller.setOrientation(0);
683 bScroller.setUnitIncrement(1);
684 bScroller.setVisibleAmount(1);
685 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
686 bScroller.addAdjustmentListener(this);
687 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
689 bText.setBounds(new Rectangle(157, 78, 52, 20));
690 bText.addActionListener(this);
691 target.setBackground(Color.black);
692 target.setBounds(new Rectangle(229, 26, 134, 79));
693 this.add(okcancelPanel, null);
694 okcancelPanel.add(okButton, null);
695 okcancelPanel.add(applyButton, null);
696 okcancelPanel.add(cancelButton, null);
697 this.add(buttonPanel, null);
698 this.add(target, null);