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 @ 45527

History | View | Annotate | Download (3.4 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2021 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
import org.slf4j.Logger;
34
import org.slf4j.LoggerFactory;
35

    
36
/**
37
 * Implements the IStyle interface in order to complete the methods ot the
38
 * IStyle interface that allow the users to add the description of an object or
39
 * obtain it.
40
 *
41
 * @author gvSIG team
42
 */
43
public abstract class AbstractStyle implements IStyle {
44

    
45
    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractStyle.class);
46
    
47
    public static final String STYLE_PERSISTENCE_DEFINITION_NAME = "Style";
48

    
49
    private static final String FIELD_DESCRIPTION = "description";
50

    
51
    private String desc;
52

    
53
    @Override
54
    public final void setDescription(String desc) {
55
        this.desc = desc;
56
    }
57

    
58
    @Override
59
    public final String getDescription() {
60
        return desc;
61
    }
62

    
63
    @Override
64
    public Object clone() throws CloneNotSupportedException {
65
        return super.clone();
66
    }
67

    
68
    @Override
69
    public void loadFromState(PersistentState state)
70
            throws PersistenceException {
71
        setDescription(state.getString(FIELD_DESCRIPTION));
72
    }
73

    
74
    @Override
75
    public void saveToState(PersistentState state) throws PersistenceException {
76
        state.set(FIELD_DESCRIPTION, getDescription());
77
    }
78

    
79
    public static class RegisterPersistence implements Callable {
80

    
81
        @Override
82
        public Object call() throws Exception {
83
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
84
            if (manager.getDefinition(STYLE_PERSISTENCE_DEFINITION_NAME) == null) {
85
                DynStruct definition = manager.addDefinition(
86
                        AbstractStyle.class,
87
                        STYLE_PERSISTENCE_DEFINITION_NAME,
88
                        STYLE_PERSISTENCE_DEFINITION_NAME + " Persistence definition",
89
                        null,
90
                        null
91
                );
92

    
93
                // Description
94
                definition.addDynFieldString(FIELD_DESCRIPTION);
95
            }
96
            return true;
97
        }
98

    
99
    }
100
}