Revision 381

View differences:

org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.10/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4

  
5
	<modelVersion>4.0.0</modelVersion>
6
	<artifactId>org.gvsig.legend.dotdensity.app.mainplugin</artifactId>
7
	<name>Vector legend: Dot density</name>
8
	<version>1.0.10</version>
9

  
10
  <parent>
11
      <groupId>org.gvsig</groupId>
12
      <artifactId>org.gvsig.desktop</artifactId>
13
      <version>2.0.107</version>
14
  </parent>
15

  
16
	<url>https://devel.gvsig.org/redmine/projects/gvsig-base-legends</url>
17

  
18
    <scm>
19
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-base-legends/org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.10</connection>
20
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-base-legends/org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.10</developerConnection>
21
        <url>scm:svn:https://devel.gvsig.org/svn/gvsig-base-legends/org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.10</url>
22
    </scm>
23
    <repositories>
24
      <repository>
25
        <id>gvsig-public-http-repository</id>
26
        <name>gvSIG maven public HTTP repository</name>
27
        <url>http://devel.gvsig.org/m2repo/j2se</url>
28
        <releases>
29
          <enabled>true</enabled>
30
          <updatePolicy>daily</updatePolicy>
31
          <checksumPolicy>warn</checksumPolicy>
32
        </releases>
33
        <snapshots>
34
          <enabled>true</enabled>
35
          <updatePolicy>daily</updatePolicy>
36
          <checksumPolicy>warn</checksumPolicy>
37
        </snapshots>
38
      </repository>
39
    </repositories>
40

  
41
	<description>Vector legend: Dot density. Only for polygon layers. Number of dots inside polygon is proportional to numeric field value.</description>
42
	<build>
43

  
44
        <plugins>
45
		    <plugin>
46
		      <artifactId>maven-release-plugin</artifactId>
47
		      <version>2.0</version>
48
		      <configuration>
49
		        <tagBase>https://devel.gvsig.org/svn/gvsig-base-legends/org.gvsig.legend.dotdensity.app.mainplugin/tags</tagBase>
50
		      </configuration>
51
		    </plugin>
52

  
53
        </plugins>
54
	</build>
55
	<dependencies>
56
		<dependency>
57
			<groupId>org.gvsig</groupId>
58
			<artifactId>org.gvsig.app.mainplugin</artifactId>
59
		</dependency>
60
        <dependency>
61
            <groupId>org.gvsig</groupId>
62
            <artifactId>org.gvsig.andami</artifactId>
63
        </dependency>
64
        <dependency>
65
            <groupId>org.gvsig</groupId>
66
            <artifactId>org.gvsig.symbology.lib.api</artifactId>
67
        </dependency>
68
        <dependency>
69
            <groupId>org.gvsig</groupId>
70
            <artifactId>org.gvsig.symbology.lib.impl</artifactId>
71
        </dependency>
72
        <dependency>
73
            <groupId>org.gvsig</groupId>
74
            <artifactId>org.gvsig.symbology.swing.api</artifactId>
75
        </dependency>
76
        <dependency>
77
            <groupId>org.gvsig</groupId>
78
            <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
79
        </dependency>
80
        <dependency>
81
            <groupId>org.gvsig</groupId>
82
            <artifactId>org.gvsig.utils</artifactId>
83
        </dependency>
84
        <dependency>
85
            <groupId>org.gvsig</groupId>
86
            <artifactId>org.gvsig.fmap.dal.api</artifactId>
87
        </dependency>
88

  
89
        <dependency>
90
            <groupId>org.gvsig</groupId>
91
            <artifactId>org.gvsig.i18n</artifactId>
92
        </dependency>
93

  
94
		<dependency>
95
            <groupId>org.gvsig</groupId>
96
            <artifactId>org.gvsig.fmap.geometry.api</artifactId>
97
        </dependency>
98

  
99
        <dependency>
100
            <groupId>org.gvsig</groupId>
101
            <artifactId>org.gvsig.tools.lib</artifactId>
102
        </dependency>
103
        <dependency>
104
            <groupId>org.gvsig</groupId>
105
            <artifactId>org.gvsig.ui</artifactId>
106
        </dependency>
107
        <dependency>
108
            <groupId>org.gvsig</groupId>
109
            <artifactId>org.gvsig.projection.api</artifactId>
110
        </dependency>
111
        <dependency>
112
            <groupId>org.gvsig</groupId>
113
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
114
        </dependency>
115

  
116
        <dependency>
117
            <groupId>org.gvsig</groupId>
118
            <artifactId>org.gvsig.compat.api</artifactId>
119
        </dependency>
120

  
121

  
122

  
123
	</dependencies>
124

  
125
	<properties>
126
	    <gvsig.package.info.categories>View,Vector,Symbology</gvsig.package.info.categories>
127
        <gvsig.package.info.official>true</gvsig.package.info.official>
128
        <gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.1.0-A</gvsig.package.info.dependencies>
129
        <gvsig.package.info.state>testing</gvsig.package.info.state>
130
		<gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-base-legends/pool</gvsig.package.info.poolURL>
131
	</properties>
132
</project>
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.10/buildNumber.properties
1
#Sat Oct 24 14:07:41 CEST 2015
2
buildNumber=14
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.10/src/main/assembly/gvsig-plugin-package.xml
1
<!--
2

  
3
    gvSIG. Desktop Geographic Information System.
4

  
5
    Copyright (C) 2007-2013 gvSIG Association.
6

  
7
    This program is free software; you can redistribute it and/or
8
    modify it under the terms of the GNU General Public License
9
    as published by the Free Software Foundation; either version 3
10
    of the License, or (at your option) any later version.
11

  
12
    This program is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU General Public License for more details.
16

  
17
    You should have received a copy of the GNU General Public License
18
    along with this program; if not, write to the Free Software
19
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
    MA  02110-1301, USA.
21

  
22
    For any additional information, do not hesitate to contact us
23
    at info AT gvsig.com, or visit our website www.gvsig.com.
24

  
25
-->
26
<assembly>
27
  <id>gvsig-plugin-package</id>
28
  <formats>
29
    <format>zip</format>
30
  </formats>
31
  <baseDirectory>${project.artifactId}</baseDirectory>
32
  <includeBaseDirectory>true</includeBaseDirectory>
33
  <files>
34
    <file>
35
      <source>target/${project.artifactId}-${project.version}.jar</source>
36
      <outputDirectory>lib</outputDirectory>
37
    </file>
38
    <file>
39
      <source>target/package.info</source>
40
    </file>
41
  </files>
42

  
43
  <fileSets>
44
    <fileSet>
45
      <directory>src/main/resources-plugin</directory>
46
      <outputDirectory>.</outputDirectory>
47
    </fileSet>
48
  </fileSets>
49

  
50
<!-- No dependencies
51
  <dependencySets>
52
    <dependencySet>
53
      <useProjectArtifact>false</useProjectArtifact>
54
      <useTransitiveDependencies>false</useTransitiveDependencies>
55
      <outputDirectory>lib</outputDirectory>
56
      <includes>
57
		<include>...</include>
58
      </includes>
59
    </dependencySet>
60
  </dependencySets>
61
-->
62

  
63
</assembly>
64

  
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.10/src/main/java/org/gvsig/symbology/fmap/symbols/DotDensityFillSymbol.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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

  
42
/* CVS MESSAGES:
43
*
44
* $Id: DotDensityFillSymbol.java 13953 2007-09-21 12:26:04Z jaume $
45
* $Log$
46
* Revision 1.8  2007-09-21 12:25:32  jaume
47
* cancellation support extended down to the IGeometry and ISymbol level
48
*
49
* Revision 1.7  2007/09/18 14:50:31  caballero
50
* Leyendas sobre el Layout
51
*
52
* Revision 1.6  2007/03/26 14:24:24  jaume
53
* IPrintable refactored
54
*
55
* Revision 1.5  2007/03/09 11:20:56  jaume
56
* Advanced symbology (start committing)
57
*
58
* Revision 1.3.2.4  2007/02/21 16:09:02  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.3.2.3  2007/02/16 10:54:12  jaume
62
* multilayer splitted to multilayerline, multilayermarker,and  multilayerfill
63
*
64
* Revision 1.3.2.2  2007/02/15 16:23:44  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.3.2.1  2007/02/09 07:47:04  jaume
68
* Isymbol moved
69
*
70
* Revision 1.3  2007/01/12 10:08:26  jaume
71
* *** empty log message ***
72
*
73
* Revision 1.2  2007/01/10 16:39:41  jaume
74
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
75
*
76
* Revision 1.1  2007/01/10 16:31:36  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.4  2006/11/14 11:10:27  jaume
80
* *** empty log message ***
81
*
82
* Revision 1.3  2006/11/13 09:15:23  jaume
83
* javadoc and some clean-up
84
*
85
* Revision 1.2  2006/11/09 18:39:05  jaume
86
* *** empty log message ***
87
*
88
* Revision 1.1  2006/11/09 10:22:50  jaume
89
* *** empty log message ***
90
*
91
*
92
*/
93
package org.gvsig.symbology.fmap.symbols;
94

  
95
import java.awt.Color;
96
import java.awt.Graphics2D;
97
import java.awt.Rectangle;
98
import java.awt.geom.AffineTransform;
99
import java.util.Random;
100

  
101
import javax.print.attribute.PrintRequestAttributeSet;
102

  
103
import org.gvsig.compat.print.PrintAttributes;
104
import org.gvsig.fmap.dal.feature.Feature;
105
import org.gvsig.fmap.geom.Geometry;
106
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
107
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
108
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.AbstractFillSymbol;
109
import org.gvsig.tools.ToolsLocator;
110
import org.gvsig.tools.dynobject.DynStruct;
111
import org.gvsig.tools.persistence.PersistenceManager;
112
import org.gvsig.tools.persistence.PersistentState;
113
import org.gvsig.tools.persistence.exception.PersistenceException;
114
import org.gvsig.tools.task.Cancellable;
115
import org.gvsig.tools.util.Callable;
116

  
117
/**
118
 * <p>
119
 * Symbol that draws a set of points within a polygon. The amount of points is
120
 * defined by the field dotCount.<br>
121
 * </p>
122
 * <p>
123
 * This symbol only draws the points. The outline and the fill of the polygon is
124
 * handled by a SimpleFillSymboll where a DotDensityFillSymbol should be
125
 * embedded.<br>
126
 * </p>
127
 * @author jaume dominguez faus - jaume.dominguez@iver.es
128
 *
129
 */
