Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / QuantityByCategoryLegend.java @ 11486

History | View | Annotate | Download (8.27 KB)

1
package com.iver.cit.gvsig.fmap.rendering;
2

    
3
import java.util.logging.Logger;
4

    
5
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
6
import com.hardcode.gdbms.engine.data.DataSource;
7
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
8
import com.iver.cit.gvsig.fmap.core.FShape;
9
import com.iver.cit.gvsig.fmap.core.IFeature;
10
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
11
import com.iver.cit.gvsig.fmap.core.styles.MarkerFillProperties;
12
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol;
13
import com.iver.cit.gvsig.fmap.core.symbols.IMultiLayerSymbol;
14
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
15
import com.iver.cit.gvsig.fmap.core.symbols.MarkerFillSymbol;
16
import com.iver.cit.gvsig.fmap.layers.XMLException;
17
import com.iver.utiles.XMLEntity;
18
/**
19
 * @author jaume dominguez faus - jaume.dominguez@iver.es
20
 */
21
public class QuantityByCategoryLegend implements ClassifiedLegend, VectorialLegend  {
22
        private GraduatedSymbolLegend graduatedSymbol = new GraduatedSymbolLegend();
23
        private VectorialIntervalLegend colorRamp = new VectorialIntervalLegend();
24
        private ISymbol defaultSymbol;
25
        private int shapeType;
26
        private boolean isUseDefaultSymbol;
27

    
28
    public void clear() {
29
        colorRamp.clear();
30
        graduatedSymbol.clear();
31
    }
32

    
33
    public String getFieldName() {
34
            String field1 = graduatedSymbol.getFieldName();
35
        String field2 = colorRamp.getFieldName();
36
        return field1 + "&&" + field2;
37
    }
38

    
39
    public void setFieldName(String i) {
40
        String[] fieldNames = i.split("&&");
41
        colorRamp.setFieldName(fieldNames[1]);
42
        graduatedSymbol.setFieldName(fieldNames[0]);
43
    }
44

    
45
    public void addSymbol(Object key, ISymbol symbol) {
46
            System.out.println("adding "+key+"["+symbol+"]");
47
//        // TODO Implement it
48
//        throw new Error("Not yet implemented!");
49
    }
50

    
51
    public void delSymbol(Object key) {
52
            colorRamp.delSymbol(key);
53
            graduatedSymbol.delSymbol(key);
54
    }
55

    
56
    public String[] getDescriptions() {
57
            String[] desc1 = colorRamp.getDescriptions();
58
            String[] desc2 = graduatedSymbol.getDescriptions();
59

    
60
            String[] descriptions = new String[desc1.length + desc2.length];
61
            for (int i = 0; i < descriptions.length; i++) {
62
                    descriptions[i] = (i <desc1.length) ? desc1[i] : desc2[i % desc1.length];
63
                }
64
            return descriptions;
65
    }
66

    
67
    public ISymbol[] getSymbols() {
68
            ISymbol[] symbols1 = colorRamp.getSymbols();
69
            ISymbol[] symbols2 = graduatedSymbol.getSymbols();
70

    
71
            ISymbol[] symbols = new ISymbol[symbols1.length + symbols2.length];
72
            for (int i = 0; i < symbols.length; i++) {
73
                    symbols[i] = (i < symbols1.length) ? symbols1[i] : symbols2[i % symbols1.length];
74
                }
75
            return symbols;
76
    }
77

    
78
    public Object[] getValues() {
79
            Object[] objects1 = colorRamp.getValues();
80
            Object[] objects2 = graduatedSymbol.getValues();
81

    
82
            Object[] objects = new FInterval[objects1.length + objects2.length];
83
            for (int i = 0; i < objects.length; i++) {
84
                    objects[i] = (i < objects1.length) ? objects1[i] : objects2[i % objects1.length];
85
                }
86
            return objects;
87
    }
88

    
89
    public ISymbol getDefaultSymbol() {
90
            return defaultSymbol;
91
    }
92

    
93
    public XMLEntity getXMLEntity() {
94
        XMLEntity xml = new XMLEntity();
95
        xml.putProperty("className", getClass().getName());
96
        xml.putProperty("shapeType", shapeType);
97
        xml.putProperty("isUseDefaultSymbol", isUseDefaultSymbol);
98
        xml.addChild(graduatedSymbol.getXMLEntity());
99

    
100
        xml.addChild(colorRamp.getXMLEntity());
101
        if (defaultSymbol != null)
102
                xml.addChild(defaultSymbol.getXMLEntity());
103
        return xml;
104
    }
105

    
106
    public String getSLDString(String layerName) {
107
        // TODO Implement it
108
        throw new Error("Not yet implemented!");
109

    
110
    }
111
    public Legend cloneLegend() throws XMLException {
112
        // TODO Implement it
113
        throw new Error("Not yet implemented!");
114

    
115
    }
116

    
117
        public GraduatedSymbolLegend getGraduatedSymbolLegend() {
118
                return graduatedSymbol;
119
        }
120

    
121
        public VectorialIntervalLegend getColorRampLegend() {
122
                return colorRamp;
123
        }
124

    
125
        public void setDataSource(DataSource ds) throws FieldNotFoundException, ReadDriverException {
126
                graduatedSymbol.setDataSource(ds);
127
                colorRamp.setDataSource(ds);
128
        }
129

    
130
        public ISymbol getSymbol(int i) throws ReadDriverException {
131
                IMarkerSymbol sym1 = (IMarkerSymbol) graduatedSymbol.getSymbol(i);
132
                ISymbol sym2 =  colorRamp.getSymbol(i);
133
                IMultiLayerSymbol multiSym = null;
134
                switch (shapeType) {
135
                case FShape.POLYGON:
136
                        /*
137
                         * symbol from the GraduatedSymbolLegend is a marker, but
138
                         * what we need is a fill symbol. Will use a MarkerFillSymbol
139
                         * to enable support for Polygons
140
                         */
141
                        MarkerFillSymbol aux = new MarkerFillSymbol();
142
                        // tell the fill style to draw the IMarkerSymbol
143
                        // as a IFillSymbol centering it in the shape polygon
144
                        // centroid and applying offset (if any).
145
                        aux.setMarker(sym1);
146
                        aux.setFillStyle(MarkerFillProperties.SINGLE_CENTERED_SYMBOL);
147

    
148
                        multiSym = SymbologyFactory.
149
                                createEmptyMultiLayerSymbol(FShape.POLYGON);
150
                        multiSym.addLayer(sym2);
151
                        multiSym.addLayer(aux);
152
                break;
153
                case FShape.LINE:
154
                        throw new Error("Shape type not yet supported");
155
                default:
156
                        throw new Error("Unsupported shape type");
157

    
158
                }
159

    
160
                return multiSym;
161
        }
162

    
163
        public ISymbol getSymbolByFeature(IFeature feat) {
164
                IMarkerSymbol sym1 = (IMarkerSymbol) graduatedSymbol.getSymbolByFeature(feat);
165
                ISymbol sym2 = colorRamp.getSymbolByFeature(feat);
166
                IMultiLayerSymbol multiSym = null;
167
                switch (shapeType) {
168
                case FShape.POLYGON:
169
                        /*
170
                         * symbol from the GraduatedSymbolLegend is a marker, but
171
                         * what we need is a fill symbol. Will use a MarkerFillSymbol
172
                         * to enable support for Polygons
173
                         */
174
                        MarkerFillSymbol aux = new MarkerFillSymbol();
175
                        // tell the fill style to draw the IMarkerSymbol
176
                        // as a IFillSymbol centering it in the shape polygon
177
                        // centroid and applying offset (if any).
178
                        aux.setMarker(sym1);
179
                        aux.setFillStyle(MarkerFillProperties.SINGLE_CENTERED_SYMBOL);
180

    
181
                        multiSym = SymbologyFactory.
182
                        createEmptyMultiLayerSymbol(FShape.POLYGON);
183
                        multiSym.addLayer(sym2);
184
                        multiSym.addLayer(aux);
185
                break;
186
                case FShape.LINE:
187
                        throw new Error("Shape type not yet supported");
188
                default:
189
                        throw new Error("Unsupported shape type");
190

    
191
                }
192

    
193
                return multiSym;
194
        }
195

    
196
        public int getShapeType() {
197
                return shapeType;
198
        }
199

    
200
        public void setShapeType(int shapeType) {
201
                this.shapeType = shapeType;
202
                graduatedSymbol.setShapeType(FShape.POINT);
203
                colorRamp.setShapeType(shapeType);
204
        }
205

    
206
        public void setDefaultSymbol(ISymbol s) throws IllegalArgumentException {
207
                this.defaultSymbol = s;
208
        }
209

    
210
        /**
211
         * @deprecated
212
         */
213
        public void setLabelField(String fieldName) {
214
                // TODO Implement it
215
                throw new Error("Not yet implemented!");
216

    
217
        }
218

    
219
        /**
220
         * @deprecated
221
         */
222
        public void setLabelHeightField(String fieldName) {
223
                throw new Error("deprecated method");
224
        }
225

    
226
        /**
227
         * @deprecated
228
         */
229
        public void setLabelRotationField(String fieldName) {
230
                throw new Error("deprecated method");
231
        }
232

    
233
        /**
234
         * @deprecated
235
         */
236
        public String getLabelField() {
237
                return null;
238
        }
239

    
240
        /**
241
         * @deprecated
242
         */
243
        public String getLabelHeightField() {
244
                return null;
245
        }
246

    
247
        /**
248
         * @deprecated
249
         */
250
        public String getLabelRotationField() {
251
                return null;
252
        }
253

    
254
        public void setXMLEntity(XMLEntity xml) {
255
                shapeType = xml.getIntProperty("shapeType");
256
        isUseDefaultSymbol = xml.getBooleanProperty("isUseDefaultSymbol");
257
        try {
258
                        graduatedSymbol = (GraduatedSymbolLegend) LegendFactory.createFromXML(xml.getChild(0));
259
                        colorRamp = (VectorialIntervalLegend) LegendFactory.createFromXML(xml.getChild(1));
260
        } catch (XMLException e) {
261
                        // TODO Auto-generated catch block
262
                Logger.getAnonymousLogger().severe(e.getFormatString());
263
                }
264

    
265
        if (defaultSymbol != null)
266
                xml.addChild(defaultSymbol.getXMLEntity());
267
        }
268

    
269
        public void setXMLEntity03(XMLEntity xml) {
270
                // nothing to do here
271
        }
272

    
273
        public boolean isUseDefaultSymbol() {
274
                return isUseDefaultSymbol;
275
        }
276

    
277
        public void useDefaultSymbol(boolean b) {
278
                this.isUseDefaultSymbol = b;
279
        }
280

    
281
        public String[] getUsedFields() {
282
                // TODO Implement it
283
                throw new Error("Not yet implemented!");
284

    
285
        }
286

    
287
        public void setGraduateSymbolLegend(Legend legend) {
288
                this.graduatedSymbol = (GraduatedSymbolLegend) legend;
289
        }
290

    
291
        public void setColorRampLegend(Legend legend) {
292
                this.colorRamp = (VectorialIntervalLegend) legend;
293
        }
294

    
295
}