Statistics
| Revision:

root / branches / v10 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / LegendFactory.java @ 20939

History | View | Annotate | Download (6.3 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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 Ib??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 com.iver.cit.gvsig.fmap.rendering;
42

    
43
import com.hardcode.gdbms.engine.data.driver.DriverException;
44

    
45
import com.iver.cit.gvsig.fmap.core.FShape;
46
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
47
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
48
import com.iver.cit.gvsig.fmap.layers.XMLException;
49

    
50
import com.iver.utiles.XMLEntity;
51

    
52

    
53
/**
54
 * Clase factoria de las diferentes leyendas.
55
 *
56
 * @author Fernando Gonz?lez Cort?s
57
 */
58
public class LegendFactory {
59
        public static FSymbol DEFAULT_POINT_SYMBOL = new FSymbol(FConstant.SYMBOL_TYPE_POINT);
60
        public static FSymbol DEFAULT_LINE_SYMBOL = new FSymbol(FConstant.SYMBOL_TYPE_LINE);
61
        public static FSymbol DEFAULT_POLYGON_SYMBOL = new FSymbol(FConstant.SYMBOL_TYPE_FILL);
62

    
63
        // TODO Descomentar esto cuando se tenga la interfaz de datos
64

    
65
        /*
66
         * Crea un objeto renderer de valor ?nico con las caracter?sticas que se pasan como par?metro y con los s?mbolos por defecto. En funci?n de la carga del sistema se podr? crear un FRenderer que almacene la referencia al FRecordset, o un FRenderer que haga cach? de los valores necesarios
67
         *
68
               public static Legend createIntervalLegend(FRecordset data, int valueField, int labelField ) {
69
               }
70
               /*
71
         * Crea un objeto renderer de valor ?nico con las caracter?sticas que se pasan como par?metro y con los s?mbolos por defecto. En funci?n de la carga del sistema se podr? crear un FRenderer que almacene la referencia al FRecordset, o un FRenderer que haga cach? de los valores necesarios
72
         *
73
               public static Legend createUniqueValueLegend(FRecordset data, int valueField, int labelField ) {
74
               }
75
         */
76

    
77
        /**
78
         * Crea un objeto renderer de s?mbolo ?nico con las caracter?sticas que se
79
         * pasan como par?metro
80
         *
81
         * @param shapeType Tipo de shape.
82
         *
83
         * @return VectorialLegend.
84
         */
85
        public static VectorialLegend createSingleSymbolLegend(int shapeType) {
86
                switch (shapeType) {
87
                        case FShape.POINT:
88
                                return new SingleSymbolLegend(new FSymbol(
89
                                                FConstant.SYMBOL_TYPE_POINT));
90

    
91
                        case FShape.LINE:
92
                                return new SingleSymbolLegend(new FSymbol(
93
                                                FConstant.SYMBOL_TYPE_LINE));
94

    
95
                        case FShape.POLYGON:
96
                                return new SingleSymbolLegend(new FSymbol(
97
                                                FConstant.SYMBOL_TYPE_FILL));
98
                        case FShape.MULTIPOINT:
99
                                return new SingleSymbolLegend(new FSymbol(
100
                                                FConstant.SYMBOL_TYPE_POINT));
101
                        case FShape.TEXT:
102
                                return new SingleSymbolLegend(new FSymbol(
103
                                                FConstant.SYMBOL_TYPE_TEXT));
104
                }
105

    
106
                return new SingleSymbolLegend(new FSymbol(shapeType));
107
        }
108

    
109
        /**
110
         * Crea un objeto VectorialUniqueValueLegend vac?o, dispuesto para cargar
111
         * s?mbolos
112
         *
113
         * @param shapeType Tipo de shape.
114
         *
115
         * @return VectorialUniqueValueLegend.
116
         */
117
        public static VectorialUniqueValueLegend createVectorialUniqueValueLegend(
118
                int shapeType) {
119
                return new VectorialUniqueValueLegend(shapeType);
120
        }
121

    
122
        /**
123
         * Crea un objeto VectorialIntervalLegend vac?o, dispuesto para cargar
124
         * s?mbolos
125
         *
126
         * @param shapeType tipo de shape.
127
         *
128
         * @return VectorialIntervalLegend
129
         */
130
        public static VectorialIntervalLegend createVectorialIntervalLegend(
131
                int shapeType) {
132
                return new VectorialIntervalLegend(shapeType);
133
        }
134

    
135
        /**
136
         * Obtiene un objeto con las propiedades del renderer. Este m?todo se
137
         * invocar? con el fin de guardar el s?mbolo en disco.
138
         *
139
         * @param r VectorialLegend.
140
         *
141
         * @return XMLEntity.
142
         *
143
         * @throws DriverException
144
         */
145
        public static XMLEntity getXMLEntity(VectorialLegend r)
146
                throws DriverException {
147
                XMLEntity xml = r.getXMLEntity();
148

    
149
                return xml;
150
        }
151

    
152
        /**
153
         * Crea un renderer con la informaci?n contenida en el objeto XMLEntity
154
         *
155
         * @param xml XMLEntity.
156
         *
157
         * @return VectorialLegend
158
         *
159
         * @throws XMLException
160
         */
161
        public static VectorialLegend createFromXML03(XMLEntity xml)
162
                throws XMLException {
163
                //TODO Implementar bien
164
                try {
165
                        VectorialLegend vl = null;
166
                        Class clase = Class.forName(xml.getStringProperty("className"));
167
                        vl = (VectorialLegend) clase.newInstance();
168
                        vl.setXMLEntity03(xml);
169

    
170
                        return vl;
171
                } catch (ClassNotFoundException e) {
172
                        throw new XMLException(e);
173
                } catch (InstantiationException e) {
174
                        throw new XMLException(e);
175
                } catch (IllegalAccessException e) {
176
                        throw new XMLException(e);
177
                }
178
        }
179

    
180
        /**
181
         * Crea un renderer con la informaci?n contenida en el objeto XMLEntity
182
         *
183
         * @param xml XMLEntity.
184
         *
185
         * @return VectorialLegend
186
         *
187
         * @throws XMLException
188
         */
189
        public static VectorialLegend createFromXML(XMLEntity xml)
190
                throws XMLException {
191
                //TODO Implementar bien
192
                try {
193
                        VectorialLegend vl = null;
194
                        Class clase = Class.forName(xml.getStringProperty("className"));
195
                        vl = (VectorialLegend) clase.newInstance();
196
                        vl.setXMLEntity(xml);
197

    
198
                        return vl;
199
                } catch (ClassNotFoundException e) {
200
                        throw new XMLException(e);
201
                } catch (InstantiationException e) {
202
                        throw new XMLException(e);
203
                } catch (IllegalAccessException e) {
204
                        throw new XMLException(e);
205
                }
206
        }
207

    
208
        /**
209
         * Clona la leyenda.
210
         *
211
         * @param l VectorialLegend a clonar.
212
         *
213
         * @return VectorialLegend cloando.
214
         *
215
         * @throws XMLException
216
         * @throws DriverException
217
         */
218
        public static VectorialLegend cloneLegend(VectorialLegend l)
219
                throws XMLException, DriverException {
220
                return createFromXML(getXMLEntity(l));
221
        }
222
}