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 @ 44899

History | View | Annotate | Download (17.2 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.JLabel;
11
import javax.swing.JList;
12
import javax.swing.JPanel;
13
import javax.swing.JScrollPane;
14
import javax.swing.JSplitPane;
15
import javax.swing.JTabbedPane;
16
import javax.swing.JTextArea;
17
import javax.swing.JTextField;
18
import javax.swing.JTree;
19
import javax.swing.border.EmptyBorder;
20

    
21
public class DefaultJExpressionBuilderView2 extends JPanel {
22

    
23
    private static class GridBagConstraintsBuilder {
24

    
25
        private GridBagConstraints gbc;
26

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
107
    }
108

    
109
    JPanel pnlCfgActions = new JPanel();
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/common-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/common-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/common-filter.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
        this.add(this.spnlExpression, BorderLayout.CENTER);        
326
        this.add(pnlCfgActions, BorderLayout.PAGE_START);
327
        
328
    }
329

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

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

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

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

    
362
            this.pnlTop = panel;
363
        }
364
        return this.pnlTop;
365
    }
366

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

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

    
386
            this.pnlElement = panel;
387
        }
388
        return this.pnlElement;
389
    }
390

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