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

History | View | Annotate | Download (17.3 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.JComponent;
12
import javax.swing.JLabel;
13
import javax.swing.JList;
14
import javax.swing.JPanel;
15
import javax.swing.JScrollPane;
16
import javax.swing.JSplitPane;
17
import javax.swing.JTabbedPane;
18
import javax.swing.JTextArea;
19
import javax.swing.JTextField;
20
import javax.swing.JTree;
21
import javax.swing.border.EmptyBorder;
22
import org.gvsig.configurableactions.ConfigurableActionsMamager;
23
import org.gvsig.tools.util.ToolsUtilLocator;
24

    
25
public class DefaultJExpressionBuilderView2 extends JPanel {
26

    
27
    private static class GridBagConstraintsBuilder {
28

    
29
        private GridBagConstraints gbc;
30

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

    
36
        public GridBagConstraintsBuilder clear() {
37
            this.gbc = new GridBagConstraints();
38
            this.gbc.insets = new Insets(1, 1, 1, 1);
39
            return this;
40
        }
41

    
42
        public GridBagConstraints get() {
43
            return this.gbc;
44
        }
45

    
46
        public GridBagConstraintsBuilder insets(int top, int left, int bottom, int right) {
47
            this.gbc.insets = new Insets(top, left, bottom, right);
48
            return this;
49
        }
50

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

    
56
        public GridBagConstraintsBuilder fill(int fill) {
57
            this.gbc.fill = fill;
58
            return this;
59
        }
60

    
61
        public GridBagConstraintsBuilder growx(float growx) {
62
            this.gbc.weightx = growx;
63
            return this;
64
        }
65

    
66
        public GridBagConstraintsBuilder growy(float growy) {
67
            this.gbc.weighty = growy;
68
            return this;
69
        }
70

    
71
        public GridBagConstraintsBuilder grow(float growx, float growy) {
72
            this.gbc.weightx = growx;
73
            this.gbc.weighty = growy;
74
            return this;
75
        }
76

    
77
        public GridBagConstraintsBuilder nogrow() {
78
            this.gbc.weightx = 0;
79
            this.gbc.weighty = 0;
80
            return this;
81
        }
82

    
83
        public GridBagConstraintsBuilder xy(int x, int y) {
84
            this.gbc.gridx = x;
85
            this.gbc.gridy = y;
86
            return this;
87
        }
88

    
89
        private GridBagConstraintsBuilder colspan(int n) {
90
            this.gbc.gridwidth = n;
91
            return this;
92
        }
93

    
94
        private GridBagConstraintsBuilder rowspan(int n) {
95
            this.gbc.gridheight = n;
96
            return this;
97
        }
98

    
99
        private GridBagConstraintsBuilder span(int cols, int rows) {
100
            this.gbc.gridwidth = cols;
101
            this.gbc.gridheight = rows;
102
            return this;
103
        }
104

    
105
        private GridBagConstraintsBuilder nospan() {
106
            this.gbc.gridwidth = 1;
107
            this.gbc.gridheight = 1;
108
            return this;
109
        }
110

    
111
    }
112

    
113
    JPanel pnlCfgActions = new JPanel();
114
    JTabbedPane tabExpressionBuilder = new JTabbedPane();
115

    
116
    JList lstSimpleElement = new JList();
117
    JScrollPane scrSimpleElement = new JScrollPane();
118

    
119
    JTree treeElements = new JTree();
120
    JScrollPane scrElements = new JScrollPane();
121

    
122
    JTextArea txtExpression = new JTextArea();
123
    JScrollPane scrExpression = new JScrollPane();
124

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

    
153
    JSplitPane spnlExpression = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
154
    JSplitPane spnlBottom = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
155
    JSplitPane spnlItem = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
156

    
157
    JPanel pnlTop;
158
    JPanel pnlElement;
159

    
160
    /**
161
     * Default constructor
162
     */
163
    public DefaultJExpressionBuilderView2() {
164
        initComponents();
165
    }
166

    
167
    private void initComponents() {
168
        EmptyBorder emptyborder2x2 = new EmptyBorder(2, 2, 2, 2);
169

    
170
        lstSimpleElement.setName("lstSimpleElement");
171

    
172
        treeElements.setName("treeElements");
173
        pnlDescription.setName("pnlDescription");
174
        txtExpression.setLineWrap(true);
175
        txtExpression.setName("txtExpression");
176
        txtExpression.setRows(2);
177

    
178

    
179
        btnHistory.setActionCommand("+");
180
        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"));
181
        btnHistory.setName("btnHistory");
182
        btnHistory.setText("");
183
        btnHistory.setBorder(emptyborder2x2);
184

    
185
        btnBookmarks.setActionCommand("+");
186
        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"));
187
        btnBookmarks.setName("btnBookmarks");
188
        btnBookmarks.setText("");
189
        btnBookmarks.setBorder(emptyborder2x2);
190

    
191
        btnEq.setActionCommand("+");
192
        btnEq.setName("btnEq");
193
        btnEq.setText("=");
194
        btnEq.setBorder(emptyborder2x2);
195

    
196
        btnNeq.setActionCommand("+");
197
        btnNeq.setName("btnNeq");
198
        btnNeq.setText("<>");
199
        btnNeq.setBorder(emptyborder2x2);
200

    
201
        btnAdd.setActionCommand("+");
202
        btnAdd.setName("btnAdd");
203
        btnAdd.setText("+");
204
        btnAdd.setBorder(emptyborder2x2);
205

    
206
        btnSubst.setActionCommand("+");
207
        btnSubst.setName("btnSubst");
208
        btnSubst.setText("-");
209
        btnSubst.setBorder(emptyborder2x2);
210

    
211
        btnMult.setActionCommand("+");
212
        btnMult.setName("btnMult");
213
        btnMult.setText("*");
214
        btnMult.setBorder(emptyborder2x2);
215

    
216
        btnDiv.setActionCommand("+");
217
        btnDiv.setName("btnDiv");
218
        btnDiv.setText("/");
219
        btnDiv.setBorder(emptyborder2x2);
220

    
221
        btnParentOpen.setActionCommand("+");
222
        btnParentOpen.setName("btnParentOpen");
223
        btnParentOpen.setText("(");
224
        btnParentOpen.setBorder(emptyborder2x2);
225

    
226
        btnParentClose.setActionCommand("+");
227
        btnParentClose.setName("btnParentClose");
228
        btnParentClose.setText(")");
229
        btnParentClose.setBorder(emptyborder2x2);
230

    
231
        lblMsg.setName("lblMsg");
232

    
233
        btnTip.setActionCommand("+");
234
        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"));
235
        btnTip.setName("btnTip");
236
        btnTip.setBorder(emptyborder2x2);
237

    
238
        lblColumn.setName("lblColumn");
239
        lblColumn.setText("0");
240

    
241
        txtGroupElement.setBackground(new Color(236, 233, 216));
242
        txtGroupElement.setEditable(false);
243
        txtGroupElement.setName("txtGroupElement");
244

    
245
        btnGroupElementInsert.setActionCommand("+");
246
        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"));
247
        btnGroupElementInsert.setName("btnGroupElementInsert");
248
        btnGroupElementInsert.setBorder(emptyborder2x2);
249

    
250
        btnSimpleElementInsert.setActionCommand("+");
251
        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"));
252
        btnSimpleElementInsert.setName("btnSimpleElementInsert");
253
        btnSimpleElementInsert.setBorder(emptyborder2x2);
254

    
255
        btnSimpleElementSortDown.setActionCommand("+");
256
        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"));
257
        btnSimpleElementSortDown.setName("btnSimpleElementSortDown");
258
        btnSimpleElementSortDown.setBorder(emptyborder2x2);
259

    
260
        btnSimpleElementSortUp.setActionCommand("+");
261
        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"));
262
        btnSimpleElementSortUp.setName("btnSimpleElementSortUp");
263
        btnSimpleElementSortUp.setBorder(emptyborder2x2);
264

    
265
        lblSimpleElementsMsg.setName("lblSimpleElementsMsg");
266

    
267
        btnSimpleElementTimeLimit.setActionCommand("+");
268
        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"));
269
        btnSimpleElementTimeLimit.setName("btnSimpleElementTimeLimit");
270
        btnSimpleElementTimeLimit.setBorder(emptyborder2x2);
271

    
272
        txtSimpleElementFilter.setName("txtSimpleElementFilter");
273

    
274
        btnSimpleElementFilter.setActionCommand("+");
275
        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"));
276
        btnSimpleElementFilter.setName("btnSimpleElementFilter");
277
        btnSimpleElementFilter.setBorder(emptyborder2x2);
278

    
279
//        pnlScriptEditorContainer.setName("pnlScriptEditorContainer");
280
//
281
//        cboPickerScripts.setName("cboPickerScripts");
282
//
283
//        btnPickerRemove.setActionCommand("+");
284
//        btnPickerRemove.setName("btnPickerRemove");
285
//        btnPickerRemove.setText("R");
286
//        btnPickerRemove.setBorder(emptyborder2x2);
287
//
288
//        btnPickerSelectScript.setActionCommand("+");
289
//        btnPickerSelectScript.setName("btnPickerSelectScript");
290
//        btnPickerSelectScript.setText("S");
291
//        btnPickerSelectScript.setBorder(emptyborder2x2);
292

    
293
        this.scrExpression = new JScrollPane();
294
        this.scrExpression.setViewportView(txtExpression);
295
        this.scrExpression.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
296
        this.scrExpression.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
297

    
298
        this.scrElements = new JScrollPane();
299
        this.scrElements.setViewportView(treeElements);
300
        this.scrElements.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
301
        this.scrElements.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
302

    
303
        this.scrSimpleElement = new JScrollPane();
304
        this.scrSimpleElement.setViewportView(lstSimpleElement);
305
        this.scrSimpleElement.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
306
        this.scrSimpleElement.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
307

    
308
        this.spnlExpression.setTopComponent(this.getPanelTop());
309
        this.spnlExpression.setBottomComponent(this.spnlBottom);
310
        this.spnlExpression.setBorder(emptyborder2x2);
311
        this.spnlExpression.setOneTouchExpandable(true);
312

    
313
        this.spnlBottom.setLeftComponent(this.scrElements);
314
        this.spnlBottom.setRightComponent(this.spnlItem);
315
        this.spnlBottom.setBorder(emptyborder2x2);
316
        this.spnlBottom.setOneTouchExpandable(true);
317

    
318
        this.spnlItem.setLeftComponent(this.getPanelElement());
319
        this.spnlItem.setRightComponent(this.pnlDescription);
320
        this.spnlItem.setBorder(emptyborder2x2);
321
        this.spnlItem.setOneTouchExpandable(true);
322

    
323
        this.tabExpressionBuilder.setName("tabExpressionBuilder");
324
        this.tabExpressionBuilder.addTab("_Expression", null, this.spnlExpression);
325
//        this.tabExpressionBuilder.addTab("_Scripts", null, this.pnlScriptEditorContainer);
326
        
327
        this.setLayout(new BorderLayout());
328
        this.add(tabExpressionBuilder, BorderLayout.CENTER);
329
        
330
        this.add(pnlCfgActions, BorderLayout.PAGE_START);
331
        
332
    }
333

    
334
    private JPanel getPanelTop() {
335
        if (this.pnlTop == null) {
336
            GridBagConstraintsBuilder cs = new GridBagConstraintsBuilder();
337
            cs.anchor(GridBagConstraints.CENTER);
338
            cs.fill(GridBagConstraints.BOTH);
339

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

    
354
            JPanel pnlLeft = new JPanel();
355
            pnlLeft.setLayout(new GridBagLayout());
356
            pnlLeft.add(this.scrExpression, cs.xy(0, 0).span(3, 1).grow(1, 1).get());
357
            pnlLeft.add(this.lblMsg, cs.xy(0, 1).nospan().grow(1, 0).get());
358
            pnlLeft.add(this.btnTip, cs.xy(1, 1).nospan().nogrow().get());
359
            pnlLeft.add(this.lblColumn, cs.xy(2, 1).nospan().nogrow().get());
360

    
361
            JPanel panel = new JPanel();
362
            panel.setLayout(new GridBagLayout());
363
            panel.add(pnlLeft, cs.xy(0, 0).nospan().grow(1, 1).get());
364
            panel.add(pnlRight, cs.xy(1, 0).nospan().nogrow().anchor(GridBagConstraints.NORTH).get());
365

    
366
            this.pnlTop = panel;
367
        }
368
        return this.pnlTop;
369
    }
370

    
371
    private JPanel getPanelElement() {
372
        if (this.pnlElement == null) {
373
            GridBagConstraintsBuilder cs = new GridBagConstraintsBuilder();
374
            cs.anchor(GridBagConstraints.CENTER);
375
            cs.fill(GridBagConstraints.BOTH);
376

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

    
390
            this.pnlElement = panel;
391
        }
392
        return this.pnlElement;
393
    }
394

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