Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / symbol / style / AbstractStyle.java @ 40560

History | View | Annotate | Download (3.03 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style;
25

    
26
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.IStyle;
27
import org.gvsig.tools.ToolsLocator;
28
import org.gvsig.tools.dynobject.DynStruct;
29
import org.gvsig.tools.persistence.PersistenceManager;
30
import org.gvsig.tools.persistence.PersistentState;
31
import org.gvsig.tools.persistence.exception.PersistenceException;
32
import org.gvsig.tools.util.Callable;
33

    
34
/**
35
 * Implements the IStyle interface in order to complete the methods ot the
36
 * IStyle interface that allow the users to add the description of an object or
37
 * obtain it.
38
 * 
39
 * @author 2005-2008 jaume dominguez faus - jaume.dominguez@iver.es
40
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
41
 */
42

    
43
public abstract class AbstractStyle implements IStyle {
44

    
45
        public static final String STYLE_PERSISTENCE_DEFINITION_NAME = "Style";
46

    
47
        private static final String FIELD_DESCRIPTION = "description";
48

    
49
        private String desc;
50

    
51
        public final void setDescription(String desc) {
52
                this.desc = desc;
53
        }
54

    
55
        public final String getDescription() {
56
                return desc;
57
        }
58
        
59
        public Object clone() throws CloneNotSupportedException {
60
                return super.clone();
61
        }
62

    
63
        public void loadFromState(PersistentState state)
64
                        throws PersistenceException {
65
                setDescription(state.getString(FIELD_DESCRIPTION));
66
        }
67

    
68
        public void saveToState(PersistentState state) throws PersistenceException {
69
                state.set(FIELD_DESCRIPTION, getDescription());
70
        }
71

    
72
        public static class RegisterPersistence implements Callable {
73

    
74
                public Object call() throws Exception {
75
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
76
                        if( manager.getDefinition(STYLE_PERSISTENCE_DEFINITION_NAME)==null ) {
77
                                DynStruct definition = manager.addDefinition(
78
                                                AbstractStyle.class,
79
                                                STYLE_PERSISTENCE_DEFINITION_NAME,
80
                                                STYLE_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
81
                                                null, 
82
                                                null
83
                                );
84

    
85
                                // Description
86
                                definition.addDynFieldString(FIELD_DESCRIPTION);
87
                        }
88
                        return Boolean.TRUE;
89
                }
90
                
91
        }
92
}