Revision 296

View differences:

org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.main/src/main/java/org/gvsig/tools/main/dynobject/TestDynObject.java
117 117
        this.addDynFieldFloat("float");
118 118
        this.addDynFieldList("float-list").setMandatory(true).setElementsType(
119 119
            DataTypes.FLOAT);
120
        this.addDynFieldFloat("byte");
120
        //revisar esto
121
        this.addDynField("byte").setType(DataTypes.BYTE);
121 122
        this.addDynFieldList("byte-list").setMandatory(true).setElementsType(
122 123
            DataTypes.BYTE);
123 124

  
......
148 149

  
149 150
        this.addDynField("Address").setType(DataTypes.DYNOBJECT);
150 151

  
151
        // this.addDynField("dates").setMandatory(true)
152
        // .setType(DataTypes.DATE);
152
         this.addDynFieldList("dates").setMandatory(true).setElementsType(
153
             DataTypes.DATE);
153 154
    }
154 155

  
155 156
    /**
......
176 177

  
177 178
        model.add("integers", "integer");
178 179
        model.add("integers", "float");
180
        model.add("integers", "dates");
179 181
        model.add("list", "byte");
180 182
        model.add("list", "integer-list");
181 183
        model.add("list", "float-list");
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.main/pom.xml
12 12
	<dependencies>
13 13
		<dependency>
14 14
			<groupId>org.gvsig</groupId>
15
			<artifactId>org.gvsig.tools.lib</artifactId>
16
			<version>2.1.0-SNAPSHOT</version>
17
		</dependency>
18
		<dependency>
19
			<groupId>org.gvsig</groupId>
15 20
			<artifactId>org.gvsig.tools.swing.api</artifactId>
16 21
			<version>2.1.0-SNAPSHOT</version>
17 22
		</dependency>
18
		<!-- 
19 23
		<dependency>
20 24
			<groupId>org.gvsig</groupId>
21 25
			<artifactId>org.gvsig.tools.swing.spi</artifactId>
22 26
			<version>2.1.0-SNAPSHOT</version>
23
			<scope>runtime</scope>
24 27
		</dependency>
25
		 -->
26 28
		<dependency>
27 29
			<groupId>org.gvsig</groupId>
28 30
			<artifactId>org.gvsig.tools.swing.impl</artifactId>
......
41 43
			<version>2.1.0-SNAPSHOT</version>
42 44
			<scope>runtime</scope>
43 45
		</dependency>
44
		<dependency>
46
		<!--  dependency>
45 47
			<groupId>org.gvsig</groupId>
46 48
			<artifactId>org.gvsig.metadata</artifactId>
47 49
			<version>2.0-SNAPSHOT</version>
......
52 54
			<version>2.0-SNAPSHOT</version>
53 55
			<classifier>simple</classifier>
54 56
			<scope>runtime</scope>
55
		</dependency>
57
		</dependency-->
56 58
	</dependencies>
57 59
</project>
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.serv/org.gvsig.tools.swing.serv.jform/pom.xml
9 9
		<artifactId>org.gvsig.tools.swing.serv</artifactId>
10 10
		<version>2.1.0-SNAPSHOT</version>
11 11
	</parent>
12
	<dependencies>
13
		<dependency>
14
			<groupId>org.gvsig</groupId>
15
			<artifactId>org.gvsig.tools.swing.spi</artifactId>
16
			<version>2.1.0-SNAPSHOT</version>
17
		</dependency>
18
	</dependencies>
19 12
</project>
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/ResultListener.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 java.util.EventListener;
37

  
38
/**
39
 * @author <a href="mailto:reinhold@uji.es">cmartin</a>
40
 * 
41
 */
42
public interface ResultListener extends EventListener {
43

  
44
    public void onResult(int returnVal, Object returnValue);
45

  
46
    public void showResultProviderDialog();
47

  
48
}
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/ResultProvider.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.swing.api.ComponentService;
37

  
38
/**
39
 * @author <a href="mailto:reinhold@uji.es">cmartin</a>
40
 * 
41
 */
42
public interface ResultProvider {
43

  
44
    int RETURN_OK = 0;
45
    int RETURN_CANCEL = 1;
46
    int RETURN_ERROR = 2;
47

  
48
    public void addResultListener(ResultListener listener);
49

  
50
    public void alignToField(ComponentService component);
51

  
52
    public void fireResultEvent(int resultVal, Object value);
53

  
54
    public void showDialog();
55

  
56
}
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/DefaultResultListenersHandler.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 java.util.ArrayList;
37

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

  
44
    public void fireResultEvent(int returnVal, Object returnValue) {
45
        for (ResultListener listener : this) {
46
            listener.onResult(returnVal, returnValue);
47
        }
48
    }
49

  
50
    /**
51
     * @param listener
52
     * @param resultVal
53
     * @param value
54
     */
55
    public void fireResultEvent(ResultListener listener, int returnVal,
56
        Object returnValue) {
57
        for (ResultListener item : this) {
58
            if (!item.equals(listener))
59
                listener.onResult(returnVal, returnValue);
60
        }
61
    }
62
}
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/JNumberDynFieldComponent.java
26 26
 */
27 27
package org.gvsig.tools.swing.serv.field.component;
28 28

  
29
import java.awt.event.ActionEvent;
30
import java.awt.event.ActionListener;
31
import java.util.Date;
29 32
import java.util.Locale;
30 33

  
31 34
import javax.swing.AbstractSpinnerModel;
35
import javax.swing.ImageIcon;
32 36
import javax.swing.JComponent;
33 37
import javax.swing.JSpinner;
34 38
import javax.swing.SpinnerModel;
......
38 42
import org.gvsig.tools.dynobject.DynField;
39 43
import org.gvsig.tools.dynobject.DynObject;
40 44
import org.gvsig.tools.service.ServiceException;
45
import org.gvsig.tools.swing.api.dynobject.ValueChangedListener;
41 46
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
42 47
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
48
import org.gvsig.tools.swing.serv.field.component.date.JDateCalendarDynFieldComponent;
43 49
import org.gvsig.tools.swing.serv.field.component.date.JNullSpinner;
44 50
import org.gvsig.tools.swing.serv.field.component.spinner.NullNumberEditor;
45 51
import org.gvsig.tools.swing.serv.field.component.spinner.NullSpinnerHandler;
......
52 58
 * @author 2010- C?sar Ordi?ana - gvSIG team
53 59
 */
54 60
public class JNumberDynFieldComponent extends AbstractJDynFieldComponent
55
    implements JDynFieldComponent, ChangeListener {
61
    implements JDynFieldComponent,ValueChangedListener {
56 62

  
57 63
    private static final long serialVersionUID = -8120715001446683582L;
58 64

  
59 65
    private static Object NULL_VALUE = null;
66
    private static final String BTN_EMPTY_IMG_PATH = "../editdelete.png";
67
    
68
    private JNullValueMuttableTextField pane;
60 69

  
61
    private NullSpinnerNumberModel model;
62

  
63
    // private JPanel panel;
64

  
65
    private JNullSpinner spinner;
66

  
67 70
    /**
68 71
     * @param parent
69 72
     * @throws ServiceException
......
81 84
     */
82 85
    @Override
83 86
    protected void afterUI() {
84
        // TODO Auto-generated method stub
85 87

  
86 88
    }
87 89

  
88
    /**
89
     * Creates a SpinnerModel for the component's spinner.
90
     */
91
    private JNullSpinner getSpinner() {
92
        if (this.spinner != null) return this.spinner;
93
    
94
        this.spinner = new JNullSpinner(this.getDynField());
95
        this.spinner.setValue(this.getInitialValue());
96
        return this.spinner;
97
    }
98

  
99 90
    /*
100 91
     * (non-Javadoc)
101 92
     * 
102 93
     * @see org.gvsig.tools.swing.api.dynobject.JComponent#getComponent()
103 94
     */
104 95
    public JComponent asJComponent() {
105
        return spinner;
96
        return this.getModel();
106 97
    }
107 98
    
108 99
    /*
......
113 104
     * ()
114 105
     */
115 106
    public Object getValue() {
116
        Object value = model.getValue();
117
        if ((value != null) && (value.equals(NULL_VALUE)))
118
            return null;
119
        return value;
107
        return getModel().getTextFieldValue();
120 108
    }
121 109

  
122 110
    /*
......
133 121
     */
134 122
    @Override
135 123
    protected void initUI() {
136
        // this.panel = new JPanel();
137
        // this.panel.setLayout(new BorderLayout());
138
        spinner = this.getSpinner();
139
        model = (NullSpinnerNumberModel) spinner.getModel();
140
                
141
        //        spinner.setEditor(new NullNumberEditor(this.getDynField(),spinner));
142
        // this.panel.add(spinner, BorderLayout.CENTER);
124
        this.pane = new JNullValueMuttableTextField(this.getDynField(),this.getInitialValue(),Locale.getDefault(), getBtnEmptyImageIcon());
125
        this.pane.addValueChangedListener(this);
143 126
    }
144 127

  
145 128
    /*
......
148 131
     * @see
149 132
     * 
150 133
     * 
151
     * org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#isMandatory
152
     * ()
153
     */
154
    @Override
155
    public boolean isMandatory() {
156
        return this.getDynField().isMandatory();
157
    }
158

  
159
    /*
160
     * (non-Javadoc)
161
     * 
162
     * @see
163
     * 
164
     * 
165 134
     * org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#requestFocus
166 135
     * ()
167 136
     */
168 137
    public void requestFocus() {
169
        spinner.requestFocus();
138
        getModel().requestFocus();
139
        this.fireValueChangedEvent();
170 140
    }
171 141

  
172 142
    @Override
173 143
    public void saveStatus() {
174
        if (model != null) {
175
            this.setFieldValue(model.getValue());
144
        if (getModel() != null) {
145
            this.setFieldValue(getModel().getValue());
176 146
        }
177 147
    }
178 148

  
......
186 156
     * (boolean)
187 157
     */
188 158
    public void setEnabled(boolean isEnabled) {
189
        spinner.getEditor().setEnabled(true);
159
        getModel().setEnabled(true);
190 160
    }
191 161

  
192 162
    /*
......
197 167
     */
198 168
    @Override
199 169
    protected void setJDynFieldComponentListeners() {
200
        model.addChangeListener(this);
170
//        getModel().addEmptyButtonActionListener(this);
201 171
    }
202 172

  
203 173
    /*
......
207 177
     */
208 178
    @Override
209 179
    protected void setReadOnly() {
210
        spinner.setEnabled(false);
180
        // do nothing
211 181
    }
212 182

  
213 183
    /*
......
218 188
     * (java.lang.Object)
219 189
     */
220 190
    protected void setNullValue() {
221
        model.setValue(NULL_VALUE);
191
        getModel().setValue(NULL_VALUE);
222 192
    }
223 193

  
224 194
    protected void setNonNullValue(Object value) {
225
        model.setValue(value);
195
        getModel().setValue(value);
226 196
    }
227 197

  
228
    /*
229
     * (non-Javadoc)
230
     * 
231
     * @see
232
     * 
233
     * 
234
     * javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent
235
     * )
236
     */
237
    public void stateChanged(ChangeEvent e) {
198
    private JNullValueMuttableTextField getModel() {
199
       return this.pane;
200
    }
201
   
202
    protected ImageIcon getBtnEmptyImageIcon() {
203
        String path = this.getClass().getResource(BTN_EMPTY_IMG_PATH).getPath();
204
        return new ImageIcon(path);
205
    }
206
//    /*
207
//     * (non-Javadoc)
208
//     * 
209
//     * @see
210
//     * 
211
//     * 
212
//     * javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent
213
//     * )
214
//     */
215
//    public void stateChanged(ChangeEvent e) {
216
//        this.fireValueChangedEvent();
217
//    }
218

  
219
//    public void actionPerformed(ActionEvent e) {
220
//        this.fireValueChangedEvent();
221
//    }
222

  
223
    public void handleValueChanged(JDynFieldComponent field) {
238 224
        this.fireValueChangedEvent();
239 225
    }
240 226

  
227
    @Override
228
    public boolean isValid() {
229
        Number num = (Number) getValue();
230
        if ((num==null)&&(this.getDynField().isMandatory()))
231
            return false;
232
        return true;      
233
    }
241 234
}
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/JNullValueMuttableTextField.java
1
package org.gvsig.tools.swing.serv.field.component;
2

  
3
import java.awt.event.ActionEvent;
4
import java.awt.event.ActionListener;
5
import java.awt.event.FocusEvent;
6
import java.awt.event.FocusListener;
7
import java.awt.event.KeyEvent;
8
import java.awt.event.KeyListener;
9
import java.text.ParseException;
10
import java.util.Locale;
11

  
12
import javax.swing.BorderFactory;
13
import javax.swing.Box;
14
import javax.swing.BoxLayout;
15
import javax.swing.ImageIcon;
16
import javax.swing.JButton;
17
import javax.swing.JLabel;
18
import javax.swing.JPanel;
19
import javax.swing.JSpinner;
20
import javax.swing.JTextField;
21

  
22
import org.gvsig.tools.dynobject.DynField;
23
import org.gvsig.tools.swing.api.dynobject.ValueChangedListener;
24
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
25
import org.gvsig.tools.swing.serv.field.component.spinner.DynFieldEditor;
26

  
27
/**
28
 * 
29
 * This class is used a JSpinner to accept null values by 
30
 *   changing to an empty JTextField when the value is null
31
 *   when clicking to the null component, the JTextField will 
32
 *   disappear and the currentValue will be shown in the 
33
 *   JSpinner.
34
 * 
35
 * @author gvSIG Team
36
 * @version $Id$
37
 *
38
 */
39
public class JNullValueMuttableTextField extends JPanel implements KeyListener{
40
    
41

  
42
    private JTextField textField;
43
    private JButton btnEmptyLabel;
44
    
45

  
46
    private DynFieldEditor editor;
47
    private DynField field;
48
    private Object value;
49
    
50
    private boolean isReadOnly;
51

  
52
    private ImageIcon icon;
53

  
54
    
55
    /**
56
     * Constructor.
57
     * 
58
     * @param field   the {@link DynField} to which the field refers to.
59
     * @param initialValue the initial value to be set.
60
     * @param locale 
61
     */
62
    public JNullValueMuttableTextField(DynField field, Object initialValue, Locale locale, ImageIcon btnEmptyImageIcon){
63
        super();
64
        this.setLocale(locale);
65
        this.field = field;
66
        this.value = null;
67
        this.isReadOnly = false;
68
        this.icon = btnEmptyImageIcon;
69
        initUI();
70
        afterUI(initialValue, locale);
71
        this.fireValueChangedEvent(); 
72
    }
73

  
74
    private void afterUI(Object initialValue, Locale locale) {
75
       if (this.field.isReadOnly()){
76
            this.isReadOnly = true;
77
            getJTextField().setVisible(false);
78
            getBtnEmpty().setVisible(false);
79
            
80
            getJSpinner().setValue(initialValue);
81
            getJSpinner().setEnabled(false);   
82
        }else{
83
            setValue(initialValue);
84
        }
85
    }
86
   
87

  
88
    public void addEmptyButtonActionListener(ActionListener listener){
89
        this.getBtnEmpty().addActionListener(listener);
90
    }  
91

  
92
    /**
93
     * Inits the main graphic user interface
94
     */
95
    private void initUI() {
96
        this.setLayout(new BoxLayout(this,BoxLayout.LINE_AXIS));
97
        this.editor = new DynFieldEditor(this.field,this.getLocale());
98
        this.editor.getTextField().addKeyListener(this);
99
        // Adding components
100
        this.add(getJSpinner());
101
        this.add(getJTextField());
102
        this.add(Box.createHorizontalStrut(3));
103
        this.add(getBtnEmpty());
104
        this.add(Box.createHorizontalStrut(4));
105
    }
106
    
107
    /**
108
     * Determines if this field is readonly or not.
109
     * 
110
     * @return  true if it is only readable, false otherwise.
111
     */
112
    private boolean isReadOnly(){
113
        return this.isReadOnly;
114
    }
115
    
116
   
117
    /**
118
     * Gets the image button component
119
     * 
120
     * @return the Image button component
121
     */
122
    private JButton getBtnEmpty() {
123
        if (btnEmptyLabel!=null){
124
            return btnEmptyLabel;
125
        }
126
        
127

  
128
        String description = "Empties the field value.";
129
        icon.setDescription(description);
130
       
131
        
132
        btnEmptyLabel = new JButton();
133
        btnEmptyLabel.setActionCommand("BTN_OK");
134
        btnEmptyLabel.setOpaque(false);
135
        btnEmptyLabel.setBorderPainted(false);
136
        btnEmptyLabel.setBorder(BorderFactory.createEmptyBorder());
137
        btnEmptyLabel.setSize(new java.awt.Dimension(icon.getIconWidth(),icon.getIconHeight()));
138
        btnEmptyLabel.setHorizontalAlignment(JLabel.RIGHT);
139
        btnEmptyLabel.setVerticalAlignment(JLabel.TOP);
140
        btnEmptyLabel.setIcon(icon);
141
        
142
//        btnEmptyPanel = new JPanel();
143
//        btnEmptyPanel.add(btnEmptyLabel);
144
//        btnEmptyLabel.setOpaque(false);
145
        btnEmptyLabel.addActionListener(new ActionListener(){
146

  
147
            public void actionPerformed(ActionEvent e) {
148
                setEmptyValue();
149
            }            
150
        });
151
        return btnEmptyLabel;
152
    }
153

  
154
    protected Object getDefaultValue() {
155
        return this.editor.getDefaultValue();
156
    }
157

  
158
    /**
159
     * Gets the current JSpinner component
160
     * 
161
     * @return  the spinner component
162
     */
163
    private JSpinner getJSpinner(){
164
        return this.editor.getSpinner();
165
    }
166
    
167
    protected DynField getDynField(){
168
        return this.field;
169
    }
170

  
171
    /**
172
     * Gets the current JTextField component
173
     * 
174
     * @return the JTextField component
175
     */
176
    private JTextField getJTextField(){
177
        if (textField !=null)
178
            return textField;
179
        
180
        textField = new JTextField();
181
//        textField.setEditable(false);
182
        textField.addFocusListener(new FocusListener(){
183
            public void focusGained(FocusEvent e) {
184
                setValue(editor.getDefaultValue());
185
            }
186

  
187
            public void focusLost(FocusEvent e) {
188
               fireValueChangedEvent();             
189
            }
190
        });
191
        return textField;
192
    }
193
    
194

  
195
    /**
196
     * Gets the current value of this component. This value can be null.
197
     * 
198
     * @return
199
     */
200
    public Object getValue() {
201
        return this.value;
202
    }
203
    
204
    /**
205
     * Sets a value if it is not readonly.
206
     * 
207
     * @param value
208
     */
209
    public void setValue(Object value) {
210
        if (isReadOnly()){
211
            return;
212
        }
213
       
214
        if (value==null){
215
            setEmptyValue();
216
        }else{
217
            setNonEmptyValue(value);
218
        }
219
    }
220

  
221
    /**
222
     * Sets the appropiate components properties for
223
     *   when the value is not null. 
224
     */
225
    private void setNonEmptyValue(Object value) {
226
//        this.editor.setText(value);
227
//        this.value = editor.getValue();
228
        getJSpinner().setValue(value);
229
        this.value = getJSpinner().getValue();
230

  
231
        
232
        this.textField.setVisible(false);
233
        getJSpinner().setVisible(true);
234
        getJSpinner().requestFocus();
235
        
236
        fireValueChangedEvent();
237
        
238
    }
239

  
240
    /**
241
     * Sets the appropiate components properties for
242
     *   when the value is null. 
243
     */
244
    private void setEmptyValue() {   
245
        this.value = null;
246

  
247
        
248
//        this.editor.setText(null);
249
        getJSpinner().setVisible(false);
250
        this.textField.setVisible(true);
251
        fireValueChangedEvent();
252
        
253
    }
254

  
255
    public void setEditable(boolean isEditable) {
256
        this.setEditable(isEditable);
257
    }
258

  
259
    public void addValueChangedListener(
260
        ValueChangedListener listener) {
261
        if (listener instanceof JDynFieldComponent){
262
           this.listenerList.add(ValueChangedListener.class, listener);
263
        }
264
    }
265
    
266

  
267
    public void keyPressed(KeyEvent e) {
268
    }
269

  
270

  
271
    public void keyReleased(KeyEvent e) {
272

  
273
    }
274

  
275
    public void keyTyped(KeyEvent e) {
276
        this.fireValueChangedEvent();
277
    }
278

  
279
    public Object getTextFieldValue() {
280
        if (this.textField.isVisible())
281
            return null;
282
        try {
283
            return this.editor.getFormat().parse(this.editor.getTextField().getText());
284
        } catch (ParseException e) {
285
            return null;
286
        }
287
    }
288

  
289
    public void fireValueChangedEvent() {
290
        ValueChangedListener[] list = this.listenerList.getListeners(ValueChangedListener.class);
291
        for (ValueChangedListener listener: list){
292
            listener.handleValueChanged((JDynFieldComponent) listener);
293
        }
294
    }
295

  
296
}
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/JBooleanDynFieldComponent.java
70 70
    public JBooleanDynFieldComponent(ValueField parent)
71 71
        throws ServiceException {
72 72
        super(parent);
73
        if (parent.getDynField().isContainer()){
74
            this.btUnknown.setEnabled(false);
75
        }
73 76
    }
74 77

  
75 78
    public void actionPerformed(ActionEvent e) {
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/JFileDynfieldComponent.java
279 279
     * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
280 280
     */
281 281
    public void keyPressed(KeyEvent e) {
282
        // TODO Auto-generated method stub
283

  
282
       
284 283
    }
285 284

  
286 285
    /*
......
299 298
     * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
300 299
     */
301 300
    public void keyTyped(KeyEvent e) {
302
       isValid();
303
       this.fireValueChangedEvent();
301
        if (!isValid()){
302
            file = null;
303
            this.fireValueChangedEvent();   
304
        }
304 305
    }
305 306

  
306 307
    /**
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/date/JDateCalendarDynFieldComponent.java
1 1
package org.gvsig.tools.swing.serv.field.component.date;
2 2

  
3
import java.awt.BorderLayout;
4
import java.awt.Component;
5 3
import java.awt.event.ActionEvent;
6 4
import java.awt.event.ActionListener;
7 5
import java.awt.event.FocusEvent;
8 6
import java.awt.event.FocusListener;
9
import java.text.ParseException;
10 7
import java.util.Calendar;
11 8
import java.util.Date;
12 9
import java.util.Locale;
13 10

  
14
import javax.swing.BorderFactory;
15
import javax.swing.Box;
16
import javax.swing.BoxLayout;
11
import javax.swing.ImageIcon;
17 12
import javax.swing.JButton;
18 13
import javax.swing.JComponent;
19 14
import javax.swing.JDialog;
20
import javax.swing.JFormattedTextField;
21
import javax.swing.JPanel;
22
import javax.swing.JFormattedTextField.AbstractFormatter;
23
import javax.swing.JSpinner.DefaultEditor;
24 15
import javax.swing.event.ChangeEvent;
25 16
import javax.swing.event.ChangeListener;
26 17

  
......
28 19

  
29 20
import org.gvsig.tools.dataTypes.DataTypes;
30 21
import org.gvsig.tools.service.ServiceException;
22
import org.gvsig.tools.swing.api.dynobject.ValueChangedListener;
31 23
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent;
32 24
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField;
25
import org.gvsig.tools.swing.serv.field.component.JNullValueMuttableTextField;
33 26
import org.gvsig.tools.swing.spi.AbstractJDynFieldComponent;
34 27

  
35 28
public class JDateCalendarDynFieldComponent extends AbstractJDynFieldComponent
36
    implements JDynFieldComponent, ActionListener, FocusListener, ChangeListener {
29
    implements JDynFieldComponent, FocusListener, ChangeListener, ValueChangedListener, ActionListener {
37 30

  
31
    private static final String BTN_EMPTY_IMG_PATH = "../../editdelete.png";
32
    
38 33
    private JButton jBtnChangeDate;
39
    private JNullSpinner dateField;
34
//    private JNullSpinner dateField;
40 35
    private DateCalendarPicker datePicker;
41 36
    private JDialog dlg;
42
    private JPanel pane;
43
    private String oldTxt;
37
//    private JPanel pane;
38
    private JNullValueMuttableTextField dateFieldPanel;
39
    private Object oldTxt;
44 40

  
45 41
    public JDateCalendarDynFieldComponent(ValueField valueField)
46 42
        throws ServiceException {
......
48 44
        if (getDynField().getType() != DataTypes.DATE) {
49 45
            this.getJBtnChangeDate().setVisible(false);
50 46
        }
51
        // for (FocusListener listener :
52
        // getTextField().getListeners(FocusListener.class)){
53
        // getTextField().removeFocusListener(listener);
54
        // }
55
        getTextField().addFocusListener(this);
56
        // .agetTextField().getDocument().addDocumentListener( new
57
        // DocumentListener(){
58
        //
59
        // public void changedUpdate(DocumentEvent e) {
60
        // validate();
61
        // }
62
        //
63
        // public void insertUpdate(DocumentEvent e) {
64
        // validate();
65
        // }
66
        //
67
        // public void removeUpdate(DocumentEvent e) {
68
        // validate();
69
        // }});
70 47
    }
71 48

  
72 49
    /**
......
83 60
        return jBtnChangeDate;
84 61
    }
85 62

  
86
    protected JNullSpinner getDateField() {
87
        if (this.dateField == null){
88
            this.dateField = new JNullSpinner(this.getDynField());
89
            this.dateField.addChangeListener(this);
90
            this.dateField.setValue(this.getInitialValue());
91
        }
92
        return this.dateField;
93
    }
94
    
95 63
    protected DateCalendarPicker createCalendarPicker(Date date, Locale loc){
96
        DateCalendarPicker datePicker = new DateCalendarPicker(this.getDate(), pane.getLocale());
64
        DateCalendarPicker datePicker = new DateCalendarPicker(this.getDate(), loc);
97 65
        datePicker.setPreferredSize(new java.awt.Dimension(450, 410));
98 66
        return datePicker;
99 67
    }
......
105 73
        dlg.setVisible(true);
106 74
    }
107 75
    
108
    private void initBtnChangeDate() {
76
    private void initBtnChangeDate(Locale loc) {
109 77
        if (datePicker == null) {
110 78
            datePicker =
111
                createCalendarPicker(this.getDate(), pane.getLocale());
79
                createCalendarPicker(this.getDate(), loc);
112 80
            // datePicker.setSize(datePicker.getPreferredSize());
113 81
            datePicker.addButtonsActionListener(this);
114 82
        }
......
126 94
        return (Date) getValue();
127 95
    }
128 96

  
129
    public void createBoxLayout(Component labelComponent, Component fieldLabel,
130
        Integer marginLeft, Integer marginRight) {
131 97

  
132
        // Create a panel that uses GridLayout.
133
        pane.setLayout(new BoxLayout(pane, BoxLayout.LINE_AXIS));
134
        pane.add(labelComponent);
135
        if (marginLeft != null)
136
            pane.add(Box.createHorizontalStrut(marginLeft));
137
        // this.add(new JSeparator(SwingConstants.VERTICAL));
138
        if (marginRight != null)
139
            pane.add(Box.createHorizontalStrut(marginRight));
140
        pane.add(fieldLabel, BorderLayout.NORTH);
141
        // if (buttonComponent!=null)
142
        // this.add(buttonComponent);
143
        pane.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
144
    }
145

  
146 98
    public void dateChanged(DateEvent dateEvent) {
147 99
        Calendar cal = dateEvent.getSelectedDate();
148 100
        if (cal != null) {
149
            this.getDateField().setValue(null);
101
            this.getModel().setValue(null);
150 102
        } else {
151
            this.getDateField().setValue(cal.getTime());
103
            this.getModel().setValue(cal.getTime());
152 104
        }
153 105
        close();
106
        this.fireValueChangedEvent();
154 107
    }
155 108

  
156 109
    protected void close() {
......
163 116

  
164 117
    @Override
165 118
    protected void setNonNullValue(Object value) {
166
        this.dateField.setValue(value);
119
        this.getModel().setValue(value);
167 120
    }
168 121

  
169 122
    @Override
170 123
    protected void setNullValue() {
171
        this.dateField.setValue(null);
124
        this.getModel().setValue(null);
172 125
    }
173 126

  
174 127
    @Override
......
185 138

  
186 139
    @Override
187 140
    protected void initUI() {
188
        pane = new JPanel();
189
        pane.setLocale(Locale.getDefault());
190
        createBoxLayout(getDateField(), getJBtnChangeDate(), 3, 1);
191
        initBtnChangeDate();
141
        this.dateFieldPanel = new JNullValueMuttableTextField(this.getDynField(),this.getInitialValue(), Locale.getDefault(),getBtnEmptyImageIcon());
142
//        this.dateFieldPanel.addEmptyButtonActionListener(this);
143
        this.dateFieldPanel.add(this.getJBtnChangeDate());
144
        this.dateFieldPanel.addValueChangedListener(this);
145
        initBtnChangeDate(getModel().getLocale());
192 146
    }
193 147

  
194 148
    @Override
195 149
    protected void setReadOnly() {
196
        this.dateField.setEditable(false);
150
        this.getModel().setEditable(false);
197 151
        this.getJBtnChangeDate().setVisible(false);
198 152
    }
199 153

  
200 154
    public void requestFocus() {
201
        this.getDateField().requestFocus();
155
        this.getModel().requestFocus();
156
        this.fireValueChangedEvent();
202 157
    }
203 158

  
204 159
    public void setEnabled(boolean isEnabled) {
205
        this.pane.setEnabled(isEnabled);
160
        getModel().setEnabled(isEnabled);
206 161
    }
207 162

  
208
    public JFormattedTextField getTextField() {
209
        return ((DefaultEditor) this.getDateField().getEditor())
210
            .getTextField();
163
    public JComponent asJComponent() {
164
        return getModel();
211 165
    }
212 166

  
213
    public AbstractFormatter getFormat() {
214
        return getTextField().getFormatter();
167
    private JNullValueMuttableTextField getModel() {
168
        return dateFieldPanel;
215 169
    }
216 170

  
217
    public Object getValue() {
218
        String txt = getTextField().getText();
219
        if ((txt == null) || (txt.equals("")))
220
            return null;
221
        try {
222
			return getFormat().stringToValue(txt);
223
		} catch (ParseException e) {
224
			return null;
225
		}
171
    protected ImageIcon getBtnEmptyImageIcon() {
172
        String path = this.getClass().getResource(BTN_EMPTY_IMG_PATH).getPath();
173
        return new ImageIcon(path);
226 174
    }
227 175

  
228
    public JComponent asJComponent() {
229
        return pane;
230
    }
231

  
232 176
    public void actionPerformed(ActionEvent e) {
233 177
        JButton btn = (JButton) e.getSource();
234 178
        if (btn.getActionCommand().equals("BTN_OK")) {
235
            setValue(datePicker.getSelectedDate());
179
            if (dlg!=null){
180
                setValue(datePicker.getSelectedDate());       
181
            }
236 182
        }
237
        dlg.setVisible(false);
183
        if (dlg!=null) 
184
            dlg.setVisible(false);
185
        this.fireValueChangedEvent();
238 186
    }
239 187

  
240 188
    public void focusGained(FocusEvent e) {
241
        oldTxt = getTextField().getText();
189
        oldTxt = getValue();
242 190
        this.fireValueChangedEvent();
243 191
    }
244 192

  
245 193
    public void focusLost(FocusEvent e) {       
246
        String txt = getTextField().getText();
194
        Object txt = getValue();
247 195
        Date date = getDate();
248 196
        if (date == null) {
249 197
            if (!((txt==null)||(txt.equals(""))))
250
               getTextField().setText(oldTxt);
198
               setValue(oldTxt);
251 199
        }else{
252
            getTextField().setText(txt);
200
            setValue(txt);
253 201
            oldTxt = txt;
254 202
        }
255 203
        this.fireValueChangedEvent();
256 204
    }
257 205

  
206
//    public void stateChanged(ChangeEvent e) {
207
//       this.fireValueChangedEvent();
208
//    }
209

  
210
    public void handleValueChanged(JDynFieldComponent jDynFieldComponent) {
211
        this.fireValueChangedEvent();
212
    }
213

  
258 214
    @Override
215
    public Object getValue() {
216
        return this.getModel().getTextFieldValue();
217
    }
218
    
219
    @Override
259 220
    public boolean isValid() {
260 221
        Date date = getDate();
261 222
        if ((date==null)&&(this.getDynField().isMandatory()))
......
265 226
    }
266 227

  
267 228
    public void stateChanged(ChangeEvent e) {
268
       this.fireValueChangedEvent();
229
        this.fireValueChangedEvent();
269 230
    }
270 231
}
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/spinner/NullNumberEditor.java
34 34
package org.gvsig.tools.swing.serv.field.component.spinner;
35 35

  
36 36
import java.text.DecimalFormat;
37
import java.text.NumberFormat;
37 38

  
38 39
import javax.swing.JSpinner;
39 40
import javax.swing.SpinnerNumberModel;
......
86 87
    
87 88

  
88 89
    public DecimalFormat getFormat() {
89
        return this.model.getFormat();
90
        return (DecimalFormat) this.model.getFormat();
90 91
    }
91 92

  
92 93
	public SpinnerNumberModel getModel() {
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/spinner/DynFieldTextFieldFormatter.java
13 13
        this.formatter = formatter;
14 14
    }
15 15

  
16
//    private DateFormat getDateFormat() {
17
//        if (df == null) {
18
//            df = new DateFormatter(loc).getDynFieldDateFormatter(dynField);
19
//        }
20
//        return df;
21
//    }
22

  
23 16
    @Override
24 17
    public Object stringToValue(String text) throws ParseException {
25 18
        if ((text == null) || (text.equals("")))
......
30 23
    @Override
31 24
    public String valueToString(Object value) throws ParseException {
32 25
    	if ((value == null) || (value.equals("")))
33
            return null;
26
            return "";
34 27
        return formatter.format(value);
35 28
    }
36 29

  
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/spinner/DynFieldFormatter.java
2 2

  
3 3
import java.text.DateFormat;
4 4
import java.text.DecimalFormat;
5
import java.text.Format;
5 6
import java.text.NumberFormat;
6 7
import java.text.ParseException;
7 8
import java.text.SimpleDateFormat;
......
18 19

  
19 20
    private Locale loc;
20 21
    private int calendarField = Calendar.DAY_OF_MONTH;
21
    private DateFormat df;
22
    private SimpleDateFormat df;
22 23
	private DynField dynField;
23 24
	private boolean isDate = false;
24 25
	private boolean isNumber = false;
......
35 36
        refresh();
36 37
    }
37 38
    
39
    public Format toFormat(){
40
        if (isDate())
41
            return df;
42
        else if (isNumber()){
43
            return f;
44
        }
45
        return null;
46
    }
47
    
48
    private SimpleDateFormat toDateFormat(){
49
        return df;
50
    }
51
    
52
    public String toLocalizedPattern(){
53
        if (isDate()){
54
            return this.df.toLocalizedPattern();
55
        }else{
56
            return this.f.toLocalizedPattern();
57
        }
58
    }
59
    
38 60
    public class DateFormatter extends SimpleDateFormat{
39 61
    	
40 62
    	private DynFieldFormatter df;
......
72 94
	        	this.isDate = true;
73 95
	            this.calendarField = Calendar.MINUTE;
74 96
	            this.df =
75
	                DateFormat.getTimeInstance(DateFormat.MEDIUM, getLocale());
97
	                (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.MEDIUM, getLocale());
76 98
	            break;
77 99
	        case DataTypes.TIMESTAMP:
78 100
	        	this.isDate = true;
79 101
	            this.calendarField = Calendar.SECOND;
80
	            this.df = DateFormat.getTimeInstance(DateFormat.MEDIUM, getLocale());
102
	            this.df = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.MEDIUM, getLocale());
81 103
	            break;
82 104
	        case DataTypes.DATE:
83 105
	        	this.isDate = true;
84 106
	            this.calendarField = Calendar.DAY_OF_MONTH;
85 107
	            if (!getSubType().equals(DataTypes.SUBTYPE_DATE)){
86
	                this.df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, getLocale());
108
	                this.df = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, getLocale());
87 109
	            }else{
88
	                this.df = DateFormat.getDateInstance(DateFormat.LONG, getLocale());     
110
	                this.df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.LONG, getLocale());     
89 111
	            }
90 112
	            break;
91 113
	        case DataTypes.DOUBLE:
92 114
	        	isNumber = true;
93 115
	            f = (DecimalFormat) DecimalFormat.getNumberInstance(getLocale());
94 116
	            f.setMaximumFractionDigits(2);
117
                f.setMinimumFractionDigits(2);
95 118
	            break;
96 119
	        case DataTypes.FLOAT:
97 120
	        	isNumber = true;
98 121
	            f = (DecimalFormat) DecimalFormat.getNumberInstance(getLocale());
99 122
	            f.setMaximumFractionDigits(2);
123
                f.setMinimumFractionDigits(2);
100 124
	            break;
101 125
	        case DataTypes.LONG:
102 126
	        	isNumber = true;
103
	            f = (DecimalFormat) DecimalFormat.getIntegerInstance(getLocale());
127
	            f = (DecimalFormat) DecimalFormat.getNumberInstance(getLocale());
104 128
	            break;
105 129
	        case DataTypes.INT:
106 130
	        	isNumber = true;
......
114 138
	}
115 139

  
116 140
	/**
117
	 * @param obj
141
	 * @param value
118 142
	 * @return
119 143
	 */
120
	public String format(Object obj) {
121
		if ((obj==null)||(obj.equals("")))
122
			return null;
144
	public String format(Object value) {
145
	    System.out.println(value);
146
	    refresh();
147
		if ((value==null)||(value.equals("")))
148
			return "";
149
		
123 150
		if (isDate()){
124
			return this.df.format(obj);			
151
		    if (value instanceof Date)
152
		        return this.df.format(value);
153
		    else 
154
		        return "0";
155
		  
125 156
		}
126 157
		if (isNumber()){
127
			return this.f.format(obj);
158
		    if (value instanceof Number)
159
		        return this.f.format(value);
128 160
		}
129
		return null;
161
		return "";
130 162
	}
131 163
	
132 164
	/**
......
163 195
  
164 196
    public DateFormatter getDateFormatter() {
165 197
        if (this.df == null)
166
            this.df = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
198
            this.df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
167 199
        return new DateFormatter(this);
168 200
    }
169 201
    
170
    public DecimalFormat getNumberFormatter() {
202
    public NumberFormat getNumberFormatter() {
171 203
        if (this.f == null)
172 204
        	if (this.df==null)
173 205
        		this.f = (DecimalFormat) DecimalFormat.getNumberInstance(getLocale());
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/spinner/DynFieldEditor.java
1
package org.gvsig.tools.swing.serv.field.component.spinner;
2

  
3
import java.text.Format;
4
import java.text.ParseException;
5
import java.util.Date;
6
import java.util.Locale;
7

  
8
import javax.swing.AbstractSpinnerModel;
9
import javax.swing.JFormattedTextField;
10
import javax.swing.JSpinner;
11
import javax.swing.SpinnerDateModel;
12
import javax.swing.SpinnerModel;
13
import javax.swing.SpinnerNumberModel;
14
import javax.swing.JFormattedTextField.AbstractFormatter;
15
import javax.swing.event.ChangeEvent;
16
import javax.swing.text.DateFormatter;
17
import javax.swing.text.DefaultFormatterFactory;
18
import javax.swing.text.NumberFormatter;
19

  
20
import org.gvsig.tools.dataTypes.DataTypes;
21
import org.gvsig.tools.dynobject.DynField;
22

  
23

  
24
public class DynFieldEditor {
25

  
26
    private DynField dynField;
27
    private DynFieldFormatter formatter;
28
    private JSpinner spinner;
29
    private JFormattedTextField tf;
30

  
31
    public DynFieldEditor(DynField field, Locale locale) {
32
        this.dynField = field;
33
        this.formatter =
34
            DynFieldFormatter.getInstance(dynField, locale);
35
        this.spinner = createSpinner();
36
        this.spinner.setLocale(locale); 
37
        this.tf = ((JSpinner.DefaultEditor) this.spinner.getEditor()).getTextField();
38
  
39
        setDynFieldFormat();
40
        
41
//        this.spinner.validate();
42
           
43
//        setText(null);
44
    }
45
    
46
    private JSpinner createSpinner(){
47
        if (formatter.isDate()){
48
            SpinnerDateModel dateModel = new SpinnerDateModel();
49
            dateModel.setStart((Comparable) dynField.getMinValue());
50
            dateModel.setEnd((Comparable) dynField.getMaxValue());
51
            return new JSpinner(dateModel);
52
        }else if (formatter.isNumber()){
53
            SpinnerNumberModel numModel = new SpinnerNumberModel();
54
            numModel.setMinimum((Comparable) dynField.getMinValue());
55
            numModel.setMaximum((Comparable) dynField.getMaxValue());
56
            numModel.setStepSize(1);
57
            return new JSpinner(numModel);
58
        }
59
        return new JSpinner();
60
    }
61
    
62
    private void setDynFieldFormat(){
63
        DefaultFormatterFactory factory = (DefaultFormatterFactory) getTextField().getFormatterFactory();
64
        AbstractFormatter formatter = factory.getDefaultFormatter();
65

  
66
        if (this.formatter.isDate()){
67
            // Change the date format 
68
            ((DateFormatter) formatter).setFormat(this.formatter.toFormat());
69
            
70
        }else if (this.formatter.isNumber()){
71
            // Change the date format 
72
            ((NumberFormatter) formatter).setFormat(this.formatter.toFormat());
73
        }
74
    }
75
    
76
//    public void init(){
77
//         this.setFormatterFactory();
78
//  
79
//        this.getSpinner().setEditor(this);
80
//        getSpinner().setLocale(loc);
81
//        getSpinner().setModel(getModel());
82
//    }
83

  
84
    public DynFieldFormatter getFormat(){
85
        return this.formatter;
86
    }
87
    
88
//    private void setFormatterFactory() {
89
//        getTextField().setFormatterFactory(
90
//
91
//        new DynFieldFormatterFactory(getFormat()));
92
//    }
93
//
94
//    @Override
95
//    public void stateChanged(ChangeEvent e) {
96
//        JSpinner spinner = (JSpinner)(e.getSource());
97
//        Object value = model.getValue();
98
////        setText(model.getValue());
99
////        if (value!=null)
100
////            this.getModel().setValue(value);
101
//    }
102
//
103
//    public void setText(Object value) {
104
//        String txtValue = getFormat().format(value);
105
//        getTextField().setValue(txtValue);
106
//        getTextField().setText(txtValue);
107
//    }
108
//    
109
//    public Object getValue(){
110
//        String text = getTextField().getText();
111
//        try {
112
//            return formatter.parse(text);
113
//        } catch (ParseException e) {
114
//            return null;
115
//        }
116
//    }
117

  
118
    public Object getDefaultValue() {
119
        switch (this.dynField.getType()) {
120
        case DataTypes.DATE:
121
            return new Date();
122
        case DataTypes.TIME:
123
            return new Date();
124
        case DataTypes.TIMESTAMP:
125
            return new Date();
126
        case DataTypes.DOUBLE:
127
            return 0.0f;
128
        case DataTypes.FLOAT:
129
            return 0.0f;
130
        default:
131
            return 0;
132
        }
133
    }
134

  
135
    public JSpinner getSpinner() {
136
        return this.spinner;
137
    }
138

  
139
    public JFormattedTextField getTextField() {
140
        return this.tf;        
141
    }
142
}
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/spinner/NullSpinnerHandler.java
30 30
package org.gvsig.tools.swing.serv.field.component.spinner;
31 31

  
32 32
import java.text.DecimalFormat;
33
import java.text.NumberFormat;
33 34
import java.text.ParseException;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff