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 if (getValueAt(rowIndex, colIndex) == null)
176 toolTipText = getValueAt(rowIndex, colIndex).toString();
177 } catch (Exception e)
179 // e.printStackTrace();
181 toolTipText = (toolTipText == null ? null
182 : (toolTipText.length() > 500 ? JvSwingUtils.wrapTooltip(
183 true, "\"" + toolTipText.subSequence(0, 500)
184 + "...\"") : JvSwingUtils.wrapTooltip(true,
190 protected JScrollPane scrl_foundStructures = new JScrollPane(tbl_summary);
192 protected JTable tbl_local_pdb = new JTable();
194 protected JScrollPane scrl_localPDB = new JScrollPane(tbl_local_pdb);
196 private JTabbedPane pnl_filter = new JTabbedPane();
198 private PDBDocFieldPreferences pdbDocFieldPrefs = new PDBDocFieldPreferences(
199 PreferenceSource.STRUCTURE_CHOOSER);
201 protected PDBDocField[] previousWantedFields;
203 public GStructureChooser()
208 mainFrame.setVisible(false);
209 mainFrame.invalidate();
211 } catch (Exception e)
218 * Initializes the GUI default properties
222 private void jbInit() throws Exception
224 tbl_summary.setAutoCreateRowSorter(true);
225 tbl_summary.getTableHeader().setReorderingAllowed(false);
226 tbl_summary.addMouseListener(new MouseAdapter()
229 public void mouseClicked(MouseEvent e)
231 validateSelections();
235 public void mouseReleased(MouseEvent e)
237 validateSelections();
240 tbl_summary.addKeyListener(new KeyAdapter()
243 public void keyPressed(KeyEvent evt)
245 validateSelections();
246 switch (evt.getKeyCode())
248 case KeyEvent.VK_ESCAPE: // escape key
251 case KeyEvent.VK_ENTER: // enter key
252 if (btn_view.isEnabled())
254 ok_ActionPerformed();
257 case KeyEvent.VK_TAB: // tab key
258 if (evt.isShiftDown())
260 pnl_filter.requestFocus();
264 btn_view.requestFocus();
273 tbl_local_pdb.setAutoCreateRowSorter(true);
274 tbl_local_pdb.getTableHeader().setReorderingAllowed(false);
275 tbl_local_pdb.addMouseListener(new MouseAdapter()
278 public void mouseClicked(MouseEvent e)
280 validateSelections();
284 public void mouseReleased(MouseEvent e)
286 validateSelections();
289 tbl_local_pdb.addKeyListener(new KeyAdapter()
292 public void keyPressed(KeyEvent evt)
294 validateSelections();
295 switch (evt.getKeyCode())
297 case KeyEvent.VK_ESCAPE: // escape key
300 case KeyEvent.VK_ENTER: // enter key
301 if (btn_view.isEnabled())
303 ok_ActionPerformed();
306 case KeyEvent.VK_TAB: // tab key
307 if (evt.isShiftDown())
309 cmb_filterOption.requestFocus();
313 if (btn_view.isEnabled())
315 btn_view.requestFocus();
319 btn_cancel.requestFocus();
328 btn_view.setFont(new java.awt.Font("Verdana", 0, 12));
329 btn_view.setText(MessageManager.getString("action.view"));
330 btn_view.addActionListener(new java.awt.event.ActionListener()
333 public void actionPerformed(ActionEvent e)
335 ok_ActionPerformed();
338 btn_view.addKeyListener(new KeyAdapter()
341 public void keyPressed(KeyEvent evt)
343 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
345 ok_ActionPerformed();
350 btn_cancel.setFont(new java.awt.Font("Verdana", 0, 12));
351 btn_cancel.setText(MessageManager.getString("action.cancel"));
352 btn_cancel.addActionListener(new java.awt.event.ActionListener()
355 public void actionPerformed(ActionEvent e)
360 btn_cancel.addKeyListener(new KeyAdapter()
363 public void keyPressed(KeyEvent evt)
365 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
372 btn_pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12));
373 String btn_title = MessageManager.getString("label.select_pdb_file");
374 btn_pdbFromFile.setText(btn_title + " ");
375 btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener()
378 public void actionPerformed(ActionEvent e)
380 pdbFromFile_actionPerformed();
383 btn_pdbFromFile.addKeyListener(new KeyAdapter()
386 public void keyPressed(KeyEvent evt)
388 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
390 pdbFromFile_actionPerformed();
395 scrl_foundStructures.setPreferredSize(new Dimension(500, 300));
397 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
399 scrl_localPDB.setPreferredSize(new Dimension(500, 300));
401 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
403 cmb_filterOption.setFont(new java.awt.Font("Verdana", 0, 12));
404 chk_invertFilter.setFont(new java.awt.Font("Verdana", 0, 12));
405 chk_rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12));
406 chk_rememberSettings.setVisible(false);
408 txt_search.setToolTipText(MessageManager
409 .getString("label.enter_pdb_id"));
410 cmb_filterOption.setToolTipText(MessageManager
411 .getString("info.select_filter_option"));
412 txt_search.getDocument().addDocumentListener(new DocumentListener()
415 public void insertUpdate(DocumentEvent e)
417 txt_search_ActionPerformed();
421 public void removeUpdate(DocumentEvent e)
423 txt_search_ActionPerformed();
427 public void changedUpdate(DocumentEvent e)
429 txt_search_ActionPerformed();
433 cmb_filterOption.addItemListener(this);
434 chk_invertFilter.addItemListener(this);
436 pnl_actions.add(chk_rememberSettings);
437 pnl_actions.add(btn_view);
438 pnl_actions.add(btn_cancel);
440 // pnl_filter.add(lbl_result);
441 pnl_main.add(cmb_filterOption);
442 pnl_main.add(lbl_loading);
443 pnl_main.add(chk_invertFilter);
444 lbl_loading.setVisible(false);
446 pnl_fileChooser.add(btn_pdbFromFile);
447 pnl_fileChooser.add(lbl_fromFileStatus);
448 pnl_fileChooserBL.add(fileChooserAssSeqPanel, BorderLayout.NORTH);
449 pnl_fileChooserBL.add(pnl_fileChooser, BorderLayout.CENTER);
451 pnl_idInput.add(txt_search);
452 pnl_idInput.add(lbl_pdbManualFetchStatus);
453 pnl_idInputBL.add(idInputAssSeqPanel, BorderLayout.NORTH);
454 pnl_idInputBL.add(pnl_idInput, BorderLayout.CENTER);
456 final String foundStructureSummary = MessageManager
457 .getString("label.found_structures_summary");
458 final String configureCols = MessageManager
459 .getString("label.configure_displayed_columns");
460 ChangeListener changeListener = new ChangeListener()
463 public void stateChanged(ChangeEvent changeEvent)
465 JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent
467 int index = sourceTabbedPane.getSelectedIndex();
468 btn_view.setVisible(true);
469 btn_cancel.setVisible(true);
470 if (sourceTabbedPane.getTitleAt(index).equals(configureCols))
472 btn_view.setEnabled(false);
473 btn_cancel.setEnabled(false);
474 btn_view.setVisible(false);
475 btn_cancel.setVisible(false);
476 previousWantedFields = PDBDocFieldPreferences
477 .getStructureSummaryFields().toArray(
478 new PDBRestClient.PDBDocField[0]);
480 if (sourceTabbedPane.getTitleAt(index)
481 .equals(foundStructureSummary))
483 btn_cancel.setEnabled(true);
484 if (wantedFieldsUpdated())
490 validateSelections();
495 pnl_filter.addChangeListener(changeListener);
496 pnl_filter.setPreferredSize(new Dimension(500, 300));
497 pnl_filter.add(foundStructureSummary, scrl_foundStructures);
498 pnl_filter.add(configureCols, pdbDocFieldPrefs);
500 pnl_locPDB.add(scrl_localPDB);
502 pnl_switchableViews.add(pnl_fileChooserBL, VIEWS_FROM_FILE);
503 pnl_switchableViews.add(pnl_idInputBL, VIEWS_ENTER_ID);
504 pnl_switchableViews.add(pnl_filter, VIEWS_FILTER);
505 pnl_switchableViews.add(pnl_locPDB, VIEWS_LOCAL_PDB);
507 this.setLayout(mainLayout);
508 this.add(pnl_main, java.awt.BorderLayout.NORTH);
509 this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER);
510 // this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
511 statusPanel.setLayout(new GridLayout());
512 pnl_actionsAndStatus.add(pnl_actions, BorderLayout.CENTER);
513 pnl_actionsAndStatus.add(statusPanel, BorderLayout.SOUTH);
514 statusPanel.add(statusBar, null);
515 this.add(pnl_actionsAndStatus, java.awt.BorderLayout.SOUTH);
517 mainFrame.setVisible(true);
518 mainFrame.setContentPane(this);
519 mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
520 Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
523 public boolean wantedFieldsUpdated()
525 if (previousWantedFields == null)
530 return Arrays.equals(PDBDocFieldPreferences.getStructureSummaryFields()
531 .toArray(new PDBRestClient.PDBDocField[0]),
532 previousWantedFields) ? false : true;
538 * Event listener for the 'filter' combo-box and 'invert' check-box
540 public void itemStateChanged(ItemEvent e)
546 * This inner class provides the data model for the structure filter combo-box
551 public class FilterOption
555 private String value;
559 public FilterOption(String name, String value, String view)
566 public String getName()
571 public void setName(String name)
576 public String getValue()
581 public void setValue(String value)
586 public String getView()
591 public void setView(String view)
597 public String toString()
604 * This inner class provides the provides the data model for associate
605 * sequence combo-box - cmb_assSeq
610 public class AssociateSeqOptions
612 private SequenceI sequence;
616 public AssociateSeqOptions(SequenceI seq)
619 this.name = (seq.getName().length() >= 23) ? seq.getName().substring(
620 0, 23) : seq.getName();
623 public AssociateSeqOptions(String name, SequenceI seq)
630 public String toString()
635 public String getName()
640 public void setName(String name)
645 public SequenceI getSequence()
650 public void setSequence(SequenceI sequence)
652 this.sequence = sequence;
658 * This inner class holds the Layout and configuration of the panel which
659 * handles association of manually fetched structures to a unique sequence
660 * when more than one sequence selection is made
665 public class AssciateSeqPanel extends JPanel implements ItemListener
667 private JComboBox<AssociateSeqOptions> cmb_assSeq = new JComboBox<AssociateSeqOptions>();
669 private JLabel lbl_associateSeq = new JLabel();
671 public AssciateSeqPanel()
673 this.setLayout(new FlowLayout());
674 this.add(cmb_assSeq);
675 this.add(lbl_associateSeq);
676 cmb_assSeq.setToolTipText(MessageManager
677 .getString("info.associate_wit_sequence"));
678 cmb_assSeq.addItemListener(this);
681 public void loadCmbAssSeq()
683 populateCmbAssociateSeqOptions(cmb_assSeq, lbl_associateSeq);
686 public JComboBox<AssociateSeqOptions> getCmb_assSeq()
691 public void setCmb_assSeq(JComboBox<AssociateSeqOptions> cmb_assSeq)
693 this.cmb_assSeq = cmb_assSeq;
697 public void itemStateChanged(ItemEvent e)
699 if (e.getStateChange() == ItemEvent.SELECTED)
701 cmbAssSeqStateChanged();
706 public JComboBox<FilterOption> getCmbFilterOption()
708 return cmb_filterOption;
711 protected abstract void stateChanged(ItemEvent e);
713 protected abstract void updateCurrentView();
715 protected abstract void populateFilterComboBox();
717 protected abstract void ok_ActionPerformed();
719 protected abstract void pdbFromFile_actionPerformed();
721 protected abstract void txt_search_ActionPerformed();
723 public abstract void populateCmbAssociateSeqOptions(
724 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq);
726 public abstract void cmbAssSeqStateChanged();
728 public abstract void tabRefresh();
730 public abstract void validateSelections();