Skip to content

Commit

Permalink
Ability to lock any Zoomable display.
Browse files Browse the repository at this point in the history
This commits adds the toggleLock() method to the Zoomable interface.
When a Zoomable item is locked, zoomIn(), zoomOut() and dragging of the
view pane have no effect, but zoomFit() is still active.

The ability to lock a display was already available for OpenGL displays,
thanks to the Camera interface. The feature has been generalised, and is
now available for:
- Java2DDisplaySurface
- GISFileViewer
- ImageViewer

The already existing lock control has been added to toolbars
accordingly, to any Zoomable display (see ZoomController).
  • Loading branch information
PaulBreugnot committed Feb 14, 2023
1 parent ea1a690 commit ccc2d0d
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 27 deletions.
Expand Up @@ -132,6 +132,11 @@ public interface OpenGL extends IDisplaySurface {
*/
void zoomFit();

/**
* Toggles surface view lock.
*/
void toggleLock();

/**
* Gets the manager.
*
Expand Down
6 changes: 5 additions & 1 deletion msi.gama.core/src/msi/gama/outputs/ImageDisplaySurface.java
Expand Up @@ -256,6 +256,10 @@ public void zoomFit() {

}

@Override
public void toggleLock() {
}

/*
* (non-Javadoc)
*
Expand Down Expand Up @@ -536,4 +540,4 @@ public void setMenuManager(final Object displaySurfaceMenu) {}
@Override
public IGraphics getIGraphics() { return displayGraphics; }

}
}
Expand Up @@ -93,6 +93,14 @@ public void zoomOut() {}
@Override
public void zoomFit() {}

/**
* Method zoomFit()
*
* @see msi.gama.common.interfaces.IDisplaySurface#toggleLock()
*/
@Override
public void toggleLock(){}

/**
* Method getManager()
*
Expand Down
Expand Up @@ -142,6 +142,8 @@ public class Java2DDisplaySurface extends JPanel implements IDisplaySurface {
/** The mouse position. */
Point mousePosition;

private boolean is_locked = false;

/**
* Instantiates a new java 2 D display surface.
*
Expand Down Expand Up @@ -210,10 +212,12 @@ public void setMousePosition(final int xm, final int ym) {

@Override
public void draggedTo(final int x, final int y) {
final Point origin = getOrigin();
setOrigin(origin.x + x - getMousePosition().x, origin.y + y - getMousePosition().y);
if(!is_locked) {
final Point origin = getOrigin();
setOrigin(origin.x + x - getMousePosition().x, origin.y + y - getMousePosition().y);
updateDisplay(true);
}
setMousePosition(x, y);
updateDisplay(true);
}

@Override
Expand Down Expand Up @@ -417,12 +421,19 @@ private void zoom(final boolean in) {

@Override
public void zoomIn() {
zoom(true);
if(!is_locked)
zoom(true);
}

@Override
public void zoomOut() {
zoom(false);
if(!is_locked)
zoom(false);
}

@Override
public void toggleLock() {
is_locked = !is_locked;
}

/**
Expand Down Expand Up @@ -845,4 +856,4 @@ public boolean isVisible() {
return visibilityBlock.get();
}

}
}
Expand Up @@ -300,7 +300,11 @@ public void zoomFit() {
output.getData().setZoomLevel(renderer.getCameraHelper().zoomLevel(), true);
// output.getData().setZoomLevel(LayeredDisplayData.INITIAL_ZOOM, true, true);
zoomFit = true;
}

@Override
public void toggleLock() {
renderer.getCameraHelper().toggleCamera();
}

/**
Expand Down
Expand Up @@ -333,6 +333,11 @@ public void zoomFit() {
if (getDisplaySurface() != null) { getDisplaySurface().zoomFit(); }
}

@Override
public void toggleLock() {
if (getDisplaySurface() != null) { getDisplaySurface().toggleLock(); }
}

@Override
public Control[] getZoomableControls() { return new Control[] { getParentComposite() }; }

Expand Down
Expand Up @@ -266,6 +266,11 @@ public interface Zoomable extends IToolbarDecoratedView {
*/
void zoomFit();

/**
* Locks/unlocks the view.
*/
void toggleLock();

/**
* @return the controls that will react to gestures / mouse doucle-cliks
*/
Expand Down
Expand Up @@ -146,11 +146,10 @@ public void widgetSelected(final SelectionEvent e) {
};
menu.open(tb.getToolbar(SWT.RIGHT), trigger, tb.height, 96);
}, SWT.RIGHT);
cameraLocked = tb.check("display.lock", "Lock/unlock", "Lock/unlock camera", e -> {
view.getCameraHelper().toggleCamera();
}, SWT.RIGHT);
}

cameraLocked = tb.check("display.lock", "Lock/unlock", "Lock/unlock camera", e -> {
view.toggleLock();
}, SWT.RIGHT);
}

}
Expand Up @@ -69,6 +69,9 @@ public abstract class GISFileViewer extends EditorPart
/** The path str. */
String pathStr;

/** Variable used to specify if the zoom/drag of the view is locked. */
boolean locked = false;

@Override
public void doSave(final IProgressMonitor monitor) {}

Expand Down Expand Up @@ -115,23 +118,33 @@ public void dispose() {

@Override
public void zoomIn() {
final ReferencedEnvelope env = pane.getDisplayArea();
env.expandBy(-env.getWidth() / 10, -env.getHeight() / 10);
pane.setDisplayArea(env);
if(!locked) {
final ReferencedEnvelope env = pane.getDisplayArea();
env.expandBy(-env.getWidth() / 10, -env.getHeight() / 10);
pane.setDisplayArea(env);
}
}

@Override
public void zoomOut() {
final ReferencedEnvelope env = pane.getDisplayArea();
env.expandBy(env.getWidth() / 10, env.getHeight() / 10);
pane.setDisplayArea(env);
if(!locked) {
final ReferencedEnvelope env = pane.getDisplayArea();
env.expandBy(env.getWidth() / 10, env.getHeight() / 10);
pane.setDisplayArea(env);
}
}

@Override
public void zoomFit() {
pane.reset();
}

@Override
public void toggleLock() {
locked = !locked;
pane.toggleLock();
}

/**
* Gets the map composite.
*
Expand Down
Expand Up @@ -154,6 +154,9 @@ public class SwtMapPane extends Canvas
/** The yellow. */
private final Color yellow;

/** Variable used to lock panning */
private boolean locked = false;

/**
* Constructor - creates an instance of JMapPane with the given renderer and map context.
*
Expand Down Expand Up @@ -191,6 +194,10 @@ public void controlResized(final ControlEvent e) {

}

public void toggleLock() {
locked = !locked;
}

@Override
public void mouseMove(final MouseEvent e) {
if (panning) {
Expand All @@ -200,10 +207,12 @@ public void mouseMove(final MouseEvent e) {
}

if (mouseDown) {
endX = e.x;
endY = e.y;
isDragging = true;
if (!isDisposed()) { redraw(); }
if(!locked) {
endX = e.x;
endY = e.y;
isDragging = true;
if (!isDisposed()) { redraw(); }
}
}

}
Expand All @@ -213,9 +222,11 @@ public void mouseDoubleClick(final MouseEvent arg0) {}

@Override
public void mouseDown(final MouseEvent e) {
panePos.x = e.x;
panePos.y = e.y;
panning = true;
if(!locked) {
panePos.x = e.x;
panePos.y = e.y;
panning = true;
}
}

@Override
Expand Down
Expand Up @@ -115,6 +115,9 @@ public class ImageViewer extends EditorPart
/** The max zoom factor. */
double maxZoomFactor = 1.0d;

/** Variable used to specify if the zoom is locked. */
boolean locked = false;

/** The input listener. */
ImageResourceChangeListener inputListener = null;

Expand Down Expand Up @@ -676,12 +679,14 @@ public void setZoomFactor(final double z) {

@Override
public void zoomIn() {
setZoomFactor(getZoomFactor() * 1.1);
if(!locked)
setZoomFactor(getZoomFactor() * 1.1);
}

@Override
public void zoomOut() {
setZoomFactor(getZoomFactor() * 0.9);
if(!locked)
setZoomFactor(getZoomFactor() * 0.9);
}

@Override
Expand All @@ -693,6 +698,11 @@ public void zoomFit() {
}
}

@Override
public void toggleLock() {
locked = !locked;
}

@Override
public Control[] getZoomableControls() {
return new Control[] { intermediate, imageCanvas };
Expand Down Expand Up @@ -813,4 +823,4 @@ public boolean zoomWhenScrolling() {
//
// @Override
// public void setToogle(final Action toggle) {}
}
}

0 comments on commit ccc2d0d

Please sign in to comment.