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