Clover icon

Coverage Report

  1. Project Clover database Thu Jun 4 2026 15:31:54 BST
  2. Package jalview.jbgui

File GStructureChooser.java

 

Coverage histogram

../../img/srcFileCovDistChart6.png
37% of files have more coverage

Code metrics

68
333
56
4
1,092
856
102
0.31
5.95
14
1.82

Classes

Class Line # Actions
GStructureChooser 91 306 84
0.5560975755.6%
GStructureChooser.AssociateSeqOptions 904 9 8
0.277777827.8%
GStructureChooser.AssociateSeqPanel 960 10 6
0.823529482.4%
GStructureChooser.CustomComboSeparatorsRenderer 1018 8 4
1.0100%
 

Contributing tests

This file is covered by 37 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21   
22    package jalview.jbgui;
23   
24    import java.awt.BorderLayout;
25    import java.awt.CardLayout;
26    import java.awt.Component;
27    import java.awt.Dimension;
28    import java.awt.FlowLayout;
29    import java.awt.Font;
30    import java.awt.GridBagConstraints;
31    import java.awt.GridBagLayout;
32    import java.awt.GridLayout;
33    import java.awt.Insets;
34    import java.awt.Point;
35    import java.awt.event.ActionEvent;
36    import java.awt.event.ActionListener;
37    import java.awt.event.ItemEvent;
38    import java.awt.event.ItemListener;
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.Arrays;
44    import java.util.HashMap;
45    import java.util.Map;
46   
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.JList;
55    import javax.swing.JPanel;
56    import javax.swing.JScrollPane;
57    import javax.swing.JSeparator;
58    import javax.swing.JTabbedPane;
59    import javax.swing.JTable;
60    import javax.swing.JTextField;
61    import javax.swing.ListCellRenderer;
62    import javax.swing.SwingConstants;
63    import javax.swing.Timer;
64    import javax.swing.event.ChangeEvent;
65    import javax.swing.event.ChangeListener;
66    import javax.swing.event.DocumentEvent;
67    import javax.swing.event.DocumentListener;
68    import javax.swing.event.InternalFrameEvent;
69    import javax.swing.table.TableColumn;
70   
71    import jalview.datamodel.SequenceI;
72    import jalview.fts.api.FTSDataColumnI;
73    import jalview.fts.core.FTSDataColumnPreferences;
74    import jalview.gui.AlignmentPanel;
75    import jalview.gui.Desktop;
76    import jalview.gui.JvSwingUtils;
77    import jalview.gui.StructureViewer;
78    import jalview.structure.StructureImportSettings;
79    import jalview.structure.StructureImportSettings.TFType;
80    import jalview.util.MessageManager;
81    import jalview.util.Platform;
82    import net.miginfocom.swing.MigLayout;
83   
84    @SuppressWarnings("serial")
85    /**
86    * GUI layout for structure chooser
87    *
88    * @author tcnofoegbu
89    *
90    */
 
