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.GridLayout;
38 import java.awt.event.ActionEvent;
39 import java.awt.event.ItemEvent;
40 import java.awt.event.ItemListener;
41 import java.awt.event.KeyAdapter;
42 import java.awt.event.KeyEvent;
43 import java.awt.event.MouseAdapter;
44 import java.awt.event.MouseEvent;
45 import java.util.Arrays;
47 import javax.swing.ImageIcon;
48 import javax.swing.JButton;
49 import javax.swing.JCheckBox;
50 import javax.swing.JComboBox;
51 import javax.swing.JFrame;
52 import javax.swing.JInternalFrame;
53 import javax.swing.JLabel;
54 import javax.swing.JPanel;
55 import javax.swing.JScrollPane;
56 import javax.swing.JTabbedPane;
57 import javax.swing.JTable;
58 import javax.swing.JTextField;
59 import javax.swing.event.ChangeEvent;
60 import javax.swing.event.ChangeListener;
61 import javax.swing.event.DocumentEvent;
62 import javax.swing.event.DocumentListener;
64 @SuppressWarnings("serial")
66 * GUI layout for structure chooser
70 public abstract class GStructureChooser extends JPanel implements
73 protected JPanel statusPanel = new JPanel();
75 public JLabel statusBar = new JLabel();
77 private JPanel pnl_actionsAndStatus = new JPanel(new BorderLayout());
79 protected String frameTitle = MessageManager
80 .getString("label.structure_chooser");
82 protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
84 protected JComboBox<FilterOption> cmb_filterOption = new JComboBox<FilterOption>();
86 protected AlignmentPanel ap;
88 protected StringBuilder errorWarning = new StringBuilder();
90 protected JLabel lbl_result = new JLabel(
91 MessageManager.getString("label.select"));
93 protected JButton btn_view = new JButton();
95 protected JButton btn_cancel = new JButton();
97 protected JButton btn_pdbFromFile = new JButton();
99 protected JTextField txt_search = new JTextField(14);
101 private JPanel pnl_actions = new JPanel();
103 private JPanel pnl_main = new JPanel();
105 private JPanel pnl_idInput = new JPanel(new FlowLayout());
107 private JPanel pnl_fileChooser = new JPanel(new FlowLayout());
109 private JPanel pnl_idInputBL = new JPanel(new BorderLayout());
111 private JPanel pnl_fileChooserBL = new JPanel(new BorderLayout());
113 private JPanel pnl_locPDB = new JPanel(new BorderLayout());
115 protected JPanel pnl_switchableViews = new JPanel(new CardLayout());
117 protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews
120 private BorderLayout mainLayout = new BorderLayout();
122 protected JCheckBox chk_rememberSettings = new JCheckBox(
123 MessageManager.getString("label.dont_ask_me_again"));
125 protected JCheckBox chk_invertFilter = new JCheckBox(
126 MessageManager.getString("label.invert"));
128 protected ImageIcon loadingImage = new ImageIcon(getClass().getResource(
129 "/images/loading.gif"));
131 protected ImageIcon goodImage = new ImageIcon(getClass().getResource(
132 "/images/good.png"));
134 protected ImageIcon errorImage = new ImageIcon(getClass().getResource(
135 "/images/error.png"));
137 protected ImageIcon warningImage = new ImageIcon(getClass().getResource(
138 "/images/warning.gif"));
140 protected JLabel lbl_warning = new JLabel(warningImage);
142 protected JLabel lbl_loading = new JLabel(loadingImage);
144 protected JLabel lbl_pdbManualFetchStatus = new JLabel(errorImage);
146 protected JLabel lbl_fromFileStatus = new JLabel(errorImage);
148 protected AssciateSeqPanel idInputAssSeqPanel = new AssciateSeqPanel();
150 protected AssciateSeqPanel fileChooserAssSeqPanel = new AssciateSeqPanel();
152 protected static final String VIEWS_FILTER = "VIEWS_FILTER";
154 protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE";
156 protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
158 protected static final String VIEWS_LOCAL_PDB = "VIEWS_LOCAL_PDB";
160 protected JTable tbl_summary = new JTable()
163 public String getToolTipText(MouseEvent evt)
165 String toolTipText = null;
166 java.awt.Point pnt = evt.getPoint();
167 int rowIndex = rowAtPoint(pnt);
168 int colIndex = columnAtPoint(pnt);
172 toolTipText = getValueAt(rowIndex, colIndex).toString();
173 } catch (Exception e)
175 // e.printStackTrace();
177 toolTipText = (toolTipText == null ? null
178 : (toolTipText.length() > 500 ? JvSwingUtils.wrapTooltip(
179 true, "\"" + toolTipText.subSequence(0, 500)
180 + "...\"") : JvSwingUtils.wrapTooltip(true,
186 protected JScrollPane scrl_foundStructures = new JScrollPane(tbl_summary);
188 protected JTable tbl_local_pdb = new JTable();
190 protected JScrollPane scrl_localPDB = new JScrollPane(tbl_local_pdb);
192 private JTabbedPane pnl_filter = new JTabbedPane();
194 private PDBDocFieldPreferences pdbDocFieldPrefs = new PDBDocFieldPreferences(
195 PreferenceSource.STRUCTURE_CHOOSER);
197 protected PDBDocField[] previousWantedFields;
199 public GStructureChooser()
204 mainFrame.setVisible(false);
205 mainFrame.invalidate();
207 } catch (Exception e)
214 * Initializes the GUI default properties
218 private void jbInit() throws Exception
220 tbl_summary.setAutoCreateRowSorter(true);
221 tbl_summary.getTableHeader().setReorderingAllowed(false);
222 tbl_summary.addMouseListener(new MouseAdapter()
225 public void mouseClicked(MouseEvent e)
227 validateSelections();
231 public void mouseReleased(MouseEvent e)
233 validateSelections();
236 tbl_summary.addKeyListener(new KeyAdapter()
239 public void keyPressed(KeyEvent evt)
241 validateSelections();
242 switch (evt.getKeyCode())
244 case KeyEvent.VK_ESCAPE: // escape key
247 case KeyEvent.VK_ENTER: // enter key
248 if (btn_view.isEnabled())
250 ok_ActionPerformed();
253 case KeyEvent.VK_TAB: // tab key
254 if (evt.isShiftDown())
256 pnl_filter.requestFocus();
260 btn_view.requestFocus();
269 tbl_local_pdb.setAutoCreateRowSorter(true);
270 tbl_local_pdb.getTableHeader().setReorderingAllowed(false);
271 tbl_local_pdb.addMouseListener(new MouseAdapter()
274 public void mouseClicked(MouseEvent e)
276 validateSelections();
280 public void mouseReleased(MouseEvent e)
282 validateSelections();
285 tbl_local_pdb.addKeyListener(new KeyAdapter()
288 public void keyPressed(KeyEvent evt)
290 validateSelections();
291 switch (evt.getKeyCode())
293 case KeyEvent.VK_ESCAPE: // escape key
296 case KeyEvent.VK_ENTER: // enter key
297 if (btn_view.isEnabled())
299 ok_ActionPerformed();
302 case KeyEvent.VK_TAB: // tab key
303 if (evt.isShiftDown())
305 cmb_filterOption.requestFocus();
309 if (btn_view.isEnabled())
311 btn_view.requestFocus();
315 btn_cancel.requestFocus();
324 btn_view.setFont(new java.awt.Font("Verdana", 0, 12));
325 btn_view.setText(MessageManager.getString("action.view"));
326 btn_view.addActionListener(new java.awt.event.ActionListener()
329 public void actionPerformed(ActionEvent e)
331 ok_ActionPerformed();
334 btn_view.addKeyListener(new KeyAdapter()
337 public void keyPressed(KeyEvent evt)
339 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
341 ok_ActionPerformed();
346 btn_cancel.setFont(new java.awt.Font("Verdana", 0, 12));
347 btn_cancel.setText(MessageManager.getString("action.cancel"));
348 btn_cancel.addActionListener(new java.awt.event.ActionListener()
351 public void actionPerformed(ActionEvent e)
356 btn_cancel.addKeyListener(new KeyAdapter()
359 public void keyPressed(KeyEvent evt)
361 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
368 btn_pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12));
369 String btn_title = MessageManager.getString("label.select_pdb_file");
370 btn_pdbFromFile.setText(btn_title + " ");
371 btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener()
374 public void actionPerformed(ActionEvent e)
376 pdbFromFile_actionPerformed();
379 btn_pdbFromFile.addKeyListener(new KeyAdapter()
382 public void keyPressed(KeyEvent evt)
384 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
386 pdbFromFile_actionPerformed();
391 scrl_foundStructures.setPreferredSize(new Dimension(500, 300));
393 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
395 scrl_localPDB.setPreferredSize(new Dimension(500, 300));
397 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
399 cmb_filterOption.setFont(new java.awt.Font("Verdana", 0, 12));
400 chk_invertFilter.setFont(new java.awt.Font("Verdana", 0, 12));
401 chk_rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12));
402 chk_rememberSettings.setVisible(false);
404 txt_search.setToolTipText(MessageManager
405 .getString("label.enter_pdb_id"));
406 cmb_filterOption.setToolTipText(MessageManager
407 .getString("info.select_filter_option"));
408 txt_search.getDocument().addDocumentListener(new DocumentListener()
411 public void insertUpdate(DocumentEvent e)
413 txt_search_ActionPerformed();
417 public void removeUpdate(DocumentEvent e)
419 txt_search_ActionPerformed();
423 public void changedUpdate(DocumentEvent e)
425 txt_search_ActionPerformed();
429 cmb_filterOption.addItemListener(this);
430 chk_invertFilter.addItemListener(this);
432 pnl_actions.add(chk_rememberSettings);
433 pnl_actions.add(btn_view);
434 pnl_actions.add(btn_cancel);
436 // pnl_filter.add(lbl_result);
437 pnl_main.add(cmb_filterOption);
438 pnl_main.add(lbl_loading);
439 pnl_main.add(chk_invertFilter);
440 lbl_loading.setVisible(false);
442 pnl_fileChooser.add(btn_pdbFromFile);
443 pnl_fileChooser.add(lbl_fromFileStatus);
444 pnl_fileChooserBL.add(fileChooserAssSeqPanel, BorderLayout.NORTH);
445 pnl_fileChooserBL.add(pnl_fileChooser, BorderLayout.CENTER);
447 pnl_idInput.add(txt_search);
448 pnl_idInput.add(lbl_pdbManualFetchStatus);
449 pnl_idInputBL.add(idInputAssSeqPanel, BorderLayout.NORTH);
450 pnl_idInputBL.add(pnl_idInput, BorderLayout.CENTER);
452 final String foundStructureSummary = MessageManager
453 .getString("label.found_structures_summary");
454 final String configureCols = MessageManager
455 .getString("label.configure_displayed_columns");
456 ChangeListener changeListener = new ChangeListener()
459 public void stateChanged(ChangeEvent changeEvent)
461 JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent
463 int index = sourceTabbedPane.getSelectedIndex();
464 if (sourceTabbedPane.getTitleAt(index).equals(configureCols))
466 btn_view.setEnabled(false);
467 btn_cancel.setEnabled(false);
468 previousWantedFields = PDBDocFieldPreferences
469 .getStructureSummaryFields().toArray(
470 new PDBRestClient.PDBDocField[0]);
472 if (sourceTabbedPane.getTitleAt(index)
473 .equals(foundStructureSummary))
475 btn_cancel.setEnabled(true);
476 if (wantedFieldsUpdated())
482 validateSelections();
487 pnl_filter.addChangeListener(changeListener);
488 pnl_filter.setPreferredSize(new Dimension(500, 300));
489 pnl_filter.add(foundStructureSummary, scrl_foundStructures);
490 pnl_filter.add(configureCols, pdbDocFieldPrefs);
492 pnl_locPDB.add(scrl_localPDB);
494 pnl_switchableViews.add(pnl_fileChooserBL, VIEWS_FROM_FILE);
495 pnl_switchableViews.add(pnl_idInputBL, VIEWS_ENTER_ID);
496 pnl_switchableViews.add(pnl_filter, VIEWS_FILTER);
497 pnl_switchableViews.add(pnl_locPDB, VIEWS_LOCAL_PDB);
499 this.setLayout(mainLayout);
500 this.add(pnl_main, java.awt.BorderLayout.NORTH);
501 this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER);
502 // this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
503 statusPanel.setLayout(new GridLayout());
504 pnl_actionsAndStatus.add(pnl_actions, BorderLayout.CENTER);
505 pnl_actionsAndStatus.add(statusPanel, BorderLayout.SOUTH);
506 statusPanel.add(statusBar, null);
507 this.add(pnl_actionsAndStatus, java.awt.BorderLayout.SOUTH);
509 mainFrame.setVisible(true);
510 mainFrame.setContentPane(this);
511 mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
512 Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
515 public boolean wantedFieldsUpdated()
517 if (previousWantedFields == null)
522 return Arrays.equals(PDBDocFieldPreferences.getStructureSummaryFields()
523 .toArray(new PDBRestClient.PDBDocField[0]),
524 previousWantedFields) ? false : true;
530 * Event listener for the 'filter' combo-box and 'invert' check-box
532 public void itemStateChanged(ItemEvent e)
538 * This inner class provides the data model for the structure filter combo-box
543 public class FilterOption
547 private String value;
551 public FilterOption(String name, String value, String view)
558 public String getName()
563 public void setName(String name)
568 public String getValue()
573 public void setValue(String value)
578 public String getView()
583 public void setView(String view)
589 public String toString()
596 * This inner class provides the provides the data model for associate
597 * sequence combo-box - cmb_assSeq
602 public class AssociateSeqOptions
604 private SequenceI sequence;
608 public AssociateSeqOptions(SequenceI seq)
611 this.name = (seq.getName().length() >= 23) ? seq.getName().substring(
612 0, 23) : seq.getName();
615 public AssociateSeqOptions(String name, SequenceI seq)
622 public String toString()
627 public String getName()
632 public void setName(String name)
637 public SequenceI getSequence()
642 public void setSequence(SequenceI sequence)
644 this.sequence = sequence;
650 * This inner class holds the Layout and configuration of the panel which
651 * handles association of manually fetched structures to a unique sequence
652 * when more than one sequence selection is made
657 public class AssciateSeqPanel extends JPanel implements ItemListener
659 private JComboBox<AssociateSeqOptions> cmb_assSeq = new JComboBox<AssociateSeqOptions>();
661 private JLabel lbl_associateSeq = new JLabel();
663 public AssciateSeqPanel()
665 this.setLayout(new FlowLayout());
666 this.add(cmb_assSeq);
667 this.add(lbl_associateSeq);
668 cmb_assSeq.setToolTipText(MessageManager
669 .getString("info.associate_wit_sequence"));
670 cmb_assSeq.addItemListener(this);
673 public void loadCmbAssSeq()
675 populateCmbAssociateSeqOptions(cmb_assSeq, lbl_associateSeq);
678 public JComboBox<AssociateSeqOptions> getCmb_assSeq()
683 public void setCmb_assSeq(JComboBox<AssociateSeqOptions> cmb_assSeq)
685 this.cmb_assSeq = cmb_assSeq;
689 public void itemStateChanged(ItemEvent e)
691 if (e.getStateChange() == ItemEvent.SELECTED)
693 cmbAssSeqStateChanged();
698 public JComboBox<FilterOption> getCmbFilterOption()
700 return cmb_filterOption;
703 protected abstract void stateChanged(ItemEvent e);
705 protected abstract void updateCurrentView();
707 protected abstract void populateFilterComboBox();
709 protected abstract void ok_ActionPerformed();
711 protected abstract void pdbFromFile_actionPerformed();
713 protected abstract void txt_search_ActionPerformed();
715 public abstract void populateCmbAssociateSeqOptions(
716 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq);
718 public abstract void cmbAssSeqStateChanged();
720 public abstract void tabRefresh();
722 public abstract void validateSelections();