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.fts.api.FTSDataColumnI;
26 import jalview.fts.core.FTSDataColumnPreferences;
27 import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
28 import jalview.fts.service.pdb.PDBFTSRestClient;
29 import jalview.gui.AlignmentPanel;
30 import jalview.gui.Desktop;
31 import jalview.gui.JvSwingUtils;
32 import jalview.util.MessageManager;
34 import java.awt.BorderLayout;
35 import java.awt.CardLayout;
36 import java.awt.Dimension;
37 import java.awt.FlowLayout;
38 import java.awt.GridLayout;
39 import java.awt.event.ActionEvent;
40 import java.awt.event.ItemEvent;
41 import java.awt.event.ItemListener;
42 import java.awt.event.KeyAdapter;
43 import java.awt.event.KeyEvent;
44 import java.awt.event.MouseAdapter;
45 import java.awt.event.MouseEvent;
46 import java.util.Arrays;
48 import javax.swing.ImageIcon;
49 import javax.swing.JButton;
50 import javax.swing.JCheckBox;
51 import javax.swing.JComboBox;
52 import javax.swing.JFrame;
53 import javax.swing.JInternalFrame;
54 import javax.swing.JLabel;
55 import javax.swing.JPanel;
56 import javax.swing.JScrollPane;
57 import javax.swing.JTabbedPane;
58 import javax.swing.JTable;
59 import javax.swing.JTextField;
60 import javax.swing.event.ChangeEvent;
61 import javax.swing.event.ChangeListener;
62 import javax.swing.event.DocumentEvent;
63 import javax.swing.event.DocumentListener;
65 @SuppressWarnings("serial")
67 * GUI layout for structure chooser
71 public abstract class GStructureChooser extends JPanel implements
74 protected JPanel statusPanel = new JPanel();
76 public JLabel statusBar = new JLabel();
78 private JPanel pnl_actionsAndStatus = new JPanel(new BorderLayout());
80 protected String frameTitle = MessageManager
81 .getString("label.structure_chooser");
83 protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
85 protected JComboBox<FilterOption> cmb_filterOption = new JComboBox<FilterOption>();
87 protected AlignmentPanel ap;
89 protected StringBuilder errorWarning = new StringBuilder();
91 protected JLabel lbl_result = new JLabel(
92 MessageManager.getString("label.select"));
94 protected JButton btn_view = new JButton();
96 protected JButton btn_cancel = new JButton();
98 protected JButton btn_pdbFromFile = new JButton();
100 protected JTextField txt_search = new JTextField(14);
102 private JPanel pnl_actions = new JPanel();
104 private JPanel pnl_main = new JPanel();
106 private JPanel pnl_idInput = new JPanel(new FlowLayout());
108 private JPanel pnl_fileChooser = new JPanel(new FlowLayout());
110 private JPanel pnl_idInputBL = new JPanel(new BorderLayout());
112 private JPanel pnl_fileChooserBL = new JPanel(new BorderLayout());
114 private JPanel pnl_locPDB = new JPanel(new BorderLayout());
116 protected JPanel pnl_switchableViews = new JPanel(new CardLayout());
118 protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews
121 private BorderLayout mainLayout = new BorderLayout();
123 protected JCheckBox chk_rememberSettings = new JCheckBox(
124 MessageManager.getString("label.dont_ask_me_again"));
126 protected JCheckBox chk_invertFilter = new JCheckBox(
127 MessageManager.getString("label.invert"));
129 protected ImageIcon loadingImage = new ImageIcon(getClass().getResource(
130 "/images/loading.gif"));
132 protected ImageIcon goodImage = new ImageIcon(getClass().getResource(
133 "/images/good.png"));
135 protected ImageIcon errorImage = new ImageIcon(getClass().getResource(
136 "/images/error.png"));
138 protected ImageIcon warningImage = new ImageIcon(getClass().getResource(
139 "/images/warning.gif"));
141 protected JLabel lbl_warning = new JLabel(warningImage);
143 protected JLabel lbl_loading = new JLabel(loadingImage);
145 protected JLabel lbl_pdbManualFetchStatus = new JLabel(errorImage);
147 protected JLabel lbl_fromFileStatus = new JLabel(errorImage);
149 protected AssciateSeqPanel idInputAssSeqPanel = new AssciateSeqPanel();
151 protected AssciateSeqPanel fileChooserAssSeqPanel = new AssciateSeqPanel();
153 protected static final String VIEWS_FILTER = "VIEWS_FILTER";
155 protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE";
157 protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
159 protected static final String VIEWS_LOCAL_PDB = "VIEWS_LOCAL_PDB";
161 protected JTable tbl_summary = new JTable()
164 public String getToolTipText(MouseEvent evt)
166 String toolTipText = null;
167 java.awt.Point pnt = evt.getPoint();
168 int rowIndex = rowAtPoint(pnt);
169 int colIndex = columnAtPoint(pnt);
173 if (getValueAt(rowIndex, colIndex) == null)
177 toolTipText = getValueAt(rowIndex, colIndex).toString();
178 } catch (Exception e)
180 // e.printStackTrace();
182 toolTipText = (toolTipText == null ? null
183 : (toolTipText.length() > 500 ? JvSwingUtils.wrapTooltip(
184 true, "\"" + toolTipText.subSequence(0, 500)
185 + "...\"") : JvSwingUtils.wrapTooltip(true,
191 protected JScrollPane scrl_foundStructures = new JScrollPane(tbl_summary);
193 protected JTable tbl_local_pdb = new JTable();
195 protected JScrollPane scrl_localPDB = new JScrollPane(tbl_local_pdb);
197 private JTabbedPane pnl_filter = new JTabbedPane();
199 private FTSDataColumnPreferences pdbDocFieldPrefs = new FTSDataColumnPreferences(
200 PreferenceSource.STRUCTURE_CHOOSER, PDBFTSRestClient.getInstance());
202 protected FTSDataColumnI[] previousWantedFields;
204 public GStructureChooser()
209 mainFrame.setVisible(false);
210 mainFrame.invalidate();
212 } catch (Exception e)
219 * Initializes the GUI default properties
223 private void jbInit() throws Exception
225 tbl_summary.setAutoCreateRowSorter(true);
226 tbl_summary.getTableHeader().setReorderingAllowed(false);
227 tbl_summary.addMouseListener(new MouseAdapter()
230 public void mouseClicked(MouseEvent e)
232 validateSelections();
236 public void mouseReleased(MouseEvent e)
238 validateSelections();
241 tbl_summary.addKeyListener(new KeyAdapter()
244 public void keyPressed(KeyEvent evt)
246 validateSelections();
247 switch (evt.getKeyCode())
249 case KeyEvent.VK_ESCAPE: // escape key
252 case KeyEvent.VK_ENTER: // enter key
253 if (btn_view.isEnabled())
255 ok_ActionPerformed();
258 case KeyEvent.VK_TAB: // tab key
259 if (evt.isShiftDown())
261 pnl_filter.requestFocus();
265 btn_view.requestFocus();
274 tbl_local_pdb.setAutoCreateRowSorter(true);
275 tbl_local_pdb.getTableHeader().setReorderingAllowed(false);
276 tbl_local_pdb.addMouseListener(new MouseAdapter()
279 public void mouseClicked(MouseEvent e)
281 validateSelections();
285 public void mouseReleased(MouseEvent e)
287 validateSelections();
290 tbl_local_pdb.addKeyListener(new KeyAdapter()
293 public void keyPressed(KeyEvent evt)
295 validateSelections();
296 switch (evt.getKeyCode())
298 case KeyEvent.VK_ESCAPE: // escape key
301 case KeyEvent.VK_ENTER: // enter key
302 if (btn_view.isEnabled())
304 ok_ActionPerformed();
307 case KeyEvent.VK_TAB: // tab key
308 if (evt.isShiftDown())
310 cmb_filterOption.requestFocus();
314 if (btn_view.isEnabled())
316 btn_view.requestFocus();
320 btn_cancel.requestFocus();
329 btn_view.setFont(new java.awt.Font("Verdana", 0, 12));
330 btn_view.setText(MessageManager.getString("action.view"));
331 btn_view.addActionListener(new java.awt.event.ActionListener()
334 public void actionPerformed(ActionEvent e)
336 ok_ActionPerformed();
339 btn_view.addKeyListener(new KeyAdapter()
342 public void keyPressed(KeyEvent evt)
344 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
346 ok_ActionPerformed();
351 btn_cancel.setFont(new java.awt.Font("Verdana", 0, 12));
352 btn_cancel.setText(MessageManager.getString("action.cancel"));
353 btn_cancel.addActionListener(new java.awt.event.ActionListener()
356 public void actionPerformed(ActionEvent e)
361 btn_cancel.addKeyListener(new KeyAdapter()
364 public void keyPressed(KeyEvent evt)
366 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
373 btn_pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12));
374 String btn_title = MessageManager.getString("label.select_pdb_file");
375 btn_pdbFromFile.setText(btn_title + " ");
376 btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener()
379 public void actionPerformed(ActionEvent e)
381 pdbFromFile_actionPerformed();
384 btn_pdbFromFile.addKeyListener(new KeyAdapter()
387 public void keyPressed(KeyEvent evt)
389 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
391 pdbFromFile_actionPerformed();
396 scrl_foundStructures.setPreferredSize(new Dimension(500, 300));
398 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
400 scrl_localPDB.setPreferredSize(new Dimension(500, 300));
402 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
404 cmb_filterOption.setFont(new java.awt.Font("Verdana", 0, 12));
405 chk_invertFilter.setFont(new java.awt.Font("Verdana", 0, 12));
406 chk_rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12));
407 chk_rememberSettings.setVisible(false);
409 txt_search.setToolTipText(MessageManager
410 .getString("label.enter_pdb_id"));
411 cmb_filterOption.setToolTipText(MessageManager
412 .getString("info.select_filter_option"));
413 txt_search.getDocument().addDocumentListener(new DocumentListener()
416 public void insertUpdate(DocumentEvent e)
418 txt_search_ActionPerformed();
422 public void removeUpdate(DocumentEvent e)
424 txt_search_ActionPerformed();
428 public void changedUpdate(DocumentEvent e)
430 txt_search_ActionPerformed();
434 cmb_filterOption.addItemListener(this);
435 chk_invertFilter.addItemListener(this);
437 pnl_actions.add(chk_rememberSettings);
438 pnl_actions.add(btn_view);
439 pnl_actions.add(btn_cancel);
441 // pnl_filter.add(lbl_result);
442 pnl_main.add(cmb_filterOption);
443 pnl_main.add(lbl_loading);
444 pnl_main.add(chk_invertFilter);
445 lbl_loading.setVisible(false);
447 pnl_fileChooser.add(btn_pdbFromFile);
448 pnl_fileChooser.add(lbl_fromFileStatus);
449 pnl_fileChooserBL.add(fileChooserAssSeqPanel, BorderLayout.NORTH);
450 pnl_fileChooserBL.add(pnl_fileChooser, BorderLayout.CENTER);
452 pnl_idInput.add(txt_search);
453 pnl_idInput.add(lbl_pdbManualFetchStatus);
454 pnl_idInputBL.add(idInputAssSeqPanel, BorderLayout.NORTH);
455 pnl_idInputBL.add(pnl_idInput, BorderLayout.CENTER);
457 final String foundStructureSummary = MessageManager
458 .getString("label.found_structures_summary");
459 final String configureCols = MessageManager
460 .getString("label.configure_displayed_columns");
461 ChangeListener changeListener = new ChangeListener()
464 public void stateChanged(ChangeEvent changeEvent)
466 JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent
468 int index = sourceTabbedPane.getSelectedIndex();
469 btn_view.setVisible(true);
470 btn_cancel.setVisible(true);
471 if (sourceTabbedPane.getTitleAt(index).equals(configureCols))
473 btn_view.setEnabled(false);
474 btn_cancel.setEnabled(false);
475 btn_view.setVisible(false);
476 btn_cancel.setVisible(false);
477 previousWantedFields = PDBFTSRestClient.getInstance()
478 .getAllDefaulDisplayedDataColumns()
479 .toArray(new FTSDataColumnI[0]);
481 if (sourceTabbedPane.getTitleAt(index)
482 .equals(foundStructureSummary))
484 btn_cancel.setEnabled(true);
485 if (wantedFieldsUpdated())
491 validateSelections();
496 pnl_filter.addChangeListener(changeListener);
497 pnl_filter.setPreferredSize(new Dimension(500, 300));
498 pnl_filter.add(foundStructureSummary, scrl_foundStructures);
499 pnl_filter.add(configureCols, pdbDocFieldPrefs);
501 pnl_locPDB.add(scrl_localPDB);
503 pnl_switchableViews.add(pnl_fileChooserBL, VIEWS_FROM_FILE);
504 pnl_switchableViews.add(pnl_idInputBL, VIEWS_ENTER_ID);
505 pnl_switchableViews.add(pnl_filter, VIEWS_FILTER);
506 pnl_switchableViews.add(pnl_locPDB, VIEWS_LOCAL_PDB);
508 this.setLayout(mainLayout);
509 this.add(pnl_main, java.awt.BorderLayout.NORTH);
510 this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER);
511 // this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
512 statusPanel.setLayout(new GridLayout());
513 pnl_actionsAndStatus.add(pnl_actions, BorderLayout.CENTER);
514 pnl_actionsAndStatus.add(statusPanel, BorderLayout.SOUTH);
515 statusPanel.add(statusBar, null);
516 this.add(pnl_actionsAndStatus, java.awt.BorderLayout.SOUTH);
518 mainFrame.setVisible(true);
519 mainFrame.setContentPane(this);
520 mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
521 Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
524 public boolean wantedFieldsUpdated()
526 if (previousWantedFields == null)
531 return Arrays.equals(
532 PDBFTSRestClient.getInstance()
533 .getAllDefaulDisplayedDataColumns()
534 .toArray(new FTSDataColumnI[0]),
535 previousWantedFields) ? false : true;
541 * Event listener for the 'filter' combo-box and 'invert' check-box
543 public void itemStateChanged(ItemEvent e)
549 * This inner class provides the data model for the structure filter combo-box
554 public class FilterOption
558 private String value;
562 public FilterOption(String name, String value, String view)
569 public String getName()
574 public void setName(String name)
579 public String getValue()
584 public void setValue(String value)
589 public String getView()
594 public void setView(String view)
600 public String toString()
607 * This inner class provides the provides the data model for associate
608 * sequence combo-box - cmb_assSeq
613 public class AssociateSeqOptions
615 private SequenceI sequence;
619 public AssociateSeqOptions(SequenceI seq)
622 this.name = (seq.getName().length() >= 23) ? seq.getName().substring(
623 0, 23) : seq.getName();
626 public AssociateSeqOptions(String name, SequenceI seq)
633 public String toString()
638 public String getName()
643 public void setName(String name)
648 public SequenceI getSequence()
653 public void setSequence(SequenceI sequence)
655 this.sequence = sequence;
661 * This inner class holds the Layout and configuration of the panel which
662 * handles association of manually fetched structures to a unique sequence
663 * when more than one sequence selection is made
668 public class AssciateSeqPanel extends JPanel implements ItemListener
670 private JComboBox<AssociateSeqOptions> cmb_assSeq = new JComboBox<AssociateSeqOptions>();
672 private JLabel lbl_associateSeq = new JLabel();
674 public AssciateSeqPanel()
676 this.setLayout(new FlowLayout());
677 this.add(cmb_assSeq);
678 this.add(lbl_associateSeq);
679 cmb_assSeq.setToolTipText(MessageManager
680 .getString("info.associate_wit_sequence"));
681 cmb_assSeq.addItemListener(this);
684 public void loadCmbAssSeq()
686 populateCmbAssociateSeqOptions(cmb_assSeq, lbl_associateSeq);
689 public JComboBox<AssociateSeqOptions> getCmb_assSeq()
694 public void setCmb_assSeq(JComboBox<AssociateSeqOptions> cmb_assSeq)
696 this.cmb_assSeq = cmb_assSeq;
700 public void itemStateChanged(ItemEvent e)
702 if (e.getStateChange() == ItemEvent.SELECTED)
704 cmbAssSeqStateChanged();
709 public JComboBox<FilterOption> getCmbFilterOption()
711 return cmb_filterOption;
714 protected abstract void stateChanged(ItemEvent e);
716 protected abstract void updateCurrentView();
718 protected abstract void populateFilterComboBox();
720 protected abstract void ok_ActionPerformed();
722 protected abstract void pdbFromFile_actionPerformed();
724 protected abstract void txt_search_ActionPerformed();
726 public abstract void populateCmbAssociateSeqOptions(
727 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq);
729 public abstract void cmbAssSeqStateChanged();
731 public abstract void tabRefresh();
733 public abstract void validateSelections();