Revision 3271
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.legend.heatmap.lib.impl.HeatmapLegendLibraryImpl |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.impl/src/main/resources/org/gvsig/legend/heatmap/lib/impl/DefaultHeatmapLegend.persistence.xml | ||
---|---|---|
1 |
<?xml version="1.0"?> |
|
2 |
<definitions> |
|
3 |
<version>1.0.0</version> |
|
4 |
<classes> |
|
5 |
<class name="DefaultHeatmapLegend"> |
|
6 |
<extends> |
|
7 |
<class>VectorialLegend</class> |
|
8 |
</extends> |
|
9 |
<fields> |
|
10 |
<field name="isRamp" type="boolean" defaultValue="true"> |
|
11 |
<description></description> |
|
12 |
</field> |
|
13 |
<field name="sourceColorTable" type="list" classOfItems="java.awt.Color"> |
|
14 |
<description></description> |
|
15 |
</field> |
|
16 |
<field name="colorTableHotColorAlpha" type="integer" defaultValue="255"> |
|
17 |
<description></description> |
|
18 |
</field> |
|
19 |
<field name="colorTableColdColorAlpha" type="integer" defaultValue="255"> |
|
20 |
<description></description> |
|
21 |
</field> |
|
22 |
<field name="useAlphaInColorTable" type="boolean" defaultValue="false"> |
|
23 |
<description></description> |
|
24 |
</field> |
|
25 |
<field name="distance" type="integer" defaultValue="30"> |
|
26 |
<description></description> |
|
27 |
</field> |
|
28 |
<field name="fieldName" type="String" defaultValue=""> |
|
29 |
<description></description> |
|
30 |
</field> |
|
31 |
<field name="rampColdColor" type="Object" classOfValue="java.awt.Color"> |
|
32 |
<description></description> |
|
33 |
</field> |
|
34 |
<field name="rampHotColor" type="Object" classOfValue="java.awt.Color"> |
|
35 |
<description></description> |
|
36 |
</field> |
|
37 |
<field name="rampNumColors" type="integer" defaultValue="100"> |
|
38 |
<description></description> |
|
39 |
</field> |
|
40 |
</fields> |
|
41 |
</class> |
|
42 |
|
|
43 |
</classes> |
|
44 |
</definitions> |
|
0 | 45 |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.impl/src/main/java/org/gvsig/legend/heatmap/lib/impl/DefaultHeatmapLegend.java | ||
---|---|---|
1 |
package org.gvsig.legend.heatmap.lib.impl; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.awt.Graphics2D; |
|
5 |
import java.awt.Image; |
|
6 |
import java.awt.image.BufferedImage; |
|
7 |
import java.util.Map; |
|
8 |
|
|
9 |
import org.apache.commons.lang3.StringUtils; |
|
10 |
import org.cresques.cts.ICoordTrans; |
|
11 |
import org.gvsig.compat.print.PrintAttributes; |
|
12 |
|
|
13 |
import org.gvsig.fmap.dal.exception.DataException; |
|
14 |
import org.gvsig.fmap.dal.feature.Feature; |
|
15 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
16 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
17 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
18 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
19 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
20 |
import org.gvsig.fmap.geom.Geometry; |
|
21 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
22 |
import org.gvsig.fmap.geom.primitive.Point; |
|
23 |
import org.gvsig.fmap.mapcontext.MapContextException; |
|
24 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
25 |
import org.gvsig.fmap.mapcontext.layers.operations.IHasImageLegend; |
|
26 |
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException; |
|
27 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
|
28 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
29 |
import org.gvsig.gui.ColorTablePainter; |
|
30 |
import org.gvsig.gui.DefaultColorTablePainter; |
|
31 |
import org.gvsig.legend.heatmap.lib.api.HeatmapLegend; |
|
32 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend; |
|
33 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.DefaultFeatureDrawnNotification; |
|
34 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.impl.SimpleTextSymbol; |
|
35 |
import org.gvsig.tools.exception.BaseException; |
|
36 |
import org.gvsig.tools.persistence.PersistentState; |
|
37 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
38 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
39 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
|
40 |
import org.gvsig.tools.task.Cancellable; |
|
41 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
42 |
import org.gvsig.tools.visitor.Visitor; |
|
43 |
|
|
44 |
public class DefaultHeatmapLegend extends AbstractVectorialLegend implements HeatmapLegend, IHasImageLegend { |
|
45 |
|
|
46 |
private class DensityAlgorithm { |
|
47 |
|
|
48 |
private double[][] grid; |
|
49 |
private double[][] kernel; |
|
50 |
private int distance; |
|
51 |
private int height; |
|
52 |
private int with; |
|
53 |
private double maxValue; |
|
54 |
private double minValue; |
|
55 |
|
|
56 |
public DensityAlgorithm(int distance) { |
|
57 |
this.setDistance(distance); |
|
58 |
} |
|
59 |
|
|
60 |
public void setDistance(int distance) { |
|
61 |
if( this.distance == distance ) { |
|
62 |
return; |
|
63 |
} |
|
64 |
this.distance = distance; |
|
65 |
this.kernel = new double[2 * this.distance + 1][2 * this.distance + 1]; |
|
66 |
for( int y = -this.distance; y < this.distance + 1; y++ ) { |
|
67 |
for( int x = -this.distance; x < this.distance + 1; x++ ) { |
|
68 |
final double dDist = Math.sqrt(x * x + y * y); |
|
69 |
if( dDist < this.distance ) { |
|
70 |
this.kernel[x + this.distance][y + this.distance] = Math.pow(1 - (dDist * dDist) / (this.distance * this.distance), 2); |
|
71 |
} else { |
|
72 |
this.kernel[x + this.distance][y + this.distance] = 0; |
|
73 |
} |
|
74 |
} |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
public int getDistance() { |
|
79 |
return this.distance; |
|
80 |
} |
|
81 |
|
|
82 |
public void init(int with, int height) { |
|
83 |
this.with = with; |
|
84 |
this.height = height; |
|
85 |
this.grid = new double[with][height]; |
|
86 |
this.maxValue = 0; |
|
87 |
this.minValue = 0; |
|
88 |
} |
|
89 |
|
|
90 |
public void add(int px, int py) { |
|
91 |
add(px, py, 1); |
|
92 |
} |
|
93 |
|
|
94 |
public void add(int px, int py, double value) { |
|
95 |
for( int y = -this.distance; y < this.distance + 1; y++ ) { |
|
96 |
for( int x = -this.distance; x < this.distance + 1; x++ ) { |
|
97 |
if( this.kernel[x + this.distance][y + this.distance] != 0 ) { |
|
98 |
addValue(px + x, py + y, value * this.kernel[x + this.distance][y + this.distance]); |
|
99 |
} |
|
100 |
} |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
private void addValue(int px, int py, double value) { |
|
105 |
if( px < 0 || py < 0 || px >= with || py >= height ) { |
|
106 |
return; |
|
107 |
} |
|
108 |
value += this.grid[px][py]; |
|
109 |
this.grid[px][py] = value; |
|
110 |
if( value > this.maxValue ) { |
|
111 |
this.maxValue = value; |
|
112 |
} |
|
113 |
if( value < this.minValue ) { |
|
114 |
this.minValue = value; |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
public void drawWithOpaqueColors(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel, Geometry roi) { |
|
119 |
try { |
|
120 |
ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager(); |
|
121 |
Color c; |
|
122 |
int maxIndexColor = colorTable.length-1; |
|
123 |
for( int x = 0; x < with; x++ ) { |
|
124 |
for( int y = 0; y < height; y++ ) { |
|
125 |
if( cancel.isCanceled() ) { |
|
126 |
return; |
|
127 |
} |
|
128 |
if (roi!=null) { |
|
129 |
Point point = GeometryUtils.createPoint(x, y); |
|
130 |
if (!roi.intersects(point)) { |
|
131 |
continue; |
|
132 |
} |
|
133 |
} |
|
134 |
double value = this.grid[x][y]; |
|
135 |
if( value > 0 ) { |
|
136 |
int icolor = (int) (value * maxIndexColor / maxValue); |
|
137 |
c = toolsSwingManager.alphaBlendingWithOpaqueBackground( |
|
138 |
new Color(img.getRGB(x, y)), |
|
139 |
colorTable[icolor] |
|
140 |
); |
|
141 |
img.setRGB(x, y, c.getRGB()); |
|
142 |
} |
|
143 |
} |
|
144 |
} |
|
145 |
} catch (Exception ex) { |
|
146 |
LOG.warn("Problems drawing heatmap", ex); |
|
147 |
} |
|
148 |
} |
|
149 |
|
|
150 |
public void drawWithAlphaColors(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel, Geometry roi) { |
|
151 |
try { |
|
152 |
Color c; |
|
153 |
int maxIndexColor = colorTable.length-1; |
|
154 |
for( int x = 0; x < with; x++ ) { |
|
155 |
for( int y = 0; y < height; y++ ) { |
|
156 |
if( cancel.isCanceled() ) { |
|
157 |
return; |
|
158 |
} |
|
159 |
if (roi!=null) { |
|
160 |
Point point = GeometryUtils.createPoint(x, y); |
|
161 |
if (!roi.intersects(point)) { |
|
162 |
continue; |
|
163 |
} |
|
164 |
} |
|
165 |
double value = this.grid[x][y]; |
|
166 |
if( value > 0 ) { |
|
167 |
int icolor = (int) (value * maxIndexColor / maxValue); |
|
168 |
c = colorTable[icolor]; |
|
169 |
img.setRGB(x, y, c.getRGB()); |
|
170 |
} |
|
171 |
} |
|
172 |
} |
|
173 |
} catch (Exception ex) { |
|
174 |
LOG.warn("Problems drawing heatmap", ex); |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
|
|
179 |
private ISymbol defaultSymbol; |
|
180 |
private DensityAlgorithm algorithm; |
|
181 |
private boolean isRamp; |
|
182 |
private Color[] sourceColorTable; |
|
183 |
private int colorTableHotColorAlpha; |
|
184 |
private int colorTableColdColorAlpha; |
|
185 |
private boolean useAlphaInColorTable; |
|
186 |
private String fieldName; |
|
187 |
private Image imageLegend; |
|
188 |
private HeatmapColorTable hmColorTable; |
|
189 |
private Color rampColdColor; |
|
190 |
private Color rampHotColor; |
|
191 |
private int rampNumColors; |
|
192 |
private Geometry roi; |
|
193 |
|
|
194 |
public DefaultHeatmapLegend() { |
|
195 |
|
|
196 |
this.defaultSymbol = new SimpleTextSymbol(); |
|
197 |
this.algorithm = new DensityAlgorithm(30); |
|
198 |
this.colorTableHotColorAlpha = 255; |
|
199 |
this.colorTableColdColorAlpha = 0; |
|
200 |
this.useAlphaInColorTable = false; |
|
201 |
this.setColorTable(100, new Color(0, 0, 255, 0), new Color(255, 0, 0, 255)); |
|
202 |
this.imageLegend = null; |
|
203 |
this.hmColorTable = null; |
|
204 |
this.fieldName = null; |
|
205 |
} |
|
206 |
|
|
207 |
@Override |
|
208 |
protected String[] getRequiredFeatureAttributeNames(FeatureStore featureStore) throws DataException { |
|
209 |
FeatureType ftype = featureStore.getDefaultFeatureType(); |
|
210 |
if( StringUtils.isEmpty(this.fieldName) ) { |
|
211 |
return new String[]{ |
|
212 |
ftype.getDefaultGeometryAttributeName() |
|
213 |
}; |
|
214 |
} |
|
215 |
return new String[]{ |
|
216 |
ftype.getDefaultGeometryAttributeName(), |
|
217 |
this.fieldName |
|
218 |
}; |
|
219 |
} |
|
220 |
|
|
221 |
@Override |
|
222 |
public ISymbol getDefaultSymbol() { |
|
223 |
return this.defaultSymbol; |
|
224 |
} |
|
225 |
|
|
226 |
@Override |
|
227 |
public void setDefaultSymbol(ISymbol is) { |
|
228 |
} |
|
229 |
|
|
230 |
@Override |
|
231 |
public ISymbol getSymbolByFeature(Feature ftr) throws MapContextException { |
|
232 |
return this.defaultSymbol; |
|
233 |
} |
|
234 |
|
|
235 |
@Override |
|
236 |
public int getShapeType() { |
|
237 |
return Geometry.TYPES.GEOMETRY; |
|
238 |
} |
|
239 |
|
|
240 |
@Override |
|
241 |
public void setShapeType(int i) { |
|
242 |
} |
|
243 |
|
|
244 |
@Override |
|
245 |
public boolean isUseDefaultSymbol() { |
|
246 |
return true; |
|
247 |
} |
|
248 |
|
|
249 |
@Override |
|
250 |
public void useDefaultSymbol(boolean bln) { |
|
251 |
} |
|
252 |
|
|
253 |
@Override |
|
254 |
public boolean isSuitableForShapeType(int shapeType) { |
|
255 |
return true; |
|
256 |
} |
|
257 |
|
|
258 |
@Override |
|
259 |
protected void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, Map queryParameters, ICoordTrans coordTrans, FeatureStore featureStore, FeatureQuery featureQuery, double dpi) throws LegendException { |
|
260 |
int saved_distance = this.algorithm.getDistance(); |
|
261 |
try { |
|
262 |
int distance = (int) (this.algorithm.getDistance() * (dpi / 72)); |
|
263 |
Geometry theROI = null; |
|
264 |
if (this.roi!=null) { |
|
265 |
theROI = this.roi.cloneGeometry(); |
|
266 |
theROI.transform(viewPort.getAffineTransform()); |
|
267 |
} |
|
268 |
this.algorithm.setDistance(distance); |
|
269 |
this.algorithm.init(image.getWidth(), image.getHeight()); |
|
270 |
super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, featureStore, featureQuery, dpi); |
|
271 |
if( !cancel.isCanceled() ) { |
|
272 |
this.algorithm.drawWithOpaqueColors(image, g, this.getHeatMapColorTable().getColorTable(), cancel, theROI); |
|
273 |
} |
|
274 |
} finally { |
|
275 |
this.algorithm.setDistance(saved_distance); |
|
276 |
|
|
277 |
} |
|
278 |
} |
|
279 |
|
|
280 |
@Override |
|
281 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
|
282 |
double scale, Map queryParameters, ICoordTrans coordTrans, |
|
283 |
FeatureStore featureStore, FeatureQuery featureQuery, PrintAttributes properties) |
|
284 |
throws LegendException { |
|
285 |
int saved_distance = this.algorithm.getDistance(); |
|
286 |
try { |
|
287 |
double dpi = viewPort.getDPI(); |
|
288 |
// Ver CartographicSupportToolkit.getCartographicLength |
|
289 |
int distance = (int) (this.algorithm.getDistance() * (dpi / 72)); |
|
290 |
Geometry theROI = null; |
|
291 |
if (this.roi!=null) { |
|
292 |
theROI = this.roi.cloneGeometry(); |
|
293 |
theROI.transform(viewPort.getAffineTransform()); |
|
294 |
} |
|
295 |
this.algorithm.setDistance(distance); |
|
296 |
this.algorithm.init(viewPort.getImageWidth(), viewPort.getImageHeight()); |
|
297 |
BufferedImage image = new BufferedImage(viewPort.getImageWidth(), viewPort.getImageHeight(), BufferedImage.TYPE_INT_ARGB); |
|
298 |
super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, featureStore, featureQuery, dpi); |
|
299 |
if (!cancel.isCanceled()) { |
|
300 |
this.algorithm.drawWithAlphaColors(image, g, this.getHeatMapColorTable().getColorTable(), cancel, theROI); |
|
301 |
g.drawImage(image, 0, 0, null); |
|
302 |
} |
|
303 |
} finally { |
|
304 |
this.algorithm.setDistance(saved_distance); |
|
305 |
|
|
306 |
} |
|
307 |
} |
|
308 |
|
|
309 |
@Override |
|
310 |
protected void drawFeatures( |
|
311 |
BufferedImage image, |
|
312 |
Graphics2D g, |
|
313 |
final ViewPort viewPort, |
|
314 |
final Cancellable cancel, |
|
315 |
final ICoordTrans coordTrans, |
|
316 |
double dpi, |
|
317 |
DefaultFeatureDrawnNotification drawnNotification, |
|
318 |
FeatureSet featureSet, |
|
319 |
FeatureSelection selection |
|
320 |
) throws BaseException { |
|
321 |
int x = -1; |
|
322 |
if( !StringUtils.isEmpty(this.fieldName) ) { |
|
323 |
x = featureSet.getDefaultFeatureType().getIndex(this.fieldName); |
|
324 |
} |
|
325 |
final int n = x; |
|
326 |
featureSet.accept(new Visitor() { |
|
327 |
@Override |
|
328 |
public void visit(Object o) throws VisitCanceledException, BaseException { |
|
329 |
if( cancel.isCanceled() ) { |
|
330 |
throw new VisitCanceledException(); |
|
331 |
} |
|
332 |
Feature feature = (Feature) o; |
|
333 |
Geometry geom = feature.getDefaultGeometry(); |
|
334 |
if( geom != null ) { |
|
335 |
Point pointGeo = geom.centroid(); |
|
336 |
if( coordTrans != null ) { |
|
337 |
pointGeo.reProject(coordTrans); |
|
338 |
} |
|
339 |
Point pointPixels = (Point) pointGeo.cloneGeometry(); |
|
340 |
pointPixels.transform(viewPort.getAffineTransform()); |
|
341 |
if( n >= 0 ) { |
|
342 |
double value = 0; |
|
343 |
try { |
|
344 |
value = feature.getDouble(n); |
|
345 |
} catch(Exception ex) { |
|
346 |
} |
|
347 |
if( value >0 ) { |
|
348 |
algorithm.add((int) pointPixels.getX(), (int) pointPixels.getY(), value); |
|
349 |
} |
|
350 |
} else { |
|
351 |
algorithm.add((int) pointPixels.getX(), (int) pointPixels.getY()); |
|
352 |
} |
|
353 |
} |
|
354 |
} |
|
355 |
}); |
|
356 |
} |
|
357 |
|
|
358 |
/** |
|
359 |
* @return the distance |
|
360 |
*/ |
|
361 |
@Override |
|
362 |
public int getDistance() { |
|
363 |
return this.algorithm.getDistance(); |
|
364 |
} |
|
365 |
|
|
366 |
/** |
|
367 |
* @param distance the distance to set |
|
368 |
*/ |
|
369 |
@Override |
|
370 |
public void setDistance(int distance) { |
|
371 |
this.algorithm.setDistance(distance); |
|
372 |
} |
|
373 |
|
|
374 |
@Override |
|
375 |
public void setColorTable(Color[] colorTable) { |
|
376 |
this.isRamp = false; |
|
377 |
this.sourceColorTable = colorTable; |
|
378 |
this.imageLegend = null; |
|
379 |
this.hmColorTable = null; |
|
380 |
this.fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null,null)); |
|
381 |
} |
|
382 |
|
|
383 |
@Override |
|
384 |
public void setColorTable(int numColors, Color coldColor, Color hotColor) { |
|
385 |
this.isRamp = true; |
|
386 |
this.rampColdColor = coldColor; |
|
387 |
this.rampHotColor = hotColor; |
|
388 |
this.rampNumColors = numColors; |
|
389 |
this.imageLegend = null; |
|
390 |
this.hmColorTable = null; |
|
391 |
this.fireDefaultSymbolChangedEvent(new SymbolLegendEvent(null,null)); |
|
392 |
} |
|
393 |
|
|
394 |
@Override |
|
395 |
public Color[] getSourceColorTable() { |
|
396 |
return this.sourceColorTable; |
|
397 |
} |
|
398 |
|
|
399 |
@Override |
|
400 |
public Color[] getTargetColorTable() { |
|
401 |
return this.getHeatMapColorTable().getColorTable(); |
|
402 |
} |
|
403 |
|
|
404 |
private HeatmapColorTable getHeatMapColorTable() { |
|
405 |
if (this.hmColorTable == null) { |
|
406 |
if (this.useRamp()) { |
|
407 |
this.hmColorTable = new HeatmapColorTable(this.rampColdColor, this.rampHotColor, this.rampNumColors); |
|
408 |
} else { |
|
409 |
if(useAlphaInColorTable) { |
|
410 |
this.hmColorTable = new HeatmapColorTable(this.getSourceColorTable(), colorTableColdColorAlpha, colorTableHotColorAlpha); |
|
411 |
} else { |
|
412 |
this.hmColorTable = |
|
413 |
this.hmColorTable = new HeatmapColorTable(this.getSourceColorTable()); |
|
414 |
} |
|
415 |
} |
|
416 |
} |
|
417 |
return this.hmColorTable; |
|
418 |
} |
|
419 |
|
|
420 |
|
|
421 |
@Override |
|
422 |
public boolean useRamp() { |
|
423 |
return this.isRamp; |
|
424 |
} |
|
425 |
|
|
426 |
@Override |
|
427 |
public String getFieldName() { |
|
428 |
return this.fieldName; |
|
429 |
} |
|
430 |
|
|
431 |
@Override |
|
432 |
public void setFieldName(String fieldName) { |
|
433 |
this.fieldName = fieldName; |
|
434 |
} |
|
435 |
|
|
436 |
@Override |
|
437 |
public int getColorTableHotColorAlpha() { |
|
438 |
return colorTableHotColorAlpha; |
|
439 |
} |
|
440 |
|
|
441 |
@Override |
|
442 |
public void setColorTableHotColorAlpha(int colorTableHotColorAlpha) { |
|
443 |
this.colorTableHotColorAlpha = colorTableHotColorAlpha; |
|
444 |
this.imageLegend = null; |
|
445 |
this.hmColorTable = null; |
|
446 |
} |
|
447 |
|
|
448 |
@Override |
|
449 |
public int getColorTableColdColorAlpha() { |
|
450 |
return colorTableColdColorAlpha; |
|
451 |
} |
|
452 |
|
|
453 |
@Override |
|
454 |
public void setColorTableColdColorAlpha(int colorTableColdColorAlpha) { |
|
455 |
this.colorTableColdColorAlpha = colorTableColdColorAlpha; |
|
456 |
this.imageLegend = null; |
|
457 |
this.hmColorTable = null; |
|
458 |
} |
|
459 |
|
|
460 |
@Override |
|
461 |
public boolean useAlphaInColorTable() { |
|
462 |
return this.useAlphaInColorTable; |
|
463 |
} |
|
464 |
|
|
465 |
@Override |
|
466 |
public boolean setUseAlphaInColorTable(boolean use) { |
|
467 |
boolean x = this.useAlphaInColorTable; |
|
468 |
this.useAlphaInColorTable = use; |
|
469 |
this.hmColorTable = null; |
|
470 |
|
|
471 |
return x; |
|
472 |
} |
|
473 |
@Override |
|
474 |
public void setROI(Geometry roi) { |
|
475 |
this.roi = roi; |
|
476 |
} |
|
477 |
|
|
478 |
@Override |
|
479 |
public Geometry getROI() { |
|
480 |
return this.roi; |
|
481 |
} |
|
482 |
|
|
483 |
@Override |
|
484 |
public Image getImageLegend() { |
|
485 |
if( this.imageLegend==null ) { |
|
486 |
BufferedImage img = new BufferedImage(80, 20, BufferedImage.TYPE_INT_RGB); |
|
487 |
ColorTablePainter painter = new DefaultColorTablePainter(this.getTargetColorTable(),""); |
|
488 |
Graphics2D g = img.createGraphics(); |
|
489 |
g.setClip(0, 0, 80, 20); |
|
490 |
g.setBackground(Color.WHITE); |
|
491 |
g.fillRect(0, 0, 80, 20); |
|
492 |
painter.paint(g, false); |
|
493 |
this.imageLegend = img; |
|
494 |
} |
|
495 |
return this.imageLegend; |
|
496 |
} |
|
497 |
|
|
498 |
@Override |
|
499 |
public String getPathImage() { |
|
500 |
return null; |
|
501 |
} |
|
502 |
|
|
503 |
@Override |
|
504 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
505 |
this.defaultSymbol = new SimpleTextSymbol(); |
|
506 |
this.imageLegend = null; |
|
507 |
this.hmColorTable = null; |
|
508 |
|
|
509 |
super.loadFromState(state); |
|
510 |
this.isRamp = state.getBoolean("isRamp"); |
|
511 |
this.sourceColorTable = (Color[]) state.getArray("sourceColorTable",Color.class); |
|
512 |
this.colorTableHotColorAlpha = state.getInt("colorTableHotColorAlpha"); |
|
513 |
this.colorTableColdColorAlpha = state.getInt("colorTableColdColorAlpha"); |
|
514 |
this.useAlphaInColorTable = state.getBoolean("useAlphaInColorTable"); |
|
515 |
this.fieldName = state.getString("fieldName"); |
|
516 |
this.rampNumColors = state.getInt("rampNumColors"); |
|
517 |
this.rampColdColor = (Color)state.get("rampColdColor"); |
|
518 |
this.rampHotColor = (Color)state.get("rampHotColor"); |
|
519 |
|
|
520 |
this.algorithm = new DensityAlgorithm(state.getInt("distance")); |
|
521 |
} |
|
522 |
|
|
523 |
@Override |
|
524 |
public int getRampNumColors() { |
|
525 |
return this.rampNumColors; |
|
526 |
} |
|
527 |
|
|
528 |
@Override |
|
529 |
public Color getRampColdColor() { |
|
530 |
return this.rampColdColor; |
|
531 |
} |
|
532 |
|
|
533 |
@Override |
|
534 |
public Color getRampHotColor() { |
|
535 |
return this.rampHotColor; |
|
536 |
} |
|
537 |
|
|
538 |
@Override |
|
539 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
540 |
super.saveToState(state); |
|
541 |
state.set("isRamp", isRamp); |
|
542 |
state.set("sourceColorTable", sourceColorTable); |
|
543 |
state.set("colorTableHotColorAlpha", colorTableHotColorAlpha); |
|
544 |
state.set("colorTableColdColorAlpha", colorTableColdColorAlpha); |
|
545 |
state.set("useAlphaInColorTable", useAlphaInColorTable); |
|
546 |
state.set("fieldName", fieldName); |
|
547 |
state.set("distance", algorithm.distance); |
|
548 |
|
|
549 |
state.set("rampNumColors", rampNumColors); |
|
550 |
state.set("rampColdColor", rampColdColor); |
|
551 |
state.set("rampHotColor", rampHotColor); |
|
552 |
} |
|
553 |
|
|
554 |
|
|
555 |
private static class HeatmapColorTable { |
|
556 |
|
|
557 |
private Color[] sourceColorTable = null; |
|
558 |
private int coldAlpha = -1; |
|
559 |
private int hotAlpha = -1; |
|
560 |
private Color coldColor = null; |
|
561 |
private Color hotColor = null; |
|
562 |
private Color[] targetColorTable = null; |
|
563 |
private int length = -1; |
|
564 |
|
|
565 |
public HeatmapColorTable(Color[] sourceColorTable){ |
|
566 |
this.sourceColorTable = sourceColorTable; |
|
567 |
} |
|
568 |
|
|
569 |
public HeatmapColorTable(Color[] sourceColorTable, int coldAlpha, int hotAlpha){ |
|
570 |
this.sourceColorTable = sourceColorTable; |
|
571 |
this.coldAlpha = coldAlpha; |
|
572 |
this.hotAlpha = hotAlpha; |
|
573 |
} |
|
574 |
|
|
575 |
public HeatmapColorTable(Color coldColor, Color hotColor, int length){ |
|
576 |
this.coldColor = coldColor; |
|
577 |
this.hotColor = hotColor; |
|
578 |
this.length = length; |
|
579 |
} |
|
580 |
|
|
581 |
public Color[] getColorTable(){ |
|
582 |
if(targetColorTable==null){ |
|
583 |
if(sourceColorTable!=null){ //Tenemos tabla de color |
|
584 |
if (coldAlpha >= 0 || hotAlpha >= 0) { //Se usa alpha para la tabla de color |
|
585 |
double alphaDelta = getDelta(coldAlpha, hotAlpha, sourceColorTable.length); |
|
586 |
targetColorTable = new Color[sourceColorTable.length]; |
|
587 |
for (int i = 0; i < sourceColorTable.length; i++) { |
|
588 |
Color sourceColor = sourceColorTable[i]; |
|
589 |
if (coldAlpha >= 0 && hotAlpha >= 0) { |
|
590 |
targetColorTable[i] = |
|
591 |
new Color(sourceColor.getRed(), sourceColor.getGreen(), sourceColor.getBlue(), |
|
592 |
coldAlpha + (int) (i * alphaDelta)); |
|
593 |
} else { |
|
594 |
targetColorTable[i] = sourceColor; |
|
595 |
} |
|
596 |
} |
|
597 |
} else { //No se usa alpha para la tabla de color |
|
598 |
targetColorTable = sourceColorTable; |
|
599 |
} |
|
600 |
} else { // Tenemos gradiente |
|
601 |
targetColorTable = new Color[length]; |
|
602 |
|
|
603 |
double deltaRed = (hotColor.getRed() - coldColor.getRed()) / length; |
|
604 |
double deltaGreen = (hotColor.getGreen() - coldColor.getGreen()) / length; |
|
605 |
double deltaBlue = (hotColor.getBlue() - coldColor.getBlue()) / length; |
|
606 |
double deltaAlpha = (hotColor.getAlpha() - coldColor.getAlpha()) / length; |
|
607 |
for (int i = 0; i < length; i++) { |
|
608 |
targetColorTable[i] = |
|
609 |
new Color( |
|
610 |
(int) (coldColor.getRed() + i * deltaRed), |
|
611 |
(int) (coldColor.getGreen() + i * deltaGreen), |
|
612 |
(int) (coldColor.getBlue() + i * deltaBlue), |
|
613 |
(int) (coldColor.getAlpha() + i * deltaAlpha)); |
|
614 |
} |
|
615 |
} |
|
616 |
} |
|
617 |
return targetColorTable; |
|
618 |
} |
|
619 |
|
|
620 |
private double getDelta(int x1, int x2, int lenght){ |
|
621 |
return (x2-x1)/((double)lenght-1); |
|
622 |
} |
|
623 |
} |
|
624 |
} |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.impl/src/main/java/org/gvsig/legend/heatmap/lib/impl/HeatmapLegendLibraryImpl.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright ? 2007-2015 gvSIG Association |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.legend.heatmap.lib.impl; |
|
26 |
|
|
27 |
import org.gvsig.fmap.mapcontext.MapContextLibrary; |
|
28 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
29 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
30 |
import org.gvsig.legend.heatmap.lib.api.HeatmapLegendLibrary; |
|
31 |
import org.gvsig.legend.heatmap.lib.api.HeatmapLegendLocator; |
|
32 |
import org.gvsig.symbology.impl.SymbologyDefaultImplLibrary; |
|
33 |
import org.gvsig.tools.ToolsLocator; |
|
34 |
import org.gvsig.tools.library.AbstractLibrary; |
|
35 |
import org.gvsig.tools.library.LibraryException; |
|
36 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
37 |
|
|
38 |
public class HeatmapLegendLibraryImpl extends AbstractLibrary { |
|
39 |
|
|
40 |
@Override |
|
41 |
public void doRegistration() { |
|
42 |
registerAsImplementationOf(HeatmapLegendLibrary.class); |
|
43 |
this.require(MapContextLibrary.class); |
|
44 |
this.require(SymbologyDefaultImplLibrary.class); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
protected void doInitialize() throws LibraryException { |
|
49 |
HeatmapLegendLocator.registerHeatmapLegendManager(DefaultHeatmapLegendManager.class); |
|
50 |
MapContextManager mcmanager = MapContextLocator.getMapContextManager(); |
|
51 |
mcmanager.registerLegend("HeatmapLegend", DefaultHeatmapLegend.class); |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
protected void doPostInitialize() throws LibraryException { |
|
56 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
|
57 |
persistenceManager.addDefinition( |
|
58 |
DefaultHeatmapLegend.class, |
|
59 |
"DefaultHeatmapLegend", |
|
60 |
"/org/gvsig/legend/heatmap/lib/impl/DefaultHeatmapLegend.persistence.xml" |
|
61 |
); |
|
62 |
} |
|
63 |
|
|
64 |
} |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.impl/src/main/java/org/gvsig/legend/heatmap/lib/impl/DefaultHeatmapLegendManager.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2015 gvSIG Association |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.legend.heatmap.lib.impl; |
|
24 |
|
|
25 |
import org.gvsig.legend.heatmap.lib.api.HeatmapLegend; |
|
26 |
import org.gvsig.legend.heatmap.lib.api.HeatmapLegendManager; |
|
27 |
|
|
28 |
|
|
29 |
public class DefaultHeatmapLegendManager implements HeatmapLegendManager { |
|
30 |
|
|
31 |
@Override |
|
32 |
public HeatmapLegend create() { |
|
33 |
return new DefaultHeatmapLegend(); |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
public Class<? extends HeatmapLegend> getLegendClass() { |
|
38 |
return DefaultHeatmapLegend.class; |
|
39 |
} |
|
40 |
|
|
41 |
} |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.impl/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<artifactId>org.gvsig.legend.heatmap.lib.impl</artifactId> |
|
4 |
<name>org.gvsig.legend.heatmap.lib.impl</name> |
|
5 |
<parent> |
|
6 |
<groupId>org.gvsig</groupId> |
|
7 |
<artifactId>org.gvsig.legend.heatmap.lib</artifactId> |
|
8 |
<version>1.0.39</version> |
|
9 |
</parent> |
|
10 |
<groupId>org.gvsig</groupId> |
|
11 |
<dependencies> |
|
12 |
<dependency> |
|
13 |
<groupId>org.gvsig</groupId> |
|
14 |
<artifactId>org.gvsig.legend.heatmap.lib.api</artifactId> |
|
15 |
<scope>compile</scope> |
|
16 |
</dependency> |
|
17 |
<dependency> |
|
18 |
<groupId>org.gvsig</groupId> |
|
19 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
20 |
<scope>compile</scope> |
|
21 |
</dependency> |
|
22 |
<dependency> |
|
23 |
<groupId>org.gvsig</groupId> |
|
24 |
<artifactId>org.gvsig.symbology.lib.impl</artifactId> |
|
25 |
<scope>compile</scope> |
|
26 |
</dependency> |
|
27 |
<dependency> |
|
28 |
<groupId>org.gvsig</groupId> |
|
29 |
<artifactId>org.gvsig.ui</artifactId> |
|
30 |
<scope>compile</scope> |
|
31 |
</dependency> |
|
32 |
</dependencies> |
|
33 |
</project> |
|
0 | 34 |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.lib/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.legend.heatmap</artifactId> |
|
6 |
<version>1.0.39</version> |
|
7 |
</parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.legend.heatmap.lib</artifactId> |
|
10 |
<packaging>pom</packaging> |
|
11 |
<modules> |
|
12 |
<module>org.gvsig.legend.heatmap.lib.api</module> |
|
13 |
<module>org.gvsig.legend.heatmap.lib.impl</module> |
|
14 |
</modules> |
|
15 |
</project> |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.legend.heatmap.lib.api.HeatmapLegendLibrary |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.api/src/main/java/org/gvsig/legend/heatmap/lib/api/HeatmapLegendManager.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2015 gvSIG Association |
|
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 3 |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.legend.heatmap.lib.api; |
|
24 |
|
|
25 |
|
|
26 |
public interface HeatmapLegendManager { |
|
27 |
|
|
28 |
/** |
|
29 |
* Creates an aggregate legend |
|
30 |
* |
|
31 |
* @return the aggregate legend |
|
32 |
*/ |
|
33 |
public HeatmapLegend create(); |
|
34 |
|
|
35 |
public Class<? extends HeatmapLegend> getLegendClass(); |
|
36 |
} |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.api/src/main/java/org/gvsig/legend/heatmap/lib/api/HeatmapLegend.java | ||
---|---|---|
1 |
package org.gvsig.legend.heatmap.lib.api; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import org.gvsig.fmap.geom.Geometry; |
|
5 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
6 |
|
|
7 |
public interface HeatmapLegend extends IVectorLegend { |
|
8 |
|
|
9 |
public int getDistance(); |
|
10 |
|
|
11 |
public void setDistance(int distance); |
|
12 |
|
|
13 |
public void setColorTable(Color[] colorTable); |
|
14 |
|
|
15 |
public void setColorTable(int numColors, Color coldColor, Color hotColor); |
|
16 |
|
|
17 |
public Color[] getSourceColorTable(); |
|
18 |
|
|
19 |
public Color[] getTargetColorTable(); |
|
20 |
|
|
21 |
public Geometry getROI(); |
|
22 |
|
|
23 |
public void setROI(Geometry roi); |
|
24 |
|
|
25 |
public boolean useRamp(); |
|
26 |
|
|
27 |
public String getFieldName(); |
|
28 |
|
|
29 |
public void setFieldName(String fieldName); |
|
30 |
|
|
31 |
public int getColorTableHotColorAlpha(); |
|
32 |
|
|
33 |
public void setColorTableHotColorAlpha(int colorTableHotColorAlpha); |
|
34 |
|
|
35 |
public int getColorTableColdColorAlpha(); |
|
36 |
|
|
37 |
public void setColorTableColdColorAlpha(int colorTableColdColorAlpha); |
|
38 |
|
|
39 |
public boolean useAlphaInColorTable(); |
|
40 |
|
|
41 |
public boolean setUseAlphaInColorTable(boolean use); |
|
42 |
|
|
43 |
public int getRampNumColors(); |
|
44 |
|
|
45 |
public Color getRampColdColor(); |
|
46 |
|
|
47 |
public Color getRampHotColor(); |
|
48 |
|
|
49 |
} |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.api/src/main/java/org/gvsig/legend/heatmap/lib/api/HeatmapLegendLocator.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2015 gvSIG Association |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.legend.heatmap.lib.api; |
|
24 |
|
|
25 |
import org.gvsig.tools.locator.AbstractLocator; |
|
26 |
import org.gvsig.tools.locator.Locator; |
|
27 |
import org.gvsig.tools.locator.LocatorException; |
|
28 |
|
|
29 |
|
|
30 |
public class HeatmapLegendLocator extends AbstractLocator { |
|
31 |
|
|
32 |
/** |
|
33 |
* HeatmapLegend locator name |
|
34 |
*/ |
|
35 |
private static final String LOCATOR_NAME = "HeatmapLegendLocator"; |
|
36 |
|
|
37 |
/** |
|
38 |
* HeatmapLegend manager name |
|
39 |
*/ |
|
40 |
public static final String MANAGER_NAME = "HeatmapLegendManager"; |
|
41 |
|
|
42 |
/** |
|
43 |
* HeatmapLegend manager description |
|
44 |
*/ |
|
45 |
private static final String MANAGER_DESCRIPTION = |
|
46 |
"HeatmapLegend Manager of gvSIG"; |
|
47 |
|
|
48 |
|
|
49 |
/** |
|
50 |
* Unique instance |
|
51 |
*/ |
|
52 |
private static final HeatmapLegendLocator instance = new HeatmapLegendLocator(); |
|
53 |
|
|
54 |
@Override |
|
55 |
public String getLocatorName() { |
|
56 |
return LOCATOR_NAME; |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Registers the Class implementing the HeatmapLegendManager interface. |
|
61 |
* |
|
62 |
* @param clazz |
|
63 |
* implementing the HeatmapLegendManager interface |
|
64 |
*/ |
|
65 |
public static void registerHeatmapLegendManager(Class clazz){ |
|
66 |
getInstance().register(MANAGER_NAME, MANAGER_DESCRIPTION, clazz); |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Registers the default Class implementing the HeatmapLegendManager interface |
|
71 |
* |
|
72 |
* @param clazz |
|
73 |
* implementing the HeatmapLegendManager interface |
|
74 |
*/ |
|
75 |
public static void registerDefaultHeatmapLegendManager(Class clazz){ |
|
76 |
getInstance().registerDefault(MANAGER_NAME, MANAGER_DESCRIPTION, clazz); |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Return a reference to HeatmapLegendManager. |
|
81 |
* |
|
82 |
* @return a reference to HeatmapLegendManager |
|
83 |
* @throws LocatorException |
|
84 |
* if there is no access to the class or the class |
|
85 |
* cannot be instantiated |
|
86 |
* @see Locator#get(String) |
|
87 |
*/ |
|
88 |
public static HeatmapLegendManager getHeatmapLegendManager() throws LocatorException { |
|
89 |
return (HeatmapLegendManager) getInstance().get(MANAGER_NAME); |
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* @return |
|
94 |
*/ |
|
95 |
public static Locator getInstance() { |
|
96 |
return instance; |
|
97 |
} |
|
98 |
|
|
99 |
} |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.api/src/main/java/org/gvsig/legend/heatmap/lib/api/HeatmapLegendLibrary.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2015 gvSIG Association |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.legend.heatmap.lib.api; |
|
24 |
|
|
25 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
26 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
27 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter; |
|
28 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
|
29 |
import org.gvsig.symbology.SymbologyLocator; |
|
30 |
import org.gvsig.symbology.SymbologyManager; |
|
31 |
import org.gvsig.tools.library.AbstractLibrary; |
|
32 |
import org.gvsig.tools.library.LibraryException; |
|
33 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
|
34 |
|
|
35 |
|
|
36 |
public class HeatmapLegendLibrary extends AbstractLibrary { |
|
37 |
|
|
38 |
@Override |
|
39 |
protected void doInitialize() throws LibraryException { |
|
40 |
registerAsAPI(HeatmapLegendLibrary.class); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
protected void doPostInitialize() throws LibraryException { |
|
45 |
// Validate there is any implementation registered. |
|
46 |
HeatmapLegendManager manager = HeatmapLegendLocator.getHeatmapLegendManager(); |
|
47 |
if (manager == null) { |
|
48 |
throw new ReferenceNotRegisteredException( |
|
49 |
HeatmapLegendLocator.MANAGER_NAME, HeatmapLegendLocator.getInstance()); |
|
50 |
} |
|
51 |
|
|
52 |
SymbologyManager symbolManager = SymbologyLocator.getSymbologyManager(); |
|
53 |
ILegendWriter legendWriter = symbolManager.getDefaultLegendWriter(); |
|
54 |
|
|
55 |
MapContextManager mcoman = MapContextLocator.getMapContextManager(); |
|
56 |
mcoman.registerLegendWriter( |
|
57 |
HeatmapLegend.class, |
|
58 |
SymbolManager.LEGEND_FILE_EXTENSION.substring(1), |
|
59 |
legendWriter.getClass()); |
|
60 |
} |
|
61 |
|
|
62 |
} |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.api/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<groupId>org.gvsig</groupId> |
|
4 |
<artifactId>org.gvsig.legend.heatmap.lib.api</artifactId> |
|
5 |
<name>org.gvsig.legend.heatmap.lib.api</name> |
|
6 |
<parent> |
|
7 |
<groupId>org.gvsig</groupId> |
|
8 |
<artifactId>org.gvsig.legend.heatmap.lib</artifactId> |
|
9 |
<version>1.0.39</version> |
|
10 |
</parent> |
|
11 |
|
|
12 |
<build> |
|
13 |
<plugins> |
|
14 |
<plugin> |
|
15 |
<groupId>org.apache.maven.plugins</groupId> |
|
16 |
<artifactId>maven-jar-plugin</artifactId> |
|
17 |
<configuration> |
|
18 |
</configuration> |
|
19 |
<executions> |
|
20 |
<!-- Generates a jar file only with the test classes --> |
|
21 |
<execution> |
|
22 |
<goals> |
|
23 |
<goal>test-jar</goal> |
|
24 |
</goals> |
|
25 |
</execution> |
|
26 |
</executions> |
|
27 |
</plugin> |
|
28 |
</plugins> |
|
29 |
</build> |
|
30 |
|
|
31 |
<dependencies> |
|
32 |
<dependency> |
|
33 |
<groupId>org.gvsig</groupId> |
|
34 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
35 |
<scope>compile</scope> |
|
36 |
</dependency> |
|
37 |
<dependency> |
|
38 |
<groupId>org.gvsig</groupId> |
|
39 |
<artifactId>org.gvsig.fmap.mapcontext.api</artifactId> |
|
40 |
<scope>compile</scope> |
|
41 |
</dependency> |
|
42 |
<dependency> |
|
43 |
<groupId>org.gvsig</groupId> |
|
44 |
<artifactId>org.gvsig.symbology.lib.api</artifactId> |
|
45 |
</dependency> |
|
46 |
</dependencies> |
|
47 |
</project> |
|
0 | 48 |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.swing/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.legend.heatmap</artifactId> |
|
6 |
<version>1.0.39</version> |
|
7 |
</parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.legend.heatmap.swing</artifactId> |
|
10 |
<packaging>pom</packaging> |
|
11 |
<name>org.gvsig.legend.heatmap.swing</name> |
|
12 |
<modules> |
|
13 |
<module>org.gvsig.legend.heatmap.swing.api</module> |
|
14 |
<module>org.gvsig.legend.heatmap.swing.impl</module> |
|
15 |
</modules> |
|
16 |
</project> |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.swing/org.gvsig.legend.heatmap.swing.api/src/main/java/org/gvsig/legend/heatmap/swing/api/HeatmapLegendSwingManager.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2015 gvSIG Association |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.legend.heatmap.swing.api; |
|
24 |
|
|
25 |
public interface HeatmapLegendSwingManager { |
|
26 |
|
|
27 |
public HeatmapLegendEditor createHeatmapdLegendEditor(); |
|
28 |
} |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.swing/org.gvsig.legend.heatmap.swing.api/src/main/java/org/gvsig/legend/heatmap/swing/api/HeatmapLegendEditor.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.legend.heatmap.swing.api; |
|
3 |
|
|
4 |
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel; |
|
5 |
|
|
6 |
|
|
7 |
public interface HeatmapLegendEditor extends ILegendPanel { |
|
8 |
|
|
9 |
} |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.swing/org.gvsig.legend.heatmap.swing.api/src/main/java/org/gvsig/legend/heatmap/swing/api/HeatmapLegendSwingLocator.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2015 gvSIG Association |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.legend.heatmap.swing.api; |
|
24 |
|
|
25 |
import org.gvsig.tools.locator.AbstractLocator; |
|
26 |
import org.gvsig.tools.locator.Locator; |
|
27 |
import org.gvsig.tools.locator.LocatorException; |
|
28 |
|
|
29 |
|
|
30 |
public class HeatmapLegendSwingLocator extends AbstractLocator { |
|
31 |
|
|
32 |
private static final String LOCATOR_NAME = "HeatmapLegendSwingLocator"; |
|
33 |
|
|
34 |
public static final String MANAGER_NAME = "HeatmapLegendSwingManager"; |
|
35 |
|
|
36 |
private static final String MANAGER_DESCRIPTION = |
|
37 |
"Swing Heatmap Manager of gvSIG"; |
|
38 |
|
|
39 |
|
|
40 |
/** |
|
41 |
* Unique instance |
|
42 |
*/ |
|
43 |
private static final HeatmapLegendSwingLocator instance = new HeatmapLegendSwingLocator(); |
|
44 |
|
|
45 |
|
|
46 |
@Override |
|
47 |
public String getLocatorName() { |
|
48 |
return LOCATOR_NAME; |
|
49 |
} |
|
50 |
|
|
51 |
|
|
52 |
/** |
|
53 |
* Registers the Class implementing the HeatmapSwingManager interface. |
|
54 |
* |
|
55 |
* @param clazz |
|
56 |
* implementing the HeatmapSwingManager interface |
|
57 |
*/ |
|
58 |
public static void registerHeatmapLegendSwingManager(Class clazz){ |
|
59 |
getInstance().register(MANAGER_NAME, MANAGER_DESCRIPTION, clazz); |
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* Registers the default Class implementing the HeatmapSwingManager interface |
|
64 |
* |
|
65 |
* @param clazz |
|
66 |
* implementing the HeatmapSwingManager interface |
|
67 |
*/ |
|
68 |
public static void registerDefaultHeatmapLegendSwingManager(Class clazz){ |
|
69 |
getInstance().registerDefault(MANAGER_NAME, MANAGER_DESCRIPTION, clazz); |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Return a reference to HeatmapLegendSwingManager. |
|
74 |
* |
|
75 |
* @return a reference to HeatmapLegendSwingManager |
|
76 |
* @throws LocatorException |
|
77 |
* if there is no access to the class or the class |
|
78 |
* cannot be instantiated |
|
79 |
* @see Locator#get(String) |
|
80 |
*/ |
|
81 |
public static HeatmapLegendSwingManager getHeatmapLegendSwingManager() throws LocatorException { |
|
82 |
return (HeatmapLegendSwingManager)(getInstance().get(MANAGER_NAME)); |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* @return |
|
87 |
*/ |
|
88 |
public static Locator getInstance() { |
|
89 |
return instance; |
|
90 |
} |
|
91 |
|
|
92 |
} |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.swing/org.gvsig.legend.heatmap.swing.api/src/main/java/org/gvsig/legend/heatmap/swing/api/HeatmapLegendSwingLibrary.java | ||
---|---|---|
1 |
/* gvSIG. Desktop Geographic Information System. |
|
2 |
* |
|
3 |
* Copyright ? 2007-2015 gvSIG Association |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
18 |
* MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us |
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.legend.heatmap.swing.api; |
|
24 |
|
|
25 |
import org.gvsig.legend.heatmap.lib.api.HeatmapLegendLibrary; |
|
26 |
import org.gvsig.tools.library.AbstractLibrary; |
|
27 |
import org.gvsig.tools.library.LibraryException; |
|
28 |
import org.gvsig.tools.locator.ReferenceNotRegisteredException; |
|
29 |
import org.slf4j.Logger; |
|
30 |
import org.slf4j.LoggerFactory; |
|
31 |
|
|
32 |
|
|
33 |
public class HeatmapLegendSwingLibrary extends AbstractLibrary { |
|
34 |
|
|
35 |
private static final Logger LOG = LoggerFactory.getLogger(HeatmapLegendSwingLibrary.class); |
|
36 |
|
|
37 |
@Override |
|
38 |
protected void doInitialize() throws LibraryException { |
|
39 |
registerAsAPI(HeatmapLegendSwingLibrary.class); |
|
40 |
require(HeatmapLegendLibrary.class); |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
protected void doPostInitialize() throws LibraryException { |
|
45 |
// Validate there is any implementation registered. |
|
46 |
HeatmapLegendSwingManager manager = HeatmapLegendSwingLocator.getHeatmapLegendSwingManager(); |
|
47 |
if (manager == null) { |
|
48 |
throw new ReferenceNotRegisteredException( |
|
49 |
HeatmapLegendSwingLocator.MANAGER_NAME, HeatmapLegendSwingLocator.getInstance()); |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
|
|
54 |
} |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.swing/org.gvsig.legend.heatmap.swing.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.legend.heatmap.swing.api.HeatmapLegendSwingLibrary |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.swing/org.gvsig.legend.heatmap.swing.api/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.legend.heatmap.swing</artifactId> |
|
6 |
<version>1.0.39</version> |
|
7 |
</parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.legend.heatmap.swing.api</artifactId> |
|
10 |
<name>org.gvsig.legend.heatmap.swing.api</name> |
|
11 |
<dependencies> |
|
12 |
<dependency> |
|
13 |
<groupId>org.gvsig</groupId> |
|
14 |
<artifactId>org.gvsig.tools.swing.api</artifactId> |
|
15 |
<scope>compile</scope> |
|
16 |
</dependency> |
|
17 |
<dependency> |
|
18 |
<groupId>org.gvsig</groupId> |
|
19 |
<artifactId>org.gvsig.legend.heatmap.lib.api</artifactId> |
|
20 |
<scope>compile</scope> |
|
21 |
</dependency> |
|
22 |
<dependency> |
|
23 |
<groupId>org.gvsig</groupId> |
|
24 |
<artifactId>org.gvsig.symbology.swing.api</artifactId> |
|
25 |
<version>2.0.199</version> |
|
26 |
<type>jar</type> |
|
27 |
</dependency> |
|
28 |
</dependencies> |
|
29 |
</project> |
|
0 | 30 |
org.gvsig.legend.heatmap/tags/org.gvsig.legend.heatmap-1.0.39/org.gvsig.legend.heatmap.swing/org.gvsig.legend.heatmap.swing.impl/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.legend.heatmap.swing</artifactId> |
|
6 |
<version>1.0.39</version> |
|
7 |
</parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.legend.heatmap.swing.impl</artifactId> |
|
10 |
<dependencies> |
|
11 |
<dependency> |
|
12 |
<groupId>org.gvsig</groupId> |
|
13 |
<artifactId>org.gvsig.legend.heatmap.swing.api</artifactId> |
|
14 |
<scope>compile</scope> |
|
15 |
</dependency> |
Also available in: Unified diff