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