Clover icon

Coverage Report

  1. Project Clover database Mon Sep 2 2024 17:57:51 BST
  2. Package jalview.jbgui

File GStructureChooser.java

 

Coverage histogram

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

Code metrics

68
327
56
4
1,082
849
102
0.31
5.84
14
1.82

Classes

Class Line # Actions
GStructureChooser 91 300 84
0.51980252%
GStructureChooser.AssociateSeqOptions 894 9 8
0.277777827.8%
GStructureChooser.AssociateSeqPanel 950 10 6
0.823529482.4%
GStructureChooser.CustomComboSeparatorsRenderer 1008 8 4
1.0100%
 

Contributing tests

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