Revision 285

View differences:

org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.serv/org.gvsig.tools.swing.serv.field/src/main/java/org/gvsig/tools/swing/components/SpinnerNumberModel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22
/*
23
 * AUTHORS (In addition to CIT):
24
 * 2010 Institute of New Imaging Technologies (INIT): 
25
 *   http://www.init.uji.es
26
 * Geographic Information research group: 
27
 *   http://www.geoinfo.uji.es
28
 * Universitat Jaume I, Spain
29
 */
30

  
31
/**
32
 * 
33
 */
34
package org.gvsig.tools.swing.components;
35

  
36
import org.gvsig.tools.dynobject.DynField;
37

  
38
/**
39
 * @author <a href="mailto:reinhold@uji.es">cmartin</a>
40
 * 
41
 */
42
public class SpinnerNumberModel extends javax.swing.SpinnerNumberModel {
43

  
44
    private boolean valid;
45
    private boolean firstTime = true;
46

  
47
    private SpinnerNumberModel(DynField field) {
48
        super(0, (Comparable<?>) field.getMinValue(), (Comparable<?>) field
49
            .getMaxValue(), Integer.valueOf(1));
50
    }
51

  
52
    /**
53
     * @param field
54
     * @param value
55
     */
56
    public SpinnerNumberModel(DynField field, Number value) {
57
        this(field);
58
        setValue(value);
59
    }
60

  
61
    /*
62
     * (non-Javadoc)
63
     * 
64
     * @see javax.swing.SpinnerNumberModel#getNumber()
65
     */
66
    @Override
67
    public Number getNumber() {
68
        // TODO Auto-generated method stub
69
        return super.getNumber();
70
    }
71

  
72
    /*
73
     * (non-Javadoc)
74
     * 
75
     * @see javax.swing.SpinnerNumberModel#getValue()
76
     */
77
    @Override
78
    public Object getValue() {
79
        if (valid)
80
            return super.getValue();
81
        else
82
            return null;
83
    }
84

  
85
    /*
86
     * (non-Javadoc)
87
     * 
88
     * @see javax.swing.SpinnerNumberModel#setValue(java.lang.Object)
89
     */
90
    @Override
91
    public void setValue(Object value) {
92
        if (value != null) {
93
            try {
94
                valid = true;
95
                super.setValue(value);
96
                return;
97
            } catch (Exception e) {
98
            }
99
        }
100
        valid = false;
101
        super.setValue(value);
102
    }
103

  
104
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.serv/org.gvsig.tools.swing.serv.field/src/main/java/org/gvsig/tools/swing/serv/field/component/AbstractReturnComponentLauncher.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22
/*
23
 * AUTHORS (In addition to CIT):
24
 * 2010 Institute of New Imaging Technologies (INIT): 
25
 *   http://www.init.uji.es
26
 * Geographic Information research group: 
27
 *   http://www.geoinfo.uji.es
28
 * Universitat Jaume I, Spain
29
 */
30

  
31
/**
32
 * 
33
 */
34
package org.gvsig.tools.swing.serv.field.component;
35

  
36
import java.awt.event.ActionEvent;
37
import java.awt.event.ActionListener;
38

  
39
import javax.swing.JButton;
40

  
41
import org.gvsig.tools.dynobject.DynField;
42
import org.gvsig.tools.service.ServiceException;
43
import org.gvsig.tools.swing.api.ToolsSwingLocator;
44
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
45
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
46
import org.gvsig.tools.swing.components.ResultListener;
47
import org.gvsig.tools.swing.spi.AbstractJDynFieldComponent;
48

  
49
/**
50
 * @author <a href="mailto:reinhold@uji.es">cmartin</a>
51
 * 
52
 */
53
public abstract class AbstractReturnComponentLauncher extends
54
    AbstractJDynFieldComponent implements ResultListener, JDynFieldComponent {
55

  
56
    private JButton button;
57

  
58
    /**
59
     * @param dynField
60
     * @param value
61
     * @throws ServiceException
62
     */
63
    public AbstractReturnComponentLauncher(DynField dynField, ValueField value,
64
        String buttonLabel) throws ServiceException {
65
        super(dynField, value);
66
        button.setText(buttonLabel);
67
    }
68

  
69
    /**
70
     * @return
71
     */
72
    protected JButton getButton() {
73
        if (button == null)
74
            this.initButton();
75
        return button;
76
    }
77

  
78
    private void initButton() {
79
        button = this.createButton("");
80
        button.addActionListener(new ActionListener() {
81

  
82
            public void actionPerformed(ActionEvent e) {
83
                AbstractReturnComponentLauncher.this.onButtonClicked();
84
            }
85

  
86
        });
87

  
88
    }
89

  
90
    private void onButtonClicked() {
91
        this.showResultProviderDialog();
92
    }
93
}

Also available in: Unified diff