apply gpl development license
[jalview.git] / src / jalview / gui / UserDefinedColours.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3  * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.gui;
20
21 import java.io.*;
22 import java.util.*;
23
24 import java.awt.*;
25 import java.awt.event.*;
26 import javax.swing.*;
27 import javax.swing.event.*;
28
29 import jalview.datamodel.*;
30 import jalview.io.*;
31 import jalview.jbgui.*;
32 import jalview.schemes.*;
33
34 /**
35  * DOCUMENT ME!
36  * 
37  * @author $author$
38  * @version $Revision$
39  */
40 public class UserDefinedColours extends GUserDefinedColours implements
41         ChangeListener
42 {
43   AlignmentPanel ap;
44
45   SequenceGroup seqGroup;
46
47   Vector selectedButtons;
48
49   ColourSchemeI oldColourScheme;
50
51   JInternalFrame frame;
52
53   AppJmol jmol;
54
55   Vector upperCaseButtons;
56
57   Vector lowerCaseButtons;
58
59   /**
60    * Creates a new UserDefinedColours object.
61    * 
62    * @param ap
63    *                DOCUMENT ME!
64    * @param sg
65    *                DOCUMENT ME!
66    */
67   public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
68   {
69     super();
70
71     lcaseColour.setEnabled(false);
72
73     this.ap = ap;
74     seqGroup = sg;
75
76     if (seqGroup != null)
77     {
78       oldColourScheme = seqGroup.cs;
79     }
80     else
81     {
82       oldColourScheme = ap.av.getGlobalColourScheme();
83     }
84
85     if (oldColourScheme instanceof UserColourScheme)
86     {
87       schemeName.setText(((UserColourScheme) oldColourScheme).getName());
88       if (((UserColourScheme) oldColourScheme).getLowerCaseColours() != null)
89       {
90         caseSensitive.setSelected(true);
91         lcaseColour.setEnabled(true);
92         resetButtonPanel(true);
93       }
94       else
95       {
96         resetButtonPanel(false);
97       }
98     }
99     else
100     {
101       resetButtonPanel(false);
102     }
103
104     showFrame();
105   }
106
107   public UserDefinedColours(AppJmol jmol, ColourSchemeI oldcs)
108   {
109     super();
110     this.jmol = jmol;
111
112     colorChooser.getSelectionModel().addChangeListener(this);
113
114     oldColourScheme = oldcs;
115
116     if (oldColourScheme instanceof UserColourScheme)
117     {
118       schemeName.setText(((UserColourScheme) oldColourScheme).getName());
119     }
120
121     resetButtonPanel(false);
122
123     showFrame();
124
125   }
126
127   void showFrame()
128   {
129     colorChooser.getSelectionModel().addChangeListener(this);
130     frame = new JInternalFrame();
131     frame.setContentPane(this);
132     Desktop.addInternalFrame(frame, "User Defined Colours", 720, 370, true);
133
134     if (seqGroup != null)
135     {
136       frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
137     }
138
139     if (new jalview.util.Platform().isAMac())
140     {
141       frame.setSize(760, 370);
142     }
143   }
144
145   void resetButtonPanel(boolean caseSensitive)
146   {
147     buttonPanel.removeAll();
148
149     if (upperCaseButtons == null)
150     {
151       upperCaseButtons = new Vector();
152     }
153
154     JButton button;
155     String label;
156     for (int i = 0; i < 20; i++)
157     {
158       if (caseSensitive)
159       {
160         label = ResidueProperties.aa[i];
161       }
162       else
163       {
164         label = ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
165                 .toString();
166       }
167
168       button = makeButton(label, ResidueProperties.aa[i], upperCaseButtons,
169               i);
170
171       buttonPanel.add(button);
172     }
173
174     buttonPanel.add(makeButton("B", "B", upperCaseButtons, 20));
175     buttonPanel.add(makeButton("Z", "Z", upperCaseButtons, 21));
176     buttonPanel.add(makeButton("X", "X", upperCaseButtons, 22));
177     buttonPanel.add(makeButton("Gap", "-", upperCaseButtons, 23));
178
179     if (!caseSensitive)
180     {
181       gridLayout.setRows(6);
182       gridLayout.setColumns(4);
183     }
184     else
185     {
186       gridLayout.setRows(7);
187       int cols = 7;
188       gridLayout.setColumns(cols + 1);
189
190       if (lowerCaseButtons == null)
191       {
192         lowerCaseButtons = new Vector();
193       }
194
195       for (int i = 0; i < 20; i++)
196       {
197         int row = i / cols + 1;
198         int index = (row * cols) + i;
199         button = makeButton(ResidueProperties.aa[i].toLowerCase(),
200                 ResidueProperties.aa[i].toLowerCase(), lowerCaseButtons, i);
201
202         buttonPanel.add(button, index);
203       }
204     }
205
206     if (caseSensitive)
207     {
208       buttonPanel.add(makeButton("b", "b", lowerCaseButtons, 20));
209       buttonPanel.add(makeButton("z", "z", lowerCaseButtons, 21));
210       buttonPanel.add(makeButton("x", "x", lowerCaseButtons, 22));
211     }
212
213     buttonPanel.validate();
214     validate();
215   }
216
217   /**
218    * DOCUMENT ME!
219    * 
220    * @param evt
221    *                DOCUMENT ME!
222    */
223   public void stateChanged(ChangeEvent evt)
224   {
225     if (selectedButtons != null)
226     {
227       JButton button = null;
228       for (int i = 0; i < selectedButtons.size(); i++)
229       {
230         button = (JButton) selectedButtons.elementAt(i);
231         button.setBackground(colorChooser.getColor());
232         button.setForeground(button.getBackground().brighter().brighter()
233                 .brighter());
234       }
235       if (button == lcaseColour)
236       {
237         for (int i = 0; i < lowerCaseButtons.size(); i++)
238         {
239           button = (JButton) lowerCaseButtons.elementAt(i);
240           button.setBackground(colorChooser.getColor());
241           button.setForeground(button.getBackground().brighter().brighter()
242                   .brighter());
243         }
244       }
245     }
246   }
247
248   /**
249    * DOCUMENT ME!
250    * 
251    * @param e
252    *                DOCUMENT ME!
253    */
254   public void colourButtonPressed(MouseEvent e)
255   {
256     if (selectedButtons == null)
257     {
258       selectedButtons = new Vector();
259     }
260
261     JButton pressed = (JButton) e.getSource();
262
263     if (e.isShiftDown())
264     {
265       JButton start, end = (JButton) e.getSource();
266       if (selectedButtons.size() > 0)
267       {
268         start = (JButton) selectedButtons
269                 .elementAt(selectedButtons.size() - 1);
270       }
271       else
272       {
273         start = (JButton) e.getSource();
274       }
275
276       int startIndex = 0, endIndex = 0;
277       for (int b = 0; b < buttonPanel.getComponentCount(); b++)
278       {
279         if (buttonPanel.getComponent(b) == start)
280         {
281           startIndex = b;
282         }
283         if (buttonPanel.getComponent(b) == end)
284         {
285           endIndex = b;
286         }
287       }
288
289       if (startIndex > endIndex)
290       {
291         int temp = startIndex;
292         startIndex = endIndex;
293         endIndex = temp;
294       }
295
296       for (int b = startIndex; b <= endIndex; b++)
297       {
298         JButton button = (JButton) buttonPanel.getComponent(b);
299         if (!selectedButtons.contains(button))
300         {
301           button
302                   .setForeground(button.getBackground().brighter()
303                           .brighter());
304           selectedButtons.add(button);
305         }
306       }
307     }
308     else if (!e.isControlDown())
309     {
310       for (int b = 0; b < selectedButtons.size(); b++)
311       {
312         JButton button = (JButton) selectedButtons.elementAt(b);
313         button.setForeground(button.getBackground().darker().darker());
314       }
315       selectedButtons.clear();
316       pressed.setForeground(pressed.getBackground().brighter().brighter());
317       selectedButtons.addElement(pressed);
318
319     }
320     else if (e.isControlDown())
321     {
322       if (selectedButtons.contains(pressed))
323       {
324         pressed.setForeground(pressed.getBackground().darker().darker());
325         selectedButtons.remove(pressed);
326       }
327       else
328       {
329         pressed
330                 .setForeground(pressed.getBackground().brighter()
331                         .brighter());
332         selectedButtons.addElement(pressed);
333       }
334     }
335
336     if (selectedButtons.size() > 0)
337     {
338       colorChooser.setColor(((JButton) selectedButtons.elementAt(0))
339               .getBackground());
340     }
341   }
342
343   /**
344    * DOCUMENT ME!
345    * 
346    * @param label
347    *                DOCUMENT ME!
348    * @param aa
349    *                DOCUMENT ME!
350    */
351   JButton makeButton(String label, String aa, Vector caseSensitiveButtons,
352           int buttonIndex)
353   {
354     final JButton button;
355     Color col;
356
357     if (buttonIndex < caseSensitiveButtons.size())
358     {
359       button = (JButton) caseSensitiveButtons.elementAt(buttonIndex);
360       col = button.getBackground();
361     }
362     else
363     {
364       button = new JButton();
365       button.addMouseListener(new java.awt.event.MouseAdapter()
366       {
367         public void mouseClicked(MouseEvent e)
368         {
369           colourButtonPressed(e);
370         }
371       });
372
373       caseSensitiveButtons.addElement(button);
374
375       col = Color.white;
376       if (oldColourScheme!=null)
377       {
378         try
379         {
380           col = oldColourScheme.findColour(aa.charAt(0), -1);
381         } catch (Exception ex)
382         {
383         }
384       }
385     }
386
387     if (caseSensitive.isSelected())
388     {
389       button.setMargin(new java.awt.Insets(2, 2, 2, 2));
390     }
391     else
392     {
393       button.setMargin(new java.awt.Insets(2, 14, 2, 14));
394     }
395
396     button.setBackground(col);
397     button.setText(label);
398     button.setForeground(col.darker().darker().darker());
399     button.setFont(new java.awt.Font("Verdana", Font.BOLD, 10));
400
401     return button;
402   }
403
404   /**
405    * DOCUMENT ME!
406    * 
407    * @param e
408    *                DOCUMENT ME!
409    */
410   protected void okButton_actionPerformed(ActionEvent e)
411   {
412     applyButton_actionPerformed(null);
413
414     try
415     {
416       frame.setClosed(true);
417     } catch (Exception ex)
418     {
419     }
420   }
421
422   /**
423    * DOCUMENT ME!
424    * 
425    * @param e
426    *                DOCUMENT ME!
427    */
428   protected void applyButton_actionPerformed(ActionEvent e)
429   {
430     UserColourScheme ucs = getSchemeFromButtons();
431     ucs.setName(schemeName.getText());
432
433     if (seqGroup != null)
434     {
435       seqGroup.cs = ucs;
436       ap.paintAlignment(true);
437     }
438     else if (ap != null)
439     {
440       ap.alignFrame.changeColour(ucs);
441     }
442     else if (jmol != null)
443     {
444       jmol.setJalviewColourScheme(ucs);
445     }
446   }
447
448   UserColourScheme getSchemeFromButtons()
449   {
450
451     Color[] newColours = new Color[24];
452
453     for (int i = 0; i < 24; i++)
454     {
455       JButton button = (JButton) upperCaseButtons.elementAt(i);
456       newColours[i] = button.getBackground();
457     }
458
459     UserColourScheme ucs = new UserColourScheme(newColours);
460
461     if (caseSensitive.isSelected())
462     {
463       newColours = new Color[23];
464       for (int i = 0; i < 23; i++)
465       {
466         JButton button = (JButton) lowerCaseButtons.elementAt(i);
467         newColours[i] = button.getBackground();
468       }
469       ucs.setLowerCaseColours(newColours);
470     }
471
472     if (ap != null)
473     {
474       ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
475     }
476
477     return ucs;
478   }
479
480   /**
481    * DOCUMENT ME!
482    * 
483    * @param e
484    *                DOCUMENT ME!
485    */
486   protected void loadbutton_actionPerformed(ActionEvent e)
487   {
488     upperCaseButtons = new Vector();
489     lowerCaseButtons = new Vector();
490
491     JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
492             .getProperty("LAST_DIRECTORY"), new String[]
493     { "jc" }, new String[]
494     { "Jalview User Colours" }, "Jalview User Colours");
495     chooser.setFileView(new jalview.io.JalviewFileView());
496     chooser.setDialogTitle("Load colour scheme");
497     chooser.setToolTipText("Load");
498
499     int value = chooser.showOpenDialog(this);
500
501     if (value == JalviewFileChooser.APPROVE_OPTION)
502     {
503       File choice = chooser.getSelectedFile();
504       jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
505       String defaultColours = jalview.bin.Cache.getDefault(
506               "USER_DEFINED_COLOURS", choice.getPath());
507       if (defaultColours.indexOf(choice.getPath()) == -1)
508       {
509         defaultColours = defaultColours.concat("|")
510                 .concat(choice.getPath());
511       }
512
513       jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", defaultColours);
514
515       UserColourScheme ucs = loadColours(choice.getAbsolutePath());
516       Color[] colors = ucs.getColours();
517       schemeName.setText(ucs.getName());
518
519       if (ucs.getLowerCaseColours() != null)
520       {
521         caseSensitive.setSelected(true);
522         lcaseColour.setEnabled(true);
523         resetButtonPanel(true);
524         for (int i = 0; i < lowerCaseButtons.size(); i++)
525         {
526           JButton button = (JButton) lowerCaseButtons.elementAt(i);
527           button.setBackground(ucs.getLowerCaseColours()[i]);
528         }
529
530       }
531       else
532       {
533         caseSensitive.setSelected(false);
534         lcaseColour.setEnabled(false);
535         resetButtonPanel(false);
536       }
537
538       for (int i = 0; i < upperCaseButtons.size(); i++)
539       {
540         JButton button = (JButton) upperCaseButtons.elementAt(i);
541         button.setBackground(colors[i]);
542       }
543
544     }
545   }
546
547   /**
548    * DOCUMENT ME!
549    * 
550    * @return DOCUMENT ME!
551    */
552   public static UserColourScheme loadDefaultColours()
553   {
554     UserColourScheme ret = null;
555
556     String colours = jalview.bin.Cache.getProperty("USER_DEFINED_COLOURS");
557     if (colours != null)
558     {
559       if (colours.indexOf("|") > -1)
560       {
561         colours = colours.substring(0, colours.indexOf("|"));
562       }
563
564       ret = loadColours(colours);
565     }
566
567     if (ret == null)
568     {
569       Color[] newColours = new Color[24];
570       for (int i = 0; i < 24; i++)
571       {
572         newColours[i] = Color.white;
573       }
574       ret = new UserColourScheme(newColours);
575     }
576
577     return ret;
578   }
579
580   /**
581    * DOCUMENT ME!
582    * 
583    * @param file
584    *                DOCUMENT ME!
585    * 
586    * @return DOCUMENT ME!
587    */
588   static UserColourScheme loadColours(String file)
589   {
590     UserColourScheme ucs = null;
591     Color[] newColours = null;
592     try
593     {
594       InputStreamReader in = new InputStreamReader(
595               new FileInputStream(file), "UTF-8");
596
597       jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours();
598
599       org.exolab.castor.xml.Unmarshaller unmar = new org.exolab.castor.xml.Unmarshaller(
600               jucs);
601       jucs = (jalview.schemabinding.version2.JalviewUserColours) unmar
602               .unmarshal(in);
603
604       newColours = new Color[24];
605
606       Color[] lowerCase = null;
607       boolean caseSensitive = false;
608
609       String name;
610       int index;
611       for (int i = 0; i < jucs.getColourCount(); i++)
612       {
613         name = jucs.getColour(i).getName();
614         if (ResidueProperties.aa3Hash.containsKey(name))
615         {
616           index = ((Integer) ResidueProperties.aa3Hash.get(name))
617                   .intValue();
618         }
619         else
620         {
621           index = ResidueProperties.aaIndex[name.charAt(0)];
622         }
623         if (index == -1)
624         {
625           continue;
626         }
627
628         if (name.toLowerCase().equals(name))
629         {
630           if (lowerCase == null)
631           {
632             lowerCase = new Color[23];
633           }
634           caseSensitive = true;
635           lowerCase[index] = new Color(Integer.parseInt(jucs.getColour(i)
636                   .getRGB(), 16));
637         }
638         else
639         {
640           newColours[index] = new Color(Integer.parseInt(jucs.getColour(i)
641                   .getRGB(), 16));
642         }
643       }
644
645       if (newColours != null)
646       {
647         ucs = new UserColourScheme(newColours);
648         ucs.setName(jucs.getSchemeName());
649         if (caseSensitive)
650         {
651           ucs.setLowerCaseColours(lowerCase);
652         }
653       }
654
655     } catch (Exception ex)
656     {
657       // Could be Archive Jalview format
658       try
659       {
660         InputStreamReader in = new InputStreamReader(new FileInputStream(
661                 file), "UTF-8");
662
663         jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours();
664
665         jucs = (jalview.binding.JalviewUserColours) jucs.unmarshal(in);
666
667         newColours = new Color[jucs.getColourCount()];
668
669         for (int i = 0; i < 24; i++)
670         {
671           newColours[i] = new Color(Integer.parseInt(jucs.getColour(i)
672                   .getRGB(), 16));
673         }
674         if (newColours != null)
675         {
676           ucs = new UserColourScheme(newColours);
677           ucs.setName(jucs.getSchemeName());
678         }
679       } catch (Exception ex2)
680       {
681         ex2.printStackTrace();
682       }
683
684       if (newColours == null)
685       {
686         System.out.println("Error loading User ColourFile\n" + ex);
687       }
688     }
689
690     return ucs;
691   }
692
693   /**
694    * DOCUMENT ME!
695    * 
696    * @param e
697    *                DOCUMENT ME!
698    */
699   protected void savebutton_actionPerformed(ActionEvent e)
700   {
701     if (schemeName.getText().trim().length() < 1)
702     {
703       JOptionPane.showInternalMessageDialog(Desktop.desktop,
704               "User colour scheme must have a name!",
705               "No name for colour scheme", JOptionPane.WARNING_MESSAGE);
706       return;
707     }
708
709     if (userColourSchemes != null
710             && userColourSchemes.containsKey(schemeName.getText()))
711     {
712       int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
713               "Colour scheme " + schemeName.getText() + " exists."
714                       + "\nContinue saving colour scheme as "
715                       + schemeName.getText() + "?",
716               "Duplicate scheme name", JOptionPane.YES_NO_OPTION);
717       if (reply != JOptionPane.YES_OPTION)
718       {
719         return;
720       }
721
722       userColourSchemes.remove(schemeName.getText());
723     }
724     JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
725             .getProperty("LAST_DIRECTORY"), new String[]
726     { "jc" }, new String[]
727     { "Jalview User Colours" }, "Jalview User Colours");
728
729     chooser.setFileView(new jalview.io.JalviewFileView());
730     chooser.setDialogTitle("Save colour scheme");
731     chooser.setToolTipText("Save");
732
733     int value = chooser.showSaveDialog(this);
734
735     if (value == JalviewFileChooser.APPROVE_OPTION)
736     {
737       String choice = chooser.getSelectedFile().getPath();
738       String defaultColours = jalview.bin.Cache.getDefault(
739               "USER_DEFINED_COLOURS", choice);
740       if (defaultColours.indexOf(choice) == -1)
741       {
742         if (defaultColours.length() > 0)
743         {
744           defaultColours = defaultColours.concat("|");
745         }
746         defaultColours = defaultColours.concat(choice);
747       }
748
749       userColourSchemes.put(schemeName.getText(), getSchemeFromButtons());
750
751       ap.alignFrame.updateUserColourMenu();
752
753       jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", defaultColours);
754
755       jalview.schemabinding.version2.JalviewUserColours ucs = new jalview.schemabinding.version2.JalviewUserColours();
756
757       ucs.setSchemeName(schemeName.getText());
758       try
759       {
760         PrintWriter out = new PrintWriter(new OutputStreamWriter(
761                 new FileOutputStream(choice), "UTF-8"));
762
763         for (int i = 0; i < buttonPanel.getComponentCount(); i++)
764         {
765           JButton button = (JButton) buttonPanel.getComponent(i);
766           jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
767           col.setName(button.getText());
768           col.setRGB(jalview.util.Format.getHexString(button
769                   .getBackground()));
770           ucs.addColour(col);
771         }
772
773         ucs.marshal(out);
774         out.close();
775       } catch (Exception ex)
776       {
777         ex.printStackTrace();
778       }
779     }
780   }
781
782   /**
783    * DOCUMENT ME!
784    * 
785    * @param e
786    *                DOCUMENT ME!
787    */
788   protected void cancelButton_actionPerformed(ActionEvent e)
789   {
790     if (ap != null)
791     {
792       if (seqGroup != null)
793       {
794         seqGroup.cs = oldColourScheme;
795       }
796       else if (ap != null)
797       {
798         ap.av.setGlobalColourScheme(oldColourScheme);
799       }
800       ap.paintAlignment(true);
801     }
802
803     if (jmol != null)
804     {
805       jmol.setJalviewColourScheme(oldColourScheme);
806     }
807
808     try
809     {
810       frame.setClosed(true);
811     } catch (Exception ex)
812     {
813     }
814   }
815
816   static Hashtable userColourSchemes;
817
818   public static Hashtable getUserColourSchemes()
819   {
820     return userColourSchemes;
821   }
822
823   public static void initUserColourSchemes(String files)
824   {
825     userColourSchemes = new Hashtable();
826
827     if (files == null || files.length() == 0)
828     {
829       return;
830     }
831
832     // In case colours can't be loaded, we'll remove them
833     // from the default list here.
834     StringBuffer coloursFound = new StringBuffer();
835     StringTokenizer st = new StringTokenizer(files, "|");
836     while (st.hasMoreElements())
837     {
838       String file = st.nextToken();
839       try
840       {
841         UserColourScheme ucs = loadColours(file);
842         if (ucs != null)
843         {
844           if (coloursFound.length() > 0)
845           {
846             coloursFound.append("|");
847           }
848           coloursFound.append(file);
849           userColourSchemes.put(ucs.getName(), ucs);
850         }
851       } catch (Exception ex)
852       {
853         System.out.println("Error loading User ColourFile\n" + ex);
854       }
855     }
856     if (!files.equals(coloursFound.toString()))
857     {
858       if (coloursFound.toString().length() > 1)
859       {
860         jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", coloursFound
861                 .toString());
862       }
863       else
864       {
865         jalview.bin.Cache.applicationProperties
866                 .remove("USER_DEFINED_COLOURS");
867       }
868     }
869   }
870
871   public static void removeColourFromDefaults(String target)
872   {
873     // The only way to find colours by name is to load them in
874     // In case colours can't be loaded, we'll remove them
875     // from the default list here.
876
877     userColourSchemes = new Hashtable();
878
879     StringBuffer coloursFound = new StringBuffer();
880     StringTokenizer st = new StringTokenizer(jalview.bin.Cache
881             .getProperty("USER_DEFINED_COLOURS"), "|");
882
883     while (st.hasMoreElements())
884     {
885       String file = st.nextToken();
886       try
887       {
888         UserColourScheme ucs = loadColours(file);
889         if (ucs != null && !ucs.getName().equals(target))
890         {
891           if (coloursFound.length() > 0)
892           {
893             coloursFound.append("|");
894           }
895           coloursFound.append(file);
896           userColourSchemes.put(ucs.getName(), ucs);
897         }
898       } catch (Exception ex)
899       {
900         System.out.println("Error loading User ColourFile\n" + ex);
901       }
902     }
903
904     if (coloursFound.toString().length() > 1)
905     {
906       jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", coloursFound
907               .toString());
908     }
909     else
910     {
911       jalview.bin.Cache.applicationProperties
912               .remove("USER_DEFINED_COLOURS");
913     }
914
915   }
916
917   public void caseSensitive_actionPerformed(ActionEvent e)
918   {
919     resetButtonPanel(caseSensitive.isSelected());
920     lcaseColour.setEnabled(caseSensitive.isSelected());
921   }
922
923   public void lcaseColour_actionPerformed(ActionEvent e)
924   {
925     if (selectedButtons == null)
926     {
927       selectedButtons = new Vector();
928     }
929     else
930     {
931       selectedButtons.clear();
932     }
933     selectedButtons.add(lcaseColour);
934   }
935
936 }