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