Revision 250 trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrameView.java

View differences:

FFrameView.java
119 119
    private static final String HAS_TOC_FIELD = "hasToc";
120 120
    private static final String LAYER_SYNC_FIELD = "layerSync";
121 121
    private static final String EXTENT_SYNC_FIELD = "extentSync";
122
    private static final String SCALE_TYPE_FIELD = "scaleType";
122 123
    // following fields are unused - they are kept for backward-compatibility 
123 124
    private static final String EXTENSION_FIELD = "extension";
124 125
    private static final String BLINKED_FIELD = "bLinked";
......
131 132
        .getLogger(FFrameView.class);
132 133
    public static final int PRESENTATION = 0;
133 134
    public static final int DRAFT = 1;
135

  
134 136
    protected boolean syncLayers = true;
135 137
    protected boolean syncExtents = true;
136 138
    protected int quality = PRESENTATION;
......
167 169
	protected AffineTransform originalGraphicsAT = null;
168 170
	protected Rectangle originalClip = null;
169 171

  
172
	private SCALE_TYPE scaleType = SCALE_TYPE.NORMAL;
173
	private Double fixedScale = null;
174
	private Envelope fixedExtent = null;
170 175

  
176

  
171 177
    /**
172 178
     * Creates a new FFrameView object.
173 179
     */
......
294 300
    					.getViewPort().clone());
295 301
    		}
296 302
    		ViewPort newViewPort = getMapContext().getViewPort();
303
    		if (!syncExtents && oldViewEnvelope!=null) {
304
    			// if extent is not synced with the view, restore the previous
305
    			// envelope if existing
306
    			newViewPort.setEnvelope(oldViewEnvelope);
307
    		}
297 308
    		AffineTransform at;
