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