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