91    public abstract class GStructureChooser extends JPanel
92    implements ItemListener
93    {
94    private static final Font VERDANA_12 = new Font("Verdana", 0, 12);
95   
96    private static final Font VERDANA_10 = new Font("Verdana", 0, 10);
97   
98    public static final String VIEWS_FILTER = "VIEWS_FILTER";
99   
100    protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE";
101   
102    protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
103   
104    /*
105    * 'cached' structure view
106    */
107    protected static final String VIEWS_LOCAL_PDB = "VIEWS_LOCAL_PDB";
108   
109    protected JPanel actionsPanel;
110   
111    protected JPanel statusPanel = new JPanel();
112   
113    public JLabel statusBar = new JLabel();
114   
115    protected String frameTitle = MessageManager
116    .getString("label.structure_chooser");
117   
118    protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
119   
120    protected JComboBox<FilterOption> cmb_filterOption = new JComboBox<>();
121   
122    protected AlignmentPanel ap;
123   
124    protected StringBuilder errorWarning = new StringBuilder();
125   
126    protected JButton btn_cancel;
127   
128    protected JButton btn_add;
129   
130    protected JButton btn_newView;
131   
132    protected JButton btn_pdbFromFile = new JButton();
133   
134    protected JLabel lbl_pdbFile = new JLabel();
135   
136    protected JLabel lbl_chooseTempFacType = new JLabel();
137   
138    protected JComboBox<StructureImportSettings.TFType> combo_tempFacAs = new JComboBox<>();
139   
140    protected JTextField chains = new JTextField();
141   
142    protected boolean tempFacAsChanged = false;
143   
144    protected JButton btn_paeMatrixFile = new JButton();
145   
146    protected JLabel lbl_paeFile = new JLabel();
147   
148    // holder for icon and button
149    protected JPanel pnl_queryTDB;
150   
151    protected JButton btn_queryTDB = new JButton();
152   
153    protected JCheckBox chk_superpose = new JCheckBox(
154    MessageManager.getString("label.superpose_structures"));
155   
156    protected JTextField txt_search = new JTextField(14);
157   
158    protected JPanel pnl_switchableViews = new JPanel(new CardLayout());
159   
160    protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews
161    .getLayout());
162   
163    protected JCheckBox chk_invertFilter = new JCheckBox(
164    MessageManager.getString("label.invert"));
165   
166    protected ImageIcon loadingImage = new ImageIcon(
167    getClass().getResource("/images/loading.gif"));
168   
169    protected ImageIcon goodImage = new ImageIcon(
170    getClass().getResource("/images/good.png"));
171   
172    protected ImageIcon errorImage = new ImageIcon(
173    getClass().getResource("/images/error.png"));
174   
175    protected ImageIcon warningImage = new ImageIcon(
176    getClass().getResource("/images/warning.gif"));
177   
178    protected ImageIcon tdbImage = new ImageIcon(getClass()
179    .getResource("/images/3d-beacons-logo-transparent.png"));
180   
181    protected JLabel lbl_loading = new JLabel(loadingImage);
182   
183    protected JLabel lbl_pdbManualFetchStatus = new JLabel(errorImage);
184   
185    // protected JLabel lbl_fromFileStatus = new JLabel(errorImage);
186   
187    protected AssociateSeqPanel idInputAssSeqPanel = new AssociateSeqPanel();
188   
189    protected AssociateSeqPanel fileChooserAssSeqPanel = new AssociateSeqPanel();
190   
191    protected JComboBox<StructureViewer> targetView = new JComboBox<>();
192   
193    protected JTable tbl_local_pdb = new JTable();
194   
195    protected JTabbedPane pnl_filter = new JTabbedPane();
196   
197    protected abstract FTSDataColumnPreferences getFTSDocFieldPrefs();
198   
199    protected abstract void setFTSDocFieldPrefs(
200    FTSDataColumnPreferences newPrefs);
201   
202    protected FTSDataColumnI[] previousWantedFields;
203   
204    protected static Map<String, Integer> tempUserPrefs = new HashMap<>();
205   
206    private JTable tbl_summary = new JTable()
207    {
208    private boolean inLayout;
209   
 
210  927 toggle @Override
211    public boolean getScrollableTracksViewportWidth()
212    {
213  927 return hasExcessWidth();
214   
215    }
216   
 
217  127 toggle @Override
218    public void doLayout()
219    {
220  127 if (hasExcessWidth())
221    {
222  117 autoResizeMode = AUTO_RESIZE_SUBSEQUENT_COLUMNS;
223    }
224  127 inLayout = true;
225  127 super.doLayout();
226  127 inLayout = false;
227  127 autoResizeMode = AUTO_RESIZE_OFF;
228    }
229   
 
230  1054 toggle protected boolean hasExcessWidth()
231    {
232  1054 return getPreferredSize().width < getParent().getWidth();
233    }
234   
 
235  148 toggle @Override
236    public void columnMarginChanged(ChangeEvent e)
237    {
238  148 if (isEditing())
239    {
240  0 removeEditor();
241    }
242  148 TableColumn resizingColumn = getTableHeader().getResizingColumn();
243    // Need to do this here, before the parent's
244    // layout manager calls getPreferredSize().
245  148 if (resizingColumn != null && autoResizeMode == AUTO_RESIZE_OFF
246    && !inLayout)
247    {
248  0 resizingColumn.setPreferredWidth(resizingColumn.getWidth());
249  0 String colHeader = resizingColumn.getHeaderValue().toString();
250  0 tempUserPrefs.put(colHeader, resizingColumn.getWidth());
251    }
252  148 resizeAndRepaint();
253    }
254   
 
255  0 toggle @Override
256    public String getToolTipText(MouseEvent evt)
257    {
258  0 String toolTipText = null;
259  0 java.awt.Point pnt = evt.getPoint();
260  0 int rowIndex = rowAtPoint(pnt);
261  0 int colIndex = columnAtPoint(pnt);
262   
263  0 try
264    {
265  0 if (getValueAt(rowIndex, colIndex) == null)
266    {
267  0 return null;
268    }
269  0 toolTipText = getValueAt(rowIndex, colIndex).toString();
270    } catch (Exception e)
271    {
272    // e.printStackTrace();
273    }
274  0 toolTipText = (toolTipText == null ? null
275  0 : (toolTipText.length() > 500
276    ? JvSwingUtils.wrapTooltip(true,
277    "\"" + toolTipText.subSequence(0, 500)
278    + "...\"")
279    : JvSwingUtils.wrapTooltip(true, toolTipText)));
280  0 return toolTipText;
281    }
282    };
283   
 
284  57 toggle public GStructureChooser()
285    {
286    }
287   
 
