*/\r
package jalview.gui;\r
\r
-import java.io.*;\r
-import java.util.*;\r
+import jalview.datamodel.*;\r
+\r
+import jalview.io.*;\r
+\r
+import jalview.jbgui.*;\r
+\r
+import jalview.schemes.*;\r
\r
import java.awt.*;\r
import java.awt.event.*;\r
+\r
+import java.io.*;\r
+\r
+import java.util.*;\r
+\r
import javax.swing.*;\r
import javax.swing.event.*;\r
\r
-import jalview.datamodel.*;\r
-import jalview.io.*;\r
-import jalview.jbgui.*;\r
-import jalview.schemes.*;\r
\r
-public class UserDefinedColours\r
- extends GUserDefinedColours implements ChangeListener\r
+/**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @author $author$\r
+ * @version $Revision$\r
+ */\r
+public class UserDefinedColours extends GUserDefinedColours\r
+ implements ChangeListener\r
{\r
- AlignmentPanel ap;\r
- SequenceGroup seqGroup;\r
- JButton selectedButton;\r
- Vector oldColours = new Vector();\r
- ColourSchemeI oldColourScheme;\r
- JInternalFrame frame;\r
-\r
- public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)\r
- {\r
- super();\r
- frame = new JInternalFrame();\r
- frame.setContentPane(this);\r
- Desktop.addInternalFrame(frame, "User Defined Colours", 450, 530, false);\r
-\r
- if (System.getProperty("os.name").startsWith("Mac"))\r
+ AlignmentPanel ap;\r
+ SequenceGroup seqGroup;\r
+ Vector selectedButtons;\r
+ Vector oldColours = new Vector();\r
+ ColourSchemeI oldColourScheme;\r
+ JInternalFrame frame;\r
+\r
+ /**\r
+ * Creates a new UserDefinedColours object.\r
+ *\r
+ * @param ap DOCUMENT ME!\r
+ * @param sg DOCUMENT ME!\r
+ */\r
+ public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)\r
{\r
- frame.setSize(450, 560);\r
- }\r
+ super();\r
+ frame = new JInternalFrame();\r
+ frame.setContentPane(this);\r
+ Desktop.addInternalFrame(frame, "User Defined Colours", 450, 530, false);\r
\r
- if (sg != null)\r
- {\r
- frame.setTitle(frame.getTitle() + " (" + sg.getName() + ")");\r
- }\r
+ if (System.getProperty("os.name").startsWith("Mac"))\r
+ {\r
+ frame.setSize(450, 560);\r
+ }\r
\r
- colorChooser.getSelectionModel().addChangeListener(this);\r
+ if (sg != null)\r
+ {\r
+ frame.setTitle(frame.getTitle() + " (" + sg.getName() + ")");\r
+ }\r
\r
- this.ap = ap;\r
- seqGroup = sg;\r
+ colorChooser.getSelectionModel().addChangeListener(this);\r
\r
- if (seqGroup != null)\r
- {\r
- oldColourScheme = seqGroup.cs;\r
- }\r
- else\r
- {\r
- oldColourScheme = ap.av.getGlobalColourScheme();\r
- }\r
+ this.ap = ap;\r
+ seqGroup = sg;\r
\r
- for (int i = 0; i < 20; i++)\r
- {\r
- makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +\r
- "", ResidueProperties.aa[i]);\r
- }\r
+ if (seqGroup != null)\r
+ {\r
+ oldColourScheme = seqGroup.cs;\r
+ }\r
+ else\r
+ {\r
+ oldColourScheme = ap.av.getGlobalColourScheme();\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
+ makeButton("B", "B");\r
+ makeButton("Z", "Z");\r
+ makeButton("X", "X");\r
+ makeButton("Gap", "'.','-',' '");\r
\r
- if (jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR") != null)\r
- {\r
- loadColours(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR"));\r
+ if (jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR") != null)\r
+ {\r
+ loadColours(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR"));\r
+ }\r
}\r
- }\r
\r
- public void stateChanged(ChangeEvent evt)\r
- {\r
- if (selectedButton != null)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param evt DOCUMENT ME!\r
+ */\r
+ public void stateChanged(ChangeEvent evt)\r
{\r
- selectedButton.setBackground(colorChooser.getColor());\r
+ if (selectedButtons != null)\r
+ {\r
+ JButton button;\r
+ for(int i=0; i<selectedButtons.size(); i++)\r
+ {\r
+ button = (JButton)selectedButtons.elementAt(i);\r
+ button.setBackground(colorChooser.getColor());\r
+ button.setForeground( button.getBackground().brighter().brighter().brighter());\r
+ }\r
+ }\r
}\r
- }\r
-\r
- public void colourButtonPressed(MouseEvent e)\r
- {\r
- selectedButton = (JButton) e.getSource();\r
- colorChooser.setColor(selectedButton.getBackground());\r
- }\r
\r
- void makeButton(String label, String aa)\r
- {\r
- final JButton button = new JButton();\r
- Color col = Color.white;\r
-\r
- try\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void colourButtonPressed(MouseEvent e)\r
{\r
- col = oldColourScheme.findColour(aa, -1);\r
- }\r
- catch (Exception ex)\r
- {\r
- }\r
+ if(selectedButtons == null)\r
+ selectedButtons = new Vector();\r
\r
- button.setBackground(col);\r
- oldColours.addElement(col);\r
- button.setText(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 mouseClicked(MouseEvent e)\r
+ JButton pressed = (JButton) e.getSource();\r
+\r
+ if(e.isShiftDown())\r
{\r
- colourButtonPressed(e);\r
- }\r
- });\r
+ JButton start = (JButton)selectedButtons.elementAt(selectedButtons.size()-1);\r
+ JButton end = (JButton) e.getSource();\r
+ int startIndex=0, endIndex=0;\r
+ for(int b=0; b<buttonPanel.getComponentCount(); b++)\r
+ {\r
+ if(buttonPanel.getComponent(b)==start)\r
+ startIndex = b;\r
+ if(buttonPanel.getComponent(b)==end)\r
+ endIndex = b;\r
+ }\r
+\r
+ if(startIndex > endIndex)\r
+ {\r
+ int temp = startIndex;\r
+ startIndex = endIndex;\r
+ endIndex = temp;\r
+ }\r
\r
- buttonPanel.add(button, null);\r
- }\r
+ for(int b=startIndex; b<=endIndex; b++)\r
+ {\r
+ JButton button = (JButton)buttonPanel.getComponent(b);\r
+ if(!selectedButtons.contains(button))\r
+ {\r
+ button.setForeground(button.getBackground().brighter().brighter());\r
+ selectedButtons.add(button);\r
+ }\r
+ }\r
+ }\r
+ else if(!e.isControlDown())\r
+ {\r
+ for(int b=0; b<selectedButtons.size(); b++)\r
+ {\r
+ JButton button = (JButton)selectedButtons.elementAt(b);\r
+ button.setForeground(button.getBackground().darker().darker());\r
+ }\r
+ selectedButtons.clear();\r
+ pressed.setForeground( pressed.getBackground().brighter().brighter());\r
+ selectedButtons.addElement(pressed);\r
\r
- protected void okButton_actionPerformed(ActionEvent e)\r
- {\r
- applyButton_actionPerformed(null);\r
+ }\r
+ else if(e.isControlDown())\r
+ {\r
+ if(selectedButtons.contains(pressed))\r
+ {\r
+ pressed.setForeground(pressed.getBackground().darker().darker());\r
+ selectedButtons.remove(pressed);\r
+ }\r
+ else\r
+ {\r
+ pressed.setForeground( pressed.getBackground().brighter().brighter());\r
+ selectedButtons.addElement(pressed);\r
+ }\r
+ }\r
\r
- try\r
- {\r
- frame.setClosed(true);\r
+ if(selectedButtons.size()>0)\r
+ colorChooser.setColor( ((JButton)selectedButtons.elementAt(0)).getBackground());\r
}\r
- catch (Exception ex)\r
- {\r
- }\r
- }\r
\r
- protected void applyButton_actionPerformed(ActionEvent e)\r
- {\r
- Color[] newColours = new Color[24];\r
-\r
- for (int i = 0; i < 24; i++)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param label DOCUMENT ME!\r
+ * @param aa DOCUMENT ME!\r
+ */\r
+ void makeButton(String label, String aa)\r
{\r
- JButton button = (JButton) buttonPanel.getComponent(i);\r
- newColours[i] = button.getBackground();\r
- }\r
+ final JButton button = new JButton();\r
+ Color col = Color.white;\r
\r
- UserColourScheme ucs = new UserColourScheme(newColours);\r
- ucs.setThreshold(0);\r
+ try\r
+ {\r
+ col = oldColourScheme.findColour(aa, -1);\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ }\r
\r
- if (seqGroup != null)\r
- {\r
- seqGroup.cs = ucs;\r
- ap.repaint();\r
+ button.setBackground(col);\r
+ oldColours.addElement(col);\r
+ button.setText(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 mouseClicked(MouseEvent e)\r
+ {\r
+ colourButtonPressed(e);\r
+ }\r
+ });\r
+\r
+ buttonPanel.add(button, null);\r
}\r
- else\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void okButton_actionPerformed(ActionEvent e)\r
{\r
- ap.alignFrame.changeColour(ucs);\r
+ applyButton_actionPerformed(null);\r
+\r
+ try\r
+ {\r
+ frame.setClosed(true);\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ }\r
}\r
- }\r
-\r
- protected void loadbutton_actionPerformed(ActionEvent e)\r
- {\r
- JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
- getProperty(\r
- "LAST_DIRECTORY"), new String[]\r
- {"jc"},\r
- new String[]\r
- {"Jalview User Colours"}, "Jalview User Colours");\r
- chooser.setFileView(new jalview.io.JalviewFileView());\r
- chooser.setDialogTitle("Load colour scheme");\r
- chooser.setToolTipText("Load");\r
-\r
- int value = chooser.showOpenDialog(this);\r
-\r
- if (value == JalviewFileChooser.APPROVE_OPTION)\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void applyButton_actionPerformed(ActionEvent e)\r
{\r
- File choice = chooser.getSelectedFile();\r
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());\r
- jalview.bin.Cache.setProperty("USER_DEFINED_COLOUR",\r
- choice.getPath());\r
+ Color[] newColours = new Color[24];\r
\r
- Color[] colors = loadColours(choice.getAbsolutePath());\r
+ for (int i = 0; i < 24; i++)\r
+ {\r
+ JButton button = (JButton) buttonPanel.getComponent(i);\r
+ newColours[i] = button.getBackground();\r
+ }\r
\r
- for (int i = 0; i < colors.length; i++)\r
- {\r
- JButton button = (JButton) buttonPanel.getComponent(i);\r
- button.setBackground(colors[i]);\r
- }\r
- }\r
- }\r
+ UserColourScheme ucs = new UserColourScheme(newColours);\r
+ ucs.setThreshold(0);\r
\r
- public static UserColourScheme loadDefaultColours()\r
- {\r
- if (jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR") != null)\r
- {\r
- return loadDefaultColours(jalview.bin.Cache.getProperty(\r
- "USER_DEFINED_COLOUR"));\r
- }\r
- else\r
- {\r
- return null;\r
+ if (seqGroup != null)\r
+ {\r
+ seqGroup.cs = ucs;\r
+ ap.repaint();\r
+ }\r
+ else\r
+ {\r
+ ap.alignFrame.changeColour(ucs);\r
+ }\r
}\r
- }\r
-\r
- public static UserColourScheme loadDefaultColours(String file)\r
- {\r
- UserColourScheme ucs = null;\r
- Color[] cols = loadColours(file);\r
\r
- if (cols != null)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void loadbutton_actionPerformed(ActionEvent e)\r
{\r
- ucs = new UserColourScheme(cols);\r
- ucs.setThreshold(0);\r
- }\r
+ JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(\r
+ "LAST_DIRECTORY"), new String[] { "jc" },\r
+ new String[] { "Jalview User Colours" }, "Jalview User Colours");\r
+ chooser.setFileView(new jalview.io.JalviewFileView());\r
+ chooser.setDialogTitle("Load colour scheme");\r
+ chooser.setToolTipText("Load");\r
\r
- return ucs;\r
- }\r
+ int value = chooser.showOpenDialog(this);\r
\r
- static Color[] loadColours(String file)\r
- {\r
- Color[] newColours = null;\r
+ if (value == JalviewFileChooser.APPROVE_OPTION)\r
+ {\r
+ File choice = chooser.getSelectedFile();\r
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());\r
+ jalview.bin.Cache.setProperty("USER_DEFINED_COLOUR",\r
+ choice.getPath());\r
+\r
+ Color[] colors = loadColours(choice.getAbsolutePath());\r
+\r
+ for (int i = 0; i < colors.length; i++)\r
+ {\r
+ JButton button = (JButton) buttonPanel.getComponent(i);\r
+ button.setBackground(colors[i]);\r
+ }\r
+ }\r
+ }\r
\r
- try\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public static UserColourScheme loadDefaultColours()\r
{\r
- InputStreamReader in = new InputStreamReader(new FileInputStream(\r
- file), "UTF-8");\r
+ if (jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR") != null)\r
+ {\r
+ return loadDefaultColours(jalview.bin.Cache.getProperty(\r
+ "USER_DEFINED_COLOUR"));\r
+ }\r
+ else\r
+ {\r
+ return null;\r
+ }\r
+ }\r
\r
- jalview.binding.JalviewUserColours ucs = new jalview.binding.\r
- JalviewUserColours();\r
- ucs = (jalview.binding.JalviewUserColours) ucs.unmarshal(in);\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param file DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public static UserColourScheme loadDefaultColours(String file)\r
+ {\r
+ UserColourScheme ucs = null;\r
+ Color[] cols = loadColours(file);\r
\r
- newColours = new Color[ucs.getColourCount()];\r
+ if (cols != null)\r
+ {\r
+ ucs = new UserColourScheme(cols);\r
+ ucs.setThreshold(0);\r
+ }\r
\r
- for (int i = 0; i < 24; i++)\r
- {\r
- newColours[i] = new Color(Integer.parseInt(\r
- ucs.getColour(i).getRGB(), 16));\r
- }\r
+ return ucs;\r
}\r
- catch (Exception ex)\r
+\r
+ static Color[] loadColours(String file)\r
{\r
- System.out.println("Error loading UserColourFile " + file);\r
- }\r
+ Color[] newColours = null;\r
+\r
+ try\r
+ {\r
+ InputStreamReader in = new InputStreamReader(new FileInputStream(\r
+ file), "UTF-8");\r
\r
- return newColours;\r
- }\r
+ jalview.binding.JalviewUserColours ucs = new jalview.binding.JalviewUserColours();\r
+ ucs = (jalview.binding.JalviewUserColours) ucs.unmarshal(in);\r
\r
- protected void savebutton_actionPerformed(ActionEvent e)\r
- {\r
- JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.\r
- getProperty(\r
- "LAST_DIRECTORY"), new String[]\r
- {"jc"},\r
- new String[]\r
- {"Jalview User Colours"}, "Jalview User Colours");\r
+ newColours = new Color[ucs.getColourCount()];\r
\r
- chooser.setFileView(new jalview.io.JalviewFileView());\r
- chooser.setDialogTitle("Save colour scheme");\r
- chooser.setToolTipText("Save");\r
+ for (int i = 0; i < 24; i++)\r
+ {\r
+ newColours[i] = new Color(Integer.parseInt(\r
+ ucs.getColour(i).getRGB(), 16));\r
+ }\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ System.out.println("Error loading UserColourFile " + file);\r
+ }\r
\r
- int value = chooser.showSaveDialog(this);\r
+ return newColours;\r
+ }\r
\r
- if (value == JalviewFileChooser.APPROVE_OPTION)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void savebutton_actionPerformed(ActionEvent e)\r
{\r
- String choice = chooser.getSelectedFile().getPath();\r
- jalview.bin.Cache.setProperty("USER_DEFINED_COLOUR", choice);\r
+ JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.getProperty(\r
+ "LAST_DIRECTORY"), new String[] { "jc" },\r
+ new String[] { "Jalview User Colours" }, "Jalview User Colours");\r
\r
- jalview.binding.JalviewUserColours ucs = new jalview.binding.\r
- JalviewUserColours();\r
+ chooser.setFileView(new jalview.io.JalviewFileView());\r
+ chooser.setDialogTitle("Save colour scheme");\r
+ chooser.setToolTipText("Save");\r
\r
- try\r
- {\r
- PrintWriter out = new PrintWriter(new OutputStreamWriter(\r
- new FileOutputStream(choice), "UTF-8"));\r
+ int value = chooser.showSaveDialog(this);\r
\r
- for (int i = 0; i < 24; i++)\r
+ if (value == JalviewFileChooser.APPROVE_OPTION)\r
{\r
- JButton button = (JButton) buttonPanel.getComponent(i);\r
- jalview.binding.Colour col = new jalview.binding.Colour();\r
- col.setName(button.getText());\r
- col.setRGB(jalview.util.Format.getHexString(\r
- button.getBackground()));\r
- ucs.addColour(col);\r
+ String choice = chooser.getSelectedFile().getPath();\r
+ jalview.bin.Cache.setProperty("USER_DEFINED_COLOUR", choice);\r
+\r
+ jalview.binding.JalviewUserColours ucs = new jalview.binding.JalviewUserColours();\r
+\r
+ try\r
+ {\r
+ PrintWriter out = new PrintWriter(new OutputStreamWriter(\r
+ new FileOutputStream(choice), "UTF-8"));\r
+\r
+ for (int i = 0; i < 24; i++)\r
+ {\r
+ JButton button = (JButton) buttonPanel.getComponent(i);\r
+ jalview.binding.Colour col = new jalview.binding.Colour();\r
+ col.setName(button.getText());\r
+ col.setRGB(jalview.util.Format.getHexString(\r
+ button.getBackground()));\r
+ ucs.addColour(col);\r
+ }\r
+\r
+ ucs.marshal(out);\r
+ out.close();\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
}\r
-\r
- ucs.marshal(out);\r
- out.close();\r
- }\r
- catch (Exception ex)\r
- {\r
- ex.printStackTrace();\r
- }\r
}\r
- }\r
-\r
- protected void cancelButton_actionPerformed(ActionEvent e)\r
- {\r
- Color[] newColours = new Color[24];\r
\r
- for (int i = 0; i < 24; i++)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void cancelButton_actionPerformed(ActionEvent e)\r
{\r
- newColours[i] = (Color) oldColours.elementAt(i);\r
- buttonPanel.getComponent(i).setBackground(newColours[i]);\r
- }\r
+ Color[] newColours = new Color[24];\r
\r
- UserColourScheme ucs = new UserColourScheme(newColours);\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
- if (seqGroup != null)\r
- {\r
- seqGroup.cs = ucs;\r
- }\r
- else\r
- {\r
- ap.av.setGlobalColourScheme(ucs);\r
- }\r
+ UserColourScheme ucs = new UserColourScheme(newColours);\r
+\r
+ if (seqGroup != null)\r
+ {\r
+ seqGroup.cs = ucs;\r
+ }\r
+ else\r
+ {\r
+ ap.av.setGlobalColourScheme(ucs);\r
+ }\r
\r
- ap.repaint();\r
+ ap.repaint();\r
\r
- try\r
- {\r
- frame.setClosed(true);\r
- }\r
- catch (Exception ex)\r
- {\r
+ try\r
+ {\r
+ frame.setClosed(true);\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ }\r
}\r
- }\r
}\r