Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.swing / org.gvsig.expressionevaluator.swing.impl / src / main / java / org / gvsig / expressionevaluator / swing / impl / DefaultJExpressionBuilderView2.java @ 44259

History | View | Annotate | Download (17 KB)

1
package org.gvsig.expressionevaluator.swing.impl;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.Color;
5
import java.awt.GridBagConstraints;
6
import java.awt.GridBagLayout;
7
import java.awt.Insets;
8
import javax.swing.ImageIcon;
9
import javax.swing.JButton;
10
import javax.swing.JComboBox;
11
import javax.swing.JLabel;
12
import javax.swing.JList;
13
import javax.swing.JPanel;
14
import javax.swing.JScrollPane;
15
import javax.swing.JSplitPane;
16
import javax.swing.JTabbedPane;
17
import javax.swing.JTextArea;
18
import javax.swing.JTextField;
19
import javax.swing.JTree;
20
import javax.swing.border.EmptyBorder;
21

    
22
public class DefaultJExpressionBuilderView2 extends JPanel {
23

    
24
    private static class GridBagConstraintsBuilder {
25

    
26
        private GridBagConstraints gbc;
27

    
28
        public GridBagConstraintsBuilder() {
29
            this.gbc = new GridBagConstraints();
30
            this.gbc.insets = new Insets(1, 1, 1, 1);
31
        }
32

    
33
        public GridBagConstraintsBuilder clear() {
34
            this.gbc = new GridBagConstraints();
35
            this.gbc.insets = new Insets(1, 1, 1, 1);
36
            return this;
37
        }
38

    
39
        public GridBagConstraints get() {
40
            return this.gbc;
41
        }
42

    
43
        public GridBagConstraintsBuilder insets(int top, int left, int bottom, int right) {
44
            this.gbc.insets = new Insets(top, left, bottom, right);
45
            return this;
46
        }
47

    
48
        public GridBagConstraintsBuilder anchor(int anchor) {
49
            this.gbc.anchor = anchor;
50
            return this;
51
        }
52

    
53
        public GridBagConstraintsBuilder fill(int fill) {
54
            this.gbc.fill = fill;
55
            return this;
56
        }
57

    
58
        public GridBagConstraintsBuilder growx(float growx) {
59
            this.gbc.weightx = growx;
60
            return this;
61
        }
62

    
63
        public GridBagConstraintsBuilder growy(float growy) {
64
            this.gbc.weighty = growy;
65
            return this;
66
        }
67

    
68
        public GridBagConstraintsBuilder grow(float growx, float growy) {
69
            this.gbc.weightx = growx;
70
            this.gbc.weighty = growy;
71
            return this;
72
        }
73

    
74
        public GridBagConstraintsBuilder nogrow() {
75
            this.gbc.weightx = 0;
76
            this.gbc.weighty = 0;
77
            return this;
78
        }
79

    
80
        public GridBagConstraintsBuilder xy(int x, int y) {
81
            this.gbc.gridx = x;
82
            this.gbc.gridy = y;
83
            return this;
84
        }
85

    
86
        private GridBagConstraintsBuilder colspan(int n) {
87
            this.gbc.gridwidth = n;
88
            return this;
89
        }
90

    
91
        private GridBagConstraintsBuilder rowspan(int n) {
92
            this.gbc.gridheight = n;
93
            return this;
94
        }
95

    
96
        private GridBagConstraintsBuilder span(int cols, int rows) {
97
            this.gbc.gridwidth = cols;
98
            this.gbc.gridheight = rows;
99
            return this;
100
        }
101

    
102
        private GridBagConstraintsBuilder nospan() {
103
            this.gbc.gridwidth = 1;
104
            this.gbc.gridheight = 1;
105
            return this;
106
        }
107

    
108
    }
109

    
110
    JTabbedPane tabExpressionBuilder = new JTabbedPane();
111

    
112
    JList lstSimpleElement = new JList();
113
    JScrollPane scrSimpleElement = new JScrollPane();
114

    
115
    JTree treeElements = new JTree();
116
    JScrollPane scrElements = new JScrollPane();
117

    
118
    JTextArea txtExpression = new JTextArea();
119
    JScrollPane scrExpression = new JScrollPane();
120

    
121
    JButton btnHistory = new JButton();
122
    JButton btnBookmarks = new JButton();
123
    JButton btnEq = new JButton();
124
    JButton btnNeq = new JButton();
125
    JButton btnAdd = new JButton();
126
    JButton btnSubst = new JButton();
127
    JButton btnMult = new JButton();
128
    JButton btnDiv = new JButton();
129
    JButton btnParentOpen = new JButton();
130
    JButton btnParentClose = new JButton();
131
    JLabel lblMsg = new JLabel();
132
    JButton btnTip = new JButton();
133
    JLabel lblColumn = new JLabel();
134
    JTextField txtGroupElement = new JTextField();
135
    JButton btnGroupElementInsert = new JButton();
136
    JButton btnSimpleElementInsert = new JButton();
137
    JButton btnSimpleElementSortDown = new JButton();
138
    JButton btnSimpleElementSortUp = new JButton();
139
    JLabel lblSimpleElementsMsg = new JLabel();
140
    JButton btnSimpleElementTimeLimit = new JButton();
141
    JTextField txtSimpleElementFilter = new JTextField();
142
    JButton btnSimpleElementFilter = new JButton();
143
    JPanel pnlDescription = new JPanel();
144
    JPanel pnlScriptEditorContainer = new JPanel();
145
    JComboBox cboPickerScripts = new JComboBox();
146
    JButton btnPickerRemove = new JButton();
147
    JButton btnPickerSelectScript = new JButton();
148

    
149
    JSplitPane spnlExpression = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
150
    JSplitPane spnlBottom = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
151
    JSplitPane spnlItem = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
152

    
153
    JPanel pnlTop;
154
    JPanel pnlElement;
155

    
156
    /**
157
     * Default constructor
158
     */
159
    public DefaultJExpressionBuilderView2() {
160
        initComponents();
161
    }
162

    
163
    private void initComponents() {
164
        EmptyBorder emptyborder2x2 = new EmptyBorder(2, 2, 2, 2);
165

    
166
        lstSimpleElement.setName("lstSimpleElement");
167

    
168
        treeElements.setName("treeElements");
169
        pnlDescription.setName("pnlDescription");
170
        txtExpression.setLineWrap(true);
171
        txtExpression.setName("txtExpression");
172
        txtExpression.setRows(2);
173

    
174

    
175
        btnHistory.setActionCommand("+");
176
        btnHistory.setIcon(loadImage("datos/devel/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/resources/org/gvsig/expressionevaluator/swing/impl/expressionbuilder-history.png"));
177
        btnHistory.setName("btnHistory");
178
        btnHistory.setText("");
179
        btnHistory.setBorder(emptyborder2x2);
180

    
181
        btnBookmarks.setActionCommand("+");
182
        btnBookmarks.setIcon(loadImage("datos/devel/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/resources/org/gvsig/expressionevaluator/swing/impl/expressionbuilder-bookmarks.png"));
183
        btnBookmarks.setName("btnBookmarks");
184
        btnBookmarks.setText("");
185
        btnBookmarks.setBorder(emptyborder2x2);
186

    
187
        btnEq.setActionCommand("+");
188
        btnEq.setName("btnEq");
189
        btnEq.setText("=");
190
        btnEq.setBorder(emptyborder2x2);
191

    
192
        btnNeq.setActionCommand("+");
193
        btnNeq.setName("btnNeq");
194
        btnNeq.setText("<>");
195
        btnNeq.setBorder(emptyborder2x2);
196

    
197
        btnAdd.setActionCommand("+");
198
        btnAdd.setName("btnAdd");
199
        btnAdd.setText("+");
200
        btnAdd.setBorder(emptyborder2x2);
201

    
202
        btnSubst.setActionCommand("+");
203
        btnSubst.setName("btnSubst");
204
        btnSubst.setText("-");
205
        btnSubst.setBorder(emptyborder2x2);
206

    
207
        btnMult.setActionCommand("+");
208
        btnMult.setName("btnMult");
209
        btnMult.setText("*");
210
        btnMult.setBorder(emptyborder2x2);
211

    
212
        btnDiv.setActionCommand("+");
213
        btnDiv.setName("btnDiv");
214
        btnDiv.setText("/");
215
        btnDiv.setBorder(emptyborder2x2);
216

    
217
        btnParentOpen.setActionCommand("+");
218
        btnParentOpen.setName("btnParentOpen");
219
        btnParentOpen.setText("(");
220
        btnParentOpen.setBorder(emptyborder2x2);
221

    
222
        btnParentClose.setActionCommand("+");
223
        btnParentClose.setName("btnParentClose");
224
        btnParentClose.setText(")");
225
        btnParentClose.setBorder(emptyborder2x2);
226

    
227
        lblMsg.setName("lblMsg");
228

    
229
        btnTip.setActionCommand("+");
230
        btnTip.setIcon(loadImage("datos/devel/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/resources/org/gvsig/expressionevaluator/swing/impl/expressionbuilder-tip.png.png"));
231
        btnTip.setName("btnTip");
232
        btnTip.setBorder(emptyborder2x2);
233

    
234
        lblColumn.setName("lblColumn");
235
        lblColumn.setText("0");
236

    
237
        txtGroupElement.setBackground(new Color(236, 233, 216));
238
        txtGroupElement.setEditable(false);
239
        txtGroupElement.setName("txtGroupElement");
240

    
241
        btnGroupElementInsert.setActionCommand("+");
242
        btnGroupElementInsert.setIcon(loadImage("datos/devel/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/resources/org/gvsig/expressionevaluator/swing/impl/expressionbuilder-insert-text.png"));
243
        btnGroupElementInsert.setName("btnGroupElementInsert");
244
        btnGroupElementInsert.setBorder(emptyborder2x2);
245

    
246
        btnSimpleElementInsert.setActionCommand("+");
247
        btnSimpleElementInsert.setIcon(loadImage("datos/devel/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/resources/org/gvsig/expressionevaluator/swing/impl/expressionbuilder-insert-text.png"));
248
        btnSimpleElementInsert.setName("btnSimpleElementInsert");
249
        btnSimpleElementInsert.setBorder(emptyborder2x2);
250

    
251
        btnSimpleElementSortDown.setActionCommand("+");
252
        btnSimpleElementSortDown.setIcon(loadImage("datos/devel/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/resources/org/gvsig/expressionevaluator/swing/impl/expressionbuilder-sortdown.png"));
253
        btnSimpleElementSortDown.setName("btnSimpleElementSortDown");
254
        btnSimpleElementSortDown.setBorder(emptyborder2x2);
255

    
256
        btnSimpleElementSortUp.setActionCommand("+");
257
        btnSimpleElementSortUp.setIcon(loadImage("datos/devel/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/resources/org/gvsig/expressionevaluator/swing/impl/expressionbuilder-sortup.png"));
258
        btnSimpleElementSortUp.setName("btnSimpleElementSortUp");
259
        btnSimpleElementSortUp.setBorder(emptyborder2x2);
260

    
261
        lblSimpleElementsMsg.setName("lblSimpleElementsMsg");
262

    
263
        btnSimpleElementTimeLimit.setActionCommand("+");
264
        btnSimpleElementTimeLimit.setIcon(loadImage("datos/devel/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/resources/org/gvsig/expressionevaluator/swing/impl/expressionbuilder-time-limit.png"));
265
        btnSimpleElementTimeLimit.setName("btnSimpleElementTimeLimit");
266
        btnSimpleElementTimeLimit.setBorder(emptyborder2x2);
267

    
268
        txtSimpleElementFilter.setName("txtSimpleElementFilter");
269

    
270
        btnSimpleElementFilter.setActionCommand("+");
271
        btnSimpleElementFilter.setIcon(loadImage("datos/devel/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.impl/src/main/resources/org/gvsig/expressionevaluator/swing/impl/expressionbuilder-filter-values.png"));
272
        btnSimpleElementFilter.setName("btnSimpleElementFilter");
273
        btnSimpleElementFilter.setBorder(emptyborder2x2);
274

    
275
        pnlScriptEditorContainer.setName("pnlScriptEditorContainer");
276

    
277
        cboPickerScripts.setName("cboPickerScripts");
278

    
279
        btnPickerRemove.setActionCommand("+");
280
        btnPickerRemove.setName("btnPickerRemove");
281
        btnPickerRemove.setText("R");
282
        btnPickerRemove.setBorder(emptyborder2x2);
283

    
284
        btnPickerSelectScript.setActionCommand("+");
285
        btnPickerSelectScript.setName("btnPickerSelectScript");
286
        btnPickerSelectScript.setText("S");
287
        btnPickerSelectScript.setBorder(emptyborder2x2);
288

    
289
        this.scrExpression = new JScrollPane();
290
        this.scrExpression.setViewportView(txtExpression);
291
        this.scrExpression.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
292
        this.scrExpression.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
293

    
294
        this.scrElements = new JScrollPane();
295
        this.scrElements.setViewportView(treeElements);
296
        this.scrElements.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
297
        this.scrElements.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
298

    
299
        this.scrSimpleElement = new JScrollPane();
300
        this.scrSimpleElement.setViewportView(lstSimpleElement);
301
        this.scrSimpleElement.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
302
        this.scrSimpleElement.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
303

    
304
        this.spnlExpression.setTopComponent(this.getPanelTop());
305
        this.spnlExpression.setBottomComponent(this.spnlBottom);
306
        this.spnlExpression.setBorder(emptyborder2x2);
307
        this.spnlExpression.setOneTouchExpandable(true);
308

    
309
        this.spnlBottom.setLeftComponent(this.scrElements);
310
        this.spnlBottom.setRightComponent(this.spnlItem);
311
        this.spnlBottom.setBorder(emptyborder2x2);
312
        this.spnlBottom.setOneTouchExpandable(true);
313

    
314
        this.spnlItem.setLeftComponent(this.getPanelElement());
315
        this.spnlItem.setRightComponent(this.pnlDescription);
316
        this.spnlItem.setBorder(emptyborder2x2);
317
        this.spnlItem.setOneTouchExpandable(true);
318

    
319
        this.tabExpressionBuilder.setName("tabExpressionBuilder");
320
        this.tabExpressionBuilder.addTab("_Expression", null, this.spnlExpression);
321
        this.tabExpressionBuilder.addTab("_Scripts", null, this.pnlScriptEditorContainer);
322
        
323
        this.setLayout(new BorderLayout());
324
        this.add(tabExpressionBuilder, BorderLayout.CENTER);
325

    
326
    }
327

    
328
    private JPanel getPanelTop() {
329
        if (this.pnlTop == null) {
330
            GridBagConstraintsBuilder cs = new GridBagConstraintsBuilder();
331
            cs.anchor(GridBagConstraints.CENTER);
332
            cs.fill(GridBagConstraints.BOTH);
333

    
334
            JPanel pnlRight = new JPanel();
335
            pnlRight.setLayout(new GridBagLayout());
336
            pnlRight.add(this.btnHistory,     cs.xy(0, 0).get());
337
            pnlRight.add(this.btnBookmarks,   cs.xy(1, 0).get());
338
            pnlRight.add(this.btnEq,          cs.xy(0, 1).get());
339
            pnlRight.add(this.btnNeq,         cs.xy(1, 1).get());
340
            pnlRight.add(this.btnAdd,         cs.xy(2, 1).get());
341
            pnlRight.add(this.btnSubst,       cs.xy(3, 1).get());
342
            pnlRight.add(this.btnMult,        cs.xy(0, 2).get());
343
            pnlRight.add(this.btnDiv,         cs.xy(1, 2).get());
344
            pnlRight.add(this.btnParentOpen,  cs.xy(2, 2).get());
345
            pnlRight.add(this.btnParentClose, cs.xy(3, 2).get());
346
            pnlRight.add(new JLabel(),        cs.xy(0, 3).span(4,0).grow(1, 1).get());
347

    
348
            JPanel pnlLeft = new JPanel();
349
            pnlLeft.setLayout(new GridBagLayout());
350
            pnlLeft.add(this.scrExpression, cs.xy(0, 0).span(3, 1).grow(1, 1).get());
351
            pnlLeft.add(this.lblMsg, cs.xy(0, 1).nospan().grow(1, 0).get());
352
            pnlLeft.add(this.btnTip, cs.xy(1, 1).nospan().nogrow().get());
353
            pnlLeft.add(this.lblColumn, cs.xy(2, 1).nospan().nogrow().get());
354

    
355
            JPanel panel = new JPanel();
356
            panel.setLayout(new GridBagLayout());
357
            panel.add(pnlLeft, cs.xy(0, 0).nospan().grow(1, 1).get());
358
            panel.add(pnlRight, cs.xy(1, 0).nospan().nogrow().anchor(GridBagConstraints.NORTH).get());
359

    
360
            this.pnlTop = panel;
361
        }
362
        return this.pnlTop;
363
    }
364

    
365
    private JPanel getPanelElement() {
366
        if (this.pnlElement == null) {
367
            GridBagConstraintsBuilder cs = new GridBagConstraintsBuilder();
368
            cs.anchor(GridBagConstraints.CENTER);
369
            cs.fill(GridBagConstraints.BOTH);
370

    
371
            JPanel panel = new JPanel();
372
            panel.setLayout(new GridBagLayout());
373
            panel.add(this.txtGroupElement, cs.xy(0, 0).span(4, 1).grow(1,0).get());
374
            panel.add(this.btnGroupElementInsert, cs.xy(4, 0).nospan().nogrow().get());
375
            panel.add(this.txtSimpleElementFilter, cs.xy(0, 1).span(4, 1).grow(1,0).get());
376
            panel.add(this.btnSimpleElementInsert, cs.xy(4, 1).nospan().nogrow().get());
377
            panel.add(this.scrSimpleElement, cs.xy(0, 2).span(5, 1).grow(1, 1).get());
378
            panel.add(new JLabel(), cs.xy(0, 3).nospan().grow(1,0).get());
379
            panel.add(this.btnSimpleElementTimeLimit, cs.xy(1, 3).nospan().nogrow().get());
380
            panel.add(this.btnSimpleElementSortUp, cs.xy(2, 3).nospan().nogrow().get());
381
            panel.add(this.btnSimpleElementSortDown, cs.xy(3, 3).nospan().nogrow().get());
382
            panel.add(this.btnSimpleElementInsert, cs.xy(4, 3).nospan().nogrow().get());
383

    
384
            this.pnlElement = panel;
385
        }
386
        return this.pnlElement;
387
    }
388

    
389
    public ImageIcon loadImage(String imageName) {
390
        try {
391
            ClassLoader classloader = getClass().getClassLoader();
392
            java.net.URL url = classloader.getResource(imageName);
393
            if (url != null) {
394
                ImageIcon icon = new ImageIcon(url);
395
                return icon;
396
            }
397
        } catch (Exception e) {
398
            e.printStackTrace();
399
        }
400
        throw new IllegalArgumentException("Unable to load image: " + imageName);
401
    }
402
}