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.datamodel.SequenceI;
25 import jalview.gui.AlignmentPanel;
26 import jalview.gui.Desktop;
27 import jalview.jbgui.PDBDocFieldPreferences.PreferenceSource;
28 import jalview.util.MessageManager;
30 import java.awt.BorderLayout;
31 import java.awt.CardLayout;
32 import java.awt.Dimension;
33 import java.awt.FlowLayout;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ItemEvent;
36 import java.awt.event.ItemListener;
37 import java.awt.event.MouseAdapter;
38 import java.awt.event.MouseEvent;
40 import javax.swing.ImageIcon;
41 import javax.swing.JButton;
42 import javax.swing.JCheckBox;
43 import javax.swing.JComboBox;
44 import javax.swing.JFrame;
45 import javax.swing.JInternalFrame;
46 import javax.swing.JLabel;
47 import javax.swing.JPanel;
48 import javax.swing.JScrollPane;
49 import javax.swing.JTabbedPane;
50 import javax.swing.JTable;
51 import javax.swing.JTextField;
52 import javax.swing.event.ChangeEvent;
53 import javax.swing.event.ChangeListener;
54 import javax.swing.event.DocumentEvent;
55 import javax.swing.event.DocumentListener;
57 @SuppressWarnings("serial")
59 * GUI layout for structure chooser
63 public abstract class GStructureChooser extends JPanel implements
66 protected String frameTitle = MessageManager
67 .getString("label.structure_chooser");
69 protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
71 protected JComboBox<FilterOption> cmb_filterOption = new JComboBox<FilterOption>();
73 protected AlignmentPanel ap;
75 protected JLabel lbl_result = new JLabel(
76 MessageManager.getString("label.select"));
78 protected JButton btn_view = new JButton();
80 protected JButton btn_cancel = new JButton();
82 protected JButton btn_pdbFromFile = new JButton();
84 protected JTextField txt_search = new JTextField(14);
86 private JPanel pnl_actions = new JPanel();
88 private JPanel pnl_main = new JPanel();
90 private JPanel pnl_idInput = new JPanel(new FlowLayout());
92 private JPanel pnl_fileChooser = new JPanel(new FlowLayout());
94 private JPanel pnl_idInputBL = new JPanel(new BorderLayout());
96 private JPanel pnl_fileChooserBL = new JPanel(new BorderLayout());
98 private JPanel pnl_locPDB = new JPanel(new BorderLayout());
100 protected JPanel pnl_switchableViews = new JPanel(new CardLayout());
102 protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews
105 private BorderLayout mainLayout = new BorderLayout();
107 protected JCheckBox chk_rememberSettings = new JCheckBox(
108 MessageManager.getString("label.dont_ask_me_again"));
110 protected JCheckBox chk_invertFilter = new JCheckBox(
111 MessageManager.getString("label.invert"));
113 protected ImageIcon loadingImage = new ImageIcon(getClass().getResource(
114 "/images/loading.gif"));
116 protected ImageIcon goodImage = new ImageIcon(getClass().getResource(
117 "/images/good.png"));
119 protected ImageIcon errorImage = new ImageIcon(getClass().getResource(
120 "/images/error.png"));
122 protected JLabel lbl_loading = new JLabel(loadingImage);
124 protected JLabel lbl_pdbManualFetchStatus = new JLabel(errorImage);
126 protected JLabel lbl_fromFileStatus = new JLabel(errorImage);
129 protected AssciateSeqPanel idInputAssSeqPanel = new AssciateSeqPanel();
131 protected AssciateSeqPanel fileChooserAssSeqPanel = new AssciateSeqPanel();
133 protected static final String VIEWS_FILTER = "VIEWS_FILTER";
135 protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE";
137 protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
139 protected static final String VIEWS_LOCAL_PDB = "VIEWS_LOCAL_PDB";
141 protected JTable tbl_summary = new JTable();
143 protected JScrollPane scrl_foundStructures = new JScrollPane(
146 protected JTable tbl_local_pdb = new JTable();
148 protected JScrollPane scrl_localPDB = new JScrollPane(tbl_local_pdb);
150 private JTabbedPane pnl_filter = new JTabbedPane();
152 private PDBDocFieldPreferences pdbDocFieldPrefs = new PDBDocFieldPreferences(
153 PreferenceSource.STRUCTURE_CHOOSER);
155 public GStructureChooser()
160 mainFrame.setVisible(false);
161 mainFrame.invalidate();
163 } catch (Exception e)
170 * Initializes the GUI default properties
174 private void jbInit() throws Exception
176 tbl_summary.setAutoCreateRowSorter(true);
177 tbl_local_pdb.setAutoCreateRowSorter(true);
178 tbl_local_pdb.addMouseListener(new MouseAdapter()
180 public void mouseClicked(MouseEvent e)
186 btn_view.setFont(new java.awt.Font("Verdana", 0, 12));
187 btn_view.setText(MessageManager.getString("action.view"));
188 btn_view.addActionListener(new java.awt.event.ActionListener()
190 public void actionPerformed(ActionEvent e)
192 ok_ActionPerformed();
195 btn_cancel.setFont(new java.awt.Font("Verdana", 0, 12));
196 btn_cancel.setText(MessageManager.getString("action.cancel"));
197 btn_cancel.addActionListener(new java.awt.event.ActionListener()
199 public void actionPerformed(ActionEvent e)
205 btn_pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12));
206 String btn_title = MessageManager.getString("label.select_pdb_file");
207 btn_pdbFromFile.setText(btn_title + " ");
208 btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener()
210 public void actionPerformed(ActionEvent e)
212 pdbFromFile_actionPerformed();
216 scrl_foundStructures.setPreferredSize(new Dimension(500, 300));
218 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
220 scrl_localPDB.setPreferredSize(new Dimension(500, 300));
222 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
224 cmb_filterOption.setFont(new java.awt.Font("Verdana", 0, 12));
225 chk_invertFilter.setFont(new java.awt.Font("Verdana", 0, 12));
226 chk_rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12));
229 txt_search.setToolTipText(MessageManager
230 .getString("label.enter_pdb_id"));
231 cmb_filterOption.setToolTipText(MessageManager
232 .getString("info.select_filter_option"));
233 txt_search.getDocument().addDocumentListener(new DocumentListener()
236 public void insertUpdate(DocumentEvent e)
238 txt_search_ActionPerformed();
242 public void removeUpdate(DocumentEvent e)
244 txt_search_ActionPerformed();
248 public void changedUpdate(DocumentEvent e)
250 txt_search_ActionPerformed();
254 cmb_filterOption.addItemListener(this);
255 chk_invertFilter.addItemListener(this);
257 pnl_actions.add(chk_rememberSettings);
258 pnl_actions.add(btn_view);
259 pnl_actions.add(btn_cancel);
261 // pnl_filter.add(lbl_result);
262 pnl_main.add(cmb_filterOption);
263 pnl_main.add(lbl_loading);
264 pnl_main.add(chk_invertFilter);
265 lbl_loading.setVisible(false);
268 pnl_fileChooser.add(btn_pdbFromFile);
269 pnl_fileChooser.add(lbl_fromFileStatus);
270 pnl_fileChooserBL.add(fileChooserAssSeqPanel, BorderLayout.NORTH);
271 pnl_fileChooserBL.add(pnl_fileChooser, BorderLayout.CENTER);
273 pnl_idInput.add(txt_search);
274 pnl_idInput.add(lbl_pdbManualFetchStatus);
275 pnl_idInputBL.add(idInputAssSeqPanel, BorderLayout.NORTH);
276 pnl_idInputBL.add(pnl_idInput, BorderLayout.CENTER);
278 final String foundStructureSummary = MessageManager
279 .getString("label.found_structures_summary");
281 ChangeListener changeListener = new ChangeListener()
283 public void stateChanged(ChangeEvent changeEvent)
285 JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent
287 int index = sourceTabbedPane.getSelectedIndex();
288 if (sourceTabbedPane.getTitleAt(index)
289 .equals(foundStructureSummary))
295 pnl_filter.addChangeListener(changeListener);
296 pnl_filter.setPreferredSize(new Dimension(500, 300));
297 pnl_filter.add(foundStructureSummary, scrl_foundStructures);
299 MessageManager.getString("label.configure_displayed_columns"),
302 pnl_locPDB.add(scrl_localPDB);
304 pnl_switchableViews.add(pnl_fileChooserBL, VIEWS_FROM_FILE);
305 pnl_switchableViews.add(pnl_idInputBL, VIEWS_ENTER_ID);
306 pnl_switchableViews.add(pnl_filter, VIEWS_FILTER);
307 pnl_switchableViews.add(pnl_locPDB, VIEWS_LOCAL_PDB);
309 this.setLayout(mainLayout);
310 this.add(pnl_main, java.awt.BorderLayout.NORTH);
311 this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER);
312 this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
314 mainFrame.setVisible(true);
315 mainFrame.setContentPane(this);
316 mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
317 Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
323 * Event listener for the 'filter' combo-box and 'invert' check-box
325 public void itemStateChanged(ItemEvent e)
331 * This inner class provides the data model for the structure filter combo-box
336 public class FilterOption
340 private String value;
344 public FilterOption(String name, String value, String view)
351 public String getName()
356 public void setName(String name)
361 public String getValue()
366 public void setValue(String value)
371 public String getView()
376 public void setView(String view)
381 public String toString()
388 * This inner class provides the provides the data model for associate
389 * sequence combo-box - cmb_assSeq
394 public class AssociateSeqOptions
396 private SequenceI sequence;
399 public AssociateSeqOptions(SequenceI seq)
402 this.name = (seq.getName().length() >= 23) ? seq.getName().substring(
403 0, 23) : seq.getName();
406 public AssociateSeqOptions(String name, SequenceI seq)
412 public String toString()
417 public String getName()
422 public void setName(String name)
427 public SequenceI getSequence()
432 public void setSequence(SequenceI sequence)
434 this.sequence = sequence;
440 * This inner class holds the Layout and configuration of the panel which
441 * handles association of manually fetched structures to a unique sequence
442 * when more than one sequence selection is made
447 public class AssciateSeqPanel extends JPanel implements ItemListener
449 private JComboBox<AssociateSeqOptions> cmb_assSeq = new JComboBox<AssociateSeqOptions>();
451 private JLabel lbl_associateSeq = new JLabel();
453 public AssciateSeqPanel()
455 this.setLayout(new FlowLayout());
456 this.add(cmb_assSeq);
457 this.add(lbl_associateSeq);
458 cmb_assSeq.setToolTipText(MessageManager
459 .getString("info.associate_wit_sequence"));
460 cmb_assSeq.addItemListener(this);
463 public void loadCmbAssSeq()
465 populateCmbAssociateSeqOptions(cmb_assSeq, lbl_associateSeq);
468 public JComboBox<AssociateSeqOptions> getCmb_assSeq()
473 public void setCmb_assSeq(JComboBox<AssociateSeqOptions> cmb_assSeq)
475 this.cmb_assSeq = cmb_assSeq;
479 public void itemStateChanged(ItemEvent e)
481 if (e.getStateChange() == ItemEvent.SELECTED)
483 cmbAssSeqStateChanged();
488 public JComboBox<FilterOption> getCmbFilterOption()
490 return cmb_filterOption;
493 protected abstract void stateChanged(ItemEvent e);
495 protected abstract void updateCurrentView();
497 protected abstract void populateFilterComboBox();
499 protected abstract void ok_ActionPerformed();
501 protected abstract void pdbFromFile_actionPerformed();
503 protected abstract void txt_search_ActionPerformed();
505 public abstract void populateCmbAssociateSeqOptions(
506 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq);
508 public abstract void cmbAssSeqStateChanged();
510 public abstract void tabRefresh();