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 StringBuilder errorWarning = new StringBuilder();
77 protected JLabel lbl_result = new JLabel(
78 MessageManager.getString("label.select"));
80 protected JButton btn_view = new JButton();
82 protected JButton btn_cancel = new JButton();
84 protected JButton btn_pdbFromFile = new JButton();
86 protected JTextField txt_search = new JTextField(14);
88 private JPanel pnl_actions = new JPanel();
90 private JPanel pnl_main = new JPanel();
92 private JPanel pnl_idInput = new JPanel(new FlowLayout());
94 private JPanel pnl_fileChooser = new JPanel(new FlowLayout());
96 private JPanel pnl_idInputBL = new JPanel(new BorderLayout());
98 private JPanel pnl_fileChooserBL = new JPanel(new BorderLayout());
100 private JPanel pnl_locPDB = new JPanel(new BorderLayout());
102 protected JPanel pnl_switchableViews = new JPanel(new CardLayout());
104 protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews
107 private BorderLayout mainLayout = new BorderLayout();
109 protected JCheckBox chk_rememberSettings = new JCheckBox(
110 MessageManager.getString("label.dont_ask_me_again"));
112 protected JCheckBox chk_invertFilter = new JCheckBox(
113 MessageManager.getString("label.invert"));
115 protected ImageIcon loadingImage = new ImageIcon(getClass().getResource(
116 "/images/loading.gif"));
118 protected ImageIcon goodImage = new ImageIcon(getClass().getResource(
119 "/images/good.png"));
121 protected ImageIcon errorImage = new ImageIcon(getClass().getResource(
122 "/images/error.png"));
124 protected ImageIcon warningImage = new ImageIcon(getClass().getResource(
125 "/images/warning.gif"));
127 protected JLabel lbl_warning = new JLabel(warningImage);
129 protected JLabel lbl_loading = new JLabel(loadingImage);
131 protected JLabel lbl_pdbManualFetchStatus = new JLabel(errorImage);
133 protected JLabel lbl_fromFileStatus = new JLabel(errorImage);
136 protected AssciateSeqPanel idInputAssSeqPanel = new AssciateSeqPanel();
138 protected AssciateSeqPanel fileChooserAssSeqPanel = new AssciateSeqPanel();
140 protected static final String VIEWS_FILTER = "VIEWS_FILTER";
142 protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE";
144 protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
146 protected static final String VIEWS_LOCAL_PDB = "VIEWS_LOCAL_PDB";
148 protected JTable tbl_summary = new JTable();
150 protected JScrollPane scrl_foundStructures = new JScrollPane(
153 protected JTable tbl_local_pdb = new JTable();
155 protected JScrollPane scrl_localPDB = new JScrollPane(tbl_local_pdb);
157 private JTabbedPane pnl_filter = new JTabbedPane();
159 private PDBDocFieldPreferences pdbDocFieldPrefs = new PDBDocFieldPreferences(
160 PreferenceSource.STRUCTURE_CHOOSER);
162 public GStructureChooser()
167 mainFrame.setVisible(false);
168 mainFrame.invalidate();
170 } catch (Exception e)
177 * Initializes the GUI default properties
181 private void jbInit() throws Exception
183 tbl_summary.setAutoCreateRowSorter(true);
184 tbl_summary.getTableHeader().setReorderingAllowed(false);
185 tbl_local_pdb.setAutoCreateRowSorter(true);
186 tbl_local_pdb.getTableHeader().setReorderingAllowed(false);
187 tbl_local_pdb.addMouseListener(new MouseAdapter()
189 public void mouseClicked(MouseEvent e)
194 public void mouseReleased(MouseEvent e)
200 btn_view.setFont(new java.awt.Font("Verdana", 0, 12));
201 btn_view.setText(MessageManager.getString("action.view"));
202 btn_view.addActionListener(new java.awt.event.ActionListener()
204 public void actionPerformed(ActionEvent e)
206 ok_ActionPerformed();
209 btn_cancel.setFont(new java.awt.Font("Verdana", 0, 12));
210 btn_cancel.setText(MessageManager.getString("action.cancel"));
211 btn_cancel.addActionListener(new java.awt.event.ActionListener()
213 public void actionPerformed(ActionEvent e)
219 btn_pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12));
220 String btn_title = MessageManager.getString("label.select_pdb_file");
221 btn_pdbFromFile.setText(btn_title + " ");
222 btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener()
224 public void actionPerformed(ActionEvent e)
226 pdbFromFile_actionPerformed();
230 scrl_foundStructures.setPreferredSize(new Dimension(500, 300));
232 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
234 scrl_localPDB.setPreferredSize(new Dimension(500, 300));
236 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
238 cmb_filterOption.setFont(new java.awt.Font("Verdana", 0, 12));
239 chk_invertFilter.setFont(new java.awt.Font("Verdana", 0, 12));
240 chk_rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12));
243 txt_search.setToolTipText(MessageManager
244 .getString("label.enter_pdb_id"));
245 cmb_filterOption.setToolTipText(MessageManager
246 .getString("info.select_filter_option"));
247 txt_search.getDocument().addDocumentListener(new DocumentListener()
250 public void insertUpdate(DocumentEvent e)
252 txt_search_ActionPerformed();
256 public void removeUpdate(DocumentEvent e)
258 txt_search_ActionPerformed();
262 public void changedUpdate(DocumentEvent e)
264 txt_search_ActionPerformed();
268 cmb_filterOption.addItemListener(this);
269 chk_invertFilter.addItemListener(this);
271 pnl_actions.add(chk_rememberSettings);
272 pnl_actions.add(btn_view);
273 pnl_actions.add(btn_cancel);
275 // pnl_filter.add(lbl_result);
276 pnl_main.add(cmb_filterOption);
277 pnl_main.add(lbl_loading);
278 pnl_main.add(chk_invertFilter);
279 lbl_loading.setVisible(false);
282 pnl_fileChooser.add(btn_pdbFromFile);
283 pnl_fileChooser.add(lbl_fromFileStatus);
284 pnl_fileChooserBL.add(fileChooserAssSeqPanel, BorderLayout.NORTH);
285 pnl_fileChooserBL.add(pnl_fileChooser, BorderLayout.CENTER);
287 pnl_idInput.add(txt_search);
288 pnl_idInput.add(lbl_pdbManualFetchStatus);
289 pnl_idInputBL.add(idInputAssSeqPanel, BorderLayout.NORTH);
290 pnl_idInputBL.add(pnl_idInput, BorderLayout.CENTER);
292 final String foundStructureSummary = MessageManager
293 .getString("label.found_structures_summary");
295 ChangeListener changeListener = new ChangeListener()
297 public void stateChanged(ChangeEvent changeEvent)
299 JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent
301 int index = sourceTabbedPane.getSelectedIndex();
302 if (sourceTabbedPane.getTitleAt(index)
303 .equals(foundStructureSummary))
309 pnl_filter.addChangeListener(changeListener);
310 pnl_filter.setPreferredSize(new Dimension(500, 300));
311 pnl_filter.add(foundStructureSummary, scrl_foundStructures);
313 MessageManager.getString("label.configure_displayed_columns"),
316 pnl_locPDB.add(scrl_localPDB);
318 pnl_switchableViews.add(pnl_fileChooserBL, VIEWS_FROM_FILE);
319 pnl_switchableViews.add(pnl_idInputBL, VIEWS_ENTER_ID);
320 pnl_switchableViews.add(pnl_filter, VIEWS_FILTER);
321 pnl_switchableViews.add(pnl_locPDB, VIEWS_LOCAL_PDB);
323 this.setLayout(mainLayout);
324 this.add(pnl_main, java.awt.BorderLayout.NORTH);
325 this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER);
326 this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
328 mainFrame.setVisible(true);
329 mainFrame.setContentPane(this);
330 mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
331 Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
337 * Event listener for the 'filter' combo-box and 'invert' check-box
339 public void itemStateChanged(ItemEvent e)
345 * This inner class provides the data model for the structure filter combo-box
350 public class FilterOption
354 private String value;
358 public FilterOption(String name, String value, String view)
365 public String getName()
370 public void setName(String name)
375 public String getValue()
380 public void setValue(String value)
385 public String getView()
390 public void setView(String view)
395 public String toString()
402 * This inner class provides the provides the data model for associate
403 * sequence combo-box - cmb_assSeq
408 public class AssociateSeqOptions
410 private SequenceI sequence;
413 public AssociateSeqOptions(SequenceI seq)
416 this.name = (seq.getName().length() >= 23) ? seq.getName().substring(
417 0, 23) : seq.getName();
420 public AssociateSeqOptions(String name, SequenceI seq)
426 public String toString()
431 public String getName()
436 public void setName(String name)
441 public SequenceI getSequence()
446 public void setSequence(SequenceI sequence)
448 this.sequence = sequence;
454 * This inner class holds the Layout and configuration of the panel which
455 * handles association of manually fetched structures to a unique sequence
456 * when more than one sequence selection is made
461 public class AssciateSeqPanel extends JPanel implements ItemListener
463 private JComboBox<AssociateSeqOptions> cmb_assSeq = new JComboBox<AssociateSeqOptions>();
465 private JLabel lbl_associateSeq = new JLabel();
467 public AssciateSeqPanel()
469 this.setLayout(new FlowLayout());
470 this.add(cmb_assSeq);
471 this.add(lbl_associateSeq);
472 cmb_assSeq.setToolTipText(MessageManager
473 .getString("info.associate_wit_sequence"));
474 cmb_assSeq.addItemListener(this);
477 public void loadCmbAssSeq()
479 populateCmbAssociateSeqOptions(cmb_assSeq, lbl_associateSeq);
482 public JComboBox<AssociateSeqOptions> getCmb_assSeq()
487 public void setCmb_assSeq(JComboBox<AssociateSeqOptions> cmb_assSeq)
489 this.cmb_assSeq = cmb_assSeq;
493 public void itemStateChanged(ItemEvent e)
495 if (e.getStateChange() == ItemEvent.SELECTED)
497 cmbAssSeqStateChanged();
502 public JComboBox<FilterOption> getCmbFilterOption()
504 return cmb_filterOption;
507 protected abstract void stateChanged(ItemEvent e);
509 protected abstract void updateCurrentView();
511 protected abstract void populateFilterComboBox();
513 protected abstract void ok_ActionPerformed();
515 protected abstract void pdbFromFile_actionPerformed();
517 protected abstract void txt_search_ActionPerformed();
519 public abstract void populateCmbAssociateSeqOptions(
520 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq);
522 public abstract void cmbAssSeqStateChanged();
524 public abstract void tabRefresh();