Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / LegendFactory.java @ 3051

History | View | Annotate | Download (6.21 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
                }
102

    
103
                return new SingleSymbolLegend(new FSymbol(FConstant.SYMBOL_TYPE_FILL));
104
        }
105

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

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

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

    
146
                return xml;
147
        }
148

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

    
167
                        return vl;
168
                } catch (ClassNotFoundException e) {
169
                        throw new XMLException(e);
170
                } catch (InstantiationException e) {
171
                        throw new XMLException(e);
172
                } catch (IllegalAccessException e) {
173
                        throw new XMLException(e);
174
                }
175
        }
176

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

    
195
                        return vl;
196
                } catch (ClassNotFoundException e) {
197
                        throw new XMLException(e);
198
                } catch (InstantiationException e) {
199
                        throw new XMLException(e);
200
                } catch (IllegalAccessException e) {
201
                        throw new XMLException(e);
202
                }
203
        }
204

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