/*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
-*\r
-* This program 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 2\r
-* of the License, or (at your option) any later version.\r
-*\r
-* This program is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with this program; if not, write to the Free Software\r
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
-*/\r
-\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program 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 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+ */\r
package jalview.gui;\r
\r
-import jalview.jbgui.GUserDefinedColours;\r
import jalview.datamodel.*;\r
+\r
import jalview.io.*;\r
-import javax.swing.*;\r
+\r
+import jalview.jbgui.*;\r
+\r
+import jalview.schemes.*;\r
+\r
import java.awt.*;\r
import java.awt.event.*;\r
-import javax.swing.event.*;\r
-import jalview.schemes.*;\r
+\r
import java.io.*;\r
+\r
import java.util.*;\r
\r
+import javax.swing.*;\r
+import javax.swing.event.*;\r
+\r
+\r
\r
-public class UserDefinedColours 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
+ Vector selectedButtons;\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
+ super();\r
+ frame = new JInternalFrame();\r
+ frame.setContentPane(this);\r
+ Desktop.addInternalFrame(frame, "User Defined Colours", 720, 370, true);\r
\r
- AlignmentPanel ap;\r
- SequenceGroup seqGroup;\r
- JButton selectedButton;\r
- Vector oldColours = new Vector();\r
- ColourSchemeI oldColourScheme;\r
- JInternalFrame frame;\r
+ if (System.getProperty("os.name").startsWith("Mac"))\r
+ {\r
+ frame.setSize(760, 370);\r
+ }\r
\r
+ if (sg != null)\r
+ {\r
+ frame.setTitle(frame.getTitle() + " (" + sg.getName() + ")");\r
+ }\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
- if(System.getProperty("os.name").startsWith("Mac"))\r
- frame.setSize(450,560);\r
+ colorChooser.getSelectionModel().addChangeListener(this);\r
\r
- if(sg!=null)\r
- frame.setTitle( frame.getTitle()+ " ("+sg.getName()+")");\r
+ this.ap = ap;\r
+ seqGroup = sg;\r
\r
- colorChooser.getSelectionModel().addChangeListener(this);\r
+ if (seqGroup != null)\r
+ {\r
+ oldColourScheme = seqGroup.cs;\r
+ }\r
+ else\r
+ {\r
+ oldColourScheme = ap.av.getGlobalColourScheme();\r
+ }\r
\r
- this.ap = ap;\r
- seqGroup = sg;\r
+ if (oldColourScheme instanceof UserColourScheme)\r
+ {\r
+ schemeName.setText( ( (UserColourScheme) oldColourScheme).getName());\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
\r
- if (seqGroup != null)\r
- oldColourScheme = seqGroup.cs;\r
- else\r
- oldColourScheme = ap.av.getGlobalColourScheme();\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param evt DOCUMENT ME!\r
+ */\r
+ public void stateChanged(ChangeEvent evt)\r
+ {\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
- for (int i = 0; i < 20; i++)\r
- makeButton(ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) +\r
- "", ResidueProperties.aa[i]);\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void colourButtonPressed(MouseEvent e)\r
+ {\r
+ if(selectedButtons == null)\r
+ selectedButtons = new Vector();\r
+\r
+ JButton pressed = (JButton) e.getSource();\r
+\r
+ if(e.isShiftDown())\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
- makeButton("B", "B");\r
- makeButton("Z", "Z");\r
- makeButton("X", "X");\r
- makeButton("Gap", "'.','-',' '");\r
+ if(startIndex > endIndex)\r
+ {\r
+ int temp = startIndex;\r
+ startIndex = endIndex;\r
+ endIndex = temp;\r
+ }\r
\r
- if(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR")!=null)\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
- loadColours(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR"));\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
}\r
- }\r
-\r
- public void stateChanged(ChangeEvent evt)\r
- {\r
- if(selectedButton!=null)\r
- selectedButton.setBackground( colorChooser.getColor() );\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
-\r
- try{\r
- col = oldColourScheme.findColour(aa, -1);\r
- }catch(Exception ex){}\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
+ else if(e.isControlDown())\r
{\r
- colourButtonPressed(e);\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
\r
- buttonPanel.add(button, null);\r
- }\r
+ if(selectedButtons.size()>0)\r
+ colorChooser.setColor( ((JButton)selectedButtons.elementAt(0)).getBackground());\r
+ }\r
\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
+ final JButton button = new JButton();\r
+ Color col = Color.white;\r
\r
- protected void okButton_actionPerformed(ActionEvent e)\r
- {\r
- applyButton_actionPerformed(null);\r
- try{\r
- frame.setClosed(true);\r
- }catch(Exception ex){}\r
- }\r
+ try\r
+ {\r
+ col = oldColourScheme.findColour(aa, -1);\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ // ex.printStackTrace();\r
+ }\r
\r
- protected void applyButton_actionPerformed(ActionEvent e)\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
+ button.setBackground(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
\r
- UserColourScheme ucs = new UserColourScheme(newColours);\r
- ucs.setThreshold(0);\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void okButton_actionPerformed(ActionEvent e)\r
+ {\r
+ applyButton_actionPerformed(null);\r
+\r
+ try\r
+ {\r
+ frame.setClosed(true);\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ }\r
+ }\r
\r
- if(seqGroup!=null)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void applyButton_actionPerformed(ActionEvent e)\r
{\r
- seqGroup.cs = ucs;\r
- ap.repaint();\r
+ UserColourScheme ucs = getSchemeFromGUI();\r
+ ucs.setName(schemeName.getText());\r
+\r
+ if (seqGroup != null)\r
+ {\r
+ seqGroup.cs = ucs;\r
+ ap.repaint();\r
+ }\r
+ else\r
+ {\r
+ ap.alignFrame.changeColour(ucs);\r
+ }\r
}\r
- else\r
- ap.alignFrame.changeColour(ucs);\r
-\r
- }\r
-\r
- protected void loadbutton_actionPerformed(ActionEvent e)\r
- {\r
- JalviewFileChooser chooser = new JalviewFileChooser(\r
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"),\r
- new String[]{"jc"},\r
- new String[]{"Jalview User Colours"},\r
- "Jalview User Colours");\r
- chooser.setFileView(new jalview.io.JalviewFileView());\r
- chooser.setDialogTitle("Load colour scheme");\r
- chooser.setToolTipText("Load");\r
- int value = chooser.showOpenDialog(this);\r
- if (value == JalviewFileChooser.APPROVE_OPTION)\r
+\r
+ UserColourScheme getSchemeFromGUI()\r
{\r
- File choice = chooser.getSelectedFile();\r
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());\r
- jalview.bin.Cache.setProperty("USER_DEFINED_COLOUR", choice.getPath());\r
- Color[] colors = loadColours(choice.getAbsolutePath());\r
- for (int i = 0; i < colors.length; i++)\r
+ Color[] newColours = new Color[24];\r
+\r
+ for (int i = 0; i < 24; i++)\r
{\r
JButton button = (JButton) buttonPanel.getComponent(i);\r
- button.setBackground(colors[i]);\r
+ newColours[i] = button.getBackground();\r
}\r
\r
- }\r
- }\r
-\r
- public static UserColourScheme loadDefaultColours()\r
- {\r
- if(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR")!=null)\r
- return loadDefaultColours(jalview.bin.Cache.getProperty("USER_DEFINED_COLOUR"));\r
- else\r
- return null;\r
- }\r
-\r
- public static UserColourScheme loadDefaultColours(String file)\r
- {\r
- UserColourScheme ucs = null;\r
- Color cols[] = loadColours(file);\r
- if(cols!=null)\r
- {\r
- ucs = new UserColourScheme(cols);\r
- ucs.setThreshold(0);\r
- }\r
+ UserColourScheme ucs = new UserColourScheme(newColours);\r
+ ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());\r
+\r
return ucs;\r
- }\r
+ }\r
+\r
\r
- static Color [] loadColours(String file)\r
- {\r
- Color [] newColours=null;\r
- try\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void loadbutton_actionPerformed(ActionEvent e)\r
{\r
- InputStreamReader in = new InputStreamReader(\r
- new FileInputStream(file), "UTF-8");\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
- jalview.binding.JalviewUserColours ucs = new jalview.binding.JalviewUserColours();\r
- ucs = (jalview.binding.JalviewUserColours)ucs.unmarshal(in);\r
+ int value = chooser.showOpenDialog(this);\r
+\r
+ if (value == JalviewFileChooser.APPROVE_OPTION)\r
+ {\r
+ File choice = chooser.getSelectedFile();\r
+ jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());\r
+ String defaultColours = jalview.bin.Cache.getDefault("USER_DEFINED_COLOURS",\r
+ choice.getPath());\r
+ if (defaultColours.indexOf(choice.getPath()) == -1)\r
+ defaultColours = defaultColours.concat("|").concat(choice.getPath());\r
+\r
+ jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", defaultColours);\r
\r
- newColours = new Color[ucs.getColourCount()];\r
- for (int i = 0; i < 24; i++)\r
- newColours[i] = new Color(Integer.parseInt(ucs.getColour(i).getRGB(), 16));\r
\r
+ UserColourScheme ucs = loadColours(choice.getAbsolutePath());\r
+ Color[] colors = ucs.getColours();\r
+ schemeName.setText(ucs.getName());\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
- catch (Exception ex)\r
- {System.out.println("Error loading UserColourFile "+file);}\r
-\r
- return newColours;\r
- }\r
-\r
- protected void savebutton_actionPerformed(ActionEvent e)\r
- {\r
- JalviewFileChooser chooser = new JalviewFileChooser(\r
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"),\r
- new String[]{"jc"},\r
- new String[]{"Jalview User Colours"},\r
- "Jalview User Colours");\r
-\r
- chooser.setFileView(new jalview.io.JalviewFileView());\r
- chooser.setDialogTitle("Save colour scheme");\r
- chooser.setToolTipText("Save");\r
- int value = chooser.showSaveDialog(this);\r
- if (value == JalviewFileChooser.APPROVE_OPTION)\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ public static UserColourScheme loadDefaultColours()\r
{\r
- String choice = chooser.getSelectedFile().getPath();\r
- jalview.bin.Cache.setProperty("USER_DEFINED_COLOUR", choice);\r
- jalview.binding.JalviewUserColours ucs = new jalview.binding.JalviewUserColours();\r
+ UserColourScheme ret = null;\r
+\r
+ String colours = jalview.bin.Cache.getProperty("USER_DEFINED_COLOURS");\r
+ if ( colours != null )\r
+ {\r
+ if(colours.indexOf("|")>-1)\r
+ colours = colours.substring(0, colours.indexOf("|"));\r
+\r
+ ret = loadColours(colours);\r
+ }\r
\r
- try{\r
- PrintWriter out = new PrintWriter(new OutputStreamWriter(\r
- new FileOutputStream(choice), "UTF-8"));\r
- for(int i=0; i<24; i++)\r
+ if(ret == null)\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( button.getBackground() ));\r
- ucs.addColour(col);\r
+ Color[] newColours = new Color[24];\r
+ for (int i = 0; i < 24; i++)\r
+ {\r
+ newColours[i] = Color.white;\r
+ }\r
+ ret = new UserColourScheme(newColours);\r
}\r
\r
- ucs.marshal(out);\r
- out.close();\r
+ return ret;\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param file DOCUMENT ME!\r
+ *\r
+ * @return DOCUMENT ME!\r
+ */\r
+ static UserColourScheme loadColours(String file)\r
+ {\r
+ UserColourScheme ucs = null;\r
+ Color[] newColours = null;\r
+\r
+ try\r
+ {\r
+ InputStreamReader in = new InputStreamReader(new FileInputStream(\r
+ file), "UTF-8");\r
+\r
+ jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours();\r
+ jucs = (jalview.binding.JalviewUserColours) jucs.unmarshal(in);\r
+\r
+ newColours = new Color[jucs.getColourCount()];\r
+\r
+ for (int i = 0; i < 24; i++)\r
+ {\r
+ newColours[i] = new Color(Integer.parseInt(\r
+ jucs.getColour(i).getRGB(), 16));\r
+ }\r
+ if (newColours != null)\r
+ {\r
+ ucs = new UserColourScheme(newColours);\r
+ ucs.setName( jucs.getSchemeName() );\r
+ }\r
+\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ System.out.println("Error loading User ColourFile\n"+ex);\r
+ }\r
+\r
+\r
+ return ucs;\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void savebutton_actionPerformed(ActionEvent e)\r
+ {\r
+ if(schemeName.getText().trim().length()<1)\r
+ {\r
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+ "User colour scheme must have a name!",\r
+ "No name for colour scheme",\r
+ JOptionPane.WARNING_MESSAGE);\r
+ return;\r
}\r
- catch(Exception ex)\r
- {ex.printStackTrace();}\r
+\r
+ if(userColourSchemes!=null && userColourSchemes.containsKey(schemeName.getText()) )\r
+ {\r
+ int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop, "Colour scheme "+schemeName.getText()+ " exists."\r
+ +"\nContinue saving colour scheme as "+schemeName.getText()+"?",\r
+ "Duplicate scheme name", JOptionPane.YES_NO_OPTION);\r
+ if(reply != JOptionPane.YES_OPTION)\r
+ return;\r
+\r
+ userColourSchemes.remove(schemeName.getText());\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
+\r
+ chooser.setFileView(new jalview.io.JalviewFileView());\r
+ chooser.setDialogTitle("Save colour scheme");\r
+ chooser.setToolTipText("Save");\r
+\r
+ int value = chooser.showSaveDialog(this);\r
+\r
+ if (value == JalviewFileChooser.APPROVE_OPTION)\r
+ {\r
+ String choice = chooser.getSelectedFile().getPath();\r
+ String defaultColours = jalview.bin.Cache.getDefault("USER_DEFINED_COLOURS", choice);\r
+ if(defaultColours.indexOf(choice)==-1)\r
+ {\r
+ if(defaultColours.length()>0)\r
+ defaultColours = defaultColours.concat("|");\r
+ defaultColours = defaultColours.concat(choice);\r
+ }\r
+\r
+ userColourSchemes.put(schemeName.getText(), getSchemeFromGUI());\r
+\r
+ ap.alignFrame.updateUserColourMenu();\r
+\r
+ jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", defaultColours);\r
+\r
+ jalview.binding.JalviewUserColours ucs = new jalview.binding.JalviewUserColours();\r
+ ucs.setSchemeName(schemeName.getText());\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
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void cancelButton_actionPerformed(ActionEvent e)\r
+ {\r
+ if (seqGroup != null)\r
+ {\r
+ seqGroup.cs = oldColourScheme;\r
+ }\r
+ else\r
+ {\r
+ ap.av.setGlobalColourScheme(oldColourScheme);\r
+ }\r
+\r
+ ap.repaint();\r
+\r
+ try\r
+ {\r
+ frame.setClosed(true);\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ }\r
}\r
\r
- }\r
\r
- protected void cancelButton_actionPerformed(ActionEvent e)\r
- {\r
+ static Hashtable userColourSchemes;\r
\r
- Color [] newColours = new Color[24];\r
- for(int i=0; i<24; i++)\r
+ public static Hashtable getUserColourSchemes()\r
{\r
- newColours[i] = (Color)oldColours.elementAt(i);\r
- buttonPanel.getComponent(i).setBackground(newColours[i]);\r
+ return userColourSchemes;\r
}\r
\r
- UserColourScheme ucs = new UserColourScheme( newColours );\r
+ public static void initUserColourSchemes(String files)\r
+ {\r
+ userColourSchemes = new Hashtable();\r
\r
- if (seqGroup != null)\r
- seqGroup.cs = ucs;\r
- else\r
- ap.av.setGlobalColourScheme(ucs);\r
+ if(files==null || files.length()==0)\r
+ return;\r
\r
- ap.repaint();\r
\r
- try{\r
- frame.setClosed(true);\r
- }catch(Exception ex){}\r
- }\r
+ // In case colours can't be loaded, we'll remove them\r
+ // from the default list here.\r
+ StringBuffer coloursFound = new StringBuffer();\r
+ StringTokenizer st = new StringTokenizer(files, "|");\r
+ while (st.hasMoreElements())\r
+ {\r
+ String file = st.nextToken();\r
+ try\r
+ {\r
+ UserColourScheme ucs = loadColours(file);\r
+ if (ucs != null)\r
+ {\r
+ if (coloursFound.length() > 0)\r
+ coloursFound.append("|");\r
+ coloursFound.append(file);\r
+ userColourSchemes.put(ucs.getName(), ucs);\r
+ }\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ System.out.println("Error loading User ColourFile\n" + ex);\r
+ }\r
+ }\r
+ if (!files.equals(coloursFound.toString()))\r
+ {\r
+ if (coloursFound.toString().length() > 1)\r
+ jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS",\r
+ coloursFound.toString());\r
+ else\r
+ jalview.bin.Cache.applicationProperties.remove("USER_DEFINED_COLOURS");\r
+ }\r
+ }\r
+\r
+ public static void removeColourFromDefaults(String target)\r
+ {\r
+ // The only way to find colours by name is to load them in\r
+ // In case colours can't be loaded, we'll remove them\r
+ // from the default list here.\r
\r
+ userColourSchemes = new Hashtable();\r
\r
+ StringBuffer coloursFound = new StringBuffer();\r
+ StringTokenizer st = new StringTokenizer(\r
+ jalview.bin.Cache.getProperty("USER_DEFINED_COLOURS"), "|");\r
+\r
+ while (st.hasMoreElements())\r
+ {\r
+ String file = st.nextToken();\r
+ try\r
+ {\r
+ UserColourScheme ucs = loadColours(file);\r
+ if (ucs != null && !ucs.getName().equals(target))\r
+ {\r
+ if (coloursFound.length() > 0)\r
+ coloursFound.append("|");\r
+ coloursFound.append(file);\r
+ userColourSchemes.put(ucs.getName(), ucs);\r
+ }\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ System.out.println("Error loading User ColourFile\n" + ex);\r
+ }\r
+ }\r
+\r
+ if (coloursFound.toString().length() > 1)\r
+ jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", coloursFound.toString());\r
+ else\r
+ jalview.bin.Cache.applicationProperties.remove("USER_DEFINED_COLOURS");\r
+\r
+ }\r
}\r