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 btn_view.setVisible(true);
465 btn_cancel.setVisible(true);
466 if (sourceTabbedPane.getTitleAt(index).equals(configureCols))
468 btn_view.setEnabled(false);
469 btn_cancel.setEnabled(false);
470 btn_view.setVisible(false);
471 btn_cancel.setVisible(false);
472 previousWantedFields = PDBDocFieldPreferences
473 .getStructureSummaryFields().toArray(
474 new PDBRestClient.PDBDocField[0]);
476 if (sourceTabbedPane.getTitleAt(index)
477 .equals(foundStructureSummary))
479 btn_cancel.setEnabled(true);
480 if (wantedFieldsUpdated())
486 validateSelections();
491 pnl_filter.addChangeListener(changeListener);
492 pnl_filter.setPreferredSize(new Dimension(500, 300));
493 pnl_filter.add(foundStructureSummary, scrl_foundStructures);
494 pnl_filter.add(configureCols, pdbDocFieldPrefs);
496 pnl_locPDB.add(scrl_localPDB);
498 pnl_switchableViews.add(pnl_fileChooserBL, VIEWS_FROM_FILE);
499 pnl_switchableViews.add(pnl_idInputBL, VIEWS_ENTER_ID);
500 pnl_switchableViews.add(pnl_filter, VIEWS_FILTER);
501 pnl_switchableViews.add(pnl_locPDB, VIEWS_LOCAL_PDB);
503 this.setLayout(mainLayout);
504 this.add(pnl_main, java.awt.BorderLayout.NORTH);
505 this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER);
506 // this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
507 statusPanel.setLayout(new GridLayout());
508 pnl_actionsAndStatus.add(pnl_actions, BorderLayout.CENTER);
509 pnl_actionsAndStatus.add(statusPanel, BorderLayout.SOUTH);
510 statusPanel.add(statusBar, null);
511 this.add(pnl_actionsAndStatus, java.awt.BorderLayout.SOUTH);
513 mainFrame.setVisible(true);
514 mainFrame.setContentPane(this);
515 mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
516 Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
519 public boolean wantedFieldsUpdated()
521 if (previousWantedFields == null)
526 return Arrays.equals(PDBDocFieldPreferences.getStructureSummaryFields()
527 .toArray(new PDBRestClient.PDBDocField[0]),
528 previousWantedFields) ? false : true;
534 * Event listener for the 'filter' combo-box and 'invert' check-box
536 public void itemStateChanged(ItemEvent e)
542 * This inner class provides the data model for the structure filter combo-box
547 public class FilterOption
551 private String value;
555 public FilterOption(String name, String value, String view)
562 public String getName()
567 public void setName(String name)
572 public String getValue()
577 public void setValue(String value)
582 public String getView()
587 public void setView(String view)
593 public String toString()
600 * This inner class provides the provides the data model for associate
601 * sequence combo-box - cmb_assSeq
606 public class AssociateSeqOptions
608 private SequenceI sequence;
612 public AssociateSeqOptions(SequenceI seq)
615 this.name = (seq.getName().length() >= 23) ? seq.getName().substring(
616 0, 23) : seq.getName();
619 public AssociateSeqOptions(String name, SequenceI seq)
626 public String toString()
631 public String getName()
636 public void setName(String name)
641 public SequenceI getSequence()
646 public void setSequence(SequenceI sequence)
648 this.sequence = sequence;
654 * This inner class holds the Layout and configuration of the panel which
655 * handles association of manually fetched structures to a unique sequence
656 * when more than one sequence selection is made
661 public class AssciateSeqPanel extends JPanel implements ItemListener
663 private JComboBox<AssociateSeqOptions> cmb_assSeq = new JComboBox<AssociateSeqOptions>();
665 private JLabel lbl_associateSeq = new JLabel();
667 public AssciateSeqPanel()
669 this.setLayout(new FlowLayout());
670 this.add(cmb_assSeq);
671 this.add(lbl_associateSeq);
672 cmb_assSeq.setToolTipText(MessageManager
673 .getString("info.associate_wit_sequence"));
674 cmb_assSeq.addItemListener(this);
677 public void loadCmbAssSeq()
679 populateCmbAssociateSeqOptions(cmb_assSeq, lbl_associateSeq);
682 public JComboBox<AssociateSeqOptions> getCmb_assSeq()
687 public void setCmb_assSeq(JComboBox<AssociateSeqOptions> cmb_assSeq)
689 this.cmb_assSeq = cmb_assSeq;
693 public void itemStateChanged(ItemEvent e)
695 if (e.getStateChange() == ItemEvent.SELECTED)
697 cmbAssSeqStateChanged();
702 public JComboBox<FilterOption> getCmbFilterOption()
704 return cmb_filterOption;
707 protected abstract void stateChanged(ItemEvent e);
709 protected abstract void updateCurrentView();
711 protected abstract void populateFilterComboBox();
713 protected abstract void ok_ActionPerformed();
715 protected abstract void pdbFromFile_actionPerformed();
717 protected abstract void txt_search_ActionPerformed();
719 public abstract void populateCmbAssociateSeqOptions(
720 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq);
722 public abstract void cmbAssSeqStateChanged();
724 public abstract void tabRefresh();
726 public abstract void validateSelections();