Jalview 2.6 source licence
[jalview.git] / src / jalview / gui / UserDefinedColours.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3  * Copyright (C) 2010 J Procter, AM Waterhouse, 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
301                   .setForeground(button.getBackground().brighter()
302                           .brighter());
303           selectedButtons.add(button);
304         }
305       }
306     }
307     else if (!e.isControlDown())
308     {
309       for (int b = 0; b < selectedButtons.size(); b++)
310       {
311         JButton button = (JButton) selectedButtons.elementAt(b);
312         button.setForeground(button.getBackground().darker().darker());
313       }
314       selectedButtons.clear();
315       pressed.setForeground(pressed.getBackground().brighter().brighter());
316       selectedButtons.addElement(pressed);
317
318     }
319     else if (e.isControlDown())
320     {
321       if (selectedButtons.contains(pressed))
322       {
323         pressed.setForeground(pressed.getBackground().darker().darker());
324         selectedButtons.remove(pressed);
325       }
326       else
327       {
328         pressed
329                 .setForeground(pressed.getBackground().brighter()
330                         .brighter());
331         selectedButtons.addElement(pressed);
332       }
333     }
334
335     if (selectedButtons.size() > 0)
336     {
337       colorChooser.setColor(((JButton) selectedButtons.elementAt(0))
338               .getBackground());
339     }
340   }
341
342   /**
343    * DOCUMENT ME!
344    * 
345    * @param label
346    *          DOCUMENT ME!
347    * @param aa
348    *          DOCUMENT ME!
349    */
350   JButton makeButton(String label, String aa, Vector caseSensitiveButtons,
351           int buttonIndex)
352   {
353     final JButton button;
354     Color col;
355
356     if (buttonIndex < caseSensitiveButtons.size())
357     {
358       button = (JButton) caseSensitiveButtons.elementAt(buttonIndex);
359       col = button.getBackground();
360     }
361     else
362     {
363       button = new JButton();
364       button.addMouseListener(new java.awt.event.MouseAdapter()
365       {
366         public void mouseClicked(MouseEvent e)
367         {
368           colourButtonPressed(e);
369         }
370       });
371
372       caseSensitiveButtons.addElement(button);
373
374       col = Color.white;
375       if (oldColourScheme != null)
376       {
377         try
378         {
379           col = oldColourScheme.findColour(aa.charAt(0), -1);
380         } catch (Exception ex)
381         {
382         }
383       }
384     }
385
386     if (caseSensitive.isSelected())
387     {
388       button.setMargin(new java.awt.Insets(2, 2, 2, 2));
389     }
390     else
391     {
392       button.setMargin(new java.awt.Insets(2, 14, 2, 14));
393     }
394
395     button.setBackground(col);
396     button.setText(label);
397     button.setForeground(col.darker().darker().darker());
398     button.setFont(new java.awt.Font("Verdana", Font.BOLD, 10));
399
400     return button;
401   }
402
403   /**
404    * DOCUMENT ME!
405    * 
406    * @param e
407    *          DOCUMENT ME!
408    */
409   protected void okButton_actionPerformed(ActionEvent e)
410   {
411     applyButton_actionPerformed(null);
412
413     try
414     {
415       frame.setClosed(true);
416     } catch (Exception ex)
417     {
418     }
419   }
420
421   /**
422    * DOCUMENT ME!
423    * 
424    * @param e
425    *          DOCUMENT ME!
426    */
427   protected void applyButton_actionPerformed(ActionEvent e)
428   {
429     UserColourScheme ucs = getSchemeFromButtons();
430     ucs.setName(schemeName.getText());
431
432     if (seqGroup != null)
433     {
434       seqGroup.cs = ucs;
435       ap.paintAlignment(true);
436     }
437     else if (ap != null)
438     {
439       ap.alignFrame.changeColour(ucs);
440     }
441     else if (jmol != null)
442     {
443       jmol.setJalviewColourScheme(ucs);
444     }
445   }
446
447   UserColourScheme getSchemeFromButtons()
448   {
449
450     Color[] newColours = new Color[24];
451
452     for (int i = 0; i < 24; i++)
453     {
454       JButton button = (JButton) upperCaseButtons.elementAt(i);
455       newColours[i] = button.getBackground();
456     }
457
458     UserColourScheme ucs = new UserColourScheme(newColours);
459
460     if (caseSensitive.isSelected())
461     {
462       newColours = new Color[23];
463       for (int i = 0; i < 23; i++)
464       {
465         JButton button = (JButton) lowerCaseButtons.elementAt(i);
466         newColours[i] = button.getBackground();
467       }
468       ucs.setLowerCaseColours(newColours);
469     }
470
471     if (ap != null)
472     {
473       ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
474     }
475
476     return ucs;
477   }
478
479   /**
480    * DOCUMENT ME!
481    * 
482    * @param e
483    *          DOCUMENT ME!
484    */
485   protected void loadbutton_actionPerformed(ActionEvent e)
486   {
487     upperCaseButtons = new Vector();
488     lowerCaseButtons = new Vector();
489
490     JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
491             .getProperty("LAST_DIRECTORY"), new String[]
492     { "jc" }, new String[]
493     { "Jalview User Colours" }, "Jalview User Colours");
494     chooser.setFileView(new jalview.io.JalviewFileView());
495     chooser.setDialogTitle("Load colour scheme");
496     chooser.setToolTipText("Load");
497
498     int value = chooser.showOpenDialog(this);
499
500     if (value == JalviewFileChooser.APPROVE_OPTION)
501     {
502       File choice = chooser.getSelectedFile();
503       jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
504       String defaultColours = jalview.bin.Cache.getDefault(
505               "USER_DEFINED_COLOURS", choice.getPath());
506       if (defaultColours.indexOf(choice.getPath()) == -1)
507       {
508         defaultColours = defaultColours.concat("|")
509                 .concat(choice.getPath());
510       }
511
512       jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", defaultColours);
513
514       UserColourScheme ucs = loadColours(choice.getAbsolutePath());
515       Color[] colors = ucs.getColours();
516       schemeName.setText(ucs.getName());
517
518       if (ucs.getLowerCaseColours() != null)
519       {
520         caseSensitive.setSelected(true);
521         lcaseColour.setEnabled(true);
522         resetButtonPanel(true);
523         for (int i = 0; i < lowerCaseButtons.size(); i++)
524         {
525           JButton button = (JButton) lowerCaseButtons.elementAt(i);
526           button.setBackground(ucs.getLowerCaseColours()[i]);
527         }
528
529       }
530       else
531       {
532         caseSensitive.setSelected(false);
533         lcaseColour.setEnabled(false);
534         resetButtonPanel(false);
535       }
536
537       for (int i = 0; i < upperCaseButtons.size(); i++)
538       {
539         JButton button = (JButton) upperCaseButtons.elementAt(i);
540         button.setBackground(colors[i]);
541       }
542
543     }
544   }
545
546   /**
547    * DOCUMENT ME!
548    * 
549    * @return DOCUMENT ME!
550    */
551   public static UserColourScheme loadDefaultColours()
552   {
553     UserColourScheme ret = null;
554
555     String colours = jalview.bin.Cache.getProperty("USER_DEFINED_COLOURS");
556     if (colours != null)
557     {
558       if (colours.indexOf("|") > -1)
559       {
560         colours = colours.substring(0, colours.indexOf("|"));
561       }
562
563       ret = loadColours(colours);
564     }
565
566     if (ret == null)
567     {
568       Color[] newColours = new Color[24];
569       for (int i = 0; i < 24; i++)
570       {
571         newColours[i] = Color.white;
572       }
573       ret = new UserColourScheme(newColours);
574     }
575
576     return ret;
577   }
578
579   /**
580    * DOCUMENT ME!
581    * 
582    * @param file
583    *          DOCUMENT ME!
584    * 
585    * @return DOCUMENT ME!
586    */
587   static UserColourScheme loadColours(String file)
588   {
589     UserColourScheme ucs = null;
590     Color[] newColours = null;
591     try
592     {
593       InputStreamReader in = new InputStreamReader(
594               new FileInputStream(file), "UTF-8");
595
596       jalview.schemabinding.version2.JalviewUserColours jucs = new jalview.schemabinding.version2.JalviewUserColours();
597
598       org.exolab.castor.xml.Unmarshaller unmar = new org.exolab.castor.xml.Unmarshaller(
599               jucs);
600       jucs = (jalview.schemabinding.version2.JalviewUserColours) unmar
601               .unmarshal(in);
602
603       newColours = new Color[24];
604
605       Color[] lowerCase = null;
606       boolean caseSensitive = false;
607
608       String name;
609       int index;
610       for (int i = 0; i < jucs.getColourCount(); i++)
611       {
612         name = jucs.getColour(i).getName();
613         if (ResidueProperties.aa3Hash.containsKey(name))
614         {
615           index = ((Integer) ResidueProperties.aa3Hash.get(name))
616                   .intValue();
617         }
618         else
619         {
620           index = ResidueProperties.aaIndex[name.charAt(0)];
621         }
622         if (index == -1)
623         {
624           continue;
625         }
626
627         if (name.toLowerCase().equals(name))
628         {
629           if (lowerCase == null)
630           {
631             lowerCase = new Color[23];
632           }
633           caseSensitive = true;
634           lowerCase[index] = new Color(Integer.parseInt(jucs.getColour(i)
635                   .getRGB(), 16));
636         }
637         else
638         {
639           newColours[index] = new Color(Integer.parseInt(jucs.getColour(i)
640                   .getRGB(), 16));
641         }
642       }
643
644       if (newColours != null)
645       {
646         ucs = new UserColourScheme(newColours);
647         ucs.setName(jucs.getSchemeName());
648         if (caseSensitive)
649         {
650           ucs.setLowerCaseColours(lowerCase);
651         }
652       }
653
654     } catch (Exception ex)
655     {
656       // Could be Archive Jalview format
657       try
658       {
659         InputStreamReader in = new InputStreamReader(new FileInputStream(
660                 file), "UTF-8");
661
662         jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours();
663
664         jucs = (jalview.binding.JalviewUserColours) jucs.unmarshal(in);
665
666         newColours = new Color[jucs.getColourCount()];
667
668         for (int i = 0; i < 24; i++)
669         {
670           newColours[i] = new Color(Integer.parseInt(jucs.getColour(i)
671                   .getRGB(), 16));
672         }
673         if (newColours != null)
674         {
675           ucs = new UserColourScheme(newColours);
676           ucs.setName(jucs.getSchemeName());
677         }
678       } catch (Exception ex2)
679       {
680         ex2.printStackTrace();
681       }
682
683       if (newColours == null)
684       {
685         System.out.println("Error loading User ColourFile\n" + ex);
686       }
687     }
688
689     return ucs;
690   }
691
692   /**
693    * DOCUMENT ME!
694    * 
695    * @param e
696    *          DOCUMENT ME!
697    */
698   protected void savebutton_actionPerformed(ActionEvent e)
699   {
700     if (schemeName.getText().trim().length() < 1)
701     {
702       JOptionPane.showInternalMessageDialog(Desktop.desktop,
703               "User colour scheme must have a name!",
704               "No name for colour scheme", JOptionPane.WARNING_MESSAGE);
705       return;
706     }
707
708     if (userColourSchemes != null
709             && userColourSchemes.containsKey(schemeName.getText()))
710     {
711       int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
712               "Colour scheme " + schemeName.getText() + " exists."
713                       + "\nContinue saving colour scheme as "
714                       + schemeName.getText() + "?",
715               "Duplicate scheme name", JOptionPane.YES_NO_OPTION);
716       if (reply != JOptionPane.YES_OPTION)
717       {
718         return;
719       }
720
721       userColourSchemes.remove(schemeName.getText());
722     }
723     JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
724             .getProperty("LAST_DIRECTORY"), new String[]
725     { "jc" }, new String[]
726     { "Jalview User Colours" }, "Jalview User Colours");
727
728     chooser.setFileView(new jalview.io.JalviewFileView());
729     chooser.setDialogTitle("Save colour scheme");
730     chooser.setToolTipText("Save");
731
732     int value = chooser.showSaveDialog(this);
733
734     if (value == JalviewFileChooser.APPROVE_OPTION)
735     {
736       String choice = chooser.getSelectedFile().getPath();
737       String defaultColours = jalview.bin.Cache.getDefault(
738               "USER_DEFINED_COLOURS", choice);
739       if (defaultColours.indexOf(choice) == -1)
740       {
741         if (defaultColours.length() > 0)
742         {
743           defaultColours = defaultColours.concat("|");
744         }
745         defaultColours = defaultColours.concat(choice);
746       }
747
748       userColourSchemes.put(schemeName.getText(), getSchemeFromButtons());
749
750       ap.alignFrame.updateUserColourMenu();
751
752       jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", defaultColours);
753
754       jalview.schemabinding.version2.JalviewUserColours ucs = new jalview.schemabinding.version2.JalviewUserColours();
755
756       ucs.setSchemeName(schemeName.getText());
757       try
758       {
759         PrintWriter out = new PrintWriter(new OutputStreamWriter(
760                 new FileOutputStream(choice), "UTF-8"));
761
762         for (int i = 0; i < buttonPanel.getComponentCount(); i++)
763         {
764           JButton button = (JButton) buttonPanel.getComponent(i);
765           jalview.schemabinding.version2.Colour col = new jalview.schemabinding.version2.Colour();
766           col.setName(button.getText());
767           col.setRGB(jalview.util.Format.getHexString(button
768                   .getBackground()));
769           ucs.addColour(col);
770         }
771
772         ucs.marshal(out);
773         out.close();
774       } catch (Exception ex)
775       {
776         ex.printStackTrace();
777       }
778     }
779   }
780
781   /**
782    * DOCUMENT ME!
783    * 
784    * @param e
785    *          DOCUMENT ME!
786    */
787   protected void cancelButton_actionPerformed(ActionEvent e)
788   {
789     if (ap != null)
790     {
791       if (seqGroup != null)
792       {
793         seqGroup.cs = oldColourScheme;
794       }
795       else if (ap != null)
796       {
797         ap.av.setGlobalColourScheme(oldColourScheme);
798       }
799       ap.paintAlignment(true);
800     }
801
802     if (jmol != null)
803     {
804       jmol.setJalviewColourScheme(oldColourScheme);
805     }
806
807     try
808     {
809       frame.setClosed(true);
810     } catch (Exception ex)
811     {
812     }
813   }
814
815   static Hashtable userColourSchemes;
816
817   public static Hashtable getUserColourSchemes()
818   {
819     return userColourSchemes;
820   }
821
822   public static void initUserColourSchemes(String files)
823   {
824     userColourSchemes = new Hashtable();
825
826     if (files == null || files.length() == 0)
827     {
828       return;
829     }
830
831     // In case colours can't be loaded, we'll remove them
832     // from the default list here.
833     StringBuffer coloursFound = new StringBuffer();
834     StringTokenizer st = new StringTokenizer(files, "|");
835     while (st.hasMoreElements())
836     {
837       String file = st.nextToken();
838       try
839       {
840         UserColourScheme ucs = loadColours(file);
841         if (ucs != null)
842         {
843           if (coloursFound.length() > 0)
844           {
845             coloursFound.append("|");
846           }
847           coloursFound.append(file);
848           userColourSchemes.put(ucs.getName(), ucs);
849         }
850       } catch (Exception ex)
851       {
852         System.out.println("Error loading User ColourFile\n" + ex);
853       }
854     }
855     if (!files.equals(coloursFound.toString()))
856     {
857       if (coloursFound.toString().length() > 1)
858       {
859         jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", coloursFound
860                 .toString());
861       }
862       else
863       {
864         jalview.bin.Cache.applicationProperties
865                 .remove("USER_DEFINED_COLOURS");
866       }
867     }
868   }
869
870   public static void removeColourFromDefaults(String target)
871   {
872     // The only way to find colours by name is to load them in
873     // In case colours can't be loaded, we'll remove them
874     // from the default list here.
875
876     userColourSchemes = new Hashtable();
877
878     StringBuffer coloursFound = new StringBuffer();
879     StringTokenizer st = new StringTokenizer(jalview.bin.Cache
880             .getProperty("USER_DEFINED_COLOURS"), "|");
881
882     while (st.hasMoreElements())
883     {
884       String file = st.nextToken();
885       try
886       {
887         UserColourScheme ucs = loadColours(file);
888         if (ucs != null && !ucs.getName().equals(target))
889         {
890           if (coloursFound.length() > 0)
891           {
892             coloursFound.append("|");
893           }
894           coloursFound.append(file);
895           userColourSchemes.put(ucs.getName(), ucs);
896         }
897       } catch (Exception ex)
898       {
899         System.out.println("Error loading User ColourFile\n" + ex);
900       }
901     }
902
903     if (coloursFound.toString().length() > 1)
904     {
905       jalview.bin.Cache.setProperty("USER_DEFINED_COLOURS", coloursFound
906               .toString());
907     }
908     else
909     {
910       jalview.bin.Cache.applicationProperties
911               .remove("USER_DEFINED_COLOURS");
912     }
913
914   }
915
916   public void caseSensitive_actionPerformed(ActionEvent e)
917   {
918     resetButtonPanel(caseSensitive.isSelected());
919     lcaseColour.setEnabled(caseSensitive.isSelected());
920   }
921
922   public void lcaseColour_actionPerformed(ActionEvent e)
923   {
924     if (selectedButtons == null)
925     {
926       selectedButtons = new Vector();
927     }
928     else
929     {
930       selectedButtons.clear();
931     }
932     selectedButtons.add(lcaseColour);
933   }
934
935 }