2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
25 import java.awt.event.*;
\r
27 import jalview.datamodel.*;
\r
28 import jalview.schemes.*;
\r
30 public class UserDefinedColours
\r
31 extends Panel implements ActionListener, AdjustmentListener
\r
35 SequenceGroup seqGroup;
\r
36 Button selectedButton;
\r
37 Vector oldColours = new Vector();
\r
38 ColourSchemeI oldColourScheme;
\r
40 MCview.AppletPDBCanvas pdbcanvas;
\r
43 String originalLabel;
\r
44 Color originalColour;
\r
46 int R = 0, G = 0, B = 0;
\r
48 public ColourSchemeI loadDefaultColours()
\r
50 // NOT IMPLEMENTED YET IN APPLET VERSION
\r
54 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
\r
59 if (seqGroup != null)
\r
61 oldColourScheme = seqGroup.cs;
\r
65 oldColourScheme = ap.av.getGlobalColourScheme();
\r
71 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
\r
73 this.pdbcanvas = pdb;
\r
77 public UserDefinedColours(Component caller,
\r
81 this.caller = caller;
\r
82 originalColour = colour;
\r
83 originalLabel = label;
\r
85 remove(buttonPanel);
\r
87 setTargetColour(colour);
\r
89 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
\r
90 frame.setTitle("User Defined Colours - "+label);
\r
91 frame.setSize(420, 200);
\r
94 public void actionPerformed(ActionEvent evt)
\r
96 if(evt.getSource()==okButton)
\r
97 okButton_actionPerformed();
\r
98 else if(evt.getSource()==applyButton)
\r
99 applyButton_actionPerformed();
\r
100 else if(evt.getSource()==cancelButton)
\r
101 cancelButton_actionPerformed();
\r
102 else if(evt.getSource()==rText)
\r
103 rText_actionPerformed();
\r
104 else if (evt.getSource() == gText)
\r
105 gText_actionPerformed();
\r
106 else if (evt.getSource() == bText)
\r
107 bText_actionPerformed();
\r
110 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
112 if(evt.getSource()==rScroller)
\r
113 rScroller_adjustmentValueChanged();
\r
114 else if(evt.getSource()==gScroller)
\r
115 gScroller_adjustmentValueChanged();
\r
116 else if(evt.getSource()==bScroller)
\r
117 bScroller_adjustmentValueChanged();
\r
126 catch (Exception e)
\r
128 e.printStackTrace();
\r
130 frame = new Frame();
\r
132 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420, 345);
\r
134 if (seqGroup != null)
\r
136 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
\r
139 for (int i = 0; i < 20; i++)
\r
141 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +
\r
142 "", ResidueProperties.aa[i]);
\r
145 makeButton("B", "B");
\r
146 makeButton("Z", "Z");
\r
147 makeButton("X", "X");
\r
148 makeButton("Gap", "'.','-',' '");
\r
152 protected void rText_actionPerformed()
\r
156 int i = Integer.parseInt(rText.getText());
\r
157 rScroller.setValue(i);
\r
158 rScroller_adjustmentValueChanged();
\r
160 catch (NumberFormatException ex)
\r
164 protected void gText_actionPerformed()
\r
168 int i = Integer.parseInt(gText.getText());
\r
169 gScroller.setValue(i);
\r
170 gScroller_adjustmentValueChanged();
\r
172 catch (NumberFormatException ex)
\r
177 protected void bText_actionPerformed()
\r
181 int i = Integer.parseInt(bText.getText());
\r
182 bScroller.setValue(i);
\r
183 bScroller_adjustmentValueChanged();
\r
185 catch (NumberFormatException ex)
\r
190 protected void rScroller_adjustmentValueChanged()
\r
192 R = rScroller.getValue();
\r
193 rText.setText(R + "");
\r
197 protected void gScroller_adjustmentValueChanged()
\r
199 G = gScroller.getValue();
\r
200 gText.setText(G + "");
\r
204 protected void bScroller_adjustmentValueChanged()
\r
206 B = bScroller.getValue();
\r
207 bText.setText(B + "");
\r
211 public void colourChanged()
\r
213 Color col = new Color(R, G, B);
\r
214 target.setBackground(col);
\r
217 if (selectedButton != null)
\r
219 selectedButton.setBackground(col);
\r
220 selectedButton.repaint();
\r
224 void setTargetColour(Color col)
\r
227 G = col.getGreen();
\r
229 rScroller.setValue(R);
\r
230 gScroller.setValue(G);
\r
231 bScroller.setValue(B);
\r
232 rText.setText(R + "");
\r
233 gText.setText(G + "");
\r
234 bText.setText(B + "");
\r
238 public void colourButtonPressed(MouseEvent e)
\r
240 selectedButton = (Button) e.getSource();
\r
241 setTargetColour(selectedButton.getBackground());
\r
244 void makeButton(String label, String aa)
\r
246 final Button button = new Button();
\r
247 Color col = Color.white;
\r
251 col = oldColourScheme.findColour(aa, -1);
\r
253 catch (Exception ex)
\r
256 button.setBackground(col);
\r
257 oldColours.addElement(col);
\r
258 button.setLabel(label);
\r
259 button.setForeground(col.darker().darker().darker());
\r
260 button.setFont(new java.awt.Font("Verdana", 1, 10));
\r
261 button.addMouseListener(new java.awt.event.MouseAdapter()
\r
263 public void mousePressed(MouseEvent e)
\r
265 colourButtonPressed(e);
\r
269 buttonPanel.add(button, null);
\r
272 protected void okButton_actionPerformed()
\r
274 applyButton_actionPerformed();
\r
275 frame.setVisible(false);
\r
278 protected void applyButton_actionPerformed()
\r
280 if (caller != null)
\r
282 if(caller instanceof FeatureSettings)
\r
283 ((FeatureSettings)caller).setUserColour
\r
284 (originalLabel, new Color(R,G,B));
\r
285 else if(caller instanceof AnnotationColourChooser)
\r
287 if (originalLabel.equals("Min Colour"))
\r
288 ( (AnnotationColourChooser) caller).minColour_actionPerformed
\r
289 (new Color(R, G, B));
\r
291 ( (AnnotationColourChooser) caller).maxColour_actionPerformed
\r
292 (new Color(R, G, B));
\r
298 Color[] newColours = new Color[24];
\r
299 for (int i = 0; i < 24; i++)
\r
301 Button button = (Button) buttonPanel.getComponent(i);
\r
302 newColours[i] = button.getBackground();
\r
305 UserColourScheme ucs = new UserColourScheme(newColours);
\r
307 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
\r
311 if (seqGroup != null)
\r
317 ap.av.setGlobalColourScheme(ucs);
\r
319 ap.seqPanel.seqCanvas.img = null;
\r
322 else if(pdbcanvas!=null)
\r
324 pdbcanvas.pdb.setColours(ucs);
\r
325 pdbcanvas.updateSeqColours();
\r
330 protected void cancelButton_actionPerformed()
\r
332 if (caller != null)
\r
334 if(caller instanceof FeatureSettings)
\r
335 ((FeatureSettings)caller).setUserColour
\r
336 (originalLabel, originalColour);
\r
337 else if (caller instanceof AnnotationColourChooser)
\r
339 if (originalLabel.equals("Min Colour"))
\r
340 ( (AnnotationColourChooser) caller).minColour_actionPerformed
\r
343 ( (AnnotationColourChooser) caller).maxColour_actionPerformed
\r
346 frame.setVisible(false);
\r
350 Color[] newColours = new Color[24];
\r
351 for (int i = 0; i < 24; i++)
\r
353 newColours[i] = (Color) oldColours.elementAt(i);
\r
354 buttonPanel.getComponent(i).setBackground(newColours[i]);
\r
357 UserColourScheme ucs = new UserColourScheme(newColours);
\r
361 if (seqGroup != null)
\r
367 ap.av.setGlobalColourScheme(ucs);
\r
371 else if(pdbcanvas!=null)
\r
373 pdbcanvas.pdb.setColours(ucs);
\r
376 frame.setVisible(false);
\r
380 protected Panel buttonPanel = new Panel();
\r
381 protected GridLayout gridLayout = new GridLayout();
\r
382 Panel okcancelPanel = new Panel();
\r
383 protected Button okButton = new Button();
\r
384 protected Button applyButton = new Button();
\r
385 protected Button cancelButton = new Button();
\r
386 protected Scrollbar rScroller = new Scrollbar();
\r
387 Label label1 = new Label();
\r
388 protected TextField rText = new TextField();
\r
389 Label label4 = new Label();
\r
390 protected Scrollbar gScroller = new Scrollbar();
\r
391 protected TextField gText = new TextField();
\r
392 Label label5 = new Label();
\r
393 protected Scrollbar bScroller = new Scrollbar();
\r
394 protected TextField bText = new TextField();
\r
395 protected Panel target = new Panel();
\r
397 private void jbInit() throws Exception {
\r
398 this.setLayout(null);
\r
399 buttonPanel.setLayout(gridLayout);
\r
400 gridLayout.setColumns(6);
\r
401 gridLayout.setRows(4);
\r
402 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
403 okButton.setLabel("OK");
\r
404 okButton.addActionListener(this);
\r
405 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
406 applyButton.setLabel("Apply");
\r
407 applyButton.addActionListener(this);
\r
408 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
409 cancelButton.setLabel("Cancel");
\r
410 cancelButton.addActionListener(this);
\r
411 this.setBackground(new Color(212, 208, 223));
\r
412 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
\r
413 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
\r
414 rScroller.setMaximum(256);
\r
415 rScroller.setMinimum(0);
\r
416 rScroller.setOrientation(0);
\r
417 rScroller.setUnitIncrement(1);
\r
418 rScroller.setVisibleAmount(1);
\r
419 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
\r
420 rScroller.addAdjustmentListener(this);
\r
421 label1.setAlignment(Label.RIGHT);
\r
422 label1.setText("R");
\r
423 label1.setBounds(new Rectangle(19, 30, 16, 15));
\r
424 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
425 rText.setText("0 ");
\r
426 rText.setBounds(new Rectangle(156, 27, 53, 19));
\r
427 rText.addActionListener(this);
\r
428 label4.setAlignment(Label.RIGHT);
\r
429 label4.setText("G");
\r
430 label4.setBounds(new Rectangle(15, 56, 20, 15));
\r
431 gScroller.setMaximum(256);
\r
432 gScroller.setMinimum(0);
\r
433 gScroller.setOrientation(0);
\r
434 gScroller.setUnitIncrement(1);
\r
435 gScroller.setVisibleAmount(1);
\r
436 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
\r
437 gScroller.addAdjustmentListener(this);
\r
438 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
439 gText.setText("0 ");
\r
440 gText.setBounds(new Rectangle(156, 52, 53, 20));
\r
441 gText.addActionListener(this);
\r
442 label5.setAlignment(Label.RIGHT);
\r
443 label5.setText("B");
\r
444 label5.setBounds(new Rectangle(14, 82, 20, 15));
\r
445 bScroller.setMaximum(256);
\r
446 bScroller.setMinimum(0);
\r
447 bScroller.setOrientation(0);
\r
448 bScroller.setUnitIncrement(1);
\r
449 bScroller.setVisibleAmount(1);
\r
450 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
\r
451 bScroller.addAdjustmentListener(this);
\r
452 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
453 bText.setText("0 ");
\r
454 bText.setBounds(new Rectangle(157, 78, 52, 20));
\r
455 bText.addActionListener(this);
\r
456 target.setBackground(Color.black);
\r
457 target.setBounds(new Rectangle(229, 26, 134, 79));
\r
458 this.add(okcancelPanel, null);
\r
459 okcancelPanel.add(okButton, null);
\r
460 okcancelPanel.add(applyButton, null);
\r
461 okcancelPanel.add(cancelButton, null);
\r
462 this.add(buttonPanel, null);
\r
463 this.add(target, null);
\r
464 this.add(gScroller);
\r
465 this.add(rScroller);
\r
466 this.add(bScroller);
\r