2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.appletgui;
20 import jalview.datamodel.SequenceGroup;
21 import jalview.schemes.ColourSchemeI;
22 import jalview.schemes.GraduatedColor;
23 import jalview.schemes.ResidueProperties;
24 import jalview.schemes.UserColourScheme;
25 import jalview.util.MessageManager;
27 import java.awt.Button;
28 import java.awt.Color;
29 import java.awt.Component;
30 import java.awt.Container;
31 import java.awt.Dialog;
33 import java.awt.Frame;
34 import java.awt.GridLayout;
35 import java.awt.Label;
36 import java.awt.Panel;
37 import java.awt.Rectangle;
38 import java.awt.Scrollbar;
39 import java.awt.TextField;
40 import java.awt.event.ActionEvent;
41 import java.awt.event.ActionListener;
42 import java.awt.event.AdjustmentEvent;
43 import java.awt.event.AdjustmentListener;
44 import java.awt.event.MouseEvent;
45 import java.util.Vector;
47 public class UserDefinedColours extends Panel implements ActionListener,
53 SequenceGroup seqGroup;
55 Button selectedButton;
57 Vector oldColours = new Vector();
59 ColourSchemeI oldColourScheme;
63 MCview.AppletPDBCanvas pdbcanvas;
73 Object originalColour;
75 int R = 0, G = 0, B = 0;
77 public ColourSchemeI loadDefaultColours()
79 // NOT IMPLEMENTED YET IN APPLET VERSION
83 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
90 oldColourScheme = seqGroup.cs;
94 oldColourScheme = ap.av.getGlobalColourScheme();
100 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
102 this.pdbcanvas = pdb;
106 public UserDefinedColours(AppletJmol jmol)
112 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
115 originalColour = fr.colourPanel.getBackground();
116 originalLabel = "Feature Colour";
117 setForDialog("Select Feature Colour", alignframe);
118 setTargetColour(fr.colourPanel.getBackground());
119 dialog.setVisible(true);
122 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
124 this(caller, col1, alignframe, "Select Colour");
128 * Makes a dialog to choose the colour
135 * - the parent Frame for the dialog
139 public UserDefinedColours(Component caller, Color col1, Frame alignframe,
142 this.caller = caller;
143 originalColour = col1;
144 originalLabel = title;
145 setForDialog(title, alignframe);
146 setTargetColour(col1);
147 dialog.setVisible(true);
151 * feature colour chooser
157 public UserDefinedColours(Object caller, String label, Color colour)
159 this(caller, label, colour, colour);
163 * feature colour chooser when changing style to single color
167 * @param graduatedColor
169 public UserDefinedColours(FeatureSettings me, String type,
170 GraduatedColor graduatedColor)
172 this(me, type, graduatedColor, graduatedColor.getMaxColor());
175 private UserDefinedColours(Object caller, String label, Object ocolour,
178 this.caller = caller;
179 originalColour = ocolour;
180 originalLabel = label;
184 setTargetColour(colour);
186 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
187 frame.setTitle("User Defined Colours - " + label);
188 frame.setSize(420, 200);
191 void setForDialog(String title, Container alignframe)
194 frame.setVisible(false);
196 if (alignframe instanceof Frame)
198 dialog = new Dialog((Frame) alignframe, title, true);
202 // if (alignframe instanceof JVDialog){
203 // // not 1.1 compatible!
204 // dialog = new Dialog(((JVDialog)alignframe), title, true);
206 throw new Error("Unsupported owner for User Colour scheme dialog.");
210 this.setSize(400, 123);
211 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
212 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
215 dialog.setBounds(alignframe.getBounds().x
216 + (alignframe.getSize().width - width) / 2,
217 alignframe.getBounds().y
218 + (alignframe.getSize().height - height) / 2, width,
223 public void actionPerformed(ActionEvent evt)
225 if (evt.getSource() == okButton)
227 okButton_actionPerformed();
229 else if (evt.getSource() == applyButton)
231 applyButton_actionPerformed();
233 else if (evt.getSource() == cancelButton)
235 cancelButton_actionPerformed();
237 else if (evt.getSource() == rText)
239 rText_actionPerformed();
241 else if (evt.getSource() == gText)
243 gText_actionPerformed();
245 else if (evt.getSource() == bText)
247 bText_actionPerformed();
251 public void adjustmentValueChanged(AdjustmentEvent evt)
253 if (evt.getSource() == rScroller)
255 rScroller_adjustmentValueChanged();
257 else if (evt.getSource() == gScroller)
259 gScroller_adjustmentValueChanged();
261 else if (evt.getSource() == bScroller)
263 bScroller_adjustmentValueChanged();
272 } catch (Exception e)
278 jalview.bin.JalviewLite.addFrame(frame, MessageManager.getString("label.user_defined_colours"), 420,
281 if (seqGroup != null)
283 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
286 for (int i = 0; i < 20; i++)
288 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
289 + "", ResidueProperties.aa[i]);
292 makeButton("B", "B");
293 makeButton("Z", "Z");
294 makeButton("X", "X");
295 makeButton("Gap", "'.','-',' '");
300 protected void rText_actionPerformed()
304 int i = Integer.parseInt(rText.getText());
305 rScroller.setValue(i);
306 rScroller_adjustmentValueChanged();
307 } catch (NumberFormatException ex)
312 protected void gText_actionPerformed()
316 int i = Integer.parseInt(gText.getText());
317 gScroller.setValue(i);
318 gScroller_adjustmentValueChanged();
319 } catch (NumberFormatException ex)
325 protected void bText_actionPerformed()
329 int i = Integer.parseInt(bText.getText());
330 bScroller.setValue(i);
331 bScroller_adjustmentValueChanged();
332 } catch (NumberFormatException ex)
338 protected void rScroller_adjustmentValueChanged()
340 R = rScroller.getValue();
341 rText.setText(R + "");
345 protected void gScroller_adjustmentValueChanged()
347 G = gScroller.getValue();
348 gText.setText(G + "");
352 protected void bScroller_adjustmentValueChanged()
354 B = bScroller.getValue();
355 bText.setText(B + "");
359 public void colourChanged()
361 Color col = new Color(R, G, B);
362 target.setBackground(col);
365 if (selectedButton != null)
367 selectedButton.setBackground(col);
368 selectedButton.repaint();
372 void setTargetColour(Color col)
378 rScroller.setValue(R);
379 gScroller.setValue(G);
380 bScroller.setValue(B);
381 rText.setText(R + "");
382 gText.setText(G + "");
383 bText.setText(B + "");
387 public void colourButtonPressed(MouseEvent e)
389 selectedButton = (Button) e.getSource();
390 setTargetColour(selectedButton.getBackground());
393 void makeButton(String label, String aa)
395 final Button button = new Button();
396 Color col = Color.white;
397 if (oldColourScheme != null)
401 col = oldColourScheme.findColour(aa.charAt(0), -1, null);
402 } catch (Exception ex)
406 button.setBackground(col);
407 oldColours.addElement(col);
408 button.setLabel(label);
409 button.setForeground(col.darker().darker().darker());
410 button.setFont(new java.awt.Font("Verdana", 1, 10));
411 button.addMouseListener(new java.awt.event.MouseAdapter()
413 public void mousePressed(MouseEvent e)
415 colourButtonPressed(e);
419 buttonPanel.add(button, null);
422 protected void okButton_actionPerformed()
424 applyButton_actionPerformed();
426 dialog.setVisible(false);
428 frame.setVisible(false);
431 public Color getColor()
433 return new Color(R, G, B);
436 protected void applyButton_actionPerformed()
440 if (caller instanceof FeatureSettings)
442 ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
444 else if (caller instanceof AnnotationColourChooser)
446 if (originalLabel.equals("Min Colour"))
448 ((AnnotationColourChooser) caller)
449 .minColour_actionPerformed(getColor());
453 ((AnnotationColourChooser) caller)
454 .maxColour_actionPerformed(getColor());
457 else if (caller instanceof FeatureRenderer)
459 ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
461 else if (caller instanceof FeatureColourChooser)
463 if (originalLabel.indexOf("inimum") > -1)
465 ((FeatureColourChooser) caller)
466 .minColour_actionPerformed(getColor());
470 ((FeatureColourChooser) caller)
471 .maxColour_actionPerformed(getColor());
478 Color[] newColours = new Color[24];
479 for (int i = 0; i < 24; i++)
481 Button button = (Button) buttonPanel.getComponent(i);
482 newColours[i] = button.getBackground();
485 UserColourScheme ucs = new UserColourScheme(newColours);
488 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
493 if (seqGroup != null)
499 ap.av.setGlobalColourScheme(ucs);
501 ap.seqPanel.seqCanvas.img = null;
502 ap.paintAlignment(true);
504 else if (jmol != null)
506 jmol.setJalviewColourScheme(ucs);
508 else if (pdbcanvas != null)
510 pdbcanvas.setColours(ucs);
514 protected void cancelButton_actionPerformed()
518 if (caller instanceof FeatureSettings)
520 ((FeatureSettings) caller).setUserColour(originalLabel,
523 else if (caller instanceof AnnotationColourChooser)
525 if (originalLabel.equals("Min Colour"))
527 ((AnnotationColourChooser) caller)
528 .minColour_actionPerformed((Color) originalColour);
532 ((AnnotationColourChooser) caller)
533 .maxColour_actionPerformed((Color) originalColour);
536 else if (caller instanceof FeatureRenderer)
538 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
542 else if (caller instanceof FeatureColourChooser)
544 if (originalLabel.indexOf("inimum") > -1)
546 ((FeatureColourChooser) caller)
547 .minColour_actionPerformed((Color) originalColour);
551 ((FeatureColourChooser) caller)
552 .maxColour_actionPerformed((Color) originalColour);
556 dialog.setVisible(false);
558 frame.setVisible(false);
562 Color[] newColours = new Color[24];
563 for (int i = 0; i < 24; i++)
565 newColours[i] = (Color) oldColours.elementAt(i);
566 buttonPanel.getComponent(i).setBackground(newColours[i]);
569 UserColourScheme ucs = new UserColourScheme(newColours);
573 if (seqGroup != null)
579 ap.av.setGlobalColourScheme(ucs);
581 ap.paintAlignment(true);
583 else if (jmol != null)
585 jmol.setJalviewColourScheme(ucs);
587 else if (pdbcanvas != null)
589 pdbcanvas.pdb.setColours(ucs);
592 frame.setVisible(false);
595 protected Panel buttonPanel = new Panel();
597 protected GridLayout gridLayout = new GridLayout();
599 Panel okcancelPanel = new Panel();
601 protected Button okButton = new Button();
603 protected Button applyButton = new Button();
605 protected Button cancelButton = new Button();
607 protected Scrollbar rScroller = new Scrollbar();
609 Label label1 = new Label();
611 protected TextField rText = new TextField();
613 Label label4 = new Label();
615 protected Scrollbar gScroller = new Scrollbar();
617 protected TextField gText = new TextField();
619 Label label5 = new Label();
621 protected Scrollbar bScroller = new Scrollbar();
623 protected TextField bText = new TextField();
625 protected Panel target = new Panel();
627 private void jbInit() throws Exception
629 this.setLayout(null);
630 buttonPanel.setLayout(gridLayout);
631 gridLayout.setColumns(6);
632 gridLayout.setRows(4);
633 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
634 okButton.setLabel(MessageManager.getString("action.ok"));
635 okButton.addActionListener(this);
636 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
637 applyButton.setLabel(MessageManager.getString("action.apply"));
638 applyButton.addActionListener(this);
639 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
640 cancelButton.setLabel(MessageManager.getString("action.cancel"));
641 cancelButton.addActionListener(this);
642 this.setBackground(new Color(212, 208, 223));
643 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
644 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
645 rScroller.setMaximum(256);
646 rScroller.setMinimum(0);
647 rScroller.setOrientation(0);
648 rScroller.setUnitIncrement(1);
649 rScroller.setVisibleAmount(1);
650 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
651 rScroller.addAdjustmentListener(this);
652 label1.setAlignment(Label.RIGHT);
654 label1.setBounds(new Rectangle(19, 30, 16, 15));
655 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
657 rText.setBounds(new Rectangle(156, 27, 53, 19));
658 rText.addActionListener(this);
659 label4.setAlignment(Label.RIGHT);
661 label4.setBounds(new Rectangle(15, 56, 20, 15));
662 gScroller.setMaximum(256);
663 gScroller.setMinimum(0);
664 gScroller.setOrientation(0);
665 gScroller.setUnitIncrement(1);
666 gScroller.setVisibleAmount(1);
667 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
668 gScroller.addAdjustmentListener(this);
669 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
671 gText.setBounds(new Rectangle(156, 52, 53, 20));
672 gText.addActionListener(this);
673 label5.setAlignment(Label.RIGHT);
675 label5.setBounds(new Rectangle(14, 82, 20, 15));
676 bScroller.setMaximum(256);
677 bScroller.setMinimum(0);
678 bScroller.setOrientation(0);
679 bScroller.setUnitIncrement(1);
680 bScroller.setVisibleAmount(1);
681 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
682 bScroller.addAdjustmentListener(this);
683 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
685 bText.setBounds(new Rectangle(157, 78, 52, 20));
686 bText.addActionListener(this);
687 target.setBackground(Color.black);
688 target.setBounds(new Rectangle(229, 26, 134, 79));
689 this.add(okcancelPanel, null);
690 okcancelPanel.add(okButton, null);
691 okcancelPanel.add(applyButton, null);
692 okcancelPanel.add(cancelButton, null);
693 this.add(buttonPanel, null);
694 this.add(target, null);