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");
107 public UserDefinedColours(Component caller, Color col1, Container alignframe, String title)
109 this.caller = caller;
110 originalColour = col1;
111 originalLabel = title;
112 setForDialog(title, alignframe);
113 setTargetColour(col1);
114 dialog.setVisible(true);
117 public UserDefinedColours(Object caller, String label, Color colour)
119 this.caller = caller;
120 originalColour = colour;
121 originalLabel = label;
125 setTargetColour(colour);
127 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
128 frame.setTitle("User Defined Colours - " + label);
129 frame.setSize(420, 200);
132 void setForDialog(String title, Container alignframe)
135 frame.setVisible(false);
137 if (alignframe instanceof Frame)
139 dialog = new Dialog((Frame)alignframe, title, true);
142 if (alignframe instanceof JVDialog){
143 dialog = new Dialog(((JVDialog)alignframe), title, true);
145 throw new Error("Unsupported owner for User Colour scheme dialog.");
149 this.setSize(400, 123);
150 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
151 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
154 dialog.setBounds(alignframe.getBounds().x
155 + (alignframe.getSize().width - width) / 2, alignframe
157 + (alignframe.getSize().height - height) / 2, width, height);
161 public void actionPerformed(ActionEvent evt)
163 if (evt.getSource() == okButton)
165 okButton_actionPerformed();
167 else if (evt.getSource() == applyButton)
169 applyButton_actionPerformed();
171 else if (evt.getSource() == cancelButton)
173 cancelButton_actionPerformed();
175 else if (evt.getSource() == rText)
177 rText_actionPerformed();
179 else if (evt.getSource() == gText)
181 gText_actionPerformed();
183 else if (evt.getSource() == bText)
185 bText_actionPerformed();
189 public void adjustmentValueChanged(AdjustmentEvent evt)
191 if (evt.getSource() == rScroller)
193 rScroller_adjustmentValueChanged();
195 else if (evt.getSource() == gScroller)
197 gScroller_adjustmentValueChanged();
199 else if (evt.getSource() == bScroller)
201 bScroller_adjustmentValueChanged();
210 } catch (Exception e)
216 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420,
219 if (seqGroup != null)
221 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
224 for (int i = 0; i < 20; i++)
226 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
227 + "", ResidueProperties.aa[i]);
230 makeButton("B", "B");
231 makeButton("Z", "Z");
232 makeButton("X", "X");
233 makeButton("Gap", "'.','-',' '");
238 protected void rText_actionPerformed()
242 int i = Integer.parseInt(rText.getText());
243 rScroller.setValue(i);
244 rScroller_adjustmentValueChanged();
245 } catch (NumberFormatException ex)
250 protected void gText_actionPerformed()
254 int i = Integer.parseInt(gText.getText());
255 gScroller.setValue(i);
256 gScroller_adjustmentValueChanged();
257 } catch (NumberFormatException ex)
263 protected void bText_actionPerformed()
267 int i = Integer.parseInt(bText.getText());
268 bScroller.setValue(i);
269 bScroller_adjustmentValueChanged();
270 } catch (NumberFormatException ex)
276 protected void rScroller_adjustmentValueChanged()
278 R = rScroller.getValue();
279 rText.setText(R + "");
283 protected void gScroller_adjustmentValueChanged()
285 G = gScroller.getValue();
286 gText.setText(G + "");
290 protected void bScroller_adjustmentValueChanged()
292 B = bScroller.getValue();
293 bText.setText(B + "");
297 public void colourChanged()
299 Color col = new Color(R, G, B);
300 target.setBackground(col);
303 if (selectedButton != null)
305 selectedButton.setBackground(col);
306 selectedButton.repaint();
310 void setTargetColour(Color col)
316 rScroller.setValue(R);
317 gScroller.setValue(G);
318 bScroller.setValue(B);
319 rText.setText(R + "");
320 gText.setText(G + "");
321 bText.setText(B + "");
325 public void colourButtonPressed(MouseEvent e)
327 selectedButton = (Button) e.getSource();
328 setTargetColour(selectedButton.getBackground());
331 void makeButton(String label, String aa)
333 final Button button = new Button();
334 Color col = Color.white;
335 if (oldColourScheme!=null)
339 col = oldColourScheme.findColour(aa.charAt(0), -1);
340 } catch (Exception ex)
344 button.setBackground(col);
345 oldColours.addElement(col);
346 button.setLabel(label);
347 button.setForeground(col.darker().darker().darker());
348 button.setFont(new java.awt.Font("Verdana", 1, 10));
349 button.addMouseListener(new java.awt.event.MouseAdapter()
351 public void mousePressed(MouseEvent e)
353 colourButtonPressed(e);
357 buttonPanel.add(button, null);
360 protected void okButton_actionPerformed()
362 applyButton_actionPerformed();
364 dialog.setVisible(false);
366 frame.setVisible(false);
369 public Color getColor()
371 return new Color(R, G, B);
374 protected void applyButton_actionPerformed()
378 if (caller instanceof FeatureSettings)
380 ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
382 else if (caller instanceof AnnotationColourChooser)
384 if (originalLabel.equals("Min Colour"))
386 ((AnnotationColourChooser) caller)
387 .minColour_actionPerformed(getColor());
391 ((AnnotationColourChooser) caller)
392 .maxColour_actionPerformed(getColor());
395 else if (caller instanceof FeatureRenderer)
397 ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
399 else if (caller instanceof FeatureColourChooser)
401 if (originalLabel.indexOf("inimum")>-1)
403 ((FeatureColourChooser) caller).minColour_actionPerformed(getColor());
405 ((FeatureColourChooser) caller).maxColour_actionPerformed(getColor());
412 Color[] newColours = new Color[24];
413 for (int i = 0; i < 24; i++)
415 Button button = (Button) buttonPanel.getComponent(i);
416 newColours[i] = button.getBackground();
419 UserColourScheme ucs = new UserColourScheme(newColours);
422 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
427 if (seqGroup != null)
433 ap.av.setGlobalColourScheme(ucs);
435 ap.seqPanel.seqCanvas.img = null;
436 ap.paintAlignment(true);
438 else if (jmol != null)
440 jmol.setJalviewColourScheme(ucs);
442 else if (pdbcanvas != null)
444 pdbcanvas.setColours(ucs);
448 protected void cancelButton_actionPerformed()
452 if (caller instanceof FeatureSettings)
454 ((FeatureSettings) caller).setUserColour(originalLabel,
457 else if (caller instanceof AnnotationColourChooser)
459 if (originalLabel.equals("Min Colour"))
461 ((AnnotationColourChooser) caller)
462 .minColour_actionPerformed(originalColour);
466 ((AnnotationColourChooser) caller)
467 .maxColour_actionPerformed(originalColour);
470 else if (caller instanceof FeatureRenderer)
472 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
476 else if (caller instanceof FeatureColourChooser)
478 if (originalLabel.indexOf("inimum")>-1)
480 ((FeatureColourChooser) caller).minColour_actionPerformed(originalColour);
482 ((FeatureColourChooser) caller).maxColour_actionPerformed(originalColour);
486 dialog.setVisible(false);
488 frame.setVisible(false);
492 Color[] newColours = new Color[24];
493 for (int i = 0; i < 24; i++)
495 newColours[i] = (Color) oldColours.elementAt(i);
496 buttonPanel.getComponent(i).setBackground(newColours[i]);
499 UserColourScheme ucs = new UserColourScheme(newColours);
503 if (seqGroup != null)
509 ap.av.setGlobalColourScheme(ucs);
511 ap.paintAlignment(true);
513 else if (jmol != null)
515 jmol.setJalviewColourScheme(ucs);
517 else if (pdbcanvas != null)
519 pdbcanvas.pdb.setColours(ucs);
522 frame.setVisible(false);
525 protected Panel buttonPanel = new Panel();
527 protected GridLayout gridLayout = new GridLayout();
529 Panel okcancelPanel = new Panel();
531 protected Button okButton = new Button();
533 protected Button applyButton = new Button();
535 protected Button cancelButton = new Button();
537 protected Scrollbar rScroller = new Scrollbar();
539 Label label1 = new Label();
541 protected TextField rText = new TextField();
543 Label label4 = new Label();
545 protected Scrollbar gScroller = new Scrollbar();
547 protected TextField gText = new TextField();
549 Label label5 = new Label();
551 protected Scrollbar bScroller = new Scrollbar();
553 protected TextField bText = new TextField();
555 protected Panel target = new Panel();
557 private void jbInit() throws Exception
559 this.setLayout(null);
560 buttonPanel.setLayout(gridLayout);
561 gridLayout.setColumns(6);
562 gridLayout.setRows(4);
563 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
564 okButton.setLabel("OK");
565 okButton.addActionListener(this);
566 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
567 applyButton.setLabel("Apply");
568 applyButton.addActionListener(this);
569 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
570 cancelButton.setLabel("Cancel");
571 cancelButton.addActionListener(this);
572 this.setBackground(new Color(212, 208, 223));
573 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
574 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
575 rScroller.setMaximum(256);
576 rScroller.setMinimum(0);
577 rScroller.setOrientation(0);
578 rScroller.setUnitIncrement(1);
579 rScroller.setVisibleAmount(1);
580 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
581 rScroller.addAdjustmentListener(this);
582 label1.setAlignment(Label.RIGHT);
584 label1.setBounds(new Rectangle(19, 30, 16, 15));
585 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
587 rText.setBounds(new Rectangle(156, 27, 53, 19));
588 rText.addActionListener(this);
589 label4.setAlignment(Label.RIGHT);
591 label4.setBounds(new Rectangle(15, 56, 20, 15));
592 gScroller.setMaximum(256);
593 gScroller.setMinimum(0);
594 gScroller.setOrientation(0);
595 gScroller.setUnitIncrement(1);
596 gScroller.setVisibleAmount(1);
597 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
598 gScroller.addAdjustmentListener(this);
599 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
601 gText.setBounds(new Rectangle(156, 52, 53, 20));
602 gText.addActionListener(this);
603 label5.setAlignment(Label.RIGHT);
605 label5.setBounds(new Rectangle(14, 82, 20, 15));
606 bScroller.setMaximum(256);
607 bScroller.setMinimum(0);
608 bScroller.setOrientation(0);
609 bScroller.setUnitIncrement(1);
610 bScroller.setVisibleAmount(1);
611 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
612 bScroller.addAdjustmentListener(this);
613 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
615 bText.setBounds(new Rectangle(157, 78, 52, 20));
616 bText.addActionListener(this);
617 target.setBackground(Color.black);
618 target.setBounds(new Rectangle(229, 26, 134, 79));
619 this.add(okcancelPanel, null);
620 okcancelPanel.add(okButton, null);
621 okcancelPanel.add(applyButton, null);
622 okcancelPanel.add(cancelButton, null);
623 this.add(buttonPanel, null);
624 this.add(target, null);