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.ColourSchemeI;
26 import jalview.schemes.FeatureColour;
27 import jalview.schemes.ResidueProperties;
28 import jalview.schemes.UserColourScheme;
29 import jalview.util.MessageManager;
31 import java.awt.Button;
32 import java.awt.Color;
33 import java.awt.Component;
34 import java.awt.Container;
35 import java.awt.Dialog;
37 import java.awt.Frame;
38 import java.awt.GridLayout;
39 import java.awt.Label;
40 import java.awt.Panel;
41 import java.awt.Rectangle;
42 import java.awt.Scrollbar;
43 import java.awt.TextField;
44 import java.awt.event.ActionEvent;
45 import java.awt.event.ActionListener;
46 import java.awt.event.AdjustmentEvent;
47 import java.awt.event.AdjustmentListener;
48 import java.awt.event.FocusEvent;
49 import java.awt.event.FocusListener;
50 import java.awt.event.MouseEvent;
51 import java.util.Vector;
53 public class UserDefinedColours extends Panel implements ActionListener,
54 AdjustmentListener, FocusListener
59 SequenceGroup seqGroup;
61 Button selectedButton;
63 Vector<Color> oldColours = new Vector<Color>();
65 ColourSchemeI oldColourScheme;
69 MCview.AppletPDBCanvas pdbcanvas;
79 FeatureColourI originalColour;
81 int R = 0, G = 0, B = 0;
83 public ColourSchemeI loadDefaultColours()
85 // NOT IMPLEMENTED YET IN APPLET VERSION
89 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
96 oldColourScheme = seqGroup.cs;
100 oldColourScheme = ap.av.getGlobalColourScheme();
106 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
108 this.pdbcanvas = pdb;
112 public UserDefinedColours(AppletJmol jmol)
118 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
121 originalColour = new FeatureColour(fr.colourPanel.getBackground());
122 originalLabel = "Feature Colour";
123 setForDialog("Select Feature Colour", alignframe);
124 setTargetColour(fr.colourPanel.getBackground());
125 dialog.setVisible(true);
128 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
130 this(caller, col1, alignframe, "Select Colour");
134 * Makes a dialog to choose the colour
141 * - the parent Frame for the dialog
145 public UserDefinedColours(Component caller, Color col, Frame alignframe,
148 this.caller = caller;
149 originalColour = new FeatureColour(col);
150 originalLabel = title;
151 setForDialog(title, alignframe);
152 setTargetColour(col);
153 dialog.setVisible(true);
157 * feature colour chooser
163 public UserDefinedColours(Object caller, String label, Color colour)
165 this(caller, label, new FeatureColour(colour), colour);
169 * feature colour chooser when changing style to single color
173 * @param graduatedColor
175 public UserDefinedColours(FeatureSettings me, String type,
176 FeatureColourI graduatedColor)
178 this(me, type, graduatedColor, graduatedColor.getMaxColour());
181 private UserDefinedColours(Object caller, String label,
182 FeatureColourI ocolour, Color colour)
184 this.caller = caller;
185 originalColour = ocolour;
186 originalLabel = label;
190 setTargetColour(colour);
192 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
193 frame.setTitle(MessageManager.getString("label.user_defined_colours")
195 frame.setSize(420, 200);
198 void setForDialog(String title, Container alignframe)
201 frame.setVisible(false);
203 if (alignframe instanceof Frame)
205 dialog = new Dialog((Frame) alignframe, title, true);
209 // if (alignframe instanceof JVDialog){
210 // // not 1.1 compatible!
211 // dialog = new Dialog(((JVDialog)alignframe), title, true);
215 .getString("label.error_unsupported_owwner_user_colour_scheme"));
219 this.setSize(400, 123);
220 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
221 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
224 dialog.setBounds(alignframe.getBounds().x
225 + (alignframe.getSize().width - width) / 2,
226 alignframe.getBounds().y
227 + (alignframe.getSize().height - height) / 2, width,
233 public void actionPerformed(ActionEvent evt)
235 final Object source = evt.getSource();
236 if (source == okButton)
238 okButton_actionPerformed();
240 else if (source == applyButton)
242 applyButton_actionPerformed();
244 else if (source == cancelButton)
246 cancelButton_actionPerformed();
248 else if (source == rText)
250 rText_actionPerformed();
252 else if (source == gText)
254 gText_actionPerformed();
256 else if (source == bText)
258 bText_actionPerformed();
263 public void adjustmentValueChanged(AdjustmentEvent evt)
265 if (evt.getSource() == rScroller)
267 rScroller_adjustmentValueChanged();
269 else if (evt.getSource() == gScroller)
271 gScroller_adjustmentValueChanged();
273 else if (evt.getSource() == bScroller)
275 bScroller_adjustmentValueChanged();
284 } catch (Exception e)
290 jalview.bin.JalviewLite.addFrame(frame,
291 MessageManager.getString("label.user_defined_colours"), 420,
294 if (seqGroup != null)
296 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
299 for (int i = 0; i < 20; i++)
301 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
302 + "", ResidueProperties.aa[i]);
305 makeButton("B", "B");
306 makeButton("Z", "Z");
307 makeButton("X", "X");
308 makeButton("Gap", "'.','-',' '");
313 protected void rText_actionPerformed()
317 int i = Integer.parseInt(rText.getText());
318 rScroller.setValue(i);
319 rScroller_adjustmentValueChanged();
320 } catch (NumberFormatException ex)
325 protected void gText_actionPerformed()
329 int i = Integer.parseInt(gText.getText());
330 gScroller.setValue(i);
331 gScroller_adjustmentValueChanged();
332 } catch (NumberFormatException ex)
338 protected void bText_actionPerformed()
342 int i = Integer.parseInt(bText.getText());
343 bScroller.setValue(i);
344 bScroller_adjustmentValueChanged();
345 } catch (NumberFormatException ex)
351 protected void rScroller_adjustmentValueChanged()
353 R = rScroller.getValue();
354 rText.setText(R + "");
358 protected void gScroller_adjustmentValueChanged()
360 G = gScroller.getValue();
361 gText.setText(G + "");
365 protected void bScroller_adjustmentValueChanged()
367 B = bScroller.getValue();
368 bText.setText(B + "");
372 public void colourChanged()
374 Color col = new Color(R, G, B);
375 target.setBackground(col);
378 if (selectedButton != null)
380 selectedButton.setBackground(col);
381 selectedButton.repaint();
385 void setTargetColour(Color col)
391 rScroller.setValue(R);
392 gScroller.setValue(G);
393 bScroller.setValue(B);
394 rText.setText(R + "");
395 gText.setText(G + "");
396 bText.setText(B + "");
400 public void colourButtonPressed(MouseEvent e)
402 selectedButton = (Button) e.getSource();
403 setTargetColour(selectedButton.getBackground());
406 void makeButton(String label, String aa)
408 final Button button = new Button();
409 Color col = Color.white;
410 if (oldColourScheme != null)
414 col = oldColourScheme.findColour(aa.charAt(0), -1, null);
415 } catch (Exception ex)
419 button.setBackground(col);
420 oldColours.addElement(col);
421 button.setLabel(label);
422 button.setForeground(col.darker().darker().darker());
423 button.setFont(new java.awt.Font("Verdana", 1, 10));
424 button.addMouseListener(new java.awt.event.MouseAdapter()
427 public void mousePressed(MouseEvent e)
429 colourButtonPressed(e);
433 buttonPanel.add(button, null);
436 protected void okButton_actionPerformed()
438 applyButton_actionPerformed();
441 dialog.setVisible(false);
444 frame.setVisible(false);
447 public Color getColor()
449 return new Color(R, G, B);
452 protected void applyButton_actionPerformed()
456 if (caller instanceof FeatureSettings)
458 ((FeatureSettings) caller).setUserColour(originalLabel,
459 new FeatureColour(getColor()));
461 else if (caller instanceof AnnotationColourChooser)
463 if (originalLabel.equals("Min Colour"))
465 ((AnnotationColourChooser) caller)
466 .minColour_actionPerformed(getColor());
470 ((AnnotationColourChooser) caller)
471 .maxColour_actionPerformed(getColor());
474 else if (caller instanceof FeatureRenderer)
476 ((FeatureRenderer) caller).colourPanel
477 .updateColor(new FeatureColour(getColor()));
479 else if (caller instanceof FeatureColourChooser)
481 if (originalLabel.indexOf("inimum") > -1)
483 ((FeatureColourChooser) caller)
484 .minColour_actionPerformed(getColor());
488 ((FeatureColourChooser) caller)
489 .maxColour_actionPerformed(getColor());
496 Color[] newColours = new Color[24];
497 for (int i = 0; i < 24; i++)
499 Button button = (Button) buttonPanel.getComponent(i);
500 newColours[i] = button.getBackground();
503 UserColourScheme ucs = new UserColourScheme(newColours);
506 ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
511 if (seqGroup != null)
517 ap.av.setGlobalColourScheme(ucs);
519 ap.seqPanel.seqCanvas.img = null;
520 ap.paintAlignment(true);
522 else if (jmol != null)
524 jmol.setJalviewColourScheme(ucs);
526 else if (pdbcanvas != null)
528 pdbcanvas.setColours(ucs);
532 protected void cancelButton_actionPerformed()
536 if (caller instanceof FeatureSettings)
538 ((FeatureSettings) caller).setUserColour(originalLabel,
541 else if (caller instanceof AnnotationColourChooser)
543 if (originalLabel.equals("Min Colour"))
545 ((AnnotationColourChooser) caller)
546 .minColour_actionPerformed(originalColour.getColour());
550 ((AnnotationColourChooser) caller)
551 .maxColour_actionPerformed(originalColour.getColour());
554 else if (caller instanceof FeatureRenderer)
556 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
560 else if (caller instanceof FeatureColourChooser)
562 if (originalLabel.indexOf("inimum") > -1)
564 ((FeatureColourChooser) caller)
565 .minColour_actionPerformed(originalColour.getColour());
569 ((FeatureColourChooser) caller)
570 .maxColour_actionPerformed(originalColour.getColour());
575 dialog.setVisible(false);
578 frame.setVisible(false);
582 Color[] newColours = new Color[24];
583 for (int i = 0; i < 24; i++)
585 newColours[i] = oldColours.elementAt(i);
586 buttonPanel.getComponent(i).setBackground(newColours[i]);
589 UserColourScheme ucs = new UserColourScheme(newColours);
593 if (seqGroup != null)
599 ap.av.setGlobalColourScheme(ucs);
601 ap.paintAlignment(true);
603 else if (jmol != null)
605 jmol.setJalviewColourScheme(ucs);
607 else if (pdbcanvas != null)
609 pdbcanvas.pdb.setColours(ucs);
612 frame.setVisible(false);
615 protected Panel buttonPanel = new Panel();
617 protected GridLayout gridLayout = new GridLayout();
619 Panel okcancelPanel = new Panel();
621 protected Button okButton = new Button();
623 protected Button applyButton = new Button();
625 protected Button cancelButton = new Button();
627 protected Scrollbar rScroller = new Scrollbar();
629 Label label1 = new Label();
631 protected TextField rText = new TextField();
633 Label label4 = new Label();
635 protected Scrollbar gScroller = new Scrollbar();
637 protected TextField gText = new TextField();
639 Label label5 = new Label();
641 protected Scrollbar bScroller = new Scrollbar();
643 protected TextField bText = new TextField();
645 protected Panel target = new Panel();
647 private void jbInit() throws Exception
649 this.setLayout(null);
650 buttonPanel.setLayout(gridLayout);
651 gridLayout.setColumns(6);
652 gridLayout.setRows(4);
653 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
654 okButton.setLabel(MessageManager.getString("action.ok"));
655 okButton.addActionListener(this);
656 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
657 applyButton.setLabel(MessageManager.getString("action.apply"));
658 applyButton.addActionListener(this);
659 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
660 cancelButton.setLabel(MessageManager.getString("action.cancel"));
661 cancelButton.addActionListener(this);
662 this.setBackground(new Color(212, 208, 223));
663 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
664 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
665 rScroller.setMaximum(256);
666 rScroller.setMinimum(0);
667 rScroller.setOrientation(0);
668 rScroller.setUnitIncrement(1);
669 rScroller.setVisibleAmount(1);
670 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
671 rScroller.addAdjustmentListener(this);
672 label1.setAlignment(Label.RIGHT);
674 label1.setBounds(new Rectangle(19, 30, 16, 15));
675 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
677 rText.setBounds(new Rectangle(156, 27, 53, 19));
678 rText.addActionListener(this);
679 rText.addFocusListener(this);
680 label4.setAlignment(Label.RIGHT);
682 label4.setBounds(new Rectangle(15, 56, 20, 15));
683 gScroller.setMaximum(256);
684 gScroller.setMinimum(0);
685 gScroller.setOrientation(0);
686 gScroller.setUnitIncrement(1);
687 gScroller.setVisibleAmount(1);
688 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
689 gScroller.addAdjustmentListener(this);
690 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
692 gText.setBounds(new Rectangle(156, 52, 53, 20));
693 gText.addActionListener(this);
694 gText.addFocusListener(this);
695 label5.setAlignment(Label.RIGHT);
697 label5.setBounds(new Rectangle(14, 82, 20, 15));
698 bScroller.setMaximum(256);
699 bScroller.setMinimum(0);
700 bScroller.setOrientation(0);
701 bScroller.setUnitIncrement(1);
702 bScroller.setVisibleAmount(1);
703 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
704 bScroller.addAdjustmentListener(this);
705 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
707 bText.setBounds(new Rectangle(157, 78, 52, 20));
708 bText.addActionListener(this);
709 bText.addFocusListener(this);
710 target.setBackground(Color.black);
711 target.setBounds(new Rectangle(229, 26, 134, 79));
712 this.add(okcancelPanel, null);
713 okcancelPanel.add(okButton, null);
714 okcancelPanel.add(applyButton, null);
715 okcancelPanel.add(cancelButton, null);
719 this.add(buttonPanel, null);
720 this.add(target, null);
730 public void focusGained(FocusEvent e)
736 * This method applies any change to an RGB value if the user tabs out of the
737 * field instead of pressing Enter
740 public void focusLost(FocusEvent e)
742 Component c = e.getComponent();
745 rText_actionPerformed();
751 gText_actionPerformed();
757 bText_actionPerformed();