2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
\r
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3
\r
10 * of the License, or (at your option) any later version.
\r
12 * Jalview is distributed in the hope that it will be useful, but
\r
13 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
15 * PURPOSE. See the GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
\r
21 package jalview.appletgui;
\r
23 import jalview.bin.JalviewLite;
\r
24 import jalview.datamodel.SequenceGroup;
\r
25 import jalview.schemes.ColourSchemeI;
\r
26 import jalview.schemes.GraduatedColor;
\r
27 import jalview.schemes.ResidueProperties;
\r
28 import jalview.schemes.UserColourScheme;
\r
29 import jalview.util.MessageManager;
\r
31 import javax.swing.JButton;
\r
32 import java.awt.Color;
\r
33 import java.awt.Component;
\r
34 import java.awt.Container;
\r
35 import javax.swing.JDialog;
\r
36 import java.awt.Font;
\r
37 import javax.swing.JFrame;
\r
38 import java.awt.GridLayout;
\r
39 import javax.swing.JLabel;
\r
40 import javax.swing.JPanel;
\r
41 import java.awt.Rectangle;
\r
42 import javax.swing.JScrollBar;
\r
43 import javax.swing.JTextField;
\r
44 import java.awt.event.ActionEvent;
\r
45 import java.awt.event.ActionListener;
\r
46 import java.awt.event.AdjustmentEvent;
\r
47 import java.awt.event.AdjustmentListener;
\r
48 import java.awt.event.FocusEvent;
\r
49 import java.awt.event.FocusListener;
\r
50 import java.awt.event.MouseEvent;
\r
51 import java.util.Vector;
\r
53 public class UserDefinedColours extends JPanel implements ActionListener,
\r
54 AdjustmentListener, FocusListener
\r
59 SequenceGroup seqGroup;
\r
61 JButton selectedButton;
\r
63 Vector oldColours = new Vector();
\r
65 ColourSchemeI oldColourScheme;
\r
69 MCview.AppletPDBCanvas pdbcanvas;
\r
77 String originalLabel;
\r
79 Object originalColour;
\r
81 int R = 0, G = 0, B = 0;
\r
83 public ColourSchemeI loadDefaultColours()
\r
85 // NOT IMPLEMENTED YET IN APPLET VERSION
\r
89 public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
\r
94 if (seqGroup != null)
\r
96 oldColourScheme = seqGroup.cs;
\r
100 oldColourScheme = ap.av.getGlobalColourScheme();
\r
106 public UserDefinedColours(MCview.AppletPDBCanvas pdb)
\r
108 this.pdbcanvas = pdb;
\r
112 public UserDefinedColours(AppletJmol jmol)
\r
118 public UserDefinedColours(FeatureRenderer fr, JFrame alignframe)
\r
121 originalColour = fr.colourPanel.getBackground();
\r
122 originalLabel = "Feature Colour";
\r
123 setForDialog("Select Feature Colour", alignframe);
\r
124 setTargetColour(fr.colourPanel.getBackground());
\r
125 dialog.setVisible(true);
\r
128 public UserDefinedColours(Component caller, Color col1, JFrame alignframe)
\r
130 this(caller, col1, alignframe, "Select Colour");
\r
134 * Makes a dialog to choose the colour
\r
139 * - original colour
\r
140 * @param alignframe
\r
141 * - the parent Frame for the dialog
\r
145 public UserDefinedColours(Component caller, Color col1, JFrame alignframe,
\r
148 this.caller = caller;
\r
149 originalColour = col1;
\r
150 originalLabel = title;
\r
151 setForDialog(title, alignframe);
\r
152 setTargetColour(col1);
\r
153 dialog.setVisible(true);
\r
157 * feature colour chooser
\r
163 public UserDefinedColours(Object caller, String label, Color colour)
\r
165 this(caller, label, colour, colour);
\r
169 * feature colour chooser when changing style to single color
\r
173 * @param graduatedColor
\r
175 public UserDefinedColours(FeatureSettings me, String type,
\r
176 GraduatedColor graduatedColor)
\r
178 this(me, type, graduatedColor, graduatedColor.getMaxColor());
\r
181 private UserDefinedColours(Object caller, String label, Object ocolour,
\r
184 this.caller = caller;
\r
185 originalColour = ocolour;
\r
186 originalLabel = label;
\r
188 remove(buttonPanel);
\r
190 setTargetColour(colour);
\r
192 okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
\r
193 frame.setTitle(MessageManager.getString("label.user_defined_colours") + " - " + label);
\r
194 frame.setSize(420, 200);
\r
197 void setForDialog(String title, Container alignframe)
\r
200 frame.setVisible(false);
\r
201 remove(buttonPanel);
\r
202 if (alignframe instanceof JFrame)
\r
204 dialog = new JDialog((JFrame) alignframe, title, true);
\r
208 // if (alignframe instanceof JVDialog){
\r
209 // // not 1.1 compatible!
\r
210 // dialog = new Dialog(((JVDialog)alignframe), title, true);
\r
212 throw new Error(MessageManager.getString("label.error_unsupported_owwner_user_colour_scheme"));
\r
216 this.setSize(400, 123);
\r
217 okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
\r
218 int height = 160 + alignframe.getInsets().top + getInsets().bottom;
\r
221 dialog.setBounds(alignframe.getBounds().x
\r
222 + (alignframe.getSize().width - width) / 2,
\r
223 alignframe.getBounds().y
\r
224 + (alignframe.getSize().height - height) / 2, width,
\r
229 public void actionPerformed(ActionEvent evt)
\r
231 final Object source = evt.getSource();
\r
232 if (source == okButton)
\r
234 okButton_actionPerformed();
\r
236 else if (source == applyButton)
\r
238 applyButton_actionPerformed();
\r
240 else if (source == cancelButton)
\r
242 cancelButton_actionPerformed();
\r
244 else if (source == rText)
\r
246 rText_actionPerformed();
\r
248 else if (source == gText)
\r
250 gText_actionPerformed();
\r
252 else if (source == bText)
\r
254 bText_actionPerformed();
\r
258 public void adjustmentValueChanged(AdjustmentEvent evt)
\r
260 if (evt.getSource() == rScroller)
\r
262 rScroller_adjustmentValueChanged();
\r
264 else if (evt.getSource() == gScroller)
\r
266 gScroller_adjustmentValueChanged();
\r
268 else if (evt.getSource() == bScroller)
\r
270 bScroller_adjustmentValueChanged();
\r
279 } catch (Exception e)
\r
281 e.printStackTrace();
\r
283 frame = new JFrame();
\r
285 JalviewLite.addFrame(frame,
\r
286 MessageManager.getString("label.user_defined_colours"), 420,
\r
289 if (seqGroup != null)
\r
291 frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
\r
294 for (int i = 0; i < 20; i++)
\r
296 makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
\r
297 + "", ResidueProperties.aa[i]);
\r
300 makeButton("B", "B");
\r
301 makeButton("Z", "Z");
\r
302 makeButton("X", "X");
\r
303 makeButton("Gap", "'.','-',' '");
\r
308 protected void rText_actionPerformed()
\r
312 int i = Integer.parseInt(rText.getText());
\r
313 rScroller.setValue(i);
\r
314 rScroller_adjustmentValueChanged();
\r
315 } catch (NumberFormatException ex)
\r
320 protected void gText_actionPerformed()
\r
324 int i = Integer.parseInt(gText.getText());
\r
325 gScroller.setValue(i);
\r
326 gScroller_adjustmentValueChanged();
\r
327 } catch (NumberFormatException ex)
\r
333 protected void bText_actionPerformed()
\r
337 int i = Integer.parseInt(bText.getText());
\r
338 bScroller.setValue(i);
\r
339 bScroller_adjustmentValueChanged();
\r
340 } catch (NumberFormatException ex)
\r
346 protected void rScroller_adjustmentValueChanged()
\r
348 R = rScroller.getValue();
\r
349 rText.setText(R + "");
\r
353 protected void gScroller_adjustmentValueChanged()
\r
355 G = gScroller.getValue();
\r
356 gText.setText(G + "");
\r
360 protected void bScroller_adjustmentValueChanged()
\r
362 B = bScroller.getValue();
\r
363 bText.setText(B + "");
\r
367 public void colourChanged()
\r
369 Color col = new Color(R, G, B);
\r
370 target.setBackground(col);
\r
373 if (selectedButton != null)
\r
375 selectedButton.setBackground(col);
\r
376 selectedButton.repaint();
\r
380 void setTargetColour(Color col)
\r
383 G = col.getGreen();
\r
386 rScroller.setValue(R);
\r
387 gScroller.setValue(G);
\r
388 bScroller.setValue(B);
\r
389 rText.setText(R + "");
\r
390 gText.setText(G + "");
\r
391 bText.setText(B + "");
\r
395 public void colourButtonPressed(MouseEvent e)
\r
397 selectedButton = (JButton) e.getSource();
\r
398 setTargetColour(selectedButton.getBackground());
\r
401 void makeButton(String label, String aa)
\r
403 final JButton button = new JButton();
\r
404 Color col = Color.white;
\r
405 if (oldColourScheme != null)
\r
409 col = oldColourScheme.findColour(aa.charAt(0), -1, null);
\r
410 } catch (Exception ex)
\r
414 button.setBackground(col);
\r
415 oldColours.addElement(col);
\r
416 button.setLabel(label);
\r
417 button.setForeground(col.darker().darker().darker());
\r
418 button.setFont(new java.awt.Font("Verdana", 1, 10));
\r
419 button.addMouseListener(new java.awt.event.MouseAdapter()
\r
421 public void mousePressed(MouseEvent e)
\r
423 colourButtonPressed(e);
\r
427 buttonPanel.add(button, null);
\r
430 protected void okButton_actionPerformed()
\r
432 applyButton_actionPerformed();
\r
433 if (dialog != null)
\r
435 dialog.setVisible(false);
\r
438 frame.setVisible(false);
\r
441 public Color getColor()
\r
443 return new Color(R, G, B);
\r
446 protected void applyButton_actionPerformed()
\r
448 if (caller != null)
\r
450 if (caller instanceof FeatureSettings)
\r
452 ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
\r
454 else if (caller instanceof AnnotationColourChooser)
\r
456 if (originalLabel.equals("Min Colour"))
\r
458 ((AnnotationColourChooser) caller)
\r
459 .minColour_actionPerformed(getColor());
\r
463 ((AnnotationColourChooser) caller)
\r
464 .maxColour_actionPerformed(getColor());
\r
467 else if (caller instanceof FeatureRenderer)
\r
469 ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
\r
471 else if (caller instanceof FeatureColourChooser)
\r
473 if (originalLabel.indexOf("inimum") > -1)
\r
475 ((FeatureColourChooser) caller)
\r
476 .minColour_actionPerformed(getColor());
\r
480 ((FeatureColourChooser) caller)
\r
481 .maxColour_actionPerformed(getColor());
\r
488 Color[] newColours = new Color[24];
\r
489 for (int i = 0; i < 24; i++)
\r
491 JButton button = (JButton) buttonPanel.getComponent(i);
\r
492 newColours[i] = button.getBackground();
\r
495 UserColourScheme ucs = new UserColourScheme(newColours);
\r
498 ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
\r
503 if (seqGroup != null)
\r
509 ap.av.setGlobalColourScheme(ucs);
\r
511 ap.seqPanel.seqCanvas.img = null;
\r
512 ap.paintAlignment(true);
\r
514 else if (jmol != null)
\r
516 jmol.setJalviewColourScheme(ucs);
\r
518 else if (pdbcanvas != null)
\r
520 pdbcanvas.setColours(ucs);
\r
524 protected void cancelButton_actionPerformed()
\r
526 if (caller != null)
\r
528 if (caller instanceof FeatureSettings)
\r
530 ((FeatureSettings) caller).setUserColour(originalLabel,
\r
533 else if (caller instanceof AnnotationColourChooser)
\r
535 if (originalLabel.equals("Min Colour"))
\r
537 ((AnnotationColourChooser) caller)
\r
538 .minColour_actionPerformed((Color) originalColour);
\r
542 ((AnnotationColourChooser) caller)
\r
543 .maxColour_actionPerformed((Color) originalColour);
\r
546 else if (caller instanceof FeatureRenderer)
\r
548 ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
\r
552 else if (caller instanceof FeatureColourChooser)
\r
554 if (originalLabel.indexOf("inimum") > -1)
\r
556 ((FeatureColourChooser) caller)
\r
557 .minColour_actionPerformed((Color) originalColour);
\r
561 ((FeatureColourChooser) caller)
\r
562 .maxColour_actionPerformed((Color) originalColour);
\r
565 if (dialog != null)
\r
567 dialog.setVisible(false);
\r
570 frame.setVisible(false);
\r
574 Color[] newColours = new Color[24];
\r
575 for (int i = 0; i < 24; i++)
\r
577 newColours[i] = (Color) oldColours.elementAt(i);
\r
578 buttonPanel.getComponent(i).setBackground(newColours[i]);
\r
581 UserColourScheme ucs = new UserColourScheme(newColours);
\r
585 if (seqGroup != null)
\r
591 ap.av.setGlobalColourScheme(ucs);
\r
593 ap.paintAlignment(true);
\r
595 else if (jmol != null)
\r
597 jmol.setJalviewColourScheme(ucs);
\r
599 else if (pdbcanvas != null)
\r
601 pdbcanvas.pdb.setColours(ucs);
\r
604 frame.setVisible(false);
\r
607 protected JPanel buttonPanel = new JPanel();
\r
609 protected GridLayout gridLayout = new GridLayout();
\r
611 JPanel okcancelPanel = new JPanel();
\r
613 protected JButton okButton = new JButton();
\r
615 protected JButton applyButton = new JButton();
\r
617 protected JButton cancelButton = new JButton();
\r
619 protected JScrollBar rScroller = new JScrollBar();
\r
621 JLabel label1 = new JLabel();
\r
623 protected JTextField rText = new JTextField();
\r
625 JLabel label4 = new JLabel();
\r
627 protected JScrollBar gScroller = new JScrollBar();
\r
629 protected JTextField gText = new JTextField();
\r
631 JLabel label5 = new JLabel();
\r
633 protected JScrollBar bScroller = new JScrollBar();
\r
635 protected JTextField bText = new JTextField();
\r
637 protected JPanel target = new JPanel();
\r
639 private void jbInit() throws Exception
\r
641 this.setLayout(null);
\r
642 buttonPanel.setLayout(gridLayout);
\r
643 gridLayout.setColumns(6);
\r
644 gridLayout.setRows(4);
\r
645 okButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
646 okButton.setLabel(MessageManager.getString("action.ok"));
\r
647 okButton.addActionListener(this);
\r
648 applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
649 applyButton.setLabel(MessageManager.getString("action.apply"));
\r
650 applyButton.addActionListener(this);
\r
651 cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
\r
652 cancelButton.setLabel(MessageManager.getString("action.cancel"));
\r
653 cancelButton.addActionListener(this);
\r
654 this.setBackground(new Color(212, 208, 223));
\r
655 okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
\r
656 buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
\r
657 rScroller.setMaximum(256);
\r
658 rScroller.setMinimum(0);
\r
659 rScroller.setOrientation(0);
\r
660 rScroller.setUnitIncrement(1);
\r
661 rScroller.setVisibleAmount(1);
\r
662 rScroller.setBounds(new Rectangle(36, 27, 119, 19));
\r
663 rScroller.addAdjustmentListener(this);
\r
664 label1.setAlignmentX(JLabel.RIGHT);
\r
665 label1.setText("R");
\r
666 label1.setBounds(new Rectangle(19, 30, 16, 15));
\r
667 rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
668 rText.setText("0 ");
\r
669 rText.setBounds(new Rectangle(156, 27, 53, 19));
\r
670 rText.addActionListener(this);
\r
671 rText.addFocusListener(this);
\r
672 label4.setAlignmentX(JLabel.RIGHT);
\r
673 label4.setText("G");
\r
674 label4.setBounds(new Rectangle(15, 56, 20, 15));
\r
675 gScroller.setMaximum(256);
\r
676 gScroller.setMinimum(0);
\r
677 gScroller.setOrientation(0);
\r
678 gScroller.setUnitIncrement(1);
\r
679 gScroller.setVisibleAmount(1);
\r
680 gScroller.setBounds(new Rectangle(35, 52, 120, 20));
\r
681 gScroller.addAdjustmentListener(this);
\r
682 gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
683 gText.setText("0 ");
\r
684 gText.setBounds(new Rectangle(156, 52, 53, 20));
\r
685 gText.addActionListener(this);
\r
686 gText.addFocusListener(this);
\r
687 label5.setAlignmentX(JLabel.RIGHT);
\r
688 label5.setText("B");
\r
689 label5.setBounds(new Rectangle(14, 82, 20, 15));
\r
690 bScroller.setMaximum(256);
\r
691 bScroller.setMinimum(0);
\r
692 bScroller.setOrientation(0);
\r
693 bScroller.setUnitIncrement(1);
\r
694 bScroller.setVisibleAmount(1);
\r
695 bScroller.setBounds(new Rectangle(35, 78, 120, 20));
\r
696 bScroller.addAdjustmentListener(this);
\r
697 bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
\r
698 bText.setText("0 ");
\r
699 bText.setBounds(new Rectangle(157, 78, 52, 20));
\r
700 bText.addActionListener(this);
\r
701 bText.addFocusListener(this);
\r
702 target.setBackground(Color.black);
\r
703 target.setBounds(new Rectangle(229, 26, 134, 79));
\r
704 this.add(okcancelPanel, null);
\r
705 okcancelPanel.add(okButton, null);
\r
706 okcancelPanel.add(applyButton, null);
\r
707 okcancelPanel.add(cancelButton, null);
\r
711 this.add(buttonPanel, null);
\r
712 this.add(target, null);
\r
713 this.add(gScroller);
\r
714 this.add(rScroller);
\r
715 this.add(bScroller);
\r
722 public void focusGained(FocusEvent e)
\r
728 * This method applies any change to an RGB value if the user tabs out of the
\r
729 * field instead of pressing Enter
\r
732 public void focusLost(FocusEvent e)
\r
734 Component c = e.getComponent();
\r
737 rText_actionPerformed();
\r
743 gText_actionPerformed();
\r
749 bText_actionPerformed();
\r