Revision 270
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.serv/org.gvsig.tools.swing.serv.jform/src/main/java/org/gvsig/tools/swing/serv/jform/StringJDynObjectComponent.java | ||
---|---|---|
51 | 51 |
* @author 2010- C?sar Ordi?ana - gvSIG team |
52 | 52 |
*/ |
53 | 53 |
public class StringJDynObjectComponent extends AbstractDynObjectComponent |
54 |
implements JDynObjectComponent {
|
|
54 |
implements JDynObjectComponent {
|
|
55 | 55 |
|
56 | 56 |
private static final long serialVersionUID = 5716325904557339463L; |
57 | 57 |
private JPanel panel; |
... | ... | |
61 | 61 |
* @see JDynObjectView#JDynObjectView(DynObject). |
62 | 62 |
*/ |
63 | 63 |
public StringJDynObjectComponent(DynObject dynObject, DynObjectModel model) |
64 |
throws ServiceException {
|
|
65 |
super(dynObject, model);
|
|
66 |
this.initUI();
|
|
64 |
throws ServiceException {
|
|
65 |
super(dynObject, model);
|
|
66 |
this.initUI();
|
|
67 | 67 |
} |
68 | 68 |
|
69 | 69 |
/* |
... | ... | |
74 | 74 |
* (org.gvsig.tools.swing.api.dynobject.ValueChangedListener) |
75 | 75 |
*/ |
76 | 76 |
public void addValueChangedListener(ValueChangedListener listener) { |
77 |
// TODO Auto-generated method stub
|
|
77 |
// TODO Auto-generated method stub
|
|
78 | 78 |
|
79 | 79 |
} |
80 | 80 |
|
... | ... | |
83 | 83 |
* |
84 | 84 |
* @see org.gvsig.tools.swing.api.dynobject.JComponent#getComponent() |
85 | 85 |
*/ |
86 |
public JComponent asJComponent() {
|
|
87 |
return panel;
|
|
86 |
public JComponent asJComponent() {
|
|
87 |
return panel;
|
|
88 | 88 |
} |
89 | 89 |
|
90 | 90 |
/* |
... | ... | |
96 | 96 |
*/ |
97 | 97 |
@Override |
98 | 98 |
public Object getValue() { |
99 |
// TODO Auto-generated method stub
|
|
100 |
return null;
|
|
99 |
// TODO Auto-generated method stub
|
|
100 |
return null;
|
|
101 | 101 |
} |
102 | 102 |
|
103 | 103 |
/* |
104 | 104 |
* (non-Javadoc) |
105 | 105 |
* |
106 | 106 |
* @see |
107 |
* |
|
107 | 108 |
* org.gvsig.tools.swing.api.dynobject.ValueChangedListener#handleValueChanged |
108 | 109 |
* (org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent) |
109 | 110 |
*/ |
110 | 111 |
public void handleValueChanged(JDynFieldComponent field) { |
111 |
// TODO Auto-generated method stub
|
|
112 |
// TODO Auto-generated method stub
|
|
112 | 113 |
|
113 | 114 |
} |
114 | 115 |
|
115 | 116 |
private void initUI() { |
116 |
panel = new JPanel(); |
|
117 |
panel.setLayout(new BorderLayout()); |
|
118 |
JLabel label = new JLabel("<html><pre>".concat( |
|
119 |
this.getDynObject().toString()).concat("</pre></html>")); |
|
120 |
panel.add(label, BorderLayout.CENTER); |
|
117 |
panel = new JPanel(); |
|
118 |
panel.setLayout(new BorderLayout()); |
|
119 |
JLabel label = |
|
120 |
new JLabel("<html><pre>".concat(this.getDynObject().toString()) |
|
121 |
.concat("</pre></html>")); |
|
122 |
panel.add(label, BorderLayout.CENTER); |
|
121 | 123 |
} |
122 | 124 |
|
123 | 125 |
/* |
124 | 126 |
* (non-Javadoc) |
125 | 127 |
* |
126 | 128 |
* @see |
129 |
* |
|
127 | 130 |
* org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#isMandatory |
128 | 131 |
* () |
129 | 132 |
*/ |
130 | 133 |
public boolean isMandatory() { |
131 |
// TODO Auto-generated method stub
|
|
132 |
return false;
|
|
134 |
// TODO Auto-generated method stub
|
|
135 |
return false;
|
|
133 | 136 |
} |
134 | 137 |
|
135 | 138 |
/* |
... | ... | |
141 | 144 |
*/ |
142 | 145 |
@Override |
143 | 146 |
protected boolean isValid(JDynFieldComponent component) { |
144 |
// TODO Auto-generated method stub
|
|
145 |
return false;
|
|
147 |
// TODO Auto-generated method stub
|
|
148 |
return false;
|
|
146 | 149 |
} |
147 | 150 |
|
148 | 151 |
/* |
... | ... | |
152 | 155 |
* org.gvsig.tools.swing.api.dynobject.JDynObjectComponent#requestFocus() |
153 | 156 |
*/ |
154 | 157 |
public void requestFocus() { |
155 |
// TODO Auto-generated method stub
|
|
158 |
// TODO Auto-generated method stub
|
|
156 | 159 |
|
157 | 160 |
} |
158 | 161 |
|
159 | 162 |
@Override |
160 | 163 |
public void saveStatus() { |
161 |
// Nothing to do, as this component is not able to edit the DynObject
|
|
162 |
// data.
|
|
164 |
// Nothing to do, as this component is not able to edit the DynObject
|
|
165 |
// data.
|
|
163 | 166 |
} |
164 | 167 |
|
165 | 168 |
/* |
... | ... | |
170 | 173 |
* (java.lang.Object) |
171 | 174 |
*/ |
172 | 175 |
public void setValue(Object value) { |
173 |
// TODO Auto-generated method stub
|
|
176 |
// TODO Auto-generated method stub
|
|
174 | 177 |
|
175 | 178 |
} |
176 |
} |
|
179 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.serv/org.gvsig.tools.swing.serv.jform/src/main/java/org/gvsig/tools/swing/serv/jform/ToolsSwingDefaultDynObjectImplLibrary.java | ||
---|---|---|
40 | 40 |
|
41 | 41 |
@Override |
42 | 42 |
protected void doPostInitialize() throws LibraryException { |
43 |
ServiceManager dsManager = ToolsSwingServiceLocator.getServiceManager();
|
|
43 |
ServiceManager dsManager = ToolsSwingServiceLocator.getServiceManager();
|
|
44 | 44 |
|
45 |
dsManager.addServiceFactory(new StringDynObjectComponentFactory());
|
|
46 |
// dsManager.addServiceFactory(new NumberFieldComponentFactory());
|
|
47 |
// dsManager.addServiceFactory(new NumberFieldComponentFactory());
|
|
48 |
// dsManager.addServiceFactory(new NumberFieldComponentFactory());
|
|
45 |
dsManager.addServiceFactory(new StringDynObjectComponentFactory());
|
|
46 |
// dsManager.addServiceFactory(new NumberFieldComponentFactory());
|
|
47 |
// dsManager.addServiceFactory(new NumberFieldComponentFactory());
|
|
48 |
// dsManager.addServiceFactory(new NumberFieldComponentFactory());
|
|
49 | 49 |
|
50 |
// .registerDynFieldComponentFactory(numberFactory, DataTypes.INT);
|
|
51 |
// dsManager.registerDynFieldComponentFactory(numberFactory,
|
|
52 |
// DataTypes.LONG);
|
|
53 |
// dsManager.registerDynFieldComponentFactory(numberFactory,
|
|
54 |
// DataTypes.FLOAT);
|
|
55 |
// dsManager.registerDynFieldComponentFactory(numberFactory,
|
|
56 |
// DataTypes.DOUBLE);
|
|
50 |
// .registerDynFieldComponentFactory(numberFactory, DataTypes.INT);
|
|
51 |
// dsManager.registerDynFieldComponentFactory(numberFactory,
|
|
52 |
// DataTypes.LONG);
|
|
53 |
// dsManager.registerDynFieldComponentFactory(numberFactory,
|
|
54 |
// DataTypes.FLOAT);
|
|
55 |
// dsManager.registerDynFieldComponentFactory(numberFactory,
|
|
56 |
// DataTypes.DOUBLE);
|
|
57 | 57 |
} |
58 |
} |
|
58 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.serv/org.gvsig.tools.swing.serv.jform/src/main/java/org/gvsig/tools/swing/serv/jform/StringDynObjectComponentFactory.java | ||
---|---|---|
46 | 46 |
* |
47 | 47 |
*/ |
48 | 48 |
public class StringDynObjectComponentFactory extends AbstractDynObjectFactory |
49 |
implements ServiceFactory, JDynObjectComponentFactory {
|
|
49 |
implements ServiceFactory, JDynObjectComponentFactory {
|
|
50 | 50 |
|
51 | 51 |
private static final String SERVICE_NAME = "form.string"; |
52 | 52 |
|
... | ... | |
60 | 60 |
* org.gvsig.tools.swing.api.dynobject.DynObjectComponentModel) |
61 | 61 |
*/ |
62 | 62 |
public JDynObjectComponent createJDynObjectComponent(DynObject dynObject, |
63 |
DynObjectModel model) throws ServiceException {
|
|
64 |
return new StringJDynObjectComponent(dynObject, model);
|
|
63 |
DynObjectModel model) throws ServiceException {
|
|
64 |
return new StringJDynObjectComponent(dynObject, model);
|
|
65 | 65 |
} |
66 | 66 |
|
67 | 67 |
/* |
... | ... | |
72 | 72 |
*/ |
73 | 73 |
@Override |
74 | 74 |
public String getFactoryDescription() { |
75 |
// TODO Auto-generated method stub
|
|
76 |
return null;
|
|
75 |
// TODO Auto-generated method stub
|
|
76 |
return null;
|
|
77 | 77 |
} |
78 | 78 |
|
79 | 79 |
/* |
... | ... | |
85 | 85 |
*/ |
86 | 86 |
@Override |
87 | 87 |
public String getFactoryName() { |
88 |
return SERVICE_NAME;
|
|
88 |
return SERVICE_NAME;
|
|
89 | 89 |
} |
90 | 90 |
|
91 | 91 |
/* |
... | ... | |
96 | 96 |
*/ |
97 | 97 |
@Override |
98 | 98 |
public String getFactorySubType() { |
99 |
// TODO Auto-generated method stub
|
|
100 |
return null;
|
|
99 |
// TODO Auto-generated method stub
|
|
100 |
return null;
|
|
101 | 101 |
} |
102 | 102 |
|
103 | 103 |
/* |
... | ... | |
108 | 108 |
*/ |
109 | 109 |
@Override |
110 | 110 |
public Integer getFactoryType() { |
111 |
// TODO Auto-generated method stub
|
|
112 |
return 0;
|
|
111 |
// TODO Auto-generated method stub
|
|
112 |
return 0;
|
|
113 | 113 |
} |
114 | 114 |
} |
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 | ||
---|---|---|
42 | 42 |
public class DefaultResultListenersHandler extends ArrayList<ResultListener> { |
43 | 43 |
|
44 | 44 |
public void fireResultEvent(int returnVal, Object returnValue) { |
45 |
for (ResultListener listener : this) {
|
|
46 |
listener.onResult(returnVal, returnValue);
|
|
47 |
}
|
|
45 |
for (ResultListener listener : this) {
|
|
46 |
listener.onResult(returnVal, returnValue);
|
|
47 |
}
|
|
48 | 48 |
} |
49 | 49 |
|
50 | 50 |
/** |
... | ... | |
53 | 53 |
* @param value |
54 | 54 |
*/ |
55 | 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 |
}
|
|
56 |
Object returnValue) {
|
|
57 |
for (ResultListener item : this) {
|
|
58 |
if (!item.equals(listener))
|
|
59 |
listener.onResult(returnVal, returnValue);
|
|
60 |
}
|
|
61 | 61 |
} |
62 | 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/components/file/JFileChooser.java | ||
---|---|---|
56 | 56 |
|
57 | 57 |
private class JFileFilter extends FileFilter { |
58 | 58 |
|
59 |
public JFileFilter(String[] extensions) {
|
|
60 |
this.seExtensiontList(extensions);
|
|
61 |
}
|
|
59 |
public JFileFilter(String[] extensions) {
|
|
60 |
this.seExtensiontList(extensions);
|
|
61 |
}
|
|
62 | 62 |
|
63 |
/*
|
|
64 |
* (non-Javadoc)
|
|
65 |
*
|
|
66 |
* @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
|
67 |
*/
|
|
68 |
@Override
|
|
69 |
public boolean accept(File f) {
|
|
70 |
// int type =fc.getFileSelectionMode();
|
|
71 |
//
|
|
72 |
// if ((type==DIRECTORIES_ONLY)||(type==FILES_AND_DIRECTORIES))
|
|
73 |
// if (f.isDirectory())
|
|
74 |
// return true;
|
|
75 |
if (f.isDirectory())
|
|
76 |
return true;
|
|
63 |
/*
|
|
64 |
* (non-Javadoc)
|
|
65 |
*
|
|
66 |
* @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
|
67 |
*/
|
|
68 |
@Override
|
|
69 |
public boolean accept(File f) {
|
|
70 |
// int type =fc.getFileSelectionMode();
|
|
71 |
//
|
|
72 |
// if ((type==DIRECTORIES_ONLY)||(type==FILES_AND_DIRECTORIES))
|
|
73 |
// if (f.isDirectory())
|
|
74 |
// return true;
|
|
75 |
if (f.isDirectory())
|
|
76 |
return true;
|
|
77 | 77 |
|
78 |
String extension = this.getExtension(f);
|
|
79 |
if ((extension != null) && (!extensions.isEmpty())) {
|
|
80 |
for (String ext : extensions)
|
|
81 |
if (extension.equals(ext))
|
|
82 |
return true;
|
|
83 |
}
|
|
84 |
return false;
|
|
85 |
}
|
|
78 |
String extension = this.getExtension(f);
|
|
79 |
if ((extension != null) && (!extensions.isEmpty())) {
|
|
80 |
for (String ext : extensions)
|
|
81 |
if (extension.equals(ext))
|
|
82 |
return true;
|
|
83 |
}
|
|
84 |
return false;
|
|
85 |
}
|
|
86 | 86 |
|
87 |
/*
|
|
88 |
* (non-Javadoc)
|
|
89 |
*
|
|
90 |
* @see javax.swing.filechooser.FileFilter#getDescription()
|
|
91 |
*/
|
|
92 |
@Override
|
|
93 |
public String getDescription() {
|
|
94 |
// TODO Auto-generated method stub
|
|
95 |
return null;
|
|
96 |
}
|
|
87 |
/*
|
|
88 |
* (non-Javadoc)
|
|
89 |
*
|
|
90 |
* @see javax.swing.filechooser.FileFilter#getDescription()
|
|
91 |
*/
|
|
92 |
@Override
|
|
93 |
public String getDescription() {
|
|
94 |
// TODO Auto-generated method stub
|
|
95 |
return null;
|
|
96 |
}
|
|
97 | 97 |
|
98 |
/*
|
|
99 |
* Get the extension of a file.
|
|
100 |
*/
|
|
101 |
private String getExtension(File f) {
|
|
102 |
String ext = null;
|
|
103 |
String s = f.getName();
|
|
104 |
int i = s.lastIndexOf('.');
|
|
98 |
/*
|
|
99 |
* Get the extension of a file.
|
|
100 |
*/
|
|
101 |
private String getExtension(File f) {
|
|
102 |
String ext = null;
|
|
103 |
String s = f.getName();
|
|
104 |
int i = s.lastIndexOf('.');
|
|
105 | 105 |
|
106 |
if ((i > 0) && (i < s.length() - 1)) {
|
|
107 |
ext = s.substring(i + 1).toLowerCase();
|
|
108 |
}
|
|
109 |
return ext;
|
|
110 |
}
|
|
106 |
if ((i > 0) && (i < s.length() - 1)) {
|
|
107 |
ext = s.substring(i + 1).toLowerCase();
|
|
108 |
}
|
|
109 |
return ext;
|
|
110 |
}
|
|
111 | 111 |
|
112 |
private void seExtensiontList(String[] extensions) {
|
|
113 |
if (extensions == null)
|
|
114 |
return;
|
|
115 |
for (String extension : extensions) {
|
|
116 |
JFileChooser.this.getExtensions().add(extension);
|
|
117 |
}
|
|
118 |
}
|
|
112 |
private void seExtensiontList(String[] extensions) {
|
|
113 |
if (extensions == null)
|
|
114 |
return;
|
|
115 |
for (String extension : extensions) {
|
|
116 |
JFileChooser.this.getExtensions().add(extension);
|
|
117 |
}
|
|
118 |
}
|
|
119 | 119 |
} |
120 | 120 |
|
121 |
public static final int DIRECTORIES_ONLY = javax.swing.JFileChooser.DIRECTORIES_ONLY; |
|
122 |
public static final int FILES_AND_DIRECTORIES = javax.swing.JFileChooser.FILES_AND_DIRECTORIES; |
|
121 |
public static final int DIRECTORIES_ONLY = |
|
122 |
javax.swing.JFileChooser.DIRECTORIES_ONLY; |
|
123 |
public static final int FILES_AND_DIRECTORIES = |
|
124 |
javax.swing.JFileChooser.FILES_AND_DIRECTORIES; |
|
123 | 125 |
|
124 | 126 |
private static final String ACCEPT_BUTTON = null; |
125 | 127 |
|
126 | 128 |
/** Returns an ImageIcon, or null if the path was invalid. */ |
127 | 129 |
protected static ImageIcon createImageIcon(String path) { |
128 |
java.net.URL imgURL = ToolsSwingDefaultFieldImplLibrary.class
|
|
129 |
.getResource(path);
|
|
130 |
if (imgURL != null) {
|
|
131 |
return new ImageIcon(imgURL);
|
|
132 |
} else {
|
|
133 |
System.err.println("Couldn't find file: " + path);
|
|
134 |
return null;
|
|
135 |
}
|
|
130 |
java.net.URL imgURL =
|
|
131 |
ToolsSwingDefaultFieldImplLibrary.class.getResource(path);
|
|
132 |
if (imgURL != null) {
|
|
133 |
return new ImageIcon(imgURL);
|
|
134 |
} else {
|
|
135 |
System.err.println("Couldn't find file: " + path);
|
|
136 |
return null;
|
|
137 |
}
|
|
136 | 138 |
} |
137 | 139 |
|
138 | 140 |
// Create a file chooser |
... | ... | |
144 | 146 |
private final DefaultResultListenersHandler listener; |
145 | 147 |
|
146 | 148 |
public JFileChooser(int type) { |
147 |
this(type, null);
|
|
149 |
this(type, null);
|
|
148 | 150 |
} |
149 | 151 |
|
150 | 152 |
public JFileChooser(int type, String[] extensionsFilter) { |
151 |
fc = new javax.swing.JFileChooser();
|
|
152 |
listener = new DefaultResultListenersHandler();
|
|
153 |
fc = new javax.swing.JFileChooser();
|
|
154 |
listener = new DefaultResultListenersHandler();
|
|
153 | 155 |
|
154 |
extensions = new ArrayList<String>();
|
|
155 |
// By default FILES_ONLY.
|
|
156 |
if (type == DataTypes.FOLDER)
|
|
157 |
fc.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
|
|
158 |
// else
|
|
159 |
// fc.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
|
|
156 |
extensions = new ArrayList<String>();
|
|
157 |
// By default FILES_ONLY.
|
|
158 |
if (type == DataTypes.FOLDER)
|
|
159 |
fc.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
|
|
160 |
// else
|
|
161 |
// fc.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
|
|
160 | 162 |
|
161 |
if (extensionsFilter != null)
|
|
162 |
fc.addChoosableFileFilter(new JFileFilter(extensionsFilter));
|
|
163 |
if (extensionsFilter != null)
|
|
164 |
fc.addChoosableFileFilter(new JFileFilter(extensionsFilter));
|
|
163 | 165 |
} |
164 | 166 |
|
165 | 167 |
public AddItem add(String extension) { |
166 |
if (extension != null)
|
|
167 |
extensions.add(extension);
|
|
168 |
return this;
|
|
168 |
if (extension != null)
|
|
169 |
extensions.add(extension);
|
|
170 |
return this;
|
|
169 | 171 |
} |
170 | 172 |
|
171 | 173 |
public void addResultListener(ResultListener listener) { |
172 |
this.listener.add(listener);
|
|
174 |
this.listener.add(listener);
|
|
173 | 175 |
} |
174 | 176 |
|
175 | 177 |
public void alignToField(ComponentService comp) { |
176 |
panel = (javax.swing.JComponent) comp.asJComponent();
|
|
177 |
// this.field = comp.getDynField();
|
|
178 |
panel = (javax.swing.JComponent) comp.asJComponent();
|
|
179 |
// this.field = comp.getDynField();
|
|
178 | 180 |
} |
179 | 181 |
|
180 | 182 |
/* |
... | ... | |
184 | 186 |
* java.lang.Object) |
185 | 187 |
*/ |
186 | 188 |
public void fireResultEvent(int resultVal, Object value) { |
187 |
listener.fireResultEvent(resultVal, value);
|
|
189 |
listener.fireResultEvent(resultVal, value);
|
|
188 | 190 |
} |
189 | 191 |
|
190 | 192 |
/** |
191 | 193 |
* @return |
192 | 194 |
*/ |
193 | 195 |
public List<String> getExtensions() { |
194 |
return extensions;
|
|
196 |
return extensions;
|
|
195 | 197 |
} |
196 | 198 |
|
197 | 199 |
/** |
198 | 200 |
* @return |
199 | 201 |
*/ |
200 | 202 |
private int getReturnVal(int returnVal) { |
201 |
switch (returnVal) {
|
|
202 |
case javax.swing.JFileChooser.APPROVE_OPTION:
|
|
203 |
return RETURN_OK;
|
|
204 |
case javax.swing.JFileChooser.CANCEL_OPTION:
|
|
205 |
return RETURN_CANCEL;
|
|
206 |
default:
|
|
207 |
return RETURN_ERROR;
|
|
208 |
}
|
|
203 |
switch (returnVal) {
|
|
204 |
case javax.swing.JFileChooser.APPROVE_OPTION:
|
|
205 |
return RETURN_OK;
|
|
206 |
case javax.swing.JFileChooser.CANCEL_OPTION:
|
|
207 |
return RETURN_CANCEL;
|
|
208 |
default:
|
|
209 |
return RETURN_ERROR;
|
|
210 |
}
|
|
209 | 211 |
} |
210 | 212 |
|
211 | 213 |
/** |
212 | 214 |
* @return |
213 | 215 |
*/ |
214 | 216 |
private Object getReturnValue() { |
215 |
if (fc != null)
|
|
216 |
return fc.getSelectedFile();
|
|
217 |
return null;
|
|
217 |
if (fc != null)
|
|
218 |
return fc.getSelectedFile();
|
|
219 |
return null;
|
|
218 | 220 |
} |
219 | 221 |
|
220 | 222 |
public void setApproveButtonText() { |
221 |
fc.setApproveButtonText(ACCEPT_BUTTON);
|
|
223 |
fc.setApproveButtonText(ACCEPT_BUTTON);
|
|
222 | 224 |
} |
223 | 225 |
|
224 | 226 |
public void showDialog() { |
225 |
int returnVal = fc.showOpenDialog(panel);
|
|
226 |
if (listener != null) {
|
|
227 |
this.fireResultEvent(this.getReturnVal(returnVal), this
|
|
228 |
.getReturnValue());
|
|
229 |
}
|
|
227 |
int returnVal = fc.showOpenDialog(panel);
|
|
228 |
if (listener != null) {
|
|
229 |
this.fireResultEvent(this.getReturnVal(returnVal), this
|
|
230 |
.getReturnValue());
|
|
231 |
}
|
|
230 | 232 |
} |
231 | 233 |
|
232 | 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/components/SpinnerNumberModel.java | ||
---|---|---|
1 | 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 |
*/ |
|
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 | 22 |
/* |
23 | 23 |
* AUTHORS (In addition to CIT): |
24 | 24 |
* 2010 Institute of New Imaging Technologies (INIT): |
... | ... | |
33 | 33 |
*/ |
34 | 34 |
package org.gvsig.tools.swing.components; |
35 | 35 |
|
36 |
|
|
37 | 36 |
import org.gvsig.tools.dynobject.DynField; |
38 | 37 |
|
39 | 38 |
/** |
40 | 39 |
* @author <a href="mailto:reinhold@uji.es">cmartin</a> |
41 |
* |
|
40 |
*
|
|
42 | 41 |
*/ |
43 |
public class SpinnerNumberModel extends javax.swing.SpinnerNumberModel{ |
|
44 |
|
|
42 |
public class SpinnerNumberModel extends javax.swing.SpinnerNumberModel {
|
|
43 |
|
|
45 | 44 |
private boolean valid; |
46 | 45 |
private boolean firstTime = true; |
47 | 46 |
|
48 |
private SpinnerNumberModel(DynField field){ |
|
49 |
super (0, (Comparable<?>) field |
|
50 |
.getMinValue(), (Comparable<?>) field.getMaxValue(), Integer |
|
51 |
.valueOf(1)); |
|
47 |
private SpinnerNumberModel(DynField field) { |
|
48 |
super(0, (Comparable<?>) field.getMinValue(), (Comparable<?>) field |
|
49 |
.getMaxValue(), Integer.valueOf(1)); |
|
52 | 50 |
} |
53 | 51 |
|
54 | 52 |
/** |
... | ... | |
56 | 54 |
* @param value |
57 | 55 |
*/ |
58 | 56 |
public SpinnerNumberModel(DynField field, Number value) { |
59 |
this(field);
|
|
60 |
setValue(value);
|
|
57 |
this(field);
|
|
58 |
setValue(value);
|
|
61 | 59 |
} |
62 | 60 |
|
63 |
/* (non-Javadoc) |
|
61 |
/* |
|
62 |
* (non-Javadoc) |
|
63 |
* |
|
64 | 64 |
* @see javax.swing.SpinnerNumberModel#getNumber() |
65 | 65 |
*/ |
66 | 66 |
@Override |
67 | 67 |
public Number getNumber() { |
68 |
// TODO Auto-generated method stub
|
|
69 |
return super.getNumber();
|
|
68 |
// TODO Auto-generated method stub
|
|
69 |
return super.getNumber();
|
|
70 | 70 |
} |
71 | 71 |
|
72 |
/* (non-Javadoc) |
|
72 |
/* |
|
73 |
* (non-Javadoc) |
|
74 |
* |
|
73 | 75 |
* @see javax.swing.SpinnerNumberModel#getValue() |
74 | 76 |
*/ |
75 | 77 |
@Override |
76 | 78 |
public Object getValue() { |
77 |
if (valid)
|
|
78 |
return super.getValue();
|
|
79 |
else
|
|
80 |
return null;
|
|
79 |
if (valid)
|
|
80 |
return super.getValue(); |
|
81 |
else |
|
82 |
return null; |
|
81 | 83 |
} |
82 | 84 |
|
83 |
/* (non-Javadoc) |
|
85 |
/* |
|
86 |
* (non-Javadoc) |
|
87 |
* |
|
84 | 88 |
* @see javax.swing.SpinnerNumberModel#setValue(java.lang.Object) |
85 | 89 |
*/ |
86 | 90 |
@Override |
87 | 91 |
public void setValue(Object value) { |
88 |
if (value != null) |
|
89 |
{ |
|
90 |
try |
|
91 |
{ |
|
92 |
valid=true; |
|
93 |
super.setValue(value); |
|
94 |
return; |
|
95 |
} |
|
96 |
catch (Exception e){} |
|
97 |
} |
|
98 |
valid = false; |
|
99 |
super.setValue(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); |
|
100 | 102 |
} |
101 |
|
|
103 |
|
|
102 | 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/spinner/NullDateEditor.java | ||
---|---|---|
1 | 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 |
*/ |
|
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 | 22 |
/* |
23 | 23 |
* AUTHORS (In addition to CIT): |
24 | 24 |
* 2010 Institute of New Imaging Technologies (INIT): |
... | ... | |
42 | 42 |
|
43 | 43 |
/** |
44 | 44 |
* @author <a href="mailto:reinhold@uji.es">cmartin</a> |
45 |
* |
|
45 |
*
|
|
46 | 46 |
*/ |
47 | 47 |
public class NullDateEditor extends JSpinner.DateEditor { |
48 | 48 |
|
49 |
private int dynType;
|
|
49 |
private int dynType;
|
|
50 | 50 |
|
51 |
/**
|
|
51 |
/**
|
|
52 | 52 |
* @param arg0 |
53 | 53 |
*/ |
54 |
public NullDateEditor(JSpinner spinner,int dynType) { |
|
55 |
super(spinner); |
|
56 |
this.setLocale(spinner.getLocale()); |
|
57 |
this.getTextField().setAlignmentX(JTextField.RIGHT_ALIGNMENT); |
|
58 |
this.getTextField().setAlignmentY(JTextField.CENTER_ALIGNMENT); |
|
59 |
this.getTextField().setFormatterFactory(new DateFormatterFactory(dynType, spinner.getLocale())); |
|
60 |
this.dynType = dynType; |
|
54 |
public NullDateEditor(JSpinner spinner, int dynType) { |
|
55 |
super(spinner); |
|
56 |
this.setLocale(spinner.getLocale()); |
|
57 |
this.getTextField().setAlignmentX(JTextField.RIGHT_ALIGNMENT); |
|
58 |
this.getTextField().setAlignmentY(JTextField.CENTER_ALIGNMENT); |
|
59 |
this.getTextField().setFormatterFactory( |
|
60 |
new DateFormatterFactory(dynType, spinner.getLocale())); |
|
61 |
this.dynType = dynType; |
|
61 | 62 |
} |
62 | 63 |
|
63 |
@Override
|
|
64 |
public SimpleDateFormat getFormat() {
|
|
65 |
DateFormatter formatter = new DateFormatter(getLocale());
|
|
66 |
formatter.setDynTypeFormatParametters(dynType);
|
|
67 |
return formatter;
|
|
68 |
}
|
|
64 |
@Override
|
|
65 |
public SimpleDateFormat getFormat() {
|
|
66 |
DateFormatter formatter = new DateFormatter(getLocale());
|
|
67 |
formatter.setDynTypeFormatParametters(dynType);
|
|
68 |
return formatter;
|
|
69 |
}
|
|
69 | 70 |
|
70 |
// private void setFormatPattern(int type, Locale loc) {
|
|
71 |
// // to do: locale settings
|
|
72 |
// String strPattern = null;
|
|
73 |
// switch (type){
|
|
74 |
// }
|
|
75 |
// }
|
|
71 |
// private void setFormatPattern(int type, Locale loc) {
|
|
72 |
// // to do: locale settings
|
|
73 |
// String strPattern = null;
|
|
74 |
// switch (type){
|
|
75 |
// }
|
|
76 |
// }
|
|
76 | 77 |
|
77 |
// public void stateChanged(ChangeEvent e) { |
|
78 |
// |
|
79 |
// Date date = (Date) ((DateSpinner) e.getSource()).getModel().getValue(); |
|
80 |
// String str = ""; |
|
81 |
// if (date != null) { |
|
82 |
// str = date.toString(); |
|
83 |
// } |
|
84 |
// if (!getTextField().getText().equals(str)){ |
|
85 |
// getTextField().setText(str); |
|
86 |
// super.stateChanged(e); |
|
87 |
// } |
|
88 |
// } |
|
89 |
|
|
90 |
// public void format(Date date){ |
|
91 |
// ((NullableDateSpinnerModel) this.getModel()).format(date); |
|
92 |
// } |
|
93 |
// |
|
94 |
// Object value = getSpinner().getValue(); |
|
95 |
// String text = ""; |
|
96 |
//// String text = "(Add a value)"; |
|
97 |
// if (value != null) { |
|
98 |
//// text = getFormat().format((Number) value); |
|
99 |
// super.stateChanged(e); |
|
100 |
// }else{ |
|
101 |
//// |
|
102 |
//// text = getFormat().format((Date) value); |
|
103 |
//// SpinnerModel model = getSpinner().getModel(); |
|
104 |
//// model.setValue(0); |
|
105 |
// getTextField().setText(text); |
|
106 |
// getTextField().repaint(); |
|
107 |
// } |
|
108 |
// } |
|
109 |
} |
|
78 |
// public void stateChanged(ChangeEvent e) { |
|
79 |
// |
|
80 |
// Date date = (Date) ((DateSpinner) e.getSource()).getModel().getValue(); |
|
81 |
// String str = ""; |
|
82 |
// if (date != null) { |
|
83 |
// str = date.toString(); |
|
84 |
// } |
|
85 |
// if (!getTextField().getText().equals(str)){ |
|
86 |
// getTextField().setText(str); |
|
87 |
// super.stateChanged(e); |
|
88 |
// } |
|
89 |
// } |
|
90 |
|
|
91 |
// public void format(Date date){ |
|
92 |
// ((NullableDateSpinnerModel) this.getModel()).format(date); |
|
93 |
// } |
|
94 |
// |
|
95 |
// Object value = getSpinner().getValue(); |
|
96 |
// String text = ""; |
|
97 |
// // String text = "(Add a value)"; |
|
98 |
// if (value != null) { |
|
99 |
// // text = getFormat().format((Number) value); |
|
100 |
// super.stateChanged(e); |
|
101 |
// }else{ |
|
102 |
// // |
|
103 |
// // text = getFormat().format((Date) value); |
|
104 |
// // SpinnerModel model = getSpinner().getModel(); |
|
105 |
// // model.setValue(0); |
|
106 |
// getTextField().setText(text); |
|
107 |
// getTextField().repaint(); |
|
108 |
// } |
|
109 |
// } |
|
110 |
} |
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/NullableNumberSpinnerModel.java | ||
---|---|---|
1 | 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 |
*/ |
|
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 | 22 |
/* |
23 | 23 |
* AUTHORS (In addition to CIT): |
24 | 24 |
* 2010 Institute of New Imaging Technologies (INIT): |
... | ... | |
42 | 42 |
|
43 | 43 |
/** |
44 | 44 |
* @author <a href="mailto:reinhold@uji.es">cmartin</a> |
45 |
* |
|
45 |
*
|
|
46 | 46 |
*/ |
47 |
public class NullableNumberSpinnerModel extends SpinnerNumberModel implements SpinnerModel{ |
|
48 |
|
|
47 |
public class NullableNumberSpinnerModel extends SpinnerNumberModel implements |
|
48 |
SpinnerModel { |
|
49 |
|
|
49 | 50 |
private DynField field; |
50 | 51 |
private Object number; |
51 | 52 |
private boolean isFirstTime; |
52 |
|
|
53 |
|
|
53 | 54 |
/** |
54 | 55 |
* @param field |
55 | 56 |
* @param value |
56 | 57 |
*/ |
57 | 58 |
public NullableNumberSpinnerModel(DynField field, Number value) { |
58 |
super(0, (Comparable<?>) field |
|
59 |
.getMinValue(), (Comparable<?>) field.getMaxValue(), Integer |
|
60 |
.valueOf(1)); |
|
61 |
this.field = field; |
|
62 |
this.isFirstTime = true; |
|
63 |
super.setValue(0); |
|
64 |
if (value!=null) |
|
65 |
setValue(value); |
|
59 |
super(0, (Comparable<?>) field.getMinValue(), (Comparable<?>) field |
|
60 |
.getMaxValue(), Integer.valueOf(1)); |
|
61 |
this.field = field; |
|
62 |
this.isFirstTime = true; |
|
63 |
super.setValue(0); |
|
64 |
if (value != null) |
|
65 |
setValue(value); |
|
66 | 66 |
} |
67 | 67 |
|
68 |
/* (non-Javadoc) |
|
68 |
/* |
|
69 |
* (non-Javadoc) |
|
70 |
* |
|
69 | 71 |
* @see javax.swing.SpinnerModel#getNextValue() |
70 | 72 |
*/ |
71 | 73 |
@Override |
72 | 74 |
public Object getNextValue() { |
73 |
if (!isNull()) {
|
|
74 |
this.number = super.getNextValue();
|
|
75 |
super.setValue(this.number);
|
|
76 |
return this.number;
|
|
77 |
}
|
|
78 |
super.setValue(0);
|
|
79 |
return 0;
|
|
75 |
if (!isNull()) {
|
|
76 |
this.number = super.getNextValue();
|
|
77 |
super.setValue(this.number);
|
|
78 |
return this.number;
|
|
79 |
}
|
|
80 |
super.setValue(0);
|
|
81 |
return 0;
|
|
80 | 82 |
} |
81 |
|
|
82 |
protected boolean isNull(){ |
|
83 |
Object value = getValue();
|
|
84 |
return ((value== null)||(value.equals("")));
|
|
83 |
|
|
84 |
protected boolean isNull() {
|
|
85 |
Object value = getValue();
|
|
86 |
return ((value == null) || (value.equals("")));
|
|
85 | 87 |
} |
86 | 88 |
|
87 |
/* (non-Javadoc) |
|
89 |
/* |
|
90 |
* (non-Javadoc) |
|
91 |
* |
|
88 | 92 |
* @see javax.swing.SpinnerModel#getPreviousValue() |
89 | 93 |
*/ |
90 | 94 |
@Override |
91 | 95 |
public Object getPreviousValue() { |
92 |
if (isNull()) return null; |
|
93 |
if (this.number.equals(this.getMinimum())){ |
|
94 |
// we are at the minimum value and we want to change to "undetermined" |
|
95 |
this.number = null; |
|
96 |
return ""; |
|
97 |
} |
|
98 |
return super.getPreviousValue(); |
|
96 |
if (isNull()) |
|
97 |
return null; |
|
98 |
if (this.number.equals(this.getMinimum())) { |
|
99 |
// we are at the minimum value and we want to change to |
|
100 |
// "undetermined" |
|
101 |
this.number = null; |
|
102 |
return ""; |
|
103 |
} |
|
104 |
return super.getPreviousValue(); |
|
99 | 105 |
} |
100 | 106 |
|
101 |
/* (non-Javadoc) |
|
107 |
/* |
|
108 |
* (non-Javadoc) |
|
109 |
* |
|
102 | 110 |
* @see javax.swing.SpinnerModel#getValue() |
103 | 111 |
*/ |
104 | 112 |
@Override |
105 | 113 |
public Object getValue() { |
106 |
if (this.isFirstTime){
|
|
107 |
return 0;
|
|
108 |
}
|
|
109 |
if (this.number == null)
|
|
110 |
return null;
|
|
111 |
return super.getValue();
|
|
112 |
|
|
114 |
if (this.isFirstTime) {
|
|
115 |
return 0;
|
|
116 |
}
|
|
117 |
if (this.number == null)
|
|
118 |
return null;
|
|
119 |
return super.getValue();
|
|
120 |
|
|
113 | 121 |
} |
114 | 122 |
|
115 |
/* (non-Javadoc) |
|
123 |
/* |
|
124 |
* (non-Javadoc) |
|
125 |
* |
|
116 | 126 |
* @see javax.swing.SpinnerModel#setValue(java.lang.Object) |
117 | 127 |
*/ |
118 | 128 |
@Override |
119 | 129 |
public void setValue(Object value) { |
120 |
this.number = value;
|
|
121 |
this.isFirstTime = false;
|
|
122 |
if (!isNull())
|
|
123 |
super.setValue(value);
|
|
124 |
else
|
|
125 |
this.fireStateChanged();
|
|
130 |
this.number = value;
|
|
131 |
this.isFirstTime = false;
|
|
132 |
if (!isNull())
|
|
133 |
super.setValue(value);
|
|
134 |
else
|
|
135 |
this.fireStateChanged();
|
|
126 | 136 |
} |
127 | 137 |
} |
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/DateFormatterFactory.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
public class DateFormatterFactory extends AbstractFormatterFactory { |
12 | 12 |
|
13 |
private int dynType;
|
|
14 |
private Locale loc;
|
|
13 |
private int dynType;
|
|
14 |
private Locale loc;
|
|
15 | 15 |
|
16 |
public DateFormatterFactory (int dynType, Locale loc){ |
|
17 |
this.dynType = dynType; |
|
18 |
this.loc = loc; |
|
19 |
} |
|
20 |
|
|
21 |
@Override |
|
22 |
public AbstractFormatter getFormatter(JFormattedTextField tf) { |
|
23 |
return new DateTextFieldFormatter(dynType, loc); |
|
24 |
} |
|
16 |
public DateFormatterFactory(int dynType, Locale loc) { |
|
17 |
this.dynType = dynType; |
|
18 |
this.loc = loc; |
|
19 |
} |
|
25 | 20 |
|
21 |
@Override |
|
22 |
public AbstractFormatter getFormatter(JFormattedTextField tf) { |
|
23 |
return new DateTextFieldFormatter(dynType, loc); |
|
24 |
} |
|
25 |
|
|
26 | 26 |
} |
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/DateTextFieldFormatter.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
public class DateTextFieldFormatter extends AbstractFormatter { |
12 | 12 |
|
13 |
private DateFormat df;
|
|
14 |
private int dynType;
|
|
15 |
private Locale loc;
|
|
13 |
private DateFormat df;
|
|
14 |
private int dynType;
|
|
15 |
private Locale loc;
|
|
16 | 16 |
|
17 |
public DateTextFieldFormatter(int dynType, Locale loc) { |
|
18 |
super(); |
|
19 |
this.dynType = dynType; |
|
20 |
this.loc = loc; |
|
21 |
} |
|
22 |
private DateFormat getDateFormat(){ |
|
23 |
if (df==null){ |
|
24 |
df = new DateFormatter(loc).getDynFieldDateFormatter(dynType); |
|
25 |
} |
|
26 |
return df; |
|
27 |
} |
|
17 |
public DateTextFieldFormatter(int dynType, Locale loc) { |
|
18 |
super(); |
|
19 |
this.dynType = dynType; |
|
20 |
this.loc = loc; |
|
21 |
} |
|
28 | 22 |
|
29 |
@Override
|
|
30 |
public Object stringToValue(String text) throws ParseException {
|
|
31 |
if ((text==null)||(text.equals("")))
|
|
32 |
return null;
|
|
33 |
return getDateFormat().parse(text);
|
|
34 |
}
|
|
23 |
private DateFormat getDateFormat() {
|
|
24 |
if (df == null) {
|
|
25 |
df = new DateFormatter(loc).getDynFieldDateFormatter(dynType);
|
|
26 |
}
|
|
27 |
return df;
|
|
28 |
}
|
|
35 | 29 |
|
36 |
@Override
|
|
37 |
public String valueToString(Object value) throws ParseException {
|
|
38 |
if (value == null)
|
|
39 |
return "";
|
|
40 |
return getDateFormat().format(value);
|
|
41 |
}
|
|
30 |
@Override
|
|
31 |
public Object stringToValue(String text) throws ParseException {
|
|
32 |
if ((text == null) || (text.equals("")))
|
|
33 |
return null;
|
|
34 |
return getDateFormat().parse(text);
|
|
35 |
}
|
|
42 | 36 |
|
37 |
@Override |
|
38 |
public String valueToString(Object value) throws ParseException { |
|
39 |
if (value == null) |
|
40 |
return ""; |
|
41 |
return getDateFormat().format(value); |
|
42 |
} |
|
43 |
|
|
43 | 44 |
} |
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 | ||
---|---|---|
1 | 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 |
*/ |
|
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 | 22 |
/* |
23 | 23 |
* AUTHORS (In addition to CIT): |
24 | 24 |
* 2010 Institute of New Imaging Technologies (INIT): |
... | ... | |
41 | 41 |
|
42 | 42 |
/** |
43 | 43 |
* @author <a href="mailto:reinhold@uji.es">cmartin</a> |
44 |
* |
|
44 |
*
|
|
45 | 45 |
*/ |
46 | 46 |
public class NullNumberEditor extends JSpinner.NumberEditor { |
47 |
|
|
47 | 48 |
/** |
48 | 49 |
* @param arg0 |
49 | 50 |
*/ |
50 | 51 |
public NullNumberEditor(JSpinner spinner) { |
51 |
super(spinner);
|
|
52 |
super(spinner);
|
|
52 | 53 |
} |
53 | 54 |
|
54 | 55 |
/** |
... | ... | |
56 | 57 |
* @param arg1 |
57 | 58 |
*/ |
58 | 59 |
public NullNumberEditor(JSpinner spinner, String dateFormatPattern) { |
59 |
super(spinner, dateFormatPattern);
|
|
60 |
super(spinner, dateFormatPattern);
|
|
60 | 61 |
} |
61 | 62 |
|
62 | 63 |
public void stateChanged(ChangeEvent e) { |
63 |
// super.stateChanged(e);
|
|
64 |
Object value = getSpinner().getValue();
|
|
65 |
String text = "";
|
|
66 |
// String text = "(Add a value)";
|
|
67 |
if (value != null) {
|
|
68 |
// text = getFormat().format((Number) value);
|
|
69 |
super.stateChanged(e);
|
|
70 |
}else{
|
|
71 |
SpinnerModel model = getSpinner().getModel();
|
|
72 |
model.setValue(0);
|
|
73 |
getTextField().setText(text);
|
|
74 |
getTextField().repaint();
|
|
75 |
}
|
|
64 |
// super.stateChanged(e);
|
|
65 |
Object value = getSpinner().getValue();
|
|
66 |
String text = "";
|
|
67 |
// String text = "(Add a value)";
|
|
68 |
if (value != null) {
|
|
69 |
// text = getFormat().format((Number) value);
|
|
70 |
super.stateChanged(e);
|
|
71 |
} else {
|
|
72 |
SpinnerModel model = getSpinner().getModel();
|
|
73 |
model.setValue(0);
|
|
74 |
getTextField().setText(text);
|
|
75 |
getTextField().repaint();
|
|
76 |
}
|
|
76 | 77 |
} |
77 |
} |
|
78 |
} |
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/NullableDateSpinnerModel.java | ||
---|---|---|
1 | 1 |
package org.gvsig.tools.swing.serv.field.component.spinner; |
2 | 2 |
|
3 | 3 |
/* |
4 |
* @(#)SpinnerDateModel.java 1.11 04/05/12 |
|
5 |
* |
|
6 |
* Copyright 2004 Sun Microsystems, Inc. All rights reserved. |
|
7 |
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. |
|
8 |
*/ |
|
4 |
* @(#)SpinnerDateModel.java 1.11 04/05/12
|
|
5 |
*
|
|
6 |
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
|
|
7 |
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
|
8 |
*/
|
|
9 | 9 |
|
10 |
|
|
11 | 10 |
import java.text.DateFormat; |
12 | 11 |
import java.text.ParseException; |
13 | 12 |
import java.util.*; |
... | ... | |
19 | 18 |
import org.gvsig.tools.dataTypes.DataTypes; |
20 | 19 |
import org.gvsig.tools.swing.serv.field.component.date.DateFormatter; |
21 | 20 |
|
22 |
|
|
23 | 21 |
/** |
24 |
* A <code>SpinnerModel</code> for sequences of <code>Date</code>s. |
|
25 |
* The upper and lower bounds of the sequence are defined by properties called |
|
26 |
* <code>start</code> and <code>end</code> and the size |
|
27 |
* of the increase or decrease computed by the <code>nextValue</code> |
|
28 |
* and <code>previousValue</code> methods is defined by a property |
|
29 |
* called <code>calendarField</code>. The <code>start</code> |
|
30 |
* and <code>end</code> properties can be <code>null</code> to |
|
31 |
* indicate that the sequence has no lower or upper limit. |
|
32 |
* <p> |
|
33 |
* The value of the <code>calendarField</code> property must be one of the |
|
34 |
* <code>java.util.Calendar</code> constants that specify a field |
|
35 |
* within a <code>Calendar</code>. The <code>getNextValue</code> |
|
36 |
* and <code>getPreviousValue</code> |
|
37 |
* methods change the date forward or backwards by this amount. |
|
38 |
* For example, if <code>calendarField</code> is <code>Calendar.DAY_OF_WEEK</code>, |
|
39 |
* then <code>nextValue</code> produces a <code>Date</code> that's 24 |
|
40 |
* hours after the current <code>value</code>, and <code>previousValue</code> |
|
41 |
* produces a <code>Date</code> that's 24 hours earlier. |
|
42 |
* <p> |
|
43 |
* The legal values for <code>calendarField</code> are: |
|
44 |
* <ul> |
|
45 |
* <li><code>Calendar.ERA</code> |
|
46 |
* <li><code>Calendar.YEAR</code> |
|
47 |
* <li><code>Calendar.MONTH</code> |
|
48 |
* <li><code>Calendar.WEEK_OF_YEAR</code> |
|
49 |
* <li><code>Calendar.WEEK_OF_MONTH</code> |
|
50 |
* <li><code>Calendar.DAY_OF_MONTH</code> |
|
51 |
* <li><code>Calendar.DAY_OF_YEAR</code> |
|
52 |
* <li><code>Calendar.DAY_OF_WEEK</code> |
|
53 |
* <li><code>Calendar.DAY_OF_WEEK_IN_MONTH</code> |
|
54 |
* <li><code>Calendar.AM_PM</code> |
|
55 |
* <li><code>Calendar.HOUR</code> |
|
56 |
* <li><code>Calendar.HOUR_OF_DAY</code> |
|
57 |
* <li><code>Calendar.MINUTE</code> |
|
58 |
* <li><code>Calendar.SECOND</code> |
|
59 |
* <li><code>Calendar.MILLISECOND</code> |
|
60 |
* </ul> |
|
61 |
* However some UIs may set the calendarField before commiting the edit |
|
62 |
* to spin the field under the cursor. If you only want one field to |
|
63 |
* spin you can subclass and ignore the setCalendarField calls. |
|
64 |
* <p> |
|
65 |
* This model inherits a <code>ChangeListener</code>. The |
|
66 |
* <code>ChangeListeners</code> are notified whenever the models |
|
67 |
* <code>value</code>, <code>calendarField</code>, |
|
68 |
* <code>start</code>, or <code>end</code> properties changes. |
|
69 |
* |
|
70 |
* @see JSpinner |
|
71 |
* @see SpinnerModel |
|
72 |
* @see AbstractSpinnerModel |
|
73 |
* @see SpinnerListModel |
|
74 |
* @see SpinnerNumberModel |
|
75 |
* @see Calendar#add |
|
76 |
* |
|
77 |
* @version 1.11 05/12/04 |
|
78 |
* @author Hans Muller |
|
79 |
* @since 1.4 |
|
80 |
*/ |
|
81 |
public class NullableDateSpinnerModel extends SpinnerDateModel implements Serializable |
|
82 |
{ |
|
83 |
private Comparable start, end; |
|
84 |
private DateFormatter formatter; |
|
85 |
private Date iniDate; |
|
86 |
private Date curValue; |
|
22 |
* A <code>SpinnerModel</code> for sequences of <code>Date</code>s. |
|
23 |
* The upper and lower bounds of the sequence are defined by properties called |
|
24 |
* <code>start</code> and <code>end</code> and the size |
|
25 |
* of the increase or decrease computed by the <code>nextValue</code> and |
|
26 |
* <code>previousValue</code> methods is defined by a property |
|
27 |
* called <code>calendarField</code>. The <code>start</code> and |
|
28 |
* <code>end</code> properties can be <code>null</code> to |
|
29 |
* indicate that the sequence has no lower or upper limit. |
|
30 |
* <p> |
|
31 |
* The value of the <code>calendarField</code> property must be one of the |
|
32 |
* <code>java.util.Calendar</code> constants that specify a field within a |
|
33 |
* <code>Calendar</code>. The <code>getNextValue</code> and |
|
34 |
* <code>getPreviousValue</code> methods change the date forward or backwards by |
|
35 |
* this amount. For example, if <code>calendarField</code> is |
|
36 |
* <code>Calendar.DAY_OF_WEEK</code>, then <code>nextValue</code> produces a |
|
37 |
* <code>Date</code> that's 24 hours after the current <code>value</code>, and |
|
38 |
* <code>previousValue</code> produces a <code>Date</code> that's 24 hours |
|
39 |
* earlier. |
|
40 |
* <p> |
|
41 |
* The legal values for <code>calendarField</code> are: |
|
42 |
* <ul> |
|
43 |
* <li><code>Calendar.ERA</code> |
|
44 |
* <li><code>Calendar.YEAR</code> |
|
45 |
* <li><code>Calendar.MONTH</code> |
|
46 |
* <li><code>Calendar.WEEK_OF_YEAR</code> |
|
47 |
* <li><code>Calendar.WEEK_OF_MONTH</code> |
|
48 |
* <li><code>Calendar.DAY_OF_MONTH</code> |
|
49 |
* <li><code>Calendar.DAY_OF_YEAR</code> |
|
50 |
* <li><code>Calendar.DAY_OF_WEEK</code> |
|
51 |
* <li><code>Calendar.DAY_OF_WEEK_IN_MONTH</code> |
|
52 |
* <li><code>Calendar.AM_PM</code> |
|
53 |
* <li><code>Calendar.HOUR</code> |
|
54 |
* <li><code>Calendar.HOUR_OF_DAY</code> |
|
55 |
* <li><code>Calendar.MINUTE</code> |
|
56 |
* <li><code>Calendar.SECOND</code> |
|
57 |
* <li><code>Calendar.MILLISECOND</code> |
|
58 |
* </ul> |
|
59 |
* However some UIs may set the calendarField before commiting the edit to spin |
|
60 |
* the field under the cursor. If you only want one field to spin you can |
|
61 |
* subclass and ignore the setCalendarField calls. |
|
62 |
* <p> |
|
63 |
* This model inherits a <code>ChangeListener</code>. The |
|
64 |
* <code>ChangeListeners</code> are notified whenever the models |
|
65 |
* <code>value</code>, <code>calendarField</code>, <code>start</code>, or |
|
66 |
* <code>end</code> properties changes. |
|
67 |
* |
|
68 |
* @see JSpinner |
|
69 |
* @see SpinnerModel |
|
70 |
* @see AbstractSpinnerModel |
|
71 |
* @see SpinnerListModel |
|
72 |
* @see SpinnerNumberModel |
|
73 |
* @see Calendar#add |
|
74 |
* |
|
75 |
* @version 1.11 05/12/04 |
|
76 |
* @author Hans Muller |
|
77 |
* @since 1.4 |
|
78 |
*/ |
|
79 |
public class NullableDateSpinnerModel extends SpinnerDateModel implements |
|
80 |
Serializable { |
|
87 | 81 |
|
82 |
private Comparable start, end; |
|
83 |
private DateFormatter formatter; |
|
84 |
private Date iniDate; |
|
85 |
private Date curValue; |
|
88 | 86 |
|
89 |
private boolean calendarFieldOK(int calendarField) { |
|
90 |
switch(calendarField) { |
|
91 |
case Calendar.ERA: |
|
92 |
case Calendar.YEAR: |
|
93 |
case Calendar.MONTH: |
|
94 |
case Calendar.WEEK_OF_YEAR: |
|
95 |
case Calendar.WEEK_OF_MONTH: |
|
96 |
case Calendar.DAY_OF_MONTH: |
|
97 |
case Calendar.DAY_OF_YEAR: |
|
98 |
case Calendar.DAY_OF_WEEK: |
|
99 |
case Calendar.DAY_OF_WEEK_IN_MONTH: |
|
100 |
case Calendar.AM_PM: |
|
101 |
case Calendar.HOUR: |
|
102 |
case Calendar.HOUR_OF_DAY: |
|
103 |
case Calendar.MINUTE: |
|
104 |
case Calendar.SECOND: |
|
105 |
case Calendar.MILLISECOND: |
|
106 |
return true; |
|
107 |
default: |
|
108 |
return false; |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
87 |
private boolean calendarFieldOK(int calendarField) { |
|
88 |
switch (calendarField) { |
|
89 |
case Calendar.ERA: |
|
90 |
case Calendar.YEAR: |
|
91 |
case Calendar.MONTH: |
|
92 |
case Calendar.WEEK_OF_YEAR: |
|
93 |
case Calendar.WEEK_OF_MONTH: |
|
94 |
case Calendar.DAY_OF_MONTH: |
|
95 |
case Calendar.DAY_OF_YEAR: |
|
96 |
case Calendar.DAY_OF_WEEK: |
|
97 |
case Calendar.DAY_OF_WEEK_IN_MONTH: |
|
98 |
case Calendar.AM_PM: |
|
99 |
case Calendar.HOUR: |
|
100 |
case Calendar.HOUR_OF_DAY: |
|
101 |
case Calendar.MINUTE: |
|
102 |
case Calendar.SECOND: |
|
103 |
case Calendar.MILLISECOND: |
|
104 |
return true; |
|
105 |
default: |
|
106 |
return false; |
|
107 |
} |
|
108 |
} |
|
112 | 109 |
|
113 |
/** |
|
114 |
* Creates a <code>SpinnerDateModel</code> that represents a sequence of dates |
|
115 |
* between <code>start</code> and <code>end</code>. The |
|
116 |
* <code>nextValue</code> and <code>previousValue</code> methods |
|
117 |
* compute elements of the sequence by advancing or reversing |
|
118 |
* the current date <code>value</code> by the |
|
119 |
* <code>calendarField</code> time unit. For a precise description |
|
120 |
* of what it means to increment or decrement a <code>Calendar</code> |
|
121 |
* <code>field</code>, see the <code>add</code> method in |
|
122 |
* <code>java.util.Calendar</code>. |
|
123 |
* <p> |
|
124 |
* The <code>start</code> and <code>end</code> parameters can be |
|
125 |
* <code>null</code> to indicate that the range doesn't have an |
|
126 |
* upper or lower bound. If <code>value</code> or |
|
127 |
* <code>calendarField</code> is <code>null</code>, or if both |
|
128 |
* <code>start</code> and <code>end</code> are specified and |
|
129 |
* <code>mininum > maximum</code> then an |
Also available in: Unified diff