288  57 toggle protected void initDialog()
289    {
290   
291  57 try
292    {
293  57 jbInit();
294  57 mainFrame.setFrameIcon(null);
295  57 mainFrame.setVisible(false);
296  57 mainFrame.invalidate();
297  57 mainFrame.pack();
298    } catch (Exception e)
299    {
300  0 jalview.bin.Console.outPrintln(e); // for JavaScript TypeError
301  0 e.printStackTrace();
302    }
303    }
304   
305    // BH SwingJS optimization
306    // (a) 100-ms interruptable timer for text entry -- BH 1/10/2019
307    // (b) two-character minimum, at least for JavaScript.
308   
309    private Timer timer;
310   
 
311  0 toggle protected void txt_search_ActionPerformedDelayed()
312    {
313  0 if (timer != null)
314    {
315  0 timer.stop();
316    }
317  0 timer = new Timer(300, new ActionListener()
318    {
319   
 
320  0 toggle @Override
321    public void actionPerformed(ActionEvent e)
322    {
323  0 txt_search_ActionPerformed();
324    }
325    });
326  0 timer.setRepeats(false);
327  0 timer.start();
328    }
329    //
330   
331    /**
332    * Initializes the GUI default properties
333    *
334    * @throws Exception
335    */
 
336  57 toggle private void jbInit() throws Exception
337    {
338  57 Integer width = tempUserPrefs.get("structureChooser.width") == null
339    ? 800
340    : tempUserPrefs.get("structureChooser.width");
341  57 Integer height = tempUserPrefs.get("structureChooser.height") == null
342    ? 400
343    : tempUserPrefs.get("structureChooser.height");
344  57 tbl_summary.setAutoCreateRowSorter(true);
345  57 tbl_summary.getTableHeader().setReorderingAllowed(false);
346  57 tbl_summary.addMouseListener(new MouseAdapter()
347    {
 
348  0 toggle @Override
349    public void mousePressed(MouseEvent e)
350    {
351  0 if (!popupAction(e))
352    {
353  0 super.mousePressed(e);
354    }
355    }
356   
 
357  0 toggle @Override
358    public void mouseClicked(MouseEvent e)
359    {
360  0 if (!popupAction(e))
361    {
362  0 validateSelections();
363    }
364    }
365   
 
366  0 toggle @Override
367    public void mouseReleased(MouseEvent e)
368    {
369  0 if (!popupAction(e))
370    {
371  0 validateSelections();
372    }
373    }
374   
 
375  0 toggle boolean popupAction(MouseEvent e)
376    {
377  0 if (e.isPopupTrigger())
378    {
379  0 Point pt = e.getPoint();
380  0 int selectedRow = tbl_summary.rowAtPoint(pt);
381  0 if (showPopupFor(selectedRow, pt.x, pt.y))
382    {
383  0 return true;
384    }
385    }
386  0 return false;
387    }
388    });
389  57 tbl_summary.addKeyListener(new KeyAdapter()
390    {
 
391  0 toggle @Override
392    public void keyPressed(KeyEvent evt)
393    {
394  0 validateSelections();
395  0 switch (evt.getKeyCode())
396    {
397  0 case KeyEvent.VK_ESCAPE: // escape key
398  0 mainFrame.dispose();
399  0 break;
400  0 case KeyEvent.VK_ENTER: // enter key
401  0 if (btn_add.isEnabled())
402    {
403  0 add_ActionPerformed();
404    }
405  0 break;
406  0 case KeyEvent.VK_TAB: // tab key
407  0 if (evt.isShiftDown())
408    {
409  0 pnl_filter.requestFocus();
410    }
411    else
412    {
413  0 btn_add.requestFocus();
414    }
415  0 evt.consume();
416  0 break;
417  0 default:
418  0 return;
419    }
420    }
421    });
422   
423  57 btn_cancel = new JButton(MessageManager.getString("action.cancel"));
424  57 btn_cancel.setFont(VERDANA_12);
425  57 btn_cancel.addActionListener(new ActionListener()
426    {
 
427  0 toggle @Override
428    public void actionPerformed(ActionEvent e)
429    {
430  0 closeAction(pnl_filter.getHeight());
431    }
432    });
433  57 btn_cancel.addKeyListener(new KeyAdapter()
434    {
 
435  0 toggle @Override
436    public void keyPressed(KeyEvent evt)
437    {
438  0 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
439    {
440  0 closeAction(pnl_filter.getHeight());
441    }
442    }
443    });
444   
445  57 tbl_local_pdb.setAutoCreateRowSorter(true);
446  57 tbl_local_pdb.getTableHeader().setReorderingAllowed(false);
447  57 tbl_local_pdb.addMouseListener(new MouseAdapter()
448    {
 
449  0 toggle @Override
450    public void mouseClicked(MouseEvent e)
451    {
452  0 validateSelections();
453    }
454   
 
455  0 toggle @Override
456    public void mouseReleased(MouseEvent e)
457    {
458  0 validateSelections();
459    }
460    });
461  57 tbl_local_pdb.addKeyListener(new KeyAdapter()
462    {
 
463  0 toggle @Override
464    public void keyPressed(KeyEvent evt)
465    {
466  0 validateSelections();
467  0 switch (evt.getKeyCode())
468    {
469  0 case KeyEvent.VK_ESCAPE: // escape key
470  0 mainFrame.dispose();
471  0 break;
472  0 case KeyEvent.VK_ENTER: // enter key
473  0 if (btn_add.isEnabled())
474    {
475  0 add_ActionPerformed();
476    }
477  0 break;
478  0 case KeyEvent.VK_TAB: // tab key
479  0 if (evt.isShiftDown())
480    {
481  0 cmb_filterOption.requestFocus();
482    }
483    else
484    {
485  0 if (btn_add.isEnabled())
486    {
487  0 btn_add.requestFocus();
488    }
489    else
490    {
491  0 btn_cancel.requestFocus();
492    }
493    }
494  0 evt.consume();
495  0 break;
496  0 default:
497  0 return;
498    }
499    }
500    });
501   
502  57 btn_newView = new JButton(
503    MessageManager.formatMessage("action.new_structure_view_with",
504    StructureViewer.getViewerType().toString()));
505  57 btn_newView.setFont(VERDANA_12);
506  57 btn_newView.addActionListener(new ActionListener()
507    {
 
508  0 toggle @Override
509    public void actionPerformed(ActionEvent e)
510    {
511  0 newView_ActionPerformed();
512    }
513    });
514  57 btn_newView.addKeyListener(new KeyAdapter()
515    {
 
516  0 toggle @Override
517    public void keyPressed(KeyEvent evt)
518    {
519  0 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
520    {
521  0 newView_ActionPerformed();
522    }
523    }
524    });
525   
526    // TODO: JAL-3898 - get list of available external programs to view
527    // structures with
528   
529  57 btn_add = new JButton(MessageManager.getString("action.add"));
530  57 btn_add.setFont(VERDANA_12);
531  57 btn_add.addActionListener(new ActionListener()
532    {
 
533  0 toggle @Override
534    public void actionPerformed(ActionEvent e)
535    {
536  0 add_ActionPerformed();
537    }
538    });
539  57 btn_add.addKeyListener(new KeyAdapter()
540    {
 
541  0 toggle @Override
542    public void keyPressed(KeyEvent evt)
543    {
544  0 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
545    {
546  0 add_ActionPerformed();
547    }
548    }
549    });
550   
551  57 btn_pdbFromFile.setFont(VERDANA_12);
552  57 String btn_title = MessageManager.getString("label.select_pdb_file");
553  57 btn_pdbFromFile.setText(btn_title + " ");
554  57 btn_pdbFromFile.addActionListener(new ActionListener()
555    {
 
556  0 toggle @Override
557    public void actionPerformed(ActionEvent e)
558    {
559  0 pdbFromFile_actionPerformed();
560    }
561    });
562  57 btn_pdbFromFile.addKeyListener(new KeyAdapter()
563    {
 
564  0 toggle @Override
565    public void keyPressed(KeyEvent evt)
566    {
567  0 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
568    {
569  0 pdbFromFile_actionPerformed();
570    }
571    }
572    });
573  57 lbl_pdbFile.setFont(VERDANA_10);
574  57 lbl_pdbFile.setFont(VERDANA_10);
575   
576  57 lbl_chooseTempFacType.setFont(VERDANA_12);
577  57 lbl_chooseTempFacType.setText(
578    MessageManager.getString("label.interpret_tempfac_as"));
579   
580  57 combo_tempFacAs.setFont(VERDANA_12);
581  57 for (TFType t : TFType.values())
582    {
583  171 combo_tempFacAs.addItem(t);
584    }
585  57 combo_tempFacAs.addItemListener(new ItemListener()
586    {
 
587  0 toggle @Override
588    public void itemStateChanged(ItemEvent e)
589    {
590    // used to determine if we should guess pLDDT or leave a user-choice
591  0 tempFacAsChanged = true;
592    }
593    });
594  57 chains.setFont(VERDANA_12);
595  57 chains.setText("*");
596  57 chains.setToolTipText("Enter chains to map");
597   
598  57 btn_paeMatrixFile.setFont(VERDANA_12);
599  57 btn_paeMatrixFile
600    .setText(MessageManager.getString("label.add_pae_matrix_file"));
601  57 btn_paeMatrixFile.addActionListener(new ActionListener()
602    {
 
603  0 toggle @Override
604    public void actionPerformed(ActionEvent e)
605    {
606  0 paeMatrixFile_actionPerformed();
607    }
608    });
609  57 btn_paeMatrixFile.addKeyListener(new KeyAdapter()
610    {
 
611  0 toggle @Override
612    public void keyPressed(KeyEvent evt)
613    {
614  0 if (evt.getKeyCode() == KeyEvent.VK_ENTER)
615    {
616  0 paeMatrixFile_actionPerformed();
617    }
618    }
619    });
620  57 lbl_paeFile.setFont(VERDANA_10);
621   
622  57 JScrollPane scrl_foundStructures = new JScrollPane(tbl_summary);
623  57 scrl_foundStructures.setPreferredSize(new Dimension(width, height));
624   
625  57 JScrollPane scrl_localPDB = new JScrollPane(tbl_local_pdb);
626  57 scrl_localPDB.setPreferredSize(new Dimension(width, height));
627  57 scrl_localPDB.setHorizontalScrollBarPolicy(
628    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
629   
630  57 chk_invertFilter.setFont(VERDANA_12);
631  57 txt_search.setToolTipText(JvSwingUtils.wrapTooltip(true,
632    MessageManager.getString("label.enter_pdb_id_tip")));
633  57 txt_search.getDocument().addDocumentListener(new DocumentListener()
634    {
 
635  0 toggle @Override
636    public void insertUpdate(DocumentEvent e)
637    {
638  0 txt_search_ActionPerformedDelayed();
639    }
640   
 
641  0 toggle @Override
642    public void removeUpdate(DocumentEvent e)
643    {
644  0 txt_search_ActionPerformedDelayed();
645    }
646   
 
647  0 toggle @Override
648    public void changedUpdate(DocumentEvent e)
649    {
650  0 txt_search_ActionPerformedDelayed();
651    }
652    });
653   
654  57 cmb_filterOption.setFont(VERDANA_12);
655  57 cmb_filterOption.setToolTipText(
656    MessageManager.getString("info.select_filter_option"));
657  57 cmb_filterOption.addItemListener(this);
658    // add CustomComboSeparatorsRenderer to filter option combo-box
659  57 cmb_filterOption.setRenderer(new CustomComboSeparatorsRenderer(
660    (ListCellRenderer<Object>) cmb_filterOption.getRenderer())
661    {
 
662  23 toggle @Override
663    protected boolean addSeparatorAfter(JList list, FilterOption value,
664    int index)
665    {
666  23 return value.isAddSeparatorAfter();
667    }
668    });
669   
670  57 chk_invertFilter.addItemListener(this);
671  57 btn_queryTDB = new JButton();
672  57 if (Platform.isMac())
673    {
674    // needed to make icon button have round corners in vaqua
675  0 btn_queryTDB.putClientProperty("JButton.buttonType", "bevel");
676    }
677  57 btn_queryTDB.setMargin(new Insets(0, 16, 0, 20));
678  57 btn_queryTDB
679    .setText(MessageManager.getString("label.search_3dbeacons"));
680  57 btn_queryTDB.setIconTextGap(12);
681  57 btn_queryTDB.setIcon(tdbImage);
682  57 btn_queryTDB.setVerticalTextPosition(SwingConstants.CENTER);
683  57 btn_queryTDB.setHorizontalTextPosition(SwingConstants.TRAILING);
684  57 btn_queryTDB.setFont(VERDANA_12);
685  57 btn_queryTDB.setToolTipText(
686    MessageManager.getString("label.find_models_from_3dbeacons"));
687    // btn_queryTDB.setPreferredSize(new Dimension(200, 32));
688  57 btn_queryTDB.setVisible(false);
689   
690  57 targetView.setVisible(false);
691   
692  57 actionsPanel = new JPanel(new MigLayout());
693  57 actionsPanel.add(targetView, "left");
694  57 actionsPanel.add(btn_add, "wrap");
695  57 actionsPanel.add(chk_superpose, "left");
696  57 actionsPanel.add(btn_newView);
697  57 actionsPanel.add(btn_cancel, "right");
698   
699  57 JPanel pnl_main = new JPanel(new BorderLayout());
700  57 JPanel pnl_controls = new JPanel();
701  57 pnl_queryTDB = new JPanel();
702  57 pnl_queryTDB.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 4));
703  57 pnl_queryTDB.setBackground(getBackground());
704  57 pnl_queryTDB.add(btn_queryTDB);
705   
706  57 pnl_queryTDB.setVisible(false);
707  57 pnl_main.add(pnl_queryTDB, BorderLayout.NORTH);
708  57 pnl_controls.add(cmb_filterOption);
709  57 pnl_controls.add(lbl_loading);
710  57 pnl_controls.add(chk_invertFilter);
711  57 pnl_main.add(pnl_controls, BorderLayout.CENTER);
712  57 lbl_loading.setVisible(false);
713   
714    // JPanel pnl_fileChooser = new JPanel(new FlowLayout());
715    // pnl_fileChooser.add(btn_pdbFromFile);
716    // pnl_fileChooser.add(lbl_fromFileStatus);
717   
718  57 JPanel pnl_fileOptions = new JPanel();
719  57 pnl_fileOptions.setLayout(new GridBagLayout());
720  57 GridBagConstraints gbc = new GridBagConstraints();
721  57 gbc.gridx = 0;
722  57 gbc.gridy = 0;
723  57 gbc.weightx = 0.0;
724  57 gbc.weighty = 0.0;
725  57 gbc.insets = new Insets(0, 0, 2, 0);
726  57 gbc.fill = GridBagConstraints.NONE;
727  57 gbc.anchor = GridBagConstraints.FIRST_LINE_START;
728    // pnl_fileOptions.add(pnl_fileChooser, gbc);
729  57 pnl_fileOptions.add(btn_pdbFromFile, gbc);
730  57 gbc.gridy++;
731  57 gbc.insets = new Insets(0, 0, 18, 0);
732  57 pnl_fileOptions.add(lbl_pdbFile, gbc);
733  57 gbc.gridy++;
734   
735  57 gbc.insets = new Insets(0, 0, 2, 0);
736  57 pnl_fileOptions.add(new JLabel(
737    MessageManager.getString("label.structure_import_options")),
738    gbc);
739  57 gbc.gridy++;
740   
741  57 gbc.insets = new Insets(0, 0, 6, 0);
742  57 pnl_fileOptions.add(chains,gbc);
743   
744  57 gbc.gridy++;
745   
746  57 gbc.insets = new Insets(0, 0, 6, 0);
747  57 pnl_fileOptions.add(lbl_chooseTempFacType, gbc);
748  57 gbc.gridy++;
749  57 gbc.insets = new Insets(0, 0, 18, 0);
750  57 pnl_fileOptions.add(combo_tempFacAs, gbc);
751  57 gbc.gridy++;
752  57 gbc.insets = new Insets(0, 0, 6, 0);
753  57 pnl_fileOptions.add(btn_paeMatrixFile, gbc);
754  57 gbc.gridy++;
755  57 gbc.insets = new Insets(0, 0, 2, 0);
756  57 gbc.weighty = 1.0;
757  57 pnl_fileOptions.add(lbl_paeFile, gbc);
758   
759  57 JPanel pnl_fileChooserBL = new JPanel(new BorderLayout());
760  57 pnl_fileChooserBL.add(fileChooserAssSeqPanel, BorderLayout.PAGE_START);
761  57 pnl_fileChooserBL.add(pnl_fileOptions, BorderLayout.CENTER);
762   
763  57 JPanel pnl_idInput = new JPanel(new FlowLayout());
764  57 pnl_idInput.add(txt_search);
765  57 pnl_idInput.add(lbl_pdbManualFetchStatus);
766   
767  57 JPanel pnl_idInputBL = new JPanel(new BorderLayout());
768  57 pnl_idInputBL.add(idInputAssSeqPanel, BorderLayout.NORTH);
769  57 pnl_idInputBL.add(pnl_idInput, BorderLayout.CENTER);
770   
771  57 final String foundStructureSummary = MessageManager
772    .getString("label.found_structures_summary");
773  57 final String configureCols = MessageManager
774    .getString("label.configure_displayed_columns");
775  57 ChangeListener changeListener = new ChangeListener()
776    {
 
777  57 toggle @Override
778    public void stateChanged(ChangeEvent changeEvent)
779    {
780  57 JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent
781    .getSource();
782  57 int index = sourceTabbedPane.getSelectedIndex();
783  57 btn_add.setVisible(targetView.isVisible());
784  57 btn_newView.setVisible(true);
785  57 btn_cancel.setVisible(true);
786  57 if (sourceTabbedPane.getTitleAt(index).equals(configureCols))
787    {
788  0 btn_add.setEnabled(false);
789  0 btn_cancel.setEnabled(false);
790  0 btn_add.setVisible(false);
791  0 btn_newView.setEnabled(false);
792  0 btn_cancel.setVisible(false);
793  0 previousWantedFields = getFTSDocFieldPrefs()
794    .getStructureSummaryFields()
795    .toArray(new FTSDataColumnI[0]);
796    }
797  57 if (sourceTabbedPane.getTitleAt(index)
798    .equals(foundStructureSummary))
799    {
800  57 btn_cancel.setEnabled(true);
801  57 if (wantedFieldsUpdated())
802    {
803  57 tabRefresh();
804    }
805    else
806    {
807  0 validateSelections();
808    }
809    }
810    }
811    };
812  57 pnl_filter.addChangeListener(changeListener);
813  57 pnl_filter.setPreferredSize(new Dimension(width, height));
814  57 pnl_filter.add(foundStructureSummary, scrl_foundStructures);
815  57 pnl_filter.add(configureCols, getFTSDocFieldPrefs());
816   
817  57 JPanel pnl_locPDB = new JPanel(new BorderLayout());
818  57 pnl_locPDB.add(scrl_localPDB);
819   
820  57 pnl_switchableViews.add(pnl_fileChooserBL, VIEWS_FROM_FILE);
821  57 pnl_switchableViews.add(pnl_idInputBL, VIEWS_ENTER_ID);
822  57 pnl_switchableViews.add(pnl_filter, VIEWS_FILTER);
823  57 pnl_switchableViews.add(pnl_locPDB, VIEWS_LOCAL_PDB);
824   
825  57 this.setLayout(new BorderLayout());
826  57 this.add(pnl_main, java.awt.BorderLayout.NORTH);
827  57 this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER);
828    // this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
829  57 statusPanel.setLayout(new GridLayout());
830   
831  57 JPanel pnl_actionsAndStatus = new JPanel(new BorderLayout());
832  57 pnl_actionsAndStatus.add(actionsPanel, BorderLayout.CENTER);
833  57 pnl_actionsAndStatus.add(statusPanel, BorderLayout.SOUTH);
834  57 statusPanel.add(statusBar, null);
835  57 this.add(pnl_actionsAndStatus, java.awt.BorderLayout.SOUTH);
836   
837  57 mainFrame.addInternalFrameListener(
838    new javax.swing.event.InternalFrameAdapter()
839    {
 
840  8 toggle @Override
841    public void internalFrameClosing(InternalFrameEvent e)
842    {
843  8 closeAction(pnl_filter.getHeight());
844    }
845    });
846  57 mainFrame.setVisible(true);
847  57 mainFrame.setContentPane(this);
848  57 mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
849  57 Integer x = tempUserPrefs.get("structureChooser.x");
850  57 Integer y = tempUserPrefs.get("structureChooser.y");
851  57 if (x != null && y != null)
852    {
853  16 mainFrame.setLocation(x, y);
854    }
855  57 Desktop.addInternalFrame(mainFrame, frameTitle, width, height);
856    }
857   
858    protected abstract boolean showPopupFor(int selectedRow, int x, int y);
859   
 
