2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
22 package jalview.jbgui;
24 import jalview.gui.AlignmentPanel;
25 import jalview.gui.Desktop;
26 import jalview.util.MessageManager;
27 import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary;
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;
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;
51 @SuppressWarnings("serial")
53 * GUI layout for structure chooser
57 public abstract class GStructureChooser extends JPanel implements
60 protected String frameTitle = MessageManager
61 .getString("label.structure_chooser");
63 protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
65 protected JComboBox<FilterOption> cmb_filterOption = new JComboBox<FilterOption>();
67 protected AlignmentPanel ap;
69 protected JLabel lbl_result = new JLabel(
70 MessageManager.getString("label.select") /* "Select : " */);
72 protected JButton btn_ok = new JButton();
74 protected JButton btn_cancel = new JButton();
76 protected JButton btn_pdbFromFile = new JButton();
78 protected JTextField txt_search = new JTextField(18);
80 private JPanel pnl_actions = new JPanel();
82 private JPanel pnl_filter = new JPanel();
84 private JPanel pnl_idInput = new JPanel();
86 private JPanel pnl_fileChooser = new JPanel();
88 protected JPanel pnl_switchableViews = new JPanel(new CardLayout());
90 protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews
93 private BorderLayout mainLayout = new BorderLayout();
95 protected JCheckBox chk_rememberSettings = new JCheckBox(
96 MessageManager.getString("label.dont_ask_me_again"));
98 protected JCheckBox chk_invertFilter = new JCheckBox(
99 MessageManager.getString("label.invert"));
101 protected ImageIcon loadingImage = new ImageIcon(getClass().getResource(
102 "/images/loading.gif"));
104 protected JLabel lbl_loading = new JLabel(loadingImage);
106 protected static final String VIEWS_FILTER = "VIEWS_FILTER";
108 protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE";
110 protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
112 protected JList<PDBResponseSummary> jList_FoundStructures = new JList<PDBResponseSummary>();
114 protected JTable tbl_summary = new JTable();
116 protected JScrollPane scrl_foundStructures = new JScrollPane(
119 public GStructureChooser()
124 mainFrame.setVisible(false);
125 mainFrame.invalidate();
127 } catch (Exception e)
134 * Initializes the GUI default properties
138 private void jbInit() throws Exception
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()
144 public void actionPerformed(ActionEvent e)
146 ok_ActionPerformed();
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()
153 public void actionPerformed(ActionEvent e)
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()
164 public void actionPerformed(ActionEvent e)
166 pdbFromFile_actionPerformed();
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));
176 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
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));
182 cmb_filterOption.addItemListener(this);
183 chk_invertFilter.addItemListener(this);
185 pnl_actions.add(chk_rememberSettings);
186 pnl_actions.add(btn_ok);
187 pnl_actions.add(btn_cancel);
189 pnl_filter.add(lbl_result);
190 pnl_filter.add(cmb_filterOption);
191 lbl_loading.setVisible(false);
193 pnl_filter.add(lbl_loading);
195 pnl_filter.add(chk_invertFilter);
197 pnl_idInput.setLayout(new FlowLayout());
198 pnl_idInput.add(txt_search);
200 pnl_fileChooser.setLayout(new FlowLayout());
201 pnl_fileChooser.add(btn_pdbFromFile);
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);
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);
212 mainFrame.setVisible(true);
213 mainFrame.setContentPane(this);
214 mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
215 Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
221 * Event listener for the 'filter' combo-box and 'invert' check-box
223 public void itemStateChanged(ItemEvent e)
229 * This inner class provides the data model for the structure filter combo-box
234 public class FilterOption
238 private String value;
242 public FilterOption(String name, String value, String view)
249 public String getName()
254 public void setName(String name)
259 public String getValue()
264 public void setValue(String value)
269 public String getView()
274 public void setView(String view)
279 public String toString()
285 public JComboBox<FilterOption> getCmbFilterOption()
287 return cmb_filterOption;
290 protected abstract void stateChanged(ItemEvent e);
292 protected abstract void updateCurrentView();
294 protected abstract void ok_ActionPerformed();
296 protected abstract void populateFilterComboBox();
298 protected abstract void pdbFromFile_actionPerformed();