Revision 2006

View differences:

org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.60/buildNumber.properties
1
#Fri Oct 13 09:53:22 CEST 2017
2
buildNumber=64
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.60/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.60/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.geom.GeometryLocator;
97
import org.gvsig.fmap.geom.GeometryManager;
98
import org.gvsig.fmap.mapcontext.MapContextLocator;
99
import org.gvsig.fmap.mapcontext.MapContextManager;
100
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
101
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend;
102
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
103
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol;
104
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
105
import org.gvsig.symbology.fmap.symbols.DotDensityFillSymbol;
106
import org.gvsig.tools.ToolsLocator;
107
import org.gvsig.tools.dynobject.DynStruct;
108
import org.gvsig.tools.persistence.PersistenceManager;
109
import org.gvsig.tools.persistence.PersistentState;
110
import org.gvsig.tools.persistence.exception.PersistenceException;
111
import org.gvsig.tools.util.Callable;
112

  
113

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

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

  
140

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

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

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

  
172
    public void saveToState(PersistentState state) throws PersistenceException {
173

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

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

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

  
215
		return fillsym.getOutline();
216
	}
217

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

  
234

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

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

  
245
		this.dotColor = color;
246

  
247
	}
248

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

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

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

  
306
	}
307

  
308
	/**
309
	 * Sets the size of the dot that is used in the dot density legend
310
	 */
311
	public void setDotSize(double value) {
312
		DotDensityFillSymbol sym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
313
		getLayer(DOT_DENSITY_LAYER_INDEX);
314
		sym.setDotSize(value);
315
	}
316
	
317
	
318
    public static boolean isPolygonal(int ty) {
319
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
320
        return geomManager.isSubtype(Geometry.TYPES.MULTISURFACE, ty) || 
321
            geomManager.isSubtype(Geometry.TYPES.SURFACE, ty);
322
    }
323

  
324
    // =============================
325
    
326
    public static class RegisterPersistence implements Callable {
327

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

  
352
    }
353

  
354
    public static class RegisterLegend implements Callable {
355

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

  
360
            manager.registerLegend(
361
                DOT_DENSITY_LEGEND_NAME,
362
                DotDensityLegend.class);
363

  
364
            return Boolean.TRUE;
365
        }
366

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

  
378

  
379
}
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.60/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.geom.GeometryLocator;
107
import org.gvsig.fmap.geom.GeometryManager;
108
import org.gvsig.fmap.geom.primitive.Point;
109
import org.gvsig.fmap.geom.primitive.Polygon;
110
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
111
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
112
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.AbstractFillSymbol;
113
import org.gvsig.tools.ToolsLocator;
114
import org.gvsig.tools.dynobject.DynStruct;
115
import org.gvsig.tools.persistence.PersistenceManager;
116
import org.gvsig.tools.persistence.PersistentState;
117
import org.gvsig.tools.persistence.exception.PersistenceException;
118
import org.gvsig.tools.task.Cancellable;
119
import org.gvsig.tools.util.Callable;
120
import org.slf4j.Logger;
121
import org.slf4j.LoggerFactory;
122

  
123
/**
124
 * <p>
125
 * Symbol that draws a set of points within a polygon. The amount of points is
126
 * defined by the field dotCount.<br>
127
 * </p>
128
 * <p>
129
 * This symbol only draws the points. The outline and the fill of the polygon is
130
 * handled by a SimpleFillSymboll where a DotDensityFillSymbol should be
131
 * embedded.<br>
132
 * </p>
133
 * @author jaume dominguez faus - jaume.dominguez@iver.es
134
 *
135
 */
