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.renderer.ResidueShader;
26 import jalview.schemes.ColourSchemeI;
27 import jalview.schemes.FeatureColour;
28 import jalview.schemes.ResidueProperties;
29 import jalview.schemes.UserColourScheme;
30 import jalview.util.MessageManager;
32 import java.awt.Button;
33 import java.awt.Color;
34 import java.awt.Component;
35 import java.awt.Container;
36 import java.awt.Dialog;
38 import java.awt.Frame;
39 import java.awt.GridLayout;
40 import java.awt.Label;
41 import java.awt.Panel;
42 import java.awt.Rectangle;
43 import java.awt.Scrollbar;
44 import java.awt.TextField;
45 import java.awt.event.ActionEvent;
46 import java.awt.event.ActionListener;
47 import java.awt.event.AdjustmentEvent;
48 import java.awt.event.AdjustmentListener;
49 import java.awt.event.FocusEvent;
50 import java.awt.event.FocusListener;
51 import java.awt.event.MouseEvent;
52 import java.util.Vector;
54 public class UserDefinedColours extends Panel implements ActionListener,
55 AdjustmentListener, FocusListener
60 SequenceGroup seqGroup;
62 Button selectedButton;
64 Vector<Color> oldColours = new Vector<Color>();
66 ColourSchemeI oldColourScheme;
70 MCview.AppletPDBCanvas pdbcanvas;
80 FeatureColourI originalColour;
82 int R = 0, G = 0, B = 0;
84 public ColourSchemeI loadDefaultColours()
86 // NOT IMPLEMENTED YET IN APPLET VERSION
90 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
97 oldColourScheme = seqGroup.getColourScheme();
101 oldColourScheme = ap.av.getGlobalColourScheme();
107 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
109 this.pdbcanvas = pdb;
113 public UserDefinedColours(AppletJmol jmol)
119 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
122 originalColour = new FeatureColour(fr.colourPanel.getBackground());
123 originalLabel = "Feature Colour";
124 setForDialog("Select Feature Colour", alignframe);
125 setTargetColour(fr.colourPanel.getBackground());
126 dialog.setVisible(true);
129 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
131 this(caller, col1, alignframe, "Select Colour");
135 * Makes a dialog to choose the colour
142 * - the parent Frame for the dialog
146 public UserDefinedColours(Component caller, Color col, Frame alignframe,
149 this.caller = caller;
150 originalColour = new FeatureColour(col);
151 originalLabel = title;
152 setForDialog(title, alignframe);
153 setTargetColour(col);
154 dialog.setVisible(true);
158 * feature colour chooser
164 public UserDefinedColours(Object caller, String label, Color colour)
166 this(caller, label, new FeatureColour(colour), colour);
170 * feature colour chooser when changing style to single color
174 * @param graduatedColor
176 public UserDefinedColours(FeatureSettings me, String type,
177 FeatureColourI graduatedColor)
179 this(me, type, graduatedColor, graduatedColor.getMaxColour());
182 private UserDefinedColours(Object caller, String label,
183 FeatureColourI ocolour, Color colour)
185 this.caller = caller;
186 originalColour = ocolour;
187 originalLabel = label;
191 setTargetColour(colour);
193 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
194 frame.setTitle(MessageManager.getString("label.user_defined_colours")
196 frame.setSize(420, 200);
199 void setForDialog(String title, Container alignframe)
202 frame.setVisible(false);
204 if (alignframe instanceof Frame)
206 dialog = new Dialog((Frame) alignframe, title, true);
210 // if (alignframe instanceof JVDialog){
211 // // not 1.1 compatible!
212 // dialog = new Dialog(((JVDialog)alignframe), title, true);
216 .getString("label.error_unsupported_owwner_user_colour_scheme"));
220 this.setSize(400, 123);
221 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
222 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
225 dialog.setBounds(alignframe.getBounds().x
226 + (alignframe.getSize().width - width) / 2,
227 alignframe.getBounds().y
228 + (alignframe.getSize().height - height) / 2, width,
234 public void actionPerformed(ActionEvent evt)
236 final Object source = evt.getSource();
237 if (source == okButton)
239 okButton_actionPerformed();
241 else if (source == applyButton)
243 applyButton_actionPerformed();
245 else if (source == cancelButton)
247 cancelButton_actionPerformed();
249 else if (source == rText)
251 rText_actionPerformed();
253 else if (source == gText)
255 gText_actionPerformed();
257 else if (source == bText)
259 bText_actionPerformed();
264 public void adjustmentValueChanged(AdjustmentEvent evt)
266 if (evt.getSource() == rScroller)
268 rScroller_adjustmentValueChanged();
270 else if (evt.getSource() == gScroller)
272 gScroller_adjustmentValueChanged();
274 else if (evt.getSource() == bScroller)
276 bScroller_adjustmentValueChanged();
285 } catch (Exception e)
291 jalview.bin.JalviewLite.addFrame(frame,
292 MessageManager.getString("label.user_defined_colours"), 420,
295 if (seqGroup != null)
297 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
300 for (int i = 0; i < 20; i++)
302 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
303 + "", ResidueProperties.aa[i]);
306 makeButton("B", "B");
307 makeButton("Z", "Z");
308 makeButton("X", "X");
309 makeButton("Gap", "'.','-',' '");
314 protected void rText_actionPerformed()
318 int i = Integer.parseInt(rText.getText());
319 rScroller.setValue(i);
320 rScroller_adjustmentValueChanged();
321 } catch (NumberFormatException ex)
326 protected void gText_actionPerformed()
330 int i = Integer.parseInt(gText.getText());
331 gScroller.setValue(i);
332 gScroller_adjustmentValueChanged();
333 } catch (NumberFormatException ex)
339 protected void bText_actionPerformed()
343 int i = Integer.parseInt(bText.getText());
344 bScroller.setValue(i);
345 bScroller_adjustmentValueChanged();
346 } catch (NumberFormatException ex)
352 protected void rScroller_adjustmentValueChanged()
354 R = rScroller.getValue();
355 rText.setText(R + "");
359 protected void gScroller_adjustmentValueChanged()
361 G = gScroller.getValue();
362 gText.setText(G + "");
366 protected void bScroller_adjustmentValueChanged()
368 B = bScroller.getValue();
369 bText.setText(B + "");
373 public void colourChanged()
375 Color col = new Color(R, G, B);
376 target.setBackground(col);
379 if (selectedButton != null)
381 selectedButton.setBackground(col);
382 selectedButton.repaint();
386 void setTargetColour(Color col)
392 rScroller.setValue(R);
393 gScroller.setValue(G);
394 bScroller.setValue(B);
395 rText.setText(R + "");
396 gText.setText(G + "");
397 bText.setText(B + "");
401 public void colourButtonPressed(MouseEvent e)
403 selectedButton = (Button) e.getSource();
404 setTargetColour(selectedButton.getBackground());
407 void makeButton(String label, String aa)
409 final Button button = new Button();
410 Color col = Color.white;
411 if (oldColourScheme != null && oldColourScheme.isSimple())
413 col = oldColourScheme.findColour(aa.charAt(0), 0, null, null, 0f);
415 button.setBackground(col);
416 oldColours.addElement(col);
417 button.setLabel(label);
418 button.setForeground(col.darker().darker().darker());
419 button.setFont(new java.awt.Font("Verdana", 1, 10));
420 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,
455 new FeatureColour(getColor()));
457 else if (caller instanceof AnnotationColourChooser)
459 if (originalLabel.equals("Min Colour"))
461 ((AnnotationColourChooser) caller)
462 .minColour_actionPerformed(getColor());
466 ((AnnotationColourChooser) caller)
467 .maxColour_actionPerformed(getColor());
470 else if (caller instanceof FeatureRenderer)
472 ((FeatureRenderer) caller).colourPanel
473 .updateColor(new FeatureColour(getColor()));
475 else if (caller instanceof FeatureColourChooser)
477 if (originalLabel.indexOf("inimum") > -1)
479 ((FeatureColourChooser) caller)
480 .minColour_actionPerformed(getColor());
484 ((FeatureColourChooser) caller)
485 .maxColour_actionPerformed(getColor());
492 Color[] newColours = new Color[24];
493 for (int i = 0; i < 24; i++)
495 Button button = (Button) buttonPanel.getComponent(i);
496 newColours[i] = button.getBackground();
499 UserColourScheme ucs = new UserColourScheme(newColours);
502 // ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
507 if (seqGroup != null)
509 seqGroup.cs = new ResidueShader(ucs);
510 seqGroup.getGroupColourScheme().setThreshold(0,
511 ap.av.isIgnoreGapsConsensus());
515 ap.av.setGlobalColourScheme(ucs);
516 ap.av.getResidueShading().setThreshold(0,
517 ap.av.isIgnoreGapsConsensus());
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)
595 seqGroup.cs = new ResidueShader(ucs);
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();