From ae53f8dd425831c3992332323d98f412486df8c8 Mon Sep 17 00:00:00 2001 From: AlexisDrogoul Date: Wed, 1 May 2024 18:46:04 +0700 Subject: [PATCH] Allows to lock Java2D displays in the code (#9) --- .../gama/core/outputs/LayeredDisplayData.java | 7 +- .../core/outputs/LayeredDisplayOutput.java | 5 ++ .../ui/display/java2d/AWTDisplayView.java | 16 +++-- .../display/java2d/Java2DDisplaySurface.java | 25 +++---- .../opengl/view/OpenGLDisplayView.java | 13 ++-- .../views/toolbar/IToolbarDecoratedView.java | 2 +- .../shared/views/toolbar/ZoomController.java | 17 ++--- .../gama/ui/viewers/gis/GISFileViewer.java | 72 +++++++++---------- .../gama/ui/viewers/image/ImageViewer.java | 13 ++-- 9 files changed, 90 insertions(+), 80 deletions(-) diff --git a/gama.core/src/gama/core/outputs/LayeredDisplayData.java b/gama.core/src/gama/core/outputs/LayeredDisplayData.java index 11ac95b99e..1d7af9e69a 100644 --- a/gama.core/src/gama/core/outputs/LayeredDisplayData.java +++ b/gama.core/src/gama/core/outputs/LayeredDisplayData.java @@ -1,9 +1,9 @@ /******************************************************************************************************* * * LayeredDisplayData.java, in gama.core, 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, TLU, CTU) + * (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. * @@ -625,6 +625,9 @@ public void initWith(final IScope scope, final IDescription desc) { final IExpression antialias = facets.getExpr("antialias"); if (antialias != null) { setAntialias(Cast.asBool(scope, antialias.value(scope))); } + final IExpression locked = facets.getExpr("locked"); + if (locked != null) { setCameraLocked(Cast.asBool(scope, locked.value(scope))); } + if (camera != null) { camera.refresh(scope); } if (rotation != null) { rotation.refresh(scope); } lights.forEach((s, l) -> l.refresh(scope)); diff --git a/gama.core/src/gama/core/outputs/LayeredDisplayOutput.java b/gama.core/src/gama/core/outputs/LayeredDisplayOutput.java index f11eef22e8..3bc502d65b 100644 --- a/gama.core/src/gama/core/outputs/LayeredDisplayOutput.java +++ b/gama.core/src/gama/core/outputs/LayeredDisplayOutput.java @@ -212,6 +212,11 @@ type = IType.BOOL, optional = true, doc = @doc ("Allows to enable/disable the light at once. Default is true")), + @facet ( + name = "locked", + type = IType.BOOL, + optional = true, + doc = @doc ("Allows to lock/unlock a 2D display when it opens. For 3D displays please use the `camera` statement")), @facet ( name = "draw_diffuse_light", type = IType.BOOL, 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 9a7c637eea..d23ac336a4 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 @@ -1,9 +1,9 @@ /******************************************************************************************************* * - * AWTDisplayView.java, in gama.ui.display.java2d, is part of the source code of the GAMA modeling and simulation platform - * . + * AWTDisplayView.java, in gama.ui.display.java2d, 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, TLU, CTU) + * (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. * @@ -28,11 +28,13 @@ public class AWTDisplayView extends LayeredDisplayView { @Override protected Composite createSurfaceComposite(final Composite parent) { if (getOutput() == null) return null; - surfaceComposite = SwingControl.create(parent, AWTDisplayView.this, (Java2DDisplaySurface) getDisplaySurface(), - SWT.NO_FOCUS); + surfaceComposite = SwingControl.create(parent, AWTDisplayView.this, getDisplaySurface(), SWT.NO_FOCUS); return surfaceComposite; } + @Override + public Java2DDisplaySurface getDisplaySurface() { return (Java2DDisplaySurface) super.getDisplaySurface(); } + @Override public void ownCreatePartControl(final Composite c) { super.ownCreatePartControl(c); @@ -56,7 +58,6 @@ public void focusCanvas() { WorkbenchHelper.asyncRun(() -> centralPanel.forceFocus()); } - @Override public IDisposable getMultiListener() { SWTLayeredDisplayMultiListener listener = (SWTLayeredDisplayMultiListener) super.getMultiListener(); @@ -74,4 +75,7 @@ public boolean is2D() { return true; } + @Override + public boolean isLocked() { return getDisplaySurface().isLocked(); } + } \ 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 1903552736..746b0695fd 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 @@ -145,7 +145,7 @@ public class Java2DDisplaySurface extends JPanel implements IDisplaySurface { Point mousePosition; /** The is locked. */ - private boolean is_locked = false; + private boolean isLocked = false; /** * Instantiates a new java 2 D display surface. @@ -158,11 +158,11 @@ public Java2DDisplaySurface(final Object... args) { output.setSurface(this); setDisplayScope(output.getScope().copyForGraphics("in java2D display")); output.getData().addListener(this); - // temp_focus = output.getFacet(IKeyword.FOCUS); setDoubleBuffered(true); setIgnoreRepaint(true); setLayout(new BorderLayout()); setBackground(output.getData().getBackgroundColor()); + isLocked = output.getData().isCameraLocked(); setName(output.getName()); layerManager = new LayerManager(this, output); @@ -227,7 +227,7 @@ public void setMousePosition(final int xm, final int ym) { @Override public void draggedTo(final int x, final int y) { - if (!is_locked) { + if (!isLocked) { final Point origin = getOrigin(); setOrigin(origin.x + x - getMousePosition().x, origin.y + y - getMousePosition().y); updateDisplay(true); @@ -413,12 +413,6 @@ public void focusOn(final IShape geometry) { updateDisplay(true); } - // - // @Override - // public void validate() {} - // - // @Override - // public void doLayout() {} /** * Zoom. @@ -446,19 +440,26 @@ private void zoom(final boolean in) { @Override public void zoomIn() { - if (!is_locked) { zoom(true); } + if (!isLocked) { zoom(true); } } @Override public void zoomOut() { - if (!is_locked) { zoom(false); } + if (!isLocked) { zoom(false); } } @Override public void toggleLock() { - is_locked = !is_locked; + isLocked = !isLocked; } + /** + * Checks if is locked. + * + * @return true, if is locked + */ + public boolean isLocked() { return isLocked; } + /** * Checks if is image edge in panel. * 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 3cffb54ecc..94dee55944 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.2.0.0). + * 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, TLU, CTU) - * - * Visit https://github.com/gama-platform/gama2 for license information and contacts. + * (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; @@ -131,4 +131,7 @@ public boolean is2D() { return false; } + @Override + public boolean isLocked() { return getCameraHelper().isCameraLocked(); } + } 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 d42436374c..fcf9c80c08 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(); /** * * @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; } /** * * 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 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 8a8b80bff3..f6948e2e99 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 @@ -1,9 +1,9 @@ /******************************************************************************************************* * - * ZoomController.java, in gama.ui.shared.shared, is part of the source code of the GAMA modeling and simulation - * platform . + * ZoomController.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, TLU, CTU) + * (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. * @@ -102,9 +102,7 @@ public void controlResized(final ControlEvent e) { // toolbar } } - if (view.getCameraHelper() != null && cameraLocked != null) { - tb.setSelection(cameraLocked, view.getCameraHelper().isCameraLocked()); - } + if (cameraLocked != null) { tb.setSelection(cameraLocked, view.isLocked()); } tb.removeControlListener(this); } @@ -127,7 +125,7 @@ protected void fillMenu() { @Override public void widgetSelected(final SelectionEvent e) { view.getCameraHelper().setCameraName(p); - cameraLocked.setSelection(view.getCameraHelper().isCameraLocked()); + cameraLocked.setSelection(view.isLocked()); } }, p.equals(view.getCameraHelper().getCameraName()) @@ -149,9 +147,8 @@ public void widgetSelected(final SelectionEvent e) { menu.open(tb.getToolbar(SWT.RIGHT), trigger, tb.height, 96); }, SWT.RIGHT); } - cameraLocked = tb.check(IGamaIcons.CAMERA_LOCK, "Lock/unlock", "Lock/unlock camera", e -> { - view.toggleLock(); - }, SWT.RIGHT); + cameraLocked = tb.check(IGamaIcons.CAMERA_LOCK, "Lock/unlock", "Lock/unlock view", e -> { view.toggleLock(); }, + SWT.RIGHT); } } 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 cb6630e127..37ef34d758 100644 --- a/gama.ui.viewers/src/gama/ui/viewers/gis/GISFileViewer.java +++ b/gama.ui.viewers/src/gama/ui/viewers/gis/GISFileViewer.java @@ -1,9 +1,9 @@ /******************************************************************************************************* * - * GISFileViewer.java, in gama.ui.shared.viewers, is part of the source code of the - * GAMA modeling and simulation platform . + * 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, TLU, CTU) + * (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. * @@ -44,28 +44,28 @@ public abstract class GISFileViewer extends EditorPart /** The pane. */ SwtMapPane pane; - + /** The content. */ MapContent content; - + /** The toolbar. */ GamaToolbar2 toolbar; - + /** The file. */ IFile file; - + /** The feature source. */ SimpleFeatureSource featureSource; - + /** The no CRS. */ boolean noCRS = false; - + /** The style. */ Style style; - + /** The layer. */ Layer layer; - + /** The path str. */ String pathStr; @@ -79,14 +79,10 @@ public void doSave(final IProgressMonitor monitor) {} public void doSaveAs() {} @Override - public boolean isDirty() { - return false; - } + public boolean isDirty() { return false; } @Override - public boolean isSaveAsAllowed() { - return false; - } + public boolean isSaveAsAllowed() { return false; } @Override public void createPartControl(final Composite composite) { @@ -118,7 +114,7 @@ public void dispose() { @Override public void zoomIn() { - if(!locked) { + if (!locked) { final ReferencedEnvelope env = pane.getDisplayArea(); env.expandBy(-env.getWidth() / 10, -env.getHeight() / 10); pane.setDisplayArea(env); @@ -127,7 +123,7 @@ public void zoomIn() { @Override public void zoomOut() { - if(!locked) { + if (!locked) { final ReferencedEnvelope env = pane.getDisplayArea(); env.expandBy(env.getWidth() / 10, env.getHeight() / 10); pane.setDisplayArea(env); @@ -145,19 +141,18 @@ public void toggleLock() { pane.toggleLock(); } + @Override + public boolean isLocked() { return locked; } + /** * Gets the map composite. * * @return the map composite */ - public Control getMapComposite() { - return pane; - } + public Control getMapComposite() { return pane; } @Override - public Control[] getZoomableControls() { - return new Control[] { pane }; - } + public Control[] getZoomableControls() { return new Control[] { pane }; } /** * Method createToolItem() @@ -183,28 +178,27 @@ public boolean zoomWhenScrolling() { /** * Save as CSV. * - * @param attributes the attributes - * @param geoms the geoms - * @param name the name + * @param attributes + * the attributes + * @param geoms + * the geoms + * @param name + * the name */ public void saveAsCSV(final List attributes, final List geoms, final String name) { - String path = ""; + StringBuilder path = new StringBuilder(); final String[] decomp = pathStr.split("\\."); - for (int i = 0; i < decomp.length - 1; i++) { - path += decomp[i] + (i < decomp.length - 2 ? "." : ""); - } + for (int i = 0; i < decomp.length - 1; i++) { path.append(decomp[i]).append(i < decomp.length - 2 ? "." : ""); } if (name != null) { - path += name + "."; + path.append(name).append("."); } else { - path += "."; + path.append("."); } - path += "csv"; - final File fcsv = new File(path); + path.append("csv"); + final File fcsv = new File(path.toString()); try (FileWriter fw = new FileWriter(fcsv, false)) { fw.write("id"); - for (final String att : attributes) { - fw.write(";" + att); - } + for (final String att : attributes) { fw.write(";" + att); } fw.write(Strings.LN); if (geoms != null) { int cpt = 0; 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 b33c73836a..1a478f2c4d 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.shared.viewers, is part of the source code of the GAMA modeling and simulation platform - * . + * 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, TLU, CTU) + * (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; @@ -77,9 +77,9 @@ import gama.dev.DEBUG; import gama.ui.navigator.metadata.ImageDataLoader; import gama.ui.shared.resources.GamaColors; +import gama.ui.shared.resources.GamaColors.GamaUIColor; import gama.ui.shared.resources.IGamaColors; import gama.ui.shared.resources.IGamaIcons; -import gama.ui.shared.resources.GamaColors.GamaUIColor; import gama.ui.shared.utils.PreferencesHelper; import gama.ui.shared.utils.WorkbenchHelper; import gama.ui.shared.views.toolbar.GamaToolbar2; @@ -819,4 +819,7 @@ public boolean zoomWhenScrolling() { // // @Override // public void setToogle(final Action toggle) {} + + @Override + public boolean isLocked() { return locked; } }