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