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