860  8 toggle protected void closeAction(int preferredHeight)
861    {
862    // jalview.bin.Console.outPrintln(">>>>>>>>>> closing internal frame!!!");
863    // jalview.bin.Console.outPrintln("width : " + mainFrame.getWidth());
864    // jalview.bin.Console.outPrintln("heigh : " + mainFrame.getHeight());
865    // jalview.bin.Console.outPrintln("x : " + mainFrame.getX());
866    // jalview.bin.Console.outPrintln("y : " + mainFrame.getY());
867  8 tempUserPrefs.put("structureChooser.width", pnl_filter.getWidth());
868  8 tempUserPrefs.put("structureChooser.height", preferredHeight);
869  8 tempUserPrefs.put("structureChooser.x", mainFrame.getX());
870  8 tempUserPrefs.put("structureChooser.y", mainFrame.getY());
871  8 mainFrame.dispose();
872    }
873   
 
874  57 toggle public boolean wantedFieldsUpdated()
875    {
876  57 if (previousWantedFields == null)
877    {
878  57 return true;
879    }
880   
881  0 FTSDataColumnI[] currentWantedFields = getFTSDocFieldPrefs()
882    .getStructureSummaryFields().toArray(new FTSDataColumnI[0]);
883  0 return Arrays.equals(currentWantedFields, previousWantedFields) ? false
884    : true;
885   
886    }
887   
 
