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