Statistics
| Revision:

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

History | View | Annotate | Download (6.31 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
import com.iver.cit.gvsig.fmap.core.FShape;
45
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
46
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
47
import com.iver.cit.gvsig.fmap.layers.XMLException;
48
import com.iver.utiles.XMLEntity;
49

    
50

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

    
61
        // TODO Descomentar esto cuando se tenga la interfaz de datos
62

    
63
        /*
64
         * 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
65
         *
66
               public static Legend createIntervalLegend(FRecordset data, int valueField, int labelField ) {
67
               }
68
               /*
69
         * 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
70
         *
71
               public static Legend createUniqueValueLegend(FRecordset data, int valueField, int labelField ) {
72
               }
73
         */
74

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

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

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

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

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

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

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

    
147
                return xml;
148
        }
149

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

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

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

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

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