Revision 32880 branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/tools/persistence/FontPersistenceFactory.java

View differences:

FontPersistenceFactory.java
26 26
 */
27 27
package org.gvsig.fmap.mapcontext.tools.persistence;
28 28

  
29
import java.awt.Color;
30 29
import java.awt.Font;
31 30

  
32
import org.gvsig.tools.ToolsLocator;
33
import org.gvsig.tools.dynobject.DynObjectManager;
34 31
import org.gvsig.tools.dynobject.DynStruct;
35
import org.gvsig.tools.persistence.AbstractHierarchyPersistenceFactory;
36
import org.gvsig.tools.persistence.PersistenceException;
32
import org.gvsig.tools.persistence.AbstractSinglePersistenceFactory;
37 33
import org.gvsig.tools.persistence.PersistentState;
34
import org.gvsig.tools.persistence.exception.PersistenceException;
38 35

  
39 36
/**
40 37
 * Factory to manage the persistence of {@link Font} objects.
41 38
 * 
42 39
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
40
 * @author 2010- <a href="jjdelcerro@gvsig.org">Joaquin Jose del Cerro</a> -
41
 *         gvSIG team
43 42
 */
44
public class FontPersistenceFactory extends
45
		AbstractHierarchyPersistenceFactory {
43
public class FontPersistenceFactory extends AbstractSinglePersistenceFactory {
46 44

  
47 45
	static final String FIELD_NAME = "name";
48

  
49 46
	static final String FIELD_STYLE = "style";
50

  
51 47
	static final String FIELD_SIZE = "size";
52 48

  
53
	private static final String FONT_DYNCLASS_NAME = "Font";
49
	private static final String DYNCLASS_NAME = "Font";
50
	private static final String DYNCLASS_DESCRIPTION = "Font";
54 51

  
55
	private static final String FONT_DYNCLASS_DESCRIPTION = "Font";
56

  
57
	private DynStruct pointDefinition;
58

  
59 52
	/**
60
	 * Creates a new {@link FontPersistenceFactory} with the
61
	 * {@link DynStruct} definition for the {@link Color} objects.
53
	 * Creates a new {@link FontPersistenceFactory} with the {@link DynStruct}
54
	 * definition for the {@link Font} objects.
62 55
	 */
63 56
	public FontPersistenceFactory() {
57
		super(Font.class, DYNCLASS_NAME, DYNCLASS_DESCRIPTION, null, null);
64 58

  
65
		// Create the DynStruct related to the Font objects persisted
66
		// data, which will be its name, style and size.
67
		DynObjectManager dynman = ToolsLocator.getDynObjectManager();
59
		DynStruct definition = this.getDefinition();
68 60

  
69
		pointDefinition = dynman.add(FONT_DYNCLASS_NAME,
70
				FONT_DYNCLASS_DESCRIPTION);
71

  
72
		pointDefinition.addDynFieldString(FIELD_NAME).setMandatory(true);
73
		pointDefinition.addDynFieldInt(FIELD_STYLE).setMandatory(true);
74
		pointDefinition.addDynFieldInt(FIELD_SIZE).setMandatory(true);
61
		definition.addDynFieldString(FIELD_NAME).setMandatory(true);
62
		definition.addDynFieldInt(FIELD_STYLE).setMandatory(true);
63
		definition.addDynFieldInt(FIELD_SIZE).setMandatory(true);
75 64
	}
76 65

  
77
	protected Class getParentClass() {
78
		return Font.class;
79
	}
80

  
81
	protected DynStruct getParentClassDefinition() {
82
		return pointDefinition;
83
	}
84

  
85
	public Object createFromState(PersistentState state, Class classToUse)
66
	public Object createFromState(PersistentState state)
86 67
			throws PersistenceException {
87 68
		String name = state.getString(FIELD_NAME);
88 69
		int style = state.getInt(FIELD_STYLE);
......
91 72
		return new Font(name, style, size);
92 73
	}
93 74

  
94
	public void loadFromState(PersistentState state, Object object)
95
			throws PersistenceException {
96
		// Nothing to do here, everything is read in the creation
97
	}
98

  
99 75
	public void saveToState(PersistentState state, Object obj)
100 76
			throws PersistenceException {
101 77
		Font font = (Font) obj;
......
103 79
		state.set(FIELD_STYLE, font.getStyle());
104 80
		state.set(FIELD_SIZE, font.getSize());
105 81
	}
106

  
107
	public String getDomainName() {
108
		// Use the default domain name
109
		return null;
110
	}
111

  
112
	public String getDomainURL() {
113
		// Use the default domain url
114
		return null;
115
	}
116

  
117 82
}

Also available in: Unified diff