888  0 toggle @Override
889    /**
890    * Event listener for the 'filter' combo-box and 'invert' check-box
891    */
892    public void itemStateChanged(ItemEvent e)
893    {
894  0 stateChanged(e);
895    }
896   
897    /**
898    * This inner class provides the provides the data model for associate
899    * sequence combo-box - cmb_assSeq
900    *
901    * @author tcnofoegbu
902    *
903    */
 
904    public class AssociateSeqOptions
905    {
906    private SequenceI sequence;
907   
908    private String name;
909   
 
910  0 toggle public AssociateSeqOptions(SequenceI seq)
911    {
912  0 this.sequence = seq;
913  0 this.name = (seq.getName().length() >= 23)
914    ? seq.getName().substring(0, 23)
915    : seq.getName();
916    }
917   
 
918  2 toggle public AssociateSeqOptions(String name, SequenceI seq)
919    {
920  2 this.name = name;
921  2 this.sequence = seq;
922    }
923   
 
924  2 toggle @Override
925    public String toString()
926    {
927  2 return name;
928    }
929   
 
930  0 toggle public String getName()
931    {
932  0 return name;
933    }
934   
 
935  0 toggle public void setName(String name)
936    {
937  0 this.name = name;
938    }
939   
 
940  0 toggle public SequenceI getSequence()
941    {
942  0 return sequence;
943    }
944   
 
945  0 toggle public void setSequence(SequenceI sequence)
946    {
947  0 this.sequence = sequence;
948    }
949   
950    }
951   
952    /**
953    * This inner class holds the Layout and configuration of the panel which
954    * handles association of manually fetched structures to a unique sequence
955    * when more than one sequence selection is made
956    *
957    * @author tcnofoegbu
958    *
959    */
 
