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