Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / rendering / tools / persistence / FontPersistenceFactory.java @ 31544

History | View | Annotate | Download (3.48 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
 * 2009 {}  {{Task}}
26
 */
27
package org.gvsig.fmap.mapcontext.rendering.tools.persistence;
28

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

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

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

    
47
        static final String FIELD_NAME = "name";
48

    
49
        static final String FIELD_STYLE = "style";
50

    
51
        static final String FIELD_SIZE = "size";
52

    
53
        private static final String FONT_DYNCLASS_NAME = "Font";
54

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

    
57
        private DynStruct pointDefinition;
58

    
59
        /**
60
         * Creates a new {@link FontPersistenceFactory} with the
61
         * {@link DynStruct} definition for the {@link Color} objects.
62
         */
63
        public FontPersistenceFactory() {
64

    
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();
68

    
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);
75
        }
76

    
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)
86
                        throws PersistenceException {
87
                String name = state.getString(FIELD_NAME);
88
                int style = state.getInt(FIELD_STYLE);
89
                int size = state.getInt(FIELD_SIZE);
90

    
91
                return new Font(name, style, size);
92
        }
93

    
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
        public void saveToState(PersistentState state, Object obj)
100
                        throws PersistenceException {
101
                Font font = (Font) obj;
102
                state.set(FIELD_NAME, font.getName());
103
                state.set(FIELD_STYLE, font.getStyle());
104
                state.set(FIELD_SIZE, font.getSize());
105
        }
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
}