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.analysis.AAFrequency;
24 import jalview.api.FeatureColourI;
25 import jalview.datamodel.SequenceGroup;
26 import jalview.renderer.ResidueShader;
27 import jalview.schemes.Blosum62ColourScheme;
28 import jalview.schemes.ColourSchemeI;
29 import jalview.schemes.FeatureColour;
30 import jalview.schemes.PIDColourScheme;
31 import jalview.schemes.ResidueProperties;
32 import jalview.schemes.UserColourScheme;
33 import jalview.util.MessageManager;
35 import java.awt.Button;
36 import java.awt.Color;
37 import java.awt.Component;
38 import java.awt.Container;
39 import java.awt.Dialog;
41 import java.awt.Frame;
42 import java.awt.GridLayout;
43 import java.awt.Label;
44 import java.awt.Panel;
45 import java.awt.Rectangle;
46 import java.awt.Scrollbar;
47 import java.awt.TextField;
48 import java.awt.event.ActionEvent;
49 import java.awt.event.ActionListener;
50 import java.awt.event.AdjustmentEvent;
51 import java.awt.event.AdjustmentListener;
52 import java.awt.event.FocusEvent;
53 import java.awt.event.FocusListener;
54 import java.awt.event.MouseEvent;
55 import java.util.Vector;
57 public class UserDefinedColours extends Panel
58 implements ActionListener, AdjustmentListener, FocusListener
63 SequenceGroup seqGroup;
65 Button selectedButton;
67 Vector<Color> oldColours = new Vector<>();
69 ColourSchemeI oldColourScheme;
73 mc_view.AppletPDBCanvas pdbcanvas;
83 FeatureColourI originalColour;
85 int R = 0, G = 0, B = 0;
87 public ColourSchemeI loadDefaultColours()
89 // NOT IMPLEMENTED YET IN APPLET VERSION
93 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
100 oldColourScheme = seqGroup.getColourScheme();
104 oldColourScheme = ap.av.getGlobalColourScheme();
110 public UserDefinedColours(mc_view.AppletPDBCanvas pdb)
112 this.pdbcanvas = pdb;
116 public UserDefinedColours(AppletJmol jmol)
122 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
125 originalColour = new FeatureColour(fr.colourPanel.getBackground());
126 originalLabel = "Feature Colour";
127 setForDialog("Select Feature Colour", alignframe);
128 setTargetColour(fr.colourPanel.getBackground());
129 dialog.setVisible(true);
132 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
134 this(caller, col1, alignframe, "Select Colour");
138 * Makes a dialog to choose the colour
145 * - the parent Frame for the dialog
149 public UserDefinedColours(Component caller, Color col, Frame alignframe,
152 this.caller = caller;
153 originalColour = new FeatureColour(col);
154 originalLabel = title;
155 setForDialog(title, alignframe);
156 setTargetColour(col);
157 dialog.setVisible(true);
161 * feature colour chooser
167 public UserDefinedColours(Object caller, String label, Color colour)
169 this(caller, label, new FeatureColour(colour), colour);
173 * feature colour chooser when changing style to single color
177 * @param graduatedColor
179 public UserDefinedColours(FeatureSettings me, String type,
180 FeatureColourI graduatedColor)
182 this(me, type, graduatedColor, graduatedColor.getMaxColour());
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);
217 throw new Error(MessageManager.getString(
218 "label.error_unsupported_owwner_user_colour_scheme"));
222 this.setSize(400, 123);
223 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
224 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
228 alignframe.getBounds().x
229 + (alignframe.getSize().width - width) / 2,
230 alignframe.getBounds().y
231 + (alignframe.getSize().height - height) / 2,
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 && oldColourScheme.isSimple())
416 col = oldColourScheme.findColour(aa.charAt(0), 0, null, null, 0f);
418 button.setBackground(col);
419 oldColours.addElement(col);
420 button.setLabel(label);
421 button.setForeground(col.darker().darker().darker());
422 button.setFont(new java.awt.Font("Verdana", 1, 10));
423 button.addMouseListener(new java.awt.event.MouseAdapter()
426 public void mousePressed(MouseEvent e)
428 colourButtonPressed(e);
432 buttonPanel.add(button, null);
435 protected void okButton_actionPerformed()
437 applyButton_actionPerformed();
440 dialog.setVisible(false);
443 frame.setVisible(false);
446 public Color getColor()
448 return new Color(R, G, B);
451 protected void applyButton_actionPerformed()
455 if (caller instanceof FeatureSettings)
457 ((FeatureSettings) caller).setUserColour(originalLabel,
458 new FeatureColour(getColor()));
460 else if (caller instanceof AnnotationColourChooser)
462 if (originalLabel.equals("Min Colour"))
464 ((AnnotationColourChooser) caller)
465 .minColour_actionPerformed(getColor());
469 ((AnnotationColourChooser) caller)
470 .maxColour_actionPerformed(getColor());
473 else if (caller instanceof FeatureRenderer)
475 ((FeatureRenderer) caller).colourPanel
476 .updateColor(new FeatureColour(getColor()));
478 else if (caller instanceof FeatureColourChooser)
480 if (originalLabel.indexOf("inimum") > -1)
482 ((FeatureColourChooser) caller)
483 .minColour_actionPerformed(getColor());
487 ((FeatureColourChooser) caller)
488 .maxColour_actionPerformed(getColor());
495 Color[] newColours = new Color[24];
496 for (int i = 0; i < 24; i++)
498 Button button = (Button) buttonPanel.getComponent(i);
499 newColours[i] = button.getBackground();
502 UserColourScheme ucs = new UserColourScheme(newColours);
505 // ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
510 if (seqGroup != null)
512 seqGroup.cs = new ResidueShader(ucs);
513 seqGroup.getGroupColourScheme().setThreshold(0,
514 ap.av.isIgnoreGapsConsensus());
518 ap.av.setGlobalColourScheme(ucs);
519 ap.av.getResidueShading().setThreshold(0,
520 ap.av.isIgnoreGapsConsensus());
522 ap.seqPanel.seqCanvas.img = null;
523 ap.paintAlignment(true, true);
525 else if (jmol != null)
527 jmol.colourByJalviewColourScheme(ucs);
529 else if (pdbcanvas != null)
531 pdbcanvas.setColours(ucs);
535 protected void cancelButton_actionPerformed()
539 if (caller instanceof FeatureSettings)
541 ((FeatureSettings) caller).setUserColour(originalLabel,
544 else if (caller instanceof AnnotationColourChooser)
546 if (originalLabel.equals("Min Colour"))
548 ((AnnotationColourChooser) caller)
549 .minColour_actionPerformed(originalColour.getColour());
553 ((AnnotationColourChooser) caller)
554 .maxColour_actionPerformed(originalColour.getColour());
557 else if (caller instanceof FeatureRenderer)
559 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
563 else if (caller instanceof FeatureColourChooser)
565 if (originalLabel.indexOf("inimum") > -1)
567 ((FeatureColourChooser) caller)
568 .minColour_actionPerformed(originalColour.getColour());
572 ((FeatureColourChooser) caller)
573 .maxColour_actionPerformed(originalColour.getColour());
578 dialog.setVisible(false);
581 frame.setVisible(false);
587 if (seqGroup != null)
589 seqGroup.cs = new ResidueShader(oldColourScheme);
590 if (oldColourScheme instanceof PIDColourScheme
591 || oldColourScheme instanceof Blosum62ColourScheme)
593 seqGroup.cs.setConsensus(AAFrequency.calculate(
594 seqGroup.getSequences(ap.av.getHiddenRepSequences()), 0,
595 ap.av.getAlignment().getWidth()));
600 ap.av.setGlobalColourScheme(oldColourScheme);
602 ap.paintAlignment(true, true);
605 frame.setVisible(false);
608 protected Panel buttonPanel = new Panel();
610 protected GridLayout gridLayout = new GridLayout();
612 Panel okcancelPanel = new Panel();
614 protected Button okButton = new Button();
616 protected Button applyButton = new Button();
618 protected Button cancelButton = new Button();
620 protected Scrollbar rScroller = new Scrollbar();
622 Label label1 = new Label();
624 protected TextField rText = new TextField();
626 Label label4 = new Label();
628 protected Scrollbar gScroller = new Scrollbar();
630 protected TextField gText = new TextField();
632 Label label5 = new Label();
634 protected Scrollbar bScroller = new Scrollbar();
636 protected TextField bText = new TextField();
638 protected Panel target = new Panel();
640 private void jbInit() throws Exception
642 this.setLayout(null);
643 buttonPanel.setLayout(gridLayout);
644 gridLayout.setColumns(6);
645 gridLayout.setRows(4);
646 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
647 okButton.setLabel(MessageManager.getString("action.ok"));
648 okButton.addActionListener(this);
649 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
650 applyButton.setLabel(MessageManager.getString("action.apply"));
651 applyButton.addActionListener(this);
652 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
653 cancelButton.setLabel(MessageManager.getString("action.cancel"));
654 cancelButton.addActionListener(this);
655 this.setBackground(new Color(212, 208, 223));
656 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
657 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
658 rScroller.setMaximum(256);
659 rScroller.setMinimum(0);
660 rScroller.setOrientation(0);
661 rScroller.setUnitIncrement(1);
662 rScroller.setVisibleAmount(1);
663 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
664 rScroller.addAdjustmentListener(this);
665 label1.setAlignment(Label.RIGHT);
667 label1.setBounds(new Rectangle(19, 30, 16, 15));
668 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
670 rText.setBounds(new Rectangle(156, 27, 53, 19));
671 rText.addActionListener(this);
672 rText.addFocusListener(this);
673 label4.setAlignment(Label.RIGHT);
675 label4.setBounds(new Rectangle(15, 56, 20, 15));
676 gScroller.setMaximum(256);
677 gScroller.setMinimum(0);
678 gScroller.setOrientation(0);
679 gScroller.setUnitIncrement(1);
680 gScroller.setVisibleAmount(1);
681 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
682 gScroller.addAdjustmentListener(this);
683 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
685 gText.setBounds(new Rectangle(156, 52, 53, 20));
686 gText.addActionListener(this);
687 gText.addFocusListener(this);
688 label5.setAlignment(Label.RIGHT);
690 label5.setBounds(new Rectangle(14, 82, 20, 15));
691 bScroller.setMaximum(256);
692 bScroller.setMinimum(0);
693 bScroller.setOrientation(0);
694 bScroller.setUnitIncrement(1);
695 bScroller.setVisibleAmount(1);
696 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
697 bScroller.addAdjustmentListener(this);
698 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
700 bText.setBounds(new Rectangle(157, 78, 52, 20));
701 bText.addActionListener(this);
702 bText.addFocusListener(this);
703 target.setBackground(Color.black);
704 target.setBounds(new Rectangle(229, 26, 134, 79));
705 this.add(okcancelPanel, null);
706 okcancelPanel.add(okButton, null);
707 okcancelPanel.add(applyButton, null);
708 okcancelPanel.add(cancelButton, null);
712 this.add(buttonPanel, null);
713 this.add(target, null);
723 public void focusGained(FocusEvent e)
729 * This method applies any change to an RGB value if the user tabs out of the
730 * field instead of pressing Enter
733 public void focusLost(FocusEvent e)
735 Component c = e.getComponent();
738 rText_actionPerformed();
744 gText_actionPerformed();
750 bText_actionPerformed();