Statistics
| Revision:

root / org.gvsig.complexlegend / trunk / org.gvsig.complexlegend / org.gvsig.complexlegend.lib / org.gvsig.complexlegend.lib.impl / src / main / java / org / gvsig / complexlegend / impl / DefaultComplexLegendItem.java @ 86

History | View | Annotate | Download (3.19 KB)

1
package org.gvsig.complexlegend.impl;
2

    
3
import java.text.NumberFormat;
4

    
5
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel;
6
import org.gvsig.complexlegend.ComplexLegendItem;
7
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
8
import org.gvsig.tools.ToolsLocator;
9
import org.gvsig.tools.dynobject.DynStruct;
10
import org.gvsig.tools.persistence.PersistenceManager;
11
import org.gvsig.tools.persistence.Persistent;
12
import org.gvsig.tools.persistence.PersistentState;
13
import org.gvsig.tools.persistence.exception.PersistenceException;
14
import org.gvsig.tools.util.Callable;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

    
18
public class DefaultComplexLegendItem implements ComplexLegendItem, Persistent{
19

    
20
        public static final Logger logger = LoggerFactory.getLogger(DefaultComplexLegendItem.class);
21
        public static final String COMPLEX_LEGEND_ITEM_PERSISTENCE_DEFINITION_NAME = "ComplexLegendItem";
22
        private ILegend legend;
23
        private double maxScale;
24
        private double minScale;
25

    
26
        public ILegend getLegend() {
27
                return legend;
28
        }
29

    
30
        public void setLegend(ILegend legend) {
31
                this.legend = legend;                
32
        }
33

    
34
        public double getMaxScale() {
35
                return maxScale;
36
        }
37

    
38
        public void setMaxScale(double maxScale) {
39
                this.maxScale = maxScale;
40
        }
41

    
42
        public double getMinScale() {
43
                return minScale;
44
        }
45

    
46
        public void setMinScale(double minScale) {
47
                this.minScale = minScale;
48
        }
49
        
50
        public String toString(){
51
                
52
                String panel = "";
53
                if(legend != null){
54
                        ILegendPanel legPanel = ComplexLegendUtils.getLegendPanel(legend);
55
                        if(legPanel != null){
56
                                panel = " "+ legPanel.getTitle();
57
                        }
58
                }
59
                
60
                Double mind = (Double) getMinScale();
61
                String min = "0";
62
                if(mind >= 0){
63
                        int mini = mind.intValue();
64
                        min = NumberFormat.getIntegerInstance().format(mini);
65
                }
66
                
67
                Double maxd = (Double) getMaxScale();
68
                String max = "inf";
69
                if(maxd >= 0){
70
                        int maxi = maxd.intValue();
71
                        max = NumberFormat.getIntegerInstance().format(maxi);
72
                }
73
                return "[1:"+min+" - 1:"+max+"]"+ panel;
74
        }
75

    
76
        
77
        public void loadFromState(PersistentState state)
78
                        throws PersistenceException {
79
                // Set own properties
80
                setLegend((ILegend) state.get("legend"));
81
                setMinScale(state.getDouble("minScale"));
82
                setMaxScale(state.getDouble("maxScale"));
83
        }
84

    
85
        public void saveToState(PersistentState state) throws PersistenceException {
86
                // Save own properties
87
                state.set("legend", getLegend());
88
                state.set("minScale", getMinScale());
89
                state.set("maxScale", getMaxScale());
90
        }
91
        
92
        
93
        public static class RegisterPersistence implements Callable {
94

    
95
                public Object call() throws Exception {
96
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
97
                        if( manager.getDefinition(
98
                                        COMPLEX_LEGEND_ITEM_PERSISTENCE_DEFINITION_NAME)==null ) {
99
                                DynStruct definition = manager.addDefinition(
100
                                                DefaultComplexLegendItem.class,
101
                                                COMPLEX_LEGEND_ITEM_PERSISTENCE_DEFINITION_NAME,
102
                                                COMPLEX_LEGEND_ITEM_PERSISTENCE_DEFINITION_NAME +
103
                                                " Persistence definition",
104
                                                null, 
105
                                                null
106
                                                );
107

    
108
                                definition.addDynFieldObject("legend").setMandatory(true)
109
                                .setClassOfValue(ILegend.class);
110
                                definition.addDynFieldDouble("minScale").setMandatory(true);
111
                                definition.addDynFieldDouble("maxScale").setMandatory(true);
112
                        }
113
                        return Boolean.TRUE;
114
                }
115

    
116
        }
117

    
118
}