svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / tools / persistence / text / JavaTextFactory.java @ 274
History | View | Annotate | Download (2.44 KB)
1 |
package org.gvsig.tools.persistence.text; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.geom.Point2D; |
5 |
import java.text.DecimalFormat; |
6 |
import java.text.DecimalFormatSymbols; |
7 |
|
8 |
import org.gvsig.tools.dynobject.DynStruct; |
9 |
import org.gvsig.tools.persistence.AbstractMultiPersistenceFactory; |
10 |
import org.gvsig.tools.persistence.PersistentState; |
11 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
12 |
|
13 |
public class JavaTextFactory extends AbstractMultiPersistenceFactory { |
14 |
private static JavaTextFactory instance = null; |
15 |
|
16 |
private static final String DYNCLASS_DECIMAL_FORMAT_NAME = "DecimalFormat"; |
17 |
private static final String DYNCLASS_DECIMAL_FORMAT_DESCRIPTION = "DecimalFormat"; |
18 |
private static final String PATTERN_FIELD = "pattern"; |
19 |
private static final String DECIMAL_SEP_FIELD = "decimalSep"; |
20 |
private static final String GROUPING_SEP_FIELD = "groupingSep"; |
21 |
|
22 |
protected void makeDefinitions() { |
23 |
DynStruct decimalFromatDef = this.addDefinition(DecimalFormat.class, DYNCLASS_DECIMAL_FORMAT_NAME, DYNCLASS_DECIMAL_FORMAT_DESCRIPTION); |
24 |
decimalFromatDef.addDynFieldString(PATTERN_FIELD).setMandatory(true);
|
25 |
decimalFromatDef.addDynFieldString(DECIMAL_SEP_FIELD).setMandatory(true);
|
26 |
decimalFromatDef.addDynFieldString(GROUPING_SEP_FIELD).setMandatory(true);
|
27 |
} |
28 |
|
29 |
public Object createFromState(PersistentState state) |
30 |
throws PersistenceException {
|
31 |
if (this.getManagedClass(state).isAssignableFrom(DecimalFormat.class)) { |
32 |
String pattern = state.getString(PATTERN_FIELD);
|
33 |
String decimalSep = state.getString(DECIMAL_SEP_FIELD);
|
34 |
String groupingSep = state.getString(GROUPING_SEP_FIELD);
|
35 |
|
36 |
DecimalFormatSymbols sym = DecimalFormatSymbols.getInstance(); |
37 |
if (decimalSep!=null && decimalSep.length()>0) { |
38 |
sym.setDecimalSeparator(decimalSep.charAt(0));
|
39 |
} |
40 |
if (groupingSep!=null && groupingSep.length()>0) { |
41 |
sym.setGroupingSeparator(groupingSep.charAt(0));
|
42 |
} |
43 |
return new DecimalFormat(pattern, sym); |
44 |
} |
45 |
throw new RuntimeException(); //FIXME |
46 |
} |
47 |
|
48 |
public void saveToState(PersistentState state, Object obj) |
49 |
throws PersistenceException {
|
50 |
if (obj instanceof DecimalFormat) { |
51 |
DecimalFormat format = (DecimalFormat) obj; |
52 |
state.set(PATTERN_FIELD, format.toPattern()); |
53 |
state.set(DECIMAL_SEP_FIELD, String.valueOf(format.getDecimalFormatSymbols().getDecimalSeparator()));
|
54 |
state.set(GROUPING_SEP_FIELD, String.valueOf(format.getDecimalFormatSymbols().getGroupingSeparator()));
|
55 |
return;
|
56 |
} |
57 |
throw new RuntimeException(); //FIXME |
58 |
} |
59 |
|
60 |
|
61 |
|
62 |
} |