svn-gvsig-desktop / trunk / libraries / libUI / src / org / gvsig / gui / beans / filterPanel / AbstractFilterQueryJPanel.java @ 9033
History | View | Annotate | Download (12.6 KB)
1 |
package org.gvsig.gui.beans.filterPanel; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import java.awt.GridBagConstraints; |
5 |
import java.awt.GridBagLayout; |
6 |
import java.beans.PropertyChangeEvent; |
7 |
import java.beans.PropertyChangeListener; |
8 |
import java.io.Serializable; |
9 |
import java.util.Vector; |
10 |
|
11 |
import javax.swing.DefaultListModel; |
12 |
import javax.swing.JPanel; |
13 |
import javax.swing.tree.DefaultTreeCellRenderer; |
14 |
import javax.swing.tree.DefaultTreeModel; |
15 |
|
16 |
import org.gvsig.gui.beans.filterPanel.filterButtons.FilterButtonsJPanel; |
17 |
import org.gvsig.gui.beans.Messages; |
18 |
|
19 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
20 |
*
|
21 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
22 |
*
|
23 |
* This program is free software; you can redistribute it and/or
|
24 |
* modify it under the terms of the GNU General Public License
|
25 |
* as published by the Free Software Foundation; either version 2
|
26 |
* of the License, or (at your option) any later version.
|
27 |
*
|
28 |
* This program is distributed in the hope that it will be useful,
|
29 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
30 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
31 |
* GNU General Public License for more details.
|
32 |
*
|
33 |
* You should have received a copy of the GNU General Public License
|
34 |
* along with this program; if not, write to the Free Software
|
35 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
36 |
*
|
37 |
* For more information, contact:
|
38 |
*
|
39 |
* Generalitat Valenciana
|
40 |
* Conselleria d'Infraestructures i Transport
|
41 |
* Av. Blasco Ib??ez, 50
|
42 |
* 46010 VALENCIA
|
43 |
* SPAIN
|
44 |
*
|
45 |
* +34 963862235
|
46 |
* gvsig@gva.es
|
47 |
* www.gvsig.gva.es
|
48 |
*
|
49 |
* or
|
50 |
*
|
51 |
* IVER T.I. S.A
|
52 |
* Salamanca 50
|
53 |
* 46005 Valencia
|
54 |
* Spain
|
55 |
*
|
56 |
* +34 963163400
|
57 |
* dac@iver.es
|
58 |
*/
|
59 |
|
60 |
/**
|
61 |
* This abstract class represents the common components of the FilterQuery panels
|
62 |
*
|
63 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
64 |
*/
|
65 |
public abstract class AbstractFilterQueryJPanel extends JPanel implements Serializable { |
66 |
public static final int DefaultHeight = 280; |
67 |
public static final int DefaultWidth = 490; |
68 |
|
69 |
protected final int fieldsJPanelHeight = 135; |
70 |
protected final int fieldsJPanelWidth = 145; |
71 |
protected final int valuesJPanelHeight = fieldsJPanelHeight; |
72 |
protected final int valuesJPanelWidth = fieldsJPanelWidth; |
73 |
protected final int defaultBottomJPanelWidth = 480; |
74 |
protected final int defaultBottomJPanelHeight = 120; |
75 |
protected int filterJScrollPaneHeight; |
76 |
protected int filterJScrollPanelWidth; |
77 |
protected final int filterButtonsPanelHeight = FilterButtonsJPanel.default_FilterButtonsJPanellHeight; |
78 |
protected final int filterButtonsPanelWidth = FilterButtonsJPanel.default_FilterButtonsJPanelWidth; |
79 |
protected final int defaultTopJPanelWidth = defaultBottomJPanelWidth; |
80 |
protected final int defaultTopJPanelHeight = 135; |
81 |
protected int fieldsAndValuesJScrollPaneHeight = 100; |
82 |
protected int fieldsAndValuesJScrollPaneWidth = fieldsJPanelWidth; |
83 |
|
84 |
protected javax.swing.JLabel fieldsJLabel = null; |
85 |
protected javax.swing.JLabel valuesJLabel = null; |
86 |
protected javax.swing.JPanel fieldsJPanel = null; |
87 |
protected javax.swing.JPanel valuesJPanel = null; |
88 |
protected FilterButtonsJPanel filterButtonsJPanel = null; |
89 |
protected javax.swing.JScrollPane filterJScrollPane = null; |
90 |
protected javax.swing.JPanel topJPanel = null; |
91 |
protected javax.swing.JPanel bottomJPanel = null; |
92 |
protected javax.swing.JTextArea txtExpression = null; |
93 |
protected javax.swing.JTree fieldsJTree = null; |
94 |
protected javax.swing.JList valuesJList = null; |
95 |
protected javax.swing.JScrollPane fieldsJScrollPane = null; |
96 |
protected javax.swing.JScrollPane valuesJScrollPane = null; |
97 |
|
98 |
protected String title; |
99 |
|
100 |
protected DefaultTreeModel defaultTreeModel; |
101 |
protected DefaultListModel valuesListModel; |
102 |
|
103 |
|
104 |
/**
|
105 |
* This is the default constructor
|
106 |
*/
|
107 |
public AbstractFilterQueryJPanel(String _title) { |
108 |
super();
|
109 |
title = _title; |
110 |
} |
111 |
/**
|
112 |
* This is the default constructor
|
113 |
*/
|
114 |
public AbstractFilterQueryJPanel() {
|
115 |
super();
|
116 |
} |
117 |
|
118 |
/**
|
119 |
* This method initializes this
|
120 |
*/
|
121 |
protected void initialize() { |
122 |
this.setPreferredSize(new Dimension(DefaultWidth, DefaultHeight)); |
123 |
|
124 |
this.setLayout(new GridBagLayout()); |
125 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
126 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
127 |
gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
|
128 |
|
129 |
gridBagConstraints.anchor = GridBagConstraints.NORTH;
|
130 |
this.add(getTopJPanel(), gridBagConstraints);
|
131 |
|
132 |
gridBagConstraints.anchor = GridBagConstraints.SOUTH;
|
133 |
this.add(getBottomJPanel(), gridBagConstraints);
|
134 |
} |
135 |
|
136 |
/**
|
137 |
* This method initializes topJPanel
|
138 |
*
|
139 |
* @return javax.swing.JPanel
|
140 |
*/
|
141 |
protected javax.swing.JPanel getTopJPanel() {
|
142 |
if (topJPanel == null) { |
143 |
topJPanel = new JPanel(); |
144 |
|
145 |
topJPanel.setPreferredSize(new Dimension(defaultTopJPanelWidth, defaultTopJPanelHeight)); |
146 |
topJPanel.setLayout(new GridBagLayout()); |
147 |
|
148 |
GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
149 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
150 |
|
151 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
152 |
topJPanel.add(getFieldsJPanel(), gridBagConstraints); |
153 |
|
154 |
gridBagConstraints.anchor = GridBagConstraints.CENTER;
|
155 |
topJPanel.add(getFilterButtonsJPanel(), gridBagConstraints); |
156 |
|
157 |
gridBagConstraints.anchor = GridBagConstraints.EAST;
|
158 |
topJPanel.add(getValuesJPanel(), gridBagConstraints); |
159 |
} |
160 |
|
161 |
return topJPanel;
|
162 |
} |
163 |
|
164 |
/**
|
165 |
* This method initializes bottomJPanel
|
166 |
*
|
167 |
* @return javax.swing.JPanel
|
168 |
*/
|
169 |
protected abstract JPanel getBottomJPanel(); |
170 |
|
171 |
/**
|
172 |
* This method initializes fieldsJLabel
|
173 |
*
|
174 |
* @return javax.swing.JLabel
|
175 |
*/
|
176 |
protected javax.swing.JLabel getFieldsJLabel() {
|
177 |
if (fieldsJLabel == null) { |
178 |
fieldsJLabel = new javax.swing.JLabel();
|
179 |
fieldsJLabel.setText(Messages.getText("Campos") + ":"); |
180 |
} |
181 |
|
182 |
return fieldsJLabel;
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* This method initializes fieldsJPanel
|
187 |
*
|
188 |
* @return javax.swing.JPanel
|
189 |
*/
|
190 |
protected abstract JPanel getFieldsJPanel(); |
191 |
|
192 |
/**
|
193 |
* This method initializes valuesJLabel
|
194 |
*
|
195 |
* @return javax.swing.JLabel
|
196 |
*/
|
197 |
protected javax.swing.JLabel getValuesJLabel() {
|
198 |
if (valuesJLabel == null) { |
199 |
valuesJLabel = new javax.swing.JLabel();
|
200 |
valuesJLabel.setText(Messages.getText("Valores") + ":"); |
201 |
} |
202 |
|
203 |
return valuesJLabel;
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* This method initializes valuesJPanel
|
208 |
*
|
209 |
* @return javax.swing.JPanel
|
210 |
*/
|
211 |
protected abstract JPanel getValuesJPanel(); |
212 |
|
213 |
/**
|
214 |
* This method initializes filterJScrollPane
|
215 |
*
|
216 |
* @return javax.swing.JScrollPane
|
217 |
*/
|
218 |
protected abstract javax.swing.JScrollPane getFilterJScrollPane(); |
219 |
|
220 |
/**
|
221 |
* DOCUMENT ME!
|
222 |
*
|
223 |
* @param symbol DOCUMENT ME!
|
224 |
*/
|
225 |
protected void putSymbol(String symbol) { |
226 |
int position = txtExpression.getCaretPosition();
|
227 |
|
228 |
txtExpression.setText(insert(txtExpression.getText(), position, symbol)); |
229 |
|
230 |
if (symbol.equals(" () ")) { |
231 |
position = position + 2;
|
232 |
} else {
|
233 |
position = position + symbol.length(); |
234 |
} |
235 |
|
236 |
txtExpression.setCaretPosition(position); |
237 |
} |
238 |
|
239 |
/**
|
240 |
* This method initializes fieldsJTree
|
241 |
*
|
242 |
* @return javax.swing.JTree
|
243 |
*/
|
244 |
/*
|
245 |
* (non-Javadoc)
|
246 |
* @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getLstCampos()
|
247 |
*/
|
248 |
protected javax.swing.JTree getFieldsJTree() {
|
249 |
if (fieldsJTree == null) { |
250 |
fieldsJTree = new javax.swing.JTree(new Vector(0,1)); |
251 |
|
252 |
// Remove icons:
|
253 |
DefaultTreeCellRenderer defaultTreeCellRenderer = new DefaultTreeCellRenderer(); |
254 |
defaultTreeCellRenderer.setOpenIcon(null);
|
255 |
defaultTreeCellRenderer.setClosedIcon(null);
|
256 |
defaultTreeCellRenderer.setLeafIcon(null);
|
257 |
|
258 |
// Root not visible
|
259 |
fieldsJTree.setRootVisible(false);
|
260 |
fieldsJTree.setCellRenderer(defaultTreeCellRenderer); |
261 |
} |
262 |
|
263 |
return fieldsJTree;
|
264 |
} |
265 |
|
266 |
/**
|
267 |
* This method initializes valuesJList
|
268 |
*
|
269 |
* @return javax.swing.JList
|
270 |
*/
|
271 |
protected javax.swing.JList getValuesJList() {
|
272 |
if (valuesJList == null) { |
273 |
valuesJList = new javax.swing.JList(new DefaultListModel()); |
274 |
valuesListModel = new DefaultListModel(); |
275 |
valuesJList.setModel(valuesListModel); |
276 |
valuesJList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
277 |
|
278 |
// valuesJList.addMouseListener(new MouseAdapter() {
|
279 |
// /*
|
280 |
// * (non-Javadoc)
|
281 |
// * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
282 |
// */
|
283 |
// public void mouseClicked(MouseEvent e) {
|
284 |
// if (e.getClickCount() == 2) {
|
285 |
// int row = fieldsJTree.getRowForLocation(e.getX(), e.getY());
|
286 |
//
|
287 |
// if (row > -1) {
|
288 |
// putSymbol(((DefaultListModel)valuesJList.getModel()).get(row).toString());
|
289 |
// }
|
290 |
// }
|
291 |
// }
|
292 |
// });
|
293 |
} |
294 |
|
295 |
return valuesJList;
|
296 |
} |
297 |
|
298 |
/**
|
299 |
* Inserta una string en otra en la posici?n indicada
|
300 |
*
|
301 |
* @param base String donde se inserta
|
302 |
* @param position posici?n de "base" donde se inserta la String
|
303 |
* @param injerto String que se inserta en "base"
|
304 |
*
|
305 |
* @return String con la inserci?n hecha
|
306 |
*/
|
307 |
protected static String insert(String base, int position, String injerto) { |
308 |
return base.substring(0, position) + injerto + |
309 |
base.substring(position); |
310 |
} |
311 |
|
312 |
|
313 |
/**
|
314 |
* This method initializes filterButtonsJPanel
|
315 |
*
|
316 |
* @return javax.swing.JPanel
|
317 |
*/
|
318 |
protected JPanel getFilterButtonsJPanel() { |
319 |
if (filterButtonsJPanel == null) { |
320 |
filterButtonsJPanel = new FilterButtonsJPanel();
|
321 |
filterButtonsJPanel.setPreferredSize(new Dimension(filterButtonsPanelWidth, filterButtonsPanelHeight)); |
322 |
filterButtonsJPanel.addPropertyChangeListener(new PropertyChangeListener() { |
323 |
/*
|
324 |
* (non-Javadoc)
|
325 |
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
|
326 |
*/
|
327 |
public void propertyChange(PropertyChangeEvent arg0) { |
328 |
if (arg0.getPropertyName().equals(FilterButtonsJPanel.BUTTON_CLICKED_ACTION_COMMAND)) {
|
329 |
|
330 |
switch(Integer.parseInt(arg0.getNewValue().toString())) { |
331 |
case FilterButtonsJPanel.AND:
|
332 |
putSymbol(" and ");
|
333 |
break;
|
334 |
case FilterButtonsJPanel.DATE:
|
335 |
putSymbol( ((FilterButtonsJPanel)arg0.getSource()).getLastSelectedDate() ); |
336 |
break;
|
337 |
case FilterButtonsJPanel.DISTINCT:
|
338 |
putSymbol(" <> ");
|
339 |
break;
|
340 |
case FilterButtonsJPanel.EQUAL:
|
341 |
putSymbol(" = ");
|
342 |
break;
|
343 |
case FilterButtonsJPanel.EQUALGREATER:
|
344 |
putSymbol(" >= ");
|
345 |
break;
|
346 |
case FilterButtonsJPanel.EQUALSMALLER:
|
347 |
putSymbol(" <= ");
|
348 |
break;
|
349 |
case FilterButtonsJPanel.GREATER:
|
350 |
putSymbol(" > ");
|
351 |
break;
|
352 |
case FilterButtonsJPanel.NOT:
|
353 |
putSymbol(" not ");
|
354 |
break;
|
355 |
case FilterButtonsJPanel.OR:
|
356 |
putSymbol(" or ");
|
357 |
break;
|
358 |
case FilterButtonsJPanel.PARENTHESIS:
|
359 |
putSymbol(" () ");
|
360 |
break;
|
361 |
case FilterButtonsJPanel.SMALLER:
|
362 |
putSymbol(" < ");
|
363 |
break;
|
364 |
case FilterButtonsJPanel.DELETE_TEXT:
|
365 |
txtExpression.setText("");
|
366 |
break;
|
367 |
default: // do anything |
368 |
} |
369 |
} |
370 |
} |
371 |
}); |
372 |
} |
373 |
|
374 |
return filterButtonsJPanel;
|
375 |
} |
376 |
|
377 |
/**
|
378 |
* Sets new height to the 'topJPanel', (new Height must be bigger than default, else do nothing)
|
379 |
*
|
380 |
* @param new_Height New height
|
381 |
*/
|
382 |
public void resizeHeight(int new_Height) { |
383 |
int difference = new_Height - DefaultHeight;
|
384 |
|
385 |
if (difference > 0) { |
386 |
this.setPreferredSize(new Dimension(this.getPreferredSize().width, this.getPreferredSize().height + difference)); |
387 |
topJPanel.setPreferredSize(new Dimension(topJPanel.getPreferredSize().width, topJPanel.getPreferredSize().height + difference)); |
388 |
|
389 |
fieldsJPanel.setPreferredSize(new Dimension(fieldsJPanel.getPreferredSize().width, fieldsJPanel.getPreferredSize().height + difference)); |
390 |
fieldsJScrollPane.setPreferredSize(new Dimension(fieldsJScrollPane.getPreferredSize().width, fieldsJScrollPane.getPreferredSize().height + difference)); |
391 |
|
392 |
valuesJPanel.setPreferredSize(new Dimension(valuesJPanel.getPreferredSize().width, valuesJPanel.getPreferredSize().height + difference)); |
393 |
valuesJScrollPane.setPreferredSize(new Dimension(valuesJScrollPane.getPreferredSize().width, valuesJScrollPane.getPreferredSize().height + difference)); |
394 |
} |
395 |
} |
396 |
|
397 |
/**
|
398 |
* Sets the width to this JPanel
|
399 |
*
|
400 |
* @param new_Width New width
|
401 |
*/
|
402 |
public abstract void resizeWidth(int new_Width); |
403 |
|
404 |
/*
|
405 |
* (non-Javadoc)
|
406 |
* @see java.awt.Component#resize(int, int)
|
407 |
*/
|
408 |
public void resize(int width, int height) { |
409 |
int difference = height - DefaultHeight;
|
410 |
|
411 |
if (difference != 0) |
412 |
this.resizeHeight(height);
|
413 |
|
414 |
this.resizeWidth(width);
|
415 |
} |
416 |
|
417 |
/*
|
418 |
* (non-Javadoc)
|
419 |
* @see java.awt.Component#resize(java.awt.Dimension)
|
420 |
*/
|
421 |
public void resize(Dimension d) { |
422 |
int difference = d.height - DefaultHeight;
|
423 |
|
424 |
if (difference != 0) |
425 |
this.resizeHeight(d.height);
|
426 |
|
427 |
this.resizeWidth(d.width);
|
428 |
} |
429 |
} |