Statistics
| Revision:

root / branches / v10 / extensions / extPublish / src / org / gvsig / publish / infoproject / legends / VectorialIntervalLegendInfo.java @ 19419

History | View | Annotate | Download (4.87 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004-2006 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Iba?ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.publish.infoproject.legends;
42

    
43

    
44
import java.util.HashMap;
45

    
46
import org.gvsig.publish.infoproject.ISymbolInfo;
47
import org.gvsig.publish.infoproject.symbols.SymbolInfoFactory;
48

    
49
import com.iver.cit.gvsig.fmap.core.ISymbol;
50
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
51
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend;
52

    
53
public class VectorialIntervalLegendInfo implements IIntervalLegendInfo {
54
        private VectorialIntervalLegend legend = null;
55
        private HashMap expressions = null;
56
        private HashMap intervals = null;
57
        private FLyrVect layer = null;
58
        /**
59
         * constructor 
60
         * @param legend
61
         * @deprecated
62
         */
63
        public VectorialIntervalLegendInfo(VectorialIntervalLegend legend) {
64
                this.legend = legend;
65
                initialize();
66
        }
67
        /**
68
         * constructor
69
         * @param fLyrVect
70
         */
71
        public VectorialIntervalLegendInfo(FLyrVect fLyrVect) {
72
                this.layer = fLyrVect;
73
                this.legend = (VectorialIntervalLegend)fLyrVect.getLegend();
74
                initialize();
75
        }
76
        private void initialize(){
77
                expressions = new HashMap();
78
                intervals = new HashMap();
79
                String[] sIntervals = getIntervals();
80
                String[] sExpressions = new String[sIntervals.length];
81
                ISymbol[] symbols = legend.getSymbols();
82
                for (int i=0 ; i<sIntervals.length ; i++){
83
                        sExpressions[i] = createExpression(sIntervals[i]);
84
                        ISymbolInfo symbol = SymbolInfoFactory.getInstance(symbols[i]);
85
                        intervals.put(sIntervals[i], symbol);
86
                        expressions.put(sExpressions[i], symbol);
87
                }                
88
        }
89
        
90
        /*
91
         * (non-Javadoc)
92
         * @see org.gvsig.publish.infoProject.legends.IIntervalLegendInfo#getFilterItem()
93
         */
94
        public String getFilterItem() {
95
                return legend.getFieldName();
96
        }
97

    
98
        /*
99
         * (non-Javadoc)
100
         * @see org.gvsig.publish.infoProject.legends.IIntervalLegendInfo#getExpressions()
101
         */
102
        public String[] getExpressions(){
103
                String[] sIntervals = getIntervals();
104
                String[] sExpressions = new String[sIntervals.length];
105
                for (int i=0 ; i<sIntervals.length ; i++){
106
                        sExpressions[i] = createExpression(sIntervals[i]);
107
                }
108
                return sExpressions;
109
        }
110
        
111
        /**
112
         * Create an expression from an interval
113
         * @param interval
114
         * An interval (MIN_VALUE - MAXVALUE)
115
         * @return
116
         * An expression
117
         * (FIELD > MIN_VALUE AND FIELD < MAX_VALUE)
118
         */
119
        private String createExpression(String interval){
120
                String[] intervals = interval.split("-");
121
                StringBuffer expression = new StringBuffer();
122
                expression.append("[" + getFilterItem() + "]" + " >= " + formatNumber(intervals[0].trim()));
123
                expression.append(" AND ");
124
                expression.append("[" + getFilterItem() + "]" + " <= " + formatNumber(intervals[1].trim()));
125
                
126
                return expression.toString();
127
        }
128
        
129
        private String formatNumber(String number){
130
                number = number.replace(".","");
131
                return number.replace(",", ".");
132
        }
133

    
134
        /*
135
         * (non-Javadoc)
136
         * @see org.gvsig.publish.infoProject.legends.IIntervalLegendInfo#getIntervals()
137
         */
138
        public String[] getIntervals() {
139
                return legend.getDescriptions();
140
        }
141

    
142
        /*
143
         * (non-Javadoc)
144
         * @see org.gvsig.publish.infoProject.legends.IIntervalLegendInfo#getSymbolByExpression(java.lang.String)
145
         */
146
        public ISymbolInfo getSymbolByExpression(String expression) {
147
                if (expressions.containsKey(expression)){
148
                        return (ISymbolInfo)expressions.get(expression);
149
                }
150
                return null;
151
        }
152

    
153
        /*
154
         * (non-Javadoc)
155
         * @see org.gvsig.publish.infoProject.legends.IIntervalLegendInfo#getSymbolByInterval(java.lang.String)
156
         */
157
        public ISymbolInfo getSymbolByInterval(String interval) {
158
                if (intervals.containsKey(interval)){
159
                        return (ISymbolInfo)intervals.get(interval);
160
                }
161
                return null;
162
        }
163
        /*
164
         * (non-Javadoc)
165
         * @see org.gvsig.publish.infoproject.ILegendInfo#getSLDString()
166
         */
167
        public String getSLDString() {
168
                if (layer != null){
169
                        return legend.getSLDString(layer.getName());
170
                }else{
171
                        return legend.getSLDString("default");
172
                }
173
        }
174

    
175
}