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.bin.JalviewLite;
24 import jalview.datamodel.SequenceGroup;
25 import jalview.schemes.ColourSchemeI;
26 import jalview.schemes.GraduatedColor;
27 import jalview.schemes.ResidueProperties;
28 import jalview.schemes.UserColourScheme;
29 import jalview.util.MessageManager;
31 import awt2swing.Button;
32 import java.awt.Color;
33 import java.awt.Component;
34 import java.awt.Container;
35 import java.awt.Dialog;
37 import awt2swing.Frame;
38 import java.awt.GridLayout;
39 import awt2swing.Label;
40 import awt2swing.Panel;
41 import java.awt.Rectangle;
42 import awt2swing.Scrollbar;
43 import awt2swing.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 oldColours = new Vector();
65 ColourSchemeI oldColourScheme;
69 // MCview.AppletPDBCanvas pdbcanvas;
79 Object 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 = 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 col1, Frame alignframe,
148 this.caller = caller;
149 originalColour = col1;
150 originalLabel = title;
151 setForDialog(title, alignframe);
152 setTargetColour(col1);
153 dialog.setVisible(true);
157 * feature colour chooser
163 public UserDefinedColours(Object caller, String label, Color colour)
165 this(caller, label, colour, colour);
169 * feature colour chooser when changing style to single color
173 * @param graduatedColor
175 public UserDefinedColours(FeatureSettings me, String type,
176 GraduatedColor graduatedColor)
178 this(me, type, graduatedColor, graduatedColor.getMaxColor());
181 private UserDefinedColours(Object caller, String label, Object ocolour,
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") + " - " + label);
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);
212 throw new Error(MessageManager.getString("label.error_unsupported_owwner_user_colour_scheme"));
216 this.setSize(400, 123);
217 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
218 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
221 dialog.setBounds(alignframe.getBounds().x
222 + (alignframe.getSize().width - width) / 2,
223 alignframe.getBounds().y
224 + (alignframe.getSize().height - height) / 2, width,
229 public void actionPerformed(ActionEvent evt)
231 final Object source = evt.getSource();
232 if (source == okButton)
234 okButton_actionPerformed();
236 else if (source == applyButton)
238 applyButton_actionPerformed();
240 else if (source == cancelButton)
242 cancelButton_actionPerformed();
244 else if (source == rText)
246 rText_actionPerformed();
248 else if (source == gText)
250 gText_actionPerformed();
252 else if (source == bText)
254 bText_actionPerformed();
258 public void adjustmentValueChanged(AdjustmentEvent evt)
260 if (evt.getSource() == rScroller)
262 rScroller_adjustmentValueChanged();
264 else if (evt.getSource() == gScroller)
266 gScroller_adjustmentValueChanged();
268 else if (evt.getSource() == bScroller)
270 bScroller_adjustmentValueChanged();
279 } catch (Exception e)
285 JalviewLite.addFrame(frame,
286 MessageManager.getString("label.user_defined_colours"), 420,
289 if (seqGroup != null)
291 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
294 for (int i = 0; i < 20; i++)
296 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
297 + "", ResidueProperties.aa[i]);
300 makeButton("B", "B");
301 makeButton("Z", "Z");
302 makeButton("X", "X");
303 makeButton("Gap", "'.','-',' '");
308 protected void rText_actionPerformed()
312 int i = Integer.parseInt(rText.getText());
313 rScroller.setValue(i);
314 rScroller_adjustmentValueChanged();
315 } catch (NumberFormatException ex)
320 protected void gText_actionPerformed()
324 int i = Integer.parseInt(gText.getText());
325 gScroller.setValue(i);
326 gScroller_adjustmentValueChanged();
327 } catch (NumberFormatException ex)
333 protected void bText_actionPerformed()
337 int i = Integer.parseInt(bText.getText());
338 bScroller.setValue(i);
339 bScroller_adjustmentValueChanged();
340 } catch (NumberFormatException ex)
346 protected void rScroller_adjustmentValueChanged()
348 R = rScroller.getValue();
349 rText.setText(R + "");
353 protected void gScroller_adjustmentValueChanged()
355 G = gScroller.getValue();
356 gText.setText(G + "");
360 protected void bScroller_adjustmentValueChanged()
362 B = bScroller.getValue();
363 bText.setText(B + "");
367 public void colourChanged()
369 Color col = new Color(R, G, B);
370 target.setBackground(col);
373 if (selectedButton != null)
375 selectedButton.setBackground(col);
376 selectedButton.repaint();
380 void setTargetColour(Color col)
386 rScroller.setValue(R);
387 gScroller.setValue(G);
388 bScroller.setValue(B);
389 rText.setText(R + "");
390 gText.setText(G + "");
391 bText.setText(B + "");
395 public void colourButtonPressed(MouseEvent e)
397 selectedButton = (Button) e.getSource();
398 setTargetColour(selectedButton.getBackground());
401 void makeButton(String label, String aa)
403 final Button button = new Button();
404 Color col = Color.white;
405 if (oldColourScheme != null)
409 col = oldColourScheme.findColour(aa.charAt(0), -1, null);
410 } catch (Exception ex)
414 button.setBackground(col);
415 oldColours.addElement(col);
416 button.setLabel(label);
417 button.setForeground(col.darker().darker().darker());
418 button.setFont(new java.awt.Font("Verdana", 1, 10));
419 button.addMouseListener(new java.awt.event.MouseAdapter()
421 public void mousePressed(MouseEvent e)
423 colourButtonPressed(e);
427 buttonPanel.add(button, null);
430 protected void okButton_actionPerformed()
432 applyButton_actionPerformed();
435 dialog.setVisible(false);
438 frame.setVisible(false);
441 public Color getColor()
443 return new Color(R, G, B);
446 protected void applyButton_actionPerformed()
450 if (caller instanceof FeatureSettings)
452 ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
454 else if (caller instanceof AnnotationColourChooser)
456 if (originalLabel.equals("Min Colour"))
458 ((AnnotationColourChooser) caller)
459 .minColour_actionPerformed(getColor());
463 ((AnnotationColourChooser) caller)
464 .maxColour_actionPerformed(getColor());
467 else if (caller instanceof FeatureRenderer)
469 ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
471 else if (caller instanceof FeatureColourChooser)
473 if (originalLabel.indexOf("inimum") > -1)
475 ((FeatureColourChooser) caller)
476 .minColour_actionPerformed(getColor());
480 ((FeatureColourChooser) caller)
481 .maxColour_actionPerformed(getColor());
488 Color[] newColours = new Color[24];
489 for (int i = 0; i < 24; i++)
491 Button button = (Button) buttonPanel.getComponent(i);
492 newColours[i] = button.getBackground();
495 UserColourScheme ucs = new UserColourScheme(newColours);
498 ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
503 if (seqGroup != null)
509 ap.av.setGlobalColourScheme(ucs);
511 ap.seqPanel.seqCanvas.img = null;
512 ap.paintAlignment(true);
514 else if (jmol != null)
516 jmol.setJalviewColourScheme(ucs);
518 // else if (pdbcanvas != null)
520 // pdbcanvas.setColours(ucs);
524 protected void cancelButton_actionPerformed()
528 if (caller instanceof FeatureSettings)
530 ((FeatureSettings) caller).setUserColour(originalLabel,
533 else if (caller instanceof AnnotationColourChooser)
535 if (originalLabel.equals("Min Colour"))
537 ((AnnotationColourChooser) caller)
538 .minColour_actionPerformed((Color) originalColour);
542 ((AnnotationColourChooser) caller)
543 .maxColour_actionPerformed((Color) originalColour);
546 else if (caller instanceof FeatureRenderer)
548 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
552 else if (caller instanceof FeatureColourChooser)
554 if (originalLabel.indexOf("inimum") > -1)
556 ((FeatureColourChooser) caller)
557 .minColour_actionPerformed((Color) originalColour);
561 ((FeatureColourChooser) caller)
562 .maxColour_actionPerformed((Color) originalColour);
567 dialog.setVisible(false);
570 frame.setVisible(false);
574 Color[] newColours = new Color[24];
575 for (int i = 0; i < 24; i++)
577 newColours[i] = (Color) oldColours.elementAt(i);
578 buttonPanel.getComponent(i).setBackground(newColours[i]);
581 UserColourScheme ucs = new UserColourScheme(newColours);
585 if (seqGroup != null)
591 ap.av.setGlobalColourScheme(ucs);
593 ap.paintAlignment(true);
595 else if (jmol != null)
597 jmol.setJalviewColourScheme(ucs);
599 // else if (pdbcanvas != null)
601 // pdbcanvas.pdb.setColours(ucs);
604 frame.setVisible(false);
607 protected Panel buttonPanel = new Panel();
609 protected GridLayout gridLayout = new GridLayout();
611 Panel okcancelPanel = new Panel();
613 protected Button okButton = new Button();
615 protected Button applyButton = new Button();
617 protected Button cancelButton = new Button();
619 protected Scrollbar rScroller = new Scrollbar();
621 Label label1 = new Label();
623 protected TextField rText = new TextField();
625 Label label4 = new Label();
627 protected Scrollbar gScroller = new Scrollbar();
629 protected TextField gText = new TextField();
631 Label label5 = new Label();
633 protected Scrollbar bScroller = new Scrollbar();
635 protected TextField bText = new TextField();
637 protected Panel target = new Panel();
639 private void jbInit() throws Exception
641 this.setLayout(null);
642 buttonPanel.setLayout(gridLayout);
643 gridLayout.setColumns(6);
644 gridLayout.setRows(4);
645 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
646 okButton.setLabel(MessageManager.getString("action.ok"));
647 okButton.addActionListener(this);
648 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
649 applyButton.setLabel(MessageManager.getString("action.apply"));
650 applyButton.addActionListener(this);
651 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
652 cancelButton.setLabel(MessageManager.getString("action.cancel"));
653 cancelButton.addActionListener(this);
654 this.setBackground(new Color(212, 208, 223));
655 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
656 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
657 rScroller.setMaximum(256);
658 rScroller.setMinimum(0);
659 rScroller.setOrientation(0);
660 rScroller.setUnitIncrement(1);
661 rScroller.setVisibleAmount(1);
662 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
663 rScroller.addAdjustmentListener(this);
664 label1.setAlignment(Label.RIGHT);
666 label1.setBounds(new Rectangle(19, 30, 16, 15));
667 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
669 rText.setBounds(new Rectangle(156, 27, 53, 19));
670 rText.addActionListener(this);
671 rText.addFocusListener(this);
672 label4.setAlignment(Label.RIGHT);
674 label4.setBounds(new Rectangle(15, 56, 20, 15));
675 gScroller.setMaximum(256);
676 gScroller.setMinimum(0);
677 gScroller.setOrientation(0);
678 gScroller.setUnitIncrement(1);
679 gScroller.setVisibleAmount(1);
680 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
681 gScroller.addAdjustmentListener(this);
682 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
684 gText.setBounds(new Rectangle(156, 52, 53, 20));
685 gText.addActionListener(this);
686 gText.addFocusListener(this);
687 label5.setAlignment(Label.RIGHT);
689 label5.setBounds(new Rectangle(14, 82, 20, 15));
690 bScroller.setMaximum(256);
691 bScroller.setMinimum(0);
692 bScroller.setOrientation(0);
693 bScroller.setUnitIncrement(1);
694 bScroller.setVisibleAmount(1);
695 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
696 bScroller.addAdjustmentListener(this);
697 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
699 bText.setBounds(new Rectangle(157, 78, 52, 20));
700 bText.addActionListener(this);
701 bText.addFocusListener(this);
702 target.setBackground(Color.black);
703 target.setBounds(new Rectangle(229, 26, 134, 79));
704 this.add(okcancelPanel, null);
705 okcancelPanel.add(okButton, null);
706 okcancelPanel.add(applyButton, null);
707 okcancelPanel.add(cancelButton, null);
711 this.add(buttonPanel, null);
712 this.add(target, null);
722 public void focusGained(FocusEvent e)
728 * This method applies any change to an RGB value if the user tabs out of the
729 * field instead of pressing Enter
732 public void focusLost(FocusEvent e)
734 Component c = e.getComponent();
737 rText_actionPerformed();
743 gText_actionPerformed();
749 bText_actionPerformed();