JAL-2361 extract methods to (re-)build colour menu
[jalview.git] / src / jalview / jbgui / GUserDefinedColours.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.jbgui;
22
23 import jalview.gui.JvSwingUtils;
24 import jalview.util.MessageManager;
25
26 import java.awt.BorderLayout;
27 import java.awt.Color;
28 import java.awt.Dimension;
29 import java.awt.FlowLayout;
30 import java.awt.Font;
31 import java.awt.GridBagLayout;
32 import java.awt.GridLayout;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
35
36 import javax.swing.JButton;
37 import javax.swing.JCheckBox;
38 import javax.swing.JColorChooser;
39 import javax.swing.JLabel;
40 import javax.swing.JPanel;
41 import javax.swing.JTextField;
42 import javax.swing.SwingConstants;
43 import javax.swing.colorchooser.AbstractColorChooserPanel;
44
45 /**
46  * DOCUMENT ME!
47  * 
48  * @author $author$
49  * @version $Revision$
50  */
51 public class GUserDefinedColours extends JPanel
52 {
53   protected JColorChooser colorChooser = new JColorChooser();
54
55   protected JPanel buttonPanel = new JPanel();
56
57   protected GridLayout gridLayout = new GridLayout();
58
59   JPanel lowerPanel = new JPanel();
60
61   protected JButton okButton = new JButton();
62
63   protected JButton applyButton = new JButton();
64
65   protected JButton loadbutton = new JButton();
66
67   protected JButton savebutton = new JButton();
68
69   protected JButton cancelButton = new JButton();
70
71   JPanel namePanel = new JPanel();
72
73   JLabel jLabel1 = new JLabel();
74
75   protected JTextField schemeName = new JTextField();
76
77   BorderLayout borderLayout1 = new BorderLayout();
78
79   JPanel panel1 = new JPanel();
80
81   JPanel okCancelPanel = new JPanel();
82
83   JPanel saveLoadPanel = new JPanel();
84
85   BorderLayout borderLayout3 = new BorderLayout();
86
87   GridBagLayout gridBagLayout1 = new GridBagLayout();
88
89   BorderLayout borderLayout2 = new BorderLayout();
90
91   FlowLayout flowLayout1 = new FlowLayout();
92
93   BorderLayout borderLayout4 = new BorderLayout();
94
95   JPanel jPanel4 = new JPanel();
96
97   BorderLayout borderLayout5 = new BorderLayout();
98
99   JLabel label = new JLabel();
100
101   protected JPanel casePanel = new JPanel();
102
103   protected JCheckBox caseSensitive = new JCheckBox();
104
105   protected JButton lcaseColour = new JButton();
106
107   /**
108    * Creates a new GUserDefinedColours object.
109    */
110   public GUserDefinedColours()
111   {
112     try
113     {
114       jbInit();
115     } catch (Exception e)
116     {
117       e.printStackTrace();
118     }
119
120   }
121
122   /**
123    * DOCUMENT ME!
124    * 
125    * @throws Exception
126    *           DOCUMENT ME!
127    */
128   private void jbInit() throws Exception
129   {
130     this.setLayout(borderLayout4);
131     buttonPanel.setLayout(gridLayout);
132     gridLayout.setColumns(4);
133     gridLayout.setRows(5);
134     okButton.setFont(new java.awt.Font("Verdana", 0, 11));
135     okButton.setText(MessageManager.getString("action.ok"));
136     okButton.addActionListener(new java.awt.event.ActionListener()
137     {
138       @Override
139       public void actionPerformed(ActionEvent e)
140       {
141         okButton_actionPerformed();
142       }
143     });
144     applyButton.setFont(new java.awt.Font("Verdana", 0, 11));
145     applyButton.setText(MessageManager.getString("action.apply"));
146     applyButton.addActionListener(new ActionListener()
147     {
148       @Override
149       public void actionPerformed(ActionEvent e)
150       {
151         applyButton_actionPerformed();
152       }
153     });
154     loadbutton.setFont(new java.awt.Font("Verdana", 0, 11));
155     loadbutton.setText(MessageManager.getString("action.load_scheme"));
156     loadbutton.addActionListener(new java.awt.event.ActionListener()
157     {
158       @Override
159       public void actionPerformed(ActionEvent e)
160       {
161         loadbutton_actionPerformed(e);
162       }
163     });
164     savebutton.setFont(new java.awt.Font("Verdana", 0, 11));
165     savebutton.setText(MessageManager.getString("action.save_scheme"));
166     savebutton.addActionListener(new java.awt.event.ActionListener()
167     {
168       @Override
169       public void actionPerformed(ActionEvent e)
170       {
171         savebutton_actionPerformed(e);
172       }
173     });
174     cancelButton.setFont(JvSwingUtils.getLabelFont());
175     cancelButton.setText(MessageManager.getString("action.cancel"));
176     cancelButton.addActionListener(new java.awt.event.ActionListener()
177     {
178       @Override
179       public void actionPerformed(ActionEvent e)
180       {
181         cancelButton_actionPerformed(e);
182       }
183     });
184     this.setBackground(new Color(212, 208, 223));
185     lowerPanel.setOpaque(false);
186     lowerPanel.setLayout(borderLayout3);
187     colorChooser.setOpaque(false);
188     jLabel1.setFont(JvSwingUtils.getLabelFont());
189     jLabel1.setText(MessageManager.getString("label.name"));
190     namePanel.setMinimumSize(new Dimension(300, 31));
191     namePanel.setOpaque(false);
192     namePanel.setPreferredSize(new Dimension(240, 25));
193     namePanel.setLayout(borderLayout1);
194     schemeName.setFont(JvSwingUtils.getLabelFont());
195     schemeName.setPreferredSize(new Dimension(105, 21));
196     schemeName.setText("");
197     schemeName.setHorizontalAlignment(SwingConstants.CENTER);
198     panel1.setLayout(flowLayout1);
199     panel1.setOpaque(false);
200     okCancelPanel.setOpaque(false);
201     saveLoadPanel.setOpaque(false);
202     jPanel4.setLayout(borderLayout5);
203     label.setFont(new java.awt.Font("Verdana", Font.ITALIC, 10));
204     label.setOpaque(false);
205     label.setPreferredSize(new Dimension(260, 34));
206     label.setText(MessageManager
207             .formatMessage(
208                     "label.html_content",
209                     new String[] { MessageManager
210                             .getString("label.save_colour_scheme_with_unique_name_added_to_colour_menu") }));
211     caseSensitive.setText(MessageManager.getString("label.case_sensitive"));
212     caseSensitive.addActionListener(new ActionListener()
213     {
214       @Override
215       public void actionPerformed(ActionEvent e)
216       {
217         caseSensitive_actionPerformed(e);
218       }
219     });
220     lcaseColour
221             .setText(MessageManager.getString("label.lower_case_colour"));
222     lcaseColour.addActionListener(new ActionListener()
223     {
224       @Override
225       public void actionPerformed(ActionEvent e)
226       {
227         lcaseColour_actionPerformed(e);
228       }
229     });
230
231     saveLoadPanel.add(savebutton);
232     saveLoadPanel.add(loadbutton);
233     okCancelPanel.add(applyButton);
234     okCancelPanel.add(okButton);
235     okCancelPanel.add(cancelButton);
236     lowerPanel.add(saveLoadPanel, java.awt.BorderLayout.NORTH);
237     lowerPanel.add(okCancelPanel, java.awt.BorderLayout.SOUTH);
238
239     namePanel.add(schemeName, java.awt.BorderLayout.CENTER);
240     namePanel.add(jLabel1, java.awt.BorderLayout.WEST);
241     panel1.add(namePanel, null);
242     panel1.add(buttonPanel, null);
243     panel1.add(casePanel);
244     casePanel.add(caseSensitive);
245     casePanel.add(lcaseColour);
246     panel1.add(lowerPanel, null);
247     panel1.add(label);
248
249     jPanel4.add(panel1, java.awt.BorderLayout.CENTER);
250     this.add(jPanel4, java.awt.BorderLayout.CENTER);
251     this.add(colorChooser, java.awt.BorderLayout.EAST);
252
253     AbstractColorChooserPanel[] choosers = colorChooser.getChooserPanels();
254     // JAL-1360 larger JColorChooser in Java 7 overwrites AA panel; restrict to
255     // swatch picker only
256     if (choosers.length > 3)
257     {
258       // Java 7 default has 5 options rather than 3 for choosing colours; keep
259       // the first only
260       colorChooser
261               .setChooserPanels(new AbstractColorChooserPanel[] { choosers[0] });
262     }
263   }
264
265   /**
266    * DOCUMENT ME!
267    */
268   protected void okButton_actionPerformed()
269   {
270   }
271
272   /**
273    * DOCUMENT ME!
274    */
275   protected void applyButton_actionPerformed()
276   {
277   }
278
279   /**
280    * DOCUMENT ME!
281    * 
282    * @param e
283    *          DOCUMENT ME!
284    */
285   protected void loadbutton_actionPerformed(ActionEvent e)
286   {
287   }
288
289   /**
290    * DOCUMENT ME!
291    * 
292    * @param e
293    *          DOCUMENT ME!
294    */
295   protected void savebutton_actionPerformed(ActionEvent e)
296   {
297   }
298
299   /**
300    * DOCUMENT ME!
301    * 
302    * @param e
303    *          DOCUMENT ME!
304    */
305   protected void cancelButton_actionPerformed(ActionEvent e)
306   {
307   }
308
309   public void caseSensitive_actionPerformed(ActionEvent e)
310   {
311
312   }
313
314   public void lcaseColour_actionPerformed(ActionEvent e)
315   {
316
317   }
318 }