130
public class DotDensityFillSymbol extends AbstractFillSymbol {
131
    
132
    public static final String
133
    DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME =
134
        "DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME";
135
    
136
	private int  dotCount;
137
	private double dotSize;
138
	private double dotSpacing;
139
	private Color dotColor = Color.BLACK;
140
	
141
	private boolean fixedPlacement;
142
	private PrintRequestAttributeSet properties;
143

  
144
	public DotDensityFillSymbol() {
145
		super();
146
	}
147

  
148
	public ISymbol getSymbolForSelection() {
149
		return this; // the selection color is applied in the SimpleFillSymbol
150
	}
151

  
152
    public void draw(Graphics2D g, AffineTransform atr,
153
        Geometry theGeom, Feature f, Cancellable cancel) {
154
	    
155
        Geometry clo_geo = theGeom.cloneGeometry();
156
        clo_geo.transform(atr);
157
        
158
		int maxIntentos = 35;
159
		int width = clo_geo.getBounds().width;
160
		int height = clo_geo.getBounds().height;
161
		int minx = clo_geo.getBounds().x;
162
		int miny = clo_geo.getBounds().y;
163
		Random random = new Random();
164
		g.setClip(clo_geo);
165
		g.setColor(getDotColor());
166
		g.setBackground(null);
167
		int size = (int) dotSize;
168
		for (int i = 0; (cancel==null || !cancel.isCanceled()) && i < dotCount; i++) {
169
			int x,y;
170
			int intentos = 0;
171
			/* Introducimos este bucle para procurar que los puntos
172
			 * queden dentro del shape. Le ponemos adem?s un
173
			 * numero m?ximo de intentos para evitar las posibilidad de
174
			 * un bucle infinito o excesivamente reiterativo.
175
			*/
176
			do{
177
				x = (int) Math.abs(random.nextDouble() * width);
178
				y = (int) Math.abs(random.nextDouble() * height);
179
				x = x + minx;
180
				y = y + miny;
181
				intentos++;
182
			} while (intentos<maxIntentos && !clo_geo.contains(x, y));
183
			g.fillRect(x, y, size, size);
184
		}
185
		g.setClip(null);
186
	}
187

  
188
    public void saveToState(PersistentState state) throws PersistenceException {
189

  
190
        super.saveToState(state);
191
        
192
        // color
193
        Color c = getDotColor();
194
        if (c == null) {
195
            c = Color.BLACK;
196
        }
197
        
198
        state.set("dotColor", c);
199
        state.set("dotCount", dotCount);
200
        state.set("dotSize", dotSize);
201
        state.set("dotSpacing", dotSpacing);
202
    }
203

  
204

  
205
	public int getSymbolType() {
206
		return Geometry.TYPES.SURFACE;
207
	}
208

  
209
    public void drawInsideRectangle(Graphics2D g,
210
        AffineTransform scaleInstance,
211
        Rectangle r,
212
        PrintAttributes properties) throws SymbolDrawingException {
213
	    
214
		int x = r.x;
215
		int y = r.y;
216
		int width = r.width;
217
		int height= r.height;
218
		int size = height / 5;
219
		g.setColor(getDotColor());
220
		g.setBackground(null);
221
		g.fillRect((int) (x+width*0.2), (int) (y+height*0.2), size, size);
222
		g.fillRect((int) (x+width*0.25), (int) (y+height*0.7), size, size);
223
		g.fillRect((int) (x+width*0.35), (int) (y+height*0.5), size, size);
224
		g.fillRect((int) (x+width*0.6), (int) (y+height*0.1), size, size);
225
		g.fillRect((int) (x+width*0.7), (int) (y+height*0.8), size, size);
226
		g.fillRect((int) (x+width*0.8), (int) (y+height*0.3), size, size);
227
		g.fillRect((int) (x+width*0.9), (int) (y+height*0.6), size, size);
228
	}
229

  
230
    public void loadFromState(PersistentState state)
231
        throws PersistenceException {
232
        
233
        super.loadFromState(state);
234
        
235
        Object obj_col = state.get("dotColor");
236
        this.setDotColor((Color) obj_col);
237
        
238
        this.setDotCount(state.getInt("dotCount"));
239
        this.setDotSize(state.getDouble("dotSize"));
240
        this.setDotSpacing(state.getDouble("dotSpacing"));
241
    }
242

  
243

  
244
	/**
245
	 * @return
246
	 * @uml.property  name="dotCount"
247
	 */
248
	public int getDotCount() {
249
		return dotCount;
250
	}
251

  
252
	/**
253
	 * @param dotCount
254
	 * @uml.property  name="dotCount"
255
	 */
256
	public void setDotCount(int dotCount) {
257
		this.dotCount = dotCount;
258
	}
259

  
260
	/**
261
	 * @return
262
	 * @uml.property  name="dotSize"
263
	 */
264
	public double getDotSize() {
265
		return dotSize;
266
	}
267

  
268
	public void setDotSize(double dotSize) {
269
		this.dotSize = dotSize;
270
	}
271

  
272
	/**
273
	 * @return
274
	 * @uml.property  name="dotSpacing"
275
	 */
276
	public double getDotSpacing() {
277
		return dotSpacing;
278
	}
279

  
280
	/**
281
	 * @param dotSpacing
282
	 * @uml.property  name="dotSpacing"
283
	 */
284
	public void setDotSpacing(double dotSpacing) {
285
		this.dotSpacing = dotSpacing;
286
	}
287

  
288
	public Color getDotColor() {
289
		return dotColor;
290
	}
291

  
292
	public void setDotColor(Color dotColor) {
293
		this.dotColor = dotColor;
294
	}
295

  
296
    /* (non-Javadoc)
297
     * @see org.gvsig.fmap.mapcontext.rendering.symbols.IPrintable#print(java.awt.Graphics2D, java.awt.geom.AffineTransform, org.gvsig.fmap.geom.Geometry, org.gvsig.compat.print.PrintAttributes)
298
     */
299
    public void print(Graphics2D g, AffineTransform at, Geometry shape,
300
        PrintAttributes prop) {
301
        
302
        // this.properties.=prop;
303
        draw(g, at, shape, null, null);
304
        // this.properties=null;
305
        
306
    }
307
    
308
    public static class RegisterPersistence implements Callable {
309

  
310
        public Object call() throws Exception {
311
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
312
            if( manager.getDefinition(
313
                DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME)==null ) {
314
                DynStruct definition = manager.addDefinition(
315
                    DotDensityFillSymbol.class,
316
                        DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME,
317
                        DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME +
318
                        " Persistence definition",
319
                        null, 
320
                        null
321
                );
322

  
323
                // Extend the Symbol base definition
324
                definition.extend(manager.getDefinition(
325
                    AbstractFillSymbol.FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME));
326

  
327
                definition.addDynFieldObject("dotColor").setMandatory(true)
328
                .setClassOfValue(Color.class);
329
                definition.addDynFieldInt("dotCount").setMandatory(true);
330
                definition.addDynFieldDouble("dotSize").setMandatory(true);
331
                definition.addDynFieldDouble("dotSpacing").setMandatory(true);
332
            }
333
            return Boolean.TRUE;
334
        }
335
        
336
    }
337

  
338

  
339
}
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.10/src/main/java/org/gvsig/symbology/fmap/rendering/DotDensityLegend.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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

  
42
/* CVS MESSAGES:
43
 *
44
 * $Id: DotDensityLegend.java 14420 2007-10-04 11:23:36Z jvidal $
45
 * $Log$
46
 * Revision 1.6  2007-09-19 16:25:39  jaume
47
 * ReadExpansionFileException removed from this context and removed unnecessary imports
48
 *
49
 * Revision 1.5  2007/07/25 07:13:34  jaume
50
 * code style
51
 *
52
 * Revision 1.4  2007/05/17 09:32:06  jaume
53
 * *** empty log message ***
54
 *
55
 * Revision 1.3  2007/03/09 11:20:56  jaume
56
 * Advanced symbology (start committing)
57
 *
58
 * Revision 1.2.2.5  2007/02/21 07:34:09  jaume
59
 * labeling starts working
60
 *
61
 * Revision 1.2.2.4  2007/02/15 16:23:44  jaume
62
 * *** empty log message ***
63
 *
64
 * Revision 1.2.2.3  2007/02/12 15:15:20  jaume
65
 * refactored interval legend and added graduated symbol legend
66
 *
67
 * Revision 1.2.2.2  2007/02/09 07:47:04  jaume
68
 * Isymbol moved
69
 *
70
 * Revision 1.2.2.1  2007/01/26 13:48:17  jaume
71
 * *** empty log message ***
72
 *
73
 * Revision 1.2  2007/01/16 11:50:50  jaume
74
 * *** empty log message ***
75
 *
76
 * Revision 1.1  2007/01/10 16:39:41  jaume
77
 * ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
78
 *
79
 * Revision 1.2  2006/11/17 12:49:58  jaume
80
 * *** empty log message ***
81
 *
82
 * Revision 1.1  2006/11/14 12:30:26  jaume
83
 * *** empty log message ***
84
 *
85
 *
86
 */
87
package org.gvsig.symbology.fmap.rendering;
88

  
89
import java.awt.Color;
90

  
91
import org.slf4j.Logger;
92
import org.slf4j.LoggerFactory;
93

  
94
import org.gvsig.fmap.dal.feature.Feature;
95
import org.gvsig.fmap.geom.Geometry;
96
import org.gvsig.fmap.mapcontext.MapContextLocator;
97
import org.gvsig.fmap.mapcontext.MapContextManager;
98
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
99
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend;
100
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
101
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol;
102
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
103
import org.gvsig.symbology.fmap.symbols.DotDensityFillSymbol;
104
import org.gvsig.tools.ToolsLocator;
105
import org.gvsig.tools.dynobject.DynStruct;
106
import org.gvsig.tools.persistence.PersistenceManager;
107
import org.gvsig.tools.persistence.PersistentState;
108
import org.gvsig.tools.persistence.exception.PersistenceException;
109
import org.gvsig.tools.util.Callable;
110

  
111

  
112
/**
113
 *
114
 * Implements a legend where the magnitudes of a specific area of the
115
 * map are represented by the density of the points that are distributed
116
 * in the surface.
117
 *
118
 *
119
 * @author  jaume dominguez faus - jaume.dominguez@iver.es
120
 */
121
public class DotDensityLegend extends VectorialUniqueValueLegend {
122

  
123
    private static Logger logger = LoggerFactory.getLogger(
124
        DotDensityLegend.class);
125
        
126
    public static final String
127
    DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME = 
128
    "DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME";
129
    public static final String
130
    DOT_DENSITY_LEGEND_NAME = "DOT_DENSITY_LEGEND_NAME";
131
    
132
	private double dotValue;
133
	private Color dotColor = Color.BLACK;
134
	private Color backgroundColor = Color.WHITE;
135
	private static final int SIMPLE_FILL_LAYER_INDEX = 0;
136
	private static final int DOT_DENSITY_LAYER_INDEX = 1;
137

  
138

  
139
	public ISymbol getSymbolByValue(Object val) {
140
		MultiLayerFillSymbol sym = (MultiLayerFillSymbol) getDefaultSymbol();
141
		DotDensityFillSymbol densitySym = (DotDensityFillSymbol) sym.getLayer(DOT_DENSITY_LAYER_INDEX);
142
		
143
		if (val instanceof Number) {
144
		    Number dou = (Number) val;
145
	        densitySym.setDotCount(
146
	            (int) (dou.doubleValue()/dotValue));
147
	        return sym;
148
		} else {
149
		    logger.info("Error: Unexpected value in dot density legend: " + val);
150
		    return null;
151
		}
152
	}
153

  
154
	public ISymbol getSymbolByFeature(Feature feat) {
155
	    
156
	    String[] ff = this.getClassifyingFieldNames();
157
	    Object val = feat.get(ff[0]);
158
	    return this.getSymbolByValue(val);
159
	}
160

  
161
	/**
162
	 * Establishes the value for the dot used in the dot density legend
163
	 *
164
	 * @param dotValue
165
	 */
166
	public void setDotValue(double dotValue) {
167
		this.dotValue = dotValue;
168
	}
169

  
170
    public void saveToState(PersistentState state) throws PersistenceException {
171

  
172
        super.saveToState(state);
173
        state.set("dotValue", dotValue);
174
        state.set("dotColor", getDotColor());
175
        state.set("bgColor", getBGColor());
176
    }
177

  
178
    public void loadFromState(PersistentState state)
179
        throws PersistenceException {
180
        
181
        super.loadFromState(state);
182
        
183
        dotValue = state.getDouble("dotValue");
184
        Object obj_col = state.get("dotColor");
185
        this.setDotColor((Color) obj_col);
186
        obj_col = state.get("bgColor");
187
        this.setBGColor((Color) obj_col);
188
    }
189
	
190
	
191
	
192

  
193
	/**
194
	 * Returns the outline
195
	 *
196
	 * @return
197
	 */
198
	public ILineSymbol getOutline() {
199
		// defined by the SimpleFillSymbol layer
200
		ISymbol symbol = getDefaultSymbol();
201
		if (!(symbol instanceof IFillSymbol)){
202
			return null;
203
		}
204
		IFillSymbol fillsym = (IFillSymbol) symbol;
205
		if (fillsym instanceof MultiLayerFillSymbol){
206
			fillsym = (IFillSymbol) ((MultiLayerFillSymbol) fillsym).
207
			getLayer(SIMPLE_FILL_LAYER_INDEX);
208
		}
209
		if (fillsym == null){
210
			return null;
211
		}
212

  
213
		return fillsym.getOutline();
214
	}
215

  
216
	/**
217
	 * Returns the color for the dot used in the dot density legend.
218
	 * @return
219
	 */
220
	public Color getDotColor() {
221
//		try {
222
//			// defined by the DotDensitySymbol layer
223
//			DotDensityFillSymbol sym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
224
//			getLayer(DOT_DENSITY_LAYER_INDEX);
225
//			return sym.getDotColor();
226
//		} catch (NullPointerException npE) {
227
//			return null;
228
//		}
229
		return dotColor;
230
	}
231

  
232

  
233
	/**
234
	 * Sets the color for the dot used in the dot density legend.
235
	 * @return
236
	 */
237
	public void setDotColor(Color color){
238

  
239
//		DotDensityFillSymbol sym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
240
//		getLayer(DOT_DENSITY_LAYER_INDEX);
241
//		sym.setDotColor(color);
242

  
243
		this.dotColor = color;
244

  
245
	}
246

  
247
	/**
248
	 * Obtains the background color for the dot density legend
249
	 * @return
250
	 */
251
	public Color getBGColor() {
252
//		try {
253
//			// defined by the SimpleFillSymbol layer
254
//			IFillSymbol symbol = (IFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
255
//			getLayer(SIMPLE_FILL_LAYER_INDEX);
256
//			return symbol.getFillColor();
257
//		} catch (NullPointerException npE) {
258
//			return null;
259
//		}
260
		return backgroundColor;
261
	}
262

  
263
	/**
264
	 * Sets the background color for the dot density legend
265
	 * @return
266
	 */
267
	public void setBGColor(Color color) {
268
		this.backgroundColor = color;
269
	}
270
	/**
271
	 * Returns the value for the dot that is used in the dot density legend
272
	 * @return
273
	 */
274
	public double getDotValue() {
275
	    return this.dotValue;
276
	}
277
	/**
278
	 * Obtains the size of the dot that is used in the dot density legend
279
	 * @return
280
	 */
281
	public double getDotSize() {
282

  
283
		// defined by the SimpleFillSymbol layer
284
		ISymbol symbol = getDefaultSymbol();
285
		if (symbol == null){
286
			return -1;
287
		}
288
		if (symbol instanceof DotDensityFillSymbol){
289
			return ((DotDensityFillSymbol)symbol).getDotSize();
290
		}
291
		if (!(symbol instanceof IFillSymbol)){
292
			return -1;
293
		}
294
		IFillSymbol fillsym = (IFillSymbol) symbol;
295
		if (fillsym instanceof MultiLayerFillSymbol){
296
			fillsym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) fillsym).
297
			getLayer(DOT_DENSITY_LAYER_INDEX);
298
		}
299
		if (fillsym instanceof DotDensityFillSymbol){
300
			return ((DotDensityFillSymbol)fillsym).getDotSize();
301
		}
302
		return -1;
303

  
304
	}
305

  
306
	/**
307
	 * Sets the size of the dot that is used in the dot density legend
308
	 */
309
	public void setDotSize(double value) {
310
		DotDensityFillSymbol sym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
311
		getLayer(DOT_DENSITY_LAYER_INDEX);
312
		sym.setDotSize(value);
313
	}
314
	
315
	
316
    public static boolean isPolygonal(int ty) {
317
        if (ty == Geometry.TYPES.MULTISURFACE
318
            || ty == Geometry.TYPES.SURFACE
319
            ) {
320
            return true;
321
        } else {
322
            return false;
323
        }
324
    }
325
    
326
    // =============================
327
    
328
    public static class RegisterPersistence implements Callable {
329

  
330
        public Object call() throws Exception {
331
            
332
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
333
            if (manager.getDefinition(
334
                DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) {
335
                DynStruct definition = manager
336
                    .addDefinition(DotDensityLegend.class,
337
                        DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME,
338
                        DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME
339
                        + " Persistence definition", null, null);
340
                
341
                definition.extend(manager.getDefinition(
342
                    VectorialUniqueValueLegend
343
                    .VECTORIAL_UNIQUE_VALUE_LEGEND_PERSISTENCE_DEFINITION_NAME));
344
                
345
                definition.addDynFieldDouble("dotValue").setMandatory(true);
346
                definition.addDynFieldObject("dotColor")
347
                .setClassOfValue(Color.class).setMandatory(true);
348
                definition.addDynFieldObject("bgColor")
349
                .setClassOfValue(Color.class).setMandatory(true);
350
            }
351
            return Boolean.TRUE;
352
        }
353

  
354
    }
355

  
356
    public static class RegisterLegend implements Callable {
357

  
358
        public Object call() throws Exception {
359
            MapContextManager manager =
360
                MapContextLocator.getMapContextManager();
361

  
362
            manager.registerLegend(
363
                DOT_DENSITY_LEGEND_NAME,
364
                DotDensityLegend.class);
365

  
366
            return Boolean.TRUE;
367
        }
368

  
369
    }
370
    
371
    public Object clone() throws CloneNotSupportedException {
372
        
373
        DotDensityLegend resp = (DotDensityLegend) super.clone();
374
        resp.setDotColor(this.getDotColor());
375
        resp.setDotSize(this.getDotSize());
376
        resp.setDotValue(this.getDotValue());
377
        return resp;
378
    }
379

  
380

  
381
}
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.10/src/main/java/org/gvsig/symbology/gui/layerproperties/DotDensityPanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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

  
42
/* CVS MESSAGES:
43
 *
44
 * $Id: DotDensity.java 15647 2007-10-30 12:03:52Z jmvivo $
45
 * $Log$
46
 * Revision 1.11  2007-09-19 15:47:10  jaume
47
 * refactor name IVectorialLegend -> IVectorLegend and a method name as well
48
 *
49
 * Revision 1.10  2007/09/04 14:13:01  jaume
50
 * *** empty log message ***
51
 *
52
 * Revision 1.9  2007/05/21 10:38:27  jaume
53
 * *** empty log message ***
54
 *
55
 * Revision 1.8  2007/05/17 09:32:37  jaume
56
 * *** empty log message ***
57
 *
58
 * Revision 1.7  2007/05/10 09:46:45  jaume
59
 * Refactored legend interface names
60
 *
61
 * Revision 1.6  2007/05/08 15:45:31  jaume
62
 * *** empty log message ***
63
 *
64
 * Revision 1.5  2007/04/20 07:54:39  jaume
65
 * *** empty log message ***
66
 *
67
 * Revision 1.4  2007/04/20 07:24:56  jaume
68
 * *** empty log message ***
69
 *
70
 * Revision 1.3  2007/04/17 06:53:46  bsanchez
71
 * - Corregido fallo de Double.MIN_VALUE por Double.NEGATIVE_INFINITY comentado por Victor Olaya.
72
 *
73
 * Revision 1.2  2007/03/09 11:25:00  jaume
74
 * Advanced symbology (start committing)
75
 *
76
 * Revision 1.1.2.4  2007/02/21 07:35:14  jaume
77
 * *** empty log message ***
78
 *
79
 * Revision 1.1.2.3  2007/02/12 15:14:41  jaume
80
 * refactored interval legend and added graduated symbol legend
81
 *
82
 * Revision 1.1.2.2  2007/02/09 11:00:03  jaume
83
 * *** empty log message ***
84
 *
85
 * Revision 1.1.2.1  2007/01/26 13:49:03  jaume
86
 * *** empty log message ***
87
 *
88
 * Revision 1.4  2006/11/17 13:53:45  cesar
89
 * *** empty log message ***
90
 *
91
 * Revision 1.3  2006/11/17 12:50:36  jaume
92
 * tama๏ฟฝo de punto defecto 2
93
 *
94
 * Revision 1.2  2006/11/15 12:57:31  jaume
95
 * *** empty log message ***
96
 *
97
 * Revision 1.1  2006/11/14 11:10:27  jaume
98
 * *** empty log message ***
99
 *
100
 *
101
 */
102
package org.gvsig.symbology.gui.layerproperties;
103

  
104
import java.awt.BorderLayout;
105
import java.awt.Color;
106
import java.awt.ComponentOrientation;
107
import java.awt.Dimension;
108
import java.awt.FlowLayout;
109
import java.awt.GridLayout;
110
import java.awt.LayoutManager;
111
import java.awt.event.ActionEvent;
112
import java.awt.event.ActionListener;
113
import java.awt.event.ItemEvent;
114
import java.awt.event.ItemListener;
115
import java.text.NumberFormat;
116

  
117
import javax.swing.BorderFactory;
118
import javax.swing.BoxLayout;
119
import javax.swing.ButtonGroup;
120
import javax.swing.Icon;
121
import javax.swing.ImageIcon;
122
import javax.swing.JComboBox;
123
import javax.swing.JLabel;
124
import javax.swing.JOptionPane;
125
import javax.swing.JPanel;
126
import javax.swing.JRadioButton;
127
import javax.swing.JSlider;
128
import javax.swing.event.ChangeEvent;
129
import javax.swing.event.ChangeListener;
130

  
131
import org.slf4j.Logger;
132
import org.slf4j.LoggerFactory;
133

  
134
import org.gvsig.andami.IconThemeHelper;
135
import org.gvsig.app.ApplicationLocator;
136
import org.gvsig.app.gui.panels.ColorChooserPanel;
137
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel;
138
import org.gvsig.app.project.documents.view.legend.gui.JSymbolPreviewButton;
139
import org.gvsig.app.project.documents.view.legend.gui.Quantities;
140
import org.gvsig.fmap.dal.feature.Feature;
141
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
142
import org.gvsig.fmap.dal.feature.FeatureSet;
143
import org.gvsig.fmap.dal.feature.FeatureStore;
144
import org.gvsig.fmap.dal.feature.FeatureType;
145
import org.gvsig.fmap.geom.Geometry;
146
import org.gvsig.fmap.mapcontext.layers.FLayer;
147
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
148
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
149
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
150
import org.gvsig.gui.beans.swing.JNumberSpinner;
151
import org.gvsig.i18n.Messages;
152
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol;
153
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
154
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
155
import org.gvsig.symbology.fmap.rendering.DotDensityLegend;
156
import org.gvsig.symbology.fmap.symbols.DotDensityFillSymbol;
157
import org.gvsig.tools.dispose.DisposableIterator;
158

  
159
/**
160
 * This panel lets the user choose the dot density legend settings
161
 * (numeric field, density of points, etc)
162
 *
163
 * @author jaume dominguez faus - jaume.dominguez@iver.es
164
 * @param <JNumberSpinner>
165
 *
166
 */
