Revision 43326 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/legend/impl/AbstractVectorialLegend.java

View differences:

AbstractVectorialLegend.java
42 42
import org.gvsig.compat.CompatLocator;
43 43
import org.gvsig.compat.print.PrintAttributes;
44 44
import org.gvsig.fmap.dal.exception.DataException;
45
import org.gvsig.fmap.dal.exception.ReadException;
46 45
import org.gvsig.fmap.dal.feature.Feature;
47 46
import org.gvsig.fmap.dal.feature.FeatureQuery;
48 47
import org.gvsig.fmap.dal.feature.FeatureReference;
49 48
import org.gvsig.fmap.dal.feature.FeatureSelection;
50 49
import org.gvsig.fmap.dal.feature.FeatureSet;
51 50
import org.gvsig.fmap.dal.feature.FeatureStore;
52
import org.gvsig.fmap.dal.feature.FeatureType;
53 51
import org.gvsig.fmap.dal.feature.exception.ConcurrentDataModificationException;
54 52
import org.gvsig.fmap.geom.Geometry;
55 53
import org.gvsig.fmap.geom.GeometryLocator;
......
59 57
import org.gvsig.fmap.geom.exception.ReprojectionRuntimeException;
60 58
import org.gvsig.fmap.geom.operation.DrawInts;
61 59
import org.gvsig.fmap.geom.operation.DrawOperationContext;
62
import org.gvsig.fmap.geom.operation.GeometryOperationException;
63
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
64 60
import org.gvsig.fmap.geom.primitive.Envelope;
65 61
import org.gvsig.fmap.mapcontext.MapContext;
66 62
import org.gvsig.fmap.mapcontext.MapContextException;
67 63
import org.gvsig.fmap.mapcontext.ViewPort;
68
import org.gvsig.fmap.mapcontext.layers.vectorial.IntersectsEnvelopeEvaluator;
69 64
import org.gvsig.fmap.mapcontext.layers.vectorial.SpatialEvaluatorsFactory;
70 65
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
71 66
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
......
76 71
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
77 72
import org.gvsig.tools.ToolsLocator;
78 73
import org.gvsig.tools.dispose.DisposableIterator;
74
import org.gvsig.tools.dispose.DisposeUtils;
79 75
import org.gvsig.tools.dynobject.DynStruct;
80 76
import org.gvsig.tools.evaluator.Evaluator;
81 77
import org.gvsig.tools.exception.BaseException;
......
95 91
 * Provides a draw method implementation which loads the {@link Feature}s and
96 92
 * uses the {@link ISymbol} objects to draw the {@link Geometry} objects.
97 93
 *
98
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
99 94
 */
100 95
public abstract class AbstractVectorialLegend extends AbstractLegend implements
101 96
IVectorLegend {
......
129 124
    }
130 125

  
131 126
    @SuppressWarnings("unchecked")
127
    @Override
132 128
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
133 129
        Cancellable cancel, double scale, Map queryParameters,
134 130
        ICoordTrans coordTrans, FeatureStore featureStore)
......
139 135
    }
140 136

  
141 137
    @SuppressWarnings("unchecked")
138
    @Override
142 139
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
143 140
        Cancellable cancel, double scale, Map queryParameters,
144 141
        ICoordTrans coordTrans, FeatureStore featureStore, FeatureQuery featureQuery)
......
147 144
        draw(image, g, viewPort, cancel, scale, queryParameters, coordTrans,
148 145
            featureStore, featureQuery, dpi);
149 146
    }
150

  
147
    
151 148
    @SuppressWarnings("unchecked")
149
    @Override
152 150
    public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
153 151
        double scale, Map queryParameters, ICoordTrans coordTrans,
154 152
        FeatureStore featureStore, PrintAttributes properties)
......
158 156
    }
159 157

  
160 158
    @SuppressWarnings("unchecked")
159
    @Override
161 160
    public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel,
162 161
        double scale, Map queryParameters, ICoordTrans coordTrans,
163 162
        FeatureStore featureStore, FeatureQuery fquery, PrintAttributes properties)
......
176 175
        DisposableIterator it = null;
177 176
        try {
178 177
            ZSort zSort = getZSort();
179

  
180
            // if layer has map levels it will use a ZSort
181
            boolean useZSort = zSort != null && zSort.isUsingZSort();
182

  
183
            int mapLevelCount = (useZSort) ? zSort.getLevelCount() : 1;
178
            boolean useZSort = false;
179
            int mapLevelCount = 1;
180
            
181
            if( zSort != null ) {
182
                useZSort = zSort.isUsingZSort();
183
                if( useZSort ) {
184
                    mapLevelCount = zSort.getLevelCount();
185
                }
186
            }
184 187
            for (int mapPass = 0; mapPass < mapLevelCount; mapPass++) {
185 188

  
186
                Envelope vp_env_in_store_crs = null;
187
                IProjection store_crs = null;
189
                Envelope vp_env_in_store_crs;
190
                IProjection store_crs;
188 191
                if (coordTrans != null) {
189 192
                    // 'coordTrans' is from store crs to vp crs
190 193
                    ICoordTrans inv = coordTrans.getInverted();
......
198 201

  
199 202
                FeatureQuery feat_query = fquery;
200 203
                Envelope store_env = featureStore.getEnvelope();
201
                boolean use_intersection_cond = false;
204
                boolean use_intersection_cond;
202 205
                if (store_env == null) {
203 206
                    // Store does not know its envelope, so we must:
204 207
                    use_intersection_cond = true;
......
327 330
    /**
328 331
     * Draws the features from the {@link FeatureStore}, filtered with the scale
329 332
     * and the query parameters, with the symbols of the legend.
333
     * @param image
334
     * @param g
335
     * @param viewPort
336
     * @param cancel
337
     * @param scale
338
     * @param queryParameters
339
     * @param coordTrans
340
     * @param featureStore
341
     * @param featureQuery
342
     * @param dpi
343
     * @throws org.gvsig.fmap.mapcontext.rendering.legend.LegendException
330 344
     */
331 345
    @SuppressWarnings("unchecked")
332 346
	protected void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
......
346 360
						featureQuery, dpi, taskStatus);
347 361
			}
348 362
		} finally {
349
			if (taskStatus != null) {
350
				taskStatus.terminate();
351
				taskStatus.remove();
352
				taskStatus = null;
353
			}
363
            taskStatus.terminate();
364
            taskStatus.remove();
354 365
		}
355 366
	}
356 367

  
......
453 464
			drawFeatures(image, g, viewPort, cancel, coordTrans, dpi,
454 465
					drawnNotification, featureSet, selection);
455 466

  
456
        } catch (RuntimeException e) {
467
        } catch (Throwable e) {
457 468
            /*
458 469
             * Probably a reprojection exception (for example,
459 470
             * trying to reproject Canada to EPSG:23030)
460 471
             */
461 472
            throw new LegendDrawingException(e);
462
		} catch (BaseException e) {
463
			throw new LegendDrawingException(e);
464 473
		} finally {
465 474
			if (featureSet != null) {
466 475
				featureSet.dispose();
......
485 494
            featureQuery.addAttributeName(fieldNames[i]);
486 495
        }
487 496

  
488
        // TODO: Mobile has it's own IntersectsEnvelopeEvaluator
489 497
        if (!containsAll) {
490 498
            // Gets the viewport envelope with the data SRS
491 499
            Envelope viewPortEnvelopeInMyProj = viewPortEnvelope;
492
            // FIXME
493 500
            if (coordTrans != null) {
494 501
                viewPortEnvelopeInMyProj = viewPortEnvelope.convert(coordTrans
495 502
                        .getInverted());
......
551 558

  
552 559
        try {
553 560
            featureSet.accept(new Visitor() {
561
                @Override
554 562
                public void visit(Object obj) throws VisitCanceledException,
555 563
                BaseException {
556 564
                    Feature feat = (Feature) obj;
......
561 569

  
562 570
        } catch (ConcurrentDataModificationException e) {
563 571
            cancel.setCanceled(true);
564
            return;
565 572
        }
566 573
    }
567 574

  
......
596 603
            } catch (ReprojectionRuntimeException re) {
597 604
                LOG.warn("Can't reproject geometry "+geom.toString(), re);
598 605
                return;
599

  
600
                /*
601
                 * Library was unable to reproject
602
                 * See reproject method in Point2D (geometry)
603
                 */
604
//                throw new CreateGeometryException(
605
//                    geom.getGeometryType().getType(),
606
//                    geom.getGeometryType().getSubType(),
607
//                    re);
608 606
            }
609 607
        }
610 608

  
......
634 632
        long time = System.currentTimeMillis();
635 633

  
636 634
        boolean bSymbolLevelError = false;
637
        // render temporary map each screenRefreshRate milliseconds;
638 635
        int screenRefreshDelay = (int) ((1D / MapContext.getDrawFrameRate()) * 3 * 1000);
639
        BufferedImage[] imageLevels = null;
640
        Graphics2D[] graphics = null;
636
        BufferedImage[] imageLevels;
637
        Graphics2D[] graphics;
641 638

  
642 639
        imageLevels = new BufferedImage[getZSort().getLevelCount()];
643 640
        graphics = new Graphics2D[imageLevels.length];
......
651 648
            graphics[i].setTransform(g.getTransform());
652 649
            graphics[i].setRenderingHints(g.getRenderingHints());
653 650
        }
654
        // -- end visual FX stuff
655 651

  
656 652
        DisposableIterator it = null;
657 653
        try {
......
672 668
            cancel.setCanceled(true);
673 669
            return;
674 670
        } finally {
675
            if (it != null) {
676
                it.dispose();
677
            }
671
            DisposeUtils.dispose(it);
678 672
        }
679 673

  
680 674
        g.drawImage(image, 0, 0, null);
......
692 686
        CompatLocator.getGraphicsUtils().translate(g, -offset.getX(),
693 687
            -offset.getY());
694 688

  
695
        imageLevels = null;
696
        graphics = null;
697

  
698 689
        if (bSymbolLevelError) {
699 690
            setZSort(null);
700 691
        }
......
715 706
        boolean bSymbolLevelError = false;
716 707
        long drawingTime = time;
717 708

  
718
        if (geom==null && geom.getType() == Geometry.TYPES.NULL) {
709
        if (geom==null || geom.getType() == Geometry.TYPES.NULL) {
719 710
            return false;
720 711
        }
721 712

  
......
879 870
        }
880 871
    }
881 872

  
873
    @Override
882 874
    public Object clone() throws CloneNotSupportedException {
883 875
        AbstractVectorialLegend clone = (AbstractVectorialLegend) super.clone();
884 876

  
......
890 882
        return clone;
891 883
    }
892 884

  
885
    @Override
893 886
    public void loadFromState(PersistentState state)
894 887
    throws PersistenceException {
895 888
        // Set parent properties
......
903 896
        setDefaultSymbol((ISymbol) state.get(FIELD_DEFAULT_SYMBOL));
904 897
    }
905 898

  
899
    @Override
906 900
    public void saveToState(PersistentState state) throws PersistenceException {
907 901
        // Save parent properties
908 902
        super.saveToState(state);
......
914 908

  
915 909
    public static class RegisterPersistence implements Callable {
916 910

  
911
        @Override
917 912
        public Object call() throws Exception {
918 913
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
919 914
            if (manager
......
924 919
                    VECTORIAL_LEGEND_PERSISTENCE_DEFINITION_NAME
925 920
                    + " persistence definition", null, null);
926 921
                // Extend the Legend base definition
927
                definition.extend(manager
928
                    .getDefinition(LEGEND_PERSISTENCE_DEFINITION_NAME));
922
                definition.extend(manager.getDefinition(LEGEND_PERSISTENCE_DEFINITION_NAME));
929 923

  
930 924
                // Shapetype
931 925
                definition.addDynFieldInt(FIELD_SHAPETYPE).setMandatory(true);
932 926
                // ZSort
933
                definition.addDynFieldBoolean(FIELD_HAS_ZSORT).setMandatory(
934
                    true);
927
                definition.addDynFieldBoolean(FIELD_HAS_ZSORT).setMandatory(true);
935 928
                // Default symbol
936 929
                definition.addDynFieldObject(FIELD_DEFAULT_SYMBOL)
937
                .setClassOfValue(ISymbol.class).setMandatory(true);
930
                    .setClassOfValue(ISymbol.class).setMandatory(true);
938 931
            }
939 932
            return Boolean.TRUE;
940 933
        }

Also available in: Unified diff