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.fts.core;
24 import jalview.fts.api.FTSDataColumnI;
25 import jalview.fts.api.FTSRestClientI;
26 import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
27 import jalview.fts.service.pdb.PDBFTSRestClient;
28 import jalview.gui.Desktop;
29 import jalview.gui.IProgressIndicator;
30 import jalview.gui.JvSwingUtils;
31 import jalview.gui.SequenceFetcher;
32 import jalview.util.MessageManager;
34 import java.awt.BorderLayout;
35 import java.awt.CardLayout;
36 import java.awt.Dimension;
37 import java.awt.event.ActionEvent;
38 import java.awt.event.ActionListener;
39 import java.awt.event.KeyAdapter;
40 import java.awt.event.KeyEvent;
41 import java.awt.event.MouseAdapter;
42 import java.awt.event.MouseEvent;
43 import java.util.ArrayList;
44 import java.util.Arrays;
45 import java.util.Collection;
46 import java.util.Collections;
47 import java.util.Comparator;
48 import java.util.List;
50 import javax.swing.ImageIcon;
51 import javax.swing.JButton;
52 import javax.swing.JComboBox;
53 import javax.swing.JFrame;
54 import javax.swing.JInternalFrame;
55 import javax.swing.JLabel;
56 import javax.swing.JPanel;
57 import javax.swing.JScrollPane;
58 import javax.swing.JTabbedPane;
59 import javax.swing.JTable;
60 import javax.swing.JTextField;
61 import javax.swing.event.ChangeEvent;
62 import javax.swing.event.ChangeListener;
63 import javax.swing.event.DocumentEvent;
64 import javax.swing.event.DocumentListener;
67 * GUI layout for PDB Fetch Panel
73 @SuppressWarnings("serial")
74 public abstract class GFTSPanel extends JPanel
76 protected JInternalFrame mainFrame = new JInternalFrame(
79 protected IProgressIndicator progressIdicator;
81 protected JComboBox<FTSDataColumnI> cmb_searchTarget = new JComboBox<FTSDataColumnI>();
83 protected JButton btn_ok = new JButton();
85 protected JButton btn_back = new JButton();
87 protected JButton btn_cancel = new JButton();
89 protected JTextField txt_search = new JTextField(20);
91 protected SequenceFetcher seqFetcher;
93 protected Collection<FTSDataColumnI> wantedFields;
95 protected JTable tbl_summary = new JTable()
98 public String getToolTipText(MouseEvent evt)
100 String toolTipText = null;
101 java.awt.Point pnt = evt.getPoint();
102 int rowIndex = rowAtPoint(pnt);
103 int colIndex = columnAtPoint(pnt);
107 if (getValueAt(rowIndex, colIndex) == null)
111 toolTipText = getValueAt(rowIndex, colIndex).toString();
113 } catch (Exception e)
117 toolTipText = (toolTipText == null ? null
118 : (toolTipText.length() > 500 ? JvSwingUtils.wrapTooltip(
119 true, toolTipText.subSequence(0, 500) + "...")
120 : JvSwingUtils.wrapTooltip(true, toolTipText)));
126 protected StringBuilder errorWarning = new StringBuilder();
128 protected JScrollPane scrl_searchResult = new JScrollPane(tbl_summary);
130 protected ImageIcon warningImage = new ImageIcon(getClass().getResource(
131 "/images/warning.gif"));
133 protected ImageIcon loadingImage = new ImageIcon(getClass().getResource(
134 "/images/loading.gif"));
136 protected JLabel lbl_warning = new JLabel(warningImage);
138 protected JLabel lbl_loading = new JLabel(loadingImage);
140 private JTabbedPane tabbedPane = new JTabbedPane();
142 private JPanel pnl_actions = new JPanel();
144 private JPanel pnl_results = new JPanel(new CardLayout());
146 private JPanel pnl_inputs = new JPanel();
148 private BorderLayout mainLayout = new BorderLayout();
150 protected Object[] previousWantedFields;
157 mainFrame.invalidate();
159 } catch (Exception e)
166 * Initializes the GUI default properties
170 private void jbInit() throws Exception
172 lbl_warning.setVisible(false);
173 lbl_warning.setFont(new java.awt.Font("Verdana", 0, 12));
174 lbl_loading.setVisible(false);
175 lbl_loading.setFont(new java.awt.Font("Verdana", 0, 12));
177 tbl_summary.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
178 tbl_summary.setAutoCreateRowSorter(true);
179 tbl_summary.getTableHeader().setReorderingAllowed(false);
180 tbl_summary.addMouseListener(new MouseAdapter()
183 public void mouseClicked(MouseEvent e)
189 public void mouseReleased(MouseEvent e)
194 tbl_summary.addKeyListener(new KeyAdapter()
197 public void keyPressed(KeyEvent evt)
200 switch (evt.getKeyCode())
202 case KeyEvent.VK_ESCAPE: // escape key
203 btn_back_ActionPerformed();
205 case KeyEvent.VK_ENTER: // enter key
206 if (btn_ok.isEnabled())
208 btn_ok_ActionPerformed();
212 case KeyEvent.VK_TAB: // tab key
213 if (evt.isShiftDown())
215 tabbedPane.requestFocus();
219 btn_back.requestFocus();
229 btn_back.setFont(new java.awt.Font("Verdana", 0, 12));
230 btn_back.setText(MessageManager.getString("action.back"));
231 btn_back.addActionListener(new java.awt.event.ActionListener()
234 public void actionPerformed(ActionEvent e)
236 btn_back_ActionPerformed();
239 btn_back.addKeyListener(new KeyAdapter()
242 public void keyPressed(KeyEvent evt)
244 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
246 btn_back_ActionPerformed();
251 btn_ok.setEnabled(false);
252 btn_ok.setFont(new java.awt.Font("Verdana", 0, 12));
253 btn_ok.setText(MessageManager.getString("action.ok"));
254 btn_ok.addActionListener(new java.awt.event.ActionListener()
257 public void actionPerformed(ActionEvent e)
259 btn_ok_ActionPerformed();
262 btn_ok.addKeyListener(new KeyAdapter()
265 public void keyPressed(KeyEvent evt)
267 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
269 btn_ok_ActionPerformed();
274 btn_cancel.setFont(new java.awt.Font("Verdana", 0, 12));
275 btn_cancel.setText(MessageManager.getString("action.cancel"));
276 btn_cancel.addActionListener(new java.awt.event.ActionListener()
279 public void actionPerformed(ActionEvent e)
281 btn_cancel_ActionPerformed();
284 btn_cancel.addKeyListener(new KeyAdapter()
287 public void keyPressed(KeyEvent evt)
289 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
291 btn_cancel_ActionPerformed();
296 scrl_searchResult.setPreferredSize(new Dimension(500, 300));
298 .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
300 cmb_searchTarget.setFont(new java.awt.Font("Verdana", 0, 12));
301 cmb_searchTarget.addActionListener(new ActionListener()
304 public void actionPerformed(ActionEvent e)
307 if ("all".equalsIgnoreCase(getCmbSearchTarget().getSelectedItem()
310 tooltipText = MessageManager.getString("label.search_all");
312 else if ("pdb id".equalsIgnoreCase(getCmbSearchTarget()
313 .getSelectedItem().toString()))
315 tooltipText = MessageManager
316 .getString("label.separate_multiple_accession_ids");
320 tooltipText = MessageManager.formatMessage(
321 "label.separate_multiple_query_values",
322 new Object[] { getCmbSearchTarget().getSelectedItem()
325 txt_search.setToolTipText(JvSwingUtils.wrapTooltip(true,
327 txt_search_ActionPerformed();
331 populateCmbSearchTargetOptions();
333 txt_search.setFont(new java.awt.Font("Verdana", 0, 12));
335 txt_search.addKeyListener(new KeyAdapter()
338 public void keyPressed(KeyEvent e)
340 if (e.getKeyCode() == KeyEvent.VK_ENTER)
342 if (txt_search.getText() == null
343 || txt_search.getText().isEmpty())
347 if ("pdb id".equalsIgnoreCase(getCmbSearchTarget()
348 .getSelectedItem().toString()))
350 transferToSequenceFetcher(txt_search.getText());
356 txt_search.getDocument().addDocumentListener(new DocumentListener()
359 public void insertUpdate(DocumentEvent e)
361 txt_search_ActionPerformed();
365 public void removeUpdate(DocumentEvent e)
367 txt_search_ActionPerformed();
371 public void changedUpdate(DocumentEvent e)
373 txt_search_ActionPerformed();
377 final String searchTabTitle = MessageManager
378 .getString("label.search_result");
379 final String configureCols = MessageManager
380 .getString("label.configure_displayed_columns");
381 ChangeListener changeListener = new ChangeListener()
384 public void stateChanged(ChangeEvent changeEvent)
386 JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent
388 int index = sourceTabbedPane.getSelectedIndex();
390 btn_back.setVisible(true);
391 btn_cancel.setVisible(true);
392 btn_ok.setVisible(true);
393 if (sourceTabbedPane.getTitleAt(index).equals(configureCols))
395 btn_back.setVisible(false);
396 btn_cancel.setVisible(false);
397 btn_ok.setVisible(false);
398 btn_back.setEnabled(false);
399 btn_cancel.setEnabled(false);
400 btn_ok.setEnabled(false);
401 previousWantedFields = PDBFTSRestClient.getInstance()
402 .getAllDefaulDisplayedDataColumns()
403 .toArray(new Object[0]);
405 if (sourceTabbedPane.getTitleAt(index).equals(searchTabTitle))
407 btn_back.setEnabled(true);
408 btn_cancel.setEnabled(true);
409 if (wantedFieldsUpdated())
411 txt_search_ActionPerformed();
420 tabbedPane.addChangeListener(changeListener);
421 tabbedPane.setPreferredSize(new Dimension(500, 300));
422 tabbedPane.add(searchTabTitle, scrl_searchResult);
423 tabbedPane.add(configureCols, new FTSDataColumnPreferences(
424 PreferenceSource.SEARCH_SUMMARY, getFTSRestClient()));
426 pnl_actions.add(btn_back);
427 pnl_actions.add(btn_ok);
428 pnl_actions.add(btn_cancel);
430 pnl_results.add(tabbedPane);
431 pnl_inputs.add(cmb_searchTarget);
432 pnl_inputs.add(txt_search);
433 pnl_inputs.add(lbl_loading);
434 pnl_inputs.add(lbl_warning);
436 this.setLayout(mainLayout);
437 this.add(pnl_inputs, java.awt.BorderLayout.NORTH);
438 this.add(pnl_results, java.awt.BorderLayout.CENTER);
439 this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
440 mainFrame.setVisible(true);
441 mainFrame.setContentPane(this);
442 mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
443 Desktop.addInternalFrame(mainFrame, getFTSFrameTitle(), 800, 400);
446 public boolean wantedFieldsUpdated()
448 if (previousWantedFields == null)
453 return Arrays.equals(PDBFTSRestClient.getInstance()
454 .getAllDefaulDisplayedDataColumns()
455 .toArray(new Object[0]), previousWantedFields) ? false
460 public void validateSelection()
462 if (tbl_summary.getSelectedRows().length > 0)
464 btn_ok.setEnabled(true);
468 btn_ok.setEnabled(false);
472 public JComboBox<FTSDataColumnI> getCmbSearchTarget()
474 return cmb_searchTarget;
477 public JTextField getTxtSearch()
482 public JInternalFrame getMainFrame()
487 protected void delayAndEnableActionButtons()
497 } catch (InterruptedException e)
501 btn_ok.setEnabled(true);
502 btn_back.setEnabled(true);
503 btn_cancel.setEnabled(true);
508 protected void checkForErrors()
510 lbl_warning.setVisible(false);
511 if (errorWarning.length() > 0)
513 lbl_loading.setVisible(false);
514 lbl_warning.setToolTipText(JvSwingUtils.wrapTooltip(true,
515 errorWarning.toString()));
516 lbl_warning.setVisible(true);
520 protected void btn_back_ActionPerformed()
523 new SequenceFetcher(progressIdicator);
526 protected void disableActionButtons()
528 btn_ok.setEnabled(false);
529 btn_back.setEnabled(false);
530 btn_cancel.setEnabled(false);
533 protected void btn_cancel_ActionPerformed()
539 * Populates search target combo-box options
541 public void populateCmbSearchTargetOptions()
543 List<FTSDataColumnI> searchableTargets = new ArrayList<FTSDataColumnI>();
546 Collection<FTSDataColumnI> foundFTSTargets = getFTSRestClient()
547 .getSearchableDataColumns();
548 searchableTargets.addAll(foundFTSTargets);
549 } catch (Exception e)
554 Collections.sort(searchableTargets, new Comparator<FTSDataColumnI>()
557 public int compare(FTSDataColumnI o1, FTSDataColumnI o2)
559 return o1.getName().compareTo(o2.getName());
563 for (FTSDataColumnI searchTarget : searchableTargets)
565 cmb_searchTarget.addItem(searchTarget);
570 public void transferToSequenceFetcher(String ids)
572 // mainFrame.dispose();
573 seqFetcher.getTextArea().setText(ids);
574 Thread worker = new Thread(seqFetcher);
578 public abstract String getFTSFrameTitle();
580 public abstract FTSRestClientI getFTSRestClient();
582 public abstract void txt_search_ActionPerformed();
584 public abstract void btn_ok_ActionPerformed();