2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5.1)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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;
23 import java.awt.event.*;
25 import jalview.datamodel.*;
26 import jalview.schemes.*;
28 public class UserDefinedColours extends Panel implements ActionListener,
34 SequenceGroup seqGroup;
36 Button selectedButton;
38 Vector oldColours = new Vector();
40 ColourSchemeI oldColourScheme;
44 MCview.AppletPDBCanvas pdbcanvas;
54 Object originalColour;
56 int R = 0, G = 0, B = 0;
58 public ColourSchemeI loadDefaultColours()
60 // NOT IMPLEMENTED YET IN APPLET VERSION
64 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
71 oldColourScheme = seqGroup.cs;
75 oldColourScheme = ap.av.getGlobalColourScheme();
81 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
87 public UserDefinedColours(AppletJmol jmol)
93 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
96 originalColour = fr.colourPanel.getBackground();
97 originalLabel = "Feature Colour";
98 setForDialog("Select Feature Colour", alignframe);
99 setTargetColour(fr.colourPanel.getBackground());
100 dialog.setVisible(true);
103 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
105 this(caller, col1, alignframe, "Select Colour");
109 * Makes a dialog to choose the colour
116 * - the parent Frame for the dialog
120 public UserDefinedColours(Component caller, Color col1, Frame alignframe,
123 this.caller = caller;
124 originalColour = col1;
125 originalLabel = title;
126 setForDialog(title, alignframe);
127 setTargetColour(col1);
128 dialog.setVisible(true);
132 * feature colour chooser
138 public UserDefinedColours(Object caller, String label, Color colour)
140 this(caller, label, colour, colour);
144 * feature colour chooser when changing style to single color
148 * @param graduatedColor
150 public UserDefinedColours(FeatureSettings me, String type,
151 GraduatedColor graduatedColor)
153 this(me, type, graduatedColor, graduatedColor.getMaxColor());
156 private UserDefinedColours(Object caller, String label, Object ocolour,
159 this.caller = caller;
160 originalColour = ocolour;
161 originalLabel = label;
165 setTargetColour(colour);
167 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
168 frame.setTitle("User Defined Colours - " + label);
169 frame.setSize(420, 200);
172 void setForDialog(String title, Container alignframe)
175 frame.setVisible(false);
177 if (alignframe instanceof Frame)
179 dialog = new Dialog((Frame) alignframe, title, true);
183 // if (alignframe instanceof JVDialog){
184 // // not 1.1 compatible!
185 // dialog = new Dialog(((JVDialog)alignframe), title, true);
187 throw new Error("Unsupported owner for User Colour scheme dialog.");
191 this.setSize(400, 123);
192 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
193 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
196 dialog.setBounds(alignframe.getBounds().x
197 + (alignframe.getSize().width - width) / 2, alignframe
199 + (alignframe.getSize().height - height) / 2, width, height);
203 public void actionPerformed(ActionEvent evt)
205 if (evt.getSource() == okButton)
207 okButton_actionPerformed();
209 else if (evt.getSource() == applyButton)
211 applyButton_actionPerformed();
213 else if (evt.getSource() == cancelButton)
215 cancelButton_actionPerformed();
217 else if (evt.getSource() == rText)
219 rText_actionPerformed();
221 else if (evt.getSource() == gText)
223 gText_actionPerformed();
225 else if (evt.getSource() == bText)
227 bText_actionPerformed();
231 public void adjustmentValueChanged(AdjustmentEvent evt)
233 if (evt.getSource() == rScroller)
235 rScroller_adjustmentValueChanged();
237 else if (evt.getSource() == gScroller)
239 gScroller_adjustmentValueChanged();
241 else if (evt.getSource() == bScroller)
243 bScroller_adjustmentValueChanged();
252 } catch (Exception e)
258 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420,
261 if (seqGroup != null)
263 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
266 for (int i = 0; i < 20; i++)
268 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
269 + "", ResidueProperties.aa[i]);
272 makeButton("B", "B");
273 makeButton("Z", "Z");
274 makeButton("X", "X");
275 makeButton("Gap", "'.','-',' '");
280 protected void rText_actionPerformed()
284 int i = Integer.parseInt(rText.getText());
285 rScroller.setValue(i);
286 rScroller_adjustmentValueChanged();
287 } catch (NumberFormatException ex)
292 protected void gText_actionPerformed()
296 int i = Integer.parseInt(gText.getText());
297 gScroller.setValue(i);
298 gScroller_adjustmentValueChanged();
299 } catch (NumberFormatException ex)
305 protected void bText_actionPerformed()
309 int i = Integer.parseInt(bText.getText());
310 bScroller.setValue(i);
311 bScroller_adjustmentValueChanged();
312 } catch (NumberFormatException ex)
318 protected void rScroller_adjustmentValueChanged()
320 R = rScroller.getValue();
321 rText.setText(R + "");
325 protected void gScroller_adjustmentValueChanged()
327 G = gScroller.getValue();
328 gText.setText(G + "");
332 protected void bScroller_adjustmentValueChanged()
334 B = bScroller.getValue();
335 bText.setText(B + "");
339 public void colourChanged()
341 Color col = new Color(R, G, B);
342 target.setBackground(col);
345 if (selectedButton != null)
347 selectedButton.setBackground(col);
348 selectedButton.repaint();
352 void setTargetColour(Color col)
358 rScroller.setValue(R);
359 gScroller.setValue(G);
360 bScroller.setValue(B);
361 rText.setText(R + "");
362 gText.setText(G + "");
363 bText.setText(B + "");
367 public void colourButtonPressed(MouseEvent e)
369 selectedButton = (Button) e.getSource();
370 setTargetColour(selectedButton.getBackground());
373 void makeButton(String label, String aa)
375 final Button button = new Button();
376 Color col = Color.white;
377 if (oldColourScheme != null)
381 col = oldColourScheme.findColour(aa.charAt(0), -1);
382 } catch (Exception ex)
386 button.setBackground(col);
387 oldColours.addElement(col);
388 button.setLabel(label);
389 button.setForeground(col.darker().darker().darker());
390 button.setFont(new java.awt.Font("Verdana", 1, 10));
391 button.addMouseListener(new java.awt.event.MouseAdapter()
393 public void mousePressed(MouseEvent e)
395 colourButtonPressed(e);
399 buttonPanel.add(button, null);
402 protected void okButton_actionPerformed()
404 applyButton_actionPerformed();
406 dialog.setVisible(false);
408 frame.setVisible(false);
411 public Color getColor()
413 return new Color(R, G, B);
416 protected void applyButton_actionPerformed()
420 if (caller instanceof FeatureSettings)
422 ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
424 else if (caller instanceof AnnotationColourChooser)
426 if (originalLabel.equals("Min Colour"))
428 ((AnnotationColourChooser) caller)
429 .minColour_actionPerformed(getColor());
433 ((AnnotationColourChooser) caller)
434 .maxColour_actionPerformed(getColor());
437 else if (caller instanceof FeatureRenderer)
439 ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
441 else if (caller instanceof FeatureColourChooser)
443 if (originalLabel.indexOf("inimum") > -1)
445 ((FeatureColourChooser) caller)
446 .minColour_actionPerformed(getColor());
450 ((FeatureColourChooser) caller)
451 .maxColour_actionPerformed(getColor());
458 Color[] newColours = new Color[24];
459 for (int i = 0; i < 24; i++)
461 Button button = (Button) buttonPanel.getComponent(i);
462 newColours[i] = button.getBackground();
465 UserColourScheme ucs = new UserColourScheme(newColours);
468 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
473 if (seqGroup != null)
479 ap.av.setGlobalColourScheme(ucs);
481 ap.seqPanel.seqCanvas.img = null;
482 ap.paintAlignment(true);
484 else if (jmol != null)
486 jmol.setJalviewColourScheme(ucs);
488 else if (pdbcanvas != null)
490 pdbcanvas.setColours(ucs);
494 protected void cancelButton_actionPerformed()
498 if (caller instanceof FeatureSettings)
500 ((FeatureSettings) caller).setUserColour(originalLabel,
503 else if (caller instanceof AnnotationColourChooser)
505 if (originalLabel.equals("Min Colour"))
507 ((AnnotationColourChooser) caller)
508 .minColour_actionPerformed((Color) originalColour);
512 ((AnnotationColourChooser) caller)
513 .maxColour_actionPerformed((Color) originalColour);
516 else if (caller instanceof FeatureRenderer)
518 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
522 else if (caller instanceof FeatureColourChooser)
524 if (originalLabel.indexOf("inimum") > -1)
526 ((FeatureColourChooser) caller)
527 .minColour_actionPerformed((Color) originalColour);
531 ((FeatureColourChooser) caller)
532 .maxColour_actionPerformed((Color) originalColour);
536 dialog.setVisible(false);
538 frame.setVisible(false);
542 Color[] newColours = new Color[24];
543 for (int i = 0; i < 24; i++)
545 newColours[i] = (Color) oldColours.elementAt(i);
546 buttonPanel.getComponent(i).setBackground(newColours[i]);
549 UserColourScheme ucs = new UserColourScheme(newColours);
553 if (seqGroup != null)
559 ap.av.setGlobalColourScheme(ucs);
561 ap.paintAlignment(true);
563 else if (jmol != null)
565 jmol.setJalviewColourScheme(ucs);
567 else if (pdbcanvas != null)
569 pdbcanvas.pdb.setColours(ucs);
572 frame.setVisible(false);
575 protected Panel buttonPanel = new Panel();
577 protected GridLayout gridLayout = new GridLayout();
579 Panel okcancelPanel = new Panel();
581 protected Button okButton = new Button();
583 protected Button applyButton = new Button();
585 protected Button cancelButton = new Button();
587 protected Scrollbar rScroller = new Scrollbar();
589 Label label1 = new Label();
591 protected TextField rText = new TextField();
593 Label label4 = new Label();
595 protected Scrollbar gScroller = new Scrollbar();
597 protected TextField gText = new TextField();
599 Label label5 = new Label();
601 protected Scrollbar bScroller = new Scrollbar();
603 protected TextField bText = new TextField();
605 protected Panel target = new Panel();
607 private void jbInit() throws Exception
609 this.setLayout(null);
610 buttonPanel.setLayout(gridLayout);
611 gridLayout.setColumns(6);
612 gridLayout.setRows(4);
613 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
614 okButton.setLabel("OK");
615 okButton.addActionListener(this);
616 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
617 applyButton.setLabel("Apply");
618 applyButton.addActionListener(this);
619 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
620 cancelButton.setLabel("Cancel");
621 cancelButton.addActionListener(this);
622 this.setBackground(new Color(212, 208, 223));
623 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
624 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
625 rScroller.setMaximum(256);
626 rScroller.setMinimum(0);
627 rScroller.setOrientation(0);
628 rScroller.setUnitIncrement(1);
629 rScroller.setVisibleAmount(1);
630 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
631 rScroller.addAdjustmentListener(this);
632 label1.setAlignment(Label.RIGHT);
634 label1.setBounds(new Rectangle(19, 30, 16, 15));
635 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
637 rText.setBounds(new Rectangle(156, 27, 53, 19));
638 rText.addActionListener(this);
639 label4.setAlignment(Label.RIGHT);
641 label4.setBounds(new Rectangle(15, 56, 20, 15));
642 gScroller.setMaximum(256);
643 gScroller.setMinimum(0);
644 gScroller.setOrientation(0);
645 gScroller.setUnitIncrement(1);
646 gScroller.setVisibleAmount(1);
647 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
648 gScroller.addAdjustmentListener(this);
649 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
651 gText.setBounds(new Rectangle(156, 52, 53, 20));
652 gText.addActionListener(this);
653 label5.setAlignment(Label.RIGHT);
655 label5.setBounds(new Rectangle(14, 82, 20, 15));
656 bScroller.setMaximum(256);
657 bScroller.setMinimum(0);
658 bScroller.setOrientation(0);
659 bScroller.setUnitIncrement(1);
660 bScroller.setVisibleAmount(1);
661 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
662 bScroller.addAdjustmentListener(this);
663 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
665 bText.setBounds(new Rectangle(157, 78, 52, 20));
666 bText.addActionListener(this);
667 target.setBackground(Color.black);
668 target.setBounds(new Rectangle(229, 26, 134, 79));
669 this.add(okcancelPanel, null);
670 okcancelPanel.add(okButton, null);
671 okcancelPanel.add(applyButton, null);
672 okcancelPanel.add(cancelButton, null);
673 this.add(buttonPanel, null);
674 this.add(target, null);