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());
390 Color[] newColours = new Color[24];
391 for (int i = 0; i < 24; i++)
393 Button button = (Button) buttonPanel.getComponent(i);
394 newColours[i] = button.getBackground();
397 UserColourScheme ucs = new UserColourScheme(newColours);
400 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
405 if (seqGroup != null)
411 ap.av.setGlobalColourScheme(ucs);
413 ap.seqPanel.seqCanvas.img = null;
414 ap.paintAlignment(true);
416 else if (jmol != null)
418 jmol.setJalviewColourScheme(ucs);
420 else if (pdbcanvas != null)
422 pdbcanvas.setColours(ucs);
426 protected void cancelButton_actionPerformed()
430 if (caller instanceof FeatureSettings)
432 ((FeatureSettings) caller).setUserColour(originalLabel,
435 else if (caller instanceof AnnotationColourChooser)
437 if (originalLabel.equals("Min Colour"))
439 ((AnnotationColourChooser) caller)
440 .minColour_actionPerformed(originalColour);
444 ((AnnotationColourChooser) caller)
445 .maxColour_actionPerformed(originalColour);
448 else if (caller instanceof FeatureRenderer)
450 ((FeatureRenderer) caller).colourPanel
451 .setBackground(originalColour);
456 dialog.setVisible(false);
458 frame.setVisible(false);
462 Color[] newColours = new Color[24];
463 for (int i = 0; i < 24; i++)
465 newColours[i] = (Color) oldColours.elementAt(i);
466 buttonPanel.getComponent(i).setBackground(newColours[i]);
469 UserColourScheme ucs = new UserColourScheme(newColours);
473 if (seqGroup != null)
479 ap.av.setGlobalColourScheme(ucs);
481 ap.paintAlignment(true);
483 else if (jmol != null)
485 jmol.setJalviewColourScheme(ucs);
487 else if (pdbcanvas != null)
489 pdbcanvas.pdb.setColours(ucs);
492 frame.setVisible(false);
495 protected Panel buttonPanel = new Panel();
497 protected GridLayout gridLayout = new GridLayout();
499 Panel okcancelPanel = new Panel();
501 protected Button okButton = new Button();
503 protected Button applyButton = new Button();
505 protected Button cancelButton = new Button();
507 protected Scrollbar rScroller = new Scrollbar();
509 Label label1 = new Label();
511 protected TextField rText = new TextField();
513 Label label4 = new Label();
515 protected Scrollbar gScroller = new Scrollbar();
517 protected TextField gText = new TextField();
519 Label label5 = new Label();
521 protected Scrollbar bScroller = new Scrollbar();
523 protected TextField bText = new TextField();
525 protected Panel target = new Panel();
527 private void jbInit() throws Exception
529 this.setLayout(null);
530 buttonPanel.setLayout(gridLayout);
531 gridLayout.setColumns(6);
532 gridLayout.setRows(4);
533 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
534 okButton.setLabel("OK");
535 okButton.addActionListener(this);
536 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
537 applyButton.setLabel("Apply");
538 applyButton.addActionListener(this);
539 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
540 cancelButton.setLabel("Cancel");
541 cancelButton.addActionListener(this);
542 this.setBackground(new Color(212, 208, 223));
543 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
544 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
545 rScroller.setMaximum(256);
546 rScroller.setMinimum(0);
547 rScroller.setOrientation(0);
548 rScroller.setUnitIncrement(1);
549 rScroller.setVisibleAmount(1);
550 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
551 rScroller.addAdjustmentListener(this);
552 label1.setAlignment(Label.RIGHT);
554 label1.setBounds(new Rectangle(19, 30, 16, 15));
555 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
557 rText.setBounds(new Rectangle(156, 27, 53, 19));
558 rText.addActionListener(this);
559 label4.setAlignment(Label.RIGHT);
561 label4.setBounds(new Rectangle(15, 56, 20, 15));
562 gScroller.setMaximum(256);
563 gScroller.setMinimum(0);
564 gScroller.setOrientation(0);
565 gScroller.setUnitIncrement(1);
566 gScroller.setVisibleAmount(1);
567 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
568 gScroller.addAdjustmentListener(this);
569 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
571 gText.setBounds(new Rectangle(156, 52, 53, 20));
572 gText.addActionListener(this);
573 label5.setAlignment(Label.RIGHT);
575 label5.setBounds(new Rectangle(14, 82, 20, 15));
576 bScroller.setMaximum(256);
577 bScroller.setMinimum(0);
578 bScroller.setOrientation(0);
579 bScroller.setUnitIncrement(1);
580 bScroller.setVisibleAmount(1);
581 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
582 bScroller.addAdjustmentListener(this);
583 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
585 bText.setBounds(new Rectangle(157, 78, 52, 20));
586 bText.addActionListener(this);
587 target.setBackground(Color.black);
588 target.setBounds(new Rectangle(229, 26, 134, 79));
589 this.add(okcancelPanel, null);
590 okcancelPanel.add(okButton, null);
591 okcancelPanel.add(applyButton, null);
592 okcancelPanel.add(cancelButton, null);
593 this.add(buttonPanel, null);
594 this.add(target, null);