2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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.FocusEvent;
48 import java.awt.event.FocusListener;
49 import java.awt.event.MouseEvent;
50 import java.util.Vector;
52 public class UserDefinedColours extends Panel implements ActionListener,
53 AdjustmentListener, FocusListener
58 SequenceGroup seqGroup;
60 Button selectedButton;
62 Vector oldColours = new Vector();
64 ColourSchemeI oldColourScheme;
68 MCview.AppletPDBCanvas pdbcanvas;
78 Object originalColour;
80 int R = 0, G = 0, B = 0;
82 public ColourSchemeI loadDefaultColours()
84 // NOT IMPLEMENTED YET IN APPLET VERSION
88 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
95 oldColourScheme = seqGroup.cs;
99 oldColourScheme = ap.av.getGlobalColourScheme();
105 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
107 this.pdbcanvas = pdb;
111 public UserDefinedColours(AppletJmol jmol)
117 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
120 originalColour = fr.colourPanel.getBackground();
121 originalLabel = "Feature Colour";
122 setForDialog("Select Feature Colour", alignframe);
123 setTargetColour(fr.colourPanel.getBackground());
124 dialog.setVisible(true);
127 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
129 this(caller, col1, alignframe, "Select Colour");
133 * Makes a dialog to choose the colour
140 * - the parent Frame for the dialog
144 public UserDefinedColours(Component caller, Color col1, Frame alignframe,
147 this.caller = caller;
148 originalColour = col1;
149 originalLabel = title;
150 setForDialog(title, alignframe);
151 setTargetColour(col1);
152 dialog.setVisible(true);
156 * feature colour chooser
162 public UserDefinedColours(Object caller, String label, Color colour)
164 this(caller, label, colour, colour);
168 * feature colour chooser when changing style to single color
172 * @param graduatedColor
174 public UserDefinedColours(FeatureSettings me, String type,
175 GraduatedColor graduatedColor)
177 this(me, type, graduatedColor, graduatedColor.getMaxColor());
180 private UserDefinedColours(Object caller, String label, Object ocolour,
183 this.caller = caller;
184 originalColour = ocolour;
185 originalLabel = label;
189 setTargetColour(colour);
191 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
192 frame.setTitle(MessageManager.getString("label.user_defined_colours")
194 frame.setSize(420, 200);
197 void setForDialog(String title, Container alignframe)
200 frame.setVisible(false);
202 if (alignframe instanceof Frame)
204 dialog = new Dialog((Frame) alignframe, title, true);
208 // if (alignframe instanceof JVDialog){
209 // // not 1.1 compatible!
210 // dialog = new Dialog(((JVDialog)alignframe), title, true);
214 .getString("label.error_unsupported_owwner_user_colour_scheme"));
218 this.setSize(400, 123);
219 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
220 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
223 dialog.setBounds(alignframe.getBounds().x
224 + (alignframe.getSize().width - width) / 2,
225 alignframe.getBounds().y
226 + (alignframe.getSize().height - height) / 2, width,
231 public void actionPerformed(ActionEvent evt)
233 final Object source = evt.getSource();
234 if (source == okButton)
236 okButton_actionPerformed();
238 else if (source == applyButton)
240 applyButton_actionPerformed();
242 else if (source == cancelButton)
244 cancelButton_actionPerformed();
246 else if (source == rText)
248 rText_actionPerformed();
250 else if (source == gText)
252 gText_actionPerformed();
254 else if (source == bText)
256 bText_actionPerformed();
260 public void adjustmentValueChanged(AdjustmentEvent evt)
262 if (evt.getSource() == rScroller)
264 rScroller_adjustmentValueChanged();
266 else if (evt.getSource() == gScroller)
268 gScroller_adjustmentValueChanged();
270 else if (evt.getSource() == bScroller)
272 bScroller_adjustmentValueChanged();
281 } catch (Exception e)
287 jalview.bin.JalviewLite.addFrame(frame,
288 MessageManager.getString("label.user_defined_colours"), 420,
291 if (seqGroup != null)
293 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
296 for (int i = 0; i < 20; i++)
298 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
299 + "", ResidueProperties.aa[i]);
302 makeButton("B", "B");
303 makeButton("Z", "Z");
304 makeButton("X", "X");
305 makeButton("Gap", "'.','-',' '");
310 protected void rText_actionPerformed()
314 int i = Integer.parseInt(rText.getText());
315 rScroller.setValue(i);
316 rScroller_adjustmentValueChanged();
317 } catch (NumberFormatException ex)
322 protected void gText_actionPerformed()
326 int i = Integer.parseInt(gText.getText());
327 gScroller.setValue(i);
328 gScroller_adjustmentValueChanged();
329 } catch (NumberFormatException ex)
335 protected void bText_actionPerformed()
339 int i = Integer.parseInt(bText.getText());
340 bScroller.setValue(i);
341 bScroller_adjustmentValueChanged();
342 } catch (NumberFormatException ex)
348 protected void rScroller_adjustmentValueChanged()
350 R = rScroller.getValue();
351 rText.setText(R + "");
355 protected void gScroller_adjustmentValueChanged()
357 G = gScroller.getValue();
358 gText.setText(G + "");
362 protected void bScroller_adjustmentValueChanged()
364 B = bScroller.getValue();
365 bText.setText(B + "");
369 public void colourChanged()
371 Color col = new Color(R, G, B);
372 target.setBackground(col);
375 if (selectedButton != null)
377 selectedButton.setBackground(col);
378 selectedButton.repaint();
382 void setTargetColour(Color col)
388 rScroller.setValue(R);
389 gScroller.setValue(G);
390 bScroller.setValue(B);
391 rText.setText(R + "");
392 gText.setText(G + "");
393 bText.setText(B + "");
397 public void colourButtonPressed(MouseEvent e)
399 selectedButton = (Button) e.getSource();
400 setTargetColour(selectedButton.getBackground());
403 void makeButton(String label, String aa)
405 final Button button = new Button();
406 Color col = Color.white;
407 if (oldColourScheme != null)
411 col = oldColourScheme.findColour(aa.charAt(0), -1, null);
412 } catch (Exception ex)
416 button.setBackground(col);
417 oldColours.addElement(col);
418 button.setLabel(label);
419 button.setForeground(col.darker().darker().darker());
420 button.setFont(new java.awt.Font("Verdana", 1, 10));
421 button.addMouseListener(new java.awt.event.MouseAdapter()
423 public void mousePressed(MouseEvent e)
425 colourButtonPressed(e);
429 buttonPanel.add(button, null);
432 protected void okButton_actionPerformed()
434 applyButton_actionPerformed();
437 dialog.setVisible(false);
440 frame.setVisible(false);
443 public Color getColor()
445 return new Color(R, G, B);
448 protected void applyButton_actionPerformed()
452 if (caller instanceof FeatureSettings)
454 ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
456 else if (caller instanceof AnnotationColourChooser)
458 if (originalLabel.equals("Min Colour"))
460 ((AnnotationColourChooser) caller)
461 .minColour_actionPerformed(getColor());
465 ((AnnotationColourChooser) caller)
466 .maxColour_actionPerformed(getColor());
469 else if (caller instanceof FeatureRenderer)
471 ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
473 else if (caller instanceof FeatureColourChooser)
475 if (originalLabel.indexOf("inimum") > -1)
477 ((FeatureColourChooser) caller)
478 .minColour_actionPerformed(getColor());
482 ((FeatureColourChooser) caller)
483 .maxColour_actionPerformed(getColor());
490 Color[] newColours = new Color[24];
491 for (int i = 0; i < 24; i++)
493 Button button = (Button) buttonPanel.getComponent(i);
494 newColours[i] = button.getBackground();
497 UserColourScheme ucs = new UserColourScheme(newColours);
500 ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
505 if (seqGroup != null)
511 ap.av.setGlobalColourScheme(ucs);
513 ap.seqPanel.seqCanvas.img = null;
514 ap.paintAlignment(true);
516 else if (jmol != null)
518 jmol.setJalviewColourScheme(ucs);
520 else if (pdbcanvas != null)
522 pdbcanvas.setColours(ucs);
526 protected void cancelButton_actionPerformed()
530 if (caller instanceof FeatureSettings)
532 ((FeatureSettings) caller).setUserColour(originalLabel,
535 else if (caller instanceof AnnotationColourChooser)
537 if (originalLabel.equals("Min Colour"))
539 ((AnnotationColourChooser) caller)
540 .minColour_actionPerformed((Color) originalColour);
544 ((AnnotationColourChooser) caller)
545 .maxColour_actionPerformed((Color) originalColour);
548 else if (caller instanceof FeatureRenderer)
550 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
554 else if (caller instanceof FeatureColourChooser)
556 if (originalLabel.indexOf("inimum") > -1)
558 ((FeatureColourChooser) caller)
559 .minColour_actionPerformed((Color) originalColour);
563 ((FeatureColourChooser) caller)
564 .maxColour_actionPerformed((Color) originalColour);
569 dialog.setVisible(false);
572 frame.setVisible(false);
576 Color[] newColours = new Color[24];
577 for (int i = 0; i < 24; i++)
579 newColours[i] = (Color) oldColours.elementAt(i);
580 buttonPanel.getComponent(i).setBackground(newColours[i]);
583 UserColourScheme ucs = new UserColourScheme(newColours);
587 if (seqGroup != null)
593 ap.av.setGlobalColourScheme(ucs);
595 ap.paintAlignment(true);
597 else if (jmol != null)
599 jmol.setJalviewColourScheme(ucs);
601 else if (pdbcanvas != null)
603 pdbcanvas.pdb.setColours(ucs);
606 frame.setVisible(false);
609 protected Panel buttonPanel = new Panel();
611 protected GridLayout gridLayout = new GridLayout();
613 Panel okcancelPanel = new Panel();
615 protected Button okButton = new Button();
617 protected Button applyButton = new Button();
619 protected Button cancelButton = new Button();
621 protected Scrollbar rScroller = new Scrollbar();
623 Label label1 = new Label();
625 protected TextField rText = new TextField();
627 Label label4 = new Label();
629 protected Scrollbar gScroller = new Scrollbar();
631 protected TextField gText = new TextField();
633 Label label5 = new Label();
635 protected Scrollbar bScroller = new Scrollbar();
637 protected TextField bText = new TextField();
639 protected Panel target = new Panel();
641 private void jbInit() throws Exception
643 this.setLayout(null);
644 buttonPanel.setLayout(gridLayout);
645 gridLayout.setColumns(6);
646 gridLayout.setRows(4);
647 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
648 okButton.setLabel(MessageManager.getString("action.ok"));
649 okButton.addActionListener(this);
650 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
651 applyButton.setLabel(MessageManager.getString("action.apply"));
652 applyButton.addActionListener(this);
653 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
654 cancelButton.setLabel(MessageManager.getString("action.cancel"));
655 cancelButton.addActionListener(this);
656 this.setBackground(new Color(212, 208, 223));
657 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
658 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
659 rScroller.setMaximum(256);
660 rScroller.setMinimum(0);
661 rScroller.setOrientation(0);
662 rScroller.setUnitIncrement(1);
663 rScroller.setVisibleAmount(1);
664 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
665 rScroller.addAdjustmentListener(this);
666 label1.setAlignment(Label.RIGHT);
668 label1.setBounds(new Rectangle(19, 30, 16, 15));
669 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
671 rText.setBounds(new Rectangle(156, 27, 53, 19));
672 rText.addActionListener(this);
673 rText.addFocusListener(this);
674 label4.setAlignment(Label.RIGHT);
676 label4.setBounds(new Rectangle(15, 56, 20, 15));
677 gScroller.setMaximum(256);
678 gScroller.setMinimum(0);
679 gScroller.setOrientation(0);
680 gScroller.setUnitIncrement(1);
681 gScroller.setVisibleAmount(1);
682 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
683 gScroller.addAdjustmentListener(this);
684 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
686 gText.setBounds(new Rectangle(156, 52, 53, 20));
687 gText.addActionListener(this);
688 gText.addFocusListener(this);
689 label5.setAlignment(Label.RIGHT);
691 label5.setBounds(new Rectangle(14, 82, 20, 15));
692 bScroller.setMaximum(256);
693 bScroller.setMinimum(0);
694 bScroller.setOrientation(0);
695 bScroller.setUnitIncrement(1);
696 bScroller.setVisibleAmount(1);
697 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
698 bScroller.addAdjustmentListener(this);
699 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
701 bText.setBounds(new Rectangle(157, 78, 52, 20));
702 bText.addActionListener(this);
703 bText.addFocusListener(this);
704 target.setBackground(Color.black);
705 target.setBounds(new Rectangle(229, 26, 134, 79));
706 this.add(okcancelPanel, null);
707 okcancelPanel.add(okButton, null);
708 okcancelPanel.add(applyButton, null);
709 okcancelPanel.add(cancelButton, null);
713 this.add(buttonPanel, null);
714 this.add(target, null);
724 public void focusGained(FocusEvent e)
730 * This method applies any change to an RGB value if the user tabs out of the
731 * field instead of pressing Enter
734 public void focusLost(FocusEvent e)
736 Component c = e.getComponent();
739 rText_actionPerformed();
745 gText_actionPerformed();
751 bText_actionPerformed();