Revision 2267

View differences:

org.gvsig.legend.heatmap/trunk/org.gvsig.legend.heatmap/org.gvsig.legend.heatmap.lib/org.gvsig.legend.heatmap.lib.impl/src/main/java/org/gvsig/legend/heatmap/lib/impl/DefaultHeatmapLegend.java
8 8

  
9 9
import org.apache.commons.lang3.StringUtils;
10 10
import org.cresques.cts.ICoordTrans;
11
import org.gvsig.compat.print.PrintAttributes;
11 12

  
12 13
import org.gvsig.fmap.dal.exception.DataException;
13 14
import org.gvsig.fmap.dal.feature.Feature;
......
56 57
        }
57 58

  
58 59
        public void setDistance(int distance) {
60
            if( this.distance == distance ) {
61
                return;
62
            }
59 63
            this.distance = distance;
60 64
            this.kernel = new double[2 * this.distance + 1][2 * this.distance + 1];
61 65
            for( int y = -this.distance; y < this.distance + 1; y++ ) {
......
110 114
            }
111 115
        }
112 116

  
113
        public void draw(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel) {
117
        public void drawWithOpaqueColors(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel) {
114 118
            try {
115 119
                ToolsSwingManager toolsSwingManager = ToolsSwingLocator.getToolsSwingManager();
116 120
                Color c;
......
135 139
                LOG.warn("Problems drawing heatmap", ex);
136 140
            }
137 141
        }
142

  
143
        public void drawWithAlphaColors(BufferedImage img, Graphics2D g, Color[] colorTable, Cancellable cancel) {
144
            try {
145
                Color c;
146
                int maxIndexColor = colorTable.length-1;
147
                for( int x = 0; x < with; x++ ) {
148
                    for( int y = 0; y < height; y++ ) {
149
                        if( cancel.isCanceled() ) {
150
                            return;
151
                        }
152
                        double value = this.grid[x][y];
153
                        if( value > 0 ) {
154
                            int icolor = (int) (value * maxIndexColor / maxValue);
155
                            c = colorTable[icolor];
156
                            img.setRGB(x, y, c.getRGB());
157
                        }
158
                    }
159
                }
160
            } catch (Exception ex) {
161
                LOG.warn("Problems drawing heatmap", ex);
162
            }
163
        }
138 164
    }
139 165

  
140 166
    private ISymbol defaultSymbol;
......
216 242

  
217 243
    @Override
218 244
    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 {
219
        this.algorithm.init(image.getWidth(), image.getHeight());
220
        super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, featureStore, featureQuery, dpi);
221
        if( !cancel.isCanceled() ) {
222
            this.algorithm.draw(image, g, this.getHeatMapColorTable().getColorTable(), cancel);
245
        int saved_distance = this.algorithm.getDistance();
246
        try {
247
            int distance = (int) (this.algorithm.getDistance() * (dpi / 72));
248
            this.algorithm.setDistance(distance);
249
            this.algorithm.init(image.getWidth(), image.getHeight());
250
            super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, featureStore, featureQuery, dpi);
251
            if( !cancel.isCanceled() ) {
252
                this.algorithm.drawWithOpaqueColors(image, g, this.getHeatMapColorTable().getColorTable(), cancel);
253
            }
254
        } finally {
255
            this.algorithm.setDistance(saved_distance);
256

  
223 257
        }
224 258
    }
259
    
260
    @Override
261
    public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
262
            double scale, Map queryParameters, ICoordTrans coordTrans,
263
            FeatureStore featureStore, FeatureQuery featureQuery, PrintAttributes properties)
264
            throws LegendException {
265
        int saved_distance = this.algorithm.getDistance();
266
        try {
267
            double dpi = viewPort.getDPI();
268
            // Ver CartographicSupportToolkit.getCartographicLength
269
            int distance = (int) (this.algorithm.getDistance() * (dpi / 72));
270
            
271
            this.algorithm.setDistance(distance);
272
            this.algorithm.init(viewPort.getImageWidth(), viewPort.getImageHeight());
273
            BufferedImage image = new BufferedImage(viewPort.getImageWidth(), viewPort.getImageHeight(), BufferedImage.TYPE_INT_ARGB);
274
            super.draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans, featureStore, featureQuery, dpi);
275
            if (!cancel.isCanceled()) {
276
                this.algorithm.drawWithAlphaColors(image, g, this.getHeatMapColorTable().getColorTable(), cancel);
277
                g.drawImage(image, 0, 0, null);
278
            }
279
        } finally {
280
            this.algorithm.setDistance(saved_distance);
225 281

  
282
        }
283
    }
284

  
226 285
    @Override
227 286
    protected void drawFeatures(
228 287
        BufferedImage image,

Also available in: Unified diff