From 71907c449aede8b00a20054e0a1019206250b158 Mon Sep 17 00:00:00 2001 From: AlexisDrogoul Date: Sun, 25 Jul 2021 12:01:17 +0700 Subject: [PATCH] Replaces an == comparison between Strings by equals --- .../gama/ui/views/displays/SnapshotMaker.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/ummisco.gama.ui.experiment/src/ummisco/gama/ui/views/displays/SnapshotMaker.java b/ummisco.gama.ui.experiment/src/ummisco/gama/ui/views/displays/SnapshotMaker.java index a14e8d8742..53a6f680d6 100644 --- a/ummisco.gama.ui.experiment/src/ummisco/gama/ui/views/displays/SnapshotMaker.java +++ b/ummisco.gama.ui.experiment/src/ummisco/gama/ui/views/displays/SnapshotMaker.java @@ -16,7 +16,6 @@ import msi.gama.common.util.ImageUtils; import msi.gama.outputs.IDisplayOutput; import msi.gama.outputs.LayeredDisplayData; -import msi.gama.outputs.LayeredDisplayOutput; import msi.gama.runtime.GAMA; import msi.gama.runtime.IScope; import msi.gama.runtime.exceptions.GamaRuntimeException; @@ -26,7 +25,7 @@ public class SnapshotMaker { void doSnapshot(final IDisplayOutput output, final IDisplaySurface surface, final Control composite) { - if (output == null || surface == null || composite == null) { return; } + if (output == null || surface == null || composite == null) return; final IScope scope = surface.getScope(); final String snapshotFile = FileUtils.constructAbsoluteFilePath(scope, IDisplaySurface.SNAPSHOT_FOLDER_NAME + "/" + GAMA.getModel().getName() + "_display_" + output.getName(), @@ -37,10 +36,11 @@ void doSnapshot(final IDisplayOutput output, final IDisplaySurface surface, fina final int width = w == -1 ? surface.getWidth() : w; final int height = h == -1 ? surface.getHeight() : h; - final String autosavePath=data.getAutosavePath(); - final String file =autosavePath!=""?autosavePath:(snapshotFile + "_size_" + width + "x" + height + "_cycle_" + scope.getClock().getCycle() - + "_time_" + java.lang.System.currentTimeMillis() + ".png"); -System.out.println("xxx "+file); + final String autosavePath = data.getAutosavePath(); + final String file = autosavePath != null && !autosavePath.isEmpty() ? autosavePath + : snapshotFile + "_size_" + width + "x" + height + "_cycle_" + scope.getClock().getCycle() + "_time_" + + java.lang.System.currentTimeMillis() + ".png"; + // System.out.println("xxx " + file); BufferedImage image = null; if (GamaPreferences.Displays.DISPLAY_FAST_SNAPSHOT.getValue()) { try { @@ -54,10 +54,8 @@ void doSnapshot(final IDisplayOutput output, final IDisplaySurface surface, fina } } // in case it has not worked, snapshot is still null - if (image == null) { - image = surface.getImage(width, height); - } - if (scope.interrupted() || image == null) { return; } + if (image == null) { image = surface.getImage(width, height); } + if (scope.interrupted() || image == null) return; // Intentionnaly passing GAMA.getRuntimeScope() to errors in order to // prevent the exceptions from being masked. try { @@ -80,9 +78,7 @@ void doSnapshot(final IDisplayOutput output, final IDisplaySurface surface, fina GAMA.reportError(GAMA.getRuntimeScope(), e, false); } finally { try { - if (os != null) { - os.close(); - } + if (os != null) { os.close(); } } catch (final Exception ex) { final GamaRuntimeException e = GamaRuntimeException.create(ex, scope); e.addContext("Unable to close output stream for snapshot image");