Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / filterPanel / filterQueryPanel / FilterQueryJPanel.java @ 40561

History | View | Annotate | Download (13.8 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.filterPanel.filterQueryPanel;
25

    
26
import java.awt.Dimension;
27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
29
import java.io.Serializable;
30

    
31
import javax.swing.BorderFactory;
32
import javax.swing.DefaultListModel;
33
import javax.swing.JCheckBox;
34
import javax.swing.JPanel;
35
import javax.swing.JScrollPane;
36

    
37
import org.gvsig.gui.beans.Messages;
38
import org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel;
39
import org.gvsig.gui.beans.filterPanel.filterQueryPanel.jLabelAsCell.DefaultListModelForJLabelAsCell;
40
import org.gvsig.gui.javax.swing.jLabelCellRenderer.JLabelCellRendererWithTextAsToolTipText;
41

    
42
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
43
 *
44
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
45
 *
46
 * This program is free software; you can redistribute it and/or
47
 * modify it under the terms of the GNU General Public License
48
 * as published by the Free Software Foundation; either version 2
49
 * of the License, or (at your option) any later version.
50
 *
51
 * This program is distributed in the hope that it will be useful,
52
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
53
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
54
 * GNU General Public License for more details.
55
 *
56
 * You should have received a copy of the GNU General Public License
57
 * along with this program; if not, write to the Free Software
58
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
59
 *
60
 * For more information, contact:
61
 *
62
 *  Generalitat Valenciana
63
 *   Conselleria d'Infraestructures i Transport
64
 *   Av. Blasco Ib??ez, 50
65
 *   46010 VALENCIA
66
 *   SPAIN
67
 *
68
 *      +34 963862235
69
 *   gvsig@gva.es
70
 *      www.gvsig.gva.es
71
 *
72
 *    or
73
 *
74
 *   IVER T.I. S.A
75
 *   Salamanca 50
76
 *   46005 Valencia
77
 *   Spain
78
 *
79
 *   +34 963163400
80
 *   dac@iver.es
81
 */
82

    
83
/**
84
 * This class is a version of the graphical interface of "FilterDialog" which was made by Fernando and is in 'appgvSIG' project.
85
 * It's supposed that other classes will extend from this and will add the logic as is in the "FilterDialog" class.
86
 * 
87
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
88
 */
89
public class FilterQueryJPanel extends AbstractFilterQueryJPanel implements Serializable{
90
        private static final long serialVersionUID = -1657663414129590679L;
91

    
92
        protected JPanelML topCenterJPanel = null;
93
        protected JCheckBoxML validateFilterExpressionJCheckBox = null;
94
        
95
        protected int filterJScrollPaneHeight = defaultBottomJPanelHeight - 10;
96
        protected int filterJScrollPanelWidth = defaultBottomJPanelWidth;
97
        protected int validateFilterExpressionJCheckBoxHeight = 20;
98
        
99
        /**
100
         * @see AbstractFilterQueryJPanel#AbstractFilterQueryJPanel()
101
         */
102
        public FilterQueryJPanel() {
103
                super();
104
                this.initialize();
105
        }
106

    
107
        /**
108
         * @see AbstractFilterQueryJPanel#AbstractFilterQueryJPanel(String)
109
         */
110
        public FilterQueryJPanel(String _title) {
111
                super(_title);
112
                this.initialize();
113
        }
114

    
115
        /*
116
         *  (non-Javadoc)
117
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#initialize()
118
         */
119
        protected void initialize() {
120
                super.initialize();
121
                this.setBorder(BorderFactory.createTitledBorder(Messages.getText("filter_by_sentence")));
122
                getValuesJList().setCellRenderer(new JLabelCellRendererWithTextAsToolTipText());
123

    
124
//                /**
125
//                 * This listener allows show in the tool tip text the value of the item when
126
//                 *   the wheel of the mouse is beeing moved
127
//                 */
128
//                getValuesJScrollPane().addMouseWheelListener(new MouseWheelListener() {
129
//                        public void mouseWheelMoved(MouseWheelEvent e) {
130
//                                if (e.getSource() != null) {
131
//                                        Object obj = ((JScrollPane)e.getSource()).getViewport().getComponent(0);
132
//                                        
133
//                                        if (obj instanceof JList) {
134
//                                                int index = ((JList)obj).locationToIndex(e.getPoint());
135
//                                                
136
//                                                if (index >= 0)
137
//                                                        ((JList)obj).setToolTipText( ((JLabel) ((JList)obj).getModel().getElementAt(index)).getText() );
138
//                                        }
139
//                                }
140
//                        }
141
//                        
142
//                });
143
        }
144
        
145
        /*
146
         *  (FilterQueryJPanel)
147
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getFieldsJPanel()
148
         */
149
        protected JPanel getFieldsJPanel() {
150
                if (fieldsJPanel == null) {
151
                        fieldsJPanel = new JPanelML();
152
                        fieldsJPanel.setPreferredSize(new java.awt.Dimension(fieldsJPanelWidth, fieldsJPanelHeight));
153
                        fieldsJPanel.setLayout(new GridBagLayout());
154
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
155
                        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
156
                        gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
157
                        gridBagConstraints.anchor = GridBagConstraints.NORTH;                        
158
                        fieldsJPanel.add(getFieldsJLabel(), gridBagConstraints);
159
                        gridBagConstraints.anchor = GridBagConstraints.SOUTH;
160
                        fieldsJPanel.add(getFieldsJScrollPane(), gridBagConstraints);                        
161
                }
162

    
163
                return fieldsJPanel;
164
        }        
165
        
166
        /**
167
         * @see AbstractFilterQueryJPanel#getValuesJList()
168
         */
169
        protected javax.swing.JList getValuesJList() {
170
                if (valuesJList == null) {
171
                        valuesJList = new JListML(new DefaultListModel());
172
                        valuesListModel = new DefaultListModelForJLabelAsCell();
173
                        valuesJList.setModel(valuesListModel);
174
                        valuesJList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
175
                        
176
//                        valuesJList.addMouseListener(new MouseAdapter() {
177
//                                /*
178
//                                 *  (non-Javadoc)
179
//                                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
180
//                                 */
181
//                                public void mouseClicked(MouseEvent e) {
182
//                                        if (e.getClickCount() == 2) {
183
//                                                int row = fieldsJTree.getRowForLocation(e.getX(), e.getY());
184
//        
185
//                                                if (row > -1) {
186
//                                                        putSymbol(((DefaultListModel)valuesJList.getModel()).get(row).toString());
187
//                                                }
188
//                                        }
189
//                                }
190
//                        });
191
                }
192

    
193
                return valuesJList;
194
        }
195

    
196
        /*
197
         * (non-Javadoc)
198
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getFieldsJScrollPane()
199
         */
200
        protected javax.swing.JScrollPane getFieldsJScrollPane() {
201
                if (fieldsJScrollPane == null) {
202
                        fieldsJScrollPane = new JScrollPaneML();
203
                        fieldsJScrollPane.setPreferredSize(new java.awt.Dimension(fieldsAndValuesJScrollPaneWidth, fieldsAndValuesJScrollPaneHeight));
204
                        fieldsJScrollPane.setViewportView(getFieldsJTree());
205
                }
206

    
207
                return fieldsJScrollPane;
208
        }
209

    
210
        /*
211
         *  (non-Javadoc)
212
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getValuesJPanel()
213
         */
214
        protected JPanel getValuesJPanel() {
215
                if (valuesJPanel == null) {
216
                        valuesJPanel = new JPanelML();
217
                        valuesJPanel.setPreferredSize(new java.awt.Dimension(valuesJPanelWidth, valuesJPanelHeight));
218
                        valuesJPanel.setLayout(new GridBagLayout());
219
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
220
                        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
221
                        gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
222
                        gridBagConstraints.anchor = GridBagConstraints.NORTH;
223
                        valuesJPanel.add(getValuesJLabel(), gridBagConstraints);
224
                        gridBagConstraints.anchor = GridBagConstraints.SOUTH;
225
                        valuesJPanel.add(getValuesJScrollPane(), gridBagConstraints);
226
                }
227

    
228
                return valuesJPanel;
229
        }
230
        
231
        /*
232
         * (non-Javadoc)
233
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getValuesJScrollPane()
234
         */
235
        protected javax.swing.JScrollPane getValuesJScrollPane() {
236
                if (valuesJScrollPane == null) {
237
                        valuesJScrollPane = new JScrollPaneML();
238
                        valuesJScrollPane.setPreferredSize(new Dimension(fieldsAndValuesJScrollPaneWidth, fieldsAndValuesJScrollPaneHeight));
239
                        valuesJScrollPane.setViewportView(getValuesJList());
240
                }
241

    
242
                return valuesJScrollPane;
243
        }
244

    
245
        /*
246
         *  (non-Javadoc)
247
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getFilterJScrollPane()
248
         */
249
        protected JScrollPane getFilterJScrollPane() {
250
                if (filterJScrollPane == null) {
251
                        filterJScrollPane = new JScrollPaneML();
252
                        filterJScrollPane.setPreferredSize(new java.awt.Dimension(filterJScrollPanelWidth, filterJScrollPaneHeight));
253
                        filterJScrollPane.setViewportView(getTxtExpression());
254
                        filterJScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
255
                }
256

    
257
                return filterJScrollPane;
258
        }        
259

    
260
        /*
261
         * (non-Javadoc)
262
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getTxtExpression()
263
         */
264
        protected javax.swing.JTextArea getTxtExpression() {
265
                if (txtExpression == null) {
266
                        txtExpression = new JEditableTextAreaML();
267
                        txtExpression.setLineWrap(true);
268
                        txtExpression.setToolTipText(Messages.getText("write_here_a_filter_expression"));
269
                }
270

    
271
                return txtExpression;
272
        }
273

    
274
        /*
275
         *  (non-Javadoc)
276
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getTopJPanel()
277
         */
278
        protected JPanel getTopJPanel() {
279
                if (topJPanel == null) {
280
                        topJPanel = new JPanelML();
281

    
282
                    topJPanel.setPreferredSize(new Dimension(defaultTopJPanelWidth, defaultTopJPanelHeight));
283
                    topJPanel.setLayout(new GridBagLayout());
284
                    
285
                    GridBagConstraints gridBagConstraints = new GridBagConstraints();
286
                    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;            
287
                    
288
                    gridBagConstraints.anchor = GridBagConstraints.WEST;
289
                    topJPanel.add(getFieldsJPanel(), gridBagConstraints);
290
                    
291
                        gridBagConstraints.anchor = GridBagConstraints.CENTER;
292
//                        topJPanel.add(getFilterButtonsJPanel(), gridBagConstraints);
293
                        topJPanel.add(getTopCenterJPanel(), gridBagConstraints);
294
//                        topJPanel.add(getValidateFilterExpressionJCheckBox(), gridBagConstraints);
295
                        
296
                        gridBagConstraints.anchor = GridBagConstraints.EAST;
297
                        topJPanel.add(getValuesJPanel(), gridBagConstraints);
298
                }
299
                
300
                return topJPanel;
301
        }
302
        
303
        /**
304
         * This method initializes topCenterJPanel
305
         *
306
         * @return javax.swing.JPanel
307
         */
308
        protected JPanel getTopCenterJPanel() {
309
                if (topCenterJPanel == null) {
310
                        topCenterJPanel = new JPanelML();
311
                        topCenterJPanel.setPreferredSize(new Dimension(getFilterButtonsJPanel().getPreferredSize().width, getFilterButtonsJPanel().getPreferredSize().height + validateFilterExpressionJCheckBoxHeight));
312
                        topCenterJPanel.setLayout(null);
313
                        
314
                        getFilterButtonsJPanel().setBounds(0, 0, getFilterButtonsJPanel().getPreferredSize().width, getFilterButtonsJPanel().getPreferredSize().height);
315
                        topCenterJPanel.add(getFilterButtonsJPanel());
316
                        topCenterJPanel.add(getValidateFilterExpressionJCheckBox());
317
                }
318
                return topCenterJPanel;
319
        }
320
        
321
        /**
322
         * This method initializes validateFilterExpressionJCheckBox
323
         *
324
         * @return javax.swing.JCheckBox
325
         */
326
        protected JCheckBox getValidateFilterExpressionJCheckBox() {
327
                if (validateFilterExpressionJCheckBox == null) {
328
                        validateFilterExpressionJCheckBox = new JCheckBoxML();
329
                        validateFilterExpressionJCheckBox.setBounds(5, getFilterButtonsJPanel().getPreferredSize().height, getFilterButtonsJPanel().getWidth(), validateFilterExpressionJCheckBoxHeight);
330
                        validateFilterExpressionJCheckBox.setText(Messages.getText("validate_expression"));
331
                        validateFilterExpressionJCheckBox.setToolTipText(Messages.getText("validate_filter_expression_explanation"));
332
                }
333
                return validateFilterExpressionJCheckBox;
334
        }
335

    
336
        /*
337
         *  (non-Javadoc)
338
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getBottomJPanel()
339
         */
340
        protected JPanel getBottomJPanel() {
341
                if (bottomJPanel == null) {
342
                        bottomJPanel = new JPanelML();
343
                        bottomJPanel.setPreferredSize(new Dimension(defaultBottomJPanelWidth, defaultBottomJPanelHeight));
344
                        bottomJPanel.add(getFilterJScrollPane(), null);
345
                }
346
                
347
                return bottomJPanel;
348
        }
349

    
350
        /*
351
         *  (non-Javadoc)
352
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#resizeWidth(int)
353
         */
354
        public void resizeWidth(int new_Width) {        
355
                int difference = new_Width - DefaultWidth;
356
                
357
                if (difference != 0) {
358
                        this.setPreferredSize(new Dimension(this.getPreferredSize().width + difference, this.getPreferredSize().height));
359
                        getTopJPanel().setPreferredSize(new Dimension(getTopJPanel().getPreferredSize().width + difference, getTopJPanel().getPreferredSize().height));
360
                        getBottomJPanel().setPreferredSize(new Dimension(getBottomJPanel().getPreferredSize().width + difference, getBottomJPanel().getPreferredSize().height));
361
                        getFilterJScrollPane().setPreferredSize(new Dimension(getFilterJScrollPane().getPreferredSize().width + difference, getFilterJScrollPane().getPreferredSize().height));
362
                        
363
                        int halfDifference = difference / 2;
364
                        
365
                        getFieldsJLabel().setPreferredSize(new Dimension(getFieldsJLabel().getPreferredSize().width + halfDifference, getFieldsJLabel().getPreferredSize().height));
366
                        getFieldsJPanel().setPreferredSize(new Dimension(getFieldsJPanel().getPreferredSize().width + halfDifference, getFieldsJPanel().getPreferredSize().height));
367
                        getFieldsJScrollPane().setPreferredSize(new Dimension(getFieldsJScrollPane().getPreferredSize().width + halfDifference, getFieldsJScrollPane().getPreferredSize().height));
368
                
369
                        getValuesJLabel().setPreferredSize(new Dimension(getValuesJLabel().getPreferredSize().width + halfDifference, getValuesJLabel().getPreferredSize().height));
370
                        getValuesJPanel().setPreferredSize(new Dimension(getValuesJPanel().getPreferredSize().width + halfDifference, getValuesJPanel().getPreferredSize().height));
371
                        getValuesJScrollPane().setPreferredSize(new Dimension(getValuesJScrollPane().getPreferredSize().width + halfDifference, getValuesJScrollPane().getPreferredSize().height));
372
                }
373
        }
374
}
375