136
public class DotDensityFillSymbol extends AbstractFillSymbol {
137
    private static final Logger logger = LoggerFactory.getLogger(DotDensityFillSymbol.class);
138
    public static final String
139
    DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME =
140
        "DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME";
141

  
142
	private int  dotCount;
143
	private double dotSize;
144
	private double dotSpacing;
145
	private Color dotColor = Color.BLACK;
146

  
147
	private boolean fixedPlacement;
148
	private PrintRequestAttributeSet properties;
149
	private GeometryManager geoManager=GeometryLocator.getGeometryManager();
150

  
151
	public DotDensityFillSymbol() {
152
		super();
153
	}
154

  
155
	public ISymbol getSymbolForSelection() {
156
		return this; // the selection color is applied in the SimpleFillSymbol
157
	}
158

  
159
    public void draw(Graphics2D g, AffineTransform atr,
160
        Geometry theGeom, Feature f, Cancellable cancel) {
161

  
162
        try {
163
            Geometry clo_geo = theGeom.cloneGeometry();
164
            clo_geo.transform(atr);
165

  
166
            Point interiorPoint=geoManager.createPoint(0, 0, Geometry.SUBTYPES.GEOM2D);
167
            int maxIntentos = 35;
168
            int width = clo_geo.getBounds().width;
169
            int height = clo_geo.getBounds().height;
170
            int minx = clo_geo.getBounds().x;
171
            int miny = clo_geo.getBounds().y;
172
            Random random = new Random();
173
            g.setClip(clo_geo.getShape());
174
            g.setColor(getDotColor());
175
            g.setBackground(null);
176

  
177
            int size = (int) dotSize;
178
            for (int i = 0; (cancel==null || !cancel.isCanceled()) && i < dotCount; i++) {
179
                int x,y;
180
                int intentos = 0;
181
                /* Introducimos este bucle para procurar que los puntos
182
                 * queden dentro del shape. Le ponemos adem?s un
183
                 * numero m?ximo de intentos para evitar las posibilidad de
184
                 * un bucle infinito o excesivamente reiterativo.
185
                 */
186
                do{
187
                    x = (int) Math.abs(random.nextDouble() * width);
188
                    y = (int) Math.abs(random.nextDouble() * height);
189
                    x = x + minx;
190
                    y = y + miny;
191
                    intentos++;
192
                    interiorPoint.setX(x);
193
                    interiorPoint.setY(y);
194
                }  while (intentos<maxIntentos && !clo_geo.contains(interiorPoint));
195
                g.fillRect(x, y, size, size);
196
            }
197
            g.setClip(null);
198

  
199
        } catch (Exception e) {
200
            logger.warn("An error has been produced drawing density points for : "+theGeom.toString());
201
        }
202
	}
203

  
204
    public void saveToState(PersistentState state) throws PersistenceException {
205

  
206
        super.saveToState(state);
207

  
208
        // color
209
        Color c = getDotColor();
210
        if (c == null) {
211
            c = Color.BLACK;
212
        }
213

  
214
        state.set("dotColor", c);
215
        state.set("dotCount", dotCount);
216
        state.set("dotSize", dotSize);
217
        state.set("dotSpacing", dotSpacing);
218
    }
219

  
220

  
221
	public int getSymbolType() {
222
		return Geometry.TYPES.SURFACE;
223
	}
224

  
225
    public void drawInsideRectangle(Graphics2D g,
226
        AffineTransform scaleInstance,
227
        Rectangle r,
228
        PrintAttributes properties) throws SymbolDrawingException {
229

  
230
		int x = r.x;
231
		int y = r.y;
232
		int width = r.width;
233
		int height= r.height;
234
		int size = height / 5;
235
		g.setColor(getDotColor());
236
		g.setBackground(null);
237
		g.fillRect((int) (x+width*0.2), (int) (y+height*0.2), size, size);
238
		g.fillRect((int) (x+width*0.25), (int) (y+height*0.7), size, size);
239
		g.fillRect((int) (x+width*0.35), (int) (y+height*0.5), size, size);
240
		g.fillRect((int) (x+width*0.6), (int) (y+height*0.1), size, size);
241
		g.fillRect((int) (x+width*0.7), (int) (y+height*0.8), size, size);
242
		g.fillRect((int) (x+width*0.8), (int) (y+height*0.3), size, size);
243
		g.fillRect((int) (x+width*0.9), (int) (y+height*0.6), size, size);
244
	}
245

  
246
    public void loadFromState(PersistentState state)
247
        throws PersistenceException {
248

  
249
        super.loadFromState(state);
250

  
251
        Object obj_col = state.get("dotColor");
252
        this.setDotColor((Color) obj_col);
253

  
254
        this.setDotCount(state.getInt("dotCount"));
255
        this.setDotSize(state.getDouble("dotSize"));
256
        this.setDotSpacing(state.getDouble("dotSpacing"));
257
    }
258

  
259

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

  
268
	/**
269
	 * @param dotCount
270
	 * @uml.property  name="dotCount"
271
	 */
272
	public void setDotCount(int dotCount) {
273
		this.dotCount = dotCount;
274
	}
275

  
276
	/**
277
	 * @return
278
	 * @uml.property  name="dotSize"
279
	 */
280
	public double getDotSize() {
281
		return dotSize;
282
	}
283

  
284
	public void setDotSize(double dotSize) {
285
		this.dotSize = dotSize;
286
	}
287

  
288
	/**
289
	 * @return
290
	 * @uml.property  name="dotSpacing"
291
	 */
292
	public double getDotSpacing() {
293
		return dotSpacing;
294
	}
295

  
296
	/**
297
	 * @param dotSpacing
298
	 * @uml.property  name="dotSpacing"
299
	 */
300
	public void setDotSpacing(double dotSpacing) {
301
		this.dotSpacing = dotSpacing;
302
	}
303

  
304
	public Color getDotColor() {
305
		return dotColor;
306
	}
307

  
308
	public void setDotColor(Color dotColor) {
309
		this.dotColor = dotColor;
310
	}
311

  
312
    /* (non-Javadoc)
313
     * @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)
314
     */
315
    public void print(Graphics2D g, AffineTransform at, Geometry shape,
316
        PrintAttributes prop) {
317

  
318
        // this.properties.=prop;
319
        draw(g, at, shape, null, null);
320
        // this.properties=null;
321

  
322
    }
323

  
324
    public static class RegisterPersistence implements Callable {
325

  
326
        public Object call() throws Exception {
327
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
328
            if( manager.getDefinition(
329
                DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME)==null ) {
330
                DynStruct definition = manager.addDefinition(
331
                    DotDensityFillSymbol.class,
332
                        DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME,
333
                        DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME +
334
                        " Persistence definition",
335
                        null,
336
                        null
337
                );
338

  
339
                // Extend the Symbol base definition
340
                definition.extend(manager.getDefinition(
341
                    AbstractFillSymbol.FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME));
342

  
343
                definition.addDynFieldObject("dotColor").setMandatory(true)
344
                .setClassOfValue(Color.class);
345
                definition.addDynFieldInt("dotCount").setMandatory(true);
346
                definition.addDynFieldDouble("dotSize").setMandatory(true);
347
                definition.addDynFieldDouble("dotSpacing").setMandatory(true);
348
            }
349
            return Boolean.TRUE;
350
        }
351

  
352
    }
353

  
354

  
355
}
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.60/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(
554
			    Messages.getText("dot_size"), aux);
555
			aux = new JPanel(layout);
556
			aux.add(getNmbrDotValue());
557
			densityButtonsPanel.addComponent(
558
			    Messages.getText("dot_value"), aux);
559
			aux = new JPanel(layout);
560
			aux.add(getDotColorChooserPanel());
561
			densityButtonsPanel.addComponent(
562
			    Messages.getText("color"), aux);
563
			aux = new JPanel(layout);
564
			aux.add(getBackgroundColorChooserPanel());
565
			densityButtonsPanel.addComponent(
566
			    Messages.getText("background_color"), aux);
567
			aux = new JPanel(layout);
568
			aux.add(getBtnOutline());
569
			densityButtonsPanel.addComponent(
570
			    Messages.getText("outline"), aux);
571
		}
572
		return densityButtonsPanel;
573
	}
574

  
575
	private ColorChooserPanel getBackgroundColorChooserPanel() {
576
		if (jccBackground == null) {
577
			jccBackground = new ColorChooserPanel() ;
578
			jccBackground.setColor(Color.WHITE);
579
			jccBackground.setAlpha(255);
580
		}
581
		return jccBackground;
582
	}
583

  
584
	private JSymbolPreviewButton getBtnOutline() {
585
		if (btnOutline == null) {
586
			btnOutline = new JSymbolPreviewButton(Geometry.TYPES.CURVE);
587
			btnOutline.setPreferredSize(new Dimension(100, 35));
588
		}
589
		return btnOutline;
590
	}
591

  
592
	/**
593
	 * This method initializes pnlDensities
594
	 *
595
	 * @return javax.swing.JPanel
596
	 */
597
	private JPanel getPnlDensities() {
598
		if (pnlDensities == null) {
599
			pnlDensities = new JPanel(new BorderLayout(5,0));
600
			pnlDensities.setBorder(BorderFactory.createTitledBorder(null,
601
			    Messages.getText("densities")));
602
			JPanel aux2 = new JPanel();
603
			JPanel aux;
604
			aux = new JPanel(new GridLayout(1,3));
605
			aux.add(new JLabel(Messages.getText("low")));
606
			aux.add(new JLabel(Messages.getText("medium")));
607
			aux.add(new JLabel(Messages.getText("high")));
608

  
609
			aux2.add(aux);
610

  
611
			aux = new JPanel(new GridLayout(1,3));
612
			aux.add(getRdBtnLow());
613
			aux.add(getRdBtnMedium());
614
			aux.add(getRdBtnHigh());
615

  
616
			aux2.add(aux);
617
			aux2.setLayout(new BoxLayout(aux2, BoxLayout.Y_AXIS));
618

  
619
			pnlDensities.add(aux2, BorderLayout.NORTH);
620
			pnlDensities.add(getSldDensity(), BorderLayout.CENTER);
621
			pnlDensities.add(getDensityButtonsPanel(), BorderLayout.SOUTH);
622

  
623
			ButtonGroup group = new ButtonGroup();
624
			group.add(getRdBtnHigh());
625
			group.add(getRdBtnLow());
626
			group.add(getRdBtnMedium());
627
			getRdBtnMedium().setSelected(true);
628
		}
629
		return pnlDensities;
630
	}
631

  
632

  
633
	/**
634
	 * This method initializes cmbLegendField
635
	 *
636
	 * @return javax.swing.JComboBox
637
	 */
638
	private JComboBox getCmbLegendField() {
639
		if (cmbLegendField == null) {
640
			cmbLegendField = new JComboBox();
641
			cmbLegendField.addActionListener(cmbAction);
642
		}
643
		return cmbLegendField;
644
	}
645

  
646
	/**
647
	 * This method initializes rdBtnHigh
648
	 *
649
	 * @return javax.swing.JRadioButton
650
	 */
651
	private JRadioButton getRdBtnHigh() {
652
		if (rdBtnHigh == null) {
653
		    Icon ic = IconThemeHelper.getImageIcon(
654
		        "legend-dot-density-high-density-sample");
655
			rdBtnHigh = new JRadioButton(ic);
656
			rdBtnHigh.addActionListener(buttonsListener);
657
		}
658
		return rdBtnHigh;
659
	}
660

  
661
	/**
662
	 * This method initializes rdBtnMedium
663
	 *
664
	 * @return javax.swing.JRadioButton
665
	 */
666
	private JRadioButton getRdBtnMedium() {
667
		if (rdBtnMedium == null) {
668
            Icon ic = IconThemeHelper.getImageIcon(
669
                "legend-dot-density-medium-density-sample");
670
			rdBtnMedium = new JRadioButton(ic);
671
			rdBtnMedium.addActionListener(buttonsListener);
672
		}
673
		return rdBtnMedium;
674
	}
675

  
676
	/**
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff