JAL-2630 first pass groovy colour scheme (with slight refactoring)
[jalview.git] / src / jalview / gui / UserDefinedColours.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.gui;
22
23 import jalview.api.structures.JalviewStructureDisplayI;
24 import jalview.bin.Cache;
25 import jalview.datamodel.SequenceGroup;
26 import jalview.io.JalviewFileChooser;
27 import jalview.io.JalviewFileView;
28 import jalview.jbgui.GUserDefinedColours;
29 import jalview.schemabinding.version2.Colour;
30 import jalview.schemabinding.version2.JalviewUserColours;
31 import jalview.schemes.ColourSchemeI;
32 import jalview.schemes.ColourSchemes;
33 import jalview.schemes.ResidueProperties;
34 import jalview.schemes.UserColourScheme;
35 import jalview.util.ColorUtils;
36 import jalview.util.Format;
37 import jalview.util.MessageManager;
38
39 import java.awt.Color;
40 import java.awt.Font;
41 import java.awt.Insets;
42 import java.awt.event.ActionEvent;
43 import java.awt.event.MouseAdapter;
44 import java.awt.event.MouseEvent;
45 import java.io.File;
46 import java.io.FileOutputStream;
47 import java.io.OutputStreamWriter;
48 import java.io.PrintWriter;
49 import java.util.ArrayList;
50 import java.util.List;
51
52 import javax.swing.JButton;
53 import javax.swing.JInternalFrame;
54 import javax.swing.event.ChangeEvent;
55 import javax.swing.event.ChangeListener;
56
57 /**
58  * This panel allows the user to assign colours to Amino Acid residue codes, and
59  * save the colour scheme.
60  * 
61  * @author Andrew Waterhouse
62  * @author Mungo Carstairs
63  */
64 public class UserDefinedColours extends GUserDefinedColours implements
65         ChangeListener
66 {
67   private static final Font VERDANA_BOLD_10 = new Font("Verdana", Font.BOLD, 10);
68
69   public static final String USER_DEFINED_COLOURS = "USER_DEFINED_COLOURS";
70
71   private static final String LAST_DIRECTORY = "LAST_DIRECTORY";
72
73   private static final int MY_FRAME_HEIGHT = 420;
74
75   private static final int MY_FRAME_WIDTH = 810;
76
77   private static final int MY_FRAME_WIDTH_CASE_SENSITIVE = 970;
78
79   AlignmentPanel ap;
80
81   SequenceGroup seqGroup;
82
83   List<JButton> selectedButtons;
84
85   ColourSchemeI oldColourScheme;
86
87   JInternalFrame frame;
88
89   JalviewStructureDisplayI structureViewer;
90
91   List<JButton> upperCaseButtons;
92
93   List<JButton> lowerCaseButtons;
94
95   /**
96    * Creates a new UserDefinedColours object.
97    * 
98    * @param ap
99    * @param sg
100    */
101   public UserDefinedColours(AlignmentPanel ap, SequenceGroup sg)
102   {
103     super();
104
105     lcaseColour.setEnabled(false);
106
107     this.ap = ap;
108     seqGroup = sg;
109
110     if (seqGroup != null)
111     {
112       oldColourScheme = seqGroup.cs;
113     }
114     else
115     {
116       oldColourScheme = ap.av.getGlobalColourScheme();
117     }
118
119     if (oldColourScheme instanceof UserColourScheme)
120     {
121       schemeName.setText(oldColourScheme.getSchemeName());
122       if (((UserColourScheme) oldColourScheme).getLowerCaseColours() != null)
123       {
124         caseSensitive.setSelected(true);
125         lcaseColour.setEnabled(true);
126         resetButtonPanel(true);
127       }
128       else
129       {
130         resetButtonPanel(false);
131       }
132     }
133     else
134     {
135       resetButtonPanel(false);
136     }
137
138     showFrame();
139   }
140
141   public UserDefinedColours(JalviewStructureDisplayI viewer,
142           ColourSchemeI oldcs)
143   {
144     super();
145     this.structureViewer = viewer;
146
147     colorChooser.getSelectionModel().addChangeListener(this);
148
149     oldColourScheme = oldcs;
150
151     if (oldColourScheme instanceof UserColourScheme)
152     {
153       schemeName.setText(((UserColourScheme) oldColourScheme).getSchemeName());
154     }
155
156     resetButtonPanel(false);
157
158     showFrame();
159
160   }
161
162   void showFrame()
163   {
164     colorChooser.getSelectionModel().addChangeListener(this);
165     frame = new JInternalFrame();
166     frame.setContentPane(this);
167     Desktop.addInternalFrame(frame,
168             MessageManager.getString("label.user_defined_colours"),
169             MY_FRAME_WIDTH, MY_FRAME_HEIGHT, true);
170
171     if (seqGroup != null)
172     {
173       frame.setTitle(frame.getTitle() + " (" + seqGroup.getName() + ")");
174     }
175   }
176
177   /**
178    * Rebuilds the panel with coloured buttons for residues. If not case
179    * sensitive colours, show 3-letter amino acid code as button text. If case
180    * sensitive, just show the single letter code, in order to make space for the
181    * additional buttons.
182    * 
183    * @param isCaseSensitive
184    */
185   void resetButtonPanel(boolean isCaseSensitive)
186   {
187     buttonPanel.removeAll();
188
189     if (upperCaseButtons == null)
190     {
191       upperCaseButtons = new ArrayList<JButton>();
192     }
193
194     for (int i = 0; i < 20; i++)
195     {
196       String label = isCaseSensitive ? ResidueProperties.aa[i]
197               : ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i])
198                       .toString();
199       JButton button = makeButton(label, ResidueProperties.aa[i],
200               upperCaseButtons, i);
201       buttonPanel.add(button);
202     }
203
204     buttonPanel.add(makeButton("B", "B", upperCaseButtons, 20));
205     buttonPanel.add(makeButton("Z", "Z", upperCaseButtons, 21));
206     buttonPanel.add(makeButton("X", "X", upperCaseButtons, 22));
207     buttonPanel.add(makeButton("Gap", "-", upperCaseButtons, 23));
208
209     if (!isCaseSensitive)
210     {
211       gridLayout.setRows(6);
212       gridLayout.setColumns(4);
213     }
214     else
215     {
216       gridLayout.setRows(7);
217       int cols = 7;
218       gridLayout.setColumns(cols + 1);
219
220       if (lowerCaseButtons == null)
221       {
222         lowerCaseButtons = new ArrayList<JButton>();
223       }
224
225       for (int i = 0; i < 20; i++)
226       {
227         int row = i / cols + 1;
228         int index = (row * cols) + i;
229         JButton button = makeButton(ResidueProperties.aa[i].toLowerCase(),
230                 ResidueProperties.aa[i].toLowerCase(), lowerCaseButtons, i);
231
232         buttonPanel.add(button, index);
233       }
234     }
235
236     if (isCaseSensitive)
237     {
238       buttonPanel.add(makeButton("b", "b", lowerCaseButtons, 20));
239       buttonPanel.add(makeButton("z", "z", lowerCaseButtons, 21));
240       buttonPanel.add(makeButton("x", "x", lowerCaseButtons, 22));
241     }
242
243     // JAL-1360 widen the frame dynamically to accommodate case-sensitive AA
244     // codes
245     if (this.frame != null)
246     {
247       int newWidth = isCaseSensitive ? MY_FRAME_WIDTH_CASE_SENSITIVE
248               : MY_FRAME_WIDTH;
249       this.frame.setSize(newWidth, this.frame.getHeight());
250     }
251
252     buttonPanel.validate();
253     validate();
254   }
255
256   /**
257    * DOCUMENT ME!
258    * 
259    * @param evt
260    *          DOCUMENT ME!
261    */
262   @Override
263   public void stateChanged(ChangeEvent evt)
264   {
265     if (selectedButtons != null)
266     {
267       JButton button = null;
268       final Color newColour = colorChooser.getColor();
269       for (int i = 0; i < selectedButtons.size(); i++)
270       {
271         button = selectedButtons.get(i);
272         button.setBackground(newColour);
273         button.setForeground(ColorUtils.brighterThan(newColour));
274       }
275       if (button == lcaseColour)
276       {
277         for (int i = 0; i < lowerCaseButtons.size(); i++)
278         {
279           button = lowerCaseButtons.get(i);
280           button.setBackground(newColour);
281           button.setForeground(ColorUtils.brighterThan(button
282                   .getBackground()));
283         }
284       }
285     }
286   }
287
288   /**
289    * Performs actions when a residue button is clicked. This manages the button
290    * selection set (highlighted by brighter foreground text).
291    * <p>
292    * On select button(s) with Ctrl/click or Shift/click: set button foreground
293    * text to brighter than background.
294    * <p>
295    * On unselect button(s) with Ctrl/click on selected, or click to release
296    * current selection: reset foreground text to darker than background.
297    * <p>
298    * Simple click: clear selection (resetting foreground to darker); set clicked
299    * button foreground to brighter
300    * <p>
301    * Finally, synchronize the colour chooser to the colour of the first button
302    * in the selected set.
303    * 
304    * @param e
305    */
306   public void colourButtonPressed(MouseEvent e)
307   {
308     if (selectedButtons == null)
309     {
310       selectedButtons = new ArrayList<JButton>();
311     }
312
313     JButton pressed = (JButton) e.getSource();
314
315     if (e.isShiftDown())
316     {
317       JButton start, end = (JButton) e.getSource();
318       if (selectedButtons.size() > 0)
319       {
320         start = selectedButtons.get(selectedButtons.size() - 1);
321       }
322       else
323       {
324         start = (JButton) e.getSource();
325       }
326
327       int startIndex = 0, endIndex = 0;
328       for (int b = 0; b < buttonPanel.getComponentCount(); b++)
329       {
330         if (buttonPanel.getComponent(b) == start)
331         {
332           startIndex = b;
333         }
334         if (buttonPanel.getComponent(b) == end)
335         {
336           endIndex = b;
337         }
338       }
339
340       if (startIndex > endIndex)
341       {
342         int temp = startIndex;
343         startIndex = endIndex;
344         endIndex = temp;
345       }
346
347       for (int b = startIndex; b <= endIndex; b++)
348       {
349         JButton button = (JButton) buttonPanel.getComponent(b);
350         if (!selectedButtons.contains(button))
351         {
352           button.setForeground(ColorUtils.brighterThan(button
353                   .getBackground()));
354           selectedButtons.add(button);
355         }
356       }
357     }
358     else if (!e.isControlDown())
359     {
360       for (int b = 0; b < selectedButtons.size(); b++)
361       {
362         JButton button = selectedButtons.get(b);
363         button.setForeground(ColorUtils.darkerThan(button.getBackground()));
364       }
365       selectedButtons.clear();
366       pressed.setForeground(ColorUtils.brighterThan(pressed.getBackground()));
367       selectedButtons.add(pressed);
368
369     }
370     else if (e.isControlDown())
371     {
372       if (selectedButtons.contains(pressed))
373       {
374         pressed.setForeground(ColorUtils.darkerThan(pressed.getBackground()));
375         selectedButtons.remove(pressed);
376       }
377       else
378       {
379         pressed.setForeground(ColorUtils.brighterThan(pressed
380                 .getBackground()));
381         selectedButtons.add(pressed);
382       }
383     }
384
385     if (selectedButtons.size() > 0)
386     {
387       colorChooser.setColor((selectedButtons.get(0)).getBackground());
388     }
389   }
390
391   /**
392    * A helper method to update or make a colour button, whose background colour
393    * is the associated colour, and text colour a darker shade of the same. If
394    * the button is already in the list, then its text and margins are updated,
395    * if not then it is created and added. This method supports toggling between
396    * case-sensitive and case-insensitive button panels. The case-sensitive
397    * version has abbreviated button text in order to fit in more buttons.
398    * 
399    * @param label
400    * @param residue
401    * @param the
402    *          list of buttons
403    * @param buttonIndex
404    *          the button's position in the list
405    */
406   JButton makeButton(String label, String residue,
407           List<JButton> buttons, int buttonIndex)
408   {
409     final JButton button;
410     Color col;
411
412     if (buttonIndex < buttons.size())
413     {
414       button = buttons.get(buttonIndex);
415       col = button.getBackground();
416     }
417     else
418     {
419       button = new JButton();
420       button.addMouseListener(new MouseAdapter()
421       {
422         @Override
423         public void mouseClicked(MouseEvent e)
424         {
425           colourButtonPressed(e);
426         }
427       });
428
429       buttons.add(button);
430
431       /*
432        * make initial button colour that of the current colour scheme,
433        * if it is a simple per-residue colouring, else white
434        */
435       col = Color.white;
436       if (oldColourScheme != null && oldColourScheme.isSimple())
437       {
438         col = oldColourScheme.findColour(residue.charAt(0));
439       }
440     }
441
442     if (caseSensitive.isSelected())
443     {
444       button.setMargin(new Insets(2, 2, 2, 2));
445     }
446     else
447     {
448       button.setMargin(new Insets(2, 14, 2, 14));
449     }
450
451     button.setOpaque(true); // required for the next line to have effect
452     button.setBackground(col);
453     button.setText(label);
454     button.setForeground(ColorUtils.darkerThan(col));
455     button.setFont(VERDANA_BOLD_10);
456
457     return button;
458   }
459
460   /**
461    * On 'OK', check that at least one colour has been assigned to a residue (and
462    * if not issue a warning), and apply the chosen colour scheme and close the
463    * panel.
464    */
465   @Override
466   protected void okButton_actionPerformed()
467   {
468     if (isNoSelectionMade())
469     {
470       JvOptionPane.showMessageDialog(Desktop.desktop, MessageManager
471               .getString("label.no_colour_selection_in_scheme"),
472               MessageManager.getString("label.no_colour_selection_warn"),
473               JvOptionPane.WARNING_MESSAGE);
474     }
475     else
476     {
477       applyButton_actionPerformed();
478
479       try
480       {
481         frame.setClosed(true);
482       } catch (Exception ex)
483       {
484       }
485     }
486   }
487
488   /**
489    * Returns true if the user has not made any colour selection (including if
490    * 'case-sensitive' selected and no lower-case colour chosen).
491    * 
492    * @return
493    */
494   protected boolean isNoSelectionMade()
495   {
496     final boolean noUpperCaseSelected = upperCaseButtons == null
497             || upperCaseButtons.isEmpty();
498     final boolean noLowerCaseSelected = caseSensitive.isSelected()
499             && (lowerCaseButtons == null || lowerCaseButtons.isEmpty());
500     final boolean noSelectionMade = noUpperCaseSelected
501             || noLowerCaseSelected;
502     return noSelectionMade;
503   }
504
505   /**
506    * Applies the current colour scheme to the alignment, sequence group or
507    * structure view.
508    */
509   @Override
510   protected void applyButton_actionPerformed()
511   {
512     if (isNoSelectionMade())
513     {
514       JvOptionPane.showMessageDialog(Desktop.desktop, MessageManager
515               .getString("label.no_colour_selection_in_scheme"),
516               MessageManager.getString("label.no_colour_selection_warn"),
517               JvOptionPane.WARNING_MESSAGE);
518
519     }
520     UserColourScheme ucs = getSchemeFromButtons();
521
522     if (seqGroup != null)
523     {
524       seqGroup.cs = ucs;
525       ap.paintAlignment(true);
526     }
527     else if (ap != null)
528     {
529       ap.alignFrame.changeColour(ucs);
530     }
531     else if (structureViewer != null)
532     {
533       structureViewer.setJalviewColourScheme(ucs);
534     }
535   }
536
537   UserColourScheme getSchemeFromButtons()
538   {
539
540     Color[] newColours = new Color[24];
541
542     int length = upperCaseButtons.size();
543     if (length < 24)
544     {
545       int i = 0;
546       for (JButton btn : upperCaseButtons)
547       {
548         newColours[i] = btn.getBackground();
549         i++;
550       }
551     }
552     else
553     {
554       for (int i = 0; i < 24; i++)
555       {
556         JButton button = upperCaseButtons.get(i);
557         newColours[i] = button.getBackground();
558       }
559     }
560
561     UserColourScheme ucs = new UserColourScheme(newColours);
562     ucs.setName(schemeName.getText());
563
564     if (caseSensitive.isSelected())
565     {
566       newColours = new Color[23];
567       length = lowerCaseButtons.size();
568       if (length < 23)
569       {
570         int i = 0;
571         for (JButton btn : lowerCaseButtons)
572         {
573           newColours[i] = btn.getBackground();
574           i++;
575         }
576       }
577       else
578       {
579         for (int i = 0; i < 23; i++)
580         {
581           JButton button = lowerCaseButtons.get(i);
582           newColours[i] = button.getBackground();
583         }
584       }
585       ucs.setLowerCaseColours(newColours);
586     }
587
588     if (ap != null)
589     {
590       ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
591     }
592
593     return ucs;
594   }
595
596   /**
597    * DOCUMENT ME!
598    * 
599    * @param e
600    *          DOCUMENT ME!
601    */
602   @Override
603   protected void loadbutton_actionPerformed(ActionEvent e)
604   {
605     upperCaseButtons = new ArrayList<JButton>();
606     lowerCaseButtons = new ArrayList<JButton>();
607
608     JalviewFileChooser chooser = new JalviewFileChooser(
609             Cache.getProperty(LAST_DIRECTORY), "jc", "Jalview User Colours");
610     chooser.setFileView(new JalviewFileView());
611     chooser.setDialogTitle(MessageManager
612             .getString("label.load_colour_scheme"));
613     chooser.setToolTipText(MessageManager.getString("action.load"));
614
615     int value = chooser.showOpenDialog(this);
616
617     if (value != JalviewFileChooser.APPROVE_OPTION)
618     {
619       return;
620     }
621     File choice = chooser.getSelectedFile();
622     Cache.setProperty(LAST_DIRECTORY, choice.getParent());
623
624     UserColourScheme ucs = ColourSchemes.loadColourScheme(choice.getAbsolutePath());
625     Color[] colors = ucs.getColours();
626     schemeName.setText(ucs.getSchemeName());
627
628     if (ucs.getLowerCaseColours() != null)
629     {
630       caseSensitive.setSelected(true);
631       lcaseColour.setEnabled(true);
632       resetButtonPanel(true);
633       for (int i = 0; i < lowerCaseButtons.size(); i++)
634       {
635         JButton button = lowerCaseButtons.get(i);
636         button.setBackground(ucs.getLowerCaseColours()[i]);
637       }
638     }
639     else
640     {
641       caseSensitive.setSelected(false);
642       lcaseColour.setEnabled(false);
643       resetButtonPanel(false);
644     }
645
646     for (int i = 0; i < upperCaseButtons.size(); i++)
647     {
648       JButton button = upperCaseButtons.get(i);
649       button.setBackground(colors[i]);
650     }
651
652     addNewColourScheme(choice.getPath());
653   }
654
655   /**
656    * Loads the user-defined colour scheme from the first file listed in property
657    * "USER_DEFINED_COLOURS". If this fails, returns an all-white colour scheme.
658    * 
659    * @return
660    */
661   public static UserColourScheme loadDefaultColours()
662   {
663     UserColourScheme ret = null;
664
665     String colours = Cache.getProperty(USER_DEFINED_COLOURS);
666     if (colours != null)
667     {
668       if (colours.indexOf("|") > -1)
669       {
670         colours = colours.substring(0, colours.indexOf("|"));
671       }
672       ret = ColourSchemes.loadColourScheme(colours);
673     }
674
675     if (ret == null)
676     {
677       ret = new UserColourScheme("white");
678     }
679
680     return ret;
681   }
682
683   /**
684    * DOCUMENT ME!
685    * 
686    * @param e
687    *          DOCUMENT ME!
688    */
689   @Override
690   protected void savebutton_actionPerformed(ActionEvent e)
691   {
692     String name = schemeName.getText().trim();
693     if (name.length() < 1)
694     {
695       JvOptionPane.showInternalMessageDialog(Desktop.desktop, MessageManager
696               .getString("label.user_colour_scheme_must_have_name"),
697               MessageManager.getString("label.no_name_colour_scheme"),
698               JvOptionPane.WARNING_MESSAGE);
699       return;
700     }
701
702     if (ColourSchemes.getInstance().nameExists(name))
703     {
704       int reply = JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
705               MessageManager.formatMessage(
706                       "label.colour_scheme_exists_overwrite", new Object[] {
707                           name, name }),
708               MessageManager.getString("label.duplicate_scheme_name"),
709               JvOptionPane.YES_NO_OPTION);
710       if (reply != JvOptionPane.YES_OPTION)
711       {
712         return;
713       }
714       ColourSchemes.getInstance().removeColourScheme(name);
715     }
716     JalviewFileChooser chooser = new JalviewFileChooser(
717             Cache.getProperty(LAST_DIRECTORY), "jc",
718             "Jalview User Colours");
719
720     JalviewFileView fileView = new JalviewFileView();
721     chooser.setFileView(fileView);
722     chooser.setDialogTitle(MessageManager
723             .getString("label.save_colour_scheme"));
724     chooser.setToolTipText(MessageManager.getString("action.save"));
725
726     int value = chooser.showSaveDialog(this);
727
728     if (value == JalviewFileChooser.APPROVE_OPTION)
729     {
730       File file = chooser.getSelectedFile();
731       addNewColourScheme(file.getPath());
732       saveToFile(file);
733     }
734   }
735
736   /**
737    * Adds the current colour scheme to the Jalview properties file so it is
738    * loaded on next startup, and updates the Colour menu in the parent
739    * AlignFrame (if there is one). Note this action does not including applying
740    * the colour scheme.
741    * 
742    * @param filePath
743    */
744   protected void addNewColourScheme(String filePath)
745   {
746     /*
747      * update the delimited list of user defined colour files in
748      * Jalview property USER_DEFINED_COLOURS
749      */
750     String defaultColours = Cache
751             .getDefault(USER_DEFINED_COLOURS, filePath);
752     if (defaultColours.indexOf(filePath) == -1)
753     {
754       if (defaultColours.length() > 0)
755       {
756         defaultColours = defaultColours.concat("|");
757       }
758       defaultColours = defaultColours.concat(filePath);
759     }
760     Cache.setProperty(USER_DEFINED_COLOURS, defaultColours);
761
762     /*
763      * construct and register the colour scheme
764      */
765     UserColourScheme ucs = getSchemeFromButtons();
766     ColourSchemes.getInstance().registerColourScheme(ucs);
767
768     /*
769      * update the Colour menu items
770      */
771     if (ap != null)
772     {
773       ap.alignFrame.buildColourMenu();
774     }
775   }
776
777   /**
778    * Saves the colour scheme to file in XML format
779    * 
780    * @param path
781    */
782   protected void saveToFile(File toFile)
783   {
784     /*
785      * build a Java model of colour scheme as XML, and 
786      * marshal to file
787      */
788     JalviewUserColours ucs = new JalviewUserColours();
789     ucs.setSchemeName(schemeName.getText());
790     try
791     {
792       PrintWriter out = new PrintWriter(new OutputStreamWriter(
793               new FileOutputStream(toFile), "UTF-8"));
794
795       for (int i = 0; i < buttonPanel.getComponentCount(); i++)
796       {
797         JButton button = (JButton) buttonPanel.getComponent(i);
798         Colour col = new Colour();
799         col.setName(button.getText());
800         col.setRGB(Format.getHexString(button.getBackground()));
801         ucs.addColour(col);
802       }
803       ucs.marshal(out);
804       out.close();
805     } catch (Exception ex)
806     {
807       ex.printStackTrace();
808     }
809   }
810
811   /**
812    * On cancel, restores the colour scheme before the dialogue was opened
813    * 
814    * @param e
815    */
816   @Override
817   protected void cancelButton_actionPerformed(ActionEvent e)
818   {
819     if (ap != null)
820     {
821       if (seqGroup != null)
822       {
823         seqGroup.cs = oldColourScheme;
824       }
825       else
826       {
827         ap.alignFrame.changeColour(oldColourScheme);
828       }
829       ap.paintAlignment(true);
830     }
831
832     if (structureViewer != null)
833     {
834       structureViewer.setJalviewColourScheme(oldColourScheme);
835     }
836
837     try
838     {
839       frame.setClosed(true);
840     } catch (Exception ex)
841     {
842     }
843   }
844
845   @Override
846   public void caseSensitive_actionPerformed(ActionEvent e)
847   {
848     resetButtonPanel(caseSensitive.isSelected());
849     lcaseColour.setEnabled(caseSensitive.isSelected());
850   }
851
852   @Override
853   public void lcaseColour_actionPerformed(ActionEvent e)
854   {
855     if (selectedButtons == null)
856     {
857       selectedButtons = new ArrayList<JButton>();
858     }
859     else
860     {
861       selectedButtons.clear();
862     }
863     selectedButtons.add(lcaseColour);
864   }
865 }