2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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);
104 public UserDefinedColours(Component caller, Color col1, Frame alignframe)
106 this.caller = caller;
107 originalColour = col1;
108 originalLabel = "Select Colour";
109 setForDialog("Select Colour", alignframe);
110 setTargetColour(col1);
111 dialog.setVisible(true);
114 public UserDefinedColours(Object caller, String label, Color colour)
116 this.caller = caller;
117 originalColour = colour;
118 originalLabel = label;
122 setTargetColour(colour);
124 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
125 frame.setTitle("User Defined Colours - " + label);
126 frame.setSize(420, 200);
129 void setForDialog(String title, Frame alignframe)
132 frame.setVisible(false);
134 dialog = new Dialog(alignframe, title, true);
137 this.setSize(400, 123);
138 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
139 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
142 dialog.setBounds(alignframe.getBounds().x
143 + (alignframe.getSize().width - width) / 2, alignframe
145 + (alignframe.getSize().height - height) / 2, width, height);
149 public void actionPerformed(ActionEvent evt)
151 if (evt.getSource() == okButton)
153 okButton_actionPerformed();
155 else if (evt.getSource() == applyButton)
157 applyButton_actionPerformed();
159 else if (evt.getSource() == cancelButton)
161 cancelButton_actionPerformed();
163 else if (evt.getSource() == rText)
165 rText_actionPerformed();
167 else if (evt.getSource() == gText)
169 gText_actionPerformed();
171 else if (evt.getSource() == bText)
173 bText_actionPerformed();
177 public void adjustmentValueChanged(AdjustmentEvent evt)
179 if (evt.getSource() == rScroller)
181 rScroller_adjustmentValueChanged();
183 else if (evt.getSource() == gScroller)
185 gScroller_adjustmentValueChanged();
187 else if (evt.getSource() == bScroller)
189 bScroller_adjustmentValueChanged();
198 } catch (Exception e)
204 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420,
207 if (seqGroup != null)
209 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
212 for (int i = 0; i < 20; i++)
214 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
215 + "", ResidueProperties.aa[i]);
218 makeButton("B", "B");
219 makeButton("Z", "Z");
220 makeButton("X", "X");
221 makeButton("Gap", "'.','-',' '");
226 protected void rText_actionPerformed()
230 int i = Integer.parseInt(rText.getText());
231 rScroller.setValue(i);
232 rScroller_adjustmentValueChanged();
233 } catch (NumberFormatException ex)
238 protected void gText_actionPerformed()
242 int i = Integer.parseInt(gText.getText());
243 gScroller.setValue(i);
244 gScroller_adjustmentValueChanged();
245 } catch (NumberFormatException ex)
251 protected void bText_actionPerformed()
255 int i = Integer.parseInt(bText.getText());
256 bScroller.setValue(i);
257 bScroller_adjustmentValueChanged();
258 } catch (NumberFormatException ex)
264 protected void rScroller_adjustmentValueChanged()
266 R = rScroller.getValue();
267 rText.setText(R + "");
271 protected void gScroller_adjustmentValueChanged()
273 G = gScroller.getValue();
274 gText.setText(G + "");
278 protected void bScroller_adjustmentValueChanged()
280 B = bScroller.getValue();
281 bText.setText(B + "");
285 public void colourChanged()
287 Color col = new Color(R, G, B);
288 target.setBackground(col);
291 if (selectedButton != null)
293 selectedButton.setBackground(col);
294 selectedButton.repaint();
298 void setTargetColour(Color col)
304 rScroller.setValue(R);
305 gScroller.setValue(G);
306 bScroller.setValue(B);
307 rText.setText(R + "");
308 gText.setText(G + "");
309 bText.setText(B + "");
313 public void colourButtonPressed(MouseEvent e)
315 selectedButton = (Button) e.getSource();
316 setTargetColour(selectedButton.getBackground());
319 void makeButton(String label, String aa)
321 final Button button = new Button();
322 Color col = Color.white;
326 col = oldColourScheme.findColour(aa.charAt(0), -1);
327 } catch (Exception ex)
331 button.setBackground(col);
332 oldColours.addElement(col);
333 button.setLabel(label);
334 button.setForeground(col.darker().darker().darker());
335 button.setFont(new java.awt.Font("Verdana", 1, 10));
336 button.addMouseListener(new java.awt.event.MouseAdapter()
338 public void mousePressed(MouseEvent e)
340 colourButtonPressed(e);
344 buttonPanel.add(button, null);
347 protected void okButton_actionPerformed()
349 applyButton_actionPerformed();
351 dialog.setVisible(false);
353 frame.setVisible(false);
356 public Color getColor()
358 return new Color(R, G, B);
361 protected void applyButton_actionPerformed()
365 if (caller instanceof FeatureSettings)
367 ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
369 else if (caller instanceof AnnotationColourChooser)
371 if (originalLabel.equals("Min Colour"))
373 ((AnnotationColourChooser) caller)
374 .minColour_actionPerformed(getColor());
378 ((AnnotationColourChooser) caller)
379 .maxColour_actionPerformed(getColor());
382 else if (caller instanceof FeatureRenderer)
384 ((FeatureRenderer) caller).colourPanel.setBackground(getColor());
386 else if (caller instanceof FeatureColourChooser)
388 if (originalLabel.indexOf("inimum")>-1)
390 ((FeatureColourChooser) caller).minColour_actionPerformed(getColor());
392 ((FeatureColourChooser) caller).maxColour_actionPerformed(getColor());
399 Color[] newColours = new Color[24];
400 for (int i = 0; i < 24; i++)
402 Button button = (Button) buttonPanel.getComponent(i);
403 newColours[i] = button.getBackground();
406 UserColourScheme ucs = new UserColourScheme(newColours);
409 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
414 if (seqGroup != null)
420 ap.av.setGlobalColourScheme(ucs);
422 ap.seqPanel.seqCanvas.img = null;
423 ap.paintAlignment(true);
425 else if (jmol != null)
427 jmol.setJalviewColourScheme(ucs);
429 else if (pdbcanvas != null)
431 pdbcanvas.setColours(ucs);
435 protected void cancelButton_actionPerformed()
439 if (caller instanceof FeatureSettings)
441 ((FeatureSettings) caller).setUserColour(originalLabel,
444 else if (caller instanceof AnnotationColourChooser)
446 if (originalLabel.equals("Min Colour"))
448 ((AnnotationColourChooser) caller)
449 .minColour_actionPerformed(originalColour);
453 ((AnnotationColourChooser) caller)
454 .maxColour_actionPerformed(originalColour);
457 else if (caller instanceof FeatureRenderer)
459 ((FeatureRenderer) caller).colourPanel
460 .setBackground(originalColour);
465 dialog.setVisible(false);
467 frame.setVisible(false);
471 Color[] newColours = new Color[24];
472 for (int i = 0; i < 24; i++)
474 newColours[i] = (Color) oldColours.elementAt(i);
475 buttonPanel.getComponent(i).setBackground(newColours[i]);
478 UserColourScheme ucs = new UserColourScheme(newColours);
482 if (seqGroup != null)
488 ap.av.setGlobalColourScheme(ucs);
490 ap.paintAlignment(true);
492 else if (jmol != null)
494 jmol.setJalviewColourScheme(ucs);
496 else if (pdbcanvas != null)
498 pdbcanvas.pdb.setColours(ucs);
501 frame.setVisible(false);
504 protected Panel buttonPanel = new Panel();
506 protected GridLayout gridLayout = new GridLayout();
508 Panel okcancelPanel = new Panel();
510 protected Button okButton = new Button();
512 protected Button applyButton = new Button();
514 protected Button cancelButton = new Button();
516 protected Scrollbar rScroller = new Scrollbar();
518 Label label1 = new Label();
520 protected TextField rText = new TextField();
522 Label label4 = new Label();
524 protected Scrollbar gScroller = new Scrollbar();
526 protected TextField gText = new TextField();
528 Label label5 = new Label();
530 protected Scrollbar bScroller = new Scrollbar();
532 protected TextField bText = new TextField();
534 protected Panel target = new Panel();
536 private void jbInit() throws Exception
538 this.setLayout(null);
539 buttonPanel.setLayout(gridLayout);
540 gridLayout.setColumns(6);
541 gridLayout.setRows(4);
542 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
543 okButton.setLabel("OK");
544 okButton.addActionListener(this);
545 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
546 applyButton.setLabel("Apply");
547 applyButton.addActionListener(this);
548 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
549 cancelButton.setLabel("Cancel");
550 cancelButton.addActionListener(this);
551 this.setBackground(new Color(212, 208, 223));
552 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
553 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
554 rScroller.setMaximum(256);
555 rScroller.setMinimum(0);
556 rScroller.setOrientation(0);
557 rScroller.setUnitIncrement(1);
558 rScroller.setVisibleAmount(1);
559 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
560 rScroller.addAdjustmentListener(this);
561 label1.setAlignment(Label.RIGHT);
563 label1.setBounds(new Rectangle(19, 30, 16, 15));
564 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
566 rText.setBounds(new Rectangle(156, 27, 53, 19));
567 rText.addActionListener(this);
568 label4.setAlignment(Label.RIGHT);
570 label4.setBounds(new Rectangle(15, 56, 20, 15));
571 gScroller.setMaximum(256);
572 gScroller.setMinimum(0);
573 gScroller.setOrientation(0);
574 gScroller.setUnitIncrement(1);
575 gScroller.setVisibleAmount(1);
576 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
577 gScroller.addAdjustmentListener(this);
578 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
580 gText.setBounds(new Rectangle(156, 52, 53, 20));
581 gText.addActionListener(this);
582 label5.setAlignment(Label.RIGHT);
584 label5.setBounds(new Rectangle(14, 82, 20, 15));
585 bScroller.setMaximum(256);
586 bScroller.setMinimum(0);
587 bScroller.setOrientation(0);
588 bScroller.setUnitIncrement(1);
589 bScroller.setVisibleAmount(1);
590 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
591 bScroller.addAdjustmentListener(this);
592 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
594 bText.setBounds(new Rectangle(157, 78, 52, 20));
595 bText.addActionListener(this);
596 target.setBackground(Color.black);
597 target.setBounds(new Rectangle(229, 26, 134, 79));
598 this.add(okcancelPanel, null);
599 okcancelPanel.add(okButton, null);
600 okcancelPanel.add(applyButton, null);
601 okcancelPanel.add(cancelButton, null);
602 this.add(buttonPanel, null);
603 this.add(target, null);