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

History | View | Annotate | Download (3.53 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.symbology.fmap.mapcontext.rendering.symbol.impl.AbstractCartographicSupport;
28
import org.gvsig.tools.ToolsLocator;
29
import org.gvsig.tools.dynobject.DynStruct;
30
import org.gvsig.tools.persistence.PersistenceManager;
31
import org.gvsig.tools.persistence.PersistentState;
32
import org.gvsig.tools.persistence.exception.PersistenceException;
33
import org.gvsig.tools.util.Callable;
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

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

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

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

    
52
    private String desc;
53

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

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

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

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

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

    
80
    public static class RegisterPersistence implements Callable {
81

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

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

    
100
    }
101
}