JAL-2906 apply GPLv3 license source
[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 jalview.datamodel.SequenceI;
25 import jalview.fts.api.FTSDataColumnI;
26 import jalview.fts.core.FTSDataColumnPreferences;
27 import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource;
28 import jalview.fts.service.pdb.PDBFTSRestClient;
29 import jalview.gui.AlignmentPanel;
30 import jalview.gui.Desktop;
31 import jalview.gui.JvSwingUtils;
32 import jalview.gui.StructureViewer;
33 import jalview.util.MessageManager;
34
35 import java.awt.BorderLayout;
36 import java.awt.CardLayout;
37 import java.awt.Component;
38 import java.awt.Dimension;
39 import java.awt.FlowLayout;
40 import java.awt.Font;
41 import java.awt.GridLayout;
42 import java.awt.event.ActionEvent;
43 import java.awt.event.ItemEvent;
44 import java.awt.event.ItemListener;
45 import java.awt.event.KeyAdapter;
46 import java.awt.event.KeyEvent;
47 import java.awt.event.MouseAdapter;
48 import java.awt.event.MouseEvent;
49 import java.util.Arrays;
50 import java.util.HashMap;
51 import java.util.Map;
52
53 import javax.swing.ImageIcon;
54 import javax.swing.JButton;
55 import javax.swing.JCheckBox;
56 import javax.swing.JComboBox;
57 import javax.swing.JFrame;
58 import javax.swing.JInternalFrame;
59 import javax.swing.JLabel;
60 import javax.swing.JList;
61 import javax.swing.JPanel;
62 import javax.swing.JScrollPane;
63 import javax.swing.JSeparator;
64 import javax.swing.JTabbedPane;
65 import javax.swing.JTable;
66 import javax.swing.JTextField;
67 import javax.swing.ListCellRenderer;
68 import javax.swing.event.ChangeEvent;
69 import javax.swing.event.ChangeListener;
70 import javax.swing.event.DocumentEvent;
71 import javax.swing.event.DocumentListener;
72 import javax.swing.event.InternalFrameEvent;
73 import javax.swing.table.TableColumn;
74
75 import net.miginfocom.swing.MigLayout;
76
77 @SuppressWarnings("serial")
78 /**
79  * GUI layout for structure chooser
80  * 
81  * @author tcnofoegbu
82  *
83  */
84 public abstract class GStructureChooser extends JPanel
85         implements ItemListener
86 {
87   private static final Font VERDANA_12 = new Font("Verdana", 0, 12);
88
89   protected static final String VIEWS_FILTER = "VIEWS_FILTER";
90
91   protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE";
92
93   protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
94
95   /*
96    * 'cached' structure view
97    */
98   protected static final String VIEWS_LOCAL_PDB = "VIEWS_LOCAL_PDB";
99
100   protected JPanel statusPanel = new JPanel();
101
102   public JLabel statusBar = new JLabel();
103
104   protected String frameTitle = MessageManager
105           .getString("label.structure_chooser");
106
107   protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
108
109   protected JComboBox<FilterOption> cmb_filterOption = new JComboBox<>();
110
111   protected AlignmentPanel ap;
112
113   protected StringBuilder errorWarning = new StringBuilder();
114
115   protected JButton btn_add;
116
117   protected JButton btn_newView;
118
119   protected JButton btn_pdbFromFile = new JButton();
120
121   protected JCheckBox chk_superpose = new JCheckBox(
122           MessageManager.getString("label.superpose_structures"));
123
124   protected JTextField txt_search = new JTextField(14);
125
126   protected JPanel pnl_switchableViews = new JPanel(new CardLayout());
127
128   protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews
129           .getLayout());
130
131   protected JCheckBox chk_invertFilter = new JCheckBox(
132           MessageManager.getString("label.invert"));
133
134   protected ImageIcon loadingImage = new ImageIcon(
135           getClass().getResource("/images/loading.gif"));
136
137   protected ImageIcon goodImage = new ImageIcon(
138           getClass().getResource("/images/good.png"));
139
140   protected ImageIcon errorImage = new ImageIcon(
141           getClass().getResource("/images/error.png"));
142
143   protected ImageIcon warningImage = new ImageIcon(
144           getClass().getResource("/images/warning.gif"));
145
146   protected JLabel lbl_loading = new JLabel(loadingImage);
147
148   protected JLabel lbl_pdbManualFetchStatus = new JLabel(errorImage);
149
150   protected JLabel lbl_fromFileStatus = new JLabel(errorImage);
151
152   protected AssociateSeqPanel idInputAssSeqPanel = new AssociateSeqPanel();
153
154   protected AssociateSeqPanel fileChooserAssSeqPanel = new AssociateSeqPanel();
155
156   protected JComboBox<StructureViewer> targetView = new JComboBox<>();
157
158   protected JTable tbl_local_pdb = new JTable();
159
160   protected JTabbedPane pnl_filter = new JTabbedPane();
161
162   protected FTSDataColumnPreferences pdbDocFieldPrefs = new FTSDataColumnPreferences(
163           PreferenceSource.STRUCTURE_CHOOSER,
164           PDBFTSRestClient.getInstance());
165
166   protected FTSDataColumnI[] previousWantedFields;
167
168   protected static Map<String, Integer> tempUserPrefs = new HashMap<>();
169
170   private JTable tbl_summary = new JTable()
171   {
172     private boolean inLayout;
173
174     @Override
175     public boolean getScrollableTracksViewportWidth()
176     {
177       return hasExcessWidth();
178
179     }
180
181     @Override
182     public void doLayout()
183     {
184       if (hasExcessWidth())
185       {
186         autoResizeMode = AUTO_RESIZE_SUBSEQUENT_COLUMNS;
187       }
188       inLayout = true;
189       super.doLayout();
190       inLayout = false;
191       autoResizeMode = AUTO_RESIZE_OFF;
192     }
193
194     protected boolean hasExcessWidth()
195     {
196       return getPreferredSize().width < getParent().getWidth();
197     }
198
199     @Override
200     public void columnMarginChanged(ChangeEvent e)
201     {
202       if (isEditing())
203       {
204         removeEditor();
205       }
206       TableColumn resizingColumn = getTableHeader().getResizingColumn();
207       // Need to do this here, before the parent's
208       // layout manager calls getPreferredSize().
209       if (resizingColumn != null && autoResizeMode == AUTO_RESIZE_OFF
210               && !inLayout)
211       {
212         resizingColumn.setPreferredWidth(resizingColumn.getWidth());
213         String colHeader = resizingColumn.getHeaderValue().toString();
214         tempUserPrefs.put(colHeader, resizingColumn.getWidth());
215       }
216       resizeAndRepaint();
217     }
218
219     @Override
220     public String getToolTipText(MouseEvent evt)
221     {
222       String toolTipText = null;
223       java.awt.Point pnt = evt.getPoint();
224       int rowIndex = rowAtPoint(pnt);
225       int colIndex = columnAtPoint(pnt);
226
227       try
228       {
229         if (getValueAt(rowIndex, colIndex) == null)
230         {
231           return null;
232         }
233         toolTipText = getValueAt(rowIndex, colIndex).toString();
234       } catch (Exception e)
235       {
236         // e.printStackTrace();
237       }
238       toolTipText = (toolTipText == null ? null
239               : (toolTipText.length() > 500
240                       ? JvSwingUtils.wrapTooltip(true,
241                               "\"" + toolTipText.subSequence(0, 500)
242                                       + "...\"")
243                       : JvSwingUtils.wrapTooltip(true, toolTipText)));
244       return toolTipText;
245     }
246   };
247
248   public GStructureChooser()
249   {
250     try
251     {
252       jbInit();
253       mainFrame.setVisible(false);
254       mainFrame.invalidate();
255       mainFrame.pack();
256     } catch (Exception e)
257     {
258       e.printStackTrace();
259     }
260   }
261
262   /**
263    * Initializes the GUI default properties
264    * 
265    * @throws Exception
266    */
267   private void jbInit() throws Exception
268   {
269     Integer width = tempUserPrefs.get("structureChooser.width") == null
270             ? 800
271             : tempUserPrefs.get("structureChooser.width");
272     Integer height = tempUserPrefs.get("structureChooser.height") == null
273             ? 400
274             : tempUserPrefs.get("structureChooser.height");
275     tbl_summary.setAutoCreateRowSorter(true);
276     tbl_summary.getTableHeader().setReorderingAllowed(false);
277     tbl_summary.addMouseListener(new MouseAdapter()
278     {
279       @Override
280       public void mouseClicked(MouseEvent e)
281       {
282         validateSelections();
283       }
284
285       @Override
286       public void mouseReleased(MouseEvent e)
287       {
288         validateSelections();
289       }
290     });
291     tbl_summary.addKeyListener(new KeyAdapter()
292     {
293       @Override
294       public void keyPressed(KeyEvent evt)
295       {
296         validateSelections();
297         switch (evt.getKeyCode())
298         {
299         case KeyEvent.VK_ESCAPE: // escape key
300           mainFrame.dispose();
301           break;
302         case KeyEvent.VK_ENTER: // enter key
303           if (btn_add.isEnabled())
304           {
305             add_ActionPerformed();
306           }
307           break;
308         case KeyEvent.VK_TAB: // tab key
309           if (evt.isShiftDown())
310           {
311             pnl_filter.requestFocus();
312           }
313           else
314           {
315             btn_add.requestFocus();
316           }
317           evt.consume();
318           break;
319         default:
320           return;
321         }
322       }
323     });
324
325     JButton btn_cancel = new JButton(
326             MessageManager.getString("action.cancel"));
327     btn_cancel.setFont(VERDANA_12);
328     btn_cancel.addActionListener(new java.awt.event.ActionListener()
329     {
330       @Override
331       public void actionPerformed(ActionEvent e)
332       {
333         closeAction(pnl_filter.getHeight());
334       }
335     });
336     btn_cancel.addKeyListener(new KeyAdapter()
337     {
338       @Override
339       public void keyPressed(KeyEvent evt)
340       {
341         if (evt.getKeyCode() == KeyEvent.VK_ENTER)
342         {
343           closeAction(pnl_filter.getHeight());
344         }
345       }
346     });
347
348     tbl_local_pdb.setAutoCreateRowSorter(true);
349     tbl_local_pdb.getTableHeader().setReorderingAllowed(false);
350     tbl_local_pdb.addMouseListener(new MouseAdapter()
351     {
352       @Override
353       public void mouseClicked(MouseEvent e)
354       {
355         validateSelections();
356       }
357
358       @Override
359       public void mouseReleased(MouseEvent e)
360       {
361         validateSelections();
362       }
363     });
364     tbl_local_pdb.addKeyListener(new KeyAdapter()
365     {
366       @Override
367       public void keyPressed(KeyEvent evt)
368       {
369         validateSelections();
370         switch (evt.getKeyCode())
371         {
372         case KeyEvent.VK_ESCAPE: // escape key
373           mainFrame.dispose();
374           break;
375         case KeyEvent.VK_ENTER: // enter key
376           if (btn_add.isEnabled())
377           {
378             add_ActionPerformed();
379           }
380           break;
381         case KeyEvent.VK_TAB: // tab key
382           if (evt.isShiftDown())
383           {
384             cmb_filterOption.requestFocus();
385           }
386           else
387           {
388             if (btn_add.isEnabled())
389             {
390               btn_add.requestFocus();
391             }
392             else
393             {
394               btn_cancel.requestFocus();
395             }
396           }
397           evt.consume();
398           break;
399         default:
400           return;
401         }
402       }
403     });
404
405     btn_newView = new JButton(MessageManager.getString("action.new_view"));
406     btn_newView.setFont(VERDANA_12);
407     btn_newView.addActionListener(new java.awt.event.ActionListener()
408     {
409       @Override
410       public void actionPerformed(ActionEvent e)
411       {
412         newView_ActionPerformed();
413       }
414     });
415     btn_newView.addKeyListener(new KeyAdapter()
416     {
417       @Override
418       public void keyPressed(KeyEvent evt)
419       {
420         if (evt.getKeyCode() == KeyEvent.VK_ENTER)
421         {
422           newView_ActionPerformed();
423         }
424       }
425     });
426
427     btn_add = new JButton(MessageManager.getString("action.add"));
428     btn_add.setFont(VERDANA_12);
429     btn_add.addActionListener(new java.awt.event.ActionListener()
430     {
431       @Override
432       public void actionPerformed(ActionEvent e)
433       {
434         add_ActionPerformed();
435       }
436     });
437     btn_add.addKeyListener(new KeyAdapter()
438     {
439       @Override
440       public void keyPressed(KeyEvent evt)
441       {
442         if (evt.getKeyCode() == KeyEvent.VK_ENTER)
443         {
444           add_ActionPerformed();
445         }
446       }
447     });
448
449     btn_pdbFromFile.setFont(VERDANA_12);
450     String btn_title = MessageManager.getString("label.select_pdb_file");
451     btn_pdbFromFile.setText(btn_title + "              ");
452     btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener()
453     {
454       @Override
455       public void actionPerformed(ActionEvent e)
456       {
457         pdbFromFile_actionPerformed();
458       }
459     });
460     btn_pdbFromFile.addKeyListener(new KeyAdapter()
461     {
462       @Override
463       public void keyPressed(KeyEvent evt)
464       {
465         if (evt.getKeyCode() == KeyEvent.VK_ENTER)
466         {
467           pdbFromFile_actionPerformed();
468         }
469       }
470     });
471
472     JScrollPane scrl_foundStructures = new JScrollPane(tbl_summary);
473     scrl_foundStructures.setPreferredSize(new Dimension(width, height));
474
475     JScrollPane scrl_localPDB = new JScrollPane(tbl_local_pdb);
476     scrl_localPDB.setPreferredSize(new Dimension(width, height));
477     scrl_localPDB.setHorizontalScrollBarPolicy(
478             JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
479
480     chk_invertFilter.setFont(VERDANA_12);
481     txt_search.setToolTipText(JvSwingUtils.wrapTooltip(true,
482             MessageManager.getString("label.enter_pdb_id_tip")));
483     txt_search.getDocument().addDocumentListener(new DocumentListener()
484     {
485       @Override
486       public void insertUpdate(DocumentEvent e)
487       {
488         txt_search_ActionPerformed();
489       }
490
491       @Override
492       public void removeUpdate(DocumentEvent e)
493       {
494         txt_search_ActionPerformed();
495       }
496
497       @Override
498       public void changedUpdate(DocumentEvent e)
499       {
500         txt_search_ActionPerformed();
501       }
502     });
503
504     cmb_filterOption.setFont(VERDANA_12);
505     cmb_filterOption.setToolTipText(
506             MessageManager.getString("info.select_filter_option"));
507     cmb_filterOption.addItemListener(this);
508     // add CustomComboSeparatorsRenderer to filter option combo-box
509     cmb_filterOption.setRenderer(new CustomComboSeparatorsRenderer(
510             (ListCellRenderer<Object>) cmb_filterOption.getRenderer())
511     {
512       @Override
513       protected boolean addSeparatorAfter(JList list, FilterOption value,
514               int index)
515       {
516         return value.isAddSeparatorAfter();
517       }
518     });
519
520     chk_invertFilter.addItemListener(this);
521
522     targetView.setVisible(false);
523
524     JPanel actionsPanel = new JPanel(new MigLayout());
525     actionsPanel.add(targetView, "left");
526     actionsPanel.add(btn_add, "wrap");
527     actionsPanel.add(chk_superpose, "left");
528     actionsPanel.add(btn_newView);
529     actionsPanel.add(btn_cancel, "right");
530
531     JPanel pnl_main = new JPanel();
532     pnl_main.add(cmb_filterOption);
533     pnl_main.add(lbl_loading);
534     pnl_main.add(chk_invertFilter);
535     lbl_loading.setVisible(false);
536
537     JPanel pnl_fileChooser = new JPanel(new FlowLayout());
538     pnl_fileChooser.add(btn_pdbFromFile);
539     pnl_fileChooser.add(lbl_fromFileStatus);
540     JPanel pnl_fileChooserBL = new JPanel(new BorderLayout());
541     pnl_fileChooserBL.add(fileChooserAssSeqPanel, BorderLayout.NORTH);
542     pnl_fileChooserBL.add(pnl_fileChooser, BorderLayout.CENTER);
543
544     JPanel pnl_idInput = new JPanel(new FlowLayout());
545     pnl_idInput.add(txt_search);
546     pnl_idInput.add(lbl_pdbManualFetchStatus);
547
548     JPanel pnl_idInputBL = new JPanel(new BorderLayout());
549     pnl_idInputBL.add(idInputAssSeqPanel, BorderLayout.NORTH);
550     pnl_idInputBL.add(pnl_idInput, BorderLayout.CENTER);
551
552     final String foundStructureSummary = MessageManager
553             .getString("label.found_structures_summary");
554     final String configureCols = MessageManager
555             .getString("label.configure_displayed_columns");
556     ChangeListener changeListener = new ChangeListener()
557     {
558       @Override
559       public void stateChanged(ChangeEvent changeEvent)
560       {
561         JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent
562                 .getSource();
563         int index = sourceTabbedPane.getSelectedIndex();
564         btn_add.setVisible(targetView.isVisible());
565         btn_newView.setVisible(true);
566         btn_cancel.setVisible(true);
567         if (sourceTabbedPane.getTitleAt(index).equals(configureCols))
568         {
569           btn_add.setEnabled(false);
570           btn_cancel.setEnabled(false);
571           btn_add.setVisible(false);
572           btn_newView.setEnabled(false);
573           btn_cancel.setVisible(false);
574           previousWantedFields = pdbDocFieldPrefs
575                   .getStructureSummaryFields()
576                   .toArray(new FTSDataColumnI[0]);
577         }
578         if (sourceTabbedPane.getTitleAt(index)
579                 .equals(foundStructureSummary))
580         {
581           btn_cancel.setEnabled(true);
582           if (wantedFieldsUpdated())
583           {
584             tabRefresh();
585           }
586           else
587           {
588             validateSelections();
589           }
590         }
591       }
592     };
593     pnl_filter.addChangeListener(changeListener);
594     pnl_filter.setPreferredSize(new Dimension(width, height));
595     pnl_filter.add(foundStructureSummary, scrl_foundStructures);
596     pnl_filter.add(configureCols, pdbDocFieldPrefs);
597
598     JPanel pnl_locPDB = new JPanel(new BorderLayout());
599     pnl_locPDB.add(scrl_localPDB);
600
601     pnl_switchableViews.add(pnl_fileChooserBL, VIEWS_FROM_FILE);
602     pnl_switchableViews.add(pnl_idInputBL, VIEWS_ENTER_ID);
603     pnl_switchableViews.add(pnl_filter, VIEWS_FILTER);
604     pnl_switchableViews.add(pnl_locPDB, VIEWS_LOCAL_PDB);
605
606     this.setLayout(new BorderLayout());
607     this.add(pnl_main, java.awt.BorderLayout.NORTH);
608     this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER);
609     // this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
610     statusPanel.setLayout(new GridLayout());
611
612     JPanel pnl_actionsAndStatus = new JPanel(new BorderLayout());
613     pnl_actionsAndStatus.add(actionsPanel, BorderLayout.CENTER);
614     pnl_actionsAndStatus.add(statusPanel, BorderLayout.SOUTH);
615     statusPanel.add(statusBar, null);
616     this.add(pnl_actionsAndStatus, java.awt.BorderLayout.SOUTH);
617
618     mainFrame.addInternalFrameListener(
619             new javax.swing.event.InternalFrameAdapter()
620             {
621               @Override
622               public void internalFrameClosing(InternalFrameEvent e)
623               {
624                 closeAction(pnl_filter.getHeight());
625               }
626             });
627     mainFrame.setVisible(true);
628     mainFrame.setContentPane(this);
629     mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
630     Integer x = tempUserPrefs.get("structureChooser.x");
631     Integer y = tempUserPrefs.get("structureChooser.y");
632     if (x != null && y != null)
633     {
634       mainFrame.setLocation(x, y);
635     }
636     Desktop.addInternalFrame(mainFrame, frameTitle, width, height);
637   }
638
639   protected void closeAction(int preferredHeight)
640   {
641     // System.out.println(">>>>>>>>>> closing internal frame!!!");
642     // System.out.println("width : " + mainFrame.getWidth());
643     // System.out.println("heigh : " + mainFrame.getHeight());
644     // System.out.println("x : " + mainFrame.getX());
645     // System.out.println("y : " + mainFrame.getY());
646     tempUserPrefs.put("structureChooser.width", pnl_filter.getWidth());
647     tempUserPrefs.put("structureChooser.height", preferredHeight);
648     tempUserPrefs.put("structureChooser.x", mainFrame.getX());
649     tempUserPrefs.put("structureChooser.y", mainFrame.getY());
650     mainFrame.dispose();
651   }
652
653   public boolean wantedFieldsUpdated()
654   {
655     if (previousWantedFields == null)
656     {
657       return true;
658     }
659
660     FTSDataColumnI[] currentWantedFields = pdbDocFieldPrefs
661             .getStructureSummaryFields().toArray(new FTSDataColumnI[0]);
662     return Arrays.equals(currentWantedFields, previousWantedFields) ? false
663             : true;
664
665   }
666
667   @Override
668   /**
669    * Event listener for the 'filter' combo-box and 'invert' check-box
670    */
671   public void itemStateChanged(ItemEvent e)
672   {
673     stateChanged(e);
674   }
675
676   /**
677    * This inner class provides the data model for the structure filter combo-box
678    * 
679    * @author tcnofoegbu
680    *
681    */
682   public class FilterOption
683   {
684     private String name;
685
686     private String value;
687
688     private String view;
689
690     private boolean addSeparatorAfter;
691
692     /**
693      * Model for structure filter option
694      * 
695      * @param name
696      *          - the name of the Option
697      * @param value
698      *          - the value of the option
699      * @param view
700      *          - the category of the filter option
701      * @param addSeparatorAfter
702      *          - if true, a horizontal separator is rendered immediately after
703      *          this filter option, otherwise
704      */
705     public FilterOption(String name, String value, String view,
706             boolean addSeparatorAfter)
707     {
708       this.name = name;
709       this.value = value;
710       this.view = view;
711       this.addSeparatorAfter = addSeparatorAfter;
712     }
713
714     public String getName()
715     {
716       return name;
717     }
718
719     public void setName(String name)
720     {
721       this.name = name;
722     }
723
724     public String getValue()
725     {
726       return value;
727     }
728
729     public void setValue(String value)
730     {
731       this.value = value;
732     }
733
734     public String getView()
735     {
736       return view;
737     }
738
739     public void setView(String view)
740     {
741       this.view = view;
742     }
743
744     @Override
745     public String toString()
746     {
747       return this.name;
748     }
749
750     public boolean isAddSeparatorAfter()
751     {
752       return addSeparatorAfter;
753     }
754
755     public void setAddSeparatorAfter(boolean addSeparatorAfter)
756     {
757       this.addSeparatorAfter = addSeparatorAfter;
758     }
759   }
760
761   /**
762    * This inner class provides the provides the data model for associate
763    * sequence combo-box - cmb_assSeq
764    * 
765    * @author tcnofoegbu
766    *
767    */
768   public class AssociateSeqOptions
769   {
770     private SequenceI sequence;
771
772     private String name;
773
774     public AssociateSeqOptions(SequenceI seq)
775     {
776       this.sequence = seq;
777       this.name = (seq.getName().length() >= 23)
778               ? seq.getName().substring(0, 23)
779               : seq.getName();
780     }
781
782     public AssociateSeqOptions(String name, SequenceI seq)
783     {
784       this.name = name;
785       this.sequence = seq;
786     }
787
788     @Override
789     public String toString()
790     {
791       return name;
792     }
793
794     public String getName()
795     {
796       return name;
797     }
798
799     public void setName(String name)
800     {
801       this.name = name;
802     }
803
804     public SequenceI getSequence()
805     {
806       return sequence;
807     }
808
809     public void setSequence(SequenceI sequence)
810     {
811       this.sequence = sequence;
812     }
813
814   }
815
816   /**
817    * This inner class holds the Layout and configuration of the panel which
818    * handles association of manually fetched structures to a unique sequence
819    * when more than one sequence selection is made
820    * 
821    * @author tcnofoegbu
822    *
823    */
824   public class AssociateSeqPanel extends JPanel implements ItemListener
825   {
826     private JComboBox<AssociateSeqOptions> cmb_assSeq = new JComboBox<>();
827
828     private JLabel lbl_associateSeq = new JLabel();
829
830     public AssociateSeqPanel()
831     {
832       this.setLayout(new FlowLayout());
833       this.add(cmb_assSeq);
834       this.add(lbl_associateSeq);
835       cmb_assSeq.setToolTipText(
836               MessageManager.getString("info.associate_wit_sequence"));
837       cmb_assSeq.addItemListener(this);
838     }
839
840     public void loadCmbAssSeq()
841     {
842       populateCmbAssociateSeqOptions(cmb_assSeq, lbl_associateSeq);
843     }
844
845     public JComboBox<AssociateSeqOptions> getCmb_assSeq()
846     {
847       return cmb_assSeq;
848     }
849
850     public void setCmb_assSeq(JComboBox<AssociateSeqOptions> cmb_assSeq)
851     {
852       this.cmb_assSeq = cmb_assSeq;
853     }
854
855     @Override
856     public void itemStateChanged(ItemEvent e)
857     {
858       if (e.getStateChange() == ItemEvent.SELECTED)
859       {
860         cmbAssSeqStateChanged();
861       }
862     }
863   }
864
865   public JTable getResultTable()
866   {
867     return tbl_summary;
868   }
869
870   public JComboBox<FilterOption> getCmbFilterOption()
871   {
872     return cmb_filterOption;
873   }
874
875   /**
876    * Custom ListCellRenderer for adding a separator between different categories
877    * of structure chooser filter option drop-down.
878    * 
879    * @author tcnofoegbu
880    *
881    */
882   public abstract class CustomComboSeparatorsRenderer
883           implements ListCellRenderer<Object>
884   {
885     private ListCellRenderer<Object> regent;
886
887     private JPanel separatorPanel = new JPanel(new BorderLayout());
888
889     private JSeparator jSeparator = new JSeparator();
890
891     public CustomComboSeparatorsRenderer(
892             ListCellRenderer<Object> listCellRenderer)
893     {
894       this.regent = listCellRenderer;
895     }
896
897     @Override
898     public Component getListCellRendererComponent(JList list, Object value,
899             int index, boolean isSelected, boolean cellHasFocus)
900     {
901
902       Component comp = regent.getListCellRendererComponent(list, value,
903               index, isSelected, cellHasFocus);
904       if (index != -1
905               && addSeparatorAfter(list, (FilterOption) value, index))
906       {
907         separatorPanel.removeAll();
908         separatorPanel.add(comp, BorderLayout.CENTER);
909         separatorPanel.add(jSeparator, BorderLayout.SOUTH);
910         return separatorPanel;
911       }
912       else
913       {
914         return comp;
915       }
916     }
917
918     protected abstract boolean addSeparatorAfter(JList list,
919             FilterOption value, int index);
920   }
921
922   protected abstract void stateChanged(ItemEvent e);
923
924   protected abstract void add_ActionPerformed();
925
926   protected abstract void newView_ActionPerformed();
927
928   protected abstract void pdbFromFile_actionPerformed();
929
930   protected abstract void txt_search_ActionPerformed();
931
932   protected abstract void populateCmbAssociateSeqOptions(
933           JComboBox<AssociateSeqOptions> cmb_assSeq,
934           JLabel lbl_associateSeq);
935
936   protected abstract void cmbAssSeqStateChanged();
937
938   protected abstract void tabRefresh();
939
940   protected abstract void validateSelections();
941 }