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 java.awt.Button;
24 import java.awt.Color;
25 import java.awt.Component;
26 import java.awt.Container;
27 import java.awt.Dialog;
29 import java.awt.Frame;
30 import java.awt.GridLayout;
31 import java.awt.Label;
32 import java.awt.Panel;
33 import java.awt.Rectangle;
34 import java.awt.Scrollbar;
35 import java.awt.TextField;
36 import java.awt.event.ActionEvent;
37 import java.awt.event.ActionListener;
38 import java.awt.event.AdjustmentEvent;
39 import java.awt.event.AdjustmentListener;
40 import java.awt.event.FocusEvent;
41 import java.awt.event.FocusListener;
42 import java.awt.event.MouseEvent;
43 import java.util.Vector;
45 import jalview.datamodel.SequenceGroup;
46 import jalview.schemes.ColourSchemeI;
47 import jalview.schemes.GraduatedColor;
48 import jalview.schemes.ResidueProperties;
49 import jalview.schemes.UserColourScheme;
50 import jalview.util.MessageManager;
52 public class UserDefinedColours extends Panel implements ActionListener,
53 AdjustmentListener, FocusListener
58 SequenceGroup seqGroup;
60 Button selectedButton;
62 Vector oldColours = new Vector();
64 ColourSchemeI oldColourScheme;
68 MCview.AppletPDBCanvas pdbcanvas;
78 Object originalColour;
80 int R = 0, G = 0, B = 0;
82 public ColourSchemeI loadDefaultColours()
84 // NOT IMPLEMENTED YET IN APPLET VERSION
88 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
95 oldColourScheme = seqGroup.cs;
99 oldColourScheme = ap.av.getGlobalColourScheme();
105 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
107 this.pdbcanvas = pdb;
111 public UserDefinedColours(AppletJmol jmol)
117 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
120 originalColour = fr.colourPanel.getBackground();
121 originalLabel = "Feature Colour";
122 setForDialog("Select Feature Colour", alignframe);
123 setTargetColour(fr.colourPanel.getBackground());
124 dialog.setVisible(true);
127 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
129 this(caller, col1, alignframe, "Select Colour");
133 * Makes a dialog to choose the colour
140 * - the parent Frame for the dialog
144 public UserDefinedColours(Component caller, Color col1, Frame alignframe,
147 this.caller = caller;
148 originalColour = col1;
149 originalLabel = title;
150 setForDialog(title, alignframe);
151 setTargetColour(col1);
152 dialog.setVisible(true);
156 * feature colour chooser
162 public UserDefinedColours(Object caller, String label, Color colour)
164 this(caller, label, colour, colour);
168 * feature colour chooser when changing style to single color
172 * @param graduatedColor
174 public UserDefinedColours(FeatureSettings me, String type,
175 GraduatedColor graduatedColor)
177 this(me, type, graduatedColor, graduatedColor.getMaxColor());
180 private UserDefinedColours(Object caller, String label, Object ocolour,
183 this.caller = caller;
184 originalColour = ocolour;
185 originalLabel = label;
189 setTargetColour(colour);
191 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
192 frame.setTitle(MessageManager.getString("label.user_defined_colours") + " - " + label);
193 frame.setSize(420, 200);
196 void setForDialog(String title, Container alignframe)
199 frame.setVisible(false);
201 if (alignframe instanceof Frame)
203 dialog = new Dialog((Frame) alignframe, title, true);
207 // if (alignframe instanceof JVDialog){
208 // // not 1.1 compatible!
209 // dialog = new Dialog(((JVDialog)alignframe), title, true);
211 throw new Error(MessageManager.getString("label.error_unsupported_owwner_user_colour_scheme"));
215 this.setSize(400, 123);
216 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
217 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
220 dialog.setBounds(alignframe.getBounds().x
221 + (alignframe.getSize().width - width) / 2,
222 alignframe.getBounds().y
223 + (alignframe.getSize().height - height) / 2, width,
228 public void actionPerformed(ActionEvent evt)
230 final Object source = evt.getSource();
231 if (source == okButton)
233 okButton_actionPerformed();
235 else if (source == applyButton)
237 applyButton_actionPerformed();
239 else if (source == cancelButton)
241 cancelButton_actionPerformed();
243 else if (source == rText)
245 rText_actionPerformed();
247 else if (source == gText)
249 gText_actionPerformed();
251 else if (source == bText)
253 bText_actionPerformed();
257 public void adjustmentValueChanged(AdjustmentEvent evt)
259 if (evt.getSource() == rScroller)
261 rScroller_adjustmentValueChanged();
263 else if (evt.getSource() == gScroller)
265 gScroller_adjustmentValueChanged();
267 else if (evt.getSource() == bScroller)
269 bScroller_adjustmentValueChanged();
278 } catch (Exception e)
284 jalview.bin.JalviewLite.addFrame(frame,
285 MessageManager.getString("label.user_defined_colours"), 420,
288 if (seqGroup != null)
290 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
293 for (int i = 0; i < 20; i++)
295 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
296 + "", ResidueProperties.aa[i]);
299 makeButton("B", "B");
300 makeButton("Z", "Z");
301 makeButton("X", "X");
302 makeButton("Gap", "'.','-',' '");
307 protected void rText_actionPerformed()
311 int i = Integer.parseInt(rText.getText());
312 rScroller.setValue(i);
313 rScroller_adjustmentValueChanged();
314 } catch (NumberFormatException ex)
319 protected void gText_actionPerformed()
323 int i = Integer.parseInt(gText.getText());
324 gScroller.setValue(i);
325 gScroller_adjustmentValueChanged();
326 } catch (NumberFormatException ex)
332 protected void bText_actionPerformed()
336 int i = Integer.parseInt(bText.getText());
337 bScroller.setValue(i);
338 bScroller_adjustmentValueChanged();
339 } catch (NumberFormatException ex)
345 protected void rScroller_adjustmentValueChanged()
347 R = rScroller.getValue();
348 rText.setText(R + "");
352 protected void gScroller_adjustmentValueChanged()
354 G = gScroller.getValue();
355 gText.setText(G + "");
359 protected void bScroller_adjustmentValueChanged()
361 B = bScroller.getValue();
362 bText.setText(B + "");
366 public void colourChanged()
368 Color col = new Color(R, G, B);
369 target.setBackground(col);
372 if (selectedButton != null)
374 selectedButton.setBackground(col);
375 selectedButton.repaint();
379 void setTargetColour(Color col)
385 rScroller.setValue(R);
386 gScroller.setValue(G);
387 bScroller.setValue(B);
388 rText.setText(R + "");
389 gText.setText(G + "");
390 bText.setText(B + "");
394 public void colourButtonPressed(MouseEvent e)
396 selectedButton = (Button) e.getSource();
397 setTargetColour(selectedButton.getBackground());
400 void makeButton(String label, String aa)
402 final Button button = new Button();
403 Color col = Color.white;
404 if (oldColourScheme != null)
408 col = oldColourScheme.findColour(aa.charAt(0), -1, null);
409 } catch (Exception ex)
413 button.setBackground(col);
414 oldColours.addElement(col);
415 button.setLabel(label);
416 button.setForeground(col.darker().darker().darker());
417 button.setFont(new java.awt.Font("Verdana", 1, 10));
418 button.addMouseListener(new java.awt.event.MouseAdapter()
420 public void mousePressed(MouseEvent e)
422 colourButtonPressed(e);
426 buttonPanel.add(button, null);
429 protected void okButton_actionPerformed()
431 applyButton_actionPerformed();
434 dialog.setVisible(false);
437 frame.setVisible(false);
440 public Color getColor()
442 return new Color(R, G, B);
445 protected void applyButton_actionPerformed()
449 if (caller instanceof FeatureSettings)
451 ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
453 else if (caller instanceof AnnotationColourChooser)
455 if (originalLabel.equals("Min Colour"))
457 ((AnnotationColourChooser) caller)
458 .minColour_actionPerformed(getColor());
462 ((AnnotationColourChooser) caller)
463 .maxColour_actionPerformed(getColor());
466 else if (caller instanceof FeatureRenderer)
468 ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
470 else if (caller instanceof FeatureColourChooser)
472 if (originalLabel.indexOf("inimum") > -1)
474 ((FeatureColourChooser) caller)
475 .minColour_actionPerformed(getColor());
479 ((FeatureColourChooser) caller)
480 .maxColour_actionPerformed(getColor());
487 Color[] newColours = new Color[24];
488 for (int i = 0; i < 24; i++)
490 Button button = (Button) buttonPanel.getComponent(i);
491 newColours[i] = button.getBackground();
494 UserColourScheme ucs = new UserColourScheme(newColours);
497 ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
502 if (seqGroup != null)
508 ap.av.setGlobalColourScheme(ucs);
510 ap.seqPanel.seqCanvas.img = null;
511 ap.paintAlignment(true);
513 else if (jmol != null)
515 jmol.setJalviewColourScheme(ucs);
517 else if (pdbcanvas != null)
519 pdbcanvas.setColours(ucs);
523 protected void cancelButton_actionPerformed()
527 if (caller instanceof FeatureSettings)
529 ((FeatureSettings) caller).setUserColour(originalLabel,
532 else if (caller instanceof AnnotationColourChooser)
534 if (originalLabel.equals("Min Colour"))
536 ((AnnotationColourChooser) caller)
537 .minColour_actionPerformed((Color) originalColour);
541 ((AnnotationColourChooser) caller)
542 .maxColour_actionPerformed((Color) originalColour);
545 else if (caller instanceof FeatureRenderer)
547 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
551 else if (caller instanceof FeatureColourChooser)
553 if (originalLabel.indexOf("inimum") > -1)
555 ((FeatureColourChooser) caller)
556 .minColour_actionPerformed((Color) originalColour);
560 ((FeatureColourChooser) caller)
561 .maxColour_actionPerformed((Color) originalColour);
566 dialog.setVisible(false);
569 frame.setVisible(false);
573 Color[] newColours = new Color[24];
574 for (int i = 0; i < 24; i++)
576 newColours[i] = (Color) oldColours.elementAt(i);
577 buttonPanel.getComponent(i).setBackground(newColours[i]);
580 UserColourScheme ucs = new UserColourScheme(newColours);
584 if (seqGroup != null)
590 ap.av.setGlobalColourScheme(ucs);
592 ap.paintAlignment(true);
594 else if (jmol != null)
596 jmol.setJalviewColourScheme(ucs);
598 else if (pdbcanvas != null)
600 pdbcanvas.pdb.setColours(ucs);
603 frame.setVisible(false);
606 protected Panel buttonPanel = new Panel();
608 protected GridLayout gridLayout = new GridLayout();
610 Panel okcancelPanel = new Panel();
612 protected Button okButton = new Button();
614 protected Button applyButton = new Button();
616 protected Button cancelButton = new Button();
618 protected Scrollbar rScroller = new Scrollbar();
620 Label label1 = new Label();
622 protected TextField rText = new TextField();
624 Label label4 = new Label();
626 protected Scrollbar gScroller = new Scrollbar();
628 protected TextField gText = new TextField();
630 Label label5 = new Label();
632 protected Scrollbar bScroller = new Scrollbar();
634 protected TextField bText = new TextField();
636 protected Panel target = new Panel();
638 private void jbInit() throws Exception
640 this.setLayout(null);
641 buttonPanel.setLayout(gridLayout);
642 gridLayout.setColumns(6);
643 gridLayout.setRows(4);
644 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
645 okButton.setLabel(MessageManager.getString("action.ok"));
646 okButton.addActionListener(this);
647 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
648 applyButton.setLabel(MessageManager.getString("action.apply"));
649 applyButton.addActionListener(this);
650 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
651 cancelButton.setLabel(MessageManager.getString("action.cancel"));
652 cancelButton.addActionListener(this);
653 this.setBackground(new Color(212, 208, 223));
654 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
655 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
656 rScroller.setMaximum(256);
657 rScroller.setMinimum(0);
658 rScroller.setOrientation(0);
659 rScroller.setUnitIncrement(1);
660 rScroller.setVisibleAmount(1);
661 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
662 rScroller.addAdjustmentListener(this);
663 label1.setAlignment(Label.RIGHT);
665 label1.setBounds(new Rectangle(19, 30, 16, 15));
666 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
668 rText.setBounds(new Rectangle(156, 27, 53, 19));
669 rText.addActionListener(this);
670 rText.addFocusListener(this);
671 label4.setAlignment(Label.RIGHT);
673 label4.setBounds(new Rectangle(15, 56, 20, 15));
674 gScroller.setMaximum(256);
675 gScroller.setMinimum(0);
676 gScroller.setOrientation(0);
677 gScroller.setUnitIncrement(1);
678 gScroller.setVisibleAmount(1);
679 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
680 gScroller.addAdjustmentListener(this);
681 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
683 gText.setBounds(new Rectangle(156, 52, 53, 20));
684 gText.addActionListener(this);
685 gText.addFocusListener(this);
686 label5.setAlignment(Label.RIGHT);
688 label5.setBounds(new Rectangle(14, 82, 20, 15));
689 bScroller.setMaximum(256);
690 bScroller.setMinimum(0);
691 bScroller.setOrientation(0);
692 bScroller.setUnitIncrement(1);
693 bScroller.setVisibleAmount(1);
694 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
695 bScroller.addAdjustmentListener(this);
696 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
698 bText.setBounds(new Rectangle(157, 78, 52, 20));
699 bText.addActionListener(this);
700 bText.addFocusListener(this);
701 target.setBackground(Color.black);
702 target.setBounds(new Rectangle(229, 26, 134, 79));
703 this.add(okcancelPanel, null);
704 okcancelPanel.add(okButton, null);
705 okcancelPanel.add(applyButton, null);
706 okcancelPanel.add(cancelButton, null);
710 this.add(buttonPanel, null);
711 this.add(target, null);
721 public void focusGained(FocusEvent e)
727 * This method applies any change to an RGB value if the user tabs out of the
728 * field instead of pressing Enter
731 public void focusLost(FocusEvent e)
733 Component c = e.getComponent();
736 rText_actionPerformed();
742 gText_actionPerformed();
748 bText_actionPerformed();