JAL-1668 added validation for manual entry of pdb structures
[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 import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary;
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.JList;
39 import javax.swing.JPanel;
40 import javax.swing.JScrollPane;
41 import javax.swing.JTextField;
42 import javax.swing.ListSelectionModel;
43 import javax.swing.event.DocumentEvent;
44 import javax.swing.event.DocumentListener;
45
46 /**
47  * GUI layout for PDB Fetch Panel
48  * 
49  * @author tcnofoegbu
50  *
51  */
52 @SuppressWarnings("serial")
53 public abstract class GPDBSearchPanel extends JPanel
54 {
55   protected String frameTitle = MessageManager
56           .getString("label.pdb_sequence_getcher");
57
58   protected JInternalFrame mainFrame = new JInternalFrame(frameTitle);
59
60   protected JComboBox<PDBDocField> cmb_searchTarget = new JComboBox<PDBDocField>();
61
62   protected JButton btn_ok = new JButton();
63
64   protected JButton btn_back = new JButton();
65   
66   protected JButton btn_cancel = new JButton();
67   
68   protected JTextField txt_search = new JTextField(20);
69   
70   protected JList<PDBResponseSummary> lst_searchResult = new JList<PDBResponseSummary>();
71
72   protected JScrollPane scrl_searchResult = new JScrollPane(
73           lst_searchResult);
74
75   private JPanel pnl_actions = new JPanel();
76
77   private JPanel pnl_results = new JPanel();
78
79   private JPanel pnl_inputs = new JPanel();
80
81   private BorderLayout mainLayout = new BorderLayout();
82
83   public GPDBSearchPanel()
84   {
85     try
86     {
87       jbInit();
88       mainFrame.invalidate();
89       mainFrame.pack();
90     } catch (Exception e)
91     {
92       e.printStackTrace();
93     }
94   }
95
96   /**
97    * Initializes the GUI default properties
98    * 
99    * @throws Exception
100    */
101   private void jbInit() throws Exception
102   {
103     btn_back.setFont(new java.awt.Font("Verdana", 0, 12));
104     btn_back.setText(MessageManager.getString("action.back"));
105     btn_back.addActionListener(new java.awt.event.ActionListener()
106     {
107       public void actionPerformed(ActionEvent e)
108       {
109         btn_back_ActionPerformed();
110       }
111     });
112     btn_ok.setFont(new java.awt.Font("Verdana", 0, 12));
113     btn_ok.setText(MessageManager.getString("action.ok"));
114     btn_ok.addActionListener(new java.awt.event.ActionListener()
115     {
116       public void actionPerformed(ActionEvent e)
117       {
118         btn_ok_ActionPerformed();
119       }
120     });
121     btn_cancel.setFont(new java.awt.Font("Verdana", 0, 12));
122     btn_cancel.setText(MessageManager.getString("action.cancel"));
123     btn_cancel.addActionListener(new java.awt.event.ActionListener()
124     {
125       public void actionPerformed(ActionEvent e)
126       {
127         btn_cancel_ActionPerformed();
128       }
129     });
130     pnl_actions.add(btn_back);
131     pnl_actions.add(btn_ok);
132     pnl_actions.add(btn_cancel);
133
134     lst_searchResult
135             .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
136     lst_searchResult.setLayoutOrientation(JList.VERTICAL);
137     lst_searchResult.setVisibleRowCount(-1);
138     scrl_searchResult.setPreferredSize(new Dimension(500, 300));
139     scrl_searchResult
140             .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
141     pnl_results.add(scrl_searchResult);
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     pnl_inputs.add(cmb_searchTarget);
178     pnl_inputs.add(txt_search);
179
180     this.setLayout(mainLayout);
181     this.add(pnl_inputs, java.awt.BorderLayout.NORTH);
182     this.add(pnl_results, java.awt.BorderLayout.CENTER);
183     this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
184     mainFrame.setVisible(true);
185     mainFrame.setContentPane(this);
186     mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
187     Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400);
188   }
189
190   public JComboBox<PDBDocField> getCmbSearchTarget()
191   {
192     return cmb_searchTarget;
193   }
194
195   public JTextField getTxtSearch()
196   {
197     return txt_search;
198   }
199
200   public JInternalFrame getMainFrame()
201   {
202     return mainFrame;
203   }
204
205   public abstract void txt_search_ActionPerformed();
206
207   public abstract void btn_ok_ActionPerformed();
208
209   public abstract void btn_back_ActionPerformed();
210
211   public abstract void btn_cancel_ActionPerformed();
212
213   public abstract void populateCmbSearchTargetOptions();
214
215 }