167
public class DotDensityPanel extends JPanel implements ILegendPanel {
168

  
169
    private static Logger logger = LoggerFactory.getLogger(DotDensityPanel.class);
170

  
171
	private static final int MAX_VALUE_COUNT = 300;
172
	private FLyrVect layer;
173
	private JPanel northPanel = null;
174
	private GridBagLayoutPanel densityButtonsPanel = null;
175
	private JPanel pnlDensities = null;
176
	private JComboBox cmbLegendField = null;
177
	private JRadioButton rdBtnHigh = null;
178
	private JRadioButton rdBtnMedium = null;
179
	private JRadioButton rdBtnLow = null;
180
	private JNumberSpinner numDotSize = null;
181

  
182
	private JNumberSpinner nmbrDotValue = null;
183
	private JLabel lblLabellingField = null;
184
	private DotDensityLegend legend;
185

  
186
	private String theFieldName;
187
	private int theFieldType;
188

  
189
	private boolean initializing;
190
	private double max;
191
	private double maxDotSize = 0;
192
	private double b, a; // line function params where: y = bx + a
193
	private int theValueCount;
194

  
195

  
196
	private NumberFormat nf = NumberFormat.getInstance();
197
	{
198
		nf.setMaximumFractionDigits(3);
199
	}
200
	private MyListener cmbAction = new MyListener();
201

  
202
	private class MyListener implements ItemListener, ActionListener {
203
		public void itemStateChanged(ItemEvent e) {
204
			if (!initializing)
205
				doIt();
206
		}
207

  
208
		public void actionPerformed(ActionEvent e) {
209
			if (!initializing)
210
				doIt();
211
		}
212

  
213
		private void doIt() {
214
			int index = cmbLegendField.getSelectedIndex();
215
			try {
216
			    FeatureStore fsto = (FeatureStore) layer.getDataStore();
217
			    FeatureSet fset = fsto.getFeatureSet();
218
			    FeatureType fty = fsto.getDefaultFeatureType();
219

  
220
				if (index != -1) {
221
					theFieldName = (String) cmbLegendField.getSelectedItem();
222
				} else {
223
					theFieldName = (String) cmbLegendField.getItemAt(0);
224
				}
225

  
226
                FeatureAttributeDescriptor att =
227
                    fty.getAttributeDescriptor(theFieldName);
228
                theFieldType = att.getDataType().getType();
229

  
230
				long vc = 0;
231
				// (rowCount > MAX_VALUE_COUNT) ? MAX_VALUE_COUNT : (int) rowCount;
232

  
233
				double maxValue = -Double.MAX_VALUE;
234
				double minValue = Double.MAX_VALUE;
235

  
236
				DisposableIterator disp = fset.fastIterator();
237
				Feature fitem = null;
238
				double value = 0;
239

  
240
				int i = 0;
241
				while (i < MAX_VALUE_COUNT && disp.hasNext()) {
242

  
243
				    fitem = (Feature) disp.next();
244
				    value = fitem.getDouble(theFieldName);
245
                    if (value < minValue){
246
                        minValue = value;
247
                    }
248
                    if (value > maxValue){
249
                        maxValue = value;
250
                    }
251
				    // ==========
252
				    i++;
253
				}
254
				disp.dispose();
255
				theValueCount = i;
256
				if (theValueCount == 0) {
257
	                b = 0;
258
	                a = minValue;
259
				} else {
260
	                b = (maxValue - minValue)/(theValueCount);
261
	                a = minValue;
262
				}
263
				buttonsListener.actionPerformed(null);
264

  
265
			} catch (Exception ex) {
266
			    logger.info("Error while computing a,b.", ex);
267

  
268
			    ApplicationLocator.getManager().message(
269
			        Messages.getText("error") +
270
			        " (" + Messages.getText("dot_density") + ")\n\n"
271
			        + ex.getMessage(),
272
			        JOptionPane.ERROR_MESSAGE);
273
			}
274
		}
275
	}
276

  
277

  
278
	private ActionListener buttonsListener = new ActionListener() {
279
		public void actionPerformed(ActionEvent e) {
280
			int oldValue = getSldDensity().getValue();
281
			int newValue = 0;
282
			if (getRdBtnHigh().isSelected()) {
283
				newValue = 33;
284
			} else if (getRdBtnLow().isSelected()) {
285
				newValue = 66;
286
			} else if (getRdBtnMedium().isSelected()) {
287
				newValue = 50;
288
			}
289
			if (oldValue == newValue){
290
				sldListener.stateChanged(null);
291
			} else{
292
				getSldDensity().setValue(newValue);
293
			}
294
		}
295
	};
296
	private JPanel centerPanel = null;
297
	private JSlider sldDensity = null;
298

  
299
	private boolean dotValueChanging= false;
300

  
301
	private ChangeListener sldListener = new ChangeListener() {
302
		public void stateChanged(ChangeEvent e) {
303
			if (dotValueChanging){
304
				return;
305
			}
306

  
307
			dotValueChanging = true;
308
			double d = sldValueToDotValue(getSldDensity().getValue());
309
            nmbrDotValue.setDouble(d);
310
			dotValueChanging = false;
311
		}
312

  
313
	};
314

  
315

  
316
	private ActionListener nmbrDotValueListener = new ActionListener(){
317
		public void actionPerformed(ActionEvent e) {
318
			if (dotValueChanging){
319
				return;
320
			}
321

  
322
			dotValueChanging = true;
323
			double dotValue = getNmbrDotValue().getDouble();
324
			if (dotValue < 0) dotValue = 0;
325
			int result = dotValueToSldValue(dotValue);
326
			getSldDensity().setValue(result);
327
			dotValueChanging = false;
328
		}
329
	};
330

  
331
	private ColorChooserPanel jcc;
332
	private ILegend oldLegend;
333
	private JSymbolPreviewButton btnOutline;
334
	private ColorChooserPanel jccBackground;
335

  
336
	public DotDensityPanel() {
337
		super();
338
		initialize();
339
	}
340

  
341
	/**
342
	 * This method initializes this
343
	 *
344
	 */
345
	private void initialize() {
346
		this.setLayout(new BorderLayout());
347
		this.setSize(new java.awt.Dimension(492,278));
348
		this.add(getNorthPanel(), java.awt.BorderLayout.NORTH);
349
		this.add(getCenterPanel(), java.awt.BorderLayout.CENTER);
350
	}
351

  
352
	private double sldValueToDotValue(int value){
353
		int quantileIndex = (theValueCount*value)/100;
354
		double d = (b*quantileIndex+a); // /50; // ?por qu? el 50?
355
		return d;
356
	}
357

  
358
	private int dotValueToSldValue(double value){
359
		int quantileIndex = (int)Math.round((value-a)/b);
360
		int result = 100*quantileIndex/theValueCount;
361
		return result;
362
	}
363

  
364
	public void setData(FLayer lyr, ILegend legend) {
365
		this.layer = (FLyrVect) lyr;
366
        this.oldLegend = legend.cloneLegend();
367

  
368
		try {
369
			// Para evitar los campos no pertenecientes a la fuente original de la capa.
370
			// SelectableDataSource sds = layer.getSource().getRecordset();
371
			// FJP: Otra vez con soporte del join
372
			// SelectableDataSource sds = layer.getRecordset();
373
            FeatureStore fsto = (FeatureStore) layer.getDataStore();
374
            FeatureType fty = fsto.getDefaultFeatureType();
375
            FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors();
376

  
377
			initializing = true; // silents events to the combo box
378
			cmbLegendField.removeAllItems();
379
			for (int i = 0; i < atts.length; i++) {
380
				if (atts[i].getDataType().isNumeric()) {
381
					cmbLegendField.addItem(atts[i].getName());
382
				}
383
			}
384

  
385
			if (!(legend instanceof DotDensityLegend)) {
386
				legend = new DotDensityLegend();
387
				((DotDensityLegend) legend).setClassifyingFieldNames(
388
						new String[] {(String) cmbLegendField.getItemAt(0)});
389
				((DotDensityLegend) legend).setShapeType(layer.getShapeType());
390
			}
391

  
392
			DotDensityLegend theLegend = (DotDensityLegend) legend;
393

  
394
			initializing = false; // enables events to the combo box
395

  
396
			cmbLegendField.setSelectedItem(theLegend.getClassifyingFieldNames()[0]);
397
			try {
398
				getDotColorChooserPanel().setColor(theLegend.getDotColor());
399
			} catch (NullPointerException npEx) {
400
				getDotColorChooserPanel().setColor(Color.RED);
401
			}
402
			try {
403
				getBackgroundColorChooserPanel().setColor(theLegend.getBGColor());
404
			} catch (NullPointerException npEx) {
405
				getDotColorChooserPanel().setColor(Color.WHITE);
406
			}
407

  
408
			getBtnOutline().setSymbol(theLegend.getOutline());
409
			try {
410
				double dotValue = theLegend.getDotValue();
411
				if (dotValue <= 0)
412
					dotValue = sldValueToDotValue(50);//100;
413
				getNmbrDotValue().setDouble(dotValue);
414
				dotValueChanging = true;
415
				getSldDensity().setValue(dotValueToSldValue(dotValue));
416
				dotValueChanging = false;
417

  
418
			} catch (NullPointerException npEx) {
419
				getSldDensity().setValue(50);
420
			}
421
			try {
422
				double dotSize = theLegend.getDotSize();
423
				if (dotSize <= 0)
424
					dotSize = 2;
425
				getNumDotSize().setDouble(dotSize);
426
			} catch (NullPointerException npEx) {
427
				getNumDotSize().setDouble(3);
428
			}
429

  
430
		} catch (Exception e) {
431
			e.printStackTrace();
432
		}
433
	}
434

  
435
	public ILegend getLegend() {
436
		try {
437
			int shapeType = layer.getShapeType();
438

  
439
			// shapeType should be always polygon
440
			if (!DotDensityLegend.isPolygonal(shapeType)) {
441

  
442
                ApplicationLocator.getManager().message(
443
                    Messages.getText("cannot_apply_to_a_non_polygon_layer"),
444
                    JOptionPane.ERROR_MESSAGE);
445
                return null;
446
			}
447

  
448
			// gather values
449
			double dotValue;
450
			double dotSize;
451
			try {
452
//				dotValue = Double.parseDouble(nmbrDotValue.getText());
453
				dotValue = nmbrDotValue.getDouble();
454
			} catch (Exception e) {
455
//				dotValue = nf.parse(nmbrDotValue.getText()).doubleValue();
456
				dotValue = nmbrDotValue.getDouble();
457
			}
458
			if (dotValue == 0)
459
				dotValue = 1;
460
			try {
461
//				dotSize = Double.parseDouble(numDotSize.getText());
462
				dotSize = numDotSize.getDouble();
463
			} catch (Exception e) {
464
//				dotSize = nf.parse(numDotSize.getText()).doubleValue();
465
				dotSize = numDotSize.getDouble();
466
			}
467

  
468
			if (max/dotValue > 50000) {
469
				int option = JOptionPane.showConfirmDialog(this,
470
				    Messages.getText("looks_like_too_low_value_for_this_field_may_cause_system_to_run_slow"),
471
				    Messages.getText("warning"),
472
				    JOptionPane.OK_CANCEL_OPTION);
473
				if (option	== JOptionPane.CANCEL_OPTION)
474
					return oldLegend;
475
			}
476

  
477
			// create the density symbol with the values set above
478
			DotDensityFillSymbol densitySymbol = new DotDensityFillSymbol();
479
			densitySymbol.setDotSize(dotSize);
480
			densitySymbol.setDotColor(getDotColorChooserPanel().getColor());
481

  
482
			// create a simple-fill symbol over which the dot density will be drawn
483
			SimpleFillSymbol fillSymbol = new SimpleFillSymbol();
484
			fillSymbol.setFillColor(getBackgroundColorChooserPanel().getColor());
485
			fillSymbol.setOutline((ILineSymbol) getBtnOutline().getSymbol());
486

  
487
			// combine both the DotDensitySymbol and the SimpleFillSymbol in
488
			// MultiLayerSymbol so they will be paint as a unique ISymbol
489
			MultiLayerFillSymbol symbol = new MultiLayerFillSymbol();
490
			symbol.setDescription(
491
					"DotDensitySymbol" + Messages.getText("in_layer") +
492
					": '"+layer.getName()+"'");
493
			symbol.addLayer(fillSymbol);
494
			symbol.addLayer(densitySymbol);
495

  
496
			legend = new DotDensityLegend();
497
			legend.addSymbol(Messages.getText("theSymbol"), symbol);
498
			legend.setDefaultSymbol(symbol);
499
			legend.setDotValue(dotValue);
500

  
501
			legend.setClassifyingFieldNames(new String[] { theFieldName });
502
            legend.setClassifyingFieldTypes(new int[] { theFieldType });
503

  
504
			legend.setBGColor(getBackgroundColorChooserPanel().getColor());
505
			legend.setDotColor(getDotColorChooserPanel().getColor());
506

  
507
		} catch (Exception e) {
508

  
509
            ApplicationLocator.getManager().message(
510
                Messages.getText("could_not_setup_legend"),
511
                JOptionPane.ERROR_MESSAGE);
512
		}
513
		return legend;
514

  
515
	}
516

  
517
	/**
518
	 * This method initializes centerPanel
519
	 *
520
	 * @return javax.swing.JPanel
521
	 */
522
	private JPanel getNorthPanel() {
523
		if (northPanel == null) {
524
			lblLabellingField = new JLabel();
525
			lblLabellingField.setText(Messages.getText("labeling_field")+".");
526
			northPanel = new JPanel(new FlowLayout(FlowLayout.LEADING,15,0));
527
			northPanel.add(lblLabellingField, null);
528
			northPanel.add(getCmbLegendField(), null);
529

  
530
		}
531
		return northPanel;
532
	}
533

  
534
	private ColorChooserPanel getDotColorChooserPanel() {
535
		if (jcc == null) {
536
			jcc = new ColorChooserPanel() ;
537
			jcc.setAlpha(255);
538
		}
539
		return jcc;
540
	}
541

  
542
	/**
543
	 * This method initializes southPanel
544
	 *
545
	 * @return javax.swing.JPanel
546
	 */
547
	private JPanel getDensityButtonsPanel() {
548
		if (densityButtonsPanel == null) {
549
			densityButtonsPanel = new GridBagLayoutPanel();
550
			LayoutManager layout = new FlowLayout(FlowLayout.LEADING, 0,0);
551
			JPanel aux = new JPanel(layout);
552
			aux.add(getNumDotSize());
553
			densityButtonsPanel.addComponent(
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff