root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / ui / SearchDialogPanel.java @ 3099
History | View | Annotate | Download (9.8 KB)
1 | 2820 | jorpiell | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | 2145 | jorpiell | package es.gva.cit.catalogClient.ui; |
42 | |||
43 | 2724 | jorpiell | import es.gva.cit.catalogClient.CatalogClient; |
44 | 3073 | jorpiell | import es.gva.cit.catalogClient.metadataXML.XMLNode; |
45 | 2724 | jorpiell | import es.gva.cit.catalogClient.querys.Query; |
46 | |||
47 | 2145 | jorpiell | import java.awt.Dimension; |
48 | import java.awt.FlowLayout; |
||
49 | import java.awt.event.ActionEvent; |
||
50 | import java.awt.event.ActionListener; |
||
51 | 2985 | jorpiell | import java.awt.event.ItemEvent; |
52 | import java.awt.event.ItemListener; |
||
53 | 2145 | jorpiell | |
54 | import javax.swing.BoxLayout; |
||
55 | import javax.swing.JButton; |
||
56 | 2985 | jorpiell | import javax.swing.JCheckBox; |
57 | 2145 | jorpiell | import javax.swing.JDialog; |
58 | 2985 | jorpiell | import javax.swing.JFrame; |
59 | 2145 | jorpiell | import javax.swing.JOptionPane; |
60 | import javax.swing.JPanel; |
||
61 | |||
62 | |||
63 | /**
|
||
64 | 2820 | jorpiell | * @author Jorge Piera Llodra (piera_jor@gva.es)
|
65 | 2145 | jorpiell | */
|
66 | 2985 | jorpiell | public class SearchDialogPanel extends JPanel implements ActionListener,ItemListener { |
67 | //This component its used to resize the frame
|
||
68 | private JFrame parent; |
||
69 | |||
70 | 2724 | jorpiell | //Panels
|
71 | 2985 | jorpiell | protected JPanel ppalPanel = null; |
72 | 3099 | jorpiell | protected SearchUpperPanel upperPanel = null; |
73 | protected SearchLowerPanel lowerPanel = null; |
||
74 | 2985 | jorpiell | protected JPanel checkBoxPanel = null; |
75 | protected JPanel buttonsPanel = null; |
||
76 | 2145 | jorpiell | |
77 | 2724 | jorpiell | //Buttons
|
78 | 2868 | jorpiell | private JButton searchButton = null; |
79 | private JButton closeButton = null; |
||
80 | 2985 | jorpiell | private JButton sizeButton = null; |
81 | private JCheckBox areaCheckBox = null; |
||
82 | 2724 | jorpiell | |
83 | //Otros
|
||
84 | 2985 | jorpiell | protected CatalogClient client = null; |
85 | 3073 | jorpiell | protected XMLNode[] nodesRecords = null; |
86 | 2985 | jorpiell | protected boolean isMinimized = true; |
87 | 3031 | jorpiell | protected String currentServer = null; |
88 | 2985 | jorpiell | |
89 | 2724 | jorpiell | /**
|
90 | * This method initializes
|
||
91 | *
|
||
92 | */
|
||
93 | 3099 | jorpiell | public SearchDialogPanel(boolean isMinimized,String title, JFrame parent) { |
94 | 2724 | jorpiell | super();
|
95 | 3099 | jorpiell | this.isMinimized = isMinimized;
|
96 | 2985 | jorpiell | this.parent = parent;
|
97 | initialize(title); |
||
98 | 2724 | jorpiell | } |
99 | |||
100 | /**
|
||
101 | * This method initializes this
|
||
102 | *
|
||
103 | * @return void
|
||
104 | */
|
||
105 | 2985 | jorpiell | protected void initialize(String title) { |
106 | ppalPanel = null;
|
||
107 | 2724 | jorpiell | ppalPanel = new JPanel(); |
108 | ppalPanel.setLocation(0, 0); |
||
109 | ppalPanel.setLayout(new BoxLayout(ppalPanel, BoxLayout.Y_AXIS)); |
||
110 | |||
111 | 3099 | jorpiell | ppalPanel.add(getUpperPanel()); |
112 | 2985 | jorpiell | |
113 | 3099 | jorpiell | if (!(isMinimized))
|
114 | ppalPanel.add(getLowerPanel()); |
||
115 | |||
116 | ppalPanel.add(getButtonsPanel()); |
||
117 | 2724 | jorpiell | |
118 | add(ppalPanel); |
||
119 | |||
120 | setDefaultButtonListeners(); |
||
121 | 2985 | jorpiell | |
122 | setTitle(title); |
||
123 | 3099 | jorpiell | } |
124 | 2985 | jorpiell | /**
|
125 | 3099 | jorpiell | * It Gets the upperPanel
|
126 | 2985 | jorpiell | * @return
|
127 | */
|
||
128 | |||
129 | 3099 | jorpiell | public SearchUpperPanel getUpperPanel() {
|
130 | if (upperPanel == null){ |
||
131 | upperPanel = new SearchUpperPanel();
|
||
132 | |||
133 | 2724 | jorpiell | } |
134 | 3099 | jorpiell | return upperPanel;
|
135 | |||
136 | 2724 | jorpiell | } |
137 | 2985 | jorpiell | /**
|
138 | 3099 | jorpiell | * It Gets the lowePanel
|
139 | 2985 | jorpiell | * @return
|
140 | */
|
||
141 | 3099 | jorpiell | |
142 | public SearchLowerPanel getLowerPanel() {
|
||
143 | if (!(isMinimized)){
|
||
144 | parent.setSize(625,450); |
||
145 | if (lowerPanel == null){ |
||
146 | lowerPanel = new SearchLowerPanel();
|
||
147 | upperPanel.setUpIcon(); |
||
148 | } |
||
149 | } |
||
150 | return lowerPanel;
|
||
151 | 2985 | jorpiell | } |
152 | |||
153 | 3099 | jorpiell | /**
|
154 | 2985 | jorpiell | * It gets the buttons panel
|
155 | * @return
|
||
156 | */
|
||
157 | public JPanel getButtonsPanel() { |
||
158 | 2724 | jorpiell | if (buttonsPanel == null) { |
159 | buttonsPanel = new JPanel(new FlowLayout()); |
||
160 | buttonsPanel.add(getSearchButton()); |
||
161 | 2868 | jorpiell | buttonsPanel.add(getCloseButton()); |
162 | 2724 | jorpiell | } |
163 | return buttonsPanel;
|
||
164 | } |
||
165 | 2985 | jorpiell | |
166 | /**
|
||
167 | * It gets the search button
|
||
168 | * @return
|
||
169 | */
|
||
170 | 2724 | jorpiell | public JButton getSearchButton() { |
171 | 2868 | jorpiell | if (searchButton == null) { |
172 | searchButton = new JButton("Buscar"); |
||
173 | searchButton.setSize(new Dimension(30, 20)); |
||
174 | 2985 | jorpiell | searchButton.setActionCommand("Search");
|
175 | 2724 | jorpiell | } |
176 | |||
177 | 2868 | jorpiell | return searchButton;
|
178 | 2724 | jorpiell | } |
179 | 2868 | jorpiell | |
180 | 2985 | jorpiell | /**
|
181 | * It gets the close button
|
||
182 | * @return
|
||
183 | */
|
||
184 | 2868 | jorpiell | public JButton getCloseButton() { |
185 | if (closeButton == null) { |
||
186 | closeButton = new JButton("Cerrar"); |
||
187 | closeButton.setSize(new Dimension(30, 20)); |
||
188 | 2985 | jorpiell | closeButton.setActionCommand("Close");
|
189 | 2868 | jorpiell | } |
190 | 2724 | jorpiell | |
191 | 2868 | jorpiell | return closeButton;
|
192 | } |
||
193 | |||
194 | 2985 | jorpiell | /**
|
195 | * It gets the change size button
|
||
196 | * @return
|
||
197 | */
|
||
198 | public JButton getSizeButton() { |
||
199 | if (sizeButton == null) { |
||
200 | 3099 | jorpiell | sizeButton = upperPanel.getSizeButton(); |
201 | 2985 | jorpiell | sizeButton.setActionCommand("Size");
|
202 | } |
||
203 | return sizeButton;
|
||
204 | } |
||
205 | 2868 | jorpiell | |
206 | 2985 | jorpiell | /**
|
207 | * It gets the checkBox area component
|
||
208 | * @return
|
||
209 | */
|
||
210 | public JCheckBox getAreaCheckBox(){ |
||
211 | if (areaCheckBox == null){ |
||
212 | 3099 | jorpiell | areaCheckBox = upperPanel.getCoordinatesCheckBox(); |
213 | 2985 | jorpiell | areaCheckBox.setActionCommand("areaCheckButton");
|
214 | } |
||
215 | return areaCheckBox;
|
||
216 | } |
||
217 | |||
218 | /**
|
||
219 | * It sets the listeners
|
||
220 | *
|
||
221 | */
|
||
222 | 2724 | jorpiell | public void setDefaultButtonListeners() { |
223 | getSearchButton().addActionListener(this);
|
||
224 | 2868 | jorpiell | getCloseButton().addActionListener(this);
|
225 | 2985 | jorpiell | getSizeButton().addActionListener(this);
|
226 | 3099 | jorpiell | getAreaCheckBox().addItemListener(this);
|
227 | } |
||
228 | 2985 | jorpiell | |
229 | /* (non-Javadoc)
|
||
230 | 2724 | jorpiell | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
231 | */
|
||
232 | public void actionPerformed(ActionEvent e) { |
||
233 | //Buscar
|
||
234 | 2985 | jorpiell | if (e.getActionCommand() == "Search") { |
235 | 2868 | jorpiell | searchButtonActionPerformed(); |
236 | } |
||
237 | 2985 | jorpiell | if (e.getActionCommand() == "Close") { |
238 | 2868 | jorpiell | closeButtonActionPerformed(); |
239 | } |
||
240 | 2985 | jorpiell | if (e.getActionCommand() == "Size") { |
241 | sizeButtonActionPerformed(); |
||
242 | 3099 | jorpiell | } |
243 | 2985 | jorpiell | |
244 | } |
||
245 | |||
246 | protected void sizeButtonActionPerformed(){ |
||
247 | parent.setVisible(false);
|
||
248 | 3099 | jorpiell | new SearchDialog(client,!(isMinimized),upperPanel.getTitle());
|
249 | 2868 | jorpiell | } |
250 | |||
251 | protected void searchButtonActionPerformed(){ |
||
252 | Query currentQuery = doQuery();
|
||
253 | doSearch(); |
||
254 | 2724 | jorpiell | |
255 | 2868 | jorpiell | if ((nodesRecords != null) && (nodesRecords.length > 1)) { |
256 | showResults(nodesRecords); |
||
257 | 2724 | jorpiell | } |
258 | } |
||
259 | 2868 | jorpiell | |
260 | protected void closeButtonActionPerformed(){ |
||
261 | 2985 | jorpiell | parent.setVisible(false);
|
262 | 2868 | jorpiell | } |
263 | 2724 | jorpiell | |
264 | 2985 | jorpiell | /**
|
265 | * It returns the query that the user has selected
|
||
266 | * @return
|
||
267 | */
|
||
268 | 2724 | jorpiell | public Query doQuery() { |
269 | 3099 | jorpiell | Query query = null; |
270 | if (isMinimized){
|
||
271 | query = new Query(upperPanel.getTitle(), |
||
272 | "E", null, |
||
273 | null , null, |
||
274 | null , null, |
||
275 | null , null, |
||
276 | null , null); |
||
277 | |||
278 | }else{
|
||
279 | query = new Query(upperPanel.getTitle(), |
||
280 | lowerPanel.getTitleOption(), lowerPanel.getAbstract(), |
||
281 | lowerPanel.getKeys(), lowerPanel.getCathegory(), |
||
282 | lowerPanel.getScale(), lowerPanel.getProvider(), |
||
283 | lowerPanel.getDateFrom(), lowerPanel.getDateTo(), |
||
284 | lowerPanel.getCoordinates(), lowerPanel.getCoordinatesOption()); |
||
285 | } |
||
286 | 2985 | jorpiell | query.setMinimized(isMinimized); |
287 | return query;
|
||
288 | 2724 | jorpiell | } |
289 | 2985 | jorpiell | |
290 | /**
|
||
291 | * This method realizes the search
|
||
292 | *
|
||
293 | */
|
||
294 | 2724 | jorpiell | public void doSearch() { |
295 | 2985 | jorpiell | nodesRecords = client.getLnkICatalogServerDriver().getRecords(client.getUrl(), |
296 | 2724 | jorpiell | doQuery(), 1);
|
297 | |||
298 | if (nodesRecords == null) { |
||
299 | JOptionPane.showMessageDialog(this, |
||
300 | "Se ha producido un error al hacer el get records", "Error", |
||
301 | JOptionPane.ERROR_MESSAGE);
|
||
302 | } else if (nodesRecords.length == 1) { |
||
303 | JOptionPane.showMessageDialog(this, |
||
304 | "La b?squeda no ha producido ning?n resultado", "B?squeda", |
||
305 | JOptionPane.INFORMATION_MESSAGE);
|
||
306 | } |
||
307 | } |
||
308 | 2985 | jorpiell | |
309 | /**
|
||
310 | * This methos calls to present results form
|
||
311 | * @param nodesRecords
|
||
312 | */
|
||
313 | 2724 | jorpiell | |
314 | 3073 | jorpiell | public void showResults(XMLNode[] nodesRecords) { |
315 | 2985 | jorpiell | JDialog dialog = new ShowResultsDialog(client, nodesRecords, 1); |
316 | 3081 | jorpiell | } |
317 | 2985 | jorpiell | |
318 | /* (non-Javadoc)
|
||
319 | * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
|
||
320 | * This methodhave to be implemented in gvSIG to load the bbox to o the search
|
||
321 | */
|
||
322 | public void itemStateChanged(ItemEvent e) { |
||
323 | |||
324 | |||
325 | 3099 | jorpiell | } |
326 | 2985 | jorpiell | |
327 | /**
|
||
328 | 3099 | jorpiell | * It sets the title field
|
329 | * @param title
|
||
330 | 2985 | jorpiell | */
|
331 | 3099 | jorpiell | |
332 | 2985 | jorpiell | public void setTitle(String title){ |
333 | 3099 | jorpiell | upperPanel.setTitle(title); |
334 | 2985 | jorpiell | } |
335 | 3099 | jorpiell | |
336 | 2985 | jorpiell | /**
|
337 | * @param isMinimized The isMinimized to set.
|
||
338 | */
|
||
339 | public void setMinimized(boolean isMinimized) { |
||
340 | this.isMinimized = isMinimized;
|
||
341 | } |
||
342 | 3031 | jorpiell | |
343 | /**
|
||
344 | * @return Returns the currentServer.
|
||
345 | */
|
||
346 | public String getCurrentServer() { |
||
347 | return currentServer;
|
||
348 | } |
||
349 | /**
|
||
350 | * @param currentServer The currentServer to set.
|
||
351 | */
|
||
352 | public void setCurrentServer(String currentServer) { |
||
353 | this.currentServer = currentServer;
|
||
354 | } |
||
355 | 3099 | jorpiell | /**
|
356 | * @param parent The parent to set.
|
||
357 | */
|
||
358 | public void setParent(JFrame parent) { |
||
359 | this.parent = parent;
|
||
360 | } |
||
361 | /**
|
||
362 | * Sets the CatalogClient
|
||
363 | * @param client
|
||
364 | * CatalogClient
|
||
365 | */
|
||
366 | public void setCatalogClient(CatalogClient client) { |
||
367 | this.client = client;
|
||
368 | } |
||
369 | 2724 | jorpiell | } |