Revision 10068

View differences:

org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.240/buildNumber.properties
1
#Mon Mar 04 00:02:02 CET 2024
2
buildNumber=246
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.240/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.symbology.library.DotDensityLibrary
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.240/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.240/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
package org.gvsig.symbology.fmap.symbols;
43

  
44
import java.awt.Color;
45
import java.awt.Graphics2D;
46
import java.awt.Rectangle;
47
import java.awt.geom.AffineTransform;
48
import java.util.Random;
49
import javax.print.attribute.PrintRequestAttributeSet;
50
import org.gvsig.fmap.dal.feature.Feature;
51
import org.gvsig.fmap.geom.Geometry;
52
import org.gvsig.fmap.geom.GeometryLocator;
53
import org.gvsig.fmap.geom.GeometryManager;
54
import org.gvsig.fmap.geom.primitive.Point;
55
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
56
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.AbstractFillSymbol;
57
import org.gvsig.tools.ToolsLocator;
58
import org.gvsig.tools.dynobject.DynStruct;
59
import org.gvsig.tools.persistence.PersistenceManager;
60
import org.gvsig.tools.persistence.PersistentState;
61
import org.gvsig.tools.persistence.exception.PersistenceException;
62
import org.gvsig.tools.task.Cancellable;
63
import org.gvsig.tools.util.Callable;
64
import org.slf4j.Logger;
65
import org.slf4j.LoggerFactory;
66

  
67
/**
68
 * <p>
69
 * Symbol that draws a set of points within a polygon. The amount of points is
70
 * defined by the field dotCount.<br>
71
 * </p>
72
 * <p>
73
 * This symbol only draws the points. The outline and the fill of the polygon is
74
 * handled by a SimpleFillSymboll where a DotDensityFillSymbol should be
75
 * embedded.<br>
76
 * </p>
77
 *
78
 */
79
public class DotDensityFillSymbol extends AbstractFillSymbol {
80
    private static final Logger logger = LoggerFactory.getLogger(DotDensityFillSymbol.class);
81
    public static final String
82
    DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME =
83
        "DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME";
84

  
85
	private int  dotCount;
86
	private double dotSize;
87
	private double dotSpacing;
88
	private Color dotColor = Color.BLACK;
89

  
90
	public DotDensityFillSymbol() {
91
		super();
92
	}
93

  
94
    @Override
95
	public ISymbol getSymbolForSelection() {
96
		return this; // the selection color is applied in the SimpleFillSymbol
97
	}
98

  
99
    @Override
100
    public void draw(Graphics2D g, AffineTransform atr,
101
        Geometry theGeom, Feature f, Cancellable cancel, Rectangle r) {
102
        if(r != null){
103
            theGeom = getSampleGeometry(r);
104
        }
105

  
106
        try {
107
            Geometry clo_geo = theGeom.cloneGeometry();
108
            clo_geo.transform(atr);
109
            GeometryManager geoManager=GeometryLocator.getGeometryManager();
110
            Point interiorPoint=geoManager.createPoint(0, 0, Geometry.SUBTYPES.GEOM2D);
111
            int maxIntentos = 35;
112
            int width = clo_geo.getBounds().width;
113
            int height = clo_geo.getBounds().height;
114
            int minx = clo_geo.getBounds().x;
115
            int miny = clo_geo.getBounds().y;
116
            Random random = new Random();
117
            g.setClip(clo_geo.getShape());
118
            g.setColor(getDotColor());
119
            g.setBackground(null);
120

  
121
            int size = (int) dotSize;
122
            for (int i = 0; (cancel==null || !cancel.isCanceled()) && i < dotCount; i++) {
123
                int x,y;
124
                int intentos = 0;
125
                /* Introducimos este bucle para procurar que los puntos
126
                 * queden dentro del shape. Le ponemos adem?s un
127
                 * numero m?ximo de intentos para evitar las posibilidad de
128
                 * un bucle infinito o excesivamente reiterativo.
129
                 */
130
                do{
131
                    x = (int) Math.abs(random.nextDouble() * width);
132
                    y = (int) Math.abs(random.nextDouble() * height);
133
                    x = x + minx;
134
                    y = y + miny;
135
                    intentos++;
136
                    interiorPoint.setX(x);
137
                    interiorPoint.setY(y);
138
                }  while (intentos<maxIntentos && !clo_geo.contains(interiorPoint));
139
                if(!clo_geo.contains(interiorPoint)){
140
                    interiorPoint = clo_geo.getInteriorPoint();
141
                    x = (int) interiorPoint.getX();
142
                    y = (int) interiorPoint.getY();
143
                }
144
                
145
                g.fillRect(x, y, size, size);
146
            }
147
            g.setClip(null);
148

  
149
        } catch (Exception e) {
150
            logger.warn("An error has been produced drawing density points for : "+theGeom.toString());
151
        }
152
	}
153

  
154
    @Override
155
    public void saveToState(PersistentState state) throws PersistenceException {
156

  
157
        super.saveToState(state);
158

  
159
        // color
160
        Color c = getDotColor();
161
        if (c == null) {
162
            c = Color.BLACK;
163
        }
164

  
165
        state.set("dotColor", c);
166
        state.set("dotCount", dotCount);
167
        state.set("dotSize", dotSize);
168
        state.set("dotSpacing", dotSpacing);
169
    }
170

  
171

  
172
    @Override
173
	public int getSymbolType() {
174
		return Geometry.TYPES.SURFACE;
175
	}
176

  
177
    @Override
178
    public void loadFromState(PersistentState state)
179
        throws PersistenceException {
180

  
181
        super.loadFromState(state);
182

  
183
        Object obj_col = state.get("dotColor");
184
        this.setDotColor((Color) obj_col);
185

  
186
        this.setDotCount(state.getInt("dotCount"));
187
        this.setDotSize(state.getDouble("dotSize"));
188
        this.setDotSpacing(state.getDouble("dotSpacing"));
189
    }
190

  
191

  
192
	/**
193
	 * @return
194
	 * @uml.property  name="dotCount"
195
	 */
196
	public int getDotCount() {
197
		return dotCount;
198
	}
199

  
200
	/**
201
	 * @param dotCount
202
	 * @uml.property  name="dotCount"
203
	 */
204
	public void setDotCount(int dotCount) {
205
		this.dotCount = dotCount;
206
	}
207

  
208
	/**
209
	 * @return
210
	 * @uml.property  name="dotSize"
211
	 */
212
	public double getDotSize() {
213
		return dotSize;
214
	}
215

  
216
	public void setDotSize(double dotSize) {
217
		this.dotSize = dotSize;
218
	}
219

  
220
	/**
221
	 * @return
222
	 * @uml.property  name="dotSpacing"
223
	 */
224
	public double getDotSpacing() {
225
		return dotSpacing;
226
	}
227

  
228
	/**
229
	 * @param dotSpacing
230
	 * @uml.property  name="dotSpacing"
231
	 */
232
	public void setDotSpacing(double dotSpacing) {
233
		this.dotSpacing = dotSpacing;
234
	}
235

  
236
	public Color getDotColor() {
237
		return dotColor;
238
	}
239

  
240
	public void setDotColor(Color dotColor) {
241
		this.dotColor = dotColor;
242
	}
243

  
244
    public static class RegisterPersistence implements Callable {
245

  
246
        @Override
247
        public Object call() throws Exception {
248
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
249
            if( manager.getDefinition(
250
                DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME)==null ) {
251
                DynStruct definition = manager.addDefinition(
252
                    DotDensityFillSymbol.class,
253
                        DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME,
254
                        DOT_DENSITY_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME +
255
                        " Persistence definition",
256
                        null,
257
                        null
258
                );
259

  
260
                // Extend the Symbol base definition
261
                definition.extend(manager.getDefinition(
262
                    AbstractFillSymbol.FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME));
263

  
264
                definition.addDynFieldObject("dotColor").setMandatory(true)
265
                .setClassOfValue(Color.class);
266
                definition.addDynFieldInt("dotCount").setMandatory(true);
267
                definition.addDynFieldDouble("dotSize").setMandatory(true);
268
                definition.addDynFieldDouble("dotSpacing").setMandatory(true);
269
            }
270
            return Boolean.TRUE;
271
        }
272

  
273
    }
274

  
275

  
276
}
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.240/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
 */
20

  
21
package org.gvsig.symbology.fmap.rendering;
22

  
23
import java.awt.Color;
24

  
25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
27

  
28
import org.gvsig.fmap.dal.feature.Feature;
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.geom.GeometryLocator;
31
import org.gvsig.fmap.geom.GeometryManager;
32
import org.gvsig.fmap.mapcontext.MapContextLocator;
33
import org.gvsig.fmap.mapcontext.MapContextManager;
34
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
35
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend;
36
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
37
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol;
38
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
39
import org.gvsig.symbology.fmap.symbols.DotDensityFillSymbol;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.dynobject.DynStruct;
42
import org.gvsig.tools.persistence.PersistenceManager;
43
import org.gvsig.tools.persistence.PersistentState;
44
import org.gvsig.tools.persistence.exception.PersistenceException;
45
import org.gvsig.tools.util.Callable;
46

  
47

  
48
/**
49
 *
50
 * Implements a legend where the magnitudes of a specific area of the
51
 * map are represented by the density of the points that are distributed
52
 * in the surface.
53
 *
54
 *
55
 */
56
public class DotDensityLegend extends VectorialUniqueValueLegend {
57

  
58
    private static Logger logger = LoggerFactory.getLogger(
59
        DotDensityLegend.class);
60
        
61
    public static final String
62
    DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME = 
63
    "DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME";
64
    public static final String
65
    DOT_DENSITY_LEGEND_NAME = "DOT_DENSITY_LEGEND_NAME";
66
    
67
	private double dotValue;
68
	private Color dotColor = Color.BLACK;
69
	private Color backgroundColor = Color.WHITE;
70
	private static final int SIMPLE_FILL_LAYER_INDEX = 0;
71
	private static final int DOT_DENSITY_LAYER_INDEX = 1;
72

  
73

  
74
	public ISymbol getSymbolByValue(Object val) {
75
		MultiLayerFillSymbol sym = (MultiLayerFillSymbol) getDefaultSymbol();
76
		DotDensityFillSymbol densitySym = (DotDensityFillSymbol) sym.getLayer(DOT_DENSITY_LAYER_INDEX);
77
		
78
		if (val instanceof Number) {
79
		    Number dou = (Number) val;
80
	        densitySym.setDotCount(
81
	            (int) (dou.doubleValue()/dotValue));
82
	        return sym;
83
		} else {
84
		    logger.info("Error: Unexpected value in dot density legend: " + val);
85
		    return null;
86
		}
87
	}
88

  
89
	public ISymbol getSymbolByFeature(Feature feat) {
90
	    
91
	    String[] ff = this.getClassifyingFieldNames();
92
	    Object val = feat.get(ff[0]);
93
	    return this.getSymbolByValue(val);
94
	}
95

  
96
	/**
97
	 * Establishes the value for the dot used in the dot density legend
98
	 *
99
	 * @param dotValue
100
	 */
101
	public void setDotValue(double dotValue) {
102
		this.dotValue = dotValue;
103
	}
104

  
105
    public void saveToState(PersistentState state) throws PersistenceException {
106

  
107
        super.saveToState(state);
108
        state.set("dotValue", dotValue);
109
        state.set("dotColor", getDotColor());
110
        state.set("bgColor", getBGColor());
111
    }
112

  
113
    public void loadFromState(PersistentState state)
114
        throws PersistenceException {
115
        
116
        super.loadFromState(state);
117
        
118
        dotValue = state.getDouble("dotValue");
119
        Object obj_col = state.get("dotColor");
120
        this.setDotColor((Color) obj_col);
121
        obj_col = state.get("bgColor");
122
        this.setBGColor((Color) obj_col);
123
    }
124
	
125
	
126
	
127

  
128
	/**
129
	 * Returns the outline
130
	 *
131
	 * @return
132
	 */
133
	public ILineSymbol getOutline() {
134
		// defined by the SimpleFillSymbol layer
135
		ISymbol symbol = getDefaultSymbol();
136
		if (!(symbol instanceof IFillSymbol)){
137
			return null;
138
		}
139
		IFillSymbol fillsym = (IFillSymbol) symbol;
140
		if (fillsym instanceof MultiLayerFillSymbol){
141
			fillsym = (IFillSymbol) ((MultiLayerFillSymbol) fillsym).
142
			getLayer(SIMPLE_FILL_LAYER_INDEX);
143
		}
144
		if (fillsym == null){
145
			return null;
146
		}
147

  
148
		return fillsym.getOutline();
149
	}
150

  
151
	/**
152
	 * Returns the color for the dot used in the dot density legend.
153
	 * @return
154
	 */
155
	public Color getDotColor() {
156
//		try {
157
//			// defined by the DotDensitySymbol layer
158
//			DotDensityFillSymbol sym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
159
//			getLayer(DOT_DENSITY_LAYER_INDEX);
160
//			return sym.getDotColor();
161
//		} catch (NullPointerException npE) {
162
//			return null;
163
//		}
164
		return dotColor;
165
	}
166

  
167

  
168
	/**
169
	 * Sets the color for the dot used in the dot density legend.
170
	 * @return
171
	 */
172
	public void setDotColor(Color color){
173

  
174
//		DotDensityFillSymbol sym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
175
//		getLayer(DOT_DENSITY_LAYER_INDEX);
176
//		sym.setDotColor(color);
177

  
178
		this.dotColor = color;
179

  
180
	}
181

  
182
	/**
183
	 * Obtains the background color for the dot density legend
184
	 * @return
185
	 */
186
	public Color getBGColor() {
187
//		try {
188
//			// defined by the SimpleFillSymbol layer
189
//			IFillSymbol symbol = (IFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
190
//			getLayer(SIMPLE_FILL_LAYER_INDEX);
191
//			return symbol.getFillColor();
192
//		} catch (NullPointerException npE) {
193
//			return null;
194
//		}
195
		return backgroundColor;
196
	}
197

  
198
	/**
199
	 * Sets the background color for the dot density legend
200
	 * @return
201
	 */
202
	public void setBGColor(Color color) {
203
		this.backgroundColor = color;
204
	}
205
	/**
206
	 * Returns the value for the dot that is used in the dot density legend
207
	 * @return
208
	 */
209
	public double getDotValue() {
210
	    return this.dotValue;
211
	}
212
	/**
213
	 * Obtains the size of the dot that is used in the dot density legend
214
	 * @return
215
	 */
216
	public double getDotSize() {
217

  
218
		// defined by the SimpleFillSymbol layer
219
		ISymbol symbol = getDefaultSymbol();
220
		if (symbol == null){
221
			return -1;
222
		}
223
		if (symbol instanceof DotDensityFillSymbol){
224
			return ((DotDensityFillSymbol)symbol).getDotSize();
225
		}
226
		if (!(symbol instanceof IFillSymbol)){
227
			return -1;
228
		}
229
		IFillSymbol fillsym = (IFillSymbol) symbol;
230
		if (fillsym instanceof MultiLayerFillSymbol){
231
			fillsym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) fillsym).
232
			getLayer(DOT_DENSITY_LAYER_INDEX);
233
		}
234
		if (fillsym instanceof DotDensityFillSymbol){
235
			return ((DotDensityFillSymbol)fillsym).getDotSize();
236
		}
237
		return -1;
238

  
239
	}
240

  
241
	/**
242
	 * Sets the size of the dot that is used in the dot density legend
243
	 */
244
	public void setDotSize(double value) {
245
		DotDensityFillSymbol sym = (DotDensityFillSymbol) ((MultiLayerFillSymbol) getDefaultSymbol()).
246
		getLayer(DOT_DENSITY_LAYER_INDEX);
247
		sym.setDotSize(value);
248
	}
249
	
250
	
251
    public static boolean isPolygonal(int ty) {
252
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
253
        return geomManager.isSubtype(Geometry.TYPES.MULTISURFACE, ty) || 
254
            geomManager.isSubtype(Geometry.TYPES.SURFACE, ty);
255
    }
256

  
257
    // =============================
258
    
259
    public static class RegisterPersistence implements Callable {
260

  
261
        public Object call() throws Exception {
262
            
263
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
264
            if (manager.getDefinition(
265
                DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) {
266
                DynStruct definition = manager
267
                    .addDefinition(DotDensityLegend.class,
268
                        DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME,
269
                        DOT_DENSITY_LEGEND_PERSISTENCE_DEFINITION_NAME
270
                        + " Persistence definition", null, null);
271
                
272
                definition.extend(manager.getDefinition(
273
                    VectorialUniqueValueLegend
274
                    .VECTORIAL_UNIQUE_VALUE_LEGEND_PERSISTENCE_DEFINITION_NAME));
275
                
276
                definition.addDynFieldDouble("dotValue").setMandatory(true);
277
                definition.addDynFieldObject("dotColor")
278
                .setClassOfValue(Color.class).setMandatory(true);
279
                definition.addDynFieldObject("bgColor")
280
                .setClassOfValue(Color.class).setMandatory(true);
281
            }
282
            return Boolean.TRUE;
283
        }
284

  
285
    }
286

  
287
    public static class RegisterLegend implements Callable {
288

  
289
        public Object call() throws Exception {
290
            MapContextManager manager =
291
                MapContextLocator.getMapContextManager();
292

  
293
            manager.registerLegend(
294
                DOT_DENSITY_LEGEND_NAME,
295
                DotDensityLegend.class);
296

  
297
            return Boolean.TRUE;
298
        }
299

  
300
    }
301
    
302
    public Object clone() throws CloneNotSupportedException {
303
        
304
        DotDensityLegend resp = (DotDensityLegend) super.clone();
305
        resp.setDotColor(this.getDotColor());
306
        resp.setDotSize(this.getDotSize());
307
        resp.setDotValue(this.getDotValue());
308
        return resp;
309
    }
310

  
311
    public String[] getDescriptions() {
312
        try {
313
            return new String[]{String.format("%s, %.3f",getClassifyingFieldNames()[0], getDotValue())};
314
        }catch (Exception ex){
315
            return new String[]{"Dot density"};
316
        }
317
    }
318

  
319
}
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.240/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 (numeric
161
 * 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
    private NumberFormat nf = NumberFormat.getInstance();
196

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

  
202
    private class MyListener implements ItemListener, ActionListener {
203

  
204
        public void itemStateChanged(ItemEvent e) {
205
            if (!initializing) {
206
                doIt();
207
            }
208
        }
209

  
210
        public void actionPerformed(ActionEvent e) {
211
            if (!initializing) {
212
                doIt();
213
            }
214
        }
215

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

  
223
                if (index != -1) {
224
                    theFieldName = (String) cmbLegendField.getSelectedItem();
225
                } else {
226
                    theFieldName = (String) cmbLegendField.getItemAt(0);
227
                }
228

  
229
                FeatureAttributeDescriptor att
230
                        = fty.getAttributeDescriptor(theFieldName);
231
                theFieldType = att.getDataType().getType();
232

  
233
                long vc = 0;
234

  
235
                double maxValue = -Double.MAX_VALUE;
236
                double minValue = Double.MAX_VALUE;
237

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

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

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

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

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

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

  
300
    private boolean dotValueChanging = false;
301

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

  
308
            dotValueChanging = true;
309
            double d = sldValueToDotValue(getSldDensity().getValue());
310
            nmbrDotValue.setDouble(d);
311
            dotValueChanging = false;
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) {
325
                dotValue = 0;
326
            }
327
            int result = dotValueToSldValue(dotValue);
328
            getSldDensity().setValue(result);
329
            dotValueChanging = false;
330
        }
331
    };
332

  
333
    private ColorChooserPanel jcc;
334
    private ILegend oldLegend;
335
    private JSymbolPreviewButton btnOutline;
336
    private ColorChooserPanel jccBackground;
337

  
338
    public DotDensityPanel() {
339
        super();
340
        initialize();
341
    }
342

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

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

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

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

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

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

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

  
394
            DotDensityLegend theLegend = (DotDensityLegend) legend;
395

  
396
            initializing = false; // enables events to the combo box
397

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

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

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

  
434
        } catch (Exception e) {
435
            e.printStackTrace();
436
        }
437
    }
438

  
439
    public ILegend getLegend() {
440
        try {
441
            int shapeType = layer.getShapeType();
442

  
443
            // shapeType should be always polygon
444
            if (!DotDensityLegend.isPolygonal(shapeType)) {
445

  
446
                ApplicationLocator.getManager().message(
447
                        Messages.getText("cannot_apply_to_a_non_polygon_layer"),
448
                        JOptionPane.ERROR_MESSAGE);
449
                return null;
450
            }
451

  
452
            // gather values
453
            double dotValue;
454
            double dotSize;
455
            try {
456
                dotValue = nmbrDotValue.getDouble();
457
            } catch (Exception e) {
458
                dotValue = nmbrDotValue.getDouble();
459
            }
460
            if (dotValue == 0) {
461
                dotValue = 1;
462
            }
463
            try {
464
                dotSize = numDotSize.getDouble();
465
            } catch (Exception e) {
466
                dotSize = numDotSize.getDouble();
467
            }
468

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

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

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

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

  
498
            legend = new DotDensityLegend();
499
            legend.setClassifyingFieldNames(new String[]{theFieldName});
500
            legend.setClassifyingFieldTypes(new int[]{theFieldType});
501

  
502
            legend.addSymbol(0, symbol);
503
            legend.setDefaultSymbol(symbol);
504
            legend.setDotValue(dotValue);
505

  
506
            legend.setBGColor(getBackgroundColorChooserPanel().getColor());
507
            legend.setDotColor(getDotColorChooserPanel().getColor());
508

  
509
        } catch (Exception e) {
510
            logger.warn(Messages.getText("could_not_setup_legend"), e);
511
        }
512
        return legend;
513

  
514
    }
515

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

  
529
        }
530
        return northPanel;
531
    }
532

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

  
541
    /**
542
     * This method initializes southPanel
543
     *
544
     * @return javax.swing.JPanel
545
     */
546
    private JPanel getDensityButtonsPanel() {
547
        if (densityButtonsPanel == null) {
548
            densityButtonsPanel = new GridBagLayoutPanel();
549
            LayoutManager layout = new FlowLayout(FlowLayout.LEADING, 0, 0);
550
            JPanel aux = new JPanel(layout);
551
            aux.add(getNumDotSize());
552
            densityButtonsPanel.addComponent(
553
                    Messages.getText("dot_size"), aux);
554
            aux = new JPanel(layout);
555
            aux.add(getNmbrDotValue());
556
            densityButtonsPanel.addComponent(
557
                    Messages.getText("dot_value"), aux);
558
            aux = new JPanel(layout);
559
            aux.add(getDotColorChooserPanel());
560
            densityButtonsPanel.addComponent(
561
                    Messages.getText("color"), aux);
562
            aux = new JPanel(layout);
563
            aux.add(getBackgroundColorChooserPanel());
564
            densityButtonsPanel.addComponent(
565
                    Messages.getText("background_color"), aux);
566
            aux = new JPanel(layout);
567
            aux.add(getBtnOutline());
568
            densityButtonsPanel.addComponent(
569
                    Messages.getText("outline"), aux);
570
        }
571
        return densityButtonsPanel;
572
    }
573

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

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

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

  
608
            aux2.add(aux);
609

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

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

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

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

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

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

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

  
674
    /**
675
     * This method initializes rdBtnMax
676
     *
677
     * @return javax.swing.JRadioButton
678
     */
679
    private JRadioButton getRdBtnLow() {
680
        if (rdBtnLow == null) {
681
            Icon ic = IconThemeHelper.getImageIcon(
682
                    "legend-dot-density-low-density-sample");
683
            rdBtnLow = new JRadioButton(ic);
684
            rdBtnLow.addActionListener(buttonsListener);
685
        }
686
        return rdBtnLow;
687
    }
688

  
689
    /**
690
     * This method initializes numDotSize
691
     *
692
     * @return de.ios.framework.swing.JNumberField
693
     */
694
    private JNumberSpinner getNumDotSize() {
695
        if (numDotSize == null) {
696
            numDotSize = new JNumberSpinner(1.0, 4, 0.0, Double.MAX_VALUE, 1.0, 2);
697
        }
698
        return numDotSize;
699
    }
700

  
701
    /**
702
     * This method initializes nmbrDotValue
703
     *
704
     * @return de.ios.framework.swing.JNumberField
705
     */
706
    private JNumberSpinner getNmbrDotValue() {
707
        if (nmbrDotValue == null) {
708
            nmbrDotValue = new JNumberSpinner(1.0, 15, 0.01, Double.MAX_VALUE, 1.0, 2);
709
            nmbrDotValue.addActionListener(nmbrDotValueListener);
710

  
711
        }
712
        return nmbrDotValue;
713
    }
714

  
715
    /**
716
     * This method initializes centerPanel
717
     *
718
     * @return javax.swing.JPanel
719
     */
720
    private JPanel getCenterPanel() {
721
        if (centerPanel == null) {
722
            centerPanel = new JPanel();
723
            centerPanel.setLayout(new BorderLayout(5, 5));
724
            centerPanel.add(getPnlDensities(), java.awt.BorderLayout.WEST);
725
        }
726
        return centerPanel;
727
    }
728

  
729
    /**
730
     * This method initializes sldDensity
731
     *
732
     * @return javax.swing.JSlider
733
     */
734
    private JSlider getSldDensity() {
735
        if (sldDensity == null) {
736
            sldDensity = new JSlider();
737
            sldDensity.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
738
            sldDensity.addChangeListener(sldListener);
739
        }
740
        return sldDensity;
741
    }
742

  
743
    public String getDescription() {
744
        return Messages.getText("Defines_a_dot_density_symbol_based_on_a_field_value") + ".";
745
    }
746

  
747
    public ImageIcon getIcon() {
748
        ImageIcon ic = IconThemeHelper.getImageIcon(
749
                "legend-overview-dot-density");
750
        return ic;
751
    }
752

  
753
    public Class getParentClass() {
754
        return Quantities.class;
755
    }
756

  
757
    public String getTitle() {
758
        return Messages.getText("dot_density");
759
    }
760

  
761
    public JPanel getPanel() {
762
        return this;
763
    }
764

  
765
    public Class getLegendClass() {
766
        return DotDensityLegend.class;
767
    }
768

  
769
    public boolean isSuitableFor(FLayer layer) {
770
        if (layer instanceof FLyrVect) {
771
            try {
772
                FLyrVect lyr = (FLyrVect) layer;
773
                if (!DotDensityLegend.isPolygonal(lyr.getShapeType())) {
774
                    return false;
775
                }
776

  
777
                FeatureStore fsto = (FeatureStore) lyr.getDataStore();
778
                FeatureType fty = fsto.getDefaultFeatureType();
779
                FeatureAttributeDescriptor[] atts = fty.getAttributeDescriptors();
780

  
781
                for (int i = 0; i < atts.length; i++) {
782
                    if (atts[i].getDataType().isNumeric()) {
783
                        return true;
784
                    }
785
                }
786
            } catch (Exception e) {
787

  
788
                ApplicationLocator.getManager().messageDialog(
789
                        Messages.getText("error_trying_to_access_to_the_layer"),
790
                        Messages.getText("error"),
791
                        JOptionPane.ERROR_MESSAGE);
792
                return false;
793
            }
794
        }
795
        return false;
796
    }
797

  
798
}
org.gvsig.legend.dotdensity.app.mainplugin/tags/org.gvsig.legend.dotdensity.app.mainplugin-1.0.240/src/main/java/org/gvsig/symbology/library/DotDensityLibrary.java
1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2013 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff