105 |
105 |
* @author Vicente Caballero Navarro
|
106 |
106 |
* @author Cesar Martinez Izquierdo
|
107 |
107 |
*/
|
108 |
|
public class FFrameView extends FFrame implements IFFrameUseProject, IFFrameUseFMap {
|
|
108 |
public class FFrameView extends FFrame implements IFFrameUseProject,
|
|
109 |
IFFrameUseFMap, LayoutPanelListener{
|
109 |
110 |
|
110 |
111 |
public static final String PERSISTENCE_DEFINITION_NAME = "FFrameView";
|
111 |
112 |
|
... | ... | |
157 |
158 |
protected OwnMapContextListener ownMapContextListener;
|
158 |
159 |
private boolean b_hasToc = true;
|
159 |
160 |
protected static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
160 |
|
protected Envelope oldViewEnvelope = null;
|
161 |
161 |
|
162 |
162 |
/**
|
163 |
163 |
* When we load a FFrameview from project, it will receive a wrong
|
... | ... | |
218 |
218 |
* @param r Envelope to be set
|
219 |
219 |
*/
|
220 |
220 |
public void setNewEnvelope(Envelope r) {
|
221 |
|
if (getView()!=null) {
|
222 |
|
oldViewEnvelope = getView().getMapContext().getViewPort().getAdjustedEnvelope();
|
223 |
|
}
|
224 |
221 |
getMapContext().getViewPort().setEnvelope(r);
|
225 |
222 |
updateScaleCtrl();
|
226 |
223 |
}
|
... | ... | |
285 |
282 |
* @param viewMapContext
|
286 |
283 |
*/
|
287 |
284 |
public void setViewMapContext(MapContext viewMapContext) {
|
|
285 |
Envelope oldEnvelope = null;
|
288 |
286 |
if (mapContext!=null) {
|
289 |
287 |
clearOwnListeners(mapContext);
|
|
288 |
if (mapContext.getViewPort()!=null) {
|
|
289 |
oldEnvelope = mapContext.getViewPort().getEnvelope();
|
|
290 |
}
|
290 |
291 |
}
|
291 |
292 |
try {
|
292 |
293 |
if (syncLayers){
|
... | ... | |
300 |
301 |
.getViewPort().clone());
|
301 |
302 |
}
|
302 |
303 |
ViewPort newViewPort = getMapContext().getViewPort();
|
303 |
|
if (!syncExtents && oldViewEnvelope!=null) {
|
|
304 |
if (!syncExtents && oldEnvelope!=null) {
|
304 |
305 |
// if extent is not synced with the view, restore the previous
|
305 |
306 |
// envelope if existing
|
306 |
|
newViewPort.setEnvelope(oldViewEnvelope);
|
|
307 |
newViewPort.setEnvelope(oldEnvelope);
|
307 |
308 |
}
|
308 |
309 |
AffineTransform at;
|
309 |
310 |
if (getLayoutContext()!=null) {
|
... | ... | |
335 |
336 |
public void setView(ViewDocument dvd) {
|
336 |
337 |
ViewDocument oldDoc = viewDocument;
|
337 |
338 |
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 |
339 |
if (oldDoc.getMapContext()!=null) {
|
348 |
340 |
clearViewListeners(oldDoc.getMapContext());
|
349 |
341 |
}
|
... | ... | |
404 |
396 |
drawDraft(g);
|
405 |
397 |
}
|
406 |
398 |
}
|
407 |
|
updateScaleCtrl(); // we need to update the scale whenever the window gets activated
|
408 |
399 |
}
|
409 |
400 |
postDraw(g, fframeViewRect, at);
|
410 |
401 |
if (showGrid && grid != null) {
|
... | ... | |
492 |
483 |
if (oldEnvelope==null) {
|
493 |
484 |
return;
|
494 |
485 |
}
|
|
486 |
|
495 |
487 |
Envelope newEnvelope = getVisibleEnvelope(fframeViewRect, visibleRect);
|
496 |
488 |
// image size must be set before the envelope, as it has influence on the adjustedExtent
|
497 |
489 |
getMapContext().getViewPort().setImageSize(new Dimension(drawWidth, drawHeight));
|
... | ... | |
630 |
622 |
|
631 |
623 |
// FIXME: should we clone the mapcontext and viewport before printing ??
|
632 |
624 |
// otherwise we will probably have unexpected results if the user modifies
|
633 |
|
// the layout while printing
|
|
625 |
// the layout while printing (answer: not an issue at the moment as printing is
|
|
626 |
// a blocking operation)
|
634 |
627 |
ViewPort viewPort = this.getMapContext().getViewPort();
|
635 |
628 |
|
636 |
629 |
Point2D old_offset = viewPort.getOffset();
|
... | ... | |
800 |
793 |
}
|
801 |
794 |
statusbar.setMessage("units",
|
802 |
795 |
PluginServices.getText(this, mapContext.getDistanceName()));
|
|
796 |
String scale;
|
|
797 |
if (fixedScale!=null && getScaleType()==SCALE_TYPE.FIXED_SCALE) {
|
|
798 |
// prefer fixedScale as getScaleView() may offer slight differences
|
|
799 |
// because the influence of the adjusted envelope
|
|
800 |
scale = String.valueOf(fixedScale.longValue());
|
|
801 |
}
|
|
802 |
else {
|
|
803 |
scale = String.valueOf(getMapContext().getScaleView());
|
|
804 |
}
|
803 |
805 |
statusbar.setControlValue("layout-view-change-scale",
|
804 |
|
String.valueOf(getMapContext().getScaleView()));
|
|
806 |
scale);
|
805 |
807 |
IProjection proj = mapContext.getViewPort().getProjection();
|
806 |
808 |
if (proj != null) {
|
807 |
809 |
statusbar.setMessage("projection", proj.getAbrev());
|
... | ... | |
930 |
932 |
else {
|
931 |
933 |
syncLayers = true;
|
932 |
934 |
}
|
|
935 |
double layoutScale = state.getDouble(SCALE_FIELD);
|
|
936 |
Envelope envelope = (Envelope) state.get(ENVELOPE_FIELD);
|
|
937 |
|
933 |
938 |
if (state.hasValue(SCALE_TYPE_FIELD)) {
|
934 |
939 |
int value = state.getInt(SCALE_TYPE_FIELD);
|
935 |
940 |
if (value==SCALE_TYPE.FIXED_EXTENT.ordinal()) {
|
936 |
941 |
scaleType = SCALE_TYPE.FIXED_EXTENT;
|
|
942 |
fixedExtent = envelope;
|
937 |
943 |
}
|
938 |
944 |
else if (value==SCALE_TYPE.FIXED_SCALE.ordinal()) {
|
939 |
945 |
scaleType = SCALE_TYPE.FIXED_SCALE;
|
|
946 |
fixedScale = new Double(layoutScale);
|
940 |
947 |
}
|
941 |
948 |
// else use the default value
|
942 |
949 |
}
|
... | ... | |
954 |
961 |
// create 2 separate EventBuffers, which will then have a very stange behaviour
|
955 |
962 |
}
|
956 |
963 |
if (getMapContext()!=null) {
|
957 |
|
double mapScale = state.getDouble(SCALE_FIELD);
|
958 |
|
getMapContext().setScaleView((long)mapScale);
|
959 |
|
Envelope envelope = (Envelope) state.get(ENVELOPE_FIELD);
|
|
964 |
getMapContext().setScaleView((long)layoutScale);
|
960 |
965 |
getMapContext().getViewPort().setEnvelope(envelope);
|
961 |
|
if (scaleType == SCALE_TYPE.FIXED_SCALE) {
|
962 |
|
fixedScale = new Double(mapScale);
|
963 |
|
}
|
964 |
|
else if (scaleType == SCALE_TYPE.FIXED_EXTENT) {
|
965 |
|
fixedExtent = envelope;
|
966 |
|
}
|
967 |
966 |
if (this.getLayoutContext()!=null) {
|
968 |
967 |
this.getLayoutContext().setTocModel(getMapContext());
|
969 |
968 |
}
|
... | ... | |
997 |
996 |
}
|
998 |
997 |
else {
|
999 |
998 |
state.set(ENVELOPE_FIELD, getMapContext().getViewPort()
|
1000 |
|
.getEnvelope());
|
|
999 |
.getAdjustedEnvelope());
|
1001 |
1000 |
}
|
1002 |
1001 |
}
|
1003 |
1002 |
|
... | ... | |
1018 |
1017 |
getMapContext().setScaleView((long) scale);
|
1019 |
1018 |
}
|
1020 |
1019 |
updateScaleCtrl();
|
1021 |
|
// FIXME: what should we do here? should we invalidate the cache?
|
1022 |
|
// should we also trigger a Layout redraw?
|
1023 |
1020 |
refresh();
|
1024 |
1021 |
}
|
1025 |
1022 |
}
|
... | ... | |
1201 |
1198 |
* @param newEnvelope
|
1202 |
1199 |
* @return
|
1203 |
1200 |
*/
|
1204 |
|
protected Envelope calculateNewExtent(Envelope newEnvelope) {
|
1205 |
|
if (isPan(oldViewEnvelope, newEnvelope)) {
|
1206 |
|
Envelope envelope = getMapContext().getViewPort().getAdjustedEnvelope();
|
1207 |
|
double shiftX = newEnvelope.getMinimum(0) - oldViewEnvelope.getMinimum(0);
|
1208 |
|
double shiftY = newEnvelope.getMinimum(1) - oldViewEnvelope.getMinimum(1);
|
|
1201 |
protected Envelope calculateNewExtent() {
|
|
1202 |
Envelope newEnvelope = getView().getMapContext().getViewPort().getEnvelope();
|
|
1203 |
Envelope oldViewEnvelope = null;
|
|
1204 |
try {
|
|
1205 |
if (getView().getMapContext().getViewPort().getEnvelopes().hasPrevious()) {
|
|
1206 |
Rectangle2D r = getView().getMapContext().getViewPort().getEnvelopes().get();
|
|
1207 |
oldViewEnvelope = GeometryLocator.getGeometryManager().createEnvelope(r.getMinX(), r.getMinY(), r.getMaxX(), r.getMaxY(), SUBTYPES.GEOM2D);
|
|
1208 |
}
|
|
1209 |
if (isPan(oldViewEnvelope, newEnvelope)) {
|
|
1210 |
Envelope envelope = getMapContext().getViewPort().getAdjustedEnvelope();
|
|
1211 |
double shiftX = newEnvelope.getMinimum(0) - oldViewEnvelope.getMinimum(0);
|
|
1212 |
double shiftY = newEnvelope.getMinimum(1) - oldViewEnvelope.getMinimum(1);
|
1209 |
1213 |
|
1210 |
|
double minX = envelope.getMinimum(0) + shiftX;
|
1211 |
|
double minY = envelope.getMinimum(1) + shiftY;
|
1212 |
|
double maxX = envelope.getMaximum(0) + shiftX;
|
1213 |
|
double maxY = envelope.getMaximum(1) + shiftY;
|
1214 |
|
try {
|
|
1214 |
double minX = envelope.getMinimum(0) + shiftX;
|
|
1215 |
double minY = envelope.getMinimum(1) + shiftY;
|
|
1216 |
double maxX = envelope.getMaximum(0) + shiftX;
|
|
1217 |
double maxY = envelope.getMaximum(1) + shiftY;
|
|
1218 |
|
1215 |
1219 |
return GeometryLocator.getGeometryManager().createEnvelope(minX, minY, maxX, maxY, SUBTYPES.GEOM2D);
|
1216 |
1220 |
}
|
1217 |
|
catch (LocatorException e) {}
|
1218 |
|
catch (CreateEnvelopeException e) {}
|
1219 |
|
|
1220 |
1221 |
}
|
|
1222 |
catch (LocatorException e) {}
|
|
1223 |
catch (CreateEnvelopeException e) {}
|
1221 |
1224 |
return newEnvelope;
|
1222 |
1225 |
}
|
1223 |
1226 |
|
... | ... | |
1236 |
1239 |
getView().getMapContext().getViewPort().setEnvelope(fixedExtent);
|
1237 |
1240 |
}
|
1238 |
1241 |
else {
|
1239 |
|
getMapContext().getViewPort().setEnvelope(calculateNewExtent(e.getNewExtent()));
|
|
1242 |
getMapContext().getViewPort().setEnvelope(calculateNewExtent());
|
1240 |
1243 |
if (scaleType==SCALE_TYPE.FIXED_SCALE) {
|
1241 |
1244 |
getMapContext().setScaleView(Math.round(fixedScale));
|
1242 |
1245 |
getView().getMapContext().getViewPort().setEnvelope(getMapContext().getViewPort().getAdjustedEnvelope());
|
1243 |
1246 |
}
|
1244 |
|
oldViewEnvelope = getView().getMapContext().getViewPort().getAdjustedEnvelope();
|
1245 |
1247 |
updateScaleCtrl();
|
1246 |
1248 |
invalidateLayout();
|
1247 |
1249 |
}
|
... | ... | |
1366 |
1368 |
if (getView()!=null) {
|
1367 |
1369 |
if (getExtentSynced()){
|
1368 |
1370 |
getView().getMapContext().getViewPort().setEnvelope(newEnvelope);
|
1369 |
|
oldViewEnvelope = getView().getMapContext().getViewPort().getAdjustedEnvelope();
|
1370 |
1371 |
}
|
1371 |
1372 |
}
|
1372 |
1373 |
}
|
... | ... | |
1509 |
1510 |
public boolean getLinked() {
|
1510 |
1511 |
return false;
|
1511 |
1512 |
}
|
|
1513 |
|
|
1514 |
public void windowActivated() {
|
|
1515 |
if (isSelected()
|
|
1516 |
&& getLayoutContext().getSelectedFFrames(IFFrameUseFMap.class).length==1) {
|
|
1517 |
// update the scale control whenever the panel window gets activated,
|
|
1518 |
// as the control instance is shared for all the windows
|
|
1519 |
updateScaleCtrl();
|
|
1520 |
}
|
|
1521 |
|
|
1522 |
}
|
|
1523 |
|
|
1524 |
public void windowClosed() {
|
|
1525 |
}
|
1512 |
1526 |
}
|