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
41 FeatureSettings featureSettings;
\r
43 Color originalFeatureCol;
\r
45 int R = 0, G = 0, B = 0;
\r
47 public ColourSchemeI loadDefaultColours()
\r
49 // NOT IMPLEMENTED YET IN APPLET VERSION
\r
53 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
\r
58 if (seqGroup != null)
\r
60 oldColourScheme = seqGroup.cs;
\r
64 oldColourScheme = ap.av.getGlobalColourScheme();
\r
70 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
\r
72 this.pdbcanvas = pdb;
\r
76 public UserDefinedColours(FeatureSettings featureSettings,
\r
80 this.featureSettings = featureSettings;
\r
81 this.feature = feature;
\r
83 remove(buttonPanel);
\r
84 originalFeatureCol = col;
\r
85 setTargetColour(col);
\r
87 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
\r
88 frame.setTitle("User Defined Colours - "+feature);
\r
89 frame.setSize(420, 200);
\r
92 public void actionPerformed(ActionEvent evt)
\r
94 if(evt.getSource()==okButton)
\r
95 okButton_actionPerformed();
\r
96 else if(evt.getSource()==applyButton)
\r
97 applyButton_actionPerformed();
\r
98 else if(evt.getSource()==cancelButton)
\r
99 cancelButton_actionPerformed();
\r
100 else if(evt.getSource()==rText)
\r
101 rText_actionPerformed();
\r
102 else if (evt.getSource() == gText)
\r
103 gText_actionPerformed();
\r
104 else if (evt.getSource() == bText)
\r
105 bText_actionPerformed();
\r
108 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
110 if(evt.getSource()==rScroller)
\r
111 rScroller_adjustmentValueChanged();
\r
112 else if(evt.getSource()==gScroller)
\r
113 gScroller_adjustmentValueChanged();
\r
114 else if(evt.getSource()==bScroller)
\r
115 bScroller_adjustmentValueChanged();
\r
124 catch (Exception e)
\r
126 e.printStackTrace();
\r
128 frame = new Frame();
\r
130 jalview.bin.JalviewLite.addFrame(frame, "User defined colours", 420, 345);
\r
132 if (seqGroup != null)
\r
134 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
\r
137 for (int i = 0; i < 20; i++)
\r
139 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +
\r
140 "", ResidueProperties.aa[i]);
\r
143 makeButton("B", "B");
\r
144 makeButton("Z", "Z");
\r
145 makeButton("X", "X");
\r
146 makeButton("Gap", "'.','-',' '");
\r
150 protected void rText_actionPerformed()
\r
154 int i = Integer.parseInt(rText.getText());
\r
155 rScroller.setValue(i);
\r
156 rScroller_adjustmentValueChanged();
\r
158 catch (NumberFormatException ex)
\r
162 protected void gText_actionPerformed()
\r
166 int i = Integer.parseInt(gText.getText());
\r
167 gScroller.setValue(i);
\r
168 gScroller_adjustmentValueChanged();
\r
170 catch (NumberFormatException ex)
\r
175 protected void bText_actionPerformed()
\r
179 int i = Integer.parseInt(bText.getText());
\r
180 bScroller.setValue(i);
\r
181 bScroller_adjustmentValueChanged();
\r
183 catch (NumberFormatException ex)
\r
188 protected void rScroller_adjustmentValueChanged()
\r
190 R = rScroller.getValue();
\r
191 rText.setText(R + "");
\r
195 protected void gScroller_adjustmentValueChanged()
\r
197 G = gScroller.getValue();
\r
198 gText.setText(G + "");
\r
202 protected void bScroller_adjustmentValueChanged()
\r
204 B = bScroller.getValue();
\r
205 bText.setText(B + "");
\r
209 public void colourChanged()
\r
211 Color col = new Color(R, G, B);
\r
212 target.setBackground(col);
\r
215 if (selectedButton != null)
\r
217 selectedButton.setBackground(col);
\r
218 selectedButton.repaint();
\r
222 void setTargetColour(Color col)
\r
225 G = col.getGreen();
\r
227 rScroller.setValue(R);
\r
228 gScroller.setValue(G);
\r
229 bScroller.setValue(B);
\r
230 rText.setText(R + "");
\r
231 gText.setText(G + "");
\r
232 bText.setText(B + "");
\r
236 public void colourButtonPressed(MouseEvent e)
\r
238 selectedButton = (Button) e.getSource();
\r
239 setTargetColour(selectedButton.getBackground());
\r
242 void makeButton(String label, String aa)
\r
244 final Button button = new Button();
\r
245 Color col = Color.white;
\r
249 col = oldColourScheme.findColour(aa, -1);
\r
251 catch (Exception ex)
\r
254 button.setBackground(col);
\r
255 oldColours.addElement(col);
\r
256 button.setLabel(label);
\r
257 button.setForeground(col.darker().darker().darker());
\r
258 button.setFont(new java.awt.Font("Verdana", 1, 10));
\r
259 button.addMouseListener(new java.awt.event.MouseAdapter()
\r
261 public void mousePressed(MouseEvent e)
\r
263 colourButtonPressed(e);
\r
267 buttonPanel.add(button, null);
\r
270 protected void okButton_actionPerformed()
\r
272 applyButton_actionPerformed();
\r
273 frame.setVisible(false);
\r
276 protected void applyButton_actionPerformed()
\r
278 if (featureSettings != null)
\r
280 featureSettings.setUserColour(feature, new Color(R,G,B));
\r
284 Color[] newColours = new Color[24];
\r
285 for (int i = 0; i < 24; i++)
\r
287 Button button = (Button) buttonPanel.getComponent(i);
\r
288 newColours[i] = button.getBackground();
\r
291 UserColourScheme ucs = new UserColourScheme(newColours);
\r
293 ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
\r
297 if (seqGroup != null)
\r
303 ap.av.setGlobalColourScheme(ucs);
\r
305 ap.seqPanel.seqCanvas.img = null;
\r
308 else if(pdbcanvas!=null)
\r
310 pdbcanvas.pdb.setColours(ucs);
\r
311 pdbcanvas.updateSeqColours();
\r
316 protected void cancelButton_actionPerformed()
\r
318 if(featureSettings!=null)
\r
320 featureSettings.setUserColour(feature, originalFeatureCol);
\r
321 frame.setVisible(false);
\r
325 Color[] newColours = new Color[24];
\r
326 for (int i = 0; i < 24; i++)
\r
328 newColours[i] = (Color) oldColours.elementAt(i);
\r
329 buttonPanel.getComponent(i).setBackground(newColours[i]);
\r
332 UserColourScheme ucs = new UserColourScheme(newColours);
\r
336 if (seqGroup != null)
\r
342 ap.av.setGlobalColourScheme(ucs);
\r
346 else if(pdbcanvas!=null)
\r
348 pdbcanvas.pdb.setColours(ucs);
\r
351 frame.setVisible(false);
\r
355 protected Panel buttonPanel = new Panel();
\r
356 protected GridLayout gridLayout = new GridLayout();
\r
357 Panel okcancelPanel = new Panel();
\r
358 protected Button okButton = new Button();
\r
359 protected Button applyButton = new Button();
\r
360 protected Button cancelButton = new Button();
\r
361 protected Scrollbar rScroller = new Scrollbar();
\r
362 Label label1 = new Label();
\r
363 protected TextField rText = new TextField();
\r
364 Label label4 = new Label();
\r
365 protected Scrollbar gScroller = new Scrollbar();
\r
366 protected TextField gText = new TextField();
\r
367 Label label5 = new Label();
\r
368 protected Scrollbar bScroller = new Scrollbar();
\r
369 protected TextField bText = new TextField();
\r
370 protected Panel target = new Panel();
\r
372 private void jbInit() throws Exception {
\r
373 this.setLayout(null);
\r
374 buttonPanel.setLayout(gridLayout);
\r
375 gridLayout.setColumns(6);
\r
376 gridLayout.setRows(4);
\r
377 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
378 okButton.setLabel("OK");
\r
379 okButton.addActionListener(this);
\r
380 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
381 applyButton.setLabel("Apply");
\r
382 applyButton.addActionListener(this);
\r
383 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
384 cancelButton.setLabel("Cancel");
\r
385 cancelButton.addActionListener(this);
\r
386 this.setBackground(new Color(212, 208, 223));
\r
387 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
\r
388 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
\r
389 rScroller.setMaximum(256);
\r
390 rScroller.setMinimum(0);
\r
391 rScroller.setOrientation(0);
\r
392 rScroller.setUnitIncrement(1);
\r
393 rScroller.setVisibleAmount(1);
\r
394 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
\r
395 rScroller.addAdjustmentListener(this);
\r
396 label1.setAlignment(Label.RIGHT);
\r
397 label1.setText("R");
\r
398 label1.setBounds(new Rectangle(19, 30, 16, 15));
\r
399 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
400 rText.setText("0 ");
\r
401 rText.setBounds(new Rectangle(156, 27, 53, 19));
\r
402 rText.addActionListener(this);
\r
403 label4.setAlignment(Label.RIGHT);
\r
404 label4.setText("G");
\r
405 label4.setBounds(new Rectangle(15, 56, 20, 15));
\r
406 gScroller.setMaximum(256);
\r
407 gScroller.setMinimum(0);
\r
408 gScroller.setOrientation(0);
\r
409 gScroller.setUnitIncrement(1);
\r
410 gScroller.setVisibleAmount(1);
\r
411 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
\r
412 gScroller.addAdjustmentListener(this);
\r
413 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
414 gText.setText("0 ");
\r
415 gText.setBounds(new Rectangle(156, 52, 53, 20));
\r
416 gText.addActionListener(this);
\r
417 label5.setAlignment(Label.RIGHT);
\r
418 label5.setText("B");
\r
419 label5.setBounds(new Rectangle(14, 82, 20, 15));
\r
420 bScroller.setMaximum(256);
\r
421 bScroller.setMinimum(0);
\r
422 bScroller.setOrientation(0);
\r
423 bScroller.setUnitIncrement(1);
\r
424 bScroller.setVisibleAmount(1);
\r
425 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
\r
426 bScroller.addAdjustmentListener(this);
\r
427 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
428 bText.setText("0 ");
\r
429 bText.setBounds(new Rectangle(157, 78, 52, 20));
\r
430 bText.addActionListener(this);
\r
431 target.setBackground(Color.black);
\r
432 target.setBounds(new Rectangle(229, 26, 134, 79));
\r
433 this.add(okcancelPanel, null);
\r
434 okcancelPanel.add(okButton, null);
\r
435 okcancelPanel.add(applyButton, null);
\r
436 okcancelPanel.add(cancelButton, null);
\r
437 this.add(buttonPanel, null);
\r
438 this.add(target, null);
\r
439 this.add(gScroller);
\r
440 this.add(rScroller);
\r
441 this.add(bScroller);
\r