2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 package jalview.appletgui;
24 import java.awt.event.*;
26 import jalview.datamodel.*;
27 import jalview.schemes.*;
29 public class UserDefinedColours extends Panel implements ActionListener,
35 SequenceGroup seqGroup;
37 Button selectedButton;
39 Vector oldColours = new Vector();
41 ColourSchemeI oldColourScheme;
45 MCview.AppletPDBCanvas pdbcanvas;
57 int R = 0, G = 0, B = 0;
59 public ColourSchemeI loadDefaultColours()
61 // NOT IMPLEMENTED YET IN APPLET VERSION
65 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
72 oldColourScheme = seqGroup.cs;
76 oldColourScheme = ap.av.getGlobalColourScheme();
82 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
88 public UserDefinedColours(AppletJmol jmol)
94 public UserDefinedColours(FeatureRenderer fr, Frame alignframe)
97 originalColour = fr.colourPanel.getBackground();
98 originalLabel = "Feature Colour";
99 setForDialog("Select Feature Colour", alignframe);
100 setTargetColour(fr.colourPanel.getBackground());
101 dialog.setVisible(true);
103 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
105 this(caller, col1, alignframe, "Select Colour");
108 * Makes a dialog to choose the colour
109 * @param caller - handles events
110 * @param col1 - original colour
111 * @param alignframe - the parent Frame for the dialog
112 * @param title - window title
114 public UserDefinedColours(Component caller, Color col1, Frame alignframe, String title)
116 this.caller = caller;
117 originalColour = col1;
118 originalLabel = title;
119 setForDialog(title, alignframe);
120 setTargetColour(col1);
121 dialog.setVisible(true);
124 public UserDefinedColours(Object caller, String label, Color colour)
126 this.caller = caller;
127 originalColour = colour;
128 originalLabel = label;
132 setTargetColour(colour);
134 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
135 frame.setTitle("User Defined Colours - " + label);
136 frame.setSize(420, 200);
139 void setForDialog(String title, Container alignframe)
142 frame.setVisible(false);
144 if (alignframe instanceof Frame)
146 dialog = new Dialog((Frame)alignframe, title, true);
149 // if (alignframe instanceof JVDialog){
150 // // not 1.1 compatible!
151 // dialog = new Dialog(((JVDialog)alignframe), title, true);
153 throw new Error("Unsupported owner for User Colour scheme dialog.");
157 this.setSize(400, 123);
158 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
159 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
162 dialog.setBounds(alignframe.getBounds().x
163 + (alignframe.getSize().width - width) / 2, alignframe
165 + (alignframe.getSize().height - height) / 2, width, height);
169 public void actionPerformed(ActionEvent evt)
171 if (evt.getSource() == okButton)
173 okButton_actionPerformed();
175 else if (evt.getSource() == applyButton)
177 applyButton_actionPerformed();
179 else if (evt.getSource() == cancelButton)
181 cancelButton_actionPerformed();
183 else if (evt.getSource() == rText)
185 rText_actionPerformed();
187 else if (evt.getSource() == gText)
189 gText_actionPerformed();
191 else if (evt.getSource() == bText)
193 bText_actionPerformed();
197 public void adjustmentValueChanged(AdjustmentEvent evt)
199 if (evt.getSource() == rScroller)
201 rScroller_adjustmentValueChanged();
203 else if (evt.getSource() == gScroller)
205 gScroller_adjustmentValueChanged();
207 else if (evt.getSource() == bScroller)
209 bScroller_adjustmentValueChanged();
218 } catch (Exception e)
224 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420,
227 if (seqGroup != null)
229 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
232 for (int i = 0; i < 20; i++)
234 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
235 + "", ResidueProperties.aa[i]);
238 makeButton("B", "B");
239 makeButton("Z", "Z");
240 makeButton("X", "X");
241 makeButton("Gap", "'.','-',' '");
246 protected void rText_actionPerformed()
250 int i = Integer.parseInt(rText.getText());
251 rScroller.setValue(i);
252 rScroller_adjustmentValueChanged();
253 } catch (NumberFormatException ex)
258 protected void gText_actionPerformed()
262 int i = Integer.parseInt(gText.getText());
263 gScroller.setValue(i);
264 gScroller_adjustmentValueChanged();
265 } catch (NumberFormatException ex)
271 protected void bText_actionPerformed()
275 int i = Integer.parseInt(bText.getText());
276 bScroller.setValue(i);
277 bScroller_adjustmentValueChanged();
278 } catch (NumberFormatException ex)
284 protected void rScroller_adjustmentValueChanged()
286 R = rScroller.getValue();
287 rText.setText(R + "");
291 protected void gScroller_adjustmentValueChanged()
293 G = gScroller.getValue();
294 gText.setText(G + "");
298 protected void bScroller_adjustmentValueChanged()
300 B = bScroller.getValue();
301 bText.setText(B + "");
305 public void colourChanged()
307 Color col = new Color(R, G, B);
308 target.setBackground(col);
311 if (selectedButton != null)
313 selectedButton.setBackground(col);
314 selectedButton.repaint();
318 void setTargetColour(Color col)
324 rScroller.setValue(R);
325 gScroller.setValue(G);
326 bScroller.setValue(B);
327 rText.setText(R + "");
328 gText.setText(G + "");
329 bText.setText(B + "");
333 public void colourButtonPressed(MouseEvent e)
335 selectedButton = (Button) e.getSource();
336 setTargetColour(selectedButton.getBackground());
339 void makeButton(String label, String aa)
341 final Button button = new Button();
342 Color col = Color.white;
343 if (oldColourScheme!=null)
347 col = oldColourScheme.findColour(aa.charAt(0), -1);
348 } catch (Exception ex)
352 button.setBackground(col);
353 oldColours.addElement(col);
354 button.setLabel(label);
355 button.setForeground(col.darker().darker().darker());
356 button.setFont(new java.awt.Font("Verdana", 1, 10));
357 button.addMouseListener(new java.awt.event.MouseAdapter()
359 public void mousePressed(MouseEvent e)
361 colourButtonPressed(e);
365 buttonPanel.add(button, null);
368 protected void okButton_actionPerformed()
370 applyButton_actionPerformed();
372 dialog.setVisible(false);
374 frame.setVisible(false);
377 public Color getColor()
379 return new Color(R, G, B);
382 protected void applyButton_actionPerformed()
386 if (caller instanceof FeatureSettings)
388 ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
390 else if (caller instanceof AnnotationColourChooser)
392 if (originalLabel.equals("Min Colour"))
394 ((AnnotationColourChooser) caller)
395 .minColour_actionPerformed(getColor());
399 ((AnnotationColourChooser) caller)
400 .maxColour_actionPerformed(getColor());
403 else if (caller instanceof FeatureRenderer)
405 ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
407 else if (caller instanceof FeatureColourChooser)
409 if (originalLabel.indexOf("inimum")>-1)
411 ((FeatureColourChooser) caller).minColour_actionPerformed(getColor());
413 ((FeatureColourChooser) caller).maxColour_actionPerformed(getColor());
420 Color[] newColours = new Color[24];
421 for (int i = 0; i < 24; i++)
423 Button button = (Button) buttonPanel.getComponent(i);
424 newColours[i] = button.getBackground();
427 UserColourScheme ucs = new UserColourScheme(newColours);
430 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
435 if (seqGroup != null)
441 ap.av.setGlobalColourScheme(ucs);
443 ap.seqPanel.seqCanvas.img = null;
444 ap.paintAlignment(true);
446 else if (jmol != null)
448 jmol.setJalviewColourScheme(ucs);
450 else if (pdbcanvas != null)
452 pdbcanvas.setColours(ucs);
456 protected void cancelButton_actionPerformed()
460 if (caller instanceof FeatureSettings)
462 ((FeatureSettings) caller).setUserColour(originalLabel,
465 else if (caller instanceof AnnotationColourChooser)
467 if (originalLabel.equals("Min Colour"))
469 ((AnnotationColourChooser) caller)
470 .minColour_actionPerformed(originalColour);
474 ((AnnotationColourChooser) caller)
475 .maxColour_actionPerformed(originalColour);
478 else if (caller instanceof FeatureRenderer)
480 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
484 else if (caller instanceof FeatureColourChooser)
486 if (originalLabel.indexOf("inimum")>-1)
488 ((FeatureColourChooser) caller).minColour_actionPerformed(originalColour);
490 ((FeatureColourChooser) caller).maxColour_actionPerformed(originalColour);
494 dialog.setVisible(false);
496 frame.setVisible(false);
500 Color[] newColours = new Color[24];
501 for (int i = 0; i < 24; i++)
503 newColours[i] = (Color) oldColours.elementAt(i);
504 buttonPanel.getComponent(i).setBackground(newColours[i]);
507 UserColourScheme ucs = new UserColourScheme(newColours);
511 if (seqGroup != null)
517 ap.av.setGlobalColourScheme(ucs);
519 ap.paintAlignment(true);
521 else if (jmol != null)
523 jmol.setJalviewColourScheme(ucs);
525 else if (pdbcanvas != null)
527 pdbcanvas.pdb.setColours(ucs);
530 frame.setVisible(false);
533 protected Panel buttonPanel = new Panel();
535 protected GridLayout gridLayout = new GridLayout();
537 Panel okcancelPanel = new Panel();
539 protected Button okButton = new Button();
541 protected Button applyButton = new Button();
543 protected Button cancelButton = new Button();
545 protected Scrollbar rScroller = new Scrollbar();
547 Label label1 = new Label();
549 protected TextField rText = new TextField();
551 Label label4 = new Label();
553 protected Scrollbar gScroller = new Scrollbar();
555 protected TextField gText = new TextField();
557 Label label5 = new Label();
559 protected Scrollbar bScroller = new Scrollbar();
561 protected TextField bText = new TextField();
563 protected Panel target = new Panel();
565 private void jbInit() throws Exception
567 this.setLayout(null);
568 buttonPanel.setLayout(gridLayout);
569 gridLayout.setColumns(6);
570 gridLayout.setRows(4);
571 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
572 okButton.setLabel("OK");
573 okButton.addActionListener(this);
574 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
575 applyButton.setLabel("Apply");
576 applyButton.addActionListener(this);
577 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
578 cancelButton.setLabel("Cancel");
579 cancelButton.addActionListener(this);
580 this.setBackground(new Color(212, 208, 223));
581 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
582 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
583 rScroller.setMaximum(256);
584 rScroller.setMinimum(0);
585 rScroller.setOrientation(0);
586 rScroller.setUnitIncrement(1);
587 rScroller.setVisibleAmount(1);
588 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
589 rScroller.addAdjustmentListener(this);
590 label1.setAlignment(Label.RIGHT);
592 label1.setBounds(new Rectangle(19, 30, 16, 15));
593 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
595 rText.setBounds(new Rectangle(156, 27, 53, 19));
596 rText.addActionListener(this);
597 label4.setAlignment(Label.RIGHT);
599 label4.setBounds(new Rectangle(15, 56, 20, 15));
600 gScroller.setMaximum(256);
601 gScroller.setMinimum(0);
602 gScroller.setOrientation(0);
603 gScroller.setUnitIncrement(1);
604 gScroller.setVisibleAmount(1);
605 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
606 gScroller.addAdjustmentListener(this);
607 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
609 gText.setBounds(new Rectangle(156, 52, 53, 20));
610 gText.addActionListener(this);
611 label5.setAlignment(Label.RIGHT);
613 label5.setBounds(new Rectangle(14, 82, 20, 15));
614 bScroller.setMaximum(256);
615 bScroller.setMinimum(0);
616 bScroller.setOrientation(0);
617 bScroller.setUnitIncrement(1);
618 bScroller.setVisibleAmount(1);
619 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
620 bScroller.addAdjustmentListener(this);
621 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
623 bText.setBounds(new Rectangle(157, 78, 52, 20));
624 bText.addActionListener(this);
625 target.setBackground(Color.black);
626 target.setBounds(new Rectangle(229, 26, 134, 79));
627 this.add(okcancelPanel, null);
628 okcancelPanel.add(okButton, null);
629 okcancelPanel.add(applyButton, null);
630 okcancelPanel.add(cancelButton, null);
631 this.add(buttonPanel, null);
632 this.add(target, null);