From 1c0dbdd1ea88eeaf966f268aac499d0117b02ad8 Mon Sep 17 00:00:00 2001 From: AlexisDrogoul Date: Sat, 12 Oct 2024 17:24:34 +0200 Subject: [PATCH 1/2] Disables the zoom when the camera is dynamic --- .../src/gama/ui/shared/views/toolbar/ZoomController.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gama.ui.shared/src/gama/ui/shared/views/toolbar/ZoomController.java b/gama.ui.shared/src/gama/ui/shared/views/toolbar/ZoomController.java index f6948e2e99..c965a19ac9 100644 --- a/gama.ui.shared/src/gama/ui/shared/views/toolbar/ZoomController.java +++ b/gama.ui.shared/src/gama/ui/shared/views/toolbar/ZoomController.java @@ -102,7 +102,13 @@ public void controlResized(final ControlEvent e) { // toolbar } } - if (cameraLocked != null) { tb.setSelection(cameraLocked, view.isLocked()); } + if (cameraLocked != null) { + boolean locked = view.isLocked(); + tb.setSelection(cameraLocked, locked); + // If locked at the beginning, it means that the camera is dynamic. + // We disable the control (see #350) + cameraLocked.setEnabled(!locked); + } tb.removeControlListener(this); } @@ -149,6 +155,7 @@ public void widgetSelected(final SelectionEvent e) { } cameraLocked = tb.check(IGamaIcons.CAMERA_LOCK, "Lock/unlock", "Lock/unlock view", e -> { view.toggleLock(); }, SWT.RIGHT); + } } From e59ba4349198a840ccf87a356adbc4f6b3a0148c Mon Sep 17 00:00:00 2001 From: AlexisDrogoul Date: Tue, 15 Oct 2024 18:57:06 +0200 Subject: [PATCH 2/2] Address concern about cameras' locked/dynamic facet. The "dynamic" and "locked" states are now clearly separated in terms of logic. While "dynamic: true" prevents the camera to be manipulated and disables the lock button, "locked: true" will allow the user to overcome the state from the UI. --- .../src/gama/core/outputs/LayeredDisplayData.java | 11 +++++++++-- .../layers/properties/CameraDefinition.java | 15 +++++++-------- .../properties/GenericCameraDefinition.java | 15 +++++++++------ .../layers/properties/ICameraDefinition.java | 11 ++++++----- .../gama/ui/display/java2d/AWTDisplayView.java | 5 ++++- .../ui/display/java2d/Java2DDisplaySurface.java | 4 +++- .../opengl/renderer/helpers/CameraHelper.java | 14 +++++++++----- .../ui/display/opengl/view/OpenGLDisplayView.java | 10 ++++++---- .../opengl/view/SWTOpenGLDisplaySurface.java | 2 +- .../views/toolbar/IToolbarDecoratedView.java | 2 +- .../ui/shared/views/toolbar/ZoomController.java | 12 ++++++------ .../src/gama/ui/viewers/gis/GISFileViewer.java | 11 +++++++---- .../src/gama/ui/viewers/image/ImageViewer.java | 11 +++++++---- 13 files changed, 75 insertions(+), 48 deletions(-) diff --git a/gama.core/src/gama/core/outputs/LayeredDisplayData.java b/gama.core/src/gama/core/outputs/LayeredDisplayData.java index ec8b56b9c4..10f49084ec 100644 --- a/gama.core/src/gama/core/outputs/LayeredDisplayData.java +++ b/gama.core/src/gama/core/outputs/LayeredDisplayData.java @@ -688,7 +688,12 @@ public void setZFar(final Double zF) { public void update(final IScope scope, final Facets facets) { if (cameraNameExpression != null) { + boolean isLocked = camera == null ? false : camera.isLocked(); setCameraNameFromGaml(Cast.asString(scope, cameraNameExpression.value(scope))); + if (camera != null) { + // camera.reset(); + camera.setLocked(isLocked); + } } if (camera != null) { camera.refresh(scope); } @@ -885,7 +890,7 @@ public void setCameraTarget(final GamaPoint point) { * the disable cam interact */ public void setCameraLocked(final boolean disableCamInteract) { - camera.setInteractive(!disableCamInteract); + camera.setLocked(disableCamInteract); } /** @@ -893,7 +898,9 @@ public void setCameraLocked(final boolean disableCamInteract) { * * @return true, if successful */ - public boolean isCameraLocked() { return !camera.isInteractive(); } + public boolean isCameraLocked() { return camera.isLocked(); } + + public boolean isCameraDynamic() { return camera.isDynamic(); } // ************************************************************************************************ // ************************************************************************************************ diff --git a/gama.core/src/gama/core/outputs/layers/properties/CameraDefinition.java b/gama.core/src/gama/core/outputs/layers/properties/CameraDefinition.java index 24d6b7fa66..ae70bfe93e 100644 --- a/gama.core/src/gama/core/outputs/layers/properties/CameraDefinition.java +++ b/gama.core/src/gama/core/outputs/layers/properties/CameraDefinition.java @@ -1,7 +1,6 @@ /******************************************************************************************************* * - * CameraDefinition.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform - * . + * CameraDefinition.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform . * * (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU) * @@ -95,7 +94,7 @@ public void update(final IScope scope) { if (temp instanceof String pos) { // If it is a symbolic position double coeff = 1.4; - if ((scope instanceof GraphicsScope gs) && (gs.getGraphics() != null)) { + if (scope instanceof GraphicsScope gs && gs.getGraphics() != null) { coeff = gs.getGraphics().getSurface().getData().getCameraDistanceCoefficient(); } double w = scope.getSimulation().getWidth(); @@ -144,7 +143,7 @@ public void update(final IScope scope) { */ @Override public boolean setLocation(final GamaPoint loc) { - if (!isInteractive() || loc == null) return false; + if (isLocked() || isDynamic() || loc == null) return false; locationAttribute = new ConstantAttribute<>(loc.yNegated()); return current.setLocation(loc); } @@ -159,7 +158,7 @@ public boolean setLocation(final GamaPoint loc) { */ @Override public boolean setTarget(final GamaPoint loc) { - if (!isInteractive() || loc == null) return false; + if (isLocked() || isDynamic() || loc == null) return false; targetAttribute = new ConstantAttribute<>(loc.yNegated()); return current.setTarget(loc); } @@ -180,7 +179,7 @@ public boolean setTarget(final GamaPoint loc) { public Integer getLens() { return lens.get(); } @Override - public Boolean isInteractive() { return !locked.get() && !isDynamic(); } + public Boolean isLocked() { return locked.get(); } /** * Sets the interactive. @@ -189,11 +188,11 @@ public boolean setTarget(final GamaPoint loc) { * the new interactive */ @Override - public void setInteractive(final Boolean b) { this.locked = new ConstantAttribute<>(b == null ? false : !b); } + public void setLocked(final Boolean b) { this.locked = new ConstantAttribute<>(b == null ? false : b); } @Override public boolean setDistance(final Double d) { - if (!isInteractive() || d == null) return false; + if (isLocked() || isDynamic() || d == null) return false; distanceAttribute = new ConstantAttribute<>(d); return current.setDistance(d); } diff --git a/gama.core/src/gama/core/outputs/layers/properties/GenericCameraDefinition.java b/gama.core/src/gama/core/outputs/layers/properties/GenericCameraDefinition.java index 1d0bc745a1..050ea2840d 100644 --- a/gama.core/src/gama/core/outputs/layers/properties/GenericCameraDefinition.java +++ b/gama.core/src/gama/core/outputs/layers/properties/GenericCameraDefinition.java @@ -1,7 +1,6 @@ /******************************************************************************************************* * - * GenericCameraDefinition.java, in gama.core, is part of the source code of the GAMA modeling and simulation - * platform . + * GenericCameraDefinition.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform . * * (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU) * @@ -28,7 +27,7 @@ public class GenericCameraDefinition implements ICameraDefinition { Integer lens = 45; /** The is interactive. */ - Boolean isInteractive = true; + Boolean isLocked = false; /** The name. */ final String name; @@ -83,11 +82,14 @@ public GenericCameraDefinition(final String name, final GamaPoint target, final public Integer getLens() { return lens; } @Override - public Boolean isInteractive() { return isInteractive; } + public Boolean isLocked() { return isLocked; } @Override - public void setInteractive(final Boolean b) { - isInteractive = b; + public Boolean isDynamic() { return false; } + + @Override + public void setLocked(final Boolean b) { + isLocked = b; } @@ -112,6 +114,7 @@ public boolean setTarget(final GamaPoint point) { public void reset() { currentLocation.setLocation(initialLocation); currentTarget.setLocation(initialTarget); + isLocked = false; } @Override diff --git a/gama.core/src/gama/core/outputs/layers/properties/ICameraDefinition.java b/gama.core/src/gama/core/outputs/layers/properties/ICameraDefinition.java index 48a3711164..b9086ce855 100644 --- a/gama.core/src/gama/core/outputs/layers/properties/ICameraDefinition.java +++ b/gama.core/src/gama/core/outputs/layers/properties/ICameraDefinition.java @@ -1,7 +1,6 @@ /******************************************************************************************************* * - * ICameraDefinition.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform - * . + * ICameraDefinition.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform . * * (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU) * @@ -12,9 +11,9 @@ import java.util.List; -import gama.annotations.precompiler.IOperatorCategory; import gama.annotations.precompiler.GamlAnnotations.constant; import gama.annotations.precompiler.GamlAnnotations.doc; +import gama.annotations.precompiler.IOperatorCategory; import gama.core.metamodel.shape.GamaPoint; import gama.core.runtime.IScope; import gama.gaml.interfaces.INamed; @@ -111,7 +110,7 @@ public interface ICameraDefinition extends INamed { * * @return the boolean */ - Boolean isInteractive(); + Boolean isLocked(); /** * Sets the interactive. @@ -119,7 +118,7 @@ public interface ICameraDefinition extends INamed { * @param b * the new interactive */ - void setInteractive(Boolean b); + void setLocked(Boolean b); /** * Sets the location. @@ -206,4 +205,6 @@ default GamaPoint computeLocation(final String pos, final GamaPoint target, fina }; } + Boolean isDynamic(); + } diff --git a/gama.ui.display.java2d/src/gama/ui/display/java2d/AWTDisplayView.java b/gama.ui.display.java2d/src/gama/ui/display/java2d/AWTDisplayView.java index d23ac336a4..4c8b23f7ef 100644 --- a/gama.ui.display.java2d/src/gama/ui/display/java2d/AWTDisplayView.java +++ b/gama.ui.display.java2d/src/gama/ui/display/java2d/AWTDisplayView.java @@ -76,6 +76,9 @@ public boolean is2D() { } @Override - public boolean isLocked() { return getDisplaySurface().isLocked(); } + public boolean isCameraLocked() { return getDisplaySurface().isCameraLocked(); } + + @Override + public boolean isCameraDynamic() { return getDisplaySurface().isCameraDynamic(); } } \ No newline at end of file diff --git a/gama.ui.display.java2d/src/gama/ui/display/java2d/Java2DDisplaySurface.java b/gama.ui.display.java2d/src/gama/ui/display/java2d/Java2DDisplaySurface.java index ec47b4082c..43fb3ae59b 100644 --- a/gama.ui.display.java2d/src/gama/ui/display/java2d/Java2DDisplaySurface.java +++ b/gama.ui.display.java2d/src/gama/ui/display/java2d/Java2DDisplaySurface.java @@ -450,7 +450,9 @@ public void toggleLock() { * * @return true, if is locked */ - public boolean isLocked() { return isLocked; } + public boolean isCameraLocked() { return isLocked; } + + public boolean isCameraDynamic() { return false; } /** * Checks if is image edge in panel. diff --git a/gama.ui.display.opengl/src/gama/ui/display/opengl/renderer/helpers/CameraHelper.java b/gama.ui.display.opengl/src/gama/ui/display/opengl/renderer/helpers/CameraHelper.java index 9c35d0993a..a14e56ca14 100644 --- a/gama.ui.display.opengl/src/gama/ui/display/opengl/renderer/helpers/CameraHelper.java +++ b/gama.ui.display.opengl/src/gama/ui/display/opengl/renderer/helpers/CameraHelper.java @@ -769,7 +769,6 @@ public GamaPoint getWorldPositionFrom(final GamaPoint mouse, final GamaPoint res return result.setLocation(result.x * distance + camLoc.x, result.y * distance + camLoc.y, 0); } - /** * Gets the mouse position. * @@ -1164,16 +1163,21 @@ public void setCameraName(final String p) { public boolean isCameraLocked() { return data.isCameraLocked(); } @Override - public void toggleCamera() { + public boolean isCameraDynamic() { return data.isCameraDynamic(); } + + @Override + public void toggleCameraLock() { data.setCameraLocked(!data.isCameraLocked()); } @Override public String getCameraDefinition() { - StringBuilder text = new StringBuilder(IKeyword.CAMERA).append(" 'default' ").append(IKeyword.LOCATION) - .append(": ").append(new GamaPoint(data.getCameraPos()).yNegated().withPrecision(4).serializeToGaml(false)); + StringBuilder text = + new StringBuilder(IKeyword.CAMERA).append(" 'default' ").append(IKeyword.LOCATION).append(": ") + .append(new GamaPoint(data.getCameraPos()).yNegated().withPrecision(4).serializeToGaml(false)); text.append(" ").append(IKeyword.TARGET).append(": ") - .append(new GamaPoint(data.getCameraTarget()).yNegated().withPrecision(4).serializeToGaml(false)).append(";"); + .append(new GamaPoint(data.getCameraTarget()).yNegated().withPrecision(4).serializeToGaml(false)) + .append(";"); return text.toString(); } diff --git a/gama.ui.display.opengl/src/gama/ui/display/opengl/view/OpenGLDisplayView.java b/gama.ui.display.opengl/src/gama/ui/display/opengl/view/OpenGLDisplayView.java index 94dee55944..5c5dd8f4f2 100644 --- a/gama.ui.display.opengl/src/gama/ui/display/opengl/view/OpenGLDisplayView.java +++ b/gama.ui.display.opengl/src/gama/ui/display/opengl/view/OpenGLDisplayView.java @@ -1,12 +1,12 @@ /******************************************************************************************************* * - * OpenGLDisplayView.java, in gama.ui.display.opengl, is part of the source code of the - * GAMA modeling and simulation platform (v.2024-06). + * OpenGLDisplayView.java, in gama.ui.display.opengl, is part of the source code of the GAMA modeling and simulation + * platform (v.2024-06). * * (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, ESPACE-DEV, CTU) * * Visit https://github.com/gama-platform/gama for license information and contacts. - * + * ********************************************************************************************************/ package gama.ui.display.opengl.view; @@ -132,6 +132,8 @@ public boolean is2D() { } @Override - public boolean isLocked() { return getCameraHelper().isCameraLocked(); } + public boolean isCameraLocked() { return getCameraHelper().isCameraLocked(); } + @Override + public boolean isCameraDynamic() { return getCameraHelper().isCameraDynamic(); } } diff --git a/gama.ui.display.opengl/src/gama/ui/display/opengl/view/SWTOpenGLDisplaySurface.java b/gama.ui.display.opengl/src/gama/ui/display/opengl/view/SWTOpenGLDisplaySurface.java index a5ae3c2681..1eef57e25b 100644 --- a/gama.ui.display.opengl/src/gama/ui/display/opengl/view/SWTOpenGLDisplaySurface.java +++ b/gama.ui.display.opengl/src/gama/ui/display/opengl/view/SWTOpenGLDisplaySurface.java @@ -320,7 +320,7 @@ public void zoomFit() { @Override public void toggleLock() { - renderer.getCameraHelper().toggleCamera(); + renderer.getCameraHelper().toggleCameraLock(); } /** diff --git a/gama.ui.shared/src/gama/ui/shared/views/toolbar/IToolbarDecoratedView.java b/gama.ui.shared/src/gama/ui/shared/views/toolbar/IToolbarDecoratedView.java index fcf9c80c08..0cf31a5d92 100644 --- a/gama.ui.shared/src/gama/ui/shared/views/toolbar/IToolbarDecoratedView.java +++ b/gama.ui.shared/src/gama/ui/shared/views/toolbar/IToolbarDecoratedView.java @@ -1 +1 @@ -/******************************************************************************************************* * * IToolbarDecoratedView.java, in gama.ui.shared, is part of the source code of the GAMA modeling and simulation * platform (v.2024-06). * * (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, ESPACE-DEV, CTU) * * Visit https://github.com/gama-platform/gama for license information and contacts. * ********************************************************************************************************/ package gama.ui.shared.views.toolbar; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collection; import java.util.Collections; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.ui.IWorkbenchSite; import gama.core.common.preferences.GamaPreferences; import gama.core.outputs.IOutput; import gama.core.runtime.GAMA; import gama.ui.shared.resources.GamaColors.GamaUIColor; import gama.ui.shared.utils.WorkbenchHelper; /** * * Class IToolbarDecoratedView. * * * * @author drogoul * * @since 7 déc. 2014 * * * */ public interface IToolbarDecoratedView { /** The null camera. */ ICameraHelper NULL_CAMERA = new ICameraHelper() {}; /** * The Interface ICameraHelper. */ public interface ICameraHelper { /** * * Gets the camera names. * * * * @return the camera names * */ default Collection getCameraNames() { return Collections.EMPTY_LIST; } /** * * Sets the camera name. * * * * @param p * * the new camera name * */ default void setCameraName(final String p) {} /** * * Gets the camera name. * * * * @return the camera name * */ default String getCameraName() { return GamaPreferences.Displays.OPENGL_DEFAULT_CAM.getValue(); } /** * * Checks if is camera locked. * * * * @return true, if is camera locked * */ default boolean isCameraLocked() { return false; } /** * * Toggle camera. * */ default void toggleCamera() {} /** * Gets the camera definition. * * @return the camera definition */ default String getCameraDefinition() { return ""; } } /** * * Gets the site. * * * * @return the site * */ IWorkbenchSite getSite(); /** * * Creates the tool items. * * * * @param tb * * the tb * */ void createToolItems(GamaToolbar2 tb); /** * * Adds the state listener. ✓ Unicode: U+2713, UTF-8: E2 9C 93 * * * * @param listener * * the listener * */ default void addStateListener(final StateListener listener) {} /** * * The listener interface for receiving state events. The class that is interested in processing a state event * * implements this interface, and the object created with that class is registered with a component using the * * component's addStateListener method. When the state event occurs, that object's appropriate method is * * invoked. * * * * @see StateEvent * */ public interface StateListener { /** * * Update to reflect state. * */ void updateToReflectState(); } /** * * The Interface Expandable. * */ public interface Expandable extends IToolbarDecoratedView { /** * * Expand all. * */ void expandAll(); /** * * Collapse all. * */ void collapseAll(); } /** * * The Interface Pausable. * */ public interface Pausable extends IToolbarDecoratedView { /** * * Pause changed. * */ void pauseChanged(); /** * * Gets the output. * * * * @return the output * */ IOutput getOutput(); } /** * * The Interface Sizable. * */ public interface Sizable extends IToolbarDecoratedView { /** * * Gets the sizable font control. * * * * @return the sizable font control * */ Control getSizableFontControl(); } /** * * The Interface Colorizable. * */ public interface Colorizable extends IToolbarDecoratedView { /** * * Gets the color labels. * * * * @return the color labels * */ String[] getColorLabels(); /** * * Gets the color. * * * * @param index * * the index * * @return the color * */ GamaUIColor getColor(int index); /** * * Sets the color. * * * * @param index * * the index * * @param c * * the c * */ void setColor(int index, GamaUIColor c); } /** * * The Interface CSVExportable. * */ public interface CSVExportable extends IToolbarDecoratedView { /** * * Save as CSV. * */ void saveAsCSV(); } /** * * The Interface LogExportable. * */ public interface LogExportable extends IToolbarDecoratedView { /** * * Save as log. * */ default void saveAsLog() { String text = getContents(); FileDialog fd = new FileDialog(WorkbenchHelper.getShell(), SWT.SAVE); fd.setText("Choose a destination file"); fd.setFilterExtensions(new String[] { "*.log" }); if (GAMA.getExperiment() != null && GAMA.getExperiment().getAgent() != null) { fd.setFilterPath(GAMA.getExperiment().getAgent().getProjectPath()); } else { fd.setFilterPath(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); } String f = fd.open(); if (f == null) return; try { Files.writeString(Path.of(f), text, StandardCharsets.UTF_8); } catch (IOException e) {} } /** * * Gets the contents. * * * * @return the contents * */ String getContents(); } /** * * The Interface Zoomable. * */ public interface Zoomable extends IToolbarDecoratedView { /** * * Zoom in. * */ void zoomIn(); /** * * Zoom out. * */ void zoomOut(); /** * * Zoom fit. * */ void zoomFit(); /** * * Locks/unlocks the view. * */ void toggleLock(); /** * Checks if is locked. * * @return true, if is locked */ boolean isLocked(); /** * * @return the controls that will react to gestures / mouse doucle-cliks * */ Control[] getZoomableControls(); /** * * @return true if the scroll triggers the zooming * */ boolean zoomWhenScrolling(); /** * Gets the camera helper. * * @return the camera helper */ default ICameraHelper getCameraHelper() { return NULL_CAMERA; } /** * * Checks for cameras. * * * * @return true, if successful * */ default boolean hasCameras() { return false; } } } \ No newline at end of file +/******************************************************************************************************* * * IToolbarDecoratedView.java, in gama.ui.shared, is part of the source code of the GAMA modeling and simulation * platform (v.2024-06). * * (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, ESPACE-DEV, CTU) * * Visit https://github.com/gama-platform/gama for license information and contacts. * ********************************************************************************************************/ package gama.ui.shared.views.toolbar; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Collection; import java.util.Collections; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.ui.IWorkbenchSite; import gama.core.common.preferences.GamaPreferences; import gama.core.outputs.IOutput; import gama.core.runtime.GAMA; import gama.ui.shared.resources.GamaColors.GamaUIColor; import gama.ui.shared.utils.WorkbenchHelper; /** * * Class IToolbarDecoratedView. * * * * @author drogoul * * @since 7 déc. 2014 * * * */ public interface IToolbarDecoratedView { /** The null camera. */ ICameraHelper NULL_CAMERA = new ICameraHelper() {}; /** * The Interface ICameraHelper. */ public interface ICameraHelper { /** * * Gets the camera names. * * * * @return the camera names * */ default Collection getCameraNames() { return Collections.EMPTY_LIST; } /** * * Sets the camera name. * * * * @param p * * the new camera name * */ default void setCameraName(final String p) {} /** * * Gets the camera name. * * * * @return the camera name * */ default String getCameraName() { return GamaPreferences.Displays.OPENGL_DEFAULT_CAM.getValue(); } /** * * Checks if is camera locked. * * * * @return true, if is camera locked * */ default boolean isCameraLocked() { return false; } default boolean isCameraDynamic() { return false; } /** * * Toggle camera. * */ default void toggleCameraLock() {} /** * Gets the camera definition. * * @return the camera definition */ default String getCameraDefinition() { return ""; } } /** * * Gets the site. * * * * @return the site * */ IWorkbenchSite getSite(); /** * * Creates the tool items. * * * * @param tb * * the tb * */ void createToolItems(GamaToolbar2 tb); /** * * Adds the state listener. ✓ Unicode: U+2713, UTF-8: E2 9C 93 * * * * @param listener * * the listener * */ default void addStateListener(final StateListener listener) {} /** * * The listener interface for receiving state events. The class that is interested in processing a state event * * implements this interface, and the object created with that class is registered with a component using the * * component's addStateListener method. When the state event occurs, that object's appropriate method is * * invoked. * * * * @see StateEvent * */ public interface StateListener { /** * * Update to reflect state. * */ void updateToReflectState(); } /** * * The Interface Expandable. * */ public interface Expandable extends IToolbarDecoratedView { /** * * Expand all. * */ void expandAll(); /** * * Collapse all. * */ void collapseAll(); } /** * * The Interface Pausable. * */ public interface Pausable extends IToolbarDecoratedView { /** * * Pause changed. * */ void pauseChanged(); /** * * Gets the output. * * * * @return the output * */ IOutput getOutput(); } /** * * The Interface Sizable. * */ public interface Sizable extends IToolbarDecoratedView { /** * * Gets the sizable font control. * * * * @return the sizable font control * */ Control getSizableFontControl(); } /** * * The Interface Colorizable. * */ public interface Colorizable extends IToolbarDecoratedView { /** * * Gets the color labels. * * * * @return the color labels * */ String[] getColorLabels(); /** * * Gets the color. * * * * @param index * * the index * * @return the color * */ GamaUIColor getColor(int index); /** * * Sets the color. * * * * @param index * * the index * * @param c * * the c * */ void setColor(int index, GamaUIColor c); } /** * * The Interface CSVExportable. * */ public interface CSVExportable extends IToolbarDecoratedView { /** * * Save as CSV. * */ void saveAsCSV(); } /** * * The Interface LogExportable. * */ public interface LogExportable extends IToolbarDecoratedView { /** * * Save as log. * */ default void saveAsLog() { String text = getContents(); FileDialog fd = new FileDialog(WorkbenchHelper.getShell(), SWT.SAVE); fd.setText("Choose a destination file"); fd.setFilterExtensions(new String[] { "*.log" }); if (GAMA.getExperiment() != null && GAMA.getExperiment().getAgent() != null) { fd.setFilterPath(GAMA.getExperiment().getAgent().getProjectPath()); } else { fd.setFilterPath(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); } String f = fd.open(); if (f == null) return; try { Files.writeString(Path.of(f), text, StandardCharsets.UTF_8); } catch (IOException e) {} } /** * * Gets the contents. * * * * @return the contents * */ String getContents(); } /** * * The Interface Zoomable. * */ public interface Zoomable extends IToolbarDecoratedView { /** * * Zoom in. * */ void zoomIn(); /** * * Zoom out. * */ void zoomOut(); /** * * Zoom fit. * */ void zoomFit(); /** * * Locks/unlocks the view. * */ void toggleLock(); /** * Checks if is locked. * * @return true, if is locked */ boolean isCameraLocked(); boolean isCameraDynamic(); /** * * @return the controls that will react to gestures / mouse doucle-cliks * */ Control[] getZoomableControls(); /** * * @return true if the scroll triggers the zooming * */ boolean zoomWhenScrolling(); /** * Gets the camera helper. * * @return the camera helper */ default ICameraHelper getCameraHelper() { return NULL_CAMERA; } /** * * Checks for cameras. * * * * @return true, if successful * */ default boolean hasCameras() { return false; } } } \ No newline at end of file diff --git a/gama.ui.shared/src/gama/ui/shared/views/toolbar/ZoomController.java b/gama.ui.shared/src/gama/ui/shared/views/toolbar/ZoomController.java index c965a19ac9..3b047ffe3f 100644 --- a/gama.ui.shared/src/gama/ui/shared/views/toolbar/ZoomController.java +++ b/gama.ui.shared/src/gama/ui/shared/views/toolbar/ZoomController.java @@ -103,11 +103,11 @@ public void controlResized(final ControlEvent e) { } } if (cameraLocked != null) { - boolean locked = view.isLocked(); - tb.setSelection(cameraLocked, locked); - // If locked at the beginning, it means that the camera is dynamic. - // We disable the control (see #350) - cameraLocked.setEnabled(!locked); + boolean locked = view.isCameraLocked(); + boolean dynamic = view.isCameraDynamic(); + tb.setSelection(cameraLocked, locked || dynamic); + // If the camera is dynamic, we disable the control (see #350) + cameraLocked.setEnabled(!dynamic); } tb.removeControlListener(this); } @@ -131,7 +131,7 @@ protected void fillMenu() { @Override public void widgetSelected(final SelectionEvent e) { view.getCameraHelper().setCameraName(p); - cameraLocked.setSelection(view.isLocked()); + cameraLocked.setSelection(view.isCameraLocked()); } }, p.equals(view.getCameraHelper().getCameraName()) diff --git a/gama.ui.viewers/src/gama/ui/viewers/gis/GISFileViewer.java b/gama.ui.viewers/src/gama/ui/viewers/gis/GISFileViewer.java index 37ef34d758..6f18443310 100644 --- a/gama.ui.viewers/src/gama/ui/viewers/gis/GISFileViewer.java +++ b/gama.ui.viewers/src/gama/ui/viewers/gis/GISFileViewer.java @@ -1,12 +1,12 @@ /******************************************************************************************************* * - * GISFileViewer.java, in gama.ui.viewers, is part of the source code of the - * GAMA modeling and simulation platform (v.2024-06). + * GISFileViewer.java, in gama.ui.viewers, is part of the source code of the GAMA modeling and simulation platform + * (v.2024-06). * * (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, ESPACE-DEV, CTU) * * Visit https://github.com/gama-platform/gama for license information and contacts. - * + * ********************************************************************************************************/ package gama.ui.viewers.gis; @@ -142,7 +142,10 @@ public void toggleLock() { } @Override - public boolean isLocked() { return locked; } + public boolean isCameraLocked() { return locked; } + + @Override + public boolean isCameraDynamic() { return false; } /** * Gets the map composite. diff --git a/gama.ui.viewers/src/gama/ui/viewers/image/ImageViewer.java b/gama.ui.viewers/src/gama/ui/viewers/image/ImageViewer.java index 1a478f2c4d..31a3035776 100644 --- a/gama.ui.viewers/src/gama/ui/viewers/image/ImageViewer.java +++ b/gama.ui.viewers/src/gama/ui/viewers/image/ImageViewer.java @@ -1,12 +1,12 @@ /******************************************************************************************************* * - * ImageViewer.java, in gama.ui.viewers, is part of the source code of the - * GAMA modeling and simulation platform (v.2024-06). + * ImageViewer.java, in gama.ui.viewers, is part of the source code of the GAMA modeling and simulation platform + * (v.2024-06). * * (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, ESPACE-DEV, CTU) * * Visit https://github.com/gama-platform/gama for license information and contacts. - * + * ********************************************************************************************************/ package gama.ui.viewers.image; @@ -821,5 +821,8 @@ public boolean zoomWhenScrolling() { // public void setToogle(final Action toggle) {} @Override - public boolean isLocked() { return locked; } + public boolean isCameraLocked() { return locked; } + + @Override + public boolean isCameraDynamic() { return false; } }