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.api.FeatureColourI;
24 import jalview.datamodel.SequenceGroup;
25 import jalview.schemes.Colour;
26 import jalview.schemes.ColourSchemeI;
27 import jalview.schemes.FeatureColour;
28 import jalview.schemes.ResidueProperties;
29 import jalview.schemes.UserColourScheme;
30 import jalview.util.ColorUtils;
31 import jalview.util.MessageManager;
33 import java.awt.Button;
34 import java.awt.Color;
35 import java.awt.Component;
36 import java.awt.Container;
37 import java.awt.Dialog;
39 import java.awt.Frame;
40 import java.awt.GridLayout;
41 import java.awt.Label;
42 import java.awt.Panel;
43 import java.awt.Rectangle;
44 import java.awt.Scrollbar;
45 import java.awt.TextField;
46 import java.awt.event.ActionEvent;
47 import java.awt.event.ActionListener;
48 import java.awt.event.AdjustmentEvent;
49 import java.awt.event.AdjustmentListener;
50 import java.awt.event.FocusEvent;
51 import java.awt.event.FocusListener;
52 import java.awt.event.MouseEvent;
53 import java.util.Vector;
55 public class UserDefinedColours extends Panel implements ActionListener,
56 AdjustmentListener, FocusListener
61 SequenceGroup seqGroup;
63 Button selectedButton;
65 Vector<Color> oldColours = new Vector<Color>();
67 ColourSchemeI oldColourScheme;
71 MCview.AppletPDBCanvas pdbcanvas;
81 FeatureColourI originalColour;
83 int R = 0, G = 0, B = 0;
85 public ColourSchemeI loadDefaultColours()
87 // NOT IMPLEMENTED YET IN APPLET VERSION
91 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
98 oldColourScheme = seqGroup.cs;
102 oldColourScheme = ap.av.getGlobalColourScheme();
108 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
110 this.pdbcanvas = pdb;
114 public UserDefinedColours(AppletJmol jmol)
120 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
123 originalColour = new FeatureColour(new Colour(
124 fr.colourPanel.getBackground()));
125 originalLabel = "Feature Colour";
126 setForDialog("Select Feature Colour", alignframe);
127 setTargetColour(fr.colourPanel.getBackground());
128 dialog.setVisible(true);
131 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
133 this(caller, col1, alignframe, "Select Colour");
137 * Makes a dialog to choose the colour
144 * - the parent Frame for the dialog
148 public UserDefinedColours(Component caller, Color col, Frame alignframe,
151 this.caller = caller;
152 originalColour = new FeatureColour(new Colour(col));
153 originalLabel = title;
154 setForDialog(title, alignframe);
155 setTargetColour(col);
156 dialog.setVisible(true);
160 * feature colour chooser
166 public UserDefinedColours(Object caller, String label, Color colour)
168 this(caller, label, new FeatureColour(new Colour(colour)), colour);
172 * feature colour chooser when changing style to single color
176 * @param graduatedColor
178 public UserDefinedColours(FeatureSettings me, String type,
179 FeatureColourI graduatedColor)
181 this(me, type, graduatedColor, ColorUtils.getColor(graduatedColor
185 private UserDefinedColours(Object caller, String label,
186 FeatureColourI ocolour, Color colour)
188 this.caller = caller;
189 originalColour = ocolour;
190 originalLabel = label;
194 setTargetColour(colour);
196 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
197 frame.setTitle(MessageManager.getString("label.user_defined_colours")
199 frame.setSize(420, 200);
202 void setForDialog(String title, Container alignframe)
205 frame.setVisible(false);
207 if (alignframe instanceof Frame)
209 dialog = new Dialog((Frame) alignframe, title, true);
213 // if (alignframe instanceof JVDialog){
214 // // not 1.1 compatible!
215 // dialog = new Dialog(((JVDialog)alignframe), title, true);
219 .getString("label.error_unsupported_owwner_user_colour_scheme"));
223 this.setSize(400, 123);
224 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
225 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
228 dialog.setBounds(alignframe.getBounds().x
229 + (alignframe.getSize().width - width) / 2,
230 alignframe.getBounds().y
231 + (alignframe.getSize().height - height) / 2, width,
237 public void actionPerformed(ActionEvent evt)
239 final Object source = evt.getSource();
240 if (source == okButton)
242 okButton_actionPerformed();
244 else if (source == applyButton)
246 applyButton_actionPerformed();
248 else if (source == cancelButton)
250 cancelButton_actionPerformed();
252 else if (source == rText)
254 rText_actionPerformed();
256 else if (source == gText)
258 gText_actionPerformed();
260 else if (source == bText)
262 bText_actionPerformed();
267 public void adjustmentValueChanged(AdjustmentEvent evt)
269 if (evt.getSource() == rScroller)
271 rScroller_adjustmentValueChanged();
273 else if (evt.getSource() == gScroller)
275 gScroller_adjustmentValueChanged();
277 else if (evt.getSource() == bScroller)
279 bScroller_adjustmentValueChanged();
288 } catch (Exception e)
294 jalview.bin.JalviewLite.addFrame(frame,
295 MessageManager.getString("label.user_defined_colours"), 420,
298 if (seqGroup != null)
300 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
303 for (int i = 0; i < 20; i++)
305 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
306 + "", ResidueProperties.aa[i]);
309 makeButton("B", "B");
310 makeButton("Z", "Z");
311 makeButton("X", "X");
312 makeButton("Gap", "'.','-',' '");
317 protected void rText_actionPerformed()
321 int i = Integer.parseInt(rText.getText());
322 rScroller.setValue(i);
323 rScroller_adjustmentValueChanged();
324 } catch (NumberFormatException ex)
329 protected void gText_actionPerformed()
333 int i = Integer.parseInt(gText.getText());
334 gScroller.setValue(i);
335 gScroller_adjustmentValueChanged();
336 } catch (NumberFormatException ex)
342 protected void bText_actionPerformed()
346 int i = Integer.parseInt(bText.getText());
347 bScroller.setValue(i);
348 bScroller_adjustmentValueChanged();
349 } catch (NumberFormatException ex)
355 protected void rScroller_adjustmentValueChanged()
357 R = rScroller.getValue();
358 rText.setText(R + "");
362 protected void gScroller_adjustmentValueChanged()
364 G = gScroller.getValue();
365 gText.setText(G + "");
369 protected void bScroller_adjustmentValueChanged()
371 B = bScroller.getValue();
372 bText.setText(B + "");
376 public void colourChanged()
378 Color col = new Color(R, G, B);
379 target.setBackground(col);
382 if (selectedButton != null)
384 selectedButton.setBackground(col);
385 selectedButton.repaint();
389 void setTargetColour(Color col)
395 rScroller.setValue(R);
396 gScroller.setValue(G);
397 bScroller.setValue(B);
398 rText.setText(R + "");
399 gText.setText(G + "");
400 bText.setText(B + "");
404 public void colourButtonPressed(MouseEvent e)
406 selectedButton = (Button) e.getSource();
407 setTargetColour(selectedButton.getBackground());
410 void makeButton(String label, String aa)
412 final Button button = new Button();
413 Color col = Color.white;
414 if (oldColourScheme != null)
418 col = oldColourScheme.findColour(aa.charAt(0), -1, null);
419 } catch (Exception ex)
423 button.setBackground(col);
424 oldColours.addElement(col);
425 button.setLabel(label);
426 button.setForeground(col.darker().darker().darker());
427 button.setFont(new java.awt.Font("Verdana", 1, 10));
428 button.addMouseListener(new java.awt.event.MouseAdapter()
431 public void mousePressed(MouseEvent e)
433 colourButtonPressed(e);
437 buttonPanel.add(button, null);
440 protected void okButton_actionPerformed()
442 applyButton_actionPerformed();
445 dialog.setVisible(false);
448 frame.setVisible(false);
451 public Color getColor()
453 return new Color(R, G, B);
456 protected void applyButton_actionPerformed()
460 if (caller instanceof FeatureSettings)
462 ((FeatureSettings) caller).setUserColour(originalLabel,
463 new FeatureColour(new Colour(getColor())));
465 else if (caller instanceof AnnotationColourChooser)
467 if (originalLabel.equals("Min Colour"))
469 ((AnnotationColourChooser) caller)
470 .minColour_actionPerformed(getColor());
474 ((AnnotationColourChooser) caller)
475 .maxColour_actionPerformed(getColor());
478 else if (caller instanceof FeatureRenderer)
480 ((FeatureRenderer) caller).colourPanel
481 .updateColor(new FeatureColour(new Colour(getColor())));
483 else if (caller instanceof FeatureColourChooser)
485 if (originalLabel.indexOf("inimum") > -1)
487 ((FeatureColourChooser) caller)
488 .minColour_actionPerformed(getColor());
492 ((FeatureColourChooser) caller)
493 .maxColour_actionPerformed(getColor());
500 Color[] newColours = new Color[24];
501 for (int i = 0; i < 24; i++)
503 Button button = (Button) buttonPanel.getComponent(i);
504 newColours[i] = button.getBackground();
507 UserColourScheme ucs = new UserColourScheme(newColours);
510 ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
515 if (seqGroup != null)
521 ap.av.setGlobalColourScheme(ucs);
523 ap.seqPanel.seqCanvas.img = null;
524 ap.paintAlignment(true);
526 else if (jmol != null)
528 jmol.setJalviewColourScheme(ucs);
530 else if (pdbcanvas != null)
532 pdbcanvas.setColours(ucs);
536 protected void cancelButton_actionPerformed()
540 if (caller instanceof FeatureSettings)
542 ((FeatureSettings) caller).setUserColour(originalLabel,
545 else if (caller instanceof AnnotationColourChooser)
547 if (originalLabel.equals("Min Colour"))
549 ((AnnotationColourChooser) caller)
550 .minColour_actionPerformed(ColorUtils
551 .getColor(originalColour.getColour()));
555 ((AnnotationColourChooser) caller)
556 .maxColour_actionPerformed(ColorUtils
557 .getColor(originalColour.getColour()));
560 else if (caller instanceof FeatureRenderer)
562 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
566 else if (caller instanceof FeatureColourChooser)
568 if (originalLabel.indexOf("inimum") > -1)
570 ((FeatureColourChooser) caller)
571 .minColour_actionPerformed(ColorUtils
572 .getColor(originalColour.getColour()));
576 ((FeatureColourChooser) caller)
577 .maxColour_actionPerformed(ColorUtils
578 .getColor(originalColour.getColour()));
583 dialog.setVisible(false);
586 frame.setVisible(false);
590 Color[] newColours = new Color[24];
591 for (int i = 0; i < 24; i++)
593 newColours[i] = oldColours.elementAt(i);
594 buttonPanel.getComponent(i).setBackground(newColours[i]);
597 UserColourScheme ucs = new UserColourScheme(newColours);
601 if (seqGroup != null)
607 ap.av.setGlobalColourScheme(ucs);
609 ap.paintAlignment(true);
611 else if (jmol != null)
613 jmol.setJalviewColourScheme(ucs);
615 else if (pdbcanvas != null)
617 pdbcanvas.pdb.setColours(ucs);
620 frame.setVisible(false);
623 protected Panel buttonPanel = new Panel();
625 protected GridLayout gridLayout = new GridLayout();
627 Panel okcancelPanel = new Panel();
629 protected Button okButton = new Button();
631 protected Button applyButton = new Button();
633 protected Button cancelButton = new Button();
635 protected Scrollbar rScroller = new Scrollbar();
637 Label label1 = new Label();
639 protected TextField rText = new TextField();
641 Label label4 = new Label();
643 protected Scrollbar gScroller = new Scrollbar();
645 protected TextField gText = new TextField();
647 Label label5 = new Label();
649 protected Scrollbar bScroller = new Scrollbar();
651 protected TextField bText = new TextField();
653 protected Panel target = new Panel();
655 private void jbInit() throws Exception
657 this.setLayout(null);
658 buttonPanel.setLayout(gridLayout);
659 gridLayout.setColumns(6);
660 gridLayout.setRows(4);
661 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
662 okButton.setLabel(MessageManager.getString("action.ok"));
663 okButton.addActionListener(this);
664 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
665 applyButton.setLabel(MessageManager.getString("action.apply"));
666 applyButton.addActionListener(this);
667 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
668 cancelButton.setLabel(MessageManager.getString("action.cancel"));
669 cancelButton.addActionListener(this);
670 this.setBackground(new Color(212, 208, 223));
671 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
672 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
673 rScroller.setMaximum(256);
674 rScroller.setMinimum(0);
675 rScroller.setOrientation(0);
676 rScroller.setUnitIncrement(1);
677 rScroller.setVisibleAmount(1);
678 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
679 rScroller.addAdjustmentListener(this);
680 label1.setAlignment(Label.RIGHT);
682 label1.setBounds(new Rectangle(19, 30, 16, 15));
683 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
685 rText.setBounds(new Rectangle(156, 27, 53, 19));
686 rText.addActionListener(this);
687 rText.addFocusListener(this);
688 label4.setAlignment(Label.RIGHT);
690 label4.setBounds(new Rectangle(15, 56, 20, 15));
691 gScroller.setMaximum(256);
692 gScroller.setMinimum(0);
693 gScroller.setOrientation(0);
694 gScroller.setUnitIncrement(1);
695 gScroller.setVisibleAmount(1);
696 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
697 gScroller.addAdjustmentListener(this);
698 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
700 gText.setBounds(new Rectangle(156, 52, 53, 20));
701 gText.addActionListener(this);
702 gText.addFocusListener(this);
703 label5.setAlignment(Label.RIGHT);
705 label5.setBounds(new Rectangle(14, 82, 20, 15));
706 bScroller.setMaximum(256);
707 bScroller.setMinimum(0);
708 bScroller.setOrientation(0);
709 bScroller.setUnitIncrement(1);
710 bScroller.setVisibleAmount(1);
711 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
712 bScroller.addAdjustmentListener(this);
713 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
715 bText.setBounds(new Rectangle(157, 78, 52, 20));
716 bText.addActionListener(this);
717 bText.addFocusListener(this);
718 target.setBackground(Color.black);
719 target.setBounds(new Rectangle(229, 26, 134, 79));
720 this.add(okcancelPanel, null);
721 okcancelPanel.add(okButton, null);
722 okcancelPanel.add(applyButton, null);
723 okcancelPanel.add(cancelButton, null);
727 this.add(buttonPanel, null);
728 this.add(target, null);
738 public void focusGained(FocusEvent e)
744 * This method applies any change to an RGB value if the user tabs out of the
745 * field instead of pressing Enter
748 public void focusLost(FocusEvent e)
750 Component c = e.getComponent();
753 rText_actionPerformed();
759 gText_actionPerformed();
765 bText_actionPerformed();