-/*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
- *
- * This file is part of Jalview.
- *
- * Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3
- * of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
-package jalview.appletgui;
-
-import jalview.bin.JalviewLite;
-import jalview.datamodel.SequenceGroup;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.GraduatedColor;
-import jalview.schemes.ResidueProperties;
-import jalview.schemes.UserColourScheme;
-import jalview.util.MessageManager;
-
-import javax.swing.JButton;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Container;
-import javax.swing.JDialog;
-import java.awt.Font;
-import javax.swing.JFrame;
-import java.awt.GridLayout;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import java.awt.Rectangle;
-import javax.swing.JScrollBar;
-import javax.swing.JTextField;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.AdjustmentEvent;
-import java.awt.event.AdjustmentListener;
-import java.awt.event.FocusEvent;
-import java.awt.event.FocusListener;
-import java.awt.event.MouseEvent;
-import java.util.Vector;
-
-public class UserDefinedColours extends JPanel implements ActionListener,
- AdjustmentListener, FocusListener
-{
-
- AlignmentPanel ap;
-
- SequenceGroup seqGroup;
-
- JButton selectedButton;
-
- Vector oldColours = new Vector();
-
- ColourSchemeI oldColourScheme;
-
- JFrame frame;
-
- MCview.AppletPDBCanvas pdbcanvas;
-
- AppletJmol jmol;
-
- JDialog dialog;
-
- Object caller;
-
- String originalLabel;
-
- Object originalColour;
-
- int R = 0, G = 0, B = 0;
-
- public ColourSchemeI loadDefaultColours()
- {
- // NOT IMPLEMENTED YET IN APPLET VERSION
- return null;
- }
-
- public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
- {
- this.ap = ap;
- seqGroup = sg;
-
- if (seqGroup != null)
- {
- oldColourScheme = seqGroup.cs;
- }
- else
- {
- oldColourScheme = ap.av.getGlobalColourScheme();
- }
-
- init();
- }
-
- public UserDefinedColours(MCview.AppletPDBCanvas pdb)
- {
- this.pdbcanvas = pdb;
- init();
- }
-
- public UserDefinedColours(AppletJmol jmol)
- {
- this.jmol = jmol;
- init();
- }
-
- public UserDefinedColours(FeatureRenderer fr, JFrame alignframe)
- {
- caller = fr;
- originalColour = fr.colourPanel.getBackground();
- originalLabel = "Feature Colour";
- setForDialog("Select Feature Colour", alignframe);
- setTargetColour(fr.colourPanel.getBackground());
- dialog.setVisible(true);
- }
-
- public UserDefinedColours(Component caller, Color col1, JFrame alignframe)
- {
- this(caller, col1, alignframe, "Select Colour");
- }
-
- /**
- * Makes a dialog to choose the colour
- *
- * @param caller
- * - handles events
- * @param col1
- * - original colour
- * @param alignframe
- * - the parent Frame for the dialog
- * @param title
- * - window title
- */
- public UserDefinedColours(Component caller, Color col1, JFrame alignframe,
- String title)
- {
- this.caller = caller;
- originalColour = col1;
- originalLabel = title;
- setForDialog(title, alignframe);
- setTargetColour(col1);
- dialog.setVisible(true);
- }
-
- /**
- * feature colour chooser
- *
- * @param caller
- * @param label
- * @param colour
- */
- public UserDefinedColours(Object caller, String label, Color colour)
- {
- this(caller, label, colour, colour);
- }
-
- /**
- * feature colour chooser when changing style to single color
- *
- * @param me
- * @param type
- * @param graduatedColor
- */
- public UserDefinedColours(FeatureSettings me, String type,
- GraduatedColor graduatedColor)
- {
- this(me, type, graduatedColor, graduatedColor.getMaxColor());
- }
-
- private UserDefinedColours(Object caller, String label, Object ocolour,
- Color colour)
- {
- this.caller = caller;
- originalColour = ocolour;
- originalLabel = label;
- init();
- remove(buttonPanel);
-
- setTargetColour(colour);
-
- okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
- frame.setTitle(MessageManager.getString("label.user_defined_colours") + " - " + label);
- frame.setSize(420, 200);
- }
-
- void setForDialog(String title, Container alignframe)
- {
- init();
- frame.setVisible(false);
- remove(buttonPanel);
- if (alignframe instanceof JFrame)
- {
- dialog = new JDialog((JFrame) alignframe, title, true);
- }
- else
- {
- // if (alignframe instanceof JVDialog){
- // // not 1.1 compatible!
- // dialog = new Dialog(((JVDialog)alignframe), title, true);
- // } else {
- throw new Error(MessageManager.getString("label.error_unsupported_owwner_user_colour_scheme"));
- }
-
- dialog.add(this);
- this.setSize(400, 123);
- okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));
- int height = 160 + alignframe.getInsets().top + getInsets().bottom;
- int width = 400;
-
- dialog.setBounds(alignframe.getBounds().x
- + (alignframe.getSize().width - width) / 2,
- alignframe.getBounds().y
- + (alignframe.getSize().height - height) / 2, width,
- height);
-
- }
-
- public void actionPerformed(ActionEvent evt)
- {
- final Object source = evt.getSource();
- if (source == okButton)
- {
- okButton_actionPerformed();
- }
- else if (source == applyButton)
- {
- applyButton_actionPerformed();
- }
- else if (source == cancelButton)
- {
- cancelButton_actionPerformed();
- }
- else if (source == rText)
- {
- rText_actionPerformed();
- }
- else if (source == gText)
- {
- gText_actionPerformed();
- }
- else if (source == bText)
- {
- bText_actionPerformed();
- }
- }
-
- public void adjustmentValueChanged(AdjustmentEvent evt)
- {
- if (evt.getSource() == rScroller)
- {
- rScroller_adjustmentValueChanged();
- }
- else if (evt.getSource() == gScroller)
- {
- gScroller_adjustmentValueChanged();
- }
- else if (evt.getSource() == bScroller)
- {
- bScroller_adjustmentValueChanged();
- }
- }
-
- void init()
- {
- try
- {
- jbInit();
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- frame = new JFrame();
- frame.add(this);
- JalviewLite.addFrame(frame,
- MessageManager.getString("label.user_defined_colours"), 420,
- 345);
-
- if (seqGroup != null)
- {
- frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
- }
-
- for (int i = 0; i < 20; i++)
- {
- makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
- + "", ResidueProperties.aa[i]);
- }
-
- makeButton("B", "B");
- makeButton("Z", "Z");
- makeButton("X", "X");
- makeButton("Gap", "'.','-',' '");
-
- validate();
- }
-
- protected void rText_actionPerformed()
- {
- try
- {
- int i = Integer.parseInt(rText.getText());
- rScroller.setValue(i);
- rScroller_adjustmentValueChanged();
- } catch (NumberFormatException ex)
- {
- }
- }
-
- protected void gText_actionPerformed()
- {
- try
- {
- int i = Integer.parseInt(gText.getText());
- gScroller.setValue(i);
- gScroller_adjustmentValueChanged();
- } catch (NumberFormatException ex)
- {
- }
-
- }
-
- protected void bText_actionPerformed()
- {
- try
- {
- int i = Integer.parseInt(bText.getText());
- bScroller.setValue(i);
- bScroller_adjustmentValueChanged();
- } catch (NumberFormatException ex)
- {
- }
-
- }
-
- protected void rScroller_adjustmentValueChanged()
- {
- R = rScroller.getValue();
- rText.setText(R + "");
- colourChanged();
- }
-
- protected void gScroller_adjustmentValueChanged()
- {
- G = gScroller.getValue();
- gText.setText(G + "");
- colourChanged();
- }
-
- protected void bScroller_adjustmentValueChanged()
- {
- B = bScroller.getValue();
- bText.setText(B + "");
- colourChanged();
- }
-
- public void colourChanged()
- {
- Color col = new Color(R, G, B);
- target.setBackground(col);
- target.repaint();
-
- if (selectedButton != null)
- {
- selectedButton.setBackground(col);
- selectedButton.repaint();
- }
- }
-
- void setTargetColour(Color col)
- {
- R = col.getRed();
- G = col.getGreen();
- B = col.getBlue();
-
- rScroller.setValue(R);
- gScroller.setValue(G);
- bScroller.setValue(B);
- rText.setText(R + "");
- gText.setText(G + "");
- bText.setText(B + "");
- colourChanged();
- }
-
- public void colourButtonPressed(MouseEvent e)
- {
- selectedButton = (JButton) e.getSource();
- setTargetColour(selectedButton.getBackground());
- }
-
- void makeButton(String label, String aa)
- {
- final JButton button = new JButton();
- Color col = Color.white;
- if (oldColourScheme != null)
- {
- try
- {
- col = oldColourScheme.findColour(aa.charAt(0), -1, null);
- } catch (Exception ex)
- {
- }
- }
- button.setBackground(col);
- oldColours.addElement(col);
- button.setLabel(label);
- button.setForeground(col.darker().darker().darker());
- button.setFont(new java.awt.Font("Verdana", 1, 10));
- button.addMouseListener(new java.awt.event.MouseAdapter()
- {
- public void mousePressed(MouseEvent e)
- {
- colourButtonPressed(e);
- }
- });
-
- buttonPanel.add(button, null);
- }
-
- protected void okButton_actionPerformed()
- {
- applyButton_actionPerformed();
- if (dialog != null)
- {
- dialog.setVisible(false);
- }
-
- frame.setVisible(false);
- }
-
- public Color getColor()
- {
- return new Color(R, G, B);
- }
-
- protected void applyButton_actionPerformed()
- {
- if (caller != null)
- {
- if (caller instanceof FeatureSettings)
- {
- ((FeatureSettings) caller).setUserColour(originalLabel, getColor());
- }
- else if (caller instanceof AnnotationColourChooser)
- {
- if (originalLabel.equals("Min Colour"))
- {
- ((AnnotationColourChooser) caller)
- .minColour_actionPerformed(getColor());
- }
- else
- {
- ((AnnotationColourChooser) caller)
- .maxColour_actionPerformed(getColor());
- }
- }
- else if (caller instanceof FeatureRenderer)
- {
- ((FeatureRenderer) caller).colourPanel.updateColor(getColor());
- }
- else if (caller instanceof FeatureColourChooser)
- {
- if (originalLabel.indexOf("inimum") > -1)
- {
- ((FeatureColourChooser) caller)
- .minColour_actionPerformed(getColor());
- }
- else
- {
- ((FeatureColourChooser) caller)
- .maxColour_actionPerformed(getColor());
- }
- }
-
- return;
- }
-
- Color[] newColours = new Color[24];
- for (int i = 0; i < 24; i++)
- {
- JButton button = (JButton) buttonPanel.getComponent(i);
- newColours[i] = button.getBackground();
- }
-
- UserColourScheme ucs = new UserColourScheme(newColours);
- if (ap != null)
- {
- ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
- }
-
- if (ap != null)
- {
- if (seqGroup != null)
- {
- seqGroup.cs = ucs;
- }
- else
- {
- ap.av.setGlobalColourScheme(ucs);
- }
- ap.seqPanel.seqCanvas.img = null;
- ap.paintAlignment(true);
- }
- else if (jmol != null)
- {
- jmol.setJalviewColourScheme(ucs);
- }
- else if (pdbcanvas != null)
- {
- pdbcanvas.setColours(ucs);
- }
- }
-
- protected void cancelButton_actionPerformed()
- {
- if (caller != null)
- {
- if (caller instanceof FeatureSettings)
- {
- ((FeatureSettings) caller).setUserColour(originalLabel,
- originalColour);
- }
- else if (caller instanceof AnnotationColourChooser)
- {
- if (originalLabel.equals("Min Colour"))
- {
- ((AnnotationColourChooser) caller)
- .minColour_actionPerformed((Color) originalColour);
- }
- else
- {
- ((AnnotationColourChooser) caller)
- .maxColour_actionPerformed((Color) originalColour);
- }
- }
- else if (caller instanceof FeatureRenderer)
- {
- ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);
-
- }
-
- else if (caller instanceof FeatureColourChooser)
- {
- if (originalLabel.indexOf("inimum") > -1)
- {
- ((FeatureColourChooser) caller)
- .minColour_actionPerformed((Color) originalColour);
- }
- else
- {
- ((FeatureColourChooser) caller)
- .maxColour_actionPerformed((Color) originalColour);
- }
- }
- if (dialog != null)
- {
- dialog.setVisible(false);
- }
-
- frame.setVisible(false);
- return;
- }
-
- Color[] newColours = new Color[24];
- for (int i = 0; i < 24; i++)
- {
- newColours[i] = (Color) oldColours.elementAt(i);
- buttonPanel.getComponent(i).setBackground(newColours[i]);
- }
-
- UserColourScheme ucs = new UserColourScheme(newColours);
-
- if (ap != null)
- {
- if (seqGroup != null)
- {
- seqGroup.cs = ucs;
- }
- else
- {
- ap.av.setGlobalColourScheme(ucs);
- }
- ap.paintAlignment(true);
- }
- else if (jmol != null)
- {
- jmol.setJalviewColourScheme(ucs);
- }
- else if (pdbcanvas != null)
- {
- pdbcanvas.pdb.setColours(ucs);
- }
-
- frame.setVisible(false);
- }
-
- protected JPanel buttonPanel = new JPanel();
-
- protected GridLayout gridLayout = new GridLayout();
-
- JPanel okcancelPanel = new JPanel();
-
- protected JButton okButton = new JButton();
-
- protected JButton applyButton = new JButton();
-
- protected JButton cancelButton = new JButton();
-
- protected JScrollBar rScroller = new JScrollBar();
-
- JLabel label1 = new JLabel();
-
- protected JTextField rText = new JTextField();
-
- JLabel label4 = new JLabel();
-
- protected JScrollBar gScroller = new JScrollBar();
-
- protected JTextField gText = new JTextField();
-
- JLabel label5 = new JLabel();
-
- protected JScrollBar bScroller = new JScrollBar();
-
- protected JTextField bText = new JTextField();
-
- protected JPanel target = new JPanel();
-
- private void jbInit() throws Exception
- {
- this.setLayout(null);
- buttonPanel.setLayout(gridLayout);
- gridLayout.setColumns(6);
- gridLayout.setRows(4);
- okButton.setFont(new java.awt.Font("Verdana", 0, 11));
- okButton.setLabel(MessageManager.getString("action.ok"));
- okButton.addActionListener(this);
- applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
- applyButton.setLabel(MessageManager.getString("action.apply"));
- applyButton.addActionListener(this);
- cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));
- cancelButton.setLabel(MessageManager.getString("action.cancel"));
- cancelButton.addActionListener(this);
- this.setBackground(new Color(212, 208, 223));
- okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));
- buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));
- rScroller.setMaximum(256);
- rScroller.setMinimum(0);
- rScroller.setOrientation(0);
- rScroller.setUnitIncrement(1);
- rScroller.setVisibleAmount(1);
- rScroller.setBounds(new Rectangle(36, 27, 119, 19));
- rScroller.addAdjustmentListener(this);
- label1.setAlignmentX(JLabel.RIGHT);
- label1.setText("R");
- label1.setBounds(new Rectangle(19, 30, 16, 15));
- rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
- rText.setText("0 ");
- rText.setBounds(new Rectangle(156, 27, 53, 19));
- rText.addActionListener(this);
- rText.addFocusListener(this);
- label4.setAlignmentX(JLabel.RIGHT);
- label4.setText("G");
- label4.setBounds(new Rectangle(15, 56, 20, 15));
- gScroller.setMaximum(256);
- gScroller.setMinimum(0);
- gScroller.setOrientation(0);
- gScroller.setUnitIncrement(1);
- gScroller.setVisibleAmount(1);
- gScroller.setBounds(new Rectangle(35, 52, 120, 20));
- gScroller.addAdjustmentListener(this);
- gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
- gText.setText("0 ");
- gText.setBounds(new Rectangle(156, 52, 53, 20));
- gText.addActionListener(this);
- gText.addFocusListener(this);
- label5.setAlignmentX(JLabel.RIGHT);
- label5.setText("B");
- label5.setBounds(new Rectangle(14, 82, 20, 15));
- bScroller.setMaximum(256);
- bScroller.setMinimum(0);
- bScroller.setOrientation(0);
- bScroller.setUnitIncrement(1);
- bScroller.setVisibleAmount(1);
- bScroller.setBounds(new Rectangle(35, 78, 120, 20));
- bScroller.addAdjustmentListener(this);
- bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));
- bText.setText("0 ");
- bText.setBounds(new Rectangle(157, 78, 52, 20));
- bText.addActionListener(this);
- bText.addFocusListener(this);
- target.setBackground(Color.black);
- target.setBounds(new Rectangle(229, 26, 134, 79));
- this.add(okcancelPanel, null);
- okcancelPanel.add(okButton, null);
- okcancelPanel.add(applyButton, null);
- okcancelPanel.add(cancelButton, null);
- this.add(rText);
- this.add(gText);
- this.add(bText);
- this.add(buttonPanel, null);
- this.add(target, null);
- this.add(gScroller);
- this.add(rScroller);
- this.add(bScroller);
- this.add(label5);
- this.add(label4);
- this.add(label1);
- }
-
- @Override
- public void focusGained(FocusEvent e)
- {
- // noop
- }
-
- /**
- * This method applies any change to an RGB value if the user tabs out of the
- * field instead of pressing Enter
- */
- @Override
- public void focusLost(FocusEvent e)
- {
- Component c = e.getComponent();
- if (c == rText)
- {
- rText_actionPerformed();
- }
- else
- {
- if (c == gText)
- {
- gText_actionPerformed();
- }
- else
- {
- if (c == bText)
- {
- bText_actionPerformed();
- }
- }
- }
- }
-
-}
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)\r
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors\r
+ * \r
+ * This file is part of Jalview.\r
+ * \r
+ * Jalview is free software: you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License \r
+ * as published by the Free Software Foundation, either version 3\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * Jalview is distributed in the hope that it will be useful, but \r
+ * WITHOUT ANY WARRANTY; without even the implied warranty \r
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
+ * PURPOSE. See the GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.\r
+ * The Jalview Authors are detailed in the 'AUTHORS' file.\r
+ */\r
+package jalview.appletgui;\r
+\r
+import jalview.bin.JalviewLite;\r
+import jalview.datamodel.SequenceGroup;\r
+import jalview.schemes.ColourSchemeI;\r
+import jalview.schemes.GraduatedColor;\r
+import jalview.schemes.ResidueProperties;\r
+import jalview.schemes.UserColourScheme;\r
+import jalview.util.MessageManager;\r
+\r
+import javax.swing.JButton;\r
+import java.awt.Color;\r
+import java.awt.Component;\r
+import java.awt.Container;\r
+import javax.swing.JDialog;\r
+import java.awt.Font;\r
+import javax.swing.JFrame;\r
+import java.awt.GridLayout;\r
+import javax.swing.JLabel;\r
+import javax.swing.JPanel;\r
+import java.awt.Rectangle;\r
+import javax.swing.JScrollBar;\r
+import javax.swing.JTextField;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.AdjustmentEvent;\r
+import java.awt.event.AdjustmentListener;\r
+import java.awt.event.FocusEvent;\r
+import java.awt.event.FocusListener;\r
+import java.awt.event.MouseEvent;\r
+import java.util.Vector;\r
+\r
+public class UserDefinedColours extends JPanel implements ActionListener,\r
+ AdjustmentListener, FocusListener\r
+{\r
+\r
+ AlignmentPanel ap;\r
+\r
+ SequenceGroup seqGroup;\r
+\r
+ JButton selectedButton;\r
+\r
+ Vector oldColours = new Vector();\r
+\r
+ ColourSchemeI oldColourScheme;\r
+\r
+ JFrame frame;\r
+\r
+ MCview.AppletPDBCanvas pdbcanvas;\r
+\r
+ AppletJmol jmol;\r
+\r
+ JDialog dialog;\r
+\r
+ Object caller;\r
+\r
+ String originalLabel;\r
+\r
+ Object originalColour;\r
+\r
+ int R = 0, G = 0, B = 0;\r
+\r
+ public ColourSchemeI loadDefaultColours()\r
+ {\r
+ // NOT IMPLEMENTED YET IN APPLET VERSION\r
+ return null;\r
+ }\r
+\r
+ public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)\r
+ {\r
+ this.ap = ap;\r
+ seqGroup = sg;\r
+\r
+ if (seqGroup != null)\r
+ {\r
+ oldColourScheme = seqGroup.cs;\r
+ }\r
+ else\r
+ {\r
+ oldColourScheme = ap.av.getGlobalColourScheme();\r
+ }\r
+\r
+ init();\r
+ }\r
+\r
+ public UserDefinedColours(MCview.AppletPDBCanvas pdb)\r
+ {\r
+ this.pdbcanvas = pdb;\r
+ init();\r
+ }\r
+\r
+ public UserDefinedColours(AppletJmol jmol)\r
+ {\r
+ this.jmol = jmol;\r
+ init();\r
+ }\r
+\r
+ public UserDefinedColours(FeatureRenderer fr, JFrame alignframe)\r
+ {\r
+ caller = fr;\r
+ originalColour = fr.colourPanel.getBackground();\r
+ originalLabel = "Feature Colour";\r
+ setForDialog("Select Feature Colour", alignframe);\r
+ setTargetColour(fr.colourPanel.getBackground());\r
+ dialog.setVisible(true);\r
+ }\r
+\r
+ public UserDefinedColours(Component caller, Color col1, JFrame alignframe)\r
+ {\r
+ this(caller, col1, alignframe, "Select Colour");\r
+ }\r
+\r
+ /**\r
+ * Makes a dialog to choose the colour\r
+ * \r
+ * @param caller\r
+ * - handles events\r
+ * @param col1\r
+ * - original colour\r
+ * @param alignframe\r
+ * - the parent Frame for the dialog\r
+ * @param title\r
+ * - window title\r
+ */\r
+ public UserDefinedColours(Component caller, Color col1, JFrame alignframe,\r
+ String title)\r
+ {\r
+ this.caller = caller;\r
+ originalColour = col1;\r
+ originalLabel = title;\r
+ setForDialog(title, alignframe);\r
+ setTargetColour(col1);\r
+ dialog.setVisible(true);\r
+ }\r
+\r
+ /**\r
+ * feature colour chooser\r
+ * \r
+ * @param caller\r
+ * @param label\r
+ * @param colour\r
+ */\r
+ public UserDefinedColours(Object caller, String label, Color colour)\r
+ {\r
+ this(caller, label, colour, colour);\r
+ }\r
+\r
+ /**\r
+ * feature colour chooser when changing style to single color\r
+ * \r
+ * @param me\r
+ * @param type\r
+ * @param graduatedColor\r
+ */\r
+ public UserDefinedColours(FeatureSettings me, String type,\r
+ GraduatedColor graduatedColor)\r
+ {\r
+ this(me, type, graduatedColor, graduatedColor.getMaxColor());\r
+ }\r
+\r
+ private UserDefinedColours(Object caller, String label, Object ocolour,\r
+ Color colour)\r
+ {\r
+ this.caller = caller;\r
+ originalColour = ocolour;\r
+ originalLabel = label;\r
+ init();\r
+ remove(buttonPanel);\r
+\r
+ setTargetColour(colour);\r
+\r
+ okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));\r
+ frame.setTitle(MessageManager.getString("label.user_defined_colours") + " - " + label);\r
+ frame.setSize(420, 200);\r
+ }\r
+\r
+ void setForDialog(String title, Container alignframe)\r
+ {\r
+ init();\r
+ frame.setVisible(false);\r
+ remove(buttonPanel);\r
+ if (alignframe instanceof JFrame)\r
+ {\r
+ dialog = new JDialog((JFrame) alignframe, title, true);\r
+ }\r
+ else\r
+ {\r
+ // if (alignframe instanceof JVDialog){\r
+ // // not 1.1 compatible!\r
+ // dialog = new Dialog(((JVDialog)alignframe), title, true);\r
+ // } else {\r
+ throw new Error(MessageManager.getString("label.error_unsupported_owwner_user_colour_scheme"));\r
+ }\r
+\r
+ dialog.add(this);\r
+ this.setSize(400, 123);\r
+ okcancelPanel.setBounds(new Rectangle(0, 123, 400, 35));\r
+ int height = 160 + alignframe.getInsets().top + getInsets().bottom;\r
+ int width = 400;\r
+\r
+ dialog.setBounds(alignframe.getBounds().x\r
+ + (alignframe.getSize().width - width) / 2,\r
+ alignframe.getBounds().y\r
+ + (alignframe.getSize().height - height) / 2, width,\r
+ height);\r
+\r
+ }\r
+\r
+ public void actionPerformed(ActionEvent evt)\r
+ {\r
+ final Object source = evt.getSource();\r
+ if (source == okButton)\r
+ {\r
+ okButton_actionPerformed();\r
+ }\r
+ else if (source == applyButton)\r
+ {\r
+ applyButton_actionPerformed();\r
+ }\r
+ else if (source == cancelButton)\r
+ {\r
+ cancelButton_actionPerformed();\r
+ }\r
+ else if (source == rText)\r
+ {\r
+ rText_actionPerformed();\r
+ }\r
+ else if (source == gText)\r
+ {\r
+ gText_actionPerformed();\r
+ }\r
+ else if (source == bText)\r
+ {\r
+ bText_actionPerformed();\r
+ }\r
+ }\r
+\r
+ public void adjustmentValueChanged(AdjustmentEvent evt)\r
+ {\r
+ if (evt.getSource() == rScroller)\r
+ {\r
+ rScroller_adjustmentValueChanged();\r
+ }\r
+ else if (evt.getSource() == gScroller)\r
+ {\r
+ gScroller_adjustmentValueChanged();\r
+ }\r
+ else if (evt.getSource() == bScroller)\r
+ {\r
+ bScroller_adjustmentValueChanged();\r
+ }\r
+ }\r
+\r
+ void init()\r
+ {\r
+ try\r
+ {\r
+ jbInit();\r
+ } catch (Exception e)\r
+ {\r
+ e.printStackTrace();\r
+ }\r
+ frame = new JFrame();\r
+ frame.add(this);\r
+ JalviewLite.addFrame(frame,\r
+ MessageManager.getString("label.user_defined_colours"), 420,\r
+ 345);\r
+\r
+ if (seqGroup != null)\r
+ {\r
+ frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");\r
+ }\r
+\r
+ for (int i = 0; i < 20; i++)\r
+ {\r
+ makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])\r
+ + "", ResidueProperties.aa[i]);\r
+ }\r
+\r
+ makeButton("B", "B");\r
+ makeButton("Z", "Z");\r
+ makeButton("X", "X");\r
+ makeButton("Gap", "'.','-',' '");\r
+\r
+ validate();\r
+ }\r
+\r
+ protected void rText_actionPerformed()\r
+ {\r
+ try\r
+ {\r
+ int i = Integer.parseInt(rText.getText());\r
+ rScroller.setValue(i);\r
+ rScroller_adjustmentValueChanged();\r
+ } catch (NumberFormatException ex)\r
+ {\r
+ }\r
+ }\r
+\r
+ protected void gText_actionPerformed()\r
+ {\r
+ try\r
+ {\r
+ int i = Integer.parseInt(gText.getText());\r
+ gScroller.setValue(i);\r
+ gScroller_adjustmentValueChanged();\r
+ } catch (NumberFormatException ex)\r
+ {\r
+ }\r
+\r
+ }\r
+\r
+ protected void bText_actionPerformed()\r
+ {\r
+ try\r
+ {\r
+ int i = Integer.parseInt(bText.getText());\r
+ bScroller.setValue(i);\r
+ bScroller_adjustmentValueChanged();\r
+ } catch (NumberFormatException ex)\r
+ {\r
+ }\r
+\r
+ }\r
+\r
+ protected void rScroller_adjustmentValueChanged()\r
+ {\r
+ R = rScroller.getValue();\r
+ rText.setText(R + "");\r
+ colourChanged();\r
+ }\r
+\r
+ protected void gScroller_adjustmentValueChanged()\r
+ {\r
+ G = gScroller.getValue();\r
+ gText.setText(G + "");\r
+ colourChanged();\r
+ }\r
+\r
+ protected void bScroller_adjustmentValueChanged()\r
+ {\r
+ B = bScroller.getValue();\r
+ bText.setText(B + "");\r
+ colourChanged();\r
+ }\r
+\r
+ public void colourChanged()\r
+ {\r
+ Color col = new Color(R, G, B);\r
+ target.setBackground(col);\r
+ target.repaint();\r
+\r
+ if (selectedButton != null)\r
+ {\r
+ selectedButton.setBackground(col);\r
+ selectedButton.repaint();\r
+ }\r
+ }\r
+\r
+ void setTargetColour(Color col)\r
+ {\r
+ R = col.getRed();\r
+ G = col.getGreen();\r
+ B = col.getBlue();\r
+\r
+ rScroller.setValue(R);\r
+ gScroller.setValue(G);\r
+ bScroller.setValue(B);\r
+ rText.setText(R + "");\r
+ gText.setText(G + "");\r
+ bText.setText(B + "");\r
+ colourChanged();\r
+ }\r
+\r
+ public void colourButtonPressed(MouseEvent e)\r
+ {\r
+ selectedButton = (JButton) e.getSource();\r
+ setTargetColour(selectedButton.getBackground());\r
+ }\r
+\r
+ void makeButton(String label, String aa)\r
+ {\r
+ final JButton button = new JButton();\r
+ Color col = Color.white;\r
+ if (oldColourScheme != null)\r
+ {\r
+ try\r
+ {\r
+ col = oldColourScheme.findColour(aa.charAt(0), -1, null);\r
+ } catch (Exception ex)\r
+ {\r
+ }\r
+ }\r
+ button.setBackground(col);\r
+ oldColours.addElement(col);\r
+ button.setLabel(label);\r
+ button.setForeground(col.darker().darker().darker());\r
+ button.setFont(new java.awt.Font("Verdana", 1, 10));\r
+ button.addMouseListener(new java.awt.event.MouseAdapter()\r
+ {\r
+ public void mousePressed(MouseEvent e)\r
+ {\r
+ colourButtonPressed(e);\r
+ }\r
+ });\r
+\r
+ buttonPanel.add(button, null);\r
+ }\r
+\r
+ protected void okButton_actionPerformed()\r
+ {\r
+ applyButton_actionPerformed();\r
+ if (dialog != null)\r
+ {\r
+ dialog.setVisible(false);\r
+ }\r
+\r
+ frame.setVisible(false);\r
+ }\r
+\r
+ public Color getColor()\r
+ {\r
+ return new Color(R, G, B);\r
+ }\r
+\r
+ protected void applyButton_actionPerformed()\r
+ {\r
+ if (caller != null)\r
+ {\r
+ if (caller instanceof FeatureSettings)\r
+ {\r
+ ((FeatureSettings) caller).setUserColour(originalLabel, getColor());\r
+ }\r
+ else if (caller instanceof AnnotationColourChooser)\r
+ {\r
+ if (originalLabel.equals("Min Colour"))\r
+ {\r
+ ((AnnotationColourChooser) caller)\r
+ .minColour_actionPerformed(getColor());\r
+ }\r
+ else\r
+ {\r
+ ((AnnotationColourChooser) caller)\r
+ .maxColour_actionPerformed(getColor());\r
+ }\r
+ }\r
+ else if (caller instanceof FeatureRenderer)\r
+ {\r
+ ((FeatureRenderer) caller).colourPanel.updateColor(getColor());\r
+ }\r
+ else if (caller instanceof FeatureColourChooser)\r
+ {\r
+ if (originalLabel.indexOf("inimum") > -1)\r
+ {\r
+ ((FeatureColourChooser) caller)\r
+ .minColour_actionPerformed(getColor());\r
+ }\r
+ else\r
+ {\r
+ ((FeatureColourChooser) caller)\r
+ .maxColour_actionPerformed(getColor());\r
+ }\r
+ }\r
+\r
+ return;\r
+ }\r
+\r
+ Color[] newColours = new Color[24];\r
+ for (int i = 0; i < 24; i++)\r
+ {\r
+ JButton button = (JButton) buttonPanel.getComponent(i);\r
+ newColours[i] = button.getBackground();\r
+ }\r
+\r
+ UserColourScheme ucs = new UserColourScheme(newColours);\r
+ if (ap != null)\r
+ {\r
+ ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());\r
+ }\r
+\r
+ if (ap != null)\r
+ {\r
+ if (seqGroup != null)\r
+ {\r
+ seqGroup.cs = ucs;\r
+ }\r
+ else\r
+ {\r
+ ap.av.setGlobalColourScheme(ucs);\r
+ }\r
+ ap.seqPanel.seqCanvas.img = null;\r
+ ap.paintAlignment(true);\r
+ }\r
+ else if (jmol != null)\r
+ {\r
+ jmol.setJalviewColourScheme(ucs);\r
+ }\r
+ else if (pdbcanvas != null)\r
+ {\r
+ pdbcanvas.setColours(ucs);\r
+ }\r
+ }\r
+\r
+ protected void cancelButton_actionPerformed()\r
+ {\r
+ if (caller != null)\r
+ {\r
+ if (caller instanceof FeatureSettings)\r
+ {\r
+ ((FeatureSettings) caller).setUserColour(originalLabel,\r
+ originalColour);\r
+ }\r
+ else if (caller instanceof AnnotationColourChooser)\r
+ {\r
+ if (originalLabel.equals("Min Colour"))\r
+ {\r
+ ((AnnotationColourChooser) caller)\r
+ .minColour_actionPerformed((Color) originalColour);\r
+ }\r
+ else\r
+ {\r
+ ((AnnotationColourChooser) caller)\r
+ .maxColour_actionPerformed((Color) originalColour);\r
+ }\r
+ }\r
+ else if (caller instanceof FeatureRenderer)\r
+ {\r
+ ((FeatureRenderer) caller).colourPanel.updateColor(originalColour);\r
+\r
+ }\r
+\r
+ else if (caller instanceof FeatureColourChooser)\r
+ {\r
+ if (originalLabel.indexOf("inimum") > -1)\r
+ {\r
+ ((FeatureColourChooser) caller)\r
+ .minColour_actionPerformed((Color) originalColour);\r
+ }\r
+ else\r
+ {\r
+ ((FeatureColourChooser) caller)\r
+ .maxColour_actionPerformed((Color) originalColour);\r
+ }\r
+ }\r
+ if (dialog != null)\r
+ {\r
+ dialog.setVisible(false);\r
+ }\r
+\r
+ frame.setVisible(false);\r
+ return;\r
+ }\r
+\r
+ Color[] newColours = new Color[24];\r
+ for (int i = 0; i < 24; i++)\r
+ {\r
+ newColours[i] = (Color) oldColours.elementAt(i);\r
+ buttonPanel.getComponent(i).setBackground(newColours[i]);\r
+ }\r
+\r
+ UserColourScheme ucs = new UserColourScheme(newColours);\r
+\r
+ if (ap != null)\r
+ {\r
+ if (seqGroup != null)\r
+ {\r
+ seqGroup.cs = ucs;\r
+ }\r
+ else\r
+ {\r
+ ap.av.setGlobalColourScheme(ucs);\r
+ }\r
+ ap.paintAlignment(true);\r
+ }\r
+ else if (jmol != null)\r
+ {\r
+ jmol.setJalviewColourScheme(ucs);\r
+ }\r
+ else if (pdbcanvas != null)\r
+ {\r
+ pdbcanvas.pdb.setColours(ucs);\r
+ }\r
+\r
+ frame.setVisible(false);\r
+ }\r
+\r
+ protected JPanel buttonPanel = new JPanel();\r
+\r
+ protected GridLayout gridLayout = new GridLayout();\r
+\r
+ JPanel okcancelPanel = new JPanel();\r
+\r
+ protected JButton okButton = new JButton();\r
+\r
+ protected JButton applyButton = new JButton();\r
+\r
+ protected JButton cancelButton = new JButton();\r
+\r
+ protected JScrollBar rScroller = new JScrollBar();\r
+\r
+ JLabel label1 = new JLabel();\r
+\r
+ protected JTextField rText = new JTextField();\r
+\r
+ JLabel label4 = new JLabel();\r
+\r
+ protected JScrollBar gScroller = new JScrollBar();\r
+\r
+ protected JTextField gText = new JTextField();\r
+\r
+ JLabel label5 = new JLabel();\r
+\r
+ protected JScrollBar bScroller = new JScrollBar();\r
+\r
+ protected JTextField bText = new JTextField();\r
+\r
+ protected JPanel target = new JPanel();\r
+\r
+ private void jbInit() throws Exception\r
+ {\r
+ this.setLayout(null);\r
+ buttonPanel.setLayout(gridLayout);\r
+ gridLayout.setColumns(6);\r
+ gridLayout.setRows(4);\r
+ okButton.setFont(new java.awt.Font("Verdana", 0, 11));\r
+ okButton.setLabel(MessageManager.getString("action.ok"));\r
+ okButton.addActionListener(this);\r
+ applyButton.setFont(new java.awt.Font("Verdana", 0, 11));\r
+ applyButton.setLabel(MessageManager.getString("action.apply"));\r
+ applyButton.addActionListener(this);\r
+ cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));\r
+ cancelButton.setLabel(MessageManager.getString("action.cancel"));\r
+ cancelButton.addActionListener(this);\r
+ this.setBackground(new Color(212, 208, 223));\r
+ okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));\r
+ buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));\r
+ rScroller.setMaximum(256);\r
+ rScroller.setMinimum(0);\r
+ rScroller.setOrientation(0);\r
+ rScroller.setUnitIncrement(1);\r
+ rScroller.setVisibleAmount(1);\r
+ rScroller.setBounds(new Rectangle(36, 27, 119, 19));\r
+ rScroller.addAdjustmentListener(this);\r
+ label1.setAlignmentX(JLabel.RIGHT);\r
+ label1.setText("R");\r
+ label1.setBounds(new Rectangle(19, 30, 16, 15));\r
+ rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));\r
+ rText.setText("0 ");\r
+ rText.setBounds(new Rectangle(156, 27, 53, 19));\r
+ rText.addActionListener(this);\r
+ rText.addFocusListener(this);\r
+ label4.setAlignmentX(JLabel.RIGHT);\r
+ label4.setText("G");\r
+ label4.setBounds(new Rectangle(15, 56, 20, 15));\r
+ gScroller.setMaximum(256);\r
+ gScroller.setMinimum(0);\r
+ gScroller.setOrientation(0);\r
+ gScroller.setUnitIncrement(1);\r
+ gScroller.setVisibleAmount(1);\r
+ gScroller.setBounds(new Rectangle(35, 52, 120, 20));\r
+ gScroller.addAdjustmentListener(this);\r
+ gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));\r
+ gText.setText("0 ");\r
+ gText.setBounds(new Rectangle(156, 52, 53, 20));\r
+ gText.addActionListener(this);\r
+ gText.addFocusListener(this);\r
+ label5.setAlignmentX(JLabel.RIGHT);\r
+ label5.setText("B");\r
+ label5.setBounds(new Rectangle(14, 82, 20, 15));\r
+ bScroller.setMaximum(256);\r
+ bScroller.setMinimum(0);\r
+ bScroller.setOrientation(0);\r
+ bScroller.setUnitIncrement(1);\r
+ bScroller.setVisibleAmount(1);\r
+ bScroller.setBounds(new Rectangle(35, 78, 120, 20));\r
+ bScroller.addAdjustmentListener(this);\r
+ bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));\r
+ bText.setText("0 ");\r
+ bText.setBounds(new Rectangle(157, 78, 52, 20));\r
+ bText.addActionListener(this);\r
+ bText.addFocusListener(this);\r
+ target.setBackground(Color.black);\r
+ target.setBounds(new Rectangle(229, 26, 134, 79));\r
+ this.add(okcancelPanel, null);\r
+ okcancelPanel.add(okButton, null);\r
+ okcancelPanel.add(applyButton, null);\r
+ okcancelPanel.add(cancelButton, null);\r
+ this.add(rText);\r
+ this.add(gText);\r
+ this.add(bText);\r
+ this.add(buttonPanel, null);\r
+ this.add(target, null);\r
+ this.add(gScroller);\r
+ this.add(rScroller);\r
+ this.add(bScroller);\r
+ this.add(label5);\r
+ this.add(label4);\r
+ this.add(label1);\r
+ }\r
+\r
+ @Override\r
+ public void focusGained(FocusEvent e)\r
+ {\r
+ // noop\r
+ }\r
+\r
+ /**\r
+ * This method applies any change to an RGB value if the user tabs out of the\r
+ * field instead of pressing Enter\r
+ */\r
+ @Override\r
+ public void focusLost(FocusEvent e)\r
+ {\r
+ Component c = e.getComponent();\r
+ if (c == rText)\r
+ {\r
+ rText_actionPerformed();\r
+ }\r
+ else\r
+ {\r
+ if (c == gText)\r
+ {\r
+ gText_actionPerformed();\r
+ }\r
+ else\r
+ {\r
+ if (c == bText)\r
+ {\r
+ bText_actionPerformed();\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+}\r