Statistics
| Revision:

root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / filterPanel / filterQueryPanel / FilterQueryJPanel.java @ 17767

History | View | Annotate | Download (12.9 KB)

1
package org.gvsig.gui.beans.filterPanel.filterQueryPanel;
2

    
3
import java.awt.Dimension;
4
import java.awt.GridBagConstraints;
5
import java.awt.GridBagLayout;
6
import java.io.Serializable;
7

    
8
import javax.swing.BorderFactory;
9
import javax.swing.DefaultListModel;
10
import javax.swing.JCheckBox;
11
import javax.swing.JPanel;
12
import javax.swing.JScrollPane;
13

    
14
import org.gvsig.gui.beans.Messages;
15
import org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel;
16
import org.gvsig.gui.beans.filterPanel.filterQueryPanel.jLabelAsCell.DefaultListModelForJLabelAsCell;
17
import org.gvsig.gui.javax.swing.jLabelCellRenderer.JLabelCellRendererWithTextAsToolTipText;
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 class is a version of the graphical interface of "FilterDialog" which was made by Fernando and is in 'appgvSIG' project.
62
 * It's supposed that other classes will extend from this and will add the logic as is in the "FilterDialog" class.
63
 * 
64
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
65
 */
66
public class FilterQueryJPanel extends AbstractFilterQueryJPanel implements Serializable{
67
        private static final long serialVersionUID = -1657663414129590679L;
68

    
69
        protected JPanelML topCenterJPanel = null;
70
        protected JCheckBoxML validateFilterExpressionJCheckBox = null;
71
        
72
        protected int filterJScrollPaneHeight = defaultBottomJPanelHeight - 10;
73
        protected int filterJScrollPanelWidth = defaultBottomJPanelWidth;
74
        protected int validateFilterExpressionJCheckBoxHeight = 20;
75
        
76
        /**
77
         * @see AbstractFilterQueryJPanel#AbstractFilterQueryJPanel()
78
         */
79
        public FilterQueryJPanel() {
80
                super();
81
                this.initialize();
82
        }
83

    
84
        /**
85
         * @see AbstractFilterQueryJPanel#AbstractFilterQueryJPanel(String)
86
         */
87
        public FilterQueryJPanel(String _title) {
88
                super(_title);
89
                this.initialize();
90
        }
91

    
92
        /*
93
         *  (non-Javadoc)
94
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#initialize()
95
         */
96
        protected void initialize() {
97
                super.initialize();
98
                this.setBorder(BorderFactory.createTitledBorder(Messages.getText("filter_by_sentence")));
99
                getValuesJList().setCellRenderer(new JLabelCellRendererWithTextAsToolTipText());
100

    
101
//                /**
102
//                 * This listener allows show in the tool tip text the value of the item when
103
//                 *   the wheel of the mouse is beeing moved
104
//                 */
105
//                getValuesJScrollPane().addMouseWheelListener(new MouseWheelListener() {
106
//                        public void mouseWheelMoved(MouseWheelEvent e) {
107
//                                if (e.getSource() != null) {
108
//                                        Object obj = ((JScrollPane)e.getSource()).getViewport().getComponent(0);
109
//                                        
110
//                                        if (obj instanceof JList) {
111
//                                                int index = ((JList)obj).locationToIndex(e.getPoint());
112
//                                                
113
//                                                if (index >= 0)
114
//                                                        ((JList)obj).setToolTipText( ((JLabel) ((JList)obj).getModel().getElementAt(index)).getText() );
115
//                                        }
116
//                                }
117
//                        }
118
//                        
119
//                });
120
        }
121
        
122
        /*
123
         *  (FilterQueryJPanel)
124
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getFieldsJPanel()
125
         */
126
        protected JPanel getFieldsJPanel() {
127
                if (fieldsJPanel == null) {
128
                        fieldsJPanel = new JPanelML();
129
                        fieldsJPanel.setPreferredSize(new java.awt.Dimension(fieldsJPanelWidth, fieldsJPanelHeight));
130
                        fieldsJPanel.setLayout(new GridBagLayout());
131
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
132
                        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
133
                        gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
134
                        gridBagConstraints.anchor = GridBagConstraints.NORTH;                        
135
                        fieldsJPanel.add(getFieldsJLabel(), gridBagConstraints);
136
                        gridBagConstraints.anchor = GridBagConstraints.SOUTH;
137
                        fieldsJPanel.add(getFieldsJScrollPane(), gridBagConstraints);                        
138
                }
139

    
140
                return fieldsJPanel;
141
        }        
142
        
143
        /**
144
         * @see AbstractFilterQueryJPanel#getValuesJList()
145
         */
146
        protected javax.swing.JList getValuesJList() {
147
                if (valuesJList == null) {
148
                        valuesJList = new JListML(new DefaultListModel());
149
                        valuesListModel = new DefaultListModelForJLabelAsCell();
150
                        valuesJList.setModel(valuesListModel);
151
                        valuesJList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
152
                        
153
//                        valuesJList.addMouseListener(new MouseAdapter() {
154
//                                /*
155
//                                 *  (non-Javadoc)
156
//                                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
157
//                                 */
158
//                                public void mouseClicked(MouseEvent e) {
159
//                                        if (e.getClickCount() == 2) {
160
//                                                int row = fieldsJTree.getRowForLocation(e.getX(), e.getY());
161
//        
162
//                                                if (row > -1) {
163
//                                                        putSymbol(((DefaultListModel)valuesJList.getModel()).get(row).toString());
164
//                                                }
165
//                                        }
166
//                                }
167
//                        });
168
                }
169

    
170
                return valuesJList;
171
        }
172

    
173
        /*
174
         * (non-Javadoc)
175
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getFieldsJScrollPane()
176
         */
177
        protected javax.swing.JScrollPane getFieldsJScrollPane() {
178
                if (fieldsJScrollPane == null) {
179
                        fieldsJScrollPane = new JScrollPaneML();
180
                        fieldsJScrollPane.setPreferredSize(new java.awt.Dimension(fieldsAndValuesJScrollPaneWidth, fieldsAndValuesJScrollPaneHeight));
181
                        fieldsJScrollPane.setViewportView(getFieldsJTree());
182
                }
183

    
184
                return fieldsJScrollPane;
185
        }
186

    
187
        /*
188
         *  (non-Javadoc)
189
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getValuesJPanel()
190
         */
191
        protected JPanel getValuesJPanel() {
192
                if (valuesJPanel == null) {
193
                        valuesJPanel = new JPanelML();
194
                        valuesJPanel.setPreferredSize(new java.awt.Dimension(valuesJPanelWidth, valuesJPanelHeight));
195
                        valuesJPanel.setLayout(new GridBagLayout());
196
                        GridBagConstraints gridBagConstraints = new GridBagConstraints();
197
                        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
198
                        gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
199
                        gridBagConstraints.anchor = GridBagConstraints.NORTH;
200
                        valuesJPanel.add(getValuesJLabel(), gridBagConstraints);
201
                        gridBagConstraints.anchor = GridBagConstraints.SOUTH;
202
                        valuesJPanel.add(getValuesJScrollPane(), gridBagConstraints);
203
                }
204

    
205
                return valuesJPanel;
206
        }
207
        
208
        /*
209
         * (non-Javadoc)
210
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getValuesJScrollPane()
211
         */
212
        protected javax.swing.JScrollPane getValuesJScrollPane() {
213
                if (valuesJScrollPane == null) {
214
                        valuesJScrollPane = new JScrollPaneML();
215
                        valuesJScrollPane.setPreferredSize(new Dimension(fieldsAndValuesJScrollPaneWidth, fieldsAndValuesJScrollPaneHeight));
216
                        valuesJScrollPane.setViewportView(getValuesJList());
217
                }
218

    
219
                return valuesJScrollPane;
220
        }
221

    
222
        /*
223
         *  (non-Javadoc)
224
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getFilterJScrollPane()
225
         */
226
        protected JScrollPane getFilterJScrollPane() {
227
                if (filterJScrollPane == null) {
228
                        filterJScrollPane = new JScrollPaneML();
229
                        filterJScrollPane.setPreferredSize(new java.awt.Dimension(filterJScrollPanelWidth, filterJScrollPaneHeight));
230
                        filterJScrollPane.setViewportView(getTxtExpression());
231
                        filterJScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
232
                }
233

    
234
                return filterJScrollPane;
235
        }        
236

    
237
        /*
238
         * (non-Javadoc)
239
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getTxtExpression()
240
         */
241
        protected javax.swing.JTextArea getTxtExpression() {
242
                if (txtExpression == null) {
243
                        txtExpression = new JEditableTextAreaML();
244
                        txtExpression.setLineWrap(true);
245
                        txtExpression.setToolTipText(Messages.getText("write_here_a_filter_expression"));
246
                }
247

    
248
                return txtExpression;
249
        }
250

    
251
        /*
252
         *  (non-Javadoc)
253
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getTopJPanel()
254
         */
255
        protected JPanel getTopJPanel() {
256
                if (topJPanel == null) {
257
                        topJPanel = new JPanelML();
258

    
259
                    topJPanel.setPreferredSize(new Dimension(defaultTopJPanelWidth, defaultTopJPanelHeight));
260
                    topJPanel.setLayout(new GridBagLayout());
261
                    
262
                    GridBagConstraints gridBagConstraints = new GridBagConstraints();
263
                    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;            
264
                    
265
                    gridBagConstraints.anchor = GridBagConstraints.WEST;
266
                    topJPanel.add(getFieldsJPanel(), gridBagConstraints);
267
                    
268
                        gridBagConstraints.anchor = GridBagConstraints.CENTER;
269
//                        topJPanel.add(getFilterButtonsJPanel(), gridBagConstraints);
270
                        topJPanel.add(getTopCenterJPanel(), gridBagConstraints);
271
//                        topJPanel.add(getValidateFilterExpressionJCheckBox(), gridBagConstraints);
272
                        
273
                        gridBagConstraints.anchor = GridBagConstraints.EAST;
274
                        topJPanel.add(getValuesJPanel(), gridBagConstraints);
275
                }
276
                
277
                return topJPanel;
278
        }
279
        
280
        /**
281
         * This method initializes topCenterJPanel
282
         *
283
         * @return javax.swing.JPanel
284
         */
285
        protected JPanel getTopCenterJPanel() {
286
                if (topCenterJPanel == null) {
287
                        topCenterJPanel = new JPanelML();
288
                        topCenterJPanel.setPreferredSize(new Dimension(getFilterButtonsJPanel().getPreferredSize().width, getFilterButtonsJPanel().getPreferredSize().height + validateFilterExpressionJCheckBoxHeight));
289
                        topCenterJPanel.setLayout(null);
290
                        
291
                        getFilterButtonsJPanel().setBounds(0, 0, getFilterButtonsJPanel().getPreferredSize().width, getFilterButtonsJPanel().getPreferredSize().height);
292
                        topCenterJPanel.add(getFilterButtonsJPanel());
293
                        topCenterJPanel.add(getValidateFilterExpressionJCheckBox());
294
                }
295
                return topCenterJPanel;
296
        }
297
        
298
        /**
299
         * This method initializes validateFilterExpressionJCheckBox
300
         *
301
         * @return javax.swing.JCheckBox
302
         */
303
        protected JCheckBox getValidateFilterExpressionJCheckBox() {
304
                if (validateFilterExpressionJCheckBox == null) {
305
                        validateFilterExpressionJCheckBox = new JCheckBoxML();
306
                        validateFilterExpressionJCheckBox.setBounds(5, getFilterButtonsJPanel().getPreferredSize().height, getFilterButtonsJPanel().getWidth(), validateFilterExpressionJCheckBoxHeight);
307
                        validateFilterExpressionJCheckBox.setText(Messages.getText("validate_expression"));
308
                        validateFilterExpressionJCheckBox.setToolTipText(Messages.getText("validate_filter_expression_explanation"));
309
                }
310
                return validateFilterExpressionJCheckBox;
311
        }
312

    
313
        /*
314
         *  (non-Javadoc)
315
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#getBottomJPanel()
316
         */
317
        protected JPanel getBottomJPanel() {
318
                if (bottomJPanel == null) {
319
                        bottomJPanel = new JPanelML();
320
                        bottomJPanel.setPreferredSize(new Dimension(defaultBottomJPanelWidth, defaultBottomJPanelHeight));
321
                        bottomJPanel.add(getFilterJScrollPane(), null);
322
                }
323
                
324
                return bottomJPanel;
325
        }
326

    
327
        /*
328
         *  (non-Javadoc)
329
         * @see org.gvsig.gui.beans.filterPanel.AbstractFilterQueryJPanel#resizeWidth(int)
330
         */
331
        public void resizeWidth(int new_Width) {        
332
                int difference = new_Width - DefaultWidth;
333
                
334
                if (difference != 0) {
335
                        this.setPreferredSize(new Dimension(this.getPreferredSize().width + difference, this.getPreferredSize().height));
336
                        getTopJPanel().setPreferredSize(new Dimension(getTopJPanel().getPreferredSize().width + difference, getTopJPanel().getPreferredSize().height));
337
                        getBottomJPanel().setPreferredSize(new Dimension(getBottomJPanel().getPreferredSize().width + difference, getBottomJPanel().getPreferredSize().height));
338
                        getFilterJScrollPane().setPreferredSize(new Dimension(getFilterJScrollPane().getPreferredSize().width + difference, getFilterJScrollPane().getPreferredSize().height));
339
                        
340
                        int halfDifference = difference / 2;
341
                        
342
                        getFieldsJLabel().setPreferredSize(new Dimension(getFieldsJLabel().getPreferredSize().width + halfDifference, getFieldsJLabel().getPreferredSize().height));
343
                        getFieldsJPanel().setPreferredSize(new Dimension(getFieldsJPanel().getPreferredSize().width + halfDifference, getFieldsJPanel().getPreferredSize().height));
344
                        getFieldsJScrollPane().setPreferredSize(new Dimension(getFieldsJScrollPane().getPreferredSize().width + halfDifference, getFieldsJScrollPane().getPreferredSize().height));
345
                
346
                        getValuesJLabel().setPreferredSize(new Dimension(getValuesJLabel().getPreferredSize().width + halfDifference, getValuesJLabel().getPreferredSize().height));
347
                        getValuesJPanel().setPreferredSize(new Dimension(getValuesJPanel().getPreferredSize().width + halfDifference, getValuesJPanel().getPreferredSize().height));
348
                        getValuesJScrollPane().setPreferredSize(new Dimension(getValuesJScrollPane().getPreferredSize().width + halfDifference, getValuesJScrollPane().getPreferredSize().height));
349
                }
350
        }
351
}
352