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 / legend / impl / FInterval.java @ 40560

History | View | Annotate | Download (4.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.legend.impl;
25

    
26
import org.gvsig.fmap.mapcontext.rendering.legend.IInterval;
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
 * Clase intervalo.
36
 * 
37
 * @author Vicente Caballero Navarro
38
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
39
 */
40
public class FInterval implements IInterval {
41
        public static final String FINTERVAL_PERSISTENCE_DEFINITION_NAME = "FInterval";
42

    
43
        private static final String FIELD_MIN = "min";
44
        private static final String FIELD_MAX = "max";
45

    
46
        private double min;
47
        private double max;
48

    
49
        /**
50
         * Creates a new empty FInterval, used to be instantiated by persistence
51
         */
52
        public FInterval(){
53
                // Nothing to do
54
        }
55

    
56
        /**
57
         * Crea un nuevo FInterval.
58
         *
59
         * @param from Origen.
60
         * @param to Destino.
61
         */
62
        public FInterval(double from, double to) {
63
                this.min = from;
64
                this.max = to;
65
        }
66

    
67
        /* (non-Javadoc)
68
         * @see com.iver.cit.gvsig.fmap.rendering.IInterval#isInInterval(com.hardcode.gdbms.engine.values.Value)
69
         */
70
        public boolean isInInterval(Object v) {
71
                double valor=0;
72
                if (v == null){
73
                        return false;
74
                }else if (v instanceof Number) {
75
                        valor = ((Number) v).doubleValue();
76
                }
77
                return ((valor >= min) && (valor <= max));
78
        }
79

    
80
        /**
81
         * Devuelve el n?mero de origen.
82
         *
83
         * @return N?mero de inicio.
84
         */
85
        public double getMin() {
86
                return min;
87
        }
88

    
89
        /**
90
         * Devuelve el n?mero final.
91
         *
92
         * @return N?mero final.
93
         */
94
        public double getMax() {
95
                return max;
96
        }
97

    
98
        /* (non-Javadoc)
99
         * @see com.iver.cit.gvsig.fmap.rendering.IInterval#toString()
100
         */
101
        public String toString() {
102
                return min + "-" + max;
103
        }
104

    
105
        public Object clone() throws CloneNotSupportedException {
106
                return super.clone();
107
        }
108

    
109
        public void loadFromState(PersistentState state)
110
                        throws PersistenceException {
111
                min = state.getDouble(FIELD_MIN);
112
                max = state.getDouble(FIELD_MAX);
113
        }
114

    
115
        public void saveToState(PersistentState state) throws PersistenceException {
116
                state.set(FIELD_MIN, getMin());
117
                state.set(FIELD_MAX, getMax());
118
        }
119

    
120
        public static class RegisterPersistence implements Callable {
121

    
122
                public Object call() throws Exception {
123
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
124
                        if( manager.getDefinition(FINTERVAL_PERSISTENCE_DEFINITION_NAME)==null ) {
125
                                DynStruct definition = manager.addDefinition(
126
                                                FInterval.class,
127
                                                FINTERVAL_PERSISTENCE_DEFINITION_NAME,
128
                                                FINTERVAL_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
129
                                                null, 
130
                                                null
131
                                );
132

    
133
                                definition.addDynFieldDouble(FIELD_MIN)
134
                                                .setMandatory(true)
135
                                                .setDescription("Minimum interval value");
136
                                definition.addDynFieldDouble(FIELD_MAX).setMandatory(true).setDescription(
137
                                                "Maximum interval value");
138
                        }
139
                        return Boolean.TRUE;
140
                }
141
                
142
        }
143

    
144

    
145
}