Revision 806

View differences:

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

  
25
import java.awt.BorderLayout;
26
import java.awt.Color;
27
import java.awt.Component;
28
import java.awt.Dimension;
29
import java.awt.Font;
30
import java.awt.GridBagConstraints;
31
import java.awt.GridBagLayout;
32
import java.awt.GridLayout;
33
import java.awt.Insets;
34
import java.awt.Rectangle;
35
import java.awt.event.ActionEvent;
36
import java.awt.event.ActionListener;
37
import java.awt.event.MouseEvent;
38
import java.awt.event.MouseListener;
39
import java.util.ArrayList;
40

  
41
import javax.swing.AbstractButton;
42
import javax.swing.BorderFactory;
43
import javax.swing.ButtonGroup;
44
import javax.swing.DefaultListModel;
45
import javax.swing.JButton;
46
import javax.swing.JLabel;
47
import javax.swing.JList;
48
import javax.swing.JPanel;
49
import javax.swing.JRadioButton;
50
import javax.swing.JScrollBar;
51
import javax.swing.JScrollPane;
52
import javax.swing.JTextArea;
53
import javax.swing.JTextPane;
54
import javax.swing.ListSelectionModel;
55
import javax.swing.ScrollPaneConstants;
56
import javax.swing.border.EmptyBorder;
57
import javax.swing.event.ListSelectionEvent;
58
import javax.swing.event.ListSelectionListener;
59
import javax.swing.text.SimpleAttributeSet;
60
import javax.swing.text.StyleConstants;
61
import javax.swing.text.StyledDocument;
62

  
63
import org.gvsig.tools.ToolsLocator;
64
import org.gvsig.tools.dynobject.DynClass;
65
import org.gvsig.tools.dynobject.DynField;
66
import org.gvsig.tools.dynobject.DynStruct;
67
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions;
68
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions.Description;
69
import org.gvsig.tools.i18n.I18nManager;
70
import org.gvsig.tools.swing.api.evaluator.EvaluatorPanel;
71
import org.gvsig.tools.swing.impl.dynobject.dynfield.DynFieldListItem;
72

  
73

  
74
/**
75
 * 
76
 * @author jldominguez
77
 *
78
 */
79
public class DefaultEvaluatorPanel extends EvaluatorPanel
80
implements ListSelectionListener, MouseListener, ActionListener {
81

  
82
    private DynClass dynclass = null;
83
    private EvaluatorWithDescriptions eval_wdesc = null;
84
    
85
    private JTextArea expressionArea = null;
86
    private JList fieldList = null;
87
    private JList opfuList = null;
88
    private JPanel categRadioPanel = null;
89
    
90
    private JTextArea fieldExplainLabel = null;
91
    private JTextArea opfuDescLabel = null;
92
    
93
    private JRadioButton num_CategRB = null;
94
    private JRadioButton str_CategRB = null;
95
    private JRadioButton dat_CategRB = null;
96
    private JRadioButton geo_CategRB = null;
97
    private JRadioButton boo_CategRB = null;
98
    private JRadioButton all_CategRB = null;
99
    
100
    private JPanel opfuDescPanel = null;
101
    private JScrollPane opfuDescScroll = null;
102
    private JPanel opfuPanel = null;
103
    private JPanel fieldsPanel = null;
104
    
105
    private JPanel topPanel = null;
106
    private JPanel expressionPanel = null;
107
    
108
    private JButton clearButton = null;
109
    private JButton validateButton = null;
110
    
111
    private static I18nManager im = ToolsLocator.getI18nManager();
112
    
113
    public DefaultEvaluatorPanel(
114
        DynClass dcla, EvaluatorWithDescriptions evaluator) {
115
        initialize(dcla, evaluator);
116
    }
117

  
118
    public String getExpression() {
119
        return getExpressionArea().getText();
120
    }
121
    
122
    public void initialize(DynClass dcla, EvaluatorWithDescriptions evaluator) {
123
        dynclass = dcla;
124
        eval_wdesc = evaluator;
125
        initComponents();
126
    }
127
    
128
    /**
129
     * 
130
     */
131
    private void initComponents() {
132
        
133
        this.setLayout(new GridBagLayout());
134
        GridBagConstraints gbc = new GridBagConstraints();
135
        gbc.fill = GridBagConstraints.BOTH;
136
        gbc.weightx = 1;
137
        gbc.weighty = 0.8;
138
        gbc.gridheight = 2;
139
        gbc.gridx = 0;
140
        gbc.gridy = 0;
141
        this.add(getTopPanel(), gbc);
142
        gbc.weightx = 1;
143
        gbc.weighty = 0.2;
144
        gbc.gridheight = 1;
145
        gbc.gridy = 2;
146
        gbc.insets = new Insets(5, 0, 0, 0);
147
        this.add(getExpressionPanel(), gbc);
148
        
149
    }
150

  
151
    
152
    private JTextArea getExpressionArea() {
153
        if (expressionArea == null) {
154
            expressionArea = new JTextArea();
155
            expressionArea.setLineWrap(true);
156
            expressionArea.setWrapStyleWord(true);
157
            if (eval_wdesc != null) {
158
                expressionArea.setText(eval_wdesc.getSQL());
159
            }
160
        }
161
        return expressionArea;
162
    }
163
    
164
    private JPanel getExpressionPanel() {
165
        
166
        if (expressionPanel == null) {
167
            expressionPanel = new JPanel();
168
            expressionPanel.setLayout(new BorderLayout());
169
            expressionPanel.setBorder(BorderFactory.createTitledBorder(
170
                im.getTranslation("_User_expression")));
171
            
172
            JScrollPane scroll = new JScrollPane(getExpressionArea());
173
            scroll.setHorizontalScrollBarPolicy(
174
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
175
            scroll.setVerticalScrollBarPolicy(
176
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
177
            expressionPanel.add(scroll, BorderLayout.CENTER);
178
            
179
            JPanel buttonsp = new JPanel();
180
            buttonsp.setLayout(new GridLayout(1, 1));
181
            // ========================
182
            // JPanel aux = new JPanel();
183
            // aux.add(getValidateButton());
184
            // buttonsp.add(aux);
185
            // =====================
186
            JPanel aux = new JPanel();
187
            aux.add(getClearButton());
188
            buttonsp.add(aux);
189
            // ===========================
190
            expressionPanel.add(buttonsp, BorderLayout.EAST);
191
        }
192
        return expressionPanel;
193
        
194
    }
195

  
196
    
197
    /**
198
     * @return
199
     */
200
    private Component getClearButton() {
201
        if (clearButton == null) {
202
            clearButton = new JButton(im.getTranslation("_Clear"));
203
            clearButton.addActionListener(this);
204
        }
205
        return clearButton;
206
    }
207

  
208
    /**
209
     * @return
210
     */
211
    private JButton getValidateButton() {
212
        if (validateButton == null) {
213
            validateButton = new JButton(im.getTranslation("_Validate"));
214
            validateButton.addActionListener(this);
215
        }
216
        return validateButton;
217
    }
218

  
219
    private JList getFieldList() {
220
        if (fieldList == null) {
221
            fieldList = new JList();
222
            if (dynclass != null) {
223
                
224
                fieldList.addListSelectionListener(this);
225
                DynField[] ff = dynclass.getDynFields();
226
                DynFieldListItem dfli = null;
227
                DefaultListModel resultList = new DefaultListModel();
228
                for (int i=0; i<ff.length; i++) {
229
                    dfli = new DynFieldListItem(ff[i]);
230
                    resultList.addElement(dfli);
231
                }
232
                fieldList.setModel(resultList);
233
                fieldList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
234
                fieldList.addMouseListener(this);
235
            }
236
        }
237
        return fieldList;
238
    }
239

  
240
    
241
    private JList getOpfuList() {
242
        if (opfuList == null) {
243
            opfuList = new JList();
244
            reloadOpfuList(opfuList);
245
            opfuList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
246
            opfuList.addListSelectionListener(this);
247
            opfuList.addMouseListener(this);
248
        }
249
        return opfuList;
250
    }
251

  
252

  
253
    private void reloadOpfuList(JList list) {
254
        
255
        DefaultListModel dlm = new DefaultListModel();
256
        if (this.eval_wdesc != null) {
257
            Description[] descs = getCurrentDescriptions(eval_wdesc);
258
            for (int i=0; i<descs.length; i++) {
259
                dlm.addElement(new DescriptionListItem(descs[i]));
260
            }
261
        }
262
        list.setModel(dlm);
263

  
264
    }
265

  
266
    private Description[] getCurrentDescriptions(
267
        EvaluatorWithDescriptions eval) {
268
        
269
        int goodbits = 0;
270
        if (getAllCategRB().isSelected()) {
271
            goodbits =
272
                EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_ALL;
273
        } else {
274
            if (getNumCategRB().isSelected()) {
275
                goodbits = EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_NUMBER;
276
            } else {
277
                if (getStrCategRB().isSelected()) {
278
                    goodbits = EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_STRING;
279
                } else {
280
                    if (getDatCategRB().isSelected()) {
281
                        goodbits = EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_DATETIME;
282
                    } else {
283
                        if (getGeoCategRB().isSelected()) {
284
                            goodbits = EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_GEOMETRY;
285
                        } else {
286
                            if (getBooCategRB().isSelected()) {
287
                                goodbits = EvaluatorWithDescriptions.Description.DATATYPE_CATEGORY_BOOLEAN;
288
                            } else {
289
                                
290
                            }
291
                        }
292
                    }
293
                }
294
            }
295
        }
296
        
297
        ArrayList list = new ArrayList();
298
        Description[] dd = eval.getAvailableOperators();
299
        int andop = 0;
300
        for (int i=0; i<dd.length; i++) {
301
            andop = (dd[i].getDataTypeCategories() & goodbits);
302
            if (goodbits == 0 /* all */ || andop != 0) {
303
                list.add(dd[i]);
304
            }
305
        }
306
        dd = eval.getAvailableFunctions();
307
        for (int i=0; i<dd.length; i++) {
308
            andop = (dd[i].getDataTypeCategories() & goodbits);
309
            if (goodbits == 0 /* all */ || andop != 0) {
310
                list.add(dd[i]);
311
            }
312
        }
313
        
314
        return (Description[]) list.toArray(new Description[0]);
315
    }
316

  
317
    private JRadioButton getAllCategRB() {
318
        if (all_CategRB == null) {
319
            this.all_CategRB = new JRadioButton(im.getTranslation("_All"));
320
            this.all_CategRB.addActionListener(this);
321
        }
322
        return all_CategRB;
323
    }
324

  
325

  
326
    private JRadioButton getNumCategRB() {
327
        if (num_CategRB == null) {
328
            this.num_CategRB = new JRadioButton(im.getTranslation("_Numeric"));
329
            this.num_CategRB.addActionListener(this);
330
        }
331
        return num_CategRB;
332
    }
333

  
334

  
335
    private JRadioButton getStrCategRB() {
336
        if (str_CategRB == null) {
337
            this.str_CategRB = new JRadioButton(im.getTranslation("_String"));
338
            this.str_CategRB.addActionListener(this);
339
        }
340
        return str_CategRB;
341
    }
342

  
343

  
344
    private JRadioButton getDatCategRB() {
345
        if (dat_CategRB == null) {
346
            this.dat_CategRB = new JRadioButton(
347
                im.getTranslation("_Date_or_time"));
348
            this.dat_CategRB.addActionListener(this);
349
        }
350
        return dat_CategRB;
351
    }
352

  
353

  
354
    private JRadioButton getGeoCategRB() {
355
        if (geo_CategRB == null) {
356
            this.geo_CategRB = new JRadioButton(im.getTranslation("_Geometry"));
357
            this.geo_CategRB.addActionListener(this);
358
        }
359
        return geo_CategRB;
360
    }
361

  
362
    
363
    private JPanel getCategRadioPanel() {
364
        if (categRadioPanel == null) {
365
            categRadioPanel = new JPanel();
366
            ButtonGroup bg = new ButtonGroup();
367
            bg.add(getAllCategRB());
368
            bg.add(getNumCategRB());
369
            bg.add(getStrCategRB());
370
            bg.add(getDatCategRB());
371
            bg.add(getBooCategRB());
372
            bg.add(getGeoCategRB());
373
            getAllCategRB().setSelected(true);
374
            categRadioPanel.setLayout(new GridBagLayout());
375
            GridBagConstraints gbc = new GridBagConstraints();
376
            gbc.anchor = GridBagConstraints.NORTHWEST;
377
            gbc.fill = GridBagConstraints.BOTH;
378
            gbc.weightx = 0.5;
379
            gbc.gridx = 0;
380
            gbc.gridy = 0;
381
            categRadioPanel.add(getAllCategRB(), gbc);
382
            gbc.gridy = 1;
383
            categRadioPanel.add(getNumCategRB(), gbc);
384
            gbc.gridy = 2;
385
            categRadioPanel.add(getStrCategRB(), gbc);
386
            gbc.gridy = 3;
387
            categRadioPanel.add(getDatCategRB(), gbc);
388
            gbc.gridy = 4;
389
            categRadioPanel.add(getBooCategRB(), gbc);
390
            gbc.gridy = 5;
391
            categRadioPanel.add(getGeoCategRB(), gbc);
392
            gbc.gridy = 6;
393
            gbc.weighty = 1;
394
            categRadioPanel.add(new JPanel(), gbc);
395
        }
396
        return categRadioPanel;
397
    }
398

  
399
    
400
    /**
401
     * @return
402
     */
403
    private JRadioButton getBooCategRB() {
404
        if (boo_CategRB == null) {
405
            this.boo_CategRB = new JRadioButton(im.getTranslation("_Boolean"));
406
            this.boo_CategRB.addActionListener(this);
407
        }
408
        return boo_CategRB;
409
    }
410

  
411
    private JTextArea getOpfuDescLabel(Color bgcolor) {
412
        if (opfuDescLabel == null) {
413
            opfuDescLabel = new JTextArea();
414
            opfuDescLabel.setEditable(false);
415
            opfuDescLabel.setBorder(new EmptyBorder(2,2,2,2));
416
            if (bgcolor != null) {
417
                opfuDescLabel.setBackground(bgcolor);
418
            }
419
            opfuDescLabel.setWrapStyleWord(true);
420
            opfuDescLabel.setLineWrap(true);
421
            opfuDescLabel.setFont(new JLabel().getFont());
422
            opfuDescLabel.setText(" \n \n \n ");
423
        }
424
        return opfuDescLabel;
425
    }
426
    
427
    private JPanel getOpfuListCategPanel() {
428
        
429
        if (opfuDescPanel == null) {
430
            opfuDescPanel = new JPanel();
431
            opfuDescPanel.setLayout(new GridBagLayout());
432
            
433
            GridBagConstraints gbc = new GridBagConstraints();
434
            gbc.fill = GridBagConstraints.BOTH;
435
            gbc.anchor = GridBagConstraints.NORTHWEST;
436
            gbc.weightx = 0.5;
437
            gbc.weighty = 1;
438
            gbc.gridx = 0;
439
            gbc.gridy = 0;
440
            
441
            JScrollPane scroll = new JScrollPane(getOpfuList());
442
            scroll.setHorizontalScrollBarPolicy(
443
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
444
            scroll.setVerticalScrollBarPolicy(
445
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
446
            // scroll.setMinimumSize(new Dimension(100, 100));
447
            opfuDescPanel.add(scroll, gbc);
448
            
449
            gbc.weightx = 0.5;
450
            gbc.weighty = 1;
451
            gbc.gridx = 1;
452
            gbc.insets = new Insets(0, 5, 0, 0);
453
            opfuDescPanel.add(getCategRadioPanel(), gbc);
454
        }
455
        return opfuDescPanel;
456
    }
457
    
458
    private JPanel getOpfuPanel() {
459
        if (opfuPanel == null) {
460
            opfuPanel = new JPanel();
461
            opfuPanel.setLayout(new GridBagLayout());
462
            
463
            GridBagConstraints gbc = new GridBagConstraints();
464
            gbc.anchor = GridBagConstraints.NORTHWEST;
465
            gbc.fill = GridBagConstraints.BOTH;
466
            gbc.gridx = 0;
467
            gbc.gridy = 0;
468
            gbc.gridheight = 2;
469
            gbc.weightx = 1;
470
            gbc.weighty = 0.5;
471
            
472
            opfuPanel.add(getOpfuListCategPanel(), gbc);
473
            
474
            gbc.gridx = 0;
475
            gbc.gridy = 2;
476
            gbc.weightx = 1;
477
            gbc.weighty = 0.5;
478
            gbc.gridheight = 1;
479
            gbc.insets = new Insets(5, 0, 0, 0);
480
            
481
            opfuPanel.add(
482
                getOpfuDescScroll(opfuPanel.getBackground()), gbc);
483
            // ==================
484
            opfuPanel.setBorder(BorderFactory.createTitledBorder(
485
                im.getTranslation("_Available_functions_and_operators")));
486
            // ==================
487
            ActionEvent aev = new ActionEvent(getAllCategRB(), 0, "");
488
            this.actionPerformed(aev);
489
            
490
        }
491
        return opfuPanel;
492
    }
493
    
494
    private JScrollPane getOpfuDescScroll(Color bg) {
495
        
496
        if (opfuDescScroll == null) {
497
            opfuDescScroll = new JScrollPane(getOpfuDescLabel(bg));
498
            opfuDescScroll.setHorizontalScrollBarPolicy(
499
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
500
            opfuDescScroll.setVerticalScrollBarPolicy(
501
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
502
            opfuDescScroll.setBorder(new EmptyBorder(0, 0, 0, 0));
503
            
504
        }
505
        return opfuDescScroll;
506
    }
507
    
508
    private JTextArea getFieldExplainLabel(Color bgcolor) {
509
        if (fieldExplainLabel == null) {
510
            fieldExplainLabel = new JTextArea();
511
            fieldExplainLabel.setEditable(false);
512
            fieldExplainLabel.setBorder(new EmptyBorder(2,2,2,2));
513
            fieldExplainLabel.setBackground(bgcolor);
514
            fieldExplainLabel.setLineWrap(true);
515
            fieldExplainLabel.setWrapStyleWord(true);
516
            fieldExplainLabel.setFont(new JLabel().getFont());
517
            fieldExplainLabel.setText(
518
                im.getTranslation("_Double-click_to_paste_into_expression_box"));
519
        }
520
        return fieldExplainLabel;
521
    }
522
    
523
    private JPanel getFieldsPanel() {
524
        if (fieldsPanel == null) {
525
            fieldsPanel = new JPanel();
526
            fieldsPanel.setLayout(new GridLayout(1, 2, 12, 0));
527
            
528
            /*
529
            GridBagConstraints gbc = new GridBagConstraints();
530
            gbc.fill = GridBagConstraints.BOTH;
531
            gbc.anchor = GridBagConstraints.NORTHWEST;
532
            gbc.gridx = 0;
533
            gbc.gridy = 0;
534
            gbc.weightx = 1;
535
            gbc.weighty = 1;
536
            */
537
            
538
            JScrollPane scroll = new JScrollPane(getFieldList());
539
            scroll.setHorizontalScrollBarPolicy(
540
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
541
            scroll.setVerticalScrollBarPolicy(
542
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
543
            scroll.setMinimumSize(new Dimension(100, 100));
544
            fieldsPanel.add(scroll); // , gbc);
545
            
546
            /*
547
            gbc.gridx = 1;
548
            gbc.insets = new Insets(0, 5, 0, 0);
549
            */
550
            fieldsPanel.add(
551
                getFieldExplainLabel(fieldsPanel.getBackground()));
552
                // , gbc);
553
            
554
            // ================
555
            fieldsPanel.setBorder(BorderFactory.createTitledBorder(
556
                im.getTranslation("_Available_fields")));
557
        }
558
        return fieldsPanel;
559
    }
560
    
561
    private JPanel getTopPanel() {
562
        if (topPanel == null) {
563
            topPanel = new JPanel();
564
            topPanel.setLayout(new GridLayout(1, 2, 12, 0));
565
            topPanel.add(getFieldsPanel());
566
            topPanel.add(getOpfuPanel());
567
        }
568
        
569
        return topPanel;
570
    }
571
    
572

  
573
    public void valueChanged(ListSelectionEvent e) {
574
        
575
        if (e.getSource() == this.getOpfuList()) {
576
            Object sel = this.getOpfuList().getSelectedValue();
577
            if (sel instanceof DescriptionListItem) {
578
                DescriptionListItem item = (DescriptionListItem) sel;
579
                String txt = item.getDescription().getTemplate() + " : "
580
                    + item.getDescription().getDescription();
581
                this.getOpfuDescLabel(null).setText(txt);
582
                this.getOpfuDescLabel(null).scrollRectToVisible(
583
                    new Rectangle(0, 0, 10, 10));
584
                
585
                // =============
586
                this.getOpfuDescLabel(null).setCaretPosition(0);
587
                
588
            } else {
589
                this.getOpfuDescLabel(null).setText(" \n \n \n ");
590
            }
591
            return;
592
        }
593
    }
594

  
595

  
596
    public void mousePressed(MouseEvent e) {
597
        
598
        Object src = e.getSource();
599
        
600
        if (src == this.getFieldList() && e.getClickCount() == 2) {
601
            // paste field in text area
602
            Object sel = this.getFieldList().getSelectedValue();
603
            if (sel instanceof DynFieldListItem) {
604
                DynFieldListItem item = (DynFieldListItem) sel;
605
                int pos = this.getExpressionArea().getCaretPosition();
606
                this.getExpressionArea().insert(
607
                    item.getDynField().getName(), pos);
608
            }
609
            return;
610
        }
611

  
612
        if (src == this.getOpfuList() && e.getClickCount() == 2) {
613
            // paste function/operator in text area
614
            Object sel = this.getOpfuList().getSelectedValue();
615
            if (sel instanceof DescriptionListItem) {
616
                DescriptionListItem item = (DescriptionListItem) sel;
617
                int pos = this.getExpressionArea().getCaretPosition();
618
                this.getExpressionArea().insert(
619
                    item.getDescription().getTemplate(), pos);
620
            }
621
            return;
622
        }
623

  
624
    }
625
    public void mouseReleased(MouseEvent e) { }
626
    public void mouseEntered(MouseEvent e) { }
627
    public void mouseExited(MouseEvent e) { }
628
    public void mouseClicked(MouseEvent e) { }
629
    
630
    private class DescriptionListItem {
631
        
632
        private Description desc = null;
633
        
634
        public DescriptionListItem(Description d) {
635
            desc = d;
636
        }
637
        
638
        public String toString() {
639
            return desc.getName();
640
        }
641
        
642
        public Description getDescription() {
643
            return desc;
644
        }
645
        
646
    }
647

  
648
    public void actionPerformed(ActionEvent e) {
649
        
650
        if (e.getSource() instanceof JRadioButton) {
651
            this.reloadOpfuList(this.getOpfuList());
652
        }
653
        
654
        if (e.getSource() == this.getClearButton()) {
655
            this.getExpressionArea().setText("");
656
        }
657

  
658
        if (e.getSource() == this.getValidateButton()) {
659
            // this.getExpressionArea().setText("");
660
        }
661

  
662
    }
663

  
664

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

  
25
import org.gvsig.tools.dynobject.DynClass;
26
import org.gvsig.tools.dynobject.DynStruct;
27
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions;
28
import org.gvsig.tools.swing.api.ToolsSwingLibrary;
29
import org.gvsig.tools.swing.api.ToolsSwingLocator;
30
import org.gvsig.tools.swing.api.evaluator.ComponentSwingManager;
31
import org.gvsig.tools.swing.api.evaluator.EvaluatorPanel;
32

  
33

  
34
/**
35
 * Default implementation of (@link ComponentSwingManager)
36
 * Registered in {@link ToolsSwingLibrary}
37
 * 
38
 * @author jldominguez
39
 *
40
 */
41
public class DefaultComponentSwingManager
42
implements ComponentSwingManager {
43

  
44
    public EvaluatorPanel getEvaluatorPanel(
45
        DynClass dclass,
46
        EvaluatorWithDescriptions evaluator) {
47

  
48
        return new DefaultEvaluatorPanel(dclass, evaluator);
49
    }
50

  
51
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/ToolsSwingDefaultImplLibrary.java
30 30
import org.gvsig.tools.service.spi.ServiceManager;
31 31
import org.gvsig.tools.swing.api.ToolsSwingLibrary;
32 32
import org.gvsig.tools.swing.api.ToolsSwingLocator;
33
import org.gvsig.tools.swing.impl.component.DefaultComponentSwingManager;
33 34
import org.gvsig.tools.swing.impl.dynobject.DefaultDynObjectSwingManager;
34 35
import org.gvsig.tools.swing.impl.dynobject.DefaultDynObjectSwingServiceManager;
35 36
import org.gvsig.tools.swing.impl.dynobject.DefaultJDynObjectComponentFactory;
......
67 68
		ToolsSwingServiceLocator
68 69
				.registerDynObjectServiceManager(DefaultDynObjectSwingServiceManager.class);
69 70
        ToolsSwingLocator.registerIconThemeManager(DefaultIconThemeManager.class);
71
        
72
        ToolsSwingLocator.registerComponentSwingManager(
73
            DefaultComponentSwingManager.class);
74

  
70 75
	}
71 76

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

  
25
import javax.swing.JPanel;
26

  
27
import org.gvsig.tools.dynobject.DynClass;
28
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions;
29

  
30

  
31
/**
32
 * @author jldominguez
33
 *
34
 */
35
public abstract class EvaluatorPanel extends JPanel {
36

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

  
25
import org.gvsig.tools.dynobject.DynClass;
26
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions;
27

  
28

  
29
/**
30
 * 
31
 * This manager will provide useful Swing-based components
32
 * which can be re-used in different parts of the application
33
 * (for example, a panel to form an expression, a panel to preview
34
 * and select something, etc)
35
 * 
36
 * 
37
 * 
38
 * @author jldominguez
39
 *
40
 */
41
public interface ComponentSwingManager {
42
    
43
    public EvaluatorPanel getEvaluatorPanel(
44
        DynClass dclass, EvaluatorWithDescriptions evaluator);
45

  
46
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.api/src/main/java/org/gvsig/tools/swing/api/ToolsSwingLocator.java
26 26
import org.gvsig.tools.locator.BaseLocator;
27 27
import org.gvsig.tools.locator.Locator;
28 28
import org.gvsig.tools.swing.api.dynobject.DynObjectSwingManager;
29
import org.gvsig.tools.swing.api.evaluator.ComponentSwingManager;
29 30
import org.gvsig.tools.swing.api.task.TaskStatusSwingManager;
30 31
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
31 32
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
......
66 67

  
67 68
	private static final String ICONTHEME_MANAGER_DESCRIPTION = "Tools Icon Theme Manager";
68 69

  
70
    private static final String COMPONENT_SWING_MANAGER_NAME = "Tools.swing.componentmanager";
71

  
72
    private static final String COMPONENT_SWING_MANAGER_DESCRIPTION = "Tools Swing Component Manager";
73

  
69 74
	/**
70 75
     * Unique instance.
71 76
     */
......
204 209
        getInstance().register(ICONTHEME_MANAGER_NAME,
205 210
        		ICONTHEME_MANAGER_DESCRIPTION, clazz);
206 211
    }
212
    
213
    /**
214
     * Gets the instance of the {@link ComponentSwingManager} registered.
215
     * 
216
     * @return {@link ComponentSwingManager}
217
     */
218
    public static ComponentSwingManager getComponentSwingManager() {
219
        return (ComponentSwingManager) getInstance().get(
220
            COMPONENT_SWING_MANAGER_NAME);
221
    }
207 222

  
223
    /**
224
     * Registers the Class implementing the {@link ComponentSwingManager}
225
     * interface.
226
     * 
227
     * @param clazz
228
     *            implementing the {@link ComponentSwingManager} interface
229
     */
230
    public static void registerComponentSwingManager(
231
        Class<? extends ComponentSwingManager> clazz) {
232
        getInstance().register(
233
            COMPONENT_SWING_MANAGER_NAME,
234
            COMPONENT_SWING_MANAGER_DESCRIPTION, clazz);
235
    }
236

  
237

  
208 238
}

Also available in: Unified diff