960    public class AssociateSeqPanel extends JPanel implements ItemListener
961    {
962    private JComboBox<AssociateSeqOptions> cmb_assSeq = new JComboBox<>();
963   
964    private JLabel lbl_associateSeq = new JLabel();
965   
 
966  114 toggle public AssociateSeqPanel()
967    {
968  114 this.setLayout(new FlowLayout());
969  114 this.add(cmb_assSeq);
970  114 this.add(lbl_associateSeq);
971  114 cmb_assSeq.setToolTipText(
972    MessageManager.getString("info.associate_wit_sequence"));
973  114 cmb_assSeq.addItemListener(this);
974    }
975   
 
976  2 toggle public void loadCmbAssSeq()
977    {
978  2 populateCmbAssociateSeqOptions(cmb_assSeq, lbl_associateSeq);
979    }
980   
 
981  3 toggle public JComboBox<AssociateSeqOptions> getCmb_assSeq()
982    {
983  3 return cmb_assSeq;
984    }
985   
 
986  0 toggle public void setCmb_assSeq(JComboBox<AssociateSeqOptions> cmb_assSeq)
987    {
988  0 this.cmb_assSeq = cmb_assSeq;
989    }
990   
 
991  2 toggle @Override
992    public void itemStateChanged(ItemEvent e)
993    {
994  2 if (e.getStateChange() == ItemEvent.SELECTED)
995    {
996  2 cmbAssSeqStateChanged();
997    }
998    }
999    }
1000   
 
1001  10 toggle public JTable getResultTable()
1002    {
1003  10 return tbl_summary;
1004    }
1005   
 
1006  6 toggle public JComboBox<FilterOption> getCmbFilterOption()
1007    {
1008  6 return cmb_filterOption;
1009    }
1010   
1011    /**
1012    * Custom ListCellRenderer for adding a separator between different categories
1013    * of structure chooser filter option drop-down.
1014    *
1015    * @author tcnofoegbu
1016    *
1017    */
 
1018    public abstract class CustomComboSeparatorsRenderer
1019    implements ListCellRenderer<Object>
1020    {
1021    private ListCellRenderer<Object> regent;
1022   
1023    private JPanel separatorPanel = new JPanel(new BorderLayout());
1024   
1025    private JSeparator jSeparator = new JSeparator();
1026   
 
1027  57 toggle public CustomComboSeparatorsRenderer(
1028    ListCellRenderer<Object> listCellRenderer)
1029    {
1030  57 this.regent = listCellRenderer;
1031    }
1032   
 
1033  67 toggle @Override
1034    public Component getListCellRendererComponent(JList list, Object value,
1035    int index, boolean isSelected, boolean cellHasFocus)
1036    {
1037   
1038  67 Component comp = regent.getListCellRendererComponent(list, value,
1039    index, isSelected, cellHasFocus);
1040  67 if (index != -1
1041    && addSeparatorAfter(list, (FilterOption) value, index))
1042    {
1043  1 separatorPanel.removeAll();
1044  1 separatorPanel.add(comp, BorderLayout.CENTER);
1045  1 separatorPanel.add(jSeparator, BorderLayout.SOUTH);
1046  1 return separatorPanel;
1047    }
1048    else
1049    {
1050  66 return comp;
1051    }
1052    }
1053   
1054    protected abstract boolean addSeparatorAfter(JList list,
1055    FilterOption value, int index);
1056    }
1057   
1058    protected abstract void stateChanged(ItemEvent e);
1059   
1060    protected abstract void add_ActionPerformed();
1061   
1062    protected abstract void newView_ActionPerformed();
1063   
1064    protected abstract void pdbFromFile_actionPerformed();
1065   
1066    protected abstract void paeMatrixFile_actionPerformed();
1067   
1068    protected abstract void txt_search_ActionPerformed();
1069   
1070    protected abstract void populateCmbAssociateSeqOptions(
1071    JComboBox<AssociateSeqOptions> cmb_assSeq,
1072    JLabel lbl_associateSeq);
1073   
1074    protected abstract void cmbAssSeqStateChanged();
1075   
1076    protected abstract void tabRefresh();
1077   
1078    protected abstract void validateSelections();
1079   
 
1080  0 toggle public JInternalFrame getFrame()
1081    {
1082  0 return mainFrame;
1083    }
1084   
 
1085  0 toggle public void setPdbOptionsEnabled(boolean b)
1086    {
1087  0 lbl_chooseTempFacType.setEnabled(b);
1088  0 combo_tempFacAs.setEnabled(b);
1089  0 btn_paeMatrixFile.setEnabled(b);
1090  0 lbl_paeFile.setEnabled(b);
1091    }
1092    }