JAL-1667 updated test and internationalization messages
[jalview.git] / src / jalview / jbgui / GStructureChooser.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3  * Copyright (C) 2014 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
22 package jalview.jbgui;
23
24 import jalview.gui.AlignmentPanel;
25 import jalview.gui.Desktop;
26 import jalview.util.MessageManager;
27 import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary;
28
29 import java.awt.BorderLayout;
30 import java.awt.CardLayout;
31 import java.awt.Dimension;
32 import java.awt.FlowLayout;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ItemEvent;
35 import java.awt.event.ItemListener;
36
37 import javax.swing.ImageIcon;
38 import javax.swing.JButton;
39 import javax.swing.JCheckBox;
40 import javax.swing.JComboBox;
41 import javax.swing.JFrame;
42 import javax.swing.JInternalFrame;
43 import javax.swing.JLabel;
44 import javax.swing.JList;
45 import javax.swing.JPanel;
46 import javax.swing.JScrollPane;
47 import javax.swing.JTable;
48 import javax.swing.JTextField;
49 import javax.swing.ListSelectionModel;
50
51 @SuppressWarnings("serial")
52 /**
53  * GUI layout for structure chooser 
54  * @author tcnofoegbu
55  *
56  */
57 public abstract class GStructureChooser extends JPanel implements
58         ItemListener
59 {
60   protected String frameTitle = MessageManager
61           .getString("label.structure_chooser");
62
63   protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
64
65   protected JComboBox<FilterOption> cmb_filterOption = new JComboBox<FilterOption>();
66
67   protected AlignmentPanel ap;
68
69   protected JLabel lbl_result = new JLabel(
70           MessageManager.getString("label.select") /* "Select : " */);
71
72   protected JButton btn_ok = new JButton();
73
74   protected JButton btn_cancel = new JButton();
75
76   protected JButton btn_pdbFromFile = new JButton();
77
78   protected JTextField txt_search = new JTextField(18);
79
80   private JPanel pnl_actions = new JPanel();
81
82   private JPanel pnl_filter = new JPanel();
83
84   private JPanel pnl_idInput = new JPanel();
85
86   private JPanel pnl_fileChooser = new JPanel();
87
88   protected JPanel pnl_switchableViews = new JPanel(new CardLayout());
89
90   protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews
91           .getLayout());
92
93   private BorderLayout mainLayout = new BorderLayout();
94
95   protected JCheckBox chk_rememberSettings = new JCheckBox(
96           MessageManager.getString("label.dont_ask_me_again"));
97
98   protected JCheckBox chk_invertFilter = new JCheckBox(
99           MessageManager.getString("label.invert"));
100
101   protected ImageIcon loadingImage = new ImageIcon(getClass().getResource(
102           "/images/loading.gif"));
103
104   protected JLabel lbl_loading = new JLabel(loadingImage);
105
106   protected static final String VIEWS_FILTER = "VIEWS_FILTER";
107
108   protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE";
109
110   protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
111
112   protected JList<PDBResponseSummary> jList_FoundStructures = new JList<PDBResponseSummary>();
113
114   protected JTable tbl_summary = new JTable();
115
116   protected JScrollPane scrl_foundStructures = new JScrollPane(
117           tbl_summary);
118
119   public GStructureChooser()
120   {
121     try
122     {
123       jbInit();
124       mainFrame.setVisible(false);
125       mainFrame.invalidate();
126       mainFrame.pack();
127     } catch (Exception e)
128     {
129       e.printStackTrace();
130     }
131   }
132
133   /**
134    * Initializes the GUI default properties
135    * 
136    * @throws Exception
137    */
138   private void jbInit() throws Exception
139   {
140     btn_ok.setFont(new java.awt.Font("Verdana", 0, 12));
141     btn_ok.setText(MessageManager.getString("action.view"));
142     btn_ok.addActionListener(new java.awt.event.ActionListener()
143     {
144       public void actionPerformed(ActionEvent e)
145       {
146         ok_ActionPerformed();
147       }
148     });
149     btn_cancel.setFont(new java.awt.Font("Verdana", 0, 12));
150     btn_cancel.setText(MessageManager.getString("action.cancel"));
151     btn_cancel.addActionListener(new java.awt.event.ActionListener()
152     {
153       public void actionPerformed(ActionEvent e)
154       {
155         mainFrame.dispose();
156       }
157     });
158
159     btn_pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12));
160     String btn_title = MessageManager.getString("label.select_pdb_file");
161     btn_pdbFromFile.setText("             " + btn_title + "            ");
162     btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener()
163     {
164       public void actionPerformed(ActionEvent e)
165       {
166         pdbFromFile_actionPerformed();
167       }
168     });
169
170     jList_FoundStructures
171             .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
172     jList_FoundStructures.setLayoutOrientation(JList.VERTICAL);
173     jList_FoundStructures.setVisibleRowCount(-1);
174     scrl_foundStructures.setPreferredSize(new Dimension(500, 300));
175     scrl_foundStructures
176             .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
177
178     cmb_filterOption.setFont(new java.awt.Font("Verdana", 0, 12));
179     chk_invertFilter.setFont(new java.awt.Font("Verdana", 0, 12));
180     chk_rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12));
181
182     cmb_filterOption.addItemListener(this);
183     chk_invertFilter.addItemListener(this);
184
185     pnl_actions.add(chk_rememberSettings);
186     pnl_actions.add(btn_ok);
187     pnl_actions.add(btn_cancel);
188
189     pnl_filter.add(lbl_result);
190     pnl_filter.add(cmb_filterOption);
191     lbl_loading.setVisible(false);
192
193     pnl_filter.add(lbl_loading);
194
195     pnl_filter.add(chk_invertFilter);
196
197     pnl_idInput.setLayout(new FlowLayout());
198     pnl_idInput.add(txt_search);
199
200     pnl_fileChooser.setLayout(new FlowLayout());
201     pnl_fileChooser.add(btn_pdbFromFile);
202
203     pnl_switchableViews.add(pnl_fileChooser, VIEWS_FROM_FILE);
204     pnl_switchableViews.add(pnl_idInput, VIEWS_ENTER_ID);
205     pnl_switchableViews.add(scrl_foundStructures, VIEWS_FILTER);
206     
207     this.setLayout(mainLayout);
208     this.add(pnl_filter, java.awt.BorderLayout.NORTH);
209     this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER);
210     this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
211
212     mainFrame.setVisible(true);
213     mainFrame.setContentPane(this);
214     mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
215     Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
216   }
217
218   
219   @Override
220   /**
221    * Event listener for the 'filter' combo-box and 'invert' check-box
222    */
223   public void itemStateChanged(ItemEvent e)
224   {
225     stateChanged(e);
226   }
227
228   /**
229    * This inner class provides the data model for the structure filter combo-box
230    * 
231    * @author tcnofoegbu
232    *
233    */
234   public class FilterOption
235   {
236     private String name;
237
238     private String value;
239
240     private String view;
241
242     public FilterOption(String name, String value, String view)
243     {
244       this.name = name;
245       this.value = value;
246       this.view = view;
247     }
248
249     public String getName()
250     {
251       return name;
252     }
253
254     public void setName(String name)
255     {
256       this.name = name;
257     }
258
259     public String getValue()
260     {
261       return value;
262     }
263
264     public void setValue(String value)
265     {
266       this.value = value;
267     }
268
269     public String getView()
270     {
271       return view;
272     }
273
274     public void setView(String view)
275     {
276       this.view = view;
277     }
278
279     public String toString()
280     {
281       return this.name;
282     }
283   }
284
285   public JComboBox<FilterOption> getCmbFilterOption()
286   {
287     return cmb_filterOption;
288   }
289
290   protected abstract void stateChanged(ItemEvent e);
291
292   protected abstract void updateCurrentView();
293
294   protected abstract void ok_ActionPerformed();
295
296   protected abstract void populateFilterComboBox();
297
298   protected abstract void pdbFromFile_actionPerformed();
299 }