29a0014248bedb72c1d13742869f80eaa65536ac
[jalview.git] / src / jalview / jbgui / GPDBSearchPanel.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.gui.Desktop;
25 import jalview.jbgui.PDBDocFieldPreferences.PreferenceSource;
26 import jalview.util.MessageManager;
27 import jalview.ws.dbsources.PDBRestClient.PDBDocField;
28
29 import java.awt.BorderLayout;
30 import java.awt.Dimension;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
33
34 import javax.swing.JButton;
35 import javax.swing.JComboBox;
36 import javax.swing.JFrame;
37 import javax.swing.JInternalFrame;
38 import javax.swing.JPanel;
39 import javax.swing.JScrollPane;
40 import javax.swing.JTabbedPane;
41 import javax.swing.JTable;
42 import javax.swing.JTextField;
43 import javax.swing.event.ChangeEvent;
44 import javax.swing.event.ChangeListener;
45 import javax.swing.event.DocumentEvent;
46 import javax.swing.event.DocumentListener;
47
48 /**
49  * GUI layout for PDB Fetch Panel
50  * 
51  * @author tcnofoegbu
52  *
53  */
54 @SuppressWarnings("serial")
55 public abstract class GPDBSearchPanel extends JPanel
56 {
57   protected String frameTitle = MessageManager
58           .getString("label.pdb_sequence_getcher");
59
60   protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
61
62   protected JComboBox<PDBDocField> cmb_searchTarget = new JComboBox<PDBDocField>();
63
64   protected JButton btn_ok = new JButton();
65
66   protected JButton btn_back = new JButton();
67   
68   protected JButton btn_cancel = new JButton();
69   
70   protected JTextField txt_search = new JTextField(20);
71   
72   protected JTable tbl_summary = new JTable();
73
74   protected JScrollPane scrl_searchResult = new JScrollPane(
75 tbl_summary);
76
77   private JTabbedPane tabbedPane = new JTabbedPane();
78
79   private PDBDocFieldPreferences pdbDocFieldPrefs = new PDBDocFieldPreferences(
80           PreferenceSource.SEARCH_SUMMARY);
81
82   private JPanel pnl_actions = new JPanel();
83
84   private JPanel pnl_results = new JPanel();
85
86   private JPanel pnl_inputs = new JPanel();
87
88   private BorderLayout mainLayout = new BorderLayout();
89
90   public GPDBSearchPanel()
91   {
92     try
93     {
94       jbInit();
95       mainFrame.invalidate();
96       mainFrame.pack();
97     } catch (Exception e)
98     {
99       e.printStackTrace();
100     }
101   }
102
103   /**
104    * Initializes the GUI default properties
105    * 
106    * @throws Exception
107    */
108   private void jbInit() throws Exception
109   {
110     tbl_summary.setAutoCreateRowSorter(true);
111     btn_back.setFont(new java.awt.Font("Verdana", 0, 12));
112     btn_back.setText(MessageManager.getString("action.back"));
113     btn_back.addActionListener(new java.awt.event.ActionListener()
114     {
115       public void actionPerformed(ActionEvent e)
116       {
117         btn_back_ActionPerformed();
118       }
119     });
120     btn_ok.setFont(new java.awt.Font("Verdana", 0, 12));
121     btn_ok.setText(MessageManager.getString("action.ok"));
122     btn_ok.addActionListener(new java.awt.event.ActionListener()
123     {
124       public void actionPerformed(ActionEvent e)
125       {
126         btn_ok_ActionPerformed();
127       }
128     });
129     btn_cancel.setFont(new java.awt.Font("Verdana", 0, 12));
130     btn_cancel.setText(MessageManager.getString("action.cancel"));
131     btn_cancel.addActionListener(new java.awt.event.ActionListener()
132     {
133       public void actionPerformed(ActionEvent e)
134       {
135         btn_cancel_ActionPerformed();
136       }
137     });
138
139     scrl_searchResult.setPreferredSize(new Dimension(500, 300));
140     scrl_searchResult
141             .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
142
143     cmb_searchTarget.setFont(new java.awt.Font("Verdana", 0, 12));
144     cmb_searchTarget.addActionListener(new ActionListener()
145     {
146       @Override
147       public void actionPerformed(ActionEvent e)
148       {
149         txt_search_ActionPerformed();
150       }
151     });
152
153     populateCmbSearchTargetOptions();
154
155     txt_search.setFont(new java.awt.Font("Verdana", 0, 12));
156     txt_search.getDocument().addDocumentListener(new DocumentListener()
157     {
158       @Override
159       public void insertUpdate(DocumentEvent e)
160       {
161         txt_search_ActionPerformed();
162       }
163
164       @Override
165       public void removeUpdate(DocumentEvent e)
166       {
167         txt_search_ActionPerformed();
168       }
169
170       @Override
171       public void changedUpdate(DocumentEvent e)
172       {
173         txt_search_ActionPerformed();
174       }
175     });
176
177     final String searchTabTitle = MessageManager
178             .getString("label.search_result");
179     ChangeListener changeListener = new ChangeListener()
180     {
181       public void stateChanged(ChangeEvent changeEvent)
182       {
183         JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent
184                 .getSource();
185         int index = sourceTabbedPane.getSelectedIndex();
186         if (sourceTabbedPane.getTitleAt(index).equals(searchTabTitle))
187         {
188           txt_search_ActionPerformed();
189         }
190       }
191     };
192     tabbedPane.addChangeListener(changeListener);
193     tabbedPane.setPreferredSize(new Dimension(500, 300));
194     tabbedPane.add(searchTabTitle, scrl_searchResult);
195     tabbedPane.add(
196             MessageManager.getString("label.configure_displayed_columns"),
197             pdbDocFieldPrefs);
198
199     pnl_actions.add(btn_back);
200     pnl_actions.add(btn_ok);
201     pnl_actions.add(btn_cancel);
202
203     pnl_results.add(tabbedPane);
204     pnl_inputs.add(cmb_searchTarget);
205     pnl_inputs.add(txt_search);
206
207     this.setLayout(mainLayout);
208     this.add(pnl_inputs, java.awt.BorderLayout.NORTH);
209     this.add(pnl_results, java.awt.BorderLayout.CENTER);
210     this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
211     mainFrame.setVisible(true);
212     mainFrame.setContentPane(this);
213     mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
214     Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
215   }
216
217   public JComboBox<PDBDocField> getCmbSearchTarget()
218   {
219     return cmb_searchTarget;
220   }
221
222   public JTextField getTxtSearch()
223   {
224     return txt_search;
225   }
226
227   public JInternalFrame getMainFrame()
228   {
229     return mainFrame;
230   }
231
232   public abstract void txt_search_ActionPerformed();
233
234   public abstract void btn_ok_ActionPerformed();
235
236   public abstract void btn_back_ActionPerformed();
237
238   public abstract void btn_cancel_ActionPerformed();
239
240   public abstract void populateCmbSearchTargetOptions();
241
242 }