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.gui.JvSwingUtils;
28 import jalview.jbgui.PDBDocFieldPreferences.PreferenceSource;
29 import jalview.util.MessageManager;
30 import jalview.ws.dbsources.PDBRestClient;
31 import jalview.ws.dbsources.PDBRestClient.PDBDocField;
33 import java.awt.BorderLayout;
34 import java.awt.CardLayout;
35 import java.awt.Dimension;
36 import java.awt.FlowLayout;
37 import java.awt.event.ActionEvent;
38 import java.awt.event.ItemEvent;
39 import java.awt.event.ItemListener;
40 import java.awt.event.KeyAdapter;
41 import java.awt.event.KeyEvent;
42 import java.awt.event.MouseAdapter;
43 import java.awt.event.MouseEvent;
44 import java.util.Arrays;
46 import javax.swing.ImageIcon;
47 import javax.swing.JButton;
48 import javax.swing.JCheckBox;
49 import javax.swing.JComboBox;
50 import javax.swing.JFrame;
51 import javax.swing.JInternalFrame;
52 import javax.swing.JLabel;
53 import javax.swing.JPanel;
54 import javax.swing.JScrollPane;
55 import javax.swing.JTabbedPane;
56 import javax.swing.JTable;
57 import javax.swing.JTextField;
58 import javax.swing.event.ChangeEvent;
59 import javax.swing.event.ChangeListener;
60 import javax.swing.event.DocumentEvent;
61 import javax.swing.event.DocumentListener;
63 @SuppressWarnings("serial")
65 * GUI layout for structure chooser
69 public abstract class GStructureChooser extends JPanel implements
72 protected String frameTitle = MessageManager
73 .getString("label.structure_chooser");
75 protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
77 protected JComboBox<FilterOption> cmb_filterOption = new JComboBox<FilterOption>();
79 protected AlignmentPanel ap;
81 protected StringBuilder errorWarning = new StringBuilder();
83 protected JLabel lbl_result = new JLabel(
84 MessageManager.getString("label.select"));
86 protected JButton btn_view = new JButton();
88 protected JButton btn_cancel = new JButton();
90 protected JButton btn_pdbFromFile = new JButton();
92 protected JTextField txt_search = new JTextField(14);
94 private JPanel pnl_actions = new JPanel();
96 private JPanel pnl_main = new JPanel();
98 private JPanel pnl_idInput = new JPanel(new FlowLayout());
100 private JPanel pnl_fileChooser = new JPanel(new FlowLayout());
102 private JPanel pnl_idInputBL = new JPanel(new BorderLayout());
104 private JPanel pnl_fileChooserBL = new JPanel(new BorderLayout());
106 private JPanel pnl_locPDB = new JPanel(new BorderLayout());
108 protected JPanel pnl_switchableViews = new JPanel(new CardLayout());
110 protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews
113 private BorderLayout mainLayout = new BorderLayout();
115 protected JCheckBox chk_rememberSettings = new JCheckBox(
116 MessageManager.getString("label.dont_ask_me_again"));
118 protected JCheckBox chk_invertFilter = new JCheckBox(
119 MessageManager.getString("label.invert"));
121 protected ImageIcon loadingImage = new ImageIcon(getClass().getResource(
122 "/images/loading.gif"));
124 protected ImageIcon goodImage = new ImageIcon(getClass().getResource(
125 "/images/good.png"));
127 protected ImageIcon errorImage = new ImageIcon(getClass().getResource(
128 "/images/error.png"));
130 protected ImageIcon warningImage = new ImageIcon(getClass().getResource(
131 "/images/warning.gif"));
133 protected JLabel lbl_warning = new JLabel(warningImage);
135 protected JLabel lbl_loading = new JLabel(loadingImage);
137 protected JLabel lbl_pdbManualFetchStatus = new JLabel(errorImage);
139 protected JLabel lbl_fromFileStatus = new JLabel(errorImage);
141 protected AssciateSeqPanel idInputAssSeqPanel = new AssciateSeqPanel();
143 protected AssciateSeqPanel fileChooserAssSeqPanel = new AssciateSeqPanel();
145 protected static final String VIEWS_FILTER = "VIEWS_FILTER";
147 protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE";
149 protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
151 protected static final String VIEWS_LOCAL_PDB = "VIEWS_LOCAL_PDB";
153 protected JTable tbl_summary = new JTable()
155 public String getToolTipText(MouseEvent evt)
157 String toolTipText = null;
158 java.awt.Point pnt = evt.getPoint();
159 int rowIndex = rowAtPoint(pnt);
160 int colIndex = columnAtPoint(pnt);
164 toolTipText = getValueAt(rowIndex, colIndex).toString();
165 } catch (Exception e)
169 toolTipText = (toolTipText == null ? null
170 : (toolTipText.length() > 500 ? JvSwingUtils.wrapTooltip(
171 true, "\"" + toolTipText.subSequence(0, 500)
172 + "...\"") : JvSwingUtils.wrapTooltip(true,
178 protected JScrollPane scrl_foundStructures = new JScrollPane(tbl_summary);
180 protected JTable tbl_local_pdb = new JTable();
182 protected JScrollPane scrl_localPDB = new JScrollPane(tbl_local_pdb);
184 private JTabbedPane pnl_filter = new JTabbedPane();
186 private PDBDocFieldPreferences pdbDocFieldPrefs = new PDBDocFieldPreferences(
187 PreferenceSource.STRUCTURE_CHOOSER);
189 protected PDBDocField[] previousWantedFields;
191 public GStructureChooser()
196 mainFrame.setVisible(false);
197 mainFrame.invalidate();
199 } catch (Exception e)
206 * Initializes the GUI default properties
210 private void jbInit() throws Exception
212 tbl_summary.setAutoCreateRowSorter(true);
213 tbl_summary.getTableHeader().setReorderingAllowed(false);
214 tbl_summary.addMouseListener(new MouseAdapter()
216 public void mouseClicked(MouseEvent e)
218 validateSelections();
221 public void mouseReleased(MouseEvent e)
223 validateSelections();
226 tbl_summary.addKeyListener(new KeyAdapter()
229 public void keyPressed(KeyEvent evt)
231 validateSelections();
232 switch (evt.getKeyCode())
234 case KeyEvent.VK_ESCAPE: // escape key
237 case KeyEvent.VK_ENTER: // enter key
238 if (btn_view.isEnabled())
240 ok_ActionPerformed();
243 case KeyEvent.VK_TAB: // tab key
244 btn_view.requestFocus();
250 tbl_local_pdb.setAutoCreateRowSorter(true);
251 tbl_local_pdb.getTableHeader().setReorderingAllowed(false);
252 tbl_local_pdb.addMouseListener(new MouseAdapter()
254 public void mouseClicked(MouseEvent e)
256 validateSelections();
259 public void mouseReleased(MouseEvent e)
261 validateSelections();
264 tbl_local_pdb.addKeyListener(new KeyAdapter()
267 public void keyPressed(KeyEvent evt)
269 validateSelections();
270 switch (evt.getKeyCode())
272 case KeyEvent.VK_ESCAPE: // escape key
275 case KeyEvent.VK_ENTER: // enter key
276 if (btn_view.isEnabled())
278 ok_ActionPerformed();
281 case KeyEvent.VK_TAB: // tab key
282 btn_cancel.requestFocus();
288 btn_view.setFont(new java.awt.Font("Verdana", 0, 12));
289 btn_view.setText(MessageManager.getString("action.view"));
290 btn_view.addActionListener(new java.awt.event.ActionListener()
292 public void actionPerformed(ActionEvent e)
294 ok_ActionPerformed();
297 btn_view.addKeyListener(new KeyAdapter()
300 public void keyPressed(KeyEvent evt)
302 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
304 ok_ActionPerformed();
309 btn_cancel.setFont(new java.awt.Font("Verdana", 0, 12));
310 btn_cancel.setText(MessageManager.getString("action.cancel"));
311 btn_cancel.addActionListener(new java.awt.event.ActionListener()
313 public void actionPerformed(ActionEvent e)
318 btn_cancel.addKeyListener(new KeyAdapter()
321 public void keyPressed(KeyEvent evt)
323 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
330 btn_pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12));
331 String btn_title = MessageManager.getString("label.select_pdb_file");
332 btn_pdbFromFile.setText(btn_title + " ");
333 btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener()
335 public void actionPerformed(ActionEvent e)
337 pdbFromFile_actionPerformed();
340 btn_pdbFromFile.addKeyListener(new KeyAdapter()
343 public void keyPressed(KeyEvent evt)
345 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
347 pdbFromFile_actionPerformed();
352 scrl_foundStructures.setPreferredSize(new Dimension(500, 300));
354 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
356 scrl_localPDB.setPreferredSize(new Dimension(500, 300));
358 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
360 cmb_filterOption.setFont(new java.awt.Font("Verdana", 0, 12));
361 chk_invertFilter.setFont(new java.awt.Font("Verdana", 0, 12));
362 chk_rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12));
363 chk_rememberSettings.setVisible(false);
365 txt_search.setToolTipText(MessageManager
366 .getString("label.enter_pdb_id"));
367 cmb_filterOption.setToolTipText(MessageManager
368 .getString("info.select_filter_option"));
369 txt_search.getDocument().addDocumentListener(new DocumentListener()
372 public void insertUpdate(DocumentEvent e)
374 txt_search_ActionPerformed();
378 public void removeUpdate(DocumentEvent e)
380 txt_search_ActionPerformed();
384 public void changedUpdate(DocumentEvent e)
386 txt_search_ActionPerformed();
390 cmb_filterOption.addItemListener(this);
391 chk_invertFilter.addItemListener(this);
393 pnl_actions.add(chk_rememberSettings);
394 pnl_actions.add(btn_view);
395 pnl_actions.add(btn_cancel);
397 // pnl_filter.add(lbl_result);
398 pnl_main.add(cmb_filterOption);
399 pnl_main.add(lbl_loading);
400 pnl_main.add(chk_invertFilter);
401 lbl_loading.setVisible(false);
403 pnl_fileChooser.add(btn_pdbFromFile);
404 pnl_fileChooser.add(lbl_fromFileStatus);
405 pnl_fileChooserBL.add(fileChooserAssSeqPanel, BorderLayout.NORTH);
406 pnl_fileChooserBL.add(pnl_fileChooser, BorderLayout.CENTER);
408 pnl_idInput.add(txt_search);
409 pnl_idInput.add(lbl_pdbManualFetchStatus);
410 pnl_idInputBL.add(idInputAssSeqPanel, BorderLayout.NORTH);
411 pnl_idInputBL.add(pnl_idInput, BorderLayout.CENTER);
413 final String foundStructureSummary = MessageManager
414 .getString("label.found_structures_summary");
415 final String configureCols = MessageManager
416 .getString("label.configure_displayed_columns");
417 ChangeListener changeListener = new ChangeListener()
419 public void stateChanged(ChangeEvent changeEvent)
421 JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent
423 int index = sourceTabbedPane.getSelectedIndex();
424 if (sourceTabbedPane.getTitleAt(index).equals(configureCols))
426 btn_view.setEnabled(false);
427 btn_cancel.setEnabled(false);
428 previousWantedFields = PDBDocFieldPreferences
429 .getStructureSummaryFields().toArray(
430 new PDBRestClient.PDBDocField[0]);
432 if (sourceTabbedPane.getTitleAt(index)
433 .equals(foundStructureSummary))
435 btn_cancel.setEnabled(true);
436 if (wantedFieldsUpdated())
442 validateSelections();
447 pnl_filter.addChangeListener(changeListener);
448 pnl_filter.setPreferredSize(new Dimension(500, 300));
449 pnl_filter.add(foundStructureSummary, scrl_foundStructures);
450 pnl_filter.add(configureCols, pdbDocFieldPrefs);
452 pnl_locPDB.add(scrl_localPDB);
454 pnl_switchableViews.add(pnl_fileChooserBL, VIEWS_FROM_FILE);
455 pnl_switchableViews.add(pnl_idInputBL, VIEWS_ENTER_ID);
456 pnl_switchableViews.add(pnl_filter, VIEWS_FILTER);
457 pnl_switchableViews.add(pnl_locPDB, VIEWS_LOCAL_PDB);
459 this.setLayout(mainLayout);
460 this.add(pnl_main, java.awt.BorderLayout.NORTH);
461 this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER);
462 this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
464 mainFrame.setVisible(true);
465 mainFrame.setContentPane(this);
466 mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
467 Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
470 public boolean wantedFieldsUpdated()
472 if (previousWantedFields == null)
477 return Arrays.equals(PDBDocFieldPreferences.getStructureSummaryFields()
478 .toArray(new PDBRestClient.PDBDocField[0]),
479 previousWantedFields) ? false : true;
485 * Event listener for the 'filter' combo-box and 'invert' check-box
487 public void itemStateChanged(ItemEvent e)
493 * This inner class provides the data model for the structure filter combo-box
498 public class FilterOption
502 private String value;
506 public FilterOption(String name, String value, String view)
513 public String getName()
518 public void setName(String name)
523 public String getValue()
528 public void setValue(String value)
533 public String getView()
538 public void setView(String view)
543 public String toString()
550 * This inner class provides the provides the data model for associate
551 * sequence combo-box - cmb_assSeq
556 public class AssociateSeqOptions
558 private SequenceI sequence;
562 public AssociateSeqOptions(SequenceI seq)
565 this.name = (seq.getName().length() >= 23) ? seq.getName().substring(
566 0, 23) : seq.getName();
569 public AssociateSeqOptions(String name, SequenceI seq)
575 public String toString()
580 public String getName()
585 public void setName(String name)
590 public SequenceI getSequence()
595 public void setSequence(SequenceI sequence)
597 this.sequence = sequence;
603 * This inner class holds the Layout and configuration of the panel which
604 * handles association of manually fetched structures to a unique sequence
605 * when more than one sequence selection is made
610 public class AssciateSeqPanel extends JPanel implements ItemListener
612 private JComboBox<AssociateSeqOptions> cmb_assSeq = new JComboBox<AssociateSeqOptions>();
614 private JLabel lbl_associateSeq = new JLabel();
616 public AssciateSeqPanel()
618 this.setLayout(new FlowLayout());
619 this.add(cmb_assSeq);
620 this.add(lbl_associateSeq);
621 cmb_assSeq.setToolTipText(MessageManager
622 .getString("info.associate_wit_sequence"));
623 cmb_assSeq.addItemListener(this);
626 public void loadCmbAssSeq()
628 populateCmbAssociateSeqOptions(cmb_assSeq, lbl_associateSeq);
631 public JComboBox<AssociateSeqOptions> getCmb_assSeq()
636 public void setCmb_assSeq(JComboBox<AssociateSeqOptions> cmb_assSeq)
638 this.cmb_assSeq = cmb_assSeq;
642 public void itemStateChanged(ItemEvent e)
644 if (e.getStateChange() == ItemEvent.SELECTED)
646 cmbAssSeqStateChanged();
651 public JComboBox<FilterOption> getCmbFilterOption()
653 return cmb_filterOption;
656 protected abstract void stateChanged(ItemEvent e);
658 protected abstract void updateCurrentView();
660 protected abstract void populateFilterComboBox();
662 protected abstract void ok_ActionPerformed();
664 protected abstract void pdbFromFile_actionPerformed();
666 protected abstract void txt_search_ActionPerformed();
668 public abstract void populateCmbAssociateSeqOptions(
669 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq);
671 public abstract void cmbAssSeqStateChanged();
673 public abstract void tabRefresh();
675 public abstract void validateSelections();