gvsig-tools / 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 @ 477
History | View | Annotate | Download (5.66 KB)
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 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2010 {} {{Task}}
|
26 |
*/
|
27 |
package org.gvsig.tools.swing.serv.field.component; |
28 |
|
29 |
import java.util.Locale; |
30 |
|
31 |
import javax.swing.ImageIcon; |
32 |
import javax.swing.JComponent; |
33 |
|
34 |
import org.gvsig.tools.dynobject.DynObject; |
35 |
import org.gvsig.tools.service.ServiceException; |
36 |
import org.gvsig.tools.swing.api.dynobject.ValueChangedListener; |
37 |
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent; |
38 |
import org.gvsig.tools.swing.api.dynobject.dynfield.ValueField; |
39 |
import org.gvsig.tools.swing.spi.AbstractJDynFieldComponent; |
40 |
|
41 |
/**
|
42 |
* Component for numeric {@link DynObject} fields.
|
43 |
*
|
44 |
* @author 2010- C?sar Ordi?ana - gvSIG team
|
45 |
*/
|
46 |
public class JNumberDynFieldComponent extends AbstractJDynFieldComponent |
47 |
implements JDynFieldComponent, ValueChangedListener {
|
48 |
|
49 |
private static final long serialVersionUID = -8120715001446683582L; |
50 |
|
51 |
private static Object NULL_VALUE = null; |
52 |
private static final String BTN_EMPTY_IMG_PATH = "editdelete.png"; |
53 |
|
54 |
private JNullValueMuttableTextField pane;
|
55 |
|
56 |
/**
|
57 |
* @param parent
|
58 |
* @throws ServiceException
|
59 |
* @see JDynFieldComponent#JDynFieldComponent(DynField, DynObject).
|
60 |
*/
|
61 |
public JNumberDynFieldComponent(ValueField parent)
|
62 |
throws ServiceException {
|
63 |
super(parent);
|
64 |
} |
65 |
|
66 |
/*
|
67 |
* (non-Javadoc)
|
68 |
*
|
69 |
* @see org.gvsig.tools.swing.spi.AbstractJDynFieldComponent#afterUI()
|
70 |
*/
|
71 |
@Override
|
72 |
protected void afterUI() { |
73 |
|
74 |
} |
75 |
|
76 |
/*
|
77 |
* (non-Javadoc)
|
78 |
*
|
79 |
* @see org.gvsig.tools.swing.api.dynobject.JComponent#getComponent()
|
80 |
*/
|
81 |
public JComponent asJComponent() { |
82 |
return this.getModel(); |
83 |
} |
84 |
|
85 |
protected ImageIcon getBtnEmptyImageIcon() { |
86 |
return new ImageIcon(this.getClass().getResource(BTN_EMPTY_IMG_PATH)); |
87 |
} |
88 |
|
89 |
private JNullValueMuttableTextField getModel() {
|
90 |
return this.pane; |
91 |
} |
92 |
|
93 |
/*
|
94 |
* (non-Javadoc)
|
95 |
*
|
96 |
* @see
|
97 |
* org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#getValue
|
98 |
* ()
|
99 |
*/
|
100 |
@Override
|
101 |
public Object getValue() { |
102 |
return getModel().getTextFieldValue();
|
103 |
} |
104 |
|
105 |
public void handleValueChanged(JDynFieldComponent field) { |
106 |
this.fireValueChangedEvent();
|
107 |
} |
108 |
|
109 |
/*
|
110 |
* (non-Javadoc)
|
111 |
*
|
112 |
* @see org.gvsig.tools.swing.spi.AbstractJDynFieldComponent#initData()
|
113 |
*/
|
114 |
@Override
|
115 |
protected void initData() { |
116 |
} |
117 |
|
118 |
/**
|
119 |
* Creates the component ui.
|
120 |
*/
|
121 |
@Override
|
122 |
protected void initUI() { |
123 |
this.pane =
|
124 |
new JNullValueMuttableTextField(this.getDynField(), this |
125 |
.getInitialValue(), Locale.getDefault(), getBtnEmptyImageIcon());
|
126 |
this.pane.addValueChangedListener(this); |
127 |
} |
128 |
|
129 |
@Override
|
130 |
public boolean isValid() { |
131 |
Number num = (Number) getValue(); |
132 |
if ((num == null) && (this.getDynField().isMandatory())) { |
133 |
return false; |
134 |
} |
135 |
return true; |
136 |
} |
137 |
|
138 |
/*
|
139 |
* (non-Javadoc)
|
140 |
*
|
141 |
* @see
|
142 |
*
|
143 |
*
|
144 |
*
|
145 |
*
|
146 |
* org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#requestFocus
|
147 |
* ()
|
148 |
*/
|
149 |
public void requestFocus() { |
150 |
getModel().requestFocus(); |
151 |
this.fireValueChangedEvent();
|
152 |
} |
153 |
|
154 |
@Override
|
155 |
public void saveStatus() { |
156 |
if (getModel() != null) { |
157 |
this.setFieldValue(getModel().getValue());
|
158 |
} |
159 |
} |
160 |
|
161 |
/*
|
162 |
* (non-Javadoc)
|
163 |
*
|
164 |
* @see
|
165 |
*
|
166 |
*
|
167 |
*
|
168 |
*
|
169 |
* org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#setEnabled
|
170 |
* (boolean)
|
171 |
*/
|
172 |
public void setEnabled(boolean isEnabled) { |
173 |
getModel().setEnabled(true);
|
174 |
} |
175 |
|
176 |
/*
|
177 |
* (non-Javadoc)
|
178 |
*
|
179 |
* @seeorg.gvsig.tools.swing.spi.AbstractJDynFieldComponent#
|
180 |
* setJDynFieldComponentListeners()
|
181 |
*/
|
182 |
@Override
|
183 |
protected void setJDynFieldComponentListeners() { |
184 |
// getModel().addEmptyButtonActionListener(this);
|
185 |
} |
186 |
|
187 |
@Override
|
188 |
protected void setNonNullValue(Object value) { |
189 |
getModel().setValue(value); |
190 |
} |
191 |
|
192 |
// /*
|
193 |
// * (non-Javadoc)
|
194 |
// *
|
195 |
// * @see
|
196 |
// *
|
197 |
// *
|
198 |
// *
|
199 |
// javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent
|
200 |
// * )
|
201 |
// */
|
202 |
// public void stateChanged(ChangeEvent e) {
|
203 |
// this.fireValueChangedEvent();
|
204 |
// }
|
205 |
|
206 |
// public void actionPerformed(ActionEvent e) {
|
207 |
// this.fireValueChangedEvent();
|
208 |
// }
|
209 |
|
210 |
/*
|
211 |
* (non-Javadoc)
|
212 |
*
|
213 |
* @see
|
214 |
* org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#setValue
|
215 |
* (java.lang.Object)
|
216 |
*/
|
217 |
@Override
|
218 |
protected void setNullValue() { |
219 |
getModel().setValue(NULL_VALUE); |
220 |
} |
221 |
|
222 |
/*
|
223 |
* (non-Javadoc)
|
224 |
*
|
225 |
* @see org.gvsig.tools.swing.spi.AbstractJDynFieldComponent#setReadOnly()
|
226 |
*/
|
227 |
@Override
|
228 |
protected void setReadOnly() { |
229 |
// do nothing
|
230 |
} |
231 |
} |