Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / rendering / legend / LegendFactory.java @ 24494

History | View | Annotate | Download (4.06 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 org.gvsig.fmap.mapcontext.rendering.legend;
42

    
43
import java.awt.Color;
44
import java.util.Random;
45

    
46
import org.gvsig.fmap.dal.exceptions.ReadException;
47
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
48

    
49
import com.iver.utiles.XMLEntity;
50
import com.iver.utiles.XMLException;
51

    
52

    
53
/**
54
 * Clase factoria de las diferentes leyendas.
55
 *
56
 * @author Fernando Gonz?lez Cort?s
57
 */
58
public class LegendFactory {
59
        /**
60
         * Crea un objeto renderer de s?mbolo ?nico con las caracter?sticas que se
61
         * pasan como par?metro
62
         *
63
         * @param shapeType Tipo de shape.
64
         *
65
         * @return VectorialLegend.
66
         */
67
        public static IVectorLegend createSingleSymbolLegend(int shapeType) {
68
                Random rand = new Random();
69

    
70
                int numreg = rand.nextInt(255/2);
71
                double div = (1-rand.nextDouble()*0.66)*0.9;
72
                Color randomColor = new Color(
73
                                ((int) (255*div + (numreg * rand.nextDouble()))) % 255,
74
                                ((int) (255*div + (numreg * rand.nextDouble()))) % 255,
75
                                ((int) (255*div + (numreg * rand.nextDouble()))) % 255);
76
                return new SingleSymbolLegend(
77
                                SymbologyFactory.createDefaultSymbolByShapeType(shapeType, randomColor));
78

    
79
        }
80

    
81
        /**
82
         * Crea un objeto VectorialUniqueValueLegend vac?o, dispuesto para cargar
83
         * s?mbolos
84
         *
85
         * @param shapeType Tipo de shape.
86
         *
87
         * @return VectorialUniqueValueLegend.
88
         */
89
        public static VectorialUniqueValueLegend createVectorialUniqueValueLegend(
90
                int shapeType) {
91
                return new VectorialUniqueValueLegend(shapeType);
92
        }
93

    
94
        /**
95
         * Crea un objeto VectorialIntervalLegend vac?o, dispuesto para cargar
96
         * s?mbolos
97
         *
98
         * @param shapeType tipo de shape.
99
         *
100
         * @return VectorialIntervalLegend
101
         */
102
        public static VectorialIntervalLegend createVectorialIntervalLegend(
103
                int shapeType) {
104
                return new VectorialIntervalLegend(shapeType);
105
        }
106

    
107
        /**
108
         * Crea un renderer con la informaci?n contenida en el objeto XMLEntity
109
         *
110
         * @param xml XMLEntity.
111
         *
112
         * @return VectorialLegend
113
         *
114
         * @throws XMLException
115
         */
116
        public static IVectorLegend createFromXML(XMLEntity xml)
117
                throws XMLException {
118
                //TODO Implementar bien
119
                try {
120
                        IVectorLegend vl = null;
121
                        Class clase = Class.forName(xml.getStringProperty("className"));
122
                        vl = (IVectorLegend) clase.newInstance();
123
                        vl.setXMLEntity(xml);
124

    
125
                        return vl;
126
                } catch (ClassNotFoundException e) {
127
                        throw new XMLLegendException(e);
128
                } catch (InstantiationException e) {
129
                        throw new XMLLegendException(e);
130
                } catch (IllegalAccessException e) {
131
                        throw new XMLLegendException(e);
132
                }
133
        }
134

    
135
        /**
136
         * Clona la leyenda.
137
         *
138
         * @param l VectorialLegend a clonar.
139
         *
140
         * @return VectorialLegend cloando.
141
         *
142
         * @throws XMLException
143
         * @throws ReadException
144
         */
145
        public static IVectorLegend cloneLegend(IVectorLegend l)
146
                throws XMLException, ReadException{
147
                return createFromXML(l.getXMLEntity());
148
        }
149
}