298 309
    		if (getLayoutContext()!=null) {
299 310
    			at = getLayoutContext().getAT();
......
323 334
     */
324 335
    public void setView(ViewDocument dvd) {
325 336
    	ViewDocument oldDoc = viewDocument;
326
    	if (oldDoc!=null && oldDoc.getMapContext()!=null) {
327
    		clearViewListeners(oldDoc.getMapContext());
337
    	if (oldDoc!=null) {
338
    		if (oldDoc!=dvd) {
339
    			// Remove the oldEnvelope if the view has changed
340
    			oldViewEnvelope = null;
341
    		}
342
    		else {
343
    			if (getMapContext()!=null && getMapContext().getViewPort()!=null) {
344
    				oldViewEnvelope = getMapContext().getViewPort().getAdjustedEnvelope();
345
    			}
346
    		}
347
    		if (oldDoc.getMapContext()!=null) {
348
    			clearViewListeners(oldDoc.getMapContext());
349
    		}
328 350
    	}
329 351
        viewDocument = dvd;
330 352
        if (dvd!=null) {
......
840 862
            DynStruct definition =
841 863
                manager.addDefinition(FFrameView.class,
842 864
                    PERSISTENCE_DEFINITION_NAME,
843
                    "FFrameView persistence definition", null, null); 
865
                    "FFrameView persistence definition", null, null);
844 866
            definition.extend(manager
845 867
                .getDefinition(FFrame.PERSISTENCE_DEFINITION_NAME));
846 868
            definition.addDynFieldInt(QUALITY_FIELD).setMandatory(true);
......
856 878
            definition.addDynFieldBoolean(HAS_TOC_FIELD).setMandatory(false);
857 879
            definition.addDynFieldBoolean(EXTENT_SYNC_FIELD).setMandatory(false);
858 880
            definition.addDynFieldBoolean(LAYER_SYNC_FIELD).setMandatory(false);
881
            definition.addDynFieldInt(SCALE_TYPE_FIELD).setMandatory(false);
859 882
            // unused fields, kept for backward compatibility
860 883
            definition.addDynFieldInt(MODE_FIELD).setMandatory(false);
861 884
            definition.addDynFieldInt(TYPESCALE_FIELD).setMandatory(false);
......
884 907
        else {
885 908
        	syncLayers = true;
886 909
        }
910
        if (state.hasValue(SCALE_TYPE_FIELD)) {
911
        	int value = state.getInt(SCALE_TYPE_FIELD);
912
        	if (value==SCALE_TYPE.FIXED_EXTENT.ordinal()) {
913
        		scaleType = SCALE_TYPE.FIXED_EXTENT;
914
        	}
915
        	else if (value==SCALE_TYPE.FIXED_SCALE.ordinal()) {
916
        		scaleType = SCALE_TYPE.FIXED_SCALE;
917
        	}
918
        	// else use the default value
919
        }
887 920
        quality = state.getInt(QUALITY_FIELD);
888 921
        mapUnits = state.getInt(MAPUNITS_FIELD);;
889 922
        viewDocument = (ViewDocument) state.get(VIEW_FIELD);
......
900 933
        if (getMapContext()!=null) {
901 934
        	double mapScale = state.getDouble(SCALE_FIELD);
902 935
        	getMapContext().setScaleView((long)mapScale);
903
        	getMapContext().getViewPort().setEnvelope(
904
                (Envelope) state.get(ENVELOPE_FIELD));
936
        	Envelope envelope = (Envelope) state.get(ENVELOPE_FIELD); 
937
        	getMapContext().getViewPort().setEnvelope(envelope);
938
        	if (scaleType == SCALE_TYPE.FIXED_SCALE) {
939
        		fixedScale = new Double(mapScale);
940
        	}
941
        	else if (scaleType == SCALE_TYPE.FIXED_EXTENT) {
942
        		fixedExtent = envelope;
943
        	}
905 944
        	if (this.getLayoutContext()!=null) {
906 945
        		this.getLayoutContext().setTocModel(getMapContext());
907 946
        	}
......
920 959
        state.set(MAPUNITS_FIELD, mapUnits);
921 960
        state.set(VIEW_FIELD, viewDocument);
922 961
        state.set(HAS_TOC_FIELD, b_hasToc);
962
        state.set(SCALE_TYPE_FIELD, scaleType.ordinal());
923 963

  
924 964
        if (getMapContext() != null
925 965
            && getMapContext().getViewPort().getEnvelope() != null) {
926
            state.set(ENVELOPE_FIELD, getMapContext().getViewPort()
927
                .getEnvelope());
928
            state.set(SCALE_FIELD, (double)getMapContext().getScaleView());
966
        	if (scaleType==SCALE_TYPE.FIXED_SCALE && fixedScale!=null) {
967
        		state.set(SCALE_FIELD, (double)fixedScale);
968
        	}
969
        	else {
970
        		state.set(SCALE_FIELD, (double)getMapContext().getScaleView());	
971
        	}
972
        	if (scaleType == SCALE_TYPE.FIXED_EXTENT && fixedExtent!=null) {
973
        		state.set(ENVELOPE_FIELD, fixedExtent);
974
        	}
975
        	else {
976
        		state.set(ENVELOPE_FIELD, getMapContext().getViewPort()
977
                        .getEnvelope());	
978
        	}
929 979
        }
930 980

  
931 981
        state.set(SHOWGRID_FIELD, showGrid);
......
937 987
    	super.setBoundBox(r);
938 988
    	if (getMapContext()!=null) {
939 989
    		AffineTransform at = this.getLayoutContext().getAT();
990
    		long scale = getMapContext().getScaleView();
940 991
    		getMapContext().getViewPort().setImageSize(
941 992
    				new Dimension((int)getBoundingBox(at).getWidth(), (int)getBoundingBox(at).getHeight()));
942 993
    		getMapContext().getViewPort().setDPI(getDrawPaperDPI());
994
    		if (getScaleType()==SCALE_TYPE.FIXED_SCALE) {
995
    			getMapContext().setScaleView((long) scale);
996
    		}
943 997
    		updateScaleCtrl();
944 998
    		// FIXME: what should we do here? should we invalidate the cache?
945 999
    		// should we also trigger a Layout redraw?
......
973 1027

  
974 1028
	public void refresh() {
975 1029
        // FIXME: what should we do here? do we really need to invalidate cache??
976
    	b_validCache = false;		
1030
    	b_validCache = false;
977 1031
	}
978 1032
    
979 1033
    protected void resetListeners() {
......
1153 1207
					b_frameInitialized = true;
1154 1208
					return;
1155 1209
				}
1210
				b_updating = true;
1156 1211
				if (getMapContext()!=null) {
1157
					b_updating = true;
1158
					getMapContext().getViewPort().setEnvelope(calculateNewExtent(e.getNewExtent()));						
1159
					oldViewEnvelope = getView().getMapContext().getViewPort().getAdjustedEnvelope();
1160
					updateScaleCtrl();
1161
					invalidateLayout();
1162
					b_updating = false;
1212
					if (scaleType==SCALE_TYPE.FIXED_EXTENT) {
1213
						getView().getMapContext().getViewPort().setEnvelope(fixedExtent);
1214
					}
1215
					else {
1216
						getMapContext().getViewPort().setEnvelope(calculateNewExtent(e.getNewExtent()));
1217
						if (scaleType==SCALE_TYPE.FIXED_SCALE) {
1218
							getMapContext().setScaleView(Math.round(fixedScale));  
1219
							getView().getMapContext().getViewPort().setEnvelope(getMapContext().getViewPort().getAdjustedEnvelope());
1220
						}
1221
						oldViewEnvelope = getView().getMapContext().getViewPort().getAdjustedEnvelope();
1222
						updateScaleCtrl();
1223
						invalidateLayout();
1224
					}
1163 1225
				}
1226
				b_updating = false;
1164 1227
			}			
1165 1228
		}
1166 1229

  
......
1264 1327

  
1265 1328
		public void extentChanged(ExtentEvent e) {
1266 1329
			if (!b_drawing && !b_updating) {
1267
				if (getView()!=null) {
1268
					b_updating = true;
1269
					if (getExtentSynced()){
1270
						getView().getMapContext().getViewPort().setEnvelope(e.getNewExtent());
1271
						oldViewEnvelope = getView().getMapContext().getViewPort().getAdjustedEnvelope();
1330
				b_updating = true;
1331
				if (scaleType==SCALE_TYPE.FIXED_EXTENT) {
1332
					getMapContext().getViewPort().setEnvelope(fixedExtent);
1333
				}
1334
				else {
1335
					Envelope newEnvelope;
1336
					if (scaleType==SCALE_TYPE.FIXED_SCALE) {
1337
						getMapContext().setScaleView(Math.round(fixedScale));
1338
						newEnvelope = getMapContext().getViewPort().getAdjustedEnvelope();
1272 1339
					}
1273
					updateScaleCtrl();
1274
					invalidateLayout();
1275
					b_updating = false;
1340
					else {
1341
						newEnvelope = e.getNewExtent();
1342
					}
1343
					if (getView()!=null) {
1344
						if (getExtentSynced()){
1345
							getView().getMapContext().getViewPort().setEnvelope(newEnvelope);
1346
							oldViewEnvelope = getView().getMapContext().getViewPort().getAdjustedEnvelope();
1347
						}
1348
					}
1276 1349
				}
1350
				updateScaleCtrl();
1351
				invalidateLayout();
1352
				b_updating = false;
1277 1353
			}			
1278 1354
		}
1279 1355

  
......
1367 1443
			conditionalRedraw();
1368 1444
		}
1369 1445
	}
1446

  
1447
	public void setExtent(Envelope extent) {
1448
		if (getScaleType()==SCALE_TYPE.NORMAL) {
1449
			getMapContext().getViewPort().setEnvelope(extent);
1450
		}
1451
	}
1452

  
1453
	public SCALE_TYPE getScaleType() {
1454
		return scaleType ;
1455
	}
1456

  
1457
	public void setScaleType(SCALE_TYPE scaleType) {
1458
		this.scaleType = scaleType;
1459
	}
1460
	
1461
	public void setScaleType(SCALE_TYPE scaleType, double fixedScale) {
1462
		if (scaleType == SCALE_TYPE.FIXED_SCALE) {
1463
			this.scaleType = scaleType;
1464
			this.fixedScale = new Double(fixedScale);
1465
			setScale(fixedScale);
1466
		}
1467
	}
1468
	
1469
	public void setScaleType(SCALE_TYPE scaleType, Envelope fixedExtent) {
1470
		if (scaleType == SCALE_TYPE.FIXED_EXTENT) {
1471
			this.scaleType = scaleType;
1472
			this.fixedExtent  = fixedExtent;
1473
			setNewEnvelope(fixedExtent);
1474
		}
1475
	}
1476

  
1477
	@Deprecated
1478
	public int getTypeScale() {
1479
		return AUTOMATICO;
1480
	}
1481

  
1482
	@Deprecated
1483
	public void setLinked(boolean b) {}
1484

  
1485
	@Deprecated
1486
	public boolean getLinked() {
1487
		return false;
1488
	}
1370 1489
}

Also available in: Unified diff