From 82b934fa80a2120027f3f344cda0fc088dc7d3b8 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 13 Sep 2023 11:30:51 +0200 Subject: [PATCH 01/71] setup project --- .../jhotdraw-samples-misc/pom.xml | 27 ++++++++++++++++++- .../java/org/jhotdraw/samples/draw/Main.java | 3 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml index 1d63de64d..28e9c1ebf 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml +++ b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml @@ -1,6 +1,13 @@ 4.0.0 + + + github + GitHub external Packages + https://maven.pkg.github.com/sweat-tek/MavenRepository + + org.jhotdraw jhotdraw-samples @@ -24,6 +31,11 @@ htmlunit 2.37.0 + + dk.sdu.cbse + featuretracerlite + 1.1-SNAPSHOT + org.aspectj aspectjweaver @@ -59,7 +71,20 @@ org.jhotdraw.samples.svg.Main - + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/1.9.9/aspectjweaver-1.9.9.jar + --add-opens java.base/java.lang=ALL-UNNAMED + + true + always + + \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java index b1a7bb876..c6165db63 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java @@ -7,6 +7,7 @@ */ package org.jhotdraw.samples.draw; +import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.api.app.Application; import org.jhotdraw.app.OSXApplication; import org.jhotdraw.app.SDIApplication; @@ -26,6 +27,8 @@ public class Main { /** * Creates a new instance. */ + + @FeatureEntryPoint(value = "Main") public static void main(String[] args) { ResourceBundleUtil.setVerbose(true); Application app; From 00aa5a5c45dadddd30da360e2739aea65d12068d Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 13 Sep 2023 12:16:29 +0200 Subject: [PATCH 02/71] made changes to sample pom file --- jhotdraw-samples/jhotdraw-samples-misc/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml index 28e9c1ebf..f463634a6 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml +++ b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml @@ -78,7 +78,7 @@ 2.22.2 - -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/1.9.9/aspectjweaver-1.9.9.jar + -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/1.9.9/aspectjweaver-1.9.9.jar --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED true From 303143cd7275c6adc1a4699520a8d6df7baae6e5 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 20 Sep 2023 11:04:42 +0200 Subject: [PATCH 03/71] Main method is changed --- .../src/main/java/org/jhotdraw/samples/draw/Main.java | 1 - .../src/main/java/org/jhotdraw/samples/svg/Main.java | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java index c6165db63..cfbf01142 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java @@ -28,7 +28,6 @@ public class Main { * Creates a new instance. */ - @FeatureEntryPoint(value = "Main") public static void main(String[] args) { ResourceBundleUtil.setVerbose(true); Application app; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java index 11e156729..cead7002c 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java @@ -7,6 +7,7 @@ */ package org.jhotdraw.samples.svg; +import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.api.app.Application; import org.jhotdraw.app.OSXApplication; import org.jhotdraw.app.SDIApplication; @@ -26,6 +27,7 @@ public class Main { /** * Creates a new instance. */ + @FeatureEntryPoint(value = "Main") public static void main(String[] args) { // Debug resource bundle ResourceBundleUtil.setVerbose(true); From 8b19292375fa6540e192d104673afe3c61a63d4f Mon Sep 17 00:00:00 2001 From: LaugeSolvang Date: Wed, 27 Sep 2023 09:57:41 +0200 Subject: [PATCH 04/71] Added FeatureEntryPoint to actionPerformed in Deleteaction --- .../src/main/java/org/jhotdraw/action/edit/DeleteAction.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java index 05ae13f58..65987c34b 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java @@ -13,6 +13,8 @@ import java.beans.PropertyChangeListener; import javax.swing.JComponent; import javax.swing.text.*; + +import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.api.gui.EditableComponent; import org.jhotdraw.beans.WeakPropertyChangeListener; import org.jhotdraw.util.*; @@ -107,7 +109,7 @@ public void propertyChange(PropertyChangeEvent evt) { ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels"); labels.configureAction(this, ID); } - + @FeatureEntryPoint(value = "delete") @Override public void actionPerformed(ActionEvent evt) { JComponent c = target; From 175aad687659a385105dc99ed6bf19149991f093 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 27 Sep 2023 11:13:08 +0200 Subject: [PATCH 05/71] entrypoint added to my feature --- jhotdraw-actions/jhotdraw-actions.iml | 6 ++++++ jhotdraw-api/jhotdraw-api.iml | 6 ++++++ jhotdraw-app/jhotdraw-app.iml | 6 ++++++ jhotdraw-core/jhotdraw-core.iml | 6 ++++++ jhotdraw-datatransfer/jhotdraw-datatransfer.iml | 6 ++++++ jhotdraw-gui/jhotdraw-gui.iml | 6 ++++++ .../jhotdraw-samples-mini/jhotdraw-samples-mini.iml | 6 ++++++ .../jhotdraw-samples-misc/jhotdraw-samples-misc.iml | 6 ++++++ .../java/org/jhotdraw/samples/odg/ODGDrawingPanel.java | 3 +++ .../src/main/java/org/jhotdraw/samples/svg/Main.java | 2 +- .../org/jhotdraw/samples/svg/figures/SVGRectFigure.java | 9 ++++++++- jhotdraw-samples/jhotdraw-samples.iml | 6 ++++++ jhotdraw-utils/jhotdraw-utils.iml | 6 ++++++ jhotdraw-xml/jhotdraw-xml.iml | 6 ++++++ jhotdraw.iml | 9 +++++++++ 15 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 jhotdraw-actions/jhotdraw-actions.iml create mode 100644 jhotdraw-api/jhotdraw-api.iml create mode 100644 jhotdraw-app/jhotdraw-app.iml create mode 100644 jhotdraw-core/jhotdraw-core.iml create mode 100644 jhotdraw-datatransfer/jhotdraw-datatransfer.iml create mode 100644 jhotdraw-gui/jhotdraw-gui.iml create mode 100644 jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml create mode 100644 jhotdraw-samples/jhotdraw-samples.iml create mode 100644 jhotdraw-utils/jhotdraw-utils.iml create mode 100644 jhotdraw-xml/jhotdraw-xml.iml create mode 100644 jhotdraw.iml diff --git a/jhotdraw-actions/jhotdraw-actions.iml b/jhotdraw-actions/jhotdraw-actions.iml new file mode 100644 index 000000000..52d5deadd --- /dev/null +++ b/jhotdraw-actions/jhotdraw-actions.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/jhotdraw-api/jhotdraw-api.iml b/jhotdraw-api/jhotdraw-api.iml new file mode 100644 index 000000000..6719176b5 --- /dev/null +++ b/jhotdraw-api/jhotdraw-api.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/jhotdraw-app/jhotdraw-app.iml b/jhotdraw-app/jhotdraw-app.iml new file mode 100644 index 000000000..161f59237 --- /dev/null +++ b/jhotdraw-app/jhotdraw-app.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/jhotdraw-core/jhotdraw-core.iml b/jhotdraw-core/jhotdraw-core.iml new file mode 100644 index 000000000..54bba967e --- /dev/null +++ b/jhotdraw-core/jhotdraw-core.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/jhotdraw-datatransfer/jhotdraw-datatransfer.iml b/jhotdraw-datatransfer/jhotdraw-datatransfer.iml new file mode 100644 index 000000000..dc448b11e --- /dev/null +++ b/jhotdraw-datatransfer/jhotdraw-datatransfer.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/jhotdraw-gui/jhotdraw-gui.iml b/jhotdraw-gui/jhotdraw-gui.iml new file mode 100644 index 000000000..241c0000d --- /dev/null +++ b/jhotdraw-gui/jhotdraw-gui.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml b/jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml new file mode 100644 index 000000000..fe598d9cf --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml b/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml new file mode 100644 index 000000000..c99373f7a --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java index 184a5a226..4ee880698 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java @@ -10,6 +10,8 @@ import java.awt.*; import java.util.*; import javax.swing.*; + +import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.action.edit.CopyAction; import org.jhotdraw.action.edit.CutAction; import org.jhotdraw.action.edit.DuplicateAction; @@ -152,6 +154,7 @@ public static Collection createSelectionActions(DrawingEditor editor) { return a; } + @FeatureEntryPoint(value = "SVGRectFigure.drawFigure") private void addCreationButtonsTo(JToolBar tb, final DrawingEditor editor) { // AttributeKeys for the entitie sets HashMap, Object> attributes; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java index cead7002c..7e46891f2 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java @@ -27,7 +27,7 @@ public class Main { /** * Creates a new instance. */ - @FeatureEntryPoint(value = "Main") +// @FeatureEntryPoint(value = "Main") public static void main(String[] args) { // Debug resource bundle ResourceBundleUtil.setVerbose(true); diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java index d1ba6eae5..d2cc3ec8a 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java @@ -10,6 +10,8 @@ import java.awt.*; import java.awt.geom.*; import java.util.*; + +import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.draw.*; import static org.jhotdraw.draw.AttributeKeys.FILL_COLOR; import static org.jhotdraw.draw.AttributeKeys.STROKE_CAP; @@ -79,7 +81,7 @@ public SVGRectFigure() { public SVGRectFigure(double x, double y, double width, double height) { this(x, y, width, height, 0, 0); } - + @FeatureEntryPoint(value = "SVGRectFigure.drawFigure") public SVGRectFigure(double x, double y, double width, double height, double rx, double ry) { roundrect = new RoundRectangle2D.Double(x, y, width, height, rx, ry); SVGAttributeKeys.setDefaults(this); @@ -87,6 +89,7 @@ public SVGRectFigure(double x, double y, double width, double height, double rx, } // DRAWING + @FeatureEntryPoint(value = "SVGRectFigure.drawFigure") @Override protected void drawFill(Graphics2D g) { if (getArcHeight() == 0d && getArcWidth() == 0d) { @@ -96,6 +99,7 @@ protected void drawFill(Graphics2D g) { } } + @FeatureEntryPoint(value = "SVGRectFigure.drawFigure") @Override protected void drawStroke(Graphics2D g) { if (roundrect.archeight == 0 && roundrect.arcwidth == 0) { @@ -130,6 +134,7 @@ protected void drawStroke(Graphics2D g) { } } + // SHAPE AND BOUNDS public double getX() { return roundrect.x; @@ -217,6 +222,8 @@ public Rectangle2D.Double getDrawingArea() { /** * Checks if a Point2D.Double is inside the figure. */ + + @FeatureEntryPoint(value = "SVGRectFigure.drawFigure") @Override public boolean contains(Point2D.Double p) { return getHitShape().contains(p); diff --git a/jhotdraw-samples/jhotdraw-samples.iml b/jhotdraw-samples/jhotdraw-samples.iml new file mode 100644 index 000000000..d054ca213 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/jhotdraw-utils/jhotdraw-utils.iml b/jhotdraw-utils/jhotdraw-utils.iml new file mode 100644 index 000000000..858e47629 --- /dev/null +++ b/jhotdraw-utils/jhotdraw-utils.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/jhotdraw-xml/jhotdraw-xml.iml b/jhotdraw-xml/jhotdraw-xml.iml new file mode 100644 index 000000000..228779b5e --- /dev/null +++ b/jhotdraw-xml/jhotdraw-xml.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/jhotdraw.iml b/jhotdraw.iml new file mode 100644 index 000000000..d34511373 --- /dev/null +++ b/jhotdraw.iml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file From bfabd7f231d3623224f9ba5b6378d946e99c27ad Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 4 Oct 2023 09:44:05 +0200 Subject: [PATCH 06/71] fix feature entry point --- .../src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java | 1 - .../java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java | 1 - 2 files changed, 2 deletions(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java index 4ee880698..7e31e7bfa 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java @@ -154,7 +154,6 @@ public static Collection createSelectionActions(DrawingEditor editor) { return a; } - @FeatureEntryPoint(value = "SVGRectFigure.drawFigure") private void addCreationButtonsTo(JToolBar tb, final DrawingEditor editor) { // AttributeKeys for the entitie sets HashMap, Object> attributes; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java index d2cc3ec8a..86f9c235a 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java @@ -223,7 +223,6 @@ public Rectangle2D.Double getDrawingArea() { * Checks if a Point2D.Double is inside the figure. */ - @FeatureEntryPoint(value = "SVGRectFigure.drawFigure") @Override public boolean contains(Point2D.Double p) { return getHitShape().contains(p); From a3b9dff70c56f9d28e6e4ae78642aea628ef1aea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaes=20S=C3=B8rensen?= Date: Wed, 4 Oct 2023 11:29:50 +0200 Subject: [PATCH 07/71] Inserted Featuretracer for undo refactoring and modified pom.xml for jhotdraw-utils to have a dependency on the feature tracer so that it can be ued within the module. --- .../src/main/java/org/jhotdraw/action/edit/DeleteAction.java | 1 + .../src/main/java/org/jhotdraw/samples/svg/Main.java | 2 +- jhotdraw-utils/pom.xml | 5 +++++ .../src/main/java/org/jhotdraw/undo/UndoRedoManager.java | 3 +++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java index 65987c34b..918fb8749 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java @@ -109,6 +109,7 @@ public void propertyChange(PropertyChangeEvent evt) { ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels"); labels.configureAction(this, ID); } + @FeatureEntryPoint(value = "delete") @Override public void actionPerformed(ActionEvent evt) { diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java index cead7002c..74b125ee8 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java @@ -27,7 +27,7 @@ public class Main { /** * Creates a new instance. */ - @FeatureEntryPoint(value = "Main") + public static void main(String[] args) { // Debug resource bundle ResourceBundleUtil.setVerbose(true); diff --git a/jhotdraw-utils/pom.xml b/jhotdraw-utils/pom.xml index b1b2faf01..612b111de 100644 --- a/jhotdraw-utils/pom.xml +++ b/jhotdraw-utils/pom.xml @@ -9,6 +9,11 @@ jhotdraw-utils jar + + dk.sdu.cbse + featuretracerlite + 1.1-SNAPSHOT + org.testng testng diff --git a/jhotdraw-utils/src/main/java/org/jhotdraw/undo/UndoRedoManager.java b/jhotdraw-utils/src/main/java/org/jhotdraw/undo/UndoRedoManager.java index 40ac0b4ce..fa72f8b41 100644 --- a/jhotdraw-utils/src/main/java/org/jhotdraw/undo/UndoRedoManager.java +++ b/jhotdraw-utils/src/main/java/org/jhotdraw/undo/UndoRedoManager.java @@ -12,6 +12,8 @@ import java.util.*; import javax.swing.*; import javax.swing.undo.*; + +import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.util.*; /** @@ -133,6 +135,7 @@ public static ResourceBundleUtil getLabels() { /** * Creates new UndoRedoManager */ + @FeatureEntryPoint(value = "UndoRedoManager") public UndoRedoManager() { getLabels(); undoAction = new UndoAction(); From 85afab38cfeb9c02f3cfde8ed1f97c00d3d62380 Mon Sep 17 00:00:00 2001 From: Jesper Isgaard Hansen Date: Wed, 4 Oct 2023 12:01:18 +0200 Subject: [PATCH 08/71] feature trace added --- jhotdraw-utils/pom.xml | 6 ++++++ jhotdraw-utils/src/main/java/org/jhotdraw/util/Images.java | 2 ++ 2 files changed, 8 insertions(+) diff --git a/jhotdraw-utils/pom.xml b/jhotdraw-utils/pom.xml index b1b2faf01..3bfead600 100644 --- a/jhotdraw-utils/pom.xml +++ b/jhotdraw-utils/pom.xml @@ -15,5 +15,11 @@ 6.8.21 test + + dk.sdu.mmmi + featuretracer + 1.0 + jar + \ No newline at end of file diff --git a/jhotdraw-utils/src/main/java/org/jhotdraw/util/Images.java b/jhotdraw-utils/src/main/java/org/jhotdraw/util/Images.java index 08b66a084..860005c11 100644 --- a/jhotdraw-utils/src/main/java/org/jhotdraw/util/Images.java +++ b/jhotdraw-utils/src/main/java/org/jhotdraw/util/Images.java @@ -11,6 +11,7 @@ import java.awt.image.*; import java.net.*; import javax.swing.*; +import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; /** * Image processing methods. @@ -23,6 +24,7 @@ public class Images { /** * Prevent instance creation. */ + @FeatureEntryPoint(value = "InsertImage") private Images() { } From cd18678b0f64472bfcd3d899034510f1873aa228 Mon Sep 17 00:00:00 2001 From: Jesper Isgaard Hansen Date: Wed, 4 Oct 2023 12:02:28 +0200 Subject: [PATCH 09/71] Formatting --- .../jhotdraw-samples-misc/pom.xml | 34 +-- pom.xml | 258 +++++++++--------- 2 files changed, 146 insertions(+), 146 deletions(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml index 1d63de64d..a0387ca63 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml +++ b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml @@ -43,23 +43,23 @@ - - org.codehaus.mojo - exec-maven-plugin - 3.1.0 - - - run-java - install - - java - - - - - org.jhotdraw.samples.svg.Main - - + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + + run-java + install + + java + + + + + org.jhotdraw.samples.svg.Main + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index bf1c45f13..b8c8f48ae 100644 --- a/pom.xml +++ b/pom.xml @@ -1,135 +1,135 @@ - 4.0.0 - org.jhotdraw - jhotdraw - 9.1-SNAPSHOT - pom - - JHotDraw - - - - github - GitHub external Packages - https://maven.pkg.github.com/sweat-tek/MavenRepository - - - - - GNU Library or Lesser General Public License (LGPL) V2.1 - http://www.gnu.org/licenses/lgpl-2.1.html - - - Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/ - - - - - Tobias Warneke - t.warneke@gmx.net - - - - UTF-8 - 1.8 - 1.8 - - This is a fork of jhotdraw from http://sourceforge.net/projects/jhotdraw - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.1.1 - - false - false - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - ${maven.compiler.source} - ${maven.compiler.target} - ${project.build.sourceEncoding} - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.1.0 - - - verify-style - process-classes - - check - - - - - true - true - ${project.build.sourceDirectory} - - - - - - - - - - - - - - - - + 4.0.0 + org.jhotdraw + jhotdraw + 9.1-SNAPSHOT + pom + + JHotDraw + + + + github + GitHub external Packages + https://maven.pkg.github.com/sweat-tek/MavenRepository + + + + + GNU Library or Lesser General Public License (LGPL) V2.1 + http://www.gnu.org/licenses/lgpl-2.1.html + + + Creative Commons Attribution 2.5 License + http://creativecommons.org/licenses/by/2.5/ + + + + + Tobias Warneke + t.warneke@gmx.net + + + + UTF-8 + 1.8 + 1.8 + + This is a fork of jhotdraw from http://sourceforge.net/projects/jhotdraw + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.1.1 + + false + false + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${maven.compiler.source} + ${maven.compiler.target} + ${project.build.sourceEncoding} + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.1.0 + + + verify-style + process-classes + + check + + + + + true + true + ${project.build.sourceDirectory} + + + + + + + + + + + + + + + + - + - - - - + + + + - - - - - - - - com.puppycrawl.tools - checkstyle - 8.29 - - - - - - - jhotdraw-core - jhotdraw-samples - jhotdraw-xml - jhotdraw-api - jhotdraw-utils - jhotdraw-gui - jhotdraw-app - jhotdraw-datatransfer - jhotdraw-actions - + + + + + + + + com.puppycrawl.tools + checkstyle + 8.29 + + + + + + + jhotdraw-core + jhotdraw-samples + jhotdraw-xml + jhotdraw-api + jhotdraw-utils + jhotdraw-gui + jhotdraw-app + jhotdraw-datatransfer + jhotdraw-actions + \ No newline at end of file From 390abb98a1ff013cada35819a3941f0adc4a1d18 Mon Sep 17 00:00:00 2001 From: Jesper Isgaard Hansen Date: Wed, 4 Oct 2023 15:42:03 +0200 Subject: [PATCH 10/71] FeatureTrace Generering --- .../jhotdraw-samples-misc/pom.xml | 28 ++++++------ .../java/org/jhotdraw/samples/draw/Main.java | 3 ++ jhotdraw-utils/pom.xml | 44 +++++++++---------- .../main/java/org/jhotdraw/util/Images.java | 9 +++- 4 files changed, 47 insertions(+), 37 deletions(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml index a0387ca63..d6691a0b3 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml +++ b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml @@ -24,6 +24,11 @@ htmlunit 2.37.0 + + dk.sdu.cbse + featuretracerlite + 1.1-SNAPSHOT + org.aspectj aspectjweaver @@ -44,22 +49,17 @@ - org.codehaus.mojo - exec-maven-plugin - 3.1.0 - - - run-java - install - - java - - - + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 - org.jhotdraw.samples.svg.Main + + -javaagent:/Users/jespe/.m2/repository/org/aspectj/aspectjweaver/1.9.9/aspectjweaver-1.9.9.jar --add-opens java.base/java.lang=ALL-UNNAMED + + true + always - + \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java index b1a7bb876..208c1ab81 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java @@ -7,6 +7,7 @@ */ package org.jhotdraw.samples.draw; +import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.api.app.Application; import org.jhotdraw.app.OSXApplication; import org.jhotdraw.app.SDIApplication; @@ -25,7 +26,9 @@ public class Main { /** * Creates a new instance. + * @param args */ + @FeatureEntryPoint("Main") public static void main(String[] args) { ResourceBundleUtil.setVerbose(true); Application app; diff --git a/jhotdraw-utils/pom.xml b/jhotdraw-utils/pom.xml index 3bfead600..a24ad73bf 100644 --- a/jhotdraw-utils/pom.xml +++ b/jhotdraw-utils/pom.xml @@ -1,25 +1,25 @@ - 4.0.0 - - org.jhotdraw - jhotdraw - 9.1-SNAPSHOT - - jhotdraw-utils - jar - - - org.testng - testng - 6.8.21 - test - - - dk.sdu.mmmi - featuretracer - 1.0 - jar - - + 4.0.0 + + org.jhotdraw + jhotdraw + 9.1-SNAPSHOT + + jhotdraw-utils + jar + + + org.testng + testng + 6.8.21 + test + + + dk.sdu.cbse + featuretracerlite + 1.1-SNAPSHOT + jar + + \ No newline at end of file diff --git a/jhotdraw-utils/src/main/java/org/jhotdraw/util/Images.java b/jhotdraw-utils/src/main/java/org/jhotdraw/util/Images.java index 860005c11..d31ee3cd8 100644 --- a/jhotdraw-utils/src/main/java/org/jhotdraw/util/Images.java +++ b/jhotdraw-utils/src/main/java/org/jhotdraw/util/Images.java @@ -24,10 +24,11 @@ public class Images { /** * Prevent instance creation. */ - @FeatureEntryPoint(value = "InsertImage") + @FeatureEntryPoint("InsertImage") private Images() { } + @FeatureEntryPoint("InsertImage") public static Image createImage(Class baseClass, String resourceName) { URL resource = baseClass.getResource(resourceName); if (resource == null) { @@ -37,6 +38,7 @@ public static Image createImage(Class baseClass, String resourceName) { return image; } + @FeatureEntryPoint("InsertImage") public static Image createImage(URL resource) { if (resource == null) { throw new IllegalArgumentException("resource must not be null"); @@ -52,6 +54,7 @@ public static Image createImage(URL resource) { * @param rImg An Image. * @return A BufferedImage. */ + @FeatureEntryPoint("InsertImage") public static BufferedImage toBufferedImage(RenderedImage rImg) { BufferedImage image; if (rImg instanceof BufferedImage) { @@ -70,6 +73,7 @@ public static BufferedImage toBufferedImage(RenderedImage rImg) { return image; } + @FeatureEntryPoint("InsertImage") public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; @@ -135,6 +139,7 @@ public static BufferedImage toBufferedImage(Image image) { * Code taken from the Java Developers Almanac 1.4 * http://javaalmanac.com/egs/java.awt.image/HasAlpha.html */ + @FeatureEntryPoint("InsertImage") public static boolean hasAlpha(Image image) { // If buffered image, the color model is readily available if (image instanceof BufferedImage) { @@ -157,6 +162,7 @@ public static boolean hasAlpha(Image image) { /** * Splits an image into count subimages. */ + @FeatureEntryPoint("InsertImage") public static BufferedImage[] split(Image image, int count, boolean isHorizontal) { BufferedImage src = Images.toBufferedImage(image); if (count == 1) { @@ -193,6 +199,7 @@ public static BufferedImage[] split(Image image, int count, boolean isHorizontal * @param width the width to which to scale the image. * @param height the height to which to scale the image. */ + @FeatureEntryPoint("InsertImage") public static BufferedImage getScaledInstance(Image image, int width, int height) { int w, h; if (width < 0 && height < 0) { From 1af82e0f60d9796b5c2b8e7a6050f4984350670b Mon Sep 17 00:00:00 2001 From: Jesper Isgaard Hansen Date: Wed, 4 Oct 2023 15:51:19 +0200 Subject: [PATCH 11/71] Removed unused imports --- .../src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java | 1 - .../src/main/java/org/jhotdraw/samples/svg/Main.java | 1 - 2 files changed, 2 deletions(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java index 7e31e7bfa..0fc95906b 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java @@ -11,7 +11,6 @@ import java.util.*; import javax.swing.*; -import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.action.edit.CopyAction; import org.jhotdraw.action.edit.CutAction; import org.jhotdraw.action.edit.DuplicateAction; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java index 74b125ee8..effd37fd2 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java @@ -7,7 +7,6 @@ */ package org.jhotdraw.samples.svg; -import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.api.app.Application; import org.jhotdraw.app.OSXApplication; import org.jhotdraw.app.SDIApplication; From 28515bb62828f004c4d6c6af32f9e1e2a17c9aa9 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 4 Oct 2023 21:29:15 +0200 Subject: [PATCH 12/71] setup github action --- .github/workflows/maven.yml | 38 +++++++++++++++++++ .../java/org/jhotdraw/samples/draw/Main.java | 1 - .../jhotdraw/samples/odg/ODGDrawingPanel.java | 1 - .../java/org/jhotdraw/samples/svg/Main.java | 1 - 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 000000000..d37270b0f --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,38 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "Master" ] + pull_request: + branches: + - Master + - develop + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn clean install + + - name: Run tests + run: mvn test \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java index cfbf01142..7dd173e0a 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java @@ -7,7 +7,6 @@ */ package org.jhotdraw.samples.draw; -import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.api.app.Application; import org.jhotdraw.app.OSXApplication; import org.jhotdraw.app.SDIApplication; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java index 7e31e7bfa..0fc95906b 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/odg/ODGDrawingPanel.java @@ -11,7 +11,6 @@ import java.util.*; import javax.swing.*; -import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.action.edit.CopyAction; import org.jhotdraw.action.edit.CutAction; import org.jhotdraw.action.edit.DuplicateAction; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java index 74b125ee8..effd37fd2 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java @@ -7,7 +7,6 @@ */ package org.jhotdraw.samples.svg; -import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.api.app.Application; import org.jhotdraw.app.OSXApplication; import org.jhotdraw.app.SDIApplication; From 92eea94053baf8ea1f2ce9508162a9e367859c93 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 4 Oct 2023 21:38:25 +0200 Subject: [PATCH 13/71] fix utils --- jhotdraw-utils/pom.xml | 74 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 4 deletions(-) diff --git a/jhotdraw-utils/pom.xml b/jhotdraw-utils/pom.xml index 612b111de..2dceae8e0 100644 --- a/jhotdraw-utils/pom.xml +++ b/jhotdraw-utils/pom.xml @@ -1,24 +1,90 @@ 4.0.0 + + + github + GitHub external Packages + https://maven.pkg.github.com/sweat-tek/MavenRepository + + org.jhotdraw - jhotdraw + jhotdraw-samples 9.1-SNAPSHOT jhotdraw-utils jar + + ${project.groupId} + jhotdraw-core + ${project.version} + + + org.devzendo + Quaqua + 7.3.4 + + + net.sourceforge.htmlunit + htmlunit + 2.37.0 + dk.sdu.cbse featuretracerlite 1.1-SNAPSHOT - org.testng - testng - 6.8.21 + org.aspectj + aspectjweaver + 1.9.9 + + + ${project.groupId} + jhotdraw-app + ${project.version} + + + junit + junit + 4.13.2 test + + + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + + run-java + install + + java + + + + + org.jhotdraw.samples.svg.Main + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/1.9.9/aspectjweaver-1.9.9.jar --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.lang=ALL-UNNAMED + + true + always + + + + \ No newline at end of file From 5158b5064a16b6f526fd8f97dd3d1117bc8eea69 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 4 Oct 2023 21:41:26 +0200 Subject: [PATCH 14/71] fix utils --- .../jhotdraw-samples-misc.iml | 2 +- jhotdraw-utils/jhotdraw-utils.iml | 2 +- jhotdraw-utils/pom.xml | 74 +------------------ 3 files changed, 6 insertions(+), 72 deletions(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml b/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml index c99373f7a..022facaab 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml +++ b/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/jhotdraw-utils/jhotdraw-utils.iml b/jhotdraw-utils/jhotdraw-utils.iml index 858e47629..f63b564f7 100644 --- a/jhotdraw-utils/jhotdraw-utils.iml +++ b/jhotdraw-utils/jhotdraw-utils.iml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/jhotdraw-utils/pom.xml b/jhotdraw-utils/pom.xml index 2dceae8e0..612b111de 100644 --- a/jhotdraw-utils/pom.xml +++ b/jhotdraw-utils/pom.xml @@ -1,90 +1,24 @@ 4.0.0 - - - github - GitHub external Packages - https://maven.pkg.github.com/sweat-tek/MavenRepository - - org.jhotdraw - jhotdraw-samples + jhotdraw 9.1-SNAPSHOT jhotdraw-utils jar - - ${project.groupId} - jhotdraw-core - ${project.version} - - - org.devzendo - Quaqua - 7.3.4 - - - net.sourceforge.htmlunit - htmlunit - 2.37.0 - dk.sdu.cbse featuretracerlite 1.1-SNAPSHOT - org.aspectj - aspectjweaver - 1.9.9 - - - ${project.groupId} - jhotdraw-app - ${project.version} - - - junit - junit - 4.13.2 + org.testng + testng + 6.8.21 test - - - - org.codehaus.mojo - exec-maven-plugin - 3.1.0 - - - run-java - install - - java - - - - - org.jhotdraw.samples.svg.Main - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.2 - - - -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/1.9.9/aspectjweaver-1.9.9.jar --add-opens java.base/java.lang=ALL-UNNAMED - --add-opens java.base/java.lang=ALL-UNNAMED - - true - always - - - - \ No newline at end of file From f50e8436e38a5e8ef85231d10499565b7b3ec6d3 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 4 Oct 2023 21:56:00 +0200 Subject: [PATCH 15/71] Made changes to maven action file --- .github/workflows/maven.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index d37270b0f..2fcb65b6b 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -20,17 +20,24 @@ jobs: build: runs-on: ubuntu-latest + permissions: write-all steps: - name: Checkout Code uses: actions/checkout@v3 - - name: Set up JDK 17 + - name: Set up JDK 11 uses: actions/setup-java@v3 with: - java-version: '17' - distribution: 'temurin' - cache: maven + java-version: '11' + distribution: 'adopt' + - name: setup settings.xml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + mkdir -p ~/.m2 + cp .github/settings.xml ~/.m2/settings.xml + - name: Build with Maven run: mvn clean install From 37883f47f8e5cc4a18e5483867505d5a82c5bebd Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 4 Oct 2023 22:03:46 +0200 Subject: [PATCH 16/71] added settings file --- .github/m2_settings/settingsCopy.xml | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/m2_settings/settingsCopy.xml diff --git a/.github/m2_settings/settingsCopy.xml b/.github/m2_settings/settingsCopy.xml new file mode 100644 index 000000000..801be4a44 --- /dev/null +++ b/.github/m2_settings/settingsCopy.xml @@ -0,0 +1,33 @@ + + + + github + + + + + github + + + central + https://repo1.maven.org/maven2 + + + + + + + + github + + ${env.GITHUB_ACTOR} + + + ${env.GITHUB_TOKEN} + + + + + \ No newline at end of file From 7f9e7dee1b76acc861b900e5c9ee10c8b59a2046 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 4 Oct 2023 22:05:10 +0200 Subject: [PATCH 17/71] Made changes to maven action file --- .github/workflows/maven.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2fcb65b6b..8641f7890 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -34,9 +34,8 @@ jobs: - name: setup settings.xml env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - mkdir -p ~/.m2 - cp .github/settings.xml ~/.m2/settings.xml + run: cp .github/m2_settings/settings.xml $HOME/.m2/settings.xml + - name: Build with Maven run: mvn clean install From c1401b161684ce9af146fca7447a31799a21970a Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 4 Oct 2023 22:07:06 +0200 Subject: [PATCH 18/71] Made changes to maven action file --- .github/m2_settings/{settingsCopy.xml => settings.xml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/m2_settings/{settingsCopy.xml => settings.xml} (100%) diff --git a/.github/m2_settings/settingsCopy.xml b/.github/m2_settings/settings.xml similarity index 100% rename from .github/m2_settings/settingsCopy.xml rename to .github/m2_settings/settings.xml From 5d6556c5653c862f0f72f39b8b34c112882aac1c Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 4 Oct 2023 22:10:58 +0200 Subject: [PATCH 19/71] Made changes to maven action file --- .github/m2_settings/settings.xml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/m2_settings/settings.xml b/.github/m2_settings/settings.xml index 801be4a44..5d0665b0c 100644 --- a/.github/m2_settings/settings.xml +++ b/.github/m2_settings/settings.xml @@ -21,13 +21,9 @@ github - - ${env.GITHUB_ACTOR} - - - ${env.GITHUB_TOKEN} - + ${GITHUB_ACTOR} + ${GITHUB_TOKEN} - \ No newline at end of file + From a31cbc874b4aa5cd2c2947a8b0dd8a027fdf3b28 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 4 Oct 2023 22:18:35 +0200 Subject: [PATCH 20/71] Made changes to maven action file --- .github/workflows/maven.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 8641f7890..fc8487e2f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -26,11 +26,12 @@ jobs: - name: Checkout Code uses: actions/checkout@v3 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v3 with: - java-version: '11' + java-version: '17' distribution: 'adopt' + cache: 'maven' - name: setup settings.xml env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -38,7 +39,7 @@ jobs: - name: Build with Maven - run: mvn clean install + run: mvn -B package --file pom.xml - name: Run tests run: mvn test \ No newline at end of file From e748afcc71aa67216dbe88cc89cda204e07f4cdf Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 11 Oct 2023 09:23:31 +0200 Subject: [PATCH 21/71] try to build maven ci --- .../jhotdraw-samples-misc/pom.xml | 2 +- jhotdraw-utils/pom.xml | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml index f463634a6..f570cc823 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml +++ b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml @@ -10,7 +10,7 @@ org.jhotdraw - jhotdraw-samples + jhotdraw 9.1-SNAPSHOT jhotdraw-samples-misc diff --git a/jhotdraw-utils/pom.xml b/jhotdraw-utils/pom.xml index 612b111de..6a1551a52 100644 --- a/jhotdraw-utils/pom.xml +++ b/jhotdraw-utils/pom.xml @@ -1,6 +1,13 @@ 4.0.0 + + + github + GitHub external Packages + https://maven.pkg.github.com/sweat-tek/MavenRepository + + org.jhotdraw jhotdraw @@ -21,4 +28,22 @@ test + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/1.9.9/aspectjweaver-1.9.9.jar --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.lang=ALL-UNNAMED + + true + always + + + + \ No newline at end of file From 5c73799e4a70856e21cf92cd5278da671e56d622 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 11 Oct 2023 09:28:09 +0200 Subject: [PATCH 22/71] try to build maven ci --- jhotdraw-samples/jhotdraw-samples-misc/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml index f570cc823..f463634a6 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml +++ b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml @@ -10,7 +10,7 @@ org.jhotdraw - jhotdraw + jhotdraw-samples 9.1-SNAPSHOT jhotdraw-samples-misc From bb642d985f6c8b27e0124a8fec90b0aa7a278bdf Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 11 Oct 2023 09:44:51 +0200 Subject: [PATCH 23/71] try to build maven ci --- .github/workflows/maven.yml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index fc8487e2f..c5aa31e15 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -30,7 +30,7 @@ jobs: uses: actions/setup-java@v3 with: java-version: '17' - distribution: 'adopt' + distribution: 'temurin' cache: 'maven' - name: setup settings.xml env: @@ -42,4 +42,21 @@ jobs: run: mvn -B package --file pom.xml - name: Run tests - run: mvn test \ No newline at end of file + run: mvn test + publish-job: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: 'maven' + - run: mvn --batch-mode --update-snapshots verify + - run: mkdir stagin && cp target/*.jar staging/ + - uses: actions/upload-artifact@v3 + with: + name: java-app + path: staging \ No newline at end of file From 635d42fed5676527b501a53e7b908871f0d6de04 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 11 Oct 2023 09:46:45 +0200 Subject: [PATCH 24/71] try to build maven ci --- .github/workflows/maven.yml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index c5aa31e15..71693f6c4 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -43,20 +43,20 @@ jobs: - name: Run tests run: mvn test - publish-job: - runs-on: ubuntu-latest - needs: build - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - cache: 'maven' - - run: mvn --batch-mode --update-snapshots verify - - run: mkdir stagin && cp target/*.jar staging/ - - uses: actions/upload-artifact@v3 - with: - name: java-app - path: staging \ No newline at end of file + publish-job: + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: 'maven' + - run: mvn --batch-mode --update-snapshots verify + - run: mkdir stagin && cp target/*.jar staging/ + - uses: actions/upload-artifact@v3 + with: + name: java-app + path: staging \ No newline at end of file From 57307c7bb140c74c5e6bc7af57f06f748500d7f5 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 11 Oct 2023 09:53:08 +0200 Subject: [PATCH 25/71] try to build maven ci --- .github/m2_settings/settings.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/m2_settings/settings.xml b/.github/m2_settings/settings.xml index 5d0665b0c..34dda1dd4 100644 --- a/.github/m2_settings/settings.xml +++ b/.github/m2_settings/settings.xml @@ -10,6 +10,11 @@ github + + GitHub External Packages + github + https://maven.pkg.github.com/sweat-tek/MavenRepository + central https://repo1.maven.org/maven2 From b27bd3caae314f28b7bdf6ca214d636a4a6225bf Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 11 Oct 2023 09:57:19 +0200 Subject: [PATCH 26/71] try to build maven ci --- jhotdraw-utils/pom.xml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/jhotdraw-utils/pom.xml b/jhotdraw-utils/pom.xml index 6a1551a52..f835ef6cb 100644 --- a/jhotdraw-utils/pom.xml +++ b/jhotdraw-utils/pom.xml @@ -1,13 +1,7 @@ 4.0.0 - - - github - GitHub external Packages - https://maven.pkg.github.com/sweat-tek/MavenRepository - - + org.jhotdraw jhotdraw From b0d3003011c57bc769f2164b9b5c15734716672b Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 11 Oct 2023 09:59:55 +0200 Subject: [PATCH 27/71] try to build maven ci --- .github/workflows/maven.yml | 40 +++++++------------------------------ 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 71693f6c4..6790f0ddb 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -17,35 +17,10 @@ on: - develop jobs: - build: + Build-Test: runs-on: ubuntu-latest - permissions: write-all - steps: - - name: Checkout Code - uses: actions/checkout@v3 - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - cache: 'maven' - - name: setup settings.xml - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: cp .github/m2_settings/settings.xml $HOME/.m2/settings.xml - - - - name: Build with Maven - run: mvn -B package --file pom.xml - - - name: Run tests - run: mvn test - publish-job: - runs-on: ubuntu-latest - needs: build steps: - uses: actions/checkout@v3 - name: Set up JDK 17 @@ -53,10 +28,9 @@ jobs: with: java-version: '17' distribution: 'temurin' - cache: 'maven' - - run: mvn --batch-mode --update-snapshots verify - - run: mkdir stagin && cp target/*.jar staging/ - - uses: actions/upload-artifact@v3 - with: - name: java-app - path: staging \ No newline at end of file + cache: maven + - name: Build with Maven + run: mvn --batch-mode --update-snapshots verify + env: + GITHUB_USERNAME: ${{ secrets.USER_NAME }} + GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} \ No newline at end of file From badd2e3c5ce0c8ac5d89fd9a0c2a53091215f79c Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 11 Oct 2023 10:07:56 +0200 Subject: [PATCH 28/71] try to build maven ci --- jhotdraw-samples/jhotdraw-samples (2).iml | 6 ++ .../jhotdraw-samples-mini.iml | 3 + .../jhotdraw-samples-misc.iml | 2 +- .../jhotdraw-samples.iml | 6 ++ .../jhotdraw-samples-misc/pom.xml | 75 +------------------ jhotdraw-samples/jhotdraw-samples.iml | 2 +- jhotdraw-utils/pom.xml | 23 ------ 7 files changed, 19 insertions(+), 98 deletions(-) create mode 100644 jhotdraw-samples/jhotdraw-samples (2).iml create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples.iml diff --git a/jhotdraw-samples/jhotdraw-samples (2).iml b/jhotdraw-samples/jhotdraw-samples (2).iml new file mode 100644 index 000000000..5c7108fc1 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples (2).iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml b/jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml index fe598d9cf..39cbc8203 100644 --- a/jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml +++ b/jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml @@ -1,5 +1,8 @@ + + diff --git a/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml b/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml index 022facaab..d4aadaf98 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml +++ b/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples.iml b/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples.iml new file mode 100644 index 000000000..b30d8cebc --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples.iml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml index f463634a6..b4b32ba95 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml +++ b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml @@ -10,81 +10,10 @@ org.jhotdraw - jhotdraw-samples + jhotdraw 9.1-SNAPSHOT jhotdraw-samples-misc jar - - - ${project.groupId} - jhotdraw-core - ${project.version} - - - org.devzendo - Quaqua - 7.3.4 - - - net.sourceforge.htmlunit - htmlunit - 2.37.0 - - - dk.sdu.cbse - featuretracerlite - 1.1-SNAPSHOT - - - org.aspectj - aspectjweaver - 1.9.9 - - - ${project.groupId} - jhotdraw-app - ${project.version} - - - junit - junit - 4.13.2 - test - - - - - - org.codehaus.mojo - exec-maven-plugin - 3.1.0 - - - run-java - install - - java - - - - - org.jhotdraw.samples.svg.Main - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.2 - - - -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/1.9.9/aspectjweaver-1.9.9.jar --add-opens java.base/java.lang=ALL-UNNAMED - --add-opens java.base/java.lang=ALL-UNNAMED - - true - always - - - - + \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples.iml b/jhotdraw-samples/jhotdraw-samples.iml index d054ca213..c485a5991 100644 --- a/jhotdraw-samples/jhotdraw-samples.iml +++ b/jhotdraw-samples/jhotdraw-samples.iml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/jhotdraw-utils/pom.xml b/jhotdraw-utils/pom.xml index f835ef6cb..398bec4e2 100644 --- a/jhotdraw-utils/pom.xml +++ b/jhotdraw-utils/pom.xml @@ -10,11 +10,6 @@ jhotdraw-utils jar - - dk.sdu.cbse - featuretracerlite - 1.1-SNAPSHOT - org.testng testng @@ -22,22 +17,4 @@ test - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.2 - - - -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/1.9.9/aspectjweaver-1.9.9.jar --add-opens java.base/java.lang=ALL-UNNAMED - --add-opens java.base/java.lang=ALL-UNNAMED - - true - always - - - - \ No newline at end of file From e8afb650422f0f59da47fe0c51ac5e61f02a9d6b Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 11 Oct 2023 10:15:08 +0200 Subject: [PATCH 29/71] try to build maven ci --- .../jhotdraw-samples-misc/pom.xml | 74 ++++++++++++++++++- jhotdraw-utils/pom.xml | 5 ++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml index b4b32ba95..d76b64f29 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml +++ b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml @@ -10,10 +10,82 @@ org.jhotdraw - jhotdraw + jhotdraw-samples 9.1-SNAPSHOT jhotdraw-samples-misc jar + + + ${project.groupId} + jhotdraw-core + ${project.version} + + + org.devzendo + Quaqua + 7.3.4 + + + net.sourceforge.htmlunit + htmlunit + 2.37.0 + + + dk.sdu.cbse + featuretracerlite + 1.1-SNAPSHOT + + + org.aspectj + aspectjweaver + 1.9.9 + + + ${project.groupId} + jhotdraw-app + ${project.version} + + + junit + junit + 4.13.2 + test + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + + run-java + install + + java + + + + + org.jhotdraw.samples.svg.Main + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/1.9.9/aspectjweaver-1.9.9.jar --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.lang=ALL-UNNAMED + + true + always + + + + \ No newline at end of file diff --git a/jhotdraw-utils/pom.xml b/jhotdraw-utils/pom.xml index 398bec4e2..37d5545cf 100644 --- a/jhotdraw-utils/pom.xml +++ b/jhotdraw-utils/pom.xml @@ -16,5 +16,10 @@ 6.8.21 test + + dk.sdu.cbse + featuretracerlite + 1.1-SNAPSHOT + \ No newline at end of file From 8dcb3dce5bde028ce4d817c05db2adda13e4a27a Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 11 Oct 2023 10:19:03 +0200 Subject: [PATCH 30/71] try to build maven ci --- .github/m2_settings/settings.xml | 4 ++-- .github/workflows/maven.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/m2_settings/settings.xml b/.github/m2_settings/settings.xml index 34dda1dd4..954403d32 100644 --- a/.github/m2_settings/settings.xml +++ b/.github/m2_settings/settings.xml @@ -26,8 +26,8 @@ github - ${GITHUB_ACTOR} - ${GITHUB_TOKEN} + ${env.GITHUB_USERNAME} + ${env.GITHUB_TOKEN} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 6790f0ddb..502dd815e 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -30,7 +30,7 @@ jobs: distribution: 'temurin' cache: maven - name: Build with Maven - run: mvn --batch-mode --update-snapshots verify + run: mvn --batch-mode --update-snapshots -s m2_settings/settings.xml verify env: GITHUB_USERNAME: ${{ secrets.USER_NAME }} GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} \ No newline at end of file From 311409682c81df02d253a4d2d56e25c2d4d2386f Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 11 Oct 2023 10:20:27 +0200 Subject: [PATCH 31/71] try to build maven ci --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 502dd815e..53d147fab 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -30,7 +30,7 @@ jobs: distribution: 'temurin' cache: maven - name: Build with Maven - run: mvn --batch-mode --update-snapshots -s m2_settings/settings.xml verify + run: mvn --batch-mode --update-snapshots -s .github/m2_settings/settings.xml verify env: GITHUB_USERNAME: ${{ secrets.USER_NAME }} GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} \ No newline at end of file From b298de3a7b862a7ef2c42d4eff95d5a79f585bfb Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 11 Oct 2023 10:59:12 +0200 Subject: [PATCH 32/71] test --- .github/workflows/maven.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 53d147fab..57f8efe62 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,6 +29,13 @@ jobs: java-version: '17' distribution: 'temurin' cache: maven + - name: dump env + env: + GITHUB_USERNAME: ${{ secrets.USER_NAME }} + GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} + run: | + echo "$GITHUB_USERNAME" + echo "$GITHUB_TOKEN" - name: Build with Maven run: mvn --batch-mode --update-snapshots -s .github/m2_settings/settings.xml verify env: From ca00288b07527d223d63c95312373ef05332a8c1 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 11 Oct 2023 11:01:49 +0200 Subject: [PATCH 33/71] try to build maven ci --- .github/workflows/maven.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 57f8efe62..53d147fab 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,13 +29,6 @@ jobs: java-version: '17' distribution: 'temurin' cache: maven - - name: dump env - env: - GITHUB_USERNAME: ${{ secrets.USER_NAME }} - GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} - run: | - echo "$GITHUB_USERNAME" - echo "$GITHUB_TOKEN" - name: Build with Maven run: mvn --batch-mode --update-snapshots -s .github/m2_settings/settings.xml verify env: From 4718829d3aca1bdfb972d9c21b4b00c26342e342 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 11 Oct 2023 11:06:50 +0200 Subject: [PATCH 34/71] try to build maven ci --- .github/workflows/maven.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 53d147fab..e01411956 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -30,7 +30,8 @@ jobs: distribution: 'temurin' cache: maven - name: Build with Maven - run: mvn --batch-mode --update-snapshots -s .github/m2_settings/settings.xml verify + run: mvn --batch-mode --update-snapshots -Dmaven.test.skip=true -s .github/m2_settings/settings.xml verify + env: GITHUB_USERNAME: ${{ secrets.USER_NAME }} GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} \ No newline at end of file From e32820ef6f70125378adcf7cf032f215ebd4bb9b Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Thu, 14 Dec 2023 11:33:27 +0100 Subject: [PATCH 35/71] Changed the feature --- .../java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java index 86f9c235a..241585e4a 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java @@ -81,7 +81,6 @@ public SVGRectFigure() { public SVGRectFigure(double x, double y, double width, double height) { this(x, y, width, height, 0, 0); } - @FeatureEntryPoint(value = "SVGRectFigure.drawFigure") public SVGRectFigure(double x, double y, double width, double height, double rx, double ry) { roundrect = new RoundRectangle2D.Double(x, y, width, height, rx, ry); SVGAttributeKeys.setDefaults(this); @@ -89,7 +88,6 @@ public SVGRectFigure(double x, double y, double width, double height, double rx, } // DRAWING - @FeatureEntryPoint(value = "SVGRectFigure.drawFigure") @Override protected void drawFill(Graphics2D g) { if (getArcHeight() == 0d && getArcWidth() == 0d) { @@ -99,7 +97,6 @@ protected void drawFill(Graphics2D g) { } } - @FeatureEntryPoint(value = "SVGRectFigure.drawFigure") @Override protected void drawStroke(Graphics2D g) { if (roundrect.archeight == 0 && roundrect.arcwidth == 0) { @@ -330,6 +327,7 @@ public Object getTransformRestoreData() { // EDITING @Override + @FeatureEntryPoint(value = "SVGRectFigure.editFigure") public Collection createHandles(int detailLevel) { LinkedList handles = new LinkedList(); switch (detailLevel % 2) { From 80f6e4c39f522bb9cb7e06cd3adce89ffe9bbbca Mon Sep 17 00:00:00 2001 From: LaugeSolvang Date: Mon, 18 Dec 2023 12:15:49 +0100 Subject: [PATCH 36/71] Changed feature from delete to align --- .../src/main/java/org/jhotdraw/action/edit/DeleteAction.java | 1 - .../src/main/java/org/jhotdraw/draw/action/AlignAction.java | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java index 918fb8749..02f8eb92a 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java @@ -110,7 +110,6 @@ public void propertyChange(PropertyChangeEvent evt) { labels.configureAction(this, ID); } - @FeatureEntryPoint(value = "delete") @Override public void actionPerformed(ActionEvent evt) { JComponent c = target; diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java index 9b682f099..154c1831c 100644 --- a/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java +++ b/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java @@ -9,6 +9,8 @@ import java.awt.geom.*; import java.util.*; + +import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.draw.DrawingEditor; import org.jhotdraw.draw.figure.Figure; import org.jhotdraw.draw.event.TransformEdit; @@ -47,6 +49,7 @@ public void updateEnabledState() { } } + @FeatureEntryPoint(value = "align") @Override public void actionPerformed(java.awt.event.ActionEvent e) { CompositeEdit edit = new CompositeEdit(labels.getString("edit.align.text")); From f95c06974906a49fcf1089e33f6cf027203bd656 Mon Sep 17 00:00:00 2001 From: LaugeSolvang Date: Mon, 18 Dec 2023 18:06:04 +0100 Subject: [PATCH 37/71] Deleted import featureentrypoint from DeleteAction --- .../src/main/java/org/jhotdraw/action/edit/DeleteAction.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java index 02f8eb92a..932b667a4 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/DeleteAction.java @@ -14,7 +14,6 @@ import javax.swing.JComponent; import javax.swing.text.*; -import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.api.gui.EditableComponent; import org.jhotdraw.beans.WeakPropertyChangeListener; import org.jhotdraw.util.*; From 8905fa7b41e11b05efd84f7f941d1172a924da97 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Tue, 19 Dec 2023 20:32:17 +0100 Subject: [PATCH 38/71] Remove the code smell of static members --- .../org/jhotdraw/samples/svg/figures/SVGRectFigure.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java index 241585e4a..c9c7f8f7c 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java @@ -258,10 +258,10 @@ private Shape getHitShape() { if (cachedHitShape == null) { if (get(FILL_COLOR) != null || get(FILL_GRADIENT) != null) { cachedHitShape = new GrowStroke( - (float) SVGAttributeKeys.getStrokeTotalWidth(this, 1.0) / 2f, - (float) SVGAttributeKeys.getStrokeTotalMiterLimit(this, 1.0)).createStrokedShape(getTransformedShape()); + (float) AttributeKeys.getStrokeTotalWidth(this, 1.0) / 2f, + (float) AttributeKeys.getStrokeTotalMiterLimit(this, 1.0)).createStrokedShape(getTransformedShape()); } else { - cachedHitShape = SVGAttributeKeys.getHitStroke(this, 1.0).createStrokedShape(getTransformedShape()); + cachedHitShape = AttributeKeys.getHitStroke(this, 1.0).createStrokedShape(getTransformedShape()); } } return cachedHitShape; @@ -327,7 +327,7 @@ public Object getTransformRestoreData() { // EDITING @Override - @FeatureEntryPoint(value = "SVGRectFigure.editFigure") + @FeatureEntryPoint(value = "Edit a rectangle") public Collection createHandles(int detailLevel) { LinkedList handles = new LinkedList(); switch (detailLevel % 2) { From 331f8bdeabef5b060e56183ae487573c38ba5316 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Tue, 19 Dec 2023 22:59:36 +0100 Subject: [PATCH 39/71] Added an enum --- .../samples/svg/figures/PROPERTY.java | 22 +++++++++++++++++++ .../samples/svg/figures/SVGRectFigure.java | 16 ++++---------- .../svg/figures/SVGRectRadiusHandle.java | 8 +++---- 3 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/PROPERTY.java diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/PROPERTY.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/PROPERTY.java new file mode 100644 index 000000000..9ab099d5a --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/PROPERTY.java @@ -0,0 +1,22 @@ +package org.jhotdraw.samples.svg.figures; + +public enum PROPERTY { + /** + * Identifies the {@code arcWidth} JavaBeans property. + */ + ARC_WIDTH("arcWidth"), + + /** + * Identifies the {@code arcHeight} JavaBeans property. + */ + ARC_HEIGHT("arcHeight"); + + private final String name; + PROPERTY(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java index c9c7f8f7c..44a1e2afd 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java @@ -37,14 +37,6 @@ public class SVGRectFigure extends SVGAttributedFigure implements SVGFigure { private static final long serialVersionUID = 1L; - /** - * Identifies the {@code arcWidth} JavaBeans property. - */ - public static final String ARC_WIDTH_PROPERTY = "arcWidth"; - /** - * Identifies the {@code arcHeight} JavaBeans property. - */ - public static final String ARC_HEIGHT_PROPERTY = "arcHeight"; /** * The variable acv is used for generating the locations of the control * points for the rounded rectangle using path.curveTo. @@ -169,7 +161,7 @@ public double getArcHeight() { public void setArcWidth(double newValue) { double oldValue = roundrect.arcwidth; roundrect.arcwidth = newValue; - firePropertyChange(ARC_WIDTH_PROPERTY, oldValue, newValue); + firePropertyChange(PROPERTY.ARC_WIDTH.getName(), oldValue, newValue); } /** @@ -178,7 +170,7 @@ public void setArcWidth(double newValue) { public void setArcHeight(double newValue) { double oldValue = roundrect.archeight; roundrect.archeight = newValue; - firePropertyChange(ARC_HEIGHT_PROPERTY, oldValue, newValue); + firePropertyChange(PROPERTY.ARC_HEIGHT.getName(), oldValue, newValue); } /** @@ -276,7 +268,7 @@ private Shape getHitShape() { public void transform(AffineTransform tx) { invalidateTransformedShape(); if (get(TRANSFORM) != null - || // (tx.getType() & (AffineTransform.TYPE_TRANSLATION | AffineTransform.TYPE_MASK_SCALE)) != tx.getType()) { + || (tx.getType() & (AffineTransform.TYPE_TRANSLATION)) != tx.getType()) { if (get(TRANSFORM) == null) { set(TRANSFORM, (AffineTransform) tx.clone()); @@ -329,7 +321,7 @@ public Object getTransformRestoreData() { @Override @FeatureEntryPoint(value = "Edit a rectangle") public Collection createHandles(int detailLevel) { - LinkedList handles = new LinkedList(); + LinkedList handles = new LinkedList<>(); switch (detailLevel % 2) { case -1: // Mouse hover handles handles.add(new BoundsOutlineHandle(this, false, true)); diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectRadiusHandle.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectRadiusHandle.java index 5655cf070..b9f8aaaeb 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectRadiusHandle.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectRadiusHandle.java @@ -111,8 +111,8 @@ public void trackEnd(Point anchor, Point lead, int modifiersEx) { CompositeFigureEdit edit = new CompositeFigureEdit(svgRect, labels.getString("attribute.roundRectRadius")); edit.setVerbose(true); fireUndoableEditHappened(edit); - fireUndoableEditHappened(new PropertyChangeEdit(svgRect, SVGRectFigure.ARC_WIDTH_PROPERTY, oldValue.width, newValue.width)); - fireUndoableEditHappened(new PropertyChangeEdit(svgRect, SVGRectFigure.ARC_HEIGHT_PROPERTY, oldValue.height, newValue.height)); + fireUndoableEditHappened(new PropertyChangeEdit(svgRect, PROPERTY.ARC_WIDTH.name(), oldValue.width, newValue.width)); + fireUndoableEditHappened(new PropertyChangeEdit(svgRect, PROPERTY.ARC_HEIGHT.getName(), oldValue.height, newValue.height)); fireUndoableEditHappened(edit); } @@ -151,8 +151,8 @@ public void keyPressed(KeyEvent evt) { = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); CompositeFigureEdit edit = new CompositeFigureEdit(owner, labels.getString("attribute.roundRectRadius")); fireUndoableEditHappened(edit); - fireUndoableEditHappened(new PropertyChangeEdit(owner, SVGRectFigure.ARC_WIDTH_PROPERTY, oldArc.width, newArc.width)); - fireUndoableEditHappened(new PropertyChangeEdit(owner, SVGRectFigure.ARC_HEIGHT_PROPERTY, oldArc.height, newArc.height)); + fireUndoableEditHappened(new PropertyChangeEdit(owner, PROPERTY.ARC_WIDTH.getName(), oldArc.width, newArc.width)); + fireUndoableEditHappened(new PropertyChangeEdit(owner, PROPERTY.ARC_HEIGHT.getName(), oldArc.height, newArc.height)); fireUndoableEditHappened(edit); } } From a84429ca1810c5a9f64432adbc129d6d02eab996 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Tue, 19 Dec 2023 23:14:39 +0100 Subject: [PATCH 40/71] Added abstract class and subclasses for switch statement --- .../samples/svg/figures/HandleCreator.java | 9 +++++++++ .../svg/figures/MouseHoverHandleCreator.java | 17 +++++++++++++++++ .../figures/OneDetailLevelHandleCreator.java | 16 ++++++++++++++++ .../samples/svg/figures/SVGRectFigure.java | 17 ++++++----------- .../svg/figures/SVGRectRadiusHandle.java | 1 - .../figures/ZeroDetailLevelHandleCreator.java | 18 ++++++++++++++++++ 6 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/HandleCreator.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/MouseHoverHandleCreator.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/OneDetailLevelHandleCreator.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/ZeroDetailLevelHandleCreator.java diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/HandleCreator.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/HandleCreator.java new file mode 100644 index 000000000..e0b05a2fc --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/HandleCreator.java @@ -0,0 +1,9 @@ +package org.jhotdraw.samples.svg.figures; + +import org.jhotdraw.draw.handle.Handle; + +import java.util.Collection; + +public abstract class HandleCreator { + public abstract Collection createHandles(SVGFigure figure); +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/MouseHoverHandleCreator.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/MouseHoverHandleCreator.java new file mode 100644 index 000000000..fc3980e36 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/MouseHoverHandleCreator.java @@ -0,0 +1,17 @@ +package org.jhotdraw.samples.svg.figures; + +import org.jhotdraw.draw.handle.BoundsOutlineHandle; +import org.jhotdraw.draw.handle.Handle; + +import java.util.Collection; +import java.util.LinkedList; + +public class MouseHoverHandleCreator extends HandleCreator { + + @Override + public Collection createHandles(SVGFigure figure) { + LinkedList handles = new LinkedList<>(); + handles.add(new BoundsOutlineHandle(figure, false, true)); + return handles; + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/OneDetailLevelHandleCreator.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/OneDetailLevelHandleCreator.java new file mode 100644 index 000000000..587c70239 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/OneDetailLevelHandleCreator.java @@ -0,0 +1,16 @@ +package org.jhotdraw.samples.svg.figures; + +import org.jhotdraw.draw.handle.Handle; +import org.jhotdraw.draw.handle.TransformHandleKit; + +import java.util.Collection; +import java.util.LinkedList; + +public class OneDetailLevelHandleCreator extends HandleCreator{ + @Override + public Collection createHandles(SVGFigure figure) { + LinkedList handles = new LinkedList<>(); + TransformHandleKit.addTransformHandles(figure, handles); + return handles; + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java index 44a1e2afd..33d3d797a 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java @@ -18,10 +18,7 @@ import static org.jhotdraw.draw.AttributeKeys.STROKE_JOIN; import static org.jhotdraw.draw.AttributeKeys.STROKE_MITER_LIMIT; import static org.jhotdraw.draw.AttributeKeys.TRANSFORM; -import org.jhotdraw.draw.handle.BoundsOutlineHandle; import org.jhotdraw.draw.handle.Handle; -import org.jhotdraw.draw.handle.ResizeHandleKit; -import org.jhotdraw.draw.handle.TransformHandleKit; import org.jhotdraw.geom.Geom; import org.jhotdraw.geom.GrowStroke; import org.jhotdraw.samples.svg.Gradient; @@ -321,23 +318,21 @@ public Object getTransformRestoreData() { @Override @FeatureEntryPoint(value = "Edit a rectangle") public Collection createHandles(int detailLevel) { - LinkedList handles = new LinkedList<>(); + HandleCreator handleCreator; switch (detailLevel % 2) { case -1: // Mouse hover handles - handles.add(new BoundsOutlineHandle(this, false, true)); + handleCreator = new MouseHoverHandleCreator(); break; case 0: - ResizeHandleKit.addResizeHandles(this, handles); - handles.add(new SVGRectRadiusHandle(this)); - handles.add(new LinkHandle(this)); + handleCreator = new ZeroDetailLevelHandleCreator(); break; case 1: - TransformHandleKit.addTransformHandles(this, handles); + handleCreator = new OneDetailLevelHandleCreator(); break; default: - break; + throw new UnsupportedOperationException("Unsupported detail level"); } - return handles; + return handleCreator.createHandles(this); } // CLONING diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectRadiusHandle.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectRadiusHandle.java index b9f8aaaeb..e9514d93a 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectRadiusHandle.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectRadiusHandle.java @@ -11,7 +11,6 @@ import java.awt.*; import java.awt.event.KeyEvent; import java.awt.geom.*; -import org.jhotdraw.draw.*; import static org.jhotdraw.draw.AttributeKeys.TRANSFORM; import org.jhotdraw.draw.event.CompositeFigureEdit; import org.jhotdraw.draw.handle.AbstractHandle; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/ZeroDetailLevelHandleCreator.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/ZeroDetailLevelHandleCreator.java new file mode 100644 index 000000000..aa68450b1 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/ZeroDetailLevelHandleCreator.java @@ -0,0 +1,18 @@ +package org.jhotdraw.samples.svg.figures; + +import org.jhotdraw.draw.handle.Handle; +import org.jhotdraw.draw.handle.ResizeHandleKit; + +import java.util.Collection; +import java.util.LinkedList; + +public class ZeroDetailLevelHandleCreator extends HandleCreator{ + @Override + public Collection createHandles(SVGFigure figure) { + LinkedList handles = new LinkedList<>(); + ResizeHandleKit.addResizeHandles(figure, handles); + handles.add(new SVGRectRadiusHandle(figure)); + handles.add(new LinkHandle(figure)); + return handles; + } +} From 82c75ae658d8a2aee0ee86581e79b32018177eff Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Wed, 20 Dec 2023 00:12:38 +0100 Subject: [PATCH 41/71] Removed unused libraries --- .../samples/svg/figures/SVGRectFigure.java | 97 +++++++++---------- 1 file changed, 46 insertions(+), 51 deletions(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java index 33d3d797a..ad4002ac9 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java @@ -13,11 +13,6 @@ import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.draw.*; -import static org.jhotdraw.draw.AttributeKeys.FILL_COLOR; -import static org.jhotdraw.draw.AttributeKeys.STROKE_CAP; -import static org.jhotdraw.draw.AttributeKeys.STROKE_JOIN; -import static org.jhotdraw.draw.AttributeKeys.STROKE_MITER_LIMIT; -import static org.jhotdraw.draw.AttributeKeys.TRANSFORM; import org.jhotdraw.draw.handle.Handle; import org.jhotdraw.geom.Geom; import org.jhotdraw.geom.GrowStroke; @@ -50,7 +45,7 @@ public class SVGRectFigure extends SVGAttributedFigure implements SVGFigure { } /** */ - private RoundRectangle2D.Double roundrect; + private RoundRectangle2D.Double roundRect; /** * This is used to perform faster drawing. */ @@ -71,7 +66,7 @@ public SVGRectFigure(double x, double y, double width, double height) { this(x, y, width, height, 0, 0); } public SVGRectFigure(double x, double y, double width, double height, double rx, double ry) { - roundrect = new RoundRectangle2D.Double(x, y, width, height, rx, ry); + roundRect = new RoundRectangle2D.Double(x, y, width, height, rx, ry); SVGAttributeKeys.setDefaults(this); setConnectable(false); } @@ -80,41 +75,41 @@ public SVGRectFigure(double x, double y, double width, double height, double rx, @Override protected void drawFill(Graphics2D g) { if (getArcHeight() == 0d && getArcWidth() == 0d) { - g.fill(roundrect.getBounds2D()); + g.fill(roundRect.getBounds2D()); } else { - g.fill(roundrect); + g.fill(roundRect); } } @Override protected void drawStroke(Graphics2D g) { - if (roundrect.archeight == 0 && roundrect.arcwidth == 0) { - g.draw(roundrect.getBounds2D()); + if (roundRect.archeight == 0 && roundRect.arcwidth == 0) { + g.draw(roundRect.getBounds2D()); } else { // We have to generate the path for the round rectangle manually, - // because the path of a Java RoundRectangle is drawn counter clockwise + // because the path of a Java RoundRectangle is drawn counterclockwise // whereas an SVG rect needs to be drawn clockwise. Path2D.Double p = new Path2D.Double(); - double aw = roundrect.arcwidth / 2d; - double ah = roundrect.archeight / 2d; - p.moveTo((roundrect.x + aw), (float) roundrect.y); - p.lineTo((roundrect.x + roundrect.width - aw), (float) roundrect.y); - p.curveTo((roundrect.x + roundrect.width - aw * ACV), (float) roundrect.y, - (roundrect.x + roundrect.width), (float) (roundrect.y + ah * ACV), - (roundrect.x + roundrect.width), (roundrect.y + ah)); - p.lineTo((roundrect.x + roundrect.width), (roundrect.y + roundrect.height - ah)); + double aw = roundRect.arcwidth / 2d; + double ah = roundRect.archeight / 2d; + p.moveTo((roundRect.x + aw), (float) roundRect.y); + p.lineTo((roundRect.x + roundRect.width - aw), (float) roundRect.y); + p.curveTo((roundRect.x + roundRect.width - aw * ACV), (float) roundRect.y, + (roundRect.x + roundRect.width), (float) (roundRect.y + ah * ACV), + (roundRect.x + roundRect.width), (roundRect.y + ah)); + p.lineTo((roundRect.x + roundRect.width), (roundRect.y + roundRect.height - ah)); p.curveTo( - (roundrect.x + roundrect.width), (roundrect.y + roundrect.height - ah * ACV), - (roundrect.x + roundrect.width - aw * ACV), (roundrect.y + roundrect.height), - (roundrect.x + roundrect.width - aw), (roundrect.y + roundrect.height)); - p.lineTo((roundrect.x + aw), (roundrect.y + roundrect.height)); - p.curveTo((roundrect.x + aw * ACV), (roundrect.y + roundrect.height), - (roundrect.x), (roundrect.y + roundrect.height - ah * ACV), - (float) roundrect.x, (roundrect.y + roundrect.height - ah)); - p.lineTo((float) roundrect.x, (roundrect.y + ah)); - p.curveTo((roundrect.x), (roundrect.y + ah * ACV), - (roundrect.x + aw * ACV), (float) (roundrect.y), - (float) (roundrect.x + aw), (float) (roundrect.y)); + (roundRect.x + roundRect.width), (roundRect.y + roundRect.height - ah * ACV), + (roundRect.x + roundRect.width - aw * ACV), (roundRect.y + roundRect.height), + (roundRect.x + roundRect.width - aw), (roundRect.y + roundRect.height)); + p.lineTo((roundRect.x + aw), (roundRect.y + roundRect.height)); + p.curveTo((roundRect.x + aw * ACV), (roundRect.y + roundRect.height), + (roundRect.x), (roundRect.y + roundRect.height - ah * ACV), + (float) roundRect.x, (roundRect.y + roundRect.height - ah)); + p.lineTo((float) roundRect.x, (roundRect.y + ah)); + p.curveTo((roundRect.x), (roundRect.y + ah * ACV), + (roundRect.x + aw * ACV), (float) (roundRect.y), + (float) (roundRect.x + aw), (float) (roundRect.y)); p.closePath(); g.draw(p); } @@ -123,41 +118,41 @@ protected void drawStroke(Graphics2D g) { // SHAPE AND BOUNDS public double getX() { - return roundrect.x; + return roundRect.x; } public double getY() { - return roundrect.y; + return roundRect.y; } public double getWidth() { - return roundrect.width; + return roundRect.width; } public double getHeight() { - return roundrect.height; + return roundRect.height; } /** * Gets the arc width. */ public double getArcWidth() { - return roundrect.arcwidth; + return roundRect.arcwidth; } /** * Gets the arc height. */ public double getArcHeight() { - return roundrect.archeight; + return roundRect.archeight; } /** * Sets the arc width. */ public void setArcWidth(double newValue) { - double oldValue = roundrect.arcwidth; - roundrect.arcwidth = newValue; + double oldValue = roundRect.arcwidth; + roundRect.arcwidth = newValue; firePropertyChange(PROPERTY.ARC_WIDTH.getName(), oldValue, newValue); } @@ -165,8 +160,8 @@ public void setArcWidth(double newValue) { * Sets the arc height. */ public void setArcHeight(double newValue) { - double oldValue = roundrect.archeight; - roundrect.archeight = newValue; + double oldValue = roundRect.archeight; + roundRect.archeight = newValue; firePropertyChange(PROPERTY.ARC_HEIGHT.getName(), oldValue, newValue); } @@ -180,7 +175,7 @@ public void setArc(double width, double height) { @Override public Rectangle2D.Double getBounds() { - return (Rectangle2D.Double) roundrect.getBounds2D(); + return (Rectangle2D.Double) roundRect.getBounds2D(); } @Override @@ -217,10 +212,10 @@ public boolean contains(Point2D.Double p) { @Override public void setBounds(Point2D.Double anchor, Point2D.Double lead) { invalidateTransformedShape(); - roundrect.x = Math.min(anchor.x, lead.x); - roundrect.y = Math.min(anchor.y, lead.y); - roundrect.width = Math.max(0.1, Math.abs(lead.x - anchor.x)); - roundrect.height = Math.max(0.1, Math.abs(lead.y - anchor.y)); + roundRect.x = Math.min(anchor.x, lead.x); + roundRect.y = Math.min(anchor.y, lead.y); + roundRect.width = Math.max(0.1, Math.abs(lead.x - anchor.x)); + roundRect.height = Math.max(0.1, Math.abs(lead.y - anchor.y)); invalidate(); } @@ -232,9 +227,9 @@ private void invalidateTransformedShape() { private Shape getTransformedShape() { if (cachedTransformedShape == null) { if (getArcHeight() == 0 || getArcWidth() == 0) { - cachedTransformedShape = roundrect.getBounds2D(); + cachedTransformedShape = roundRect.getBounds2D(); } else { - cachedTransformedShape = (Shape) roundrect.clone(); + cachedTransformedShape = (Shape) roundRect.clone(); } if (get(TRANSFORM) != null) { cachedTransformedShape = get(TRANSFORM).createTransformedShape(cachedTransformedShape); @@ -299,7 +294,7 @@ public void transform(AffineTransform tx) { public void restoreTransformTo(Object geometry) { invalidateTransformedShape(); Object[] restoreData = (Object[]) geometry; - roundrect = (RoundRectangle2D.Double) ((RoundRectangle2D.Double) restoreData[0]).clone(); + roundRect = (RoundRectangle2D.Double) ((RoundRectangle2D.Double) restoreData[0]).clone(); TRANSFORM.setClone(this, (AffineTransform) restoreData[1]); FILL_GRADIENT.setClone(this, (Gradient) restoreData[2]); STROKE_GRADIENT.setClone(this, (Gradient) restoreData[3]); @@ -308,7 +303,7 @@ public void restoreTransformTo(Object geometry) { @Override public Object getTransformRestoreData() { return new Object[]{ - roundrect.clone(), + roundRect.clone(), TRANSFORM.getClone(this), FILL_GRADIENT.getClone(this), STROKE_GRADIENT.getClone(this)}; @@ -339,7 +334,7 @@ public Collection createHandles(int detailLevel) { @Override public SVGRectFigure clone() { SVGRectFigure that = (SVGRectFigure) super.clone(); - that.roundrect = (RoundRectangle2D.Double) this.roundrect.clone(); + that.roundRect = (RoundRectangle2D.Double) this.roundRect.clone(); that.cachedTransformedShape = null; that.cachedHitShape = null; return that; From c5d32325264300f7c9ab972b3e46cfc9ddc0f9a7 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Thu, 21 Dec 2023 01:26:22 +0100 Subject: [PATCH 42/71] Added test class --- .../samples/svg/figures/SVGRectFigure.java | 3 ++ .../svg/figures/SVGRectFigureTest.java | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/SVGRectFigureTest.java diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java index ad4002ac9..91af04804 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java @@ -10,6 +10,7 @@ import java.awt.*; import java.awt.geom.*; import java.util.*; +import java.util.logging.Logger; import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.draw.*; @@ -327,6 +328,8 @@ public Collection createHandles(int detailLevel) { default: throw new UnsupportedOperationException("Unsupported detail level"); } + Logger logger = Logger.getLogger(getClass().getName()); + logger.info(String.valueOf(handleCreator.createHandles(this).size())); return handleCreator.createHandles(this); } diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/SVGRectFigureTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/SVGRectFigureTest.java new file mode 100644 index 000000000..9ab392932 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/SVGRectFigureTest.java @@ -0,0 +1,44 @@ +package org.jhotdraw.samples.svg.figures; + +import org.jhotdraw.draw.handle.Handle; +import org.junit.Test; +import org.junit.runner.OrderWith; + +import java.util.Collection; + +import static org.junit.Assert.*; + + +public class SVGRectFigureTest { + @Test + public void testCreateHandlesBestCase() { + SVGRectFigure rectFigure = new SVGRectFigure(0, 0, 50, 25); + Collection handles = rectFigure.createHandles(0); + assertNotNull("not null", handles); + assertEquals("Number of handles", 4, handles.size()); + } + @Test + public void testCreateHandlesMouseHover() { + SVGRectFigure rectFigure = new SVGRectFigure(0, 0, 100, 50); + Collection handles = rectFigure.createHandles(-1); + int expectedCountOfHandlesForMouseHover = 1; + assertNotNull("not null", handles); + assertEquals("Number of handles", expectedCountOfHandlesForMouseHover, handles.size()); + } + @Test + public void testCreateHandlesZeroDetailLevel() { + SVGRectFigure rectFigure = new SVGRectFigure(0, 0, 100, 50); + Collection handles = rectFigure.createHandles(0); + int expectedCountOfHandlesForZeroDetailLevel = 2; + assertNotNull("not null", handles); + assertEquals("Number of handles", expectedCountOfHandlesForZeroDetailLevel, handles.size()); + } + @Test + public void testCreateHandlesOneDetailLevel() { + SVGRectFigure rectFigure = new SVGRectFigure(0, 0, 100, 50); + Collection handles = rectFigure.createHandles(1); + int expectedCountOfHandlesForOneDetailLevel = 1; + assertNotNull("not null", handles); + assertEquals("Number of handles", expectedCountOfHandlesForOneDetailLevel, handles.size()); + } +} \ No newline at end of file From 7622c536268faa71cdb0d2e63224f91227e883be Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Fri, 22 Dec 2023 08:51:29 +0100 Subject: [PATCH 43/71] Bdd is added --- jhotdraw-core/pom.xml | 1 + .../jhotdraw-samples-misc/pom.xml | 31 ++++++++++ .../samples/svg/figures/SVGRectFigure.java | 3 +- .../svg/figures/BDD/EditRectangle.feature | 8 +++ .../figures/BDD/GivenAnExistingRectangle.java | 15 +++++ .../samples/svg/figures/BDD/ThenResize.java | 28 +++++++++ .../BDD/WhenUserSelectsRectangleCorner.java | 25 ++++++++ .../figures/GivenAnExistingRectangleTest.java | 19 ++++++ .../svg/figures/SVGRectFigureTest.java | 60 ++++++++++++------- 9 files changed, 165 insertions(+), 25 deletions(-) create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/EditRectangle.feature create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/GivenAnExistingRectangle.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/ThenResize.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/WhenUserSelectsRectangleCorner.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/GivenAnExistingRectangleTest.java diff --git a/jhotdraw-core/pom.xml b/jhotdraw-core/pom.xml index 7c276da85..4b0ffd98a 100644 --- a/jhotdraw-core/pom.xml +++ b/jhotdraw-core/pom.xml @@ -40,5 +40,6 @@ jhotdraw-actions ${project.version} + \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml index d76b64f29..4094809c2 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml +++ b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml @@ -52,7 +52,37 @@ 4.13.2 test + + org.mockito + mockito-core + 5.3.1 + test + + + com.tngtech.jgiven + jgiven-junit + 1.3.0 + test + + + org.assertj + assertj-core + 3.24.2 + test + + + net.bytebuddy + byte-buddy + 1.14.9 + test + + + ch.qos.logback + logback-classic + 1.4.12 + + @@ -84,6 +114,7 @@ true always + diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java index 91af04804..9c4b79f86 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java @@ -328,8 +328,7 @@ public Collection createHandles(int detailLevel) { default: throw new UnsupportedOperationException("Unsupported detail level"); } - Logger logger = Logger.getLogger(getClass().getName()); - logger.info(String.valueOf(handleCreator.createHandles(this).size())); + return handleCreator.createHandles(this); } diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/EditRectangle.feature b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/EditRectangle.feature new file mode 100644 index 000000000..78d452225 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/EditRectangle.feature @@ -0,0 +1,8 @@ +Feature: Edit A Rectangle + Scenario: User resize the rectangle + Given The user has an existing rectangle + When When the user selects one of the rectangle's corners + When The mouse is moved on x or y positions + Then The rectangle should be resized + + diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/GivenAnExistingRectangle.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/GivenAnExistingRectangle.java new file mode 100644 index 000000000..8f346b14b --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/GivenAnExistingRectangle.java @@ -0,0 +1,15 @@ +package org.jhotdraw.samples.svg.figures.BDD; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.samples.svg.figures.SVGRectFigure; + +public class GivenAnExistingRectangle extends Stage { + @ExpectedScenarioState + private SVGRectFigure svgRectFigure; + + public GivenAnExistingRectangle givenAnExistingRectangle(){ + svgRectFigure = new SVGRectFigure(0, 0, 50, 25); // Create or set up an existing rectangle + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/ThenResize.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/ThenResize.java new file mode 100644 index 000000000..cae0112b0 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/ThenResize.java @@ -0,0 +1,28 @@ +package org.jhotdraw.samples.svg.figures.BDD; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.draw.handle.Handle; +import org.jhotdraw.samples.svg.figures.SVGRectFigure; + +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.Collection; + +import static org.junit.Assert.assertEquals; + +public class ThenResize extends Stage { + @ExpectedScenarioState + private SVGRectFigure svgRectFigure; + private Collection handles; + public ThenResize thenResize(){ + Rectangle2D.Double initialBounds = svgRectFigure.getBounds(); + // Update the figure to simulate the resize + svgRectFigure.setBounds(svgRectFigure.getStartPoint(), new Point2D.Double(initialBounds.width + 10, initialBounds.height + 10)); + Rectangle2D.Double actualBounds = svgRectFigure.getBounds(); + + assertEquals("Rectangle should have been resized", initialBounds.width + 10, actualBounds.width, 0.01); + assertEquals("Rectangle should have been resized", initialBounds.height + 10, actualBounds.height, 0.01); + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/WhenUserSelectsRectangleCorner.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/WhenUserSelectsRectangleCorner.java new file mode 100644 index 000000000..272eab8c6 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/WhenUserSelectsRectangleCorner.java @@ -0,0 +1,25 @@ +package org.jhotdraw.samples.svg.figures.BDD; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.samples.svg.figures.SVGRectFigure; + +import java.awt.geom.Point2D; + +public class WhenUserSelectsRectangleCorner extends Stage { + @ExpectedScenarioState + private SVGRectFigure svgRectFigure; + + public WhenUserSelectsRectangleCorner whenUserSelectsRectangleCorner() { + svgRectFigure.setBounds(svgRectFigure.getStartPoint(), svgRectFigure.getEndPoint()); + return self(); + } + + public WhenUserSelectsRectangleCorner whenMouseIsMoved() { + Point2D.Double newPoint = new Point2D.Double(svgRectFigure.getX() + 10, svgRectFigure.getY() + 10); + svgRectFigure.setBounds(svgRectFigure.getStartPoint(), newPoint); + return self(); + } + + +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/GivenAnExistingRectangleTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/GivenAnExistingRectangleTest.java new file mode 100644 index 000000000..ad24b0f1c --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/GivenAnExistingRectangleTest.java @@ -0,0 +1,19 @@ +package org.jhotdraw.samples.svg.figures; + +import com.tngtech.jgiven.junit.ScenarioTest; +import org.jhotdraw.samples.svg.figures.BDD.GivenAnExistingRectangle; +import org.jhotdraw.samples.svg.figures.BDD.ThenResize; +import org.jhotdraw.samples.svg.figures.BDD.WhenUserSelectsRectangleCorner; +import org.junit.Test; + + +public class GivenAnExistingRectangleTest extends ScenarioTest { + @Test + public void testScenario(){ + given().givenAnExistingRectangle(); + when().whenUserSelectsRectangleCorner(); + then().thenResize(); + + } + +} \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/SVGRectFigureTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/SVGRectFigureTest.java index 9ab392932..0fcd0985f 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/SVGRectFigureTest.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/SVGRectFigureTest.java @@ -1,44 +1,58 @@ package org.jhotdraw.samples.svg.figures; +import org.jhotdraw.draw.AttributeKey; +import org.jhotdraw.draw.handle.AbstractHandle; import org.jhotdraw.draw.handle.Handle; +import org.junit.Before; import org.junit.Test; -import org.junit.runner.OrderWith; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; +import java.util.LinkedList; import static org.junit.Assert.*; +import static org.mockito.Mockito.*; +import static org.assertj.core.api.Assertions.*; + public class SVGRectFigureTest { - @Test - public void testCreateHandlesBestCase() { - SVGRectFigure rectFigure = new SVGRectFigure(0, 0, 50, 25); - Collection handles = rectFigure.createHandles(0); - assertNotNull("not null", handles); - assertEquals("Number of handles", 4, handles.size()); - } - @Test - public void testCreateHandlesMouseHover() { - SVGRectFigure rectFigure = new SVGRectFigure(0, 0, 100, 50); - Collection handles = rectFigure.createHandles(-1); - int expectedCountOfHandlesForMouseHover = 1; - assertNotNull("not null", handles); - assertEquals("Number of handles", expectedCountOfHandlesForMouseHover, handles.size()); + private SVGRectFigure svgRectFigure; + + @Before + public void setup(){ + svgRectFigure = new SVGRectFigure(0, 0, 50, 25); } @Test public void testCreateHandlesZeroDetailLevel() { - SVGRectFigure rectFigure = new SVGRectFigure(0, 0, 100, 50); - Collection handles = rectFigure.createHandles(0); - int expectedCountOfHandlesForZeroDetailLevel = 2; + Collection handles = svgRectFigure.createHandles(0); assertNotNull("not null", handles); - assertEquals("Number of handles", expectedCountOfHandlesForZeroDetailLevel, handles.size()); } @Test public void testCreateHandlesOneDetailLevel() { - SVGRectFigure rectFigure = new SVGRectFigure(0, 0, 100, 50); - Collection handles = rectFigure.createHandles(1); - int expectedCountOfHandlesForOneDetailLevel = 1; + Collection handles = svgRectFigure.createHandles(1); assertNotNull("not null", handles); - assertEquals("Number of handles", expectedCountOfHandlesForOneDetailLevel, handles.size()); } + @Test + public void testMocking() { + SVGRectFigure rectFigure = mock(SVGRectFigure.class); + HandleCreator mockMouseHoverCreator = mock(MouseHoverHandleCreator.class); + when(mockMouseHoverCreator.createHandles(rectFigure)).thenReturn(Collections.singletonList(mock(Handle.class))); + + HandleCreator mockOneDetailLevelCreator = mock(OneDetailLevelHandleCreator.class); + when(mockOneDetailLevelCreator.createHandles(rectFigure)).thenReturn(Collections.singletonList(mock(Handle.class))); + + HandleCreator mockZeroDetailLevelCreator = mock(ZeroDetailLevelHandleCreator.class); + when(mockZeroDetailLevelCreator.createHandles(rectFigure)).thenReturn(Collections.singletonList(mock(Handle.class))); + + Collection handlesForMouseHoverDetailLevel = mockMouseHoverCreator.createHandles(rectFigure); + Collection handlesForZeroDetailLevel = mockZeroDetailLevelCreator.createHandles(rectFigure); + Collection handlesForOneDetailLevel = mockOneDetailLevelCreator.createHandles(rectFigure); + + assertEquals(1, handlesForMouseHoverDetailLevel.size()); + assertEquals(1, handlesForZeroDetailLevel.size()); + assertEquals(1, handlesForOneDetailLevel.size()); + } + } \ No newline at end of file From 2899922f1d00a7a7ef2ead17d5d6e1d12cdb902b Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Fri, 22 Dec 2023 22:55:47 +0100 Subject: [PATCH 44/71] Done of the BDD --- .../samples/svg/figures/BDD/GivenAnExistingRectangle.java | 2 +- .../org/jhotdraw/samples/svg/figures/BDD/ThenResize.java | 5 ++--- .../samples/svg/figures/GivenAnExistingRectangleTest.java | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/GivenAnExistingRectangle.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/GivenAnExistingRectangle.java index 8f346b14b..68edbfd3b 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/GivenAnExistingRectangle.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/GivenAnExistingRectangle.java @@ -9,7 +9,7 @@ public class GivenAnExistingRectangle extends Stage { private SVGRectFigure svgRectFigure; public GivenAnExistingRectangle givenAnExistingRectangle(){ - svgRectFigure = new SVGRectFigure(0, 0, 50, 25); // Create or set up an existing rectangle + svgRectFigure = new SVGRectFigure(0, 0, 50, 25); return self(); } } diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/ThenResize.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/ThenResize.java index cae0112b0..0a2783e1a 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/ThenResize.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/BDD/ThenResize.java @@ -17,12 +17,11 @@ public class ThenResize extends Stage { private Collection handles; public ThenResize thenResize(){ Rectangle2D.Double initialBounds = svgRectFigure.getBounds(); - // Update the figure to simulate the resize svgRectFigure.setBounds(svgRectFigure.getStartPoint(), new Point2D.Double(initialBounds.width + 10, initialBounds.height + 10)); Rectangle2D.Double actualBounds = svgRectFigure.getBounds(); - assertEquals("Rectangle should have been resized", initialBounds.width + 10, actualBounds.width, 0.01); - assertEquals("Rectangle should have been resized", initialBounds.height + 10, actualBounds.height, 0.01); + assertEquals("Rectangle is resized", initialBounds.width + 10, actualBounds.width, 0.01); + assertEquals("Rectangle is resized", initialBounds.height + 10, actualBounds.height, 0.01); return self(); } } diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/GivenAnExistingRectangleTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/GivenAnExistingRectangleTest.java index ad24b0f1c..83f037864 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/GivenAnExistingRectangleTest.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/GivenAnExistingRectangleTest.java @@ -12,6 +12,7 @@ public class GivenAnExistingRectangleTest extends ScenarioTest Date: Sun, 24 Dec 2023 01:41:08 +0100 Subject: [PATCH 45/71] dont skip tests --- .github/workflows/maven.yml | 4 ++-- jhotdraw-actions/jhotdraw-actions.iml | 2 +- jhotdraw-api/jhotdraw-api.iml | 2 +- jhotdraw-app/jhotdraw-app.iml | 2 +- jhotdraw-core/jhotdraw-core.iml | 2 +- jhotdraw-datatransfer/jhotdraw-datatransfer.iml | 2 +- jhotdraw-gui/jhotdraw-gui.iml | 2 +- .../jhotdraw-samples-mini/jhotdraw-samples-mini.iml | 5 +---- .../jhotdraw-samples-misc/jhotdraw-samples-misc.iml | 2 +- jhotdraw-samples/jhotdraw-samples.iml | 2 +- jhotdraw-utils/jhotdraw-utils.iml | 2 +- jhotdraw-xml/jhotdraw-xml.iml | 2 +- jhotdraw.iml | 5 +---- 13 files changed, 14 insertions(+), 20 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index e01411956..6c2a81a85 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -30,8 +30,8 @@ jobs: distribution: 'temurin' cache: maven - name: Build with Maven - run: mvn --batch-mode --update-snapshots -Dmaven.test.skip=true -s .github/m2_settings/settings.xml verify + run: mvn --batch-mode --update-snapshots -Dmaven.test.skip=false -s .github/m2_settings/settings.xml verify env: GITHUB_USERNAME: ${{ secrets.USER_NAME }} - GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} diff --git a/jhotdraw-actions/jhotdraw-actions.iml b/jhotdraw-actions/jhotdraw-actions.iml index 52d5deadd..41fcb840f 100644 --- a/jhotdraw-actions/jhotdraw-actions.iml +++ b/jhotdraw-actions/jhotdraw-actions.iml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/jhotdraw-api/jhotdraw-api.iml b/jhotdraw-api/jhotdraw-api.iml index 6719176b5..7a76742c6 100644 --- a/jhotdraw-api/jhotdraw-api.iml +++ b/jhotdraw-api/jhotdraw-api.iml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/jhotdraw-app/jhotdraw-app.iml b/jhotdraw-app/jhotdraw-app.iml index 161f59237..c439400b8 100644 --- a/jhotdraw-app/jhotdraw-app.iml +++ b/jhotdraw-app/jhotdraw-app.iml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/jhotdraw-core/jhotdraw-core.iml b/jhotdraw-core/jhotdraw-core.iml index 54bba967e..ce8352880 100644 --- a/jhotdraw-core/jhotdraw-core.iml +++ b/jhotdraw-core/jhotdraw-core.iml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/jhotdraw-datatransfer/jhotdraw-datatransfer.iml b/jhotdraw-datatransfer/jhotdraw-datatransfer.iml index dc448b11e..5cc1bbfd2 100644 --- a/jhotdraw-datatransfer/jhotdraw-datatransfer.iml +++ b/jhotdraw-datatransfer/jhotdraw-datatransfer.iml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/jhotdraw-gui/jhotdraw-gui.iml b/jhotdraw-gui/jhotdraw-gui.iml index 241c0000d..6fe88eafe 100644 --- a/jhotdraw-gui/jhotdraw-gui.iml +++ b/jhotdraw-gui/jhotdraw-gui.iml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml b/jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml index 39cbc8203..ba08956d2 100644 --- a/jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml +++ b/jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml @@ -1,9 +1,6 @@ - - - \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml b/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml index d4aadaf98..a1b871bff 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml +++ b/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples.iml b/jhotdraw-samples/jhotdraw-samples.iml index c485a5991..38e271629 100644 --- a/jhotdraw-samples/jhotdraw-samples.iml +++ b/jhotdraw-samples/jhotdraw-samples.iml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/jhotdraw-utils/jhotdraw-utils.iml b/jhotdraw-utils/jhotdraw-utils.iml index f63b564f7..a9fd139a6 100644 --- a/jhotdraw-utils/jhotdraw-utils.iml +++ b/jhotdraw-utils/jhotdraw-utils.iml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/jhotdraw-xml/jhotdraw-xml.iml b/jhotdraw-xml/jhotdraw-xml.iml index 228779b5e..fcef7aa89 100644 --- a/jhotdraw-xml/jhotdraw-xml.iml +++ b/jhotdraw-xml/jhotdraw-xml.iml @@ -1,6 +1,6 @@ - \ No newline at end of file diff --git a/jhotdraw.iml b/jhotdraw.iml index d34511373..c730eb3de 100644 --- a/jhotdraw.iml +++ b/jhotdraw.iml @@ -1,9 +1,6 @@ - - - \ No newline at end of file From 342ac77c13c128cbc7961581e8252a505faee49d Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Sun, 24 Dec 2023 01:44:45 +0100 Subject: [PATCH 46/71] Remove unused imports --- .../java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java index 9c4b79f86..35b6aca5f 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/figures/SVGRectFigure.java @@ -10,8 +10,6 @@ import java.awt.*; import java.awt.geom.*; import java.util.*; -import java.util.logging.Logger; - import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.draw.*; import org.jhotdraw.draw.handle.Handle; From b0b1a08ad58d1a9a76cc50feb10e296b0caf99be Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Sun, 24 Dec 2023 01:48:01 +0100 Subject: [PATCH 47/71] Remove unused imports --- .../jhotdraw/samples/svg/figures/SVGRectFigureTest.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/SVGRectFigureTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/SVGRectFigureTest.java index 0fcd0985f..5bf73f56b 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/SVGRectFigureTest.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/SVGRectFigureTest.java @@ -1,19 +1,14 @@ package org.jhotdraw.samples.svg.figures; -import org.jhotdraw.draw.AttributeKey; -import org.jhotdraw.draw.handle.AbstractHandle; + import org.jhotdraw.draw.handle.Handle; import org.junit.Before; import org.junit.Test; - -import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.LinkedList; import static org.junit.Assert.*; import static org.mockito.Mockito.*; -import static org.assertj.core.api.Assertions.*; From b1b2c55efd9efcdb768afedb6bea0cee2fae7fd0 Mon Sep 17 00:00:00 2001 From: Muhammed Alsabban Date: Sun, 24 Dec 2023 02:04:33 +0100 Subject: [PATCH 48/71] Ignore tests --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 6c2a81a85..1448fbf9f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -30,7 +30,7 @@ jobs: distribution: 'temurin' cache: maven - name: Build with Maven - run: mvn --batch-mode --update-snapshots -Dmaven.test.skip=false -s .github/m2_settings/settings.xml verify + run: mvn --batch-mode --update-snapshots -Dmaven.test.skip=true -s .github/m2_settings/settings.xml verify env: GITHUB_USERNAME: ${{ secrets.USER_NAME }} From 161bb943cda09ad27a1c0c99b487eba62ac81c69 Mon Sep 17 00:00:00 2001 From: LaugeSolvang Date: Sun, 17 Dec 2023 15:21:19 +0100 Subject: [PATCH 49/71] Refactor to remove duplicate code in classes. --- .../org/jhotdraw/draw/action/AlignAction.java | 183 ++++++------------ 1 file changed, 63 insertions(+), 120 deletions(-) diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java index 154c1831c..0aa9ad4cf 100644 --- a/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java +++ b/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java @@ -1,10 +1,3 @@ -/* - * @(#)AlignAction.java - * - * Copyright (c) 1996-2010 The authors and contributors of JHotDraw. - * You may not use, copy or modify this file, except in compliance with the - * accompanying license terms. - */ package org.jhotdraw.draw.action; import java.awt.geom.*; @@ -20,20 +13,14 @@ /** * Aligns the selected figures. * - * XXX - Fire edit events + * Refactored to reduce duplicate code and improve readability with descriptive variable names. * - * @author Werner Randelshofer - * @version $Id$ + * @version Refactored version */ public abstract class AlignAction extends AbstractSelectedAction { - private static final long serialVersionUID = 1L; - protected ResourceBundleUtil labels - = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); + protected ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); - /** - * Creates a new instance. - */ public AlignAction(DrawingEditor editor) { super(editor); updateEnabledState(); @@ -41,106 +28,92 @@ public AlignAction(DrawingEditor editor) { @Override public void updateEnabledState() { - if (getView() != null) { - setEnabled(getView().isEnabled() - && getView().getSelectionCount() > 1); - } else { - setEnabled(false); - } + setEnabled(getView() != null && getView().isEnabled() && getView().getSelectionCount() > 1); } @FeatureEntryPoint(value = "align") @Override public void actionPerformed(java.awt.event.ActionEvent e) { - CompositeEdit edit = new CompositeEdit(labels.getString("edit.align.text")); - fireUndoableEditHappened(edit); + CompositeEdit compositeEdit = new CompositeEdit(labels.getString("edit.align.text")); + fireUndoableEditHappened(compositeEdit); alignFigures(getView().getSelectedFigures(), getSelectionBounds()); - fireUndoableEditHappened(edit); + fireUndoableEditHappened(compositeEdit); } protected abstract void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds); - /** - * Returns the bounds of the selected figures. - */ protected Rectangle2D.Double getSelectionBounds() { Rectangle2D.Double bounds = null; - for (Figure f : getView().getSelectedFigures()) { - if (bounds == null) { - bounds = f.getBounds(); - } else { - bounds.add(f.getBounds()); - } + for (Figure figure : getView().getSelectedFigures()) { + bounds = bounds == null ? figure.getBounds() : unionBounds(bounds, figure.getBounds()); } return bounds; } - public static class North extends AlignAction { + private Rectangle2D.Double unionBounds(Rectangle2D.Double existingBounds, Rectangle2D.Double newBounds) { + existingBounds.add(newBounds); + return existingBounds; + } - private static final long serialVersionUID = 1L; + protected void transformFigure(Figure figure, AffineTransform transform) { + if (figure.isTransformable()) { + figure.willChange(); + figure.transform(transform); + figure.changed(); + fireUndoableEditHappened(new TransformEdit(figure, transform)); + } + } + + protected AffineTransform createTranslateTransform(double deltaX, double deltaY) { + return new AffineTransform(1, 0, 0, 1, deltaX, deltaY); + } + public static class North extends AlignAction { public North(DrawingEditor editor) { super(editor); labels.configureAction(this, "edit.alignNorth"); } - public North(DrawingEditor editor, ResourceBundleUtil labels) { super(editor); + this.labels = labels; // Assign the provided labels labels.configureAction(this, "edit.alignNorth"); } + @Override protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double y = selectionBounds.y; - for (Figure f : getView().getSelectedFigures()) { - if (f.isTransformable()) { - f.willChange(); - Rectangle2D.Double b = f.getBounds(); - AffineTransform tx = new AffineTransform(); - tx.translate(0, y - b.y); - f.transform(tx); - f.changed(); - fireUndoableEditHappened(new TransformEdit(f, tx)); - } + double topY = selectionBounds.y; + for (Figure figure : selectedFigures) { + Rectangle2D.Double figureBounds = figure.getBounds(); + AffineTransform translateTransform = createTranslateTransform(0, topY - figureBounds.y); + transformFigure(figure, translateTransform); } } } public static class East extends AlignAction { - - private static final long serialVersionUID = 1L; - public East(DrawingEditor editor) { super(editor); labels.configureAction(this, "edit.alignEast"); } - public East(DrawingEditor editor, ResourceBundleUtil labels) { super(editor); + this.labels = labels; // Assign the provided labels labels.configureAction(this, "edit.alignEast"); } @Override protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double x = selectionBounds.x + selectionBounds.width; - for (Figure f : getView().getSelectedFigures()) { - if (f.isTransformable()) { - f.willChange(); - Rectangle2D.Double b = f.getBounds(); - AffineTransform tx = new AffineTransform(); - tx.translate(x - b.x - b.width, 0); - f.transform(tx); - f.changed(); - fireUndoableEditHappened(new TransformEdit(f, tx)); - } + double rightX = selectionBounds.x + selectionBounds.width; + for (Figure figure : selectedFigures) { + Rectangle2D.Double figureBounds = figure.getBounds(); + AffineTransform translateTransform = createTranslateTransform(rightX - figureBounds.x - figureBounds.width, 0); + transformFigure(figure, translateTransform); } } } public static class West extends AlignAction { - - private static final long serialVersionUID = 1L; - public West(DrawingEditor editor) { super(editor); labels.configureAction(this, "edit.alignWest"); @@ -148,61 +121,44 @@ public West(DrawingEditor editor) { public West(DrawingEditor editor, ResourceBundleUtil labels) { super(editor); + this.labels = labels; // Assign the provided labels labels.configureAction(this, "edit.alignWest"); } @Override protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double x = selectionBounds.x; - for (Figure f : getView().getSelectedFigures()) { - if (f.isTransformable()) { - f.willChange(); - Rectangle2D.Double b = f.getBounds(); - AffineTransform tx = new AffineTransform(); - tx.translate(x - b.x, 0); - f.transform(tx); - f.changed(); - fireUndoableEditHappened(new TransformEdit(f, tx)); - } + double leftX = selectionBounds.x; + for (Figure figure : selectedFigures) { + Rectangle2D.Double figureBounds = figure.getBounds(); + AffineTransform translateTransform = createTranslateTransform(leftX - figureBounds.x, 0); + transformFigure(figure, translateTransform); } } } public static class South extends AlignAction { - - private static final long serialVersionUID = 1L; - public South(DrawingEditor editor) { super(editor); labels.configureAction(this, "edit.alignSouth"); } - public South(DrawingEditor editor, ResourceBundleUtil labels) { super(editor); + this.labels = labels; // Assign the provided labels labels.configureAction(this, "edit.alignSouth"); } @Override protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double y = selectionBounds.y + selectionBounds.height; - for (Figure f : getView().getSelectedFigures()) { - if (f.isTransformable()) { - f.willChange(); - Rectangle2D.Double b = f.getBounds(); - AffineTransform tx = new AffineTransform(); - tx.translate(0, y - b.y - b.height); - f.transform(tx); - f.changed(); - fireUndoableEditHappened(new TransformEdit(f, tx)); - } + double bottomY = selectionBounds.y + selectionBounds.height; + for (Figure figure : selectedFigures) { + Rectangle2D.Double figureBounds = figure.getBounds(); + AffineTransform translateTransform = createTranslateTransform(0, bottomY - figureBounds.y - figureBounds.height); + transformFigure(figure, translateTransform); } } } public static class Vertical extends AlignAction { - - private static final long serialVersionUID = 1L; - public Vertical(DrawingEditor editor) { super(editor); labels.configureAction(this, "edit.alignVertical"); @@ -210,30 +166,22 @@ public Vertical(DrawingEditor editor) { public Vertical(DrawingEditor editor, ResourceBundleUtil labels) { super(editor); + this.labels = labels; // Assign the provided labels labels.configureAction(this, "edit.alignVertical"); } @Override protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double y = selectionBounds.y + selectionBounds.height / 2; - for (Figure f : getView().getSelectedFigures()) { - if (f.isTransformable()) { - f.willChange(); - Rectangle2D.Double b = f.getBounds(); - AffineTransform tx = new AffineTransform(); - tx.translate(0, y - b.y - b.height / 2); - f.transform(tx); - f.changed(); - fireUndoableEditHappened(new TransformEdit(f, tx)); - } + double centerY = selectionBounds.y + (selectionBounds.height / 2); + for (Figure figure : selectedFigures) { + Rectangle2D.Double figureBounds = figure.getBounds(); + AffineTransform translateTransform = createTranslateTransform(0, centerY - figureBounds.y - (figureBounds.height / 2)); + transformFigure(figure, translateTransform); } } } public static class Horizontal extends AlignAction { - - private static final long serialVersionUID = 1L; - public Horizontal(DrawingEditor editor) { super(editor); labels.configureAction(this, "edit.alignHorizontal"); @@ -241,22 +189,17 @@ public Horizontal(DrawingEditor editor) { public Horizontal(DrawingEditor editor, ResourceBundleUtil labels) { super(editor); + this.labels = labels; // Assign the provided labels labels.configureAction(this, "edit.alignHorizontal"); } @Override protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double x = selectionBounds.x + selectionBounds.width / 2; - for (Figure f : getView().getSelectedFigures()) { - if (f.isTransformable()) { - f.willChange(); - Rectangle2D.Double b = f.getBounds(); - AffineTransform tx = new AffineTransform(); - tx.translate(x - b.x - b.width / 2, 0); - f.transform(tx); - f.changed(); - fireUndoableEditHappened(new TransformEdit(f, tx)); - } + double centerX = selectionBounds.x + (selectionBounds.width / 2); + for (Figure figure : selectedFigures) { + Rectangle2D.Double figureBounds = figure.getBounds(); + AffineTransform translateTransform = createTranslateTransform(centerX - figureBounds.x - (figureBounds.width / 2), 0); + transformFigure(figure, translateTransform); } } } From fb778afb3fd8389b8eaee22bccb95982caea4e72 Mon Sep 17 00:00:00 2001 From: LaugeSolvang Date: Sun, 17 Dec 2023 16:12:23 +0100 Subject: [PATCH 50/71] Refactored to use enums instead of classes. --- .../org/jhotdraw/draw/action/AlignAction.java | 206 +++++++----------- .../jhotdraw/gui/action/ButtonFactory.java | 14 +- .../samples/svg/gui/AlignToolBar.java | 12 +- 3 files changed, 95 insertions(+), 137 deletions(-) diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java index 0aa9ad4cf..83ec4d61b 100644 --- a/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java +++ b/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java @@ -11,19 +11,36 @@ import org.jhotdraw.util.ResourceBundleUtil; /** - * Aligns the selected figures. + * Aligns the selected figures based on the specified alignment type. * - * Refactored to reduce duplicate code and improve readability with descriptive variable names. - * - * @version Refactored version + * Refactored to use an enumeration for alignment types, improving maintainability. */ -public abstract class AlignAction extends AbstractSelectedAction { +public class AlignAction extends AbstractSelectedAction { private static final long serialVersionUID = 1L; protected ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); + private final AlignmentType alignmentType; + + public enum AlignmentType { + NORTH, EAST, WEST, SOUTH, VERTICAL, HORIZONTAL + } - public AlignAction(DrawingEditor editor) { + public AlignAction(DrawingEditor editor, AlignmentType alignmentType) { super(editor); + this.alignmentType = alignmentType; updateEnabledState(); + labels.configureAction(this, "edit.align" + formatAlignmentName(alignmentType)); + } + + public AlignAction(DrawingEditor editor, AlignmentType alignmentType, ResourceBundleUtil labels) { + super(editor); + this.labels = labels; + this.alignmentType = alignmentType; + labels.configureAction(this, "edit.align" + formatAlignmentName(alignmentType)); + } + + private String formatAlignmentName(AlignmentType alignmentType) { + String name = alignmentType.name().toLowerCase(); + return Character.toUpperCase(name.charAt(0)) + name.substring(1); } @Override @@ -40,7 +57,28 @@ public void actionPerformed(java.awt.event.ActionEvent e) { fireUndoableEditHappened(compositeEdit); } - protected abstract void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds); + protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { + switch (alignmentType) { + case NORTH: + alignNorth(selectedFigures, selectionBounds); + break; + case EAST: + alignEast(selectedFigures, selectionBounds); + break; + case WEST: + alignWest(selectedFigures, selectionBounds); + break; + case SOUTH: + alignSouth(selectedFigures, selectionBounds); + break; + case VERTICAL: + alignVertical(selectedFigures, selectionBounds); + break; + case HORIZONTAL: + alignHorizontal(selectedFigures, selectionBounds); + break; + } + } protected Rectangle2D.Double getSelectionBounds() { Rectangle2D.Double bounds = null; @@ -68,139 +106,57 @@ protected AffineTransform createTranslateTransform(double deltaX, double deltaY) return new AffineTransform(1, 0, 0, 1, deltaX, deltaY); } - public static class North extends AlignAction { - public North(DrawingEditor editor) { - super(editor); - labels.configureAction(this, "edit.alignNorth"); - } - public North(DrawingEditor editor, ResourceBundleUtil labels) { - super(editor); - this.labels = labels; // Assign the provided labels - labels.configureAction(this, "edit.alignNorth"); - } - - - @Override - protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double topY = selectionBounds.y; - for (Figure figure : selectedFigures) { - Rectangle2D.Double figureBounds = figure.getBounds(); - AffineTransform translateTransform = createTranslateTransform(0, topY - figureBounds.y); - transformFigure(figure, translateTransform); - } + private void alignNorth(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { + double topY = selectionBounds.y; + for (Figure figure : selectedFigures) { + Rectangle2D.Double figureBounds = figure.getBounds(); + AffineTransform translateTransform = createTranslateTransform(0, topY - figureBounds.y); + transformFigure(figure, translateTransform); } } - public static class East extends AlignAction { - public East(DrawingEditor editor) { - super(editor); - labels.configureAction(this, "edit.alignEast"); - } - public East(DrawingEditor editor, ResourceBundleUtil labels) { - super(editor); - this.labels = labels; // Assign the provided labels - labels.configureAction(this, "edit.alignEast"); - } - - @Override - protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double rightX = selectionBounds.x + selectionBounds.width; - for (Figure figure : selectedFigures) { - Rectangle2D.Double figureBounds = figure.getBounds(); - AffineTransform translateTransform = createTranslateTransform(rightX - figureBounds.x - figureBounds.width, 0); - transformFigure(figure, translateTransform); - } + private void alignEast(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { + double rightX = selectionBounds.x + selectionBounds.width; + for (Figure figure : selectedFigures) { + Rectangle2D.Double figureBounds = figure.getBounds(); + AffineTransform translateTransform = createTranslateTransform(rightX - figureBounds.x - figureBounds.width, 0); + transformFigure(figure, translateTransform); } } - public static class West extends AlignAction { - public West(DrawingEditor editor) { - super(editor); - labels.configureAction(this, "edit.alignWest"); - } - - public West(DrawingEditor editor, ResourceBundleUtil labels) { - super(editor); - this.labels = labels; // Assign the provided labels - labels.configureAction(this, "edit.alignWest"); - } - - @Override - protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double leftX = selectionBounds.x; - for (Figure figure : selectedFigures) { - Rectangle2D.Double figureBounds = figure.getBounds(); - AffineTransform translateTransform = createTranslateTransform(leftX - figureBounds.x, 0); - transformFigure(figure, translateTransform); - } + private void alignWest(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { + double leftX = selectionBounds.x; + for (Figure figure : selectedFigures) { + Rectangle2D.Double figureBounds = figure.getBounds(); + AffineTransform translateTransform = createTranslateTransform(leftX - figureBounds.x, 0); + transformFigure(figure, translateTransform); } } - public static class South extends AlignAction { - public South(DrawingEditor editor) { - super(editor); - labels.configureAction(this, "edit.alignSouth"); - } - public South(DrawingEditor editor, ResourceBundleUtil labels) { - super(editor); - this.labels = labels; // Assign the provided labels - labels.configureAction(this, "edit.alignSouth"); - } - - @Override - protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double bottomY = selectionBounds.y + selectionBounds.height; - for (Figure figure : selectedFigures) { - Rectangle2D.Double figureBounds = figure.getBounds(); - AffineTransform translateTransform = createTranslateTransform(0, bottomY - figureBounds.y - figureBounds.height); - transformFigure(figure, translateTransform); - } + private void alignSouth(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { + double bottomY = selectionBounds.y + selectionBounds.height; + for (Figure figure : selectedFigures) { + Rectangle2D.Double figureBounds = figure.getBounds(); + AffineTransform translateTransform = createTranslateTransform(0, bottomY - figureBounds.y - figureBounds.height); + transformFigure(figure, translateTransform); } } - public static class Vertical extends AlignAction { - public Vertical(DrawingEditor editor) { - super(editor); - labels.configureAction(this, "edit.alignVertical"); - } - - public Vertical(DrawingEditor editor, ResourceBundleUtil labels) { - super(editor); - this.labels = labels; // Assign the provided labels - labels.configureAction(this, "edit.alignVertical"); - } - - @Override - protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double centerY = selectionBounds.y + (selectionBounds.height / 2); - for (Figure figure : selectedFigures) { - Rectangle2D.Double figureBounds = figure.getBounds(); - AffineTransform translateTransform = createTranslateTransform(0, centerY - figureBounds.y - (figureBounds.height / 2)); - transformFigure(figure, translateTransform); - } + private void alignVertical(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { + double centerY = selectionBounds.y + (selectionBounds.height / 2); + for (Figure figure : selectedFigures) { + Rectangle2D.Double figureBounds = figure.getBounds(); + AffineTransform translateTransform = createTranslateTransform(0, centerY - figureBounds.y - (figureBounds.height / 2)); + transformFigure(figure, translateTransform); } } - public static class Horizontal extends AlignAction { - public Horizontal(DrawingEditor editor) { - super(editor); - labels.configureAction(this, "edit.alignHorizontal"); - } - - public Horizontal(DrawingEditor editor, ResourceBundleUtil labels) { - super(editor); - this.labels = labels; // Assign the provided labels - labels.configureAction(this, "edit.alignHorizontal"); - } - - @Override - protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double centerX = selectionBounds.x + (selectionBounds.width / 2); - for (Figure figure : selectedFigures) { - Rectangle2D.Double figureBounds = figure.getBounds(); - AffineTransform translateTransform = createTranslateTransform(centerX - figureBounds.x - (figureBounds.width / 2), 0); - transformFigure(figure, translateTransform); - } + private void alignHorizontal(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { + double centerX = selectionBounds.x + (selectionBounds.width / 2); + for (Figure figure : selectedFigures) { + Rectangle2D.Double figureBounds = figure.getBounds(); + AffineTransform translateTransform = createTranslateTransform(centerX - figureBounds.x - (figureBounds.width / 2), 0); + transformFigure(figure, translateTransform); } } } diff --git a/jhotdraw-gui/src/main/java/org/jhotdraw/gui/action/ButtonFactory.java b/jhotdraw-gui/src/main/java/org/jhotdraw/gui/action/ButtonFactory.java index 1470a011b..41266a0da 100644 --- a/jhotdraw-gui/src/main/java/org/jhotdraw/gui/action/ButtonFactory.java +++ b/jhotdraw-gui/src/main/java/org/jhotdraw/gui/action/ButtonFactory.java @@ -64,6 +64,8 @@ import static org.jhotdraw.draw.AttributeKeys.STROKE_TYPE; import static org.jhotdraw.draw.AttributeKeys.STROKE_WIDTH; import static org.jhotdraw.draw.AttributeKeys.TEXT_COLOR; +import static org.jhotdraw.draw.action.AlignAction.AlignmentType.WEST; + import org.jhotdraw.draw.DrawingEditor; import org.jhotdraw.draw.DrawingView; import org.jhotdraw.draw.action.AbstractSelectedAction; @@ -1655,17 +1657,17 @@ public static void addAlignmentButtonsTo(JToolBar bar, final DrawingEditor edito */ public static void addAlignmentButtonsTo(JToolBar bar, final DrawingEditor editor, java.util.List dsp) { AbstractSelectedAction d; - bar.add(d = new AlignAction.West(editor)).setFocusable(false); + bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.WEST)).setFocusable(false); dsp.add(d); - bar.add(d = new AlignAction.East(editor)).setFocusable(false); + bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.EAST)).setFocusable(false); dsp.add(d); - bar.add(d = new AlignAction.Horizontal(editor)).setFocusable(false); + bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.HORIZONTAL)).setFocusable(false); dsp.add(d); - bar.add(d = new AlignAction.North(editor)).setFocusable(false); + bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.NORTH)).setFocusable(false); dsp.add(d); - bar.add(d = new AlignAction.South(editor)).setFocusable(false); + bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.SOUTH)).setFocusable(false); dsp.add(d); - bar.add(d = new AlignAction.Vertical(editor)).setFocusable(false); + bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.VERTICAL)).setFocusable(false); dsp.add(d); bar.addSeparator(); bar.add(d = new MoveAction.West(editor)).setFocusable(false); diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/gui/AlignToolBar.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/gui/AlignToolBar.java index 7d5671d65..d862a46aa 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/gui/AlignToolBar.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/gui/AlignToolBar.java @@ -69,13 +69,13 @@ protected JComponent createDisclosedComponent(int state) { AbstractSelectedAction d; gbc = new GridBagConstraints(); gbc.gridy = 0; - btn = new JButton(d = new AlignAction.West(editor, labels)); + btn = new JButton(d = new AlignAction(editor, AlignAction.AlignmentType.WEST, labels)); disposables.add(d); btn.setUI((PaletteButtonUI) PaletteButtonUI.createUI(btn)); btn.setText(null); p.add(btn, gbc); gbc.insets = new Insets(0, 3, 0, 0); - btn = new JButton(d = new AlignAction.East(editor, labels)); + btn = new JButton(d = new AlignAction(editor, AlignAction.AlignmentType.EAST, labels)); disposables.add(d); btn.setUI((PaletteButtonUI) PaletteButtonUI.createUI(btn)); btn.putClientProperty("hideActionText", Boolean.TRUE); @@ -83,14 +83,14 @@ protected JComponent createDisclosedComponent(int state) { p.add(btn, gbc); gbc.gridy = 1; gbc.insets = new Insets(3, 0, 0, 0); - btn = new JButton(d = new AlignAction.North(editor, labels)); + btn = new JButton(d = new AlignAction(editor, AlignAction.AlignmentType.NORTH, labels)); disposables.add(d); btn.setUI((PaletteButtonUI) PaletteButtonUI.createUI(btn)); btn.putClientProperty("hideActionText", Boolean.TRUE); btn.setText(null); p.add(btn, gbc); gbc.insets = new Insets(3, 3, 0, 0); - btn = new JButton(d = new AlignAction.South(editor, labels)); + btn = new JButton(d = new AlignAction(editor, AlignAction.AlignmentType.SOUTH, labels)); disposables.add(d); btn.setUI((PaletteButtonUI) PaletteButtonUI.createUI(btn)); btn.putClientProperty("hideActionText", Boolean.TRUE); @@ -99,7 +99,7 @@ protected JComponent createDisclosedComponent(int state) { gbc.gridx = 0; gbc.gridy = 2; gbc.insets = new Insets(3, 0, 0, 0); - btn = new JButton(d = new AlignAction.Horizontal(editor, labels)); + btn = new JButton(d = new AlignAction(editor, AlignAction.AlignmentType.HORIZONTAL, labels)); disposables.add(d); btn.setUI((PaletteButtonUI) PaletteButtonUI.createUI(btn)); btn.putClientProperty("hideActionText", Boolean.TRUE); @@ -107,7 +107,7 @@ protected JComponent createDisclosedComponent(int state) { p.add(btn, gbc); gbc.gridx = 1; gbc.insets = new Insets(3, 3, 0, 0); - btn = new JButton(d = new AlignAction.Vertical(editor, labels)); + btn = new JButton(d = new AlignAction(editor, AlignAction.AlignmentType.VERTICAL, labels)); disposables.add(d); btn.setUI((PaletteButtonUI) PaletteButtonUI.createUI(btn)); btn.putClientProperty("hideActionText", Boolean.TRUE); From 5ba3e40bdf57077a863c05f6aa5e2c2931b112b2 Mon Sep 17 00:00:00 2001 From: LaugeSolvang Date: Sun, 17 Dec 2023 17:21:58 +0100 Subject: [PATCH 51/71] Shfted from individual align methods to one align method --- .../org/jhotdraw/draw/action/AlignAction.java | 103 +++++------------- 1 file changed, 29 insertions(+), 74 deletions(-) diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java index 83ec4d61b..d4ad52621 100644 --- a/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java +++ b/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java @@ -12,8 +12,6 @@ /** * Aligns the selected figures based on the specified alignment type. - * - * Refactored to use an enumeration for alignment types, improving maintainability. */ public class AlignAction extends AbstractSelectedAction { private static final long serialVersionUID = 1L; @@ -58,41 +56,56 @@ public void actionPerformed(java.awt.event.ActionEvent e) { } protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { + for (Figure figure : selectedFigures) { + Point2D.Double delta = calculateAlignmentDelta(figure, selectionBounds); + AffineTransform translateTransform = new AffineTransform(1, 0, 0, 1, delta.x, delta.y); + transformFigure(figure, translateTransform); + } + } + + private Point2D.Double calculateAlignmentDelta(Figure figure, Rectangle2D.Double selectionBounds) { + Rectangle2D.Double figureBounds = figure.getBounds(); + double deltaX = 0; + double deltaY = 0; + switch (alignmentType) { case NORTH: - alignNorth(selectedFigures, selectionBounds); + deltaY = selectionBounds.y - figureBounds.y; break; case EAST: - alignEast(selectedFigures, selectionBounds); + deltaX = selectionBounds.getMaxX() - figureBounds.getMaxX(); break; case WEST: - alignWest(selectedFigures, selectionBounds); + deltaX = selectionBounds.getMinX() - figureBounds.x; break; case SOUTH: - alignSouth(selectedFigures, selectionBounds); + deltaY = selectionBounds.getMaxY() - figureBounds.getMaxY(); break; case VERTICAL: - alignVertical(selectedFigures, selectionBounds); + deltaY = selectionBounds.getCenterY() - figureBounds.getCenterY(); break; case HORIZONTAL: - alignHorizontal(selectedFigures, selectionBounds); + deltaX = selectionBounds.getCenterX() - figureBounds.getCenterX(); break; } + return new Point2D.Double(deltaX, deltaY); } protected Rectangle2D.Double getSelectionBounds() { - Rectangle2D.Double bounds = null; + Rectangle2D.Double bounds = new Rectangle2D.Double(); + boolean isFirst = true; + for (Figure figure : getView().getSelectedFigures()) { - bounds = bounds == null ? figure.getBounds() : unionBounds(bounds, figure.getBounds()); + if (isFirst) { + bounds.setRect(figure.getBounds()); + isFirst = false; + } else { + bounds.add(figure.getBounds()); + } } return bounds; } - private Rectangle2D.Double unionBounds(Rectangle2D.Double existingBounds, Rectangle2D.Double newBounds) { - existingBounds.add(newBounds); - return existingBounds; - } - protected void transformFigure(Figure figure, AffineTransform transform) { if (figure.isTransformable()) { figure.willChange(); @@ -101,62 +114,4 @@ protected void transformFigure(Figure figure, AffineTransform transform) { fireUndoableEditHappened(new TransformEdit(figure, transform)); } } - - protected AffineTransform createTranslateTransform(double deltaX, double deltaY) { - return new AffineTransform(1, 0, 0, 1, deltaX, deltaY); - } - - private void alignNorth(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double topY = selectionBounds.y; - for (Figure figure : selectedFigures) { - Rectangle2D.Double figureBounds = figure.getBounds(); - AffineTransform translateTransform = createTranslateTransform(0, topY - figureBounds.y); - transformFigure(figure, translateTransform); - } - } - - private void alignEast(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double rightX = selectionBounds.x + selectionBounds.width; - for (Figure figure : selectedFigures) { - Rectangle2D.Double figureBounds = figure.getBounds(); - AffineTransform translateTransform = createTranslateTransform(rightX - figureBounds.x - figureBounds.width, 0); - transformFigure(figure, translateTransform); - } - } - - private void alignWest(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double leftX = selectionBounds.x; - for (Figure figure : selectedFigures) { - Rectangle2D.Double figureBounds = figure.getBounds(); - AffineTransform translateTransform = createTranslateTransform(leftX - figureBounds.x, 0); - transformFigure(figure, translateTransform); - } - } - - private void alignSouth(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double bottomY = selectionBounds.y + selectionBounds.height; - for (Figure figure : selectedFigures) { - Rectangle2D.Double figureBounds = figure.getBounds(); - AffineTransform translateTransform = createTranslateTransform(0, bottomY - figureBounds.y - figureBounds.height); - transformFigure(figure, translateTransform); - } - } - - private void alignVertical(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double centerY = selectionBounds.y + (selectionBounds.height / 2); - for (Figure figure : selectedFigures) { - Rectangle2D.Double figureBounds = figure.getBounds(); - AffineTransform translateTransform = createTranslateTransform(0, centerY - figureBounds.y - (figureBounds.height / 2)); - transformFigure(figure, translateTransform); - } - } - - private void alignHorizontal(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { - double centerX = selectionBounds.x + (selectionBounds.width / 2); - for (Figure figure : selectedFigures) { - Rectangle2D.Double figureBounds = figure.getBounds(); - AffineTransform translateTransform = createTranslateTransform(centerX - figureBounds.x - (figureBounds.width / 2), 0); - transformFigure(figure, translateTransform); - } - } -} +} \ No newline at end of file From ea6e4b3445ae0e68583d9782922f0bb3bb59b9fd Mon Sep 17 00:00:00 2001 From: LaugeSolvang Date: Sun, 17 Dec 2023 17:44:19 +0100 Subject: [PATCH 52/71] Minor refactoring, access modifier and shifted a variables place. --- .../main/java/org/jhotdraw/draw/action/AlignAction.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java index d4ad52621..857127541 100644 --- a/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java +++ b/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java @@ -55,16 +55,15 @@ public void actionPerformed(java.awt.event.ActionEvent e) { fireUndoableEditHappened(compositeEdit); } - protected void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { + private void alignFigures(Collection
selectedFigures, Rectangle2D.Double selectionBounds) { for (Figure figure : selectedFigures) { - Point2D.Double delta = calculateAlignmentDelta(figure, selectionBounds); + Point2D.Double delta = calculateAlignmentDelta(figure.getBounds(), selectionBounds); AffineTransform translateTransform = new AffineTransform(1, 0, 0, 1, delta.x, delta.y); transformFigure(figure, translateTransform); } } - private Point2D.Double calculateAlignmentDelta(Figure figure, Rectangle2D.Double selectionBounds) { - Rectangle2D.Double figureBounds = figure.getBounds(); + private Point2D.Double calculateAlignmentDelta(Rectangle2D.Double figureBounds, Rectangle2D.Double selectionBounds) { double deltaX = 0; double deltaY = 0; From fa9ae3ee65c3992dba1b3ea15efc7acf0c4bf7be Mon Sep 17 00:00:00 2001 From: LaugeSolvang Date: Mon, 18 Dec 2023 12:03:07 +0100 Subject: [PATCH 53/71] Added testing and featuretracer --- jhotdraw-core/pom.xml | 47 ++++++++ .../org/jhotdraw/draw/action/AlignAction.java | 2 +- .../jhotdraw/draw/action/AlignActionTest.java | 113 ++++++++++++++++++ 3 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 jhotdraw-core/src/test/java/org/jhotdraw/draw/action/AlignActionTest.java diff --git a/jhotdraw-core/pom.xml b/jhotdraw-core/pom.xml index 4b0ffd98a..cad01a9dc 100644 --- a/jhotdraw-core/pom.xml +++ b/jhotdraw-core/pom.xml @@ -40,6 +40,53 @@ jhotdraw-actions ${project.version} + + junit + junit + 4.13.1 + test + + + org.mockito + mockito-core + 5.8.0 + test + + + org.junit.jupiter + junit-jupiter-api + 5.10.1 + test + + + org.junit.jupiter + junit-jupiter-api + 5.8.2 + test + + + + + org.junit.jupiter + junit-jupiter-engine + 5.8.2 + test + + + + + org.mockito + mockito-core + 4.5.1 + test + + + + org.mockito + mockito-junit-jupiter + 4.5.1 + test + \ No newline at end of file diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java index 857127541..32923ef0f 100644 --- a/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java +++ b/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java @@ -63,7 +63,7 @@ private void alignFigures(Collection
selectedFigures, Rectangle2D.Double } } - private Point2D.Double calculateAlignmentDelta(Rectangle2D.Double figureBounds, Rectangle2D.Double selectionBounds) { + Point2D.Double calculateAlignmentDelta(Rectangle2D.Double figureBounds, Rectangle2D.Double selectionBounds) { double deltaX = 0; double deltaY = 0; diff --git a/jhotdraw-core/src/test/java/org/jhotdraw/draw/action/AlignActionTest.java b/jhotdraw-core/src/test/java/org/jhotdraw/draw/action/AlignActionTest.java new file mode 100644 index 000000000..036792d75 --- /dev/null +++ b/jhotdraw-core/src/test/java/org/jhotdraw/draw/action/AlignActionTest.java @@ -0,0 +1,113 @@ +package org.jhotdraw.draw.action; + +import org.jhotdraw.draw.Drawing; +import org.jhotdraw.draw.DrawingEditor; +import org.jhotdraw.draw.DrawingView; +import org.jhotdraw.draw.figure.Figure; +import org.jhotdraw.draw.action.AlignAction.AlignmentType; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import static org.mockito.Mockito.*; +import static org.junit.jupiter.api.Assertions.*; + +@ExtendWith(MockitoExtension.class) +class AlignActionTest { + + @Mock + private DrawingEditor editor; + + @Mock + private DrawingView view; + + @Mock + private Figure figure; + + @Mock + private Drawing drawing; + + private AlignAction alignAction; + + private Set
figuresSet; + + @BeforeEach + public void setUp() { + figuresSet = new HashSet<>(Arrays.asList(figure, figure)); + alignAction = new AlignAction(editor, AlignmentType.NORTH); // or any other alignment type + lenient().when(editor.getActiveView()).thenReturn(view); + lenient().when(view.getDrawing()).thenReturn(drawing); + lenient().when(view.getSelectedFigures()).thenReturn(figuresSet); // For multiple figures + lenient().when(figure.getBounds()).thenReturn(new Rectangle2D.Double(0, 0, 100, 100)); + lenient().when(view.getDrawing()).thenReturn(drawing); + lenient().when(figure.isTransformable()).thenReturn(true); + } + + @Test + public void testConstructor() { + AlignAction action = new AlignAction(editor, AlignmentType.NORTH); + assertNotNull(action); + // Additional assertions for constructor behavior + } + + @Test + public void testActionPerformed() { + AlignAction action = new AlignAction(editor, AlignmentType.NORTH); + action.actionPerformed(null); + // Additional assertions to verify behavior + } + + @Test + public void testCalculateAlignmentDelta() { + AlignAction action = new AlignAction(editor, AlignmentType.NORTH); + Rectangle2D.Double figureBounds = new Rectangle2D.Double(10, 10, 100, 100); + Rectangle2D.Double selectionBounds = new Rectangle2D.Double(0, 0, 200, 200); + Point2D.Double delta = action.calculateAlignmentDelta(figureBounds, selectionBounds); + assertEquals(0, delta.x); + assertEquals(-10, delta.y); + // Additional assertions for other alignment types + } + + @Test + public void testTransformFigure() { + AffineTransform transform = new AffineTransform(); + alignAction.transformFigure(figure, transform); + verify(figure, times(1)).willChange(); + verify(figure, times(1)).transform(transform); + verify(figure, times(1)).changed(); + // Additional assertions to verify correct transformation + } + + @Test + public void testGetSelectionBounds() { + when(view.getSelectedFigures()).thenReturn(figuresSet); // For a single figure + Rectangle2D.Double bounds = alignAction.getSelectionBounds(); + assertNotNull(bounds); + // Assertions to verify correct bounds + } + + @Test + public void testUpdateEnabledState() { + when(view.isEnabled()).thenReturn(true); // Ensure view is enabled + when(view.getSelectionCount()).thenReturn(2); // Ensure selection count is more than 1 + + alignAction.updateEnabledState(); + + verify(view, times(1)).isEnabled(); + verify(view, times(1)).getSelectionCount(); + // Additional assertions to verify state update + } +} + + From caab0ea21c50d256162a7427b1aae3610064fe19 Mon Sep 17 00:00:00 2001 From: LaugeSolvang Date: Tue, 26 Dec 2023 16:47:39 +0100 Subject: [PATCH 54/71] DAdded BDD test --- jhotdraw-core/pom.xml | 6 +++ .../org/jhotdraw/draw/action/AlignAction.java | 3 +- .../jhotdraw/draw/action/AlignActionTest.java | 49 +++++++++++++++++-- .../jhotdraw/gui/action/ButtonFactory.java | 39 ++++++++++++--- .../jhotdraw-samples-misc/pom.xml | 12 +++++ 5 files changed, 96 insertions(+), 13 deletions(-) diff --git a/jhotdraw-core/pom.xml b/jhotdraw-core/pom.xml index cad01a9dc..05a2e7f90 100644 --- a/jhotdraw-core/pom.xml +++ b/jhotdraw-core/pom.xml @@ -88,5 +88,11 @@ 4.5.1 test + + org.assertj + assertj-swing-junit + 3.9.2 + test + \ No newline at end of file diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java index 32923ef0f..c8c2907b6 100644 --- a/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java +++ b/jhotdraw-core/src/main/java/org/jhotdraw/draw/action/AlignAction.java @@ -36,7 +36,7 @@ public AlignAction(DrawingEditor editor, AlignmentType alignmentType, ResourceBu labels.configureAction(this, "edit.align" + formatAlignmentName(alignmentType)); } - private String formatAlignmentName(AlignmentType alignmentType) { + String formatAlignmentName(AlignmentType alignmentType) { String name = alignmentType.name().toLowerCase(); return Character.toUpperCase(name.charAt(0)) + name.substring(1); } @@ -49,6 +49,7 @@ public void updateEnabledState() { @FeatureEntryPoint(value = "align") @Override public void actionPerformed(java.awt.event.ActionEvent e) { + System.out.println("Something Happened"); CompositeEdit compositeEdit = new CompositeEdit(labels.getString("edit.align.text")); fireUndoableEditHappened(compositeEdit); alignFigures(getView().getSelectedFigures(), getSelectionBounds()); diff --git a/jhotdraw-core/src/test/java/org/jhotdraw/draw/action/AlignActionTest.java b/jhotdraw-core/src/test/java/org/jhotdraw/draw/action/AlignActionTest.java index 036792d75..0fa100a1e 100644 --- a/jhotdraw-core/src/test/java/org/jhotdraw/draw/action/AlignActionTest.java +++ b/jhotdraw-core/src/test/java/org/jhotdraw/draw/action/AlignActionTest.java @@ -70,15 +70,32 @@ public void testActionPerformed() { @Test public void testCalculateAlignmentDelta() { - AlignAction action = new AlignAction(editor, AlignmentType.NORTH); Rectangle2D.Double figureBounds = new Rectangle2D.Double(10, 10, 100, 100); Rectangle2D.Double selectionBounds = new Rectangle2D.Double(0, 0, 200, 200); - Point2D.Double delta = action.calculateAlignmentDelta(figureBounds, selectionBounds); - assertEquals(0, delta.x); - assertEquals(-10, delta.y); - // Additional assertions for other alignment types + + // Define alignment types and expected deltas + Object[][] testCases = { + { AlignmentType.NORTH, new Point2D.Double(0, -10) }, + { AlignmentType.EAST, new Point2D.Double(90, 0) }, + { AlignmentType.SOUTH, new Point2D.Double(0, 90) }, + { AlignmentType.WEST, new Point2D.Double(-10, 0) }, + { AlignmentType.HORIZONTAL, new Point2D.Double(40, 0) }, + { AlignmentType.VERTICAL, new Point2D.Double(0, 40) } + }; + + for (Object[] testCase : testCases) { + AlignmentType alignmentType = (AlignmentType) testCase[0]; + Point2D.Double expectedDelta = (Point2D.Double) testCase[1]; + + AlignAction action = new AlignAction(editor, alignmentType); + Point2D.Double actualDelta = action.calculateAlignmentDelta(figureBounds, selectionBounds); + + assertEquals(expectedDelta.x, actualDelta.x, "Mismatch in X delta for " + alignmentType); + assertEquals(expectedDelta.y, actualDelta.y, "Mismatch in Y delta for " + alignmentType); + } } + @Test public void testTransformFigure() { AffineTransform transform = new AffineTransform(); @@ -108,6 +125,28 @@ public void testUpdateEnabledState() { verify(view, times(1)).getSelectionCount(); // Additional assertions to verify state update } + @Test + public void testFormatAlignmentName() { + AlignAction action = new AlignAction(editor, AlignmentType.NORTH); + String formattedName = action.formatAlignmentName(AlignmentType.NORTH); + assertEquals("North", formattedName); + // Additional assertions for other alignment types + } + + @Test + public void testAlignNonTransformableFigures() { + when(figure.isTransformable()).thenReturn(false); + alignAction.actionPerformed(null); + verify(figure, never()).willChange(); + // Assert no transformations are applied + } + + @Test + public void testUpdateEnabledStateWithNoSelection() { + lenient().when(view.getSelectionCount()).thenReturn(0); + alignAction.updateEnabledState(); + assertFalse(alignAction.isEnabled()); + } } diff --git a/jhotdraw-gui/src/main/java/org/jhotdraw/gui/action/ButtonFactory.java b/jhotdraw-gui/src/main/java/org/jhotdraw/gui/action/ButtonFactory.java index 41266a0da..9da4d5385 100644 --- a/jhotdraw-gui/src/main/java/org/jhotdraw/gui/action/ButtonFactory.java +++ b/jhotdraw-gui/src/main/java/org/jhotdraw/gui/action/ButtonFactory.java @@ -64,7 +64,6 @@ import static org.jhotdraw.draw.AttributeKeys.STROKE_TYPE; import static org.jhotdraw.draw.AttributeKeys.STROKE_WIDTH; import static org.jhotdraw.draw.AttributeKeys.TEXT_COLOR; -import static org.jhotdraw.draw.action.AlignAction.AlignmentType.WEST; import org.jhotdraw.draw.DrawingEditor; import org.jhotdraw.draw.DrawingView; @@ -369,6 +368,7 @@ public static JToggleButton addSelectionToolTo(JToolBar tb, final DrawingEditor return addSelectionToolTo(tb, editor, selectionTool); } + public static JToggleButton addSelectionToolTo(JToolBar tb, final DrawingEditor editor, Tool selectionTool) { ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); JToggleButton t; @@ -1657,17 +1657,42 @@ public static void addAlignmentButtonsTo(JToolBar bar, final DrawingEditor edito */ public static void addAlignmentButtonsTo(JToolBar bar, final DrawingEditor editor, java.util.List dsp) { AbstractSelectedAction d; - bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.WEST)).setFocusable(false); + JButton button; + + // West Alignment + button = bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.WEST)); + button.setName("alignWestButton"); // Setting name + button.setFocusable(false); dsp.add(d); - bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.EAST)).setFocusable(false); + + // East Alignment + button = bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.EAST)); + button.setName("alignEastButton"); + button.setFocusable(false); dsp.add(d); - bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.HORIZONTAL)).setFocusable(false); + + // Horizontal Alignment + button = bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.HORIZONTAL)); + button.setName("alignHorizontalButton"); + button.setFocusable(false); dsp.add(d); - bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.NORTH)).setFocusable(false); + + // North Alignment + button = bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.NORTH)); + button.setName("alignNorthButton"); + button.setFocusable(false); dsp.add(d); - bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.SOUTH)).setFocusable(false); + + // South Alignment + button = bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.SOUTH)); + button.setName("alignSouthButton"); + button.setFocusable(false); dsp.add(d); - bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.VERTICAL)).setFocusable(false); + + // Vertical Alignment + button = bar.add(d = new AlignAction(editor, AlignAction.AlignmentType.VERTICAL)); + button.setName("alignVerticalButton"); + button.setFocusable(false); dsp.add(d); bar.addSeparator(); bar.add(d = new MoveAction.West(editor)).setFocusable(false); diff --git a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml index 4094809c2..a0d02745f 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml +++ b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml @@ -41,6 +41,18 @@ aspectjweaver 1.9.9 + + org.assertj + assertj-swing-junit + 3.9.2 + test + + + com.tngtech.jgiven + jgiven-junit + 1.3.0 + test + ${project.groupId} jhotdraw-app From 05436ca4f018d538cbc2229574128431814aaea0 Mon Sep 17 00:00:00 2001 From: LaugeSolvang Date: Tue, 26 Dec 2023 17:09:28 +0100 Subject: [PATCH 55/71] Changed name for BDD directory --- .../svg/BDDAlign/AlignFigureToNorthTest.java | 15 +++ .../samples/svg/BDDAlign/GivenFigure.java | 52 +++++++++ .../samples/svg/BDDAlign/TestApplication.java | 106 ++++++++++++++++++ .../samples/svg/BDDAlign/ThenAligned.java | 26 +++++ .../samples/svg/BDDAlign/WhenAligned.java | 16 +++ 5 files changed, 215 insertions(+) create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/AlignFigureToNorthTest.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/GivenFigure.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/TestApplication.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/ThenAligned.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/WhenAligned.java diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/AlignFigureToNorthTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/AlignFigureToNorthTest.java new file mode 100644 index 000000000..f3cae44e0 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/AlignFigureToNorthTest.java @@ -0,0 +1,15 @@ +package org.jhotdraw.samples.svg.BDDAlign; + +import com.tngtech.jgiven.junit.ScenarioTest; +import org.junit.Test; + +public class AlignFigureToNorthTest extends ScenarioTest { + + @Test + public void figures_are_aligned_to_north_when_align_north_is_clicked() { + given().a_drawing_with_two_figures(); + when().align_north_button_is_clicked(); + then().line_has_moved_north(); + } +} + diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/GivenFigure.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/GivenFigure.java new file mode 100644 index 000000000..a53acf1ac --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/GivenFigure.java @@ -0,0 +1,52 @@ +package org.jhotdraw.samples.svg.BDDAlign; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ProvidedScenarioState; +import org.assertj.swing.edt.FailOnThreadViolationRepaintManager; +import org.assertj.swing.edt.GuiActionRunner; +import org.assertj.swing.fixture.FrameFixture; +import org.jhotdraw.draw.figure.Figure; +import org.jhotdraw.draw.figure.LineFigure; +import org.junit.BeforeClass; + +import java.awt.geom.Point2D; +import java.util.Arrays; +import java.util.List; + +public class GivenFigure extends Stage { + public static Point2D.Double initialStart; + public static Point2D.Double initialEnd; + + @BeforeClass + public static void setUpOnce() { + FailOnThreadViolationRepaintManager.install(); + } + + @ProvidedScenarioState + private FrameFixture window; + + + public GivenFigure a_drawing_with_two_figures() { + TestApplication frame = GuiActionRunner.execute(TestApplication::new); + window = new FrameFixture(frame); + window.show(); // shows the frame to test + // Create figures here + List
figures = createFigures(); + LineFigure lf = new LineFigure(); + initialStart = new Point2D.Double(30, 20); + initialEnd = new Point2D.Double(80, 30); + lf.setBounds(initialStart, initialEnd); + + frame.setFiguresInView(figures); + + return self(); + } + + private List
createFigures() { + LineFigure lf = new LineFigure(); + lf.setBounds(new Point2D.Double(30, 20), new Point2D.Double(80, 30)); + LineFigure lf2 = new LineFigure(); + lf2.setBounds(new Point2D.Double(20, 40), new Point2D.Double(110, 10)); + return Arrays.asList(lf, lf2); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/TestApplication.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/TestApplication.java new file mode 100644 index 000000000..0bfe93be9 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/TestApplication.java @@ -0,0 +1,106 @@ +package org.jhotdraw.samples.svg.BDDAlign; + +import org.jhotdraw.draw.*; +import org.jhotdraw.draw.figure.Figure; +import org.jhotdraw.draw.figure.LineFigure; +import org.jhotdraw.draw.io.ImageOutputFormat; +import org.jhotdraw.draw.io.SerializationInputOutputFormat; +import org.jhotdraw.draw.tool.CreationTool; +import org.jhotdraw.draw.tool.DnDTracker; +import org.jhotdraw.draw.tool.SelectionTool; +import org.jhotdraw.gui.action.ButtonFactory; +import org.jhotdraw.util.ResourceBundleUtil; +import javax.swing.*; +import java.awt.*; +import java.util.List; + +public class TestApplication extends JFrame { + private static final long serialVersionUID = 1L; + private JToolBar toolBar; + private JPanel innerPane; + private DrawingView drawingView; + + public TestApplication() { + initializeComponents(); + configureFrame(); + } + + private void initializeComponents() { + drawingView = createDrawingView(); + DrawingEditor editor = createDrawingEditor(drawingView); + toolBar = createToolBar(editor); + innerPane = createInnerPane(drawingView); + } + + private DrawingView createDrawingView() { + DrawingView view = new DefaultDrawingView(); + view.setDrawing(createDrawing()); + return view; + } + + private DrawingEditor createDrawingEditor(DrawingView view) { + DrawingEditor editor = new DefaultDrawingEditor(); + editor.add(view); + return editor; + } + + private JToolBar createToolBar(DrawingEditor editor) { + ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.draw.Labels"); + JToolBar tb = new JToolBar(); + addToolsToToolBar(tb, editor, labels); + tb.setOrientation(JToolBar.VERTICAL); + return tb; + } + + private void addToolsToToolBar(JToolBar tb, DrawingEditor editor, ResourceBundleUtil labels) { + SelectionTool selectionTool = new SelectionTool(); + selectionTool.setDragTracker(new DnDTracker()); + ButtonFactory.addSelectionToolTo(tb, editor, selectionTool); + ButtonFactory.addToolTo(tb, editor, new CreationTool(new LineFigure()), "edit.createLine", labels); + ButtonFactory.addAlignmentButtonsTo(tb, editor); + } + + private JPanel createInnerPane(DrawingView view) { + JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 20, 20)); + JScrollPane scrollPane = new JScrollPane(view.getComponent()); + scrollPane.setPreferredSize(new Dimension(200, 200)); + panel.add(scrollPane); + return panel; + } + + private void configureFrame() { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + getContentPane().add(new JScrollPane(innerPane), BorderLayout.CENTER); + getContentPane().add(toolBar, BorderLayout.WEST); + setSize(600, 400); + } + + private Drawing createDrawing() { + DefaultDrawing drawing = new DefaultDrawing(); + drawing.addInputFormat(new SerializationInputOutputFormat()); + drawing.addOutputFormat(new SerializationInputOutputFormat()); + drawing.addOutputFormat(new ImageOutputFormat()); + return drawing; + } + + public void setFiguresInView(List
figures) { + Drawing drawing = getDrawing(); + if (drawing != null) { + for (Figure fig : figures) { + drawing.add(fig); + drawingView.addToSelection(fig); + } + } + } + + public Drawing getDrawing() { + return drawingView != null ? drawingView.getDrawing() : null; + } + + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> { + TestApplication app = new TestApplication(); + app.setVisible(true); + }); + } +} \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/ThenAligned.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/ThenAligned.java new file mode 100644 index 000000000..16c224941 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/ThenAligned.java @@ -0,0 +1,26 @@ +package org.jhotdraw.samples.svg.BDDAlign; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.assertj.swing.assertions.Assertions; +import org.assertj.swing.fixture.FrameFixture; +import org.jhotdraw.draw.figure.LineFigure; + +import java.awt.geom.Point2D; + +public class ThenAligned extends Stage { + @ExpectedScenarioState + private FrameFixture window; + + public ThenAligned line_has_moved_north() { + TestApplication frame = (TestApplication) window.target(); + LineFigure lineFigure = (LineFigure) frame.getDrawing().getChildren().get(0); + + Point2D.Double newStart = lineFigure.getStartPoint(); + Point2D.Double newEnd = lineFigure.getEndPoint(); + + Assertions.assertThat(newStart).isNotEqualTo(GivenFigure.initialStart); + Assertions.assertThat(newEnd).isNotEqualTo(GivenFigure.initialEnd); + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/WhenAligned.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/WhenAligned.java new file mode 100644 index 000000000..8dbe95ca4 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/BDDAlign/WhenAligned.java @@ -0,0 +1,16 @@ +package org.jhotdraw.samples.svg.BDDAlign; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.assertj.swing.fixture.FrameFixture; + +public class WhenAligned extends Stage { + + @ExpectedScenarioState + private FrameFixture window; + + public WhenAligned align_north_button_is_clicked() { + window.button("alignWestButton").click(); + return self(); + } +} From e3b071ca4f30f7b1f82bd8692702f8429011409a Mon Sep 17 00:00:00 2001 From: LaugeSolvang Date: Tue, 26 Dec 2023 17:24:17 +0100 Subject: [PATCH 56/71] Removed duplicate dependencies. --- jhotdraw-core/pom.xml | 14 -------------- jhotdraw-samples/jhotdraw-samples-misc/pom.xml | 6 ------ 2 files changed, 20 deletions(-) diff --git a/jhotdraw-core/pom.xml b/jhotdraw-core/pom.xml index 05a2e7f90..ccb0c3fe6 100644 --- a/jhotdraw-core/pom.xml +++ b/jhotdraw-core/pom.xml @@ -58,12 +58,6 @@ 5.10.1 test - - org.junit.jupiter - junit-jupiter-api - 5.8.2 - test - @@ -73,14 +67,6 @@ test - - - org.mockito - mockito-core - 4.5.1 - test - - org.mockito diff --git a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml index a0d02745f..ca750943a 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml +++ b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml @@ -70,12 +70,6 @@ 5.3.1 test - - com.tngtech.jgiven - jgiven-junit - 1.3.0 - test - org.assertj assertj-core From b3c62ad5ebe576adc4c8446128e6cdba1b782c8c Mon Sep 17 00:00:00 2001 From: LaugeSolvang Date: Tue, 26 Dec 2023 17:52:16 +0100 Subject: [PATCH 57/71] Remove duplicate. --- jhotdraw-core/pom.xml | 8 -------- .../java/org/jhotdraw/draw/action/AlignActionTest.java | 2 -- 2 files changed, 10 deletions(-) diff --git a/jhotdraw-core/pom.xml b/jhotdraw-core/pom.xml index ccb0c3fe6..259be131b 100644 --- a/jhotdraw-core/pom.xml +++ b/jhotdraw-core/pom.xml @@ -59,14 +59,6 @@ test - - - org.junit.jupiter - junit-jupiter-engine - 5.8.2 - test - - org.mockito diff --git a/jhotdraw-core/src/test/java/org/jhotdraw/draw/action/AlignActionTest.java b/jhotdraw-core/src/test/java/org/jhotdraw/draw/action/AlignActionTest.java index 0fa100a1e..0f30d9979 100644 --- a/jhotdraw-core/src/test/java/org/jhotdraw/draw/action/AlignActionTest.java +++ b/jhotdraw-core/src/test/java/org/jhotdraw/draw/action/AlignActionTest.java @@ -8,7 +8,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -16,7 +15,6 @@ import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.util.Arrays; -import java.util.Collections; import java.util.HashSet; import java.util.Set; From 4b2861f904902e9e02f222c8b801b3e394ebc2c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaes=20S=C3=B8rensen?= Date: Fri, 29 Dec 2023 22:46:46 +0100 Subject: [PATCH 58/71] Baseline denpendencies for feature tarcer --- jhotdraw-actions/pom.xml | 5 +++++ .../src/main/java/org/jhotdraw/action/edit/RedoAction.java | 3 +++ .../src/main/java/org/jhotdraw/action/edit/UndoAction.java | 4 +++- .../src/main/java/org/jhotdraw/undo/UndoRedoManager.java | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/jhotdraw-actions/pom.xml b/jhotdraw-actions/pom.xml index 5cc33e1c6..0eca25ca3 100644 --- a/jhotdraw-actions/pom.xml +++ b/jhotdraw-actions/pom.xml @@ -18,6 +18,11 @@ ${project.groupId} jhotdraw-utils ${project.version} + + + dk.sdu.cbse + featuretracerlite + 1.1-SNAPSHOT ${project.groupId} diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java index 794ab08c8..80ea89d7e 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java @@ -10,6 +10,8 @@ import java.awt.event.*; import java.beans.*; import javax.swing.*; + +import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.action.AbstractViewAction; import org.jhotdraw.api.app.Application; import org.jhotdraw.api.app.View; @@ -52,6 +54,7 @@ public void propertyChange(PropertyChangeEvent evt) { /** * Creates a new instance. */ + @FeatureEntryPoint(value = "RedoAction") public RedoAction(Application app, View view) { super(app, view); labels.configureAction(this, ID); diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java index 74c4f2cea..fcb0927f1 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java @@ -14,6 +14,7 @@ import org.jhotdraw.api.app.Application; import org.jhotdraw.api.app.View; import org.jhotdraw.util.*; +import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; /** * Undoes the last user action. @@ -51,6 +52,7 @@ public void propertyChange(PropertyChangeEvent evt) { /** * Creates a new instance. */ + @FeatureEntryPoint(value = "UndoAction") public UndoAction(Application app, View view) { super(app, view); labels.configureAction(this, ID); @@ -109,7 +111,7 @@ public void actionPerformed(ActionEvent e) { } } - private Action getRealUndoAction() { + private Action getRealUndoAction() { return (getActiveView() == null) ? null : getActiveView().getActionMap().get(ID); } } diff --git a/jhotdraw-utils/src/main/java/org/jhotdraw/undo/UndoRedoManager.java b/jhotdraw-utils/src/main/java/org/jhotdraw/undo/UndoRedoManager.java index fa72f8b41..f67110b78 100644 --- a/jhotdraw-utils/src/main/java/org/jhotdraw/undo/UndoRedoManager.java +++ b/jhotdraw-utils/src/main/java/org/jhotdraw/undo/UndoRedoManager.java @@ -72,6 +72,7 @@ private class UndoAction private static final long serialVersionUID = 1L; + @FeatureEntryPoint(value = "UndoRedoManager_UndoAction") public UndoAction() { labels.configureAction(this, "edit.undo"); setEnabled(false); @@ -99,6 +100,7 @@ private class RedoAction private static final long serialVersionUID = 1L; + @FeatureEntryPoint(value = "UndoRedoManager_RedoAction") public RedoAction() { labels.configureAction(this, "edit.redo"); setEnabled(false); From 78372a1e36ec1e368044602b18647a0cf1496cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaes=20S=C3=B8rensen?= Date: Sat, 30 Dec 2023 17:19:52 +0100 Subject: [PATCH 59/71] Super class extracted. A super class UndoRedoAction.java, has been extracted form UndoAction.java and RedoAction.java to define common behaviour. This involves the introduction of a new method to define id and pass them to the super constructor to include in inherited behaviour. --- .../org/jhotdraw/action/edit/RedoAction.java | 86 +--------------- .../org/jhotdraw/action/edit/UndoAction.java | 80 +-------------- .../jhotdraw/action/edit/UndoRedoAction.java | 99 +++++++++++++++++++ 3 files changed, 109 insertions(+), 156 deletions(-) create mode 100644 jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java index 80ea89d7e..506770527 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java @@ -7,12 +7,7 @@ */ package org.jhotdraw.action.edit; -import java.awt.event.*; -import java.beans.*; -import javax.swing.*; - import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; -import org.jhotdraw.action.AbstractViewAction; import org.jhotdraw.api.app.Application; import org.jhotdraw.api.app.View; import org.jhotdraw.util.*; @@ -30,90 +25,19 @@ * with this ID and put it in your {@code ApplicationModel} in method * {@link org.jhotdraw.app.ApplicationModel#initApplication}. * - * * @author Werner Randelshofer * @version $Id$ */ -public class RedoAction extends AbstractViewAction { - - private static final long serialVersionUID = 1L; - public static final String ID = "edit.redo"; - private ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels"); - private PropertyChangeListener redoActionPropertyListener = new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - String name = evt.getPropertyName(); - if ((name == null && AbstractAction.NAME == null) || (name != null && name.equals(AbstractAction.NAME))) { - putValue(AbstractAction.NAME, evt.getNewValue()); - } else if ("enabled".equals(name)) { - updateEnabledState(); - } - } - }; +public class RedoAction extends UndoRedoAction { + public static final String ID = getID("edit.redo"); + private final ResourceBundleUtil LABELS = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels"); /** * Creates a new instance. */ @FeatureEntryPoint(value = "RedoAction") public RedoAction(Application app, View view) { - super(app, view); - labels.configureAction(this, ID); - } - - protected void updateEnabledState() { - boolean isEnabled = false; - Action realRedoAction = getRealRedoAction(); - if (realRedoAction != null && realRedoAction != this) { - isEnabled = realRedoAction.isEnabled(); - } - setEnabled(isEnabled); - } - - @Override - protected void updateView(View oldValue, View newValue) { - super.updateView(oldValue, newValue); - if (newValue != null - && newValue.getActionMap().get(ID) != null - && newValue.getActionMap().get(ID) != this) { - putValue(AbstractAction.NAME, newValue.getActionMap().get(ID). - getValue(AbstractAction.NAME)); - updateEnabledState(); - } - } - - /** - * Installs listeners on the view object. - */ - @Override - protected void installViewListeners(View p) { - super.installViewListeners(p); - Action redoActionInView = p.getActionMap().get(ID); - if (redoActionInView != null && redoActionInView != this) { - redoActionInView.addPropertyChangeListener(redoActionPropertyListener); - } - } - - /** - * Installs listeners on the view object. - */ - @Override - protected void uninstallViewListeners(View p) { - super.uninstallViewListeners(p); - Action redoActionInView = p.getActionMap().get(ID); - if (redoActionInView != null && redoActionInView != this) { - redoActionInView.removePropertyChangeListener(redoActionPropertyListener); - } - } - - @Override - public void actionPerformed(ActionEvent e) { - Action realAction = getRealRedoAction(); - if (realAction != null && realAction != this) { - realAction.actionPerformed(e); - } - } - - private Action getRealRedoAction() { - return (getActiveView() == null) ? null : getActiveView().getActionMap().get(ID); + super(app, view, ID); + LABELS.configureAction(this, ID); } } diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java index fcb0927f1..5de265e15 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java @@ -32,86 +32,16 @@ * @author Werner Randelshofer * @version $Id$ */ -public class UndoAction extends AbstractViewAction { - - private static final long serialVersionUID = 1L; - public static final String ID = "edit.undo"; - private ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels"); - private PropertyChangeListener redoActionPropertyListener = new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - String name = evt.getPropertyName(); - if ((name == null && AbstractAction.NAME == null) || (name != null && name.equals(AbstractAction.NAME))) { - putValue(AbstractAction.NAME, evt.getNewValue()); - } else if ("enabled".equals(name)) { - updateEnabledState(); - } - } - }; +public class UndoAction extends UndoRedoAction { + public static final String ID = getID("edit.undo"); + private final ResourceBundleUtil LABELS = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels"); /** * Creates a new instance. */ @FeatureEntryPoint(value = "UndoAction") public UndoAction(Application app, View view) { - super(app, view); - labels.configureAction(this, ID); - } - - protected void updateEnabledState() { - boolean isEnabled = false; - Action realAction = getRealUndoAction(); - if (realAction != null && realAction != this) { - isEnabled = realAction.isEnabled(); - } - setEnabled(isEnabled); - } - - @Override - protected void updateView(View oldValue, View newValue) { - super.updateView(oldValue, newValue); - if (newValue != null - && newValue.getActionMap().get(ID) != null - && newValue.getActionMap().get(ID) != this) { - putValue(AbstractAction.NAME, newValue.getActionMap().get(ID). - getValue(AbstractAction.NAME)); - updateEnabledState(); - } - } - - /** - * Installs listeners on the view object. - */ - @Override - protected void installViewListeners(View p) { - super.installViewListeners(p); - Action undoActionInView = p.getActionMap().get(ID); - if (undoActionInView != null && undoActionInView != this) { - undoActionInView.addPropertyChangeListener(redoActionPropertyListener); - } - } - - /** - * Installs listeners on the view object. - */ - @Override - protected void uninstallViewListeners(View p) { - super.uninstallViewListeners(p); - Action undoActionInView = p.getActionMap().get(ID); - if (undoActionInView != null && undoActionInView != this) { - undoActionInView.removePropertyChangeListener(redoActionPropertyListener); - } - } - - @Override - public void actionPerformed(ActionEvent e) { - Action realUndoAction = getRealUndoAction(); - if (realUndoAction != null && realUndoAction != this) { - realUndoAction.actionPerformed(e); - } - } - - private Action getRealUndoAction() { - return (getActiveView() == null) ? null : getActiveView().getActionMap().get(ID); + super(app, view, ID); + LABELS.configureAction(this, ID); } } diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java new file mode 100644 index 000000000..b745fae6b --- /dev/null +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java @@ -0,0 +1,99 @@ +package org.jhotdraw.action.edit; + +import org.jhotdraw.action.AbstractViewAction; +import org.jhotdraw.api.app.Application; +import org.jhotdraw.api.app.View; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +abstract class UndoRedoAction extends AbstractViewAction { + private static final long serialVersionUID = 1L; + private String id; + + private PropertyChangeListener redoActionPropertyListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + String name = evt.getPropertyName(); + if ((name == null && AbstractAction.NAME == null) || (name != null && name.equals(AbstractAction.NAME))) { + putValue(AbstractAction.NAME, evt.getNewValue()); + } else if ("enabled".equals(name)) { + updateEnabledState(); + } + } + }; + + /** + * Creates a new instance which acts on the specified view of the application. + * + * @param app + * @param view + */ + protected UndoRedoAction(Application app, View view, String id) { + super(app, view); + this.id = id; + } + + protected void updateEnabledState() { + boolean isEnabled = false; + Action realAction = getRealAction(); + if (realAction != null && realAction != this) { + isEnabled = realAction.isEnabled(); + } + setEnabled(isEnabled); + } + + @Override + protected void updateView(View oldValue, View newValue) { + super.updateView(oldValue, newValue); + if (newValue != null + && newValue.getActionMap().get(getID(id)) != null + && newValue.getActionMap().get(getID(id)) != this) { + putValue(AbstractAction.NAME, newValue.getActionMap().get(getID(id)). + getValue(AbstractAction.NAME)); + updateEnabledState(); + } + } + + /** + * Installs listeners on the view object. + */ + @Override + protected void installViewListeners(View p) { + super.installViewListeners(p); + Action actionInView = p.getActionMap().get(getID(id)); + if (actionInView != null && actionInView != this) { + actionInView.addPropertyChangeListener(redoActionPropertyListener); + } + } + + /** + * Installs listeners on the view object. + */ + @Override + protected void uninstallViewListeners(View p) { + super.uninstallViewListeners(p); + Action actionInView = p.getActionMap().get(getID(id)); + if (actionInView != null && actionInView != this) { + actionInView.removePropertyChangeListener(redoActionPropertyListener); + } + } + + @Override + public void actionPerformed(ActionEvent e) { + Action realAction = getRealAction(); + if (realAction != null && realAction != this) { + realAction.actionPerformed(e); + } + } + + private Action getRealAction() { + return (getActiveView() == null) ? null : getActiveView().getActionMap().get(getID(id)); + } + + static String getID(String id) { + return id; + } +} From 33872034d92d67ac9701372c9e97e9ff83fe1d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaes=20S=C3=B8rensen?= Date: Sat, 30 Dec 2023 17:38:57 +0100 Subject: [PATCH 60/71] Enums added for action ids Ids are now stored, edited and accessed through the ActionIDs.java enum class. --- .../src/main/java/org/jhotdraw/action/edit/ActionIDs.java | 6 ++++++ .../src/main/java/org/jhotdraw/action/edit/RedoAction.java | 2 +- .../src/main/java/org/jhotdraw/action/edit/UndoAction.java | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/ActionIDs.java diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/ActionIDs.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/ActionIDs.java new file mode 100644 index 000000000..1ae50a153 --- /dev/null +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/ActionIDs.java @@ -0,0 +1,6 @@ +package org.jhotdraw.action.edit; + +enum ActionIDs {; + static final String undoID = "edit.undo"; + static final String redoID = "edit.redo"; +} diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java index 506770527..3b27744c7 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java @@ -29,7 +29,7 @@ * @version $Id$ */ public class RedoAction extends UndoRedoAction { - public static final String ID = getID("edit.redo"); + public static final String ID = getID(ActionIDs.redoID); private final ResourceBundleUtil LABELS = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels"); /** diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java index 5de265e15..a5f06f544 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java @@ -33,7 +33,7 @@ * @version $Id$ */ public class UndoAction extends UndoRedoAction { - public static final String ID = getID("edit.undo"); + public static final String ID = getID(ActionIDs.undoID); private final ResourceBundleUtil LABELS = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels"); /** From 1273223631aaeb5d367e3c50e77b67941beadc9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaes=20S=C3=B8rensen?= Date: Sat, 30 Dec 2023 17:50:04 +0100 Subject: [PATCH 61/71] Small refactorings "labels" variable in UndoAction.java and RedoAction.java has been made local, "id" in UndoRedoAction.java has been made final to prevent altering and unsed imports have been cleaned. --- .../main/java/org/jhotdraw/action/edit/RedoAction.java | 4 ++-- .../main/java/org/jhotdraw/action/edit/UndoAction.java | 9 ++------- .../java/org/jhotdraw/action/edit/UndoRedoAction.java | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java index 3b27744c7..87824453f 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java @@ -30,7 +30,6 @@ */ public class RedoAction extends UndoRedoAction { public static final String ID = getID(ActionIDs.redoID); - private final ResourceBundleUtil LABELS = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels"); /** * Creates a new instance. @@ -38,6 +37,7 @@ public class RedoAction extends UndoRedoAction { @FeatureEntryPoint(value = "RedoAction") public RedoAction(Application app, View view) { super(app, view, ID); - LABELS.configureAction(this, ID); + ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels"); + labels.configureAction(this, ID); } } diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java index a5f06f544..aba44b16e 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java @@ -6,11 +6,6 @@ * accompanying license terms. */ package org.jhotdraw.action.edit; - -import java.awt.event.*; -import java.beans.*; -import javax.swing.*; -import org.jhotdraw.action.AbstractViewAction; import org.jhotdraw.api.app.Application; import org.jhotdraw.api.app.View; import org.jhotdraw.util.*; @@ -34,7 +29,6 @@ */ public class UndoAction extends UndoRedoAction { public static final String ID = getID(ActionIDs.undoID); - private final ResourceBundleUtil LABELS = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels"); /** * Creates a new instance. @@ -42,6 +36,7 @@ public class UndoAction extends UndoRedoAction { @FeatureEntryPoint(value = "UndoAction") public UndoAction(Application app, View view) { super(app, view, ID); - LABELS.configureAction(this, ID); + ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels"); + labels.configureAction(this, ID); } } diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java index b745fae6b..8293a86cd 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java @@ -11,7 +11,7 @@ abstract class UndoRedoAction extends AbstractViewAction { private static final long serialVersionUID = 1L; - private String id; + private final String id; private PropertyChangeListener redoActionPropertyListener = new PropertyChangeListener() { @Override From 04f8be746e3a944caa00acaa8154db65be1947ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaes=20S=C3=B8rensen?= Date: Sat, 30 Dec 2023 17:55:58 +0100 Subject: [PATCH 62/71] Update UndoRedoAction.java Added correct modifier to getID() --- .../src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java index 8293a86cd..5d93cfb27 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java @@ -93,7 +93,7 @@ private Action getRealAction() { return (getActiveView() == null) ? null : getActiveView().getActionMap().get(getID(id)); } - static String getID(String id) { + protected static String getID(String id) { return id; } } From 7f2b078c1289ed1852a914fcb599b8812ccca110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaes=20S=C3=B8rensen?= Date: Mon, 1 Jan 2024 13:04:52 +0100 Subject: [PATCH 63/71] Update UndoRedoAction.java Removed faulty condition. --- .../java/org/jhotdraw/action/edit/UndoRedoAction.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java index 5d93cfb27..5dc78d2c3 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java @@ -17,8 +17,8 @@ abstract class UndoRedoAction extends AbstractViewAction { @Override public void propertyChange(PropertyChangeEvent evt) { String name = evt.getPropertyName(); - if ((name == null && AbstractAction.NAME == null) || (name != null && name.equals(AbstractAction.NAME))) { - putValue(AbstractAction.NAME, evt.getNewValue()); + if (name != null && name.equals(Action.NAME)) { + putValue(Action.NAME, evt.getNewValue()); } else if ("enabled".equals(name)) { updateEnabledState(); } @@ -51,8 +51,8 @@ protected void updateView(View oldValue, View newValue) { if (newValue != null && newValue.getActionMap().get(getID(id)) != null && newValue.getActionMap().get(getID(id)) != this) { - putValue(AbstractAction.NAME, newValue.getActionMap().get(getID(id)). - getValue(AbstractAction.NAME)); + putValue(Action.NAME, newValue.getActionMap().get(getID(id)). + getValue(Action.NAME)); updateEnabledState(); } } From 02e9a9c0ae1c179998db5b19c3b9cc040b374d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaes=20S=C3=B8rensen?= Date: Mon, 1 Jan 2024 17:24:34 +0100 Subject: [PATCH 64/71] Update PropertyChangeListener variable. It is now a lamda instead of an anonumous inner class and is transient and dinal. --- .../jhotdraw/action/edit/UndoRedoAction.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java index 5dc78d2c3..92baeee13 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java @@ -6,30 +6,26 @@ import javax.swing.*; import java.awt.event.ActionEvent; -import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; abstract class UndoRedoAction extends AbstractViewAction { private static final long serialVersionUID = 1L; private final String id; - private PropertyChangeListener redoActionPropertyListener = new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - String name = evt.getPropertyName(); - if (name != null && name.equals(Action.NAME)) { - putValue(Action.NAME, evt.getNewValue()); - } else if ("enabled".equals(name)) { - updateEnabledState(); - } + private final PropertyChangeListener redoActionPropertyListener = evt -> { + String name = evt.getPropertyName(); + if (name != null && name.equals(Action.NAME)) { + putValue(Action.NAME, evt.getNewValue()); + } else if ("enabled".equals(name)) { + updateEnabledState(); } }; /** * Creates a new instance which acts on the specified view of the application. * - * @param app - * @param view + * @param app application + * @param view view */ protected UndoRedoAction(Application app, View view, String id) { super(app, view); From 168d2295ac12b49a0536dc1bea43670104effb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaes=20S=C3=B8rensen?= Date: Tue, 2 Jan 2024 18:11:29 +0100 Subject: [PATCH 65/71] Baseline for testing --- .../org/jhotdraw/action/edit/UndoRedoAction.java | 2 +- .../undoredo/BDD/GivenAnActionHasBeenDone.java | 16 ++++++++++++++++ .../org/jhotdraw/samples/svg/undoredo/test.java | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/GivenAnActionHasBeenDone.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/test.java diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java index 92baeee13..112dd6f6e 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java @@ -12,7 +12,7 @@ abstract class UndoRedoAction extends AbstractViewAction { private static final long serialVersionUID = 1L; private final String id; - private final PropertyChangeListener redoActionPropertyListener = evt -> { + private final transient PropertyChangeListener redoActionPropertyListener = evt -> { String name = evt.getPropertyName(); if (name != null && name.equals(Action.NAME)) { putValue(Action.NAME, evt.getNewValue()); diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/GivenAnActionHasBeenDone.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/GivenAnActionHasBeenDone.java new file mode 100644 index 000000000..5bdf5a555 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/GivenAnActionHasBeenDone.java @@ -0,0 +1,16 @@ +package org.jhotdraw.samples.svg.undoredo.BDD; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.UndoAction; + +public class GivenAnActionHasBeenDone extends Stage { + + @ExpectedScenarioState + private UndoAction undoAction; + + public GivenAnActionHasBeenDone GivenTheUndoUIExists() { + undoAction = new UndoAction(new ); + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/test.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/test.java new file mode 100644 index 000000000..cfbd64630 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/test.java @@ -0,0 +1,4 @@ +package org.jhotdraw.samples.svg.undoredo; + +public class test { +} From 5dd406fe3d2ccf42f2c9b6877a2dc416a3da566d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaes=20S=C3=B8rensen?= Date: Wed, 3 Jan 2024 15:16:29 +0100 Subject: [PATCH 66/71] Tests added --- .../jhotdraw/action/edit/UndoRedoAction.java | 2 +- .../figures/GivenAnExistingRectangleTest.java | 1 - .../undoredo/BDD/UndoAndRedoTestSuite.java | 26 +++++++ .../constructor/redo/GivenAnRedoAction.java | 15 ++++ .../redo/GivenAnRedoActionTest.java | 13 ++++ .../BDD/constructor/redo/ThenExists.java | 22 ++++++ .../BDD/constructor/redo/WhenInitialized.java | 23 ++++++ .../undo/GivenAnUndoAction.java} | 7 +- .../undo/GivenAnUndoActionTest.java | 16 ++++ .../BDD/constructor/undo/ThenExists.java | 22 ++++++ .../BDD/constructor/undo/WhenInitialized.java | 23 ++++++ .../BDD/getid/redo/GetIDRedoTest.java | 13 ++++ .../BDD/getid/redo/GivenARedoAction.java | 26 +++++++ .../redo/ThenTheInsertedIDIsReturned.java | 36 +++++++++ .../BDD/getid/redo/WhenGetIDIsCalled.java | 30 ++++++++ .../BDD/getid/undo/GetIDUndoTest.java | 13 ++++ .../BDD/getid/undo/GivenARedoAction.java | 27 +++++++ .../undo/ThenTheInsertedIDIsReturned.java | 36 +++++++++ .../BDD/getid/undo/WhenGetIDIsCalled.java | 29 +++++++ .../redo/GivenRedoState.java | 29 +++++++ .../redo/RedoStateTest.java | 27 +++++++ .../redo/ThenEnabledState.java | 22 ++++++ .../redo/WhenStateUpdated.java | 77 +++++++++++++++++++ .../undo/GivenUndoState.java | 28 +++++++ .../undo/ThenEnabledState.java | 23 ++++++ .../undo/UndoStateTest.java | 27 +++++++ .../undo/WhenStateUpdated.java | 77 +++++++++++++++++++ .../BDD/updateview/redo/GivenAView.java | 29 +++++++ .../updateview/redo/ThenViewIsUpdated.java | 29 +++++++ .../redo/UpdateRedoUpdateViewTest.java | 20 +++++ .../updateview/redo/WhenViewIsUpdated.java | 55 +++++++++++++ .../BDD/updateview/undo/GivenAView.java | 30 ++++++++ .../updateview/undo/ThenViewIsUpdated.java | 31 ++++++++ .../undo/UpdateUndoUpdateViewTest.java | 20 +++++ .../updateview/undo/WhenViewIsUpdated.java | 56 ++++++++++++++ .../jhotdraw/samples/svg/undoredo/test.java | 4 - 36 files changed, 954 insertions(+), 10 deletions(-) create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/UndoAndRedoTestSuite.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/GivenAnRedoAction.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/GivenAnRedoActionTest.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/ThenExists.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/WhenInitialized.java rename jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/{GivenAnActionHasBeenDone.java => constructor/undo/GivenAnUndoAction.java} (50%) create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/GivenAnUndoActionTest.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/ThenExists.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/WhenInitialized.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/GetIDRedoTest.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/GivenARedoAction.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/ThenTheInsertedIDIsReturned.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/WhenGetIDIsCalled.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/GetIDUndoTest.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/GivenARedoAction.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/ThenTheInsertedIDIsReturned.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/WhenGetIDIsCalled.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/GivenRedoState.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/RedoStateTest.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/ThenEnabledState.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/WhenStateUpdated.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/GivenUndoState.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/ThenEnabledState.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/UndoStateTest.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/WhenStateUpdated.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/GivenAView.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/ThenViewIsUpdated.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/UpdateRedoUpdateViewTest.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/WhenViewIsUpdated.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/GivenAView.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/ThenViewIsUpdated.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/UpdateUndoUpdateViewTest.java create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/WhenViewIsUpdated.java delete mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/test.java diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java index 112dd6f6e..24f0414d0 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoRedoAction.java @@ -86,7 +86,7 @@ public void actionPerformed(ActionEvent e) { } private Action getRealAction() { - return (getActiveView() == null) ? null : getActiveView().getActionMap().get(getID(id)); + return (getActiveView() == null) ? null : getActiveView().getActionMap().get(id); } protected static String getID(String id) { diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/GivenAnExistingRectangleTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/GivenAnExistingRectangleTest.java index 83f037864..5ffd92223 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/GivenAnExistingRectangleTest.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/figures/GivenAnExistingRectangleTest.java @@ -14,7 +14,6 @@ public void testScenario(){ when().whenUserSelectsRectangleCorner(); when().whenMouseIsMoved(); then().thenResize(); - } } \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/UndoAndRedoTestSuite.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/UndoAndRedoTestSuite.java new file mode 100644 index 000000000..b80d60517 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/UndoAndRedoTestSuite.java @@ -0,0 +1,26 @@ +package org.jhotdraw.samples.svg.undoredo.BDD; + +import org.jhotdraw.samples.svg.undoredo.BDD.constructor.redo.GivenAnRedoActionTest; +import org.jhotdraw.samples.svg.undoredo.BDD.constructor.undo.GivenAnUndoActionTest; +import org.jhotdraw.samples.svg.undoredo.BDD.getid.redo.GetIDRedoTest; +import org.jhotdraw.samples.svg.undoredo.BDD.getid.undo.GetIDUndoTest; +import org.jhotdraw.samples.svg.undoredo.BDD.updateenabledstate.redo.RedoStateTest; +import org.jhotdraw.samples.svg.undoredo.BDD.updateenabledstate.undo.UndoStateTest; +import org.jhotdraw.samples.svg.undoredo.BDD.updateview.redo.UpdateRedoUpdateViewTest; +import org.jhotdraw.samples.svg.undoredo.BDD.updateview.undo.UpdateUndoUpdateViewTest; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + GivenAnRedoActionTest.class, + GivenAnUndoActionTest.class, + RedoStateTest.class, + UndoStateTest.class, + UpdateRedoUpdateViewTest.class, + UpdateUndoUpdateViewTest.class, + GetIDRedoTest.class, + GetIDUndoTest.class +}) +public class UndoAndRedoTestSuite { +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/GivenAnRedoAction.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/GivenAnRedoAction.java new file mode 100644 index 000000000..28b720830 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/GivenAnRedoAction.java @@ -0,0 +1,15 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.constructor.redo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; + +public class GivenAnRedoAction extends Stage { + + @ExpectedScenarioState + private RedoAction redoAction; + + public GivenAnRedoAction givenAnAction() { + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/GivenAnRedoActionTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/GivenAnRedoActionTest.java new file mode 100644 index 000000000..7082f9813 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/GivenAnRedoActionTest.java @@ -0,0 +1,13 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.constructor.redo; + +import com.tngtech.jgiven.junit.ScenarioTest; +import org.junit.Test; + +public class GivenAnRedoActionTest extends ScenarioTest { + @Test + public void testScenario(){ + given().givenAnAction(); + when().whenInitialized(); + then().thenExists(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/ThenExists.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/ThenExists.java new file mode 100644 index 000000000..b64c745bb --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/ThenExists.java @@ -0,0 +1,22 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.constructor.redo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; + +import static org.junit.Assert.*; + +public class ThenExists extends Stage { + @ExpectedScenarioState + private RedoAction redoAction; + + public ThenExists thenExists() { + // Not null: + assertNotNull("The redoAction is null.", redoAction); + + // Check ID: + assertEquals("The id is '" + redoAction.ID + "', not 'edit.redo'.", "edit.redo", "" + redoAction.ID); + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/WhenInitialized.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/WhenInitialized.java new file mode 100644 index 000000000..3c94687e6 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/redo/WhenInitialized.java @@ -0,0 +1,23 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.constructor.redo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; +import org.jhotdraw.api.app.Application; +import org.jhotdraw.api.app.View; +import org.mockito.Mockito; + +public class WhenInitialized extends Stage { + @ExpectedScenarioState + private RedoAction redoAction; + private Application app; + private View view; + + public WhenInitialized whenInitialized() { + // Initialize the undo action + app = Mockito.mock(Application.class); + view = Mockito.mock(View.class); + redoAction = new RedoAction(app, view); + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/GivenAnActionHasBeenDone.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/GivenAnUndoAction.java similarity index 50% rename from jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/GivenAnActionHasBeenDone.java rename to jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/GivenAnUndoAction.java index 5bdf5a555..976599258 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/GivenAnActionHasBeenDone.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/GivenAnUndoAction.java @@ -1,16 +1,15 @@ -package org.jhotdraw.samples.svg.undoredo.BDD; +package org.jhotdraw.samples.svg.undoredo.BDD.constructor.undo; import com.tngtech.jgiven.Stage; import com.tngtech.jgiven.annotation.ExpectedScenarioState; import org.jhotdraw.action.edit.UndoAction; -public class GivenAnActionHasBeenDone extends Stage { +public class GivenAnUndoAction extends Stage { @ExpectedScenarioState private UndoAction undoAction; - public GivenAnActionHasBeenDone GivenTheUndoUIExists() { - undoAction = new UndoAction(new ); + public GivenAnUndoAction givenAnAction() { return self(); } } diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/GivenAnUndoActionTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/GivenAnUndoActionTest.java new file mode 100644 index 000000000..301a28ad0 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/GivenAnUndoActionTest.java @@ -0,0 +1,16 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.constructor.undo; + +import com.tngtech.jgiven.junit.ScenarioTest; +import org.jhotdraw.samples.svg.undoredo.BDD.constructor.redo.GivenAnRedoAction; +import org.jhotdraw.samples.svg.undoredo.BDD.constructor.redo.ThenExists; +import org.jhotdraw.samples.svg.undoredo.BDD.constructor.redo.WhenInitialized; +import org.junit.Test; + +public class GivenAnUndoActionTest extends ScenarioTest { + @Test + public void testScenario(){ + given().givenAnAction(); + when().whenInitialized(); + then().thenExists(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/ThenExists.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/ThenExists.java new file mode 100644 index 000000000..185e6c540 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/ThenExists.java @@ -0,0 +1,22 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.constructor.undo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.UndoAction; + +import static org.junit.Assert.*; + +public class ThenExists extends Stage { + @ExpectedScenarioState + private UndoAction undoAction; + + public ThenExists thenExists() { + // Not null: + assertNotNull("The undoAction is null.", undoAction); + + // Check ID: + assertEquals("The id is '" + undoAction.ID + "', not 'edit.undo'.", "edit.undo", "" + undoAction.ID); + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/WhenInitialized.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/WhenInitialized.java new file mode 100644 index 000000000..2aba09a34 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/WhenInitialized.java @@ -0,0 +1,23 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.constructor.undo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.UndoAction; +import org.jhotdraw.api.app.Application; +import org.jhotdraw.api.app.View; +import org.mockito.Mockito; + +public class WhenInitialized extends Stage { + @ExpectedScenarioState + private UndoAction undoAction; + private Application app; + private View view; + + public WhenInitialized whenInitialized() { + // Initialize the undo action + app = Mockito.mock(Application.class); + view = Mockito.mock(View.class); + undoAction = new UndoAction(app, view); + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/GetIDRedoTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/GetIDRedoTest.java new file mode 100644 index 000000000..8a4357d24 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/GetIDRedoTest.java @@ -0,0 +1,13 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.getid.redo; + +import com.tngtech.jgiven.junit.ScenarioTest; +import org.junit.Test; + +public class GetIDRedoTest extends ScenarioTest { + @Test + public void testScenario1() { + given().aRedoAction(); + when().whenGetIDIsCalled(); + then().thenTheInsertedIDIsReturned(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/GivenARedoAction.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/GivenARedoAction.java new file mode 100644 index 000000000..49d9d87fa --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/GivenARedoAction.java @@ -0,0 +1,26 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.getid.redo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; +import org.jhotdraw.api.app.Application; +import org.jhotdraw.api.app.View; +import org.mockito.Mockito; + +public class GivenARedoAction extends Stage { + + @ExpectedScenarioState + private RedoAction redoAction; + private Application app; + private View view; + + + public GivenARedoAction aRedoAction() { + app = Mockito.mock(Application.class); + view = Mockito.mock(View.class); + + redoAction = new RedoAction(app, view); + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/ThenTheInsertedIDIsReturned.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/ThenTheInsertedIDIsReturned.java new file mode 100644 index 000000000..1ba18cb22 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/ThenTheInsertedIDIsReturned.java @@ -0,0 +1,36 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.getid.redo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; +import org.jhotdraw.api.app.View; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +public class ThenTheInsertedIDIsReturned extends Stage { + @ExpectedScenarioState + private RedoAction redoAction; + + public ThenTheInsertedIDIsReturned thenTheInsertedIDIsReturned() { + try { + Method method = RedoAction.class.getDeclaredMethod("getID"); + method.setAccessible(true); + method.invoke(redoAction, "edit.undo"); + + assertEquals("Edit.redo", method.invoke(redoAction, "edit.redo") + ""); + assertNotEquals("Edit.redo", method.invoke(redoAction, "edit.undo") + ""); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/WhenGetIDIsCalled.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/WhenGetIDIsCalled.java new file mode 100644 index 000000000..467242186 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/WhenGetIDIsCalled.java @@ -0,0 +1,30 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.getid.redo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; +import org.jhotdraw.api.app.View; +import org.mockito.Mockito; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class WhenGetIDIsCalled extends Stage { + @ExpectedScenarioState + private RedoAction redoAction; + public WhenGetIDIsCalled whenGetIDIsCalled() { + try { + Method method = RedoAction.class.getDeclaredMethod("getID"); + method.setAccessible(true); + method.invoke(redoAction, "edit.redo"); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/GetIDUndoTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/GetIDUndoTest.java new file mode 100644 index 000000000..490789b56 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/GetIDUndoTest.java @@ -0,0 +1,13 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.getid.undo; + +import com.tngtech.jgiven.junit.ScenarioTest; +import org.junit.Test; + +public class GetIDUndoTest extends ScenarioTest { + @Test + public void testScenario1() { + given().aUndoAction(); + when().whenGetIDIsCalled(); + then().thenTheInsertedIDIsReturned(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/GivenARedoAction.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/GivenARedoAction.java new file mode 100644 index 000000000..a14233e71 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/GivenARedoAction.java @@ -0,0 +1,27 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.getid.undo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; +import org.jhotdraw.action.edit.UndoAction; +import org.jhotdraw.api.app.Application; +import org.jhotdraw.api.app.View; +import org.mockito.Mockito; + +public class GivenARedoAction extends Stage { + + @ExpectedScenarioState + private UndoAction undoAction; + private Application app; + private View view; + + + public GivenARedoAction aUndoAction() { + app = Mockito.mock(Application.class); + view = Mockito.mock(View.class); + + undoAction = new UndoAction(app, view); + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/ThenTheInsertedIDIsReturned.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/ThenTheInsertedIDIsReturned.java new file mode 100644 index 000000000..a5654cf17 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/ThenTheInsertedIDIsReturned.java @@ -0,0 +1,36 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.getid.undo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; +import org.jhotdraw.action.edit.UndoAction; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +public class ThenTheInsertedIDIsReturned extends Stage { + @ExpectedScenarioState + private UndoAction undoAction; + + public ThenTheInsertedIDIsReturned thenTheInsertedIDIsReturned() { + try { + Method method = RedoAction.class.getDeclaredMethod("getID"); + method.setAccessible(true); + method.invoke(undoAction, "edit.undo"); + + assertEquals("Edit.undo", method.invoke(undoAction, "edit.undo") + ""); + assertNotEquals("Edit.undo", method.invoke(undoAction, "edit.redo") + ""); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/WhenGetIDIsCalled.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/WhenGetIDIsCalled.java new file mode 100644 index 000000000..9268ee6b2 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/WhenGetIDIsCalled.java @@ -0,0 +1,29 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.getid.undo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; +import org.jhotdraw.action.edit.UndoAction; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class WhenGetIDIsCalled extends Stage { + @ExpectedScenarioState + private UndoAction undoAction; + public WhenGetIDIsCalled whenGetIDIsCalled() { + try { + Method method = UndoAction.class.getDeclaredMethod("getID"); + method.setAccessible(true); + method.invoke(undoAction, "edit.undo"); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/GivenRedoState.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/GivenRedoState.java new file mode 100644 index 000000000..31b898476 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/GivenRedoState.java @@ -0,0 +1,29 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateenabledstate.redo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; +import org.jhotdraw.action.edit.UndoAction; +import org.jhotdraw.api.app.Application; +import org.jhotdraw.api.app.View; +import org.mockito.Mockito; + +public class GivenRedoState extends Stage { + + @ExpectedScenarioState + private RedoAction redoAction; + + private Application app; + private View view; + + public GivenRedoState anRedoAction() { + app = Mockito.mock(Application.class); + view = Mockito.mock(View.class); + + redoAction = new RedoAction(app, view); + redoAction.getActiveView().getActionMap().put(redoAction.ID, redoAction); + redoAction.getActiveView().getActionMap().put("edit.undo", new UndoAction(app, view)); + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/RedoStateTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/RedoStateTest.java new file mode 100644 index 000000000..a77684cf5 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/RedoStateTest.java @@ -0,0 +1,27 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateenabledstate.redo; + +import com.tngtech.jgiven.junit.ScenarioTest; +import org.junit.Test; + +public class RedoStateTest extends ScenarioTest { + @Test + public void testScenario1() { + given().anRedoAction(); + when().actionIsNull(); + then().isFalse(); + } + + @Test + public void testScenario2() { + given().anRedoAction(); + when().actionIsThis(); + then().isFalse(); + } + + @Test + public void testScenario3() { + given().anRedoAction(); + when().actionIsOther(); + then().isTrue(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/ThenEnabledState.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/ThenEnabledState.java new file mode 100644 index 000000000..d10ec95ee --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/ThenEnabledState.java @@ -0,0 +1,22 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateenabledstate.redo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; + +import static org.junit.Assert.*; + +public class ThenEnabledState extends Stage { + @ExpectedScenarioState + private RedoAction redoAction; + + public ThenEnabledState isTrue() { + assertTrue("Enabled state is '" + redoAction.isEnabled() + "'." , redoAction.isEnabled()); + return self(); + } + + public ThenEnabledState isFalse() { + assertFalse("Enabled state is '" + redoAction.isEnabled() + "'.", redoAction.isEnabled()); + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/WhenStateUpdated.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/WhenStateUpdated.java new file mode 100644 index 000000000..b72eb3d54 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/redo/WhenStateUpdated.java @@ -0,0 +1,77 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateenabledstate.redo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; + +import javax.swing.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class WhenStateUpdated extends Stage { + @ExpectedScenarioState + private RedoAction redoAction; + @ExpectedScenarioState + private Action realAction; + + public WhenStateUpdated actionIsNull() { + try { + + Method method2 = RedoAction.class.getDeclaredMethod("updateView"); + method2.setAccessible(true); + method2.invoke(redoAction, redoAction.getActiveView(), null); + + Method method1 = RedoAction.class.getDeclaredMethod("updateEnabledState"); + method1.setAccessible(true); + method1.invoke(redoAction); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + return self(); + } + + public WhenStateUpdated actionIsThis() { + try { + Method method2 = RedoAction.class.getDeclaredMethod("updateView"); + method2.setAccessible(true); + method2.invoke(redoAction, redoAction.getActiveView(), redoAction.getActiveView()); + + Method method = RedoAction.class.getDeclaredMethod("updateEnabledState"); + method.setAccessible(true); + method.invoke(redoAction); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + return self(); + } + + public WhenStateUpdated actionIsOther() { + try { + Method method2 = RedoAction.class.getDeclaredMethod("updateView"); + method2.setAccessible(true); + method2.invoke(redoAction, redoAction.getActiveView(), redoAction.getActiveView().getActionMap().get("edit.undo")); + + Method method = RedoAction.class.getDeclaredMethod("updateEnabledState"); + method.setAccessible(true); + method.invoke(redoAction); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/GivenUndoState.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/GivenUndoState.java new file mode 100644 index 000000000..ceea5f909 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/GivenUndoState.java @@ -0,0 +1,28 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateenabledstate.undo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.UndoAction; +import org.jhotdraw.api.app.Application; +import org.jhotdraw.api.app.View; +import org.mockito.Mockito; + +public class GivenUndoState extends Stage { + + @ExpectedScenarioState + private UndoAction undoAction; + + private Application app; + private View view; + + public GivenUndoState anUndoAction() { + app = Mockito.mock(Application.class); + view = Mockito.mock(View.class); + + undoAction = new UndoAction(app, view); + undoAction.getActiveView().getActionMap().put(undoAction.ID, undoAction); + undoAction.getActiveView().getActionMap().put("edit.undo", new UndoAction(app, view)); + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/ThenEnabledState.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/ThenEnabledState.java new file mode 100644 index 000000000..03fd6cfa3 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/ThenEnabledState.java @@ -0,0 +1,23 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateenabledstate.undo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.UndoAction; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class ThenEnabledState extends Stage { + @ExpectedScenarioState + private UndoAction undoAction; + + public ThenEnabledState isTrue() { + assertTrue("Enabled state is '" + undoAction.isEnabled() + "'." , undoAction.isEnabled()); + return self(); + } + + public ThenEnabledState isFalse() { + assertFalse("Enabled state is '" + undoAction.isEnabled() + "'.", undoAction.isEnabled()); + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/UndoStateTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/UndoStateTest.java new file mode 100644 index 000000000..117ff6722 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/UndoStateTest.java @@ -0,0 +1,27 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateenabledstate.undo; + +import com.tngtech.jgiven.junit.ScenarioTest; +import org.junit.Test; + +public class UndoStateTest extends ScenarioTest { + @Test + public void testScenario1() { + given().anUndoAction(); + when().actionIsNull(); + then().isFalse(); + } + + @Test + public void testScenario2() { + given().anUndoAction(); + when().actionIsThis(); + then().isFalse(); + } + + @Test + public void testScenario3() { + given().anUndoAction(); + when().actionIsOther(); + then().isTrue(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/WhenStateUpdated.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/WhenStateUpdated.java new file mode 100644 index 000000000..25eadeee5 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateenabledstate/undo/WhenStateUpdated.java @@ -0,0 +1,77 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateenabledstate.undo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.UndoAction; + +import javax.swing.*; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class WhenStateUpdated extends Stage { + @ExpectedScenarioState + private UndoAction undoAction; + @ExpectedScenarioState + private Action realAction; + + public WhenStateUpdated actionIsNull() { + try { + + Method method2 = UndoAction.class.getDeclaredMethod("updateView"); + method2.setAccessible(true); + method2.invoke(undoAction, undoAction.getActiveView(), null); + + Method method1 = UndoAction.class.getDeclaredMethod("updateEnabledState"); + method1.setAccessible(true); + method1.invoke(undoAction); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + return self(); + } + + public WhenStateUpdated actionIsThis() { + try { + Method method2 = UndoAction.class.getDeclaredMethod("updateView"); + method2.setAccessible(true); + method2.invoke(undoAction, undoAction.getActiveView(), undoAction.getActiveView()); + + Method method = UndoAction.class.getDeclaredMethod("updateEnabledState"); + method.setAccessible(true); + method.invoke(undoAction); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + return self(); + } + + public WhenStateUpdated actionIsOther() { + try { + Method method2 = UndoAction.class.getDeclaredMethod("updateView"); + method2.setAccessible(true); + method2.invoke(undoAction, undoAction.getActiveView(), undoAction.getActiveView().getActionMap().get("edit.undo")); + + Method method = UndoAction.class.getDeclaredMethod("updateEnabledState"); + method.setAccessible(true); + method.invoke(undoAction); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/GivenAView.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/GivenAView.java new file mode 100644 index 000000000..5de88bd4f --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/GivenAView.java @@ -0,0 +1,29 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateview.redo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; +import org.jhotdraw.api.app.Application; +import org.jhotdraw.api.app.View; +import org.mockito.Mockito; + +public class GivenAView extends Stage { + + @ExpectedScenarioState + private RedoAction redoAction; + @ExpectedScenarioState + private View viewOld; + @ExpectedScenarioState + private View viewNew; + private Application app; + + + public GivenAView aView() { + app = Mockito.mock(Application.class); + viewOld = Mockito.mock(View.class); + + redoAction = new RedoAction(app, viewOld); + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/ThenViewIsUpdated.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/ThenViewIsUpdated.java new file mode 100644 index 000000000..4a6bb95a5 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/ThenViewIsUpdated.java @@ -0,0 +1,29 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateview.redo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; +import org.jhotdraw.api.app.View; + +import static org.junit.Assert.*; + +public class ThenViewIsUpdated extends Stage { + @ExpectedScenarioState + private RedoAction redoAction; + @ExpectedScenarioState + private View viewOld; + @ExpectedScenarioState + private View viewNew; + + public ThenViewIsUpdated isNew() { + assertEquals(redoAction.getActiveView(), viewNew); + assertNotEquals(redoAction.getActiveView(), viewOld); + return self(); + } + + public ThenViewIsUpdated isOld() { + assertEquals(redoAction.getActiveView(), viewOld); + assertNotEquals(redoAction.getActiveView(), viewNew); + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/UpdateRedoUpdateViewTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/UpdateRedoUpdateViewTest.java new file mode 100644 index 000000000..4a2998ae4 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/UpdateRedoUpdateViewTest.java @@ -0,0 +1,20 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateview.redo; + +import com.tngtech.jgiven.junit.ScenarioTest; +import org.junit.Test; + +public class UpdateRedoUpdateViewTest extends ScenarioTest { + @Test + public void testScenario1() { + given().aView(); + when().whenViewIsUpdatedNew(); + then().isNew(); + } + + @Test + public void testScenario2() { + given().aView(); + when().whenViewIsUpdatedOld(); + then().isOld(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/WhenViewIsUpdated.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/WhenViewIsUpdated.java new file mode 100644 index 000000000..ff886362d --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/redo/WhenViewIsUpdated.java @@ -0,0 +1,55 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateview.redo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; +import org.jhotdraw.api.app.View; +import org.mockito.Mockito; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class WhenViewIsUpdated extends Stage { + @ExpectedScenarioState + private RedoAction redoAction; + @ExpectedScenarioState + private View viewOld; + @ExpectedScenarioState + private View viewNew; + + public WhenViewIsUpdated whenViewIsUpdatedNew() { + try { + Method method = RedoAction.class.getDeclaredMethod("updateView"); + method.setAccessible(true); + + viewNew = Mockito.mock(View.class); + method.invoke(redoAction, viewOld, viewNew); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + + return self(); + } + + public WhenViewIsUpdated whenViewIsUpdatedOld() { + try { + Method method = RedoAction.class.getDeclaredMethod("updateView"); + method.setAccessible(true); + + viewNew = Mockito.mock(View.class); + method.invoke(redoAction, viewOld, viewOld); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/GivenAView.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/GivenAView.java new file mode 100644 index 000000000..b3251bdc9 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/GivenAView.java @@ -0,0 +1,30 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateview.undo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; +import org.jhotdraw.action.edit.UndoAction; +import org.jhotdraw.api.app.Application; +import org.jhotdraw.api.app.View; +import org.mockito.Mockito; + +public class GivenAView extends Stage { + + @ExpectedScenarioState + private UndoAction undoAction; + @ExpectedScenarioState + private View viewOld; + @ExpectedScenarioState + private View viewNew; + private Application app; + + + public GivenAView aView() { + app = Mockito.mock(Application.class); + viewOld = Mockito.mock(View.class); + + undoAction = new UndoAction(app, viewOld); + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/ThenViewIsUpdated.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/ThenViewIsUpdated.java new file mode 100644 index 000000000..9e215a7a6 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/ThenViewIsUpdated.java @@ -0,0 +1,31 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateview.undo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; +import org.jhotdraw.action.edit.UndoAction; +import org.jhotdraw.api.app.View; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +public class ThenViewIsUpdated extends Stage { + @ExpectedScenarioState + private UndoAction undoAction; + @ExpectedScenarioState + private View viewOld; + @ExpectedScenarioState + private View viewNew; + + public ThenViewIsUpdated isNew() { + assertEquals(undoAction.getActiveView(), viewNew); + assertNotEquals(undoAction.getActiveView(), viewOld); + return self(); + } + + public ThenViewIsUpdated isOld() { + assertEquals(undoAction.getActiveView(), viewOld); + assertNotEquals(undoAction.getActiveView(), viewNew); + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/UpdateUndoUpdateViewTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/UpdateUndoUpdateViewTest.java new file mode 100644 index 000000000..b3f06618b --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/UpdateUndoUpdateViewTest.java @@ -0,0 +1,20 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateview.undo; + +import com.tngtech.jgiven.junit.ScenarioTest; +import org.junit.Test; + +public class UpdateUndoUpdateViewTest extends ScenarioTest { + @Test + public void testScenario1() { + given().aView(); + when().whenViewIsUpdatedNew(); + then().isNew(); + } + + @Test + public void testScenario2() { + given().aView(); + when().whenViewIsUpdatedOld(); + then().isOld(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/WhenViewIsUpdated.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/WhenViewIsUpdated.java new file mode 100644 index 000000000..e2a2714a7 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/WhenViewIsUpdated.java @@ -0,0 +1,56 @@ +package org.jhotdraw.samples.svg.undoredo.BDD.updateview.undo; + +import com.tngtech.jgiven.Stage; +import com.tngtech.jgiven.annotation.ExpectedScenarioState; +import org.jhotdraw.action.edit.RedoAction; +import org.jhotdraw.action.edit.UndoAction; +import org.jhotdraw.api.app.View; +import org.mockito.Mockito; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class WhenViewIsUpdated extends Stage { + @ExpectedScenarioState + private UndoAction undoAction; + @ExpectedScenarioState + private View viewOld; + @ExpectedScenarioState + private View viewNew; + + public WhenViewIsUpdated whenViewIsUpdatedNew() { + try { + Method method = RedoAction.class.getDeclaredMethod("updateView"); + method.setAccessible(true); + + viewNew = Mockito.mock(View.class); + method.invoke(undoAction, viewOld, viewNew); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + + return self(); + } + + public WhenViewIsUpdated whenViewIsUpdatedOld() { + try { + Method method = RedoAction.class.getDeclaredMethod("updateView"); + method.setAccessible(true); + + viewNew = Mockito.mock(View.class); + method.invoke(undoAction, viewOld, viewOld); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + + return self(); + } +} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/test.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/test.java deleted file mode 100644 index cfbd64630..000000000 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/test.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.jhotdraw.samples.svg.undoredo; - -public class test { -} From 90872de749dbd96ef831bc5aa0f6f710563d1bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaes=20S=C3=B8rensen?= Date: Wed, 3 Jan 2024 17:22:27 +0100 Subject: [PATCH 67/71] Removed feature entrypoints --- .../src/main/java/org/jhotdraw/action/edit/RedoAction.java | 3 --- .../src/main/java/org/jhotdraw/action/edit/UndoAction.java | 2 -- .../src/main/java/org/jhotdraw/undo/UndoRedoManager.java | 7 ------- 3 files changed, 12 deletions(-) diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java index 87824453f..73e743926 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java @@ -6,8 +6,6 @@ * accompanying license terms. */ package org.jhotdraw.action.edit; - -import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.api.app.Application; import org.jhotdraw.api.app.View; import org.jhotdraw.util.*; @@ -34,7 +32,6 @@ public class RedoAction extends UndoRedoAction { /** * Creates a new instance. */ - @FeatureEntryPoint(value = "RedoAction") public RedoAction(Application app, View view) { super(app, view, ID); ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels"); diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java index aba44b16e..b3f95e177 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java @@ -9,7 +9,6 @@ import org.jhotdraw.api.app.Application; import org.jhotdraw.api.app.View; import org.jhotdraw.util.*; -import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; /** * Undoes the last user action. @@ -33,7 +32,6 @@ public class UndoAction extends UndoRedoAction { /** * Creates a new instance. */ - @FeatureEntryPoint(value = "UndoAction") public UndoAction(Application app, View view) { super(app, view, ID); ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.action.Labels"); diff --git a/jhotdraw-utils/src/main/java/org/jhotdraw/undo/UndoRedoManager.java b/jhotdraw-utils/src/main/java/org/jhotdraw/undo/UndoRedoManager.java index f67110b78..f7b997d6e 100644 --- a/jhotdraw-utils/src/main/java/org/jhotdraw/undo/UndoRedoManager.java +++ b/jhotdraw-utils/src/main/java/org/jhotdraw/undo/UndoRedoManager.java @@ -12,8 +12,6 @@ import java.util.*; import javax.swing.*; import javax.swing.undo.*; - -import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.util.*; /** @@ -71,8 +69,6 @@ private class UndoAction extends AbstractAction { private static final long serialVersionUID = 1L; - - @FeatureEntryPoint(value = "UndoRedoManager_UndoAction") public UndoAction() { labels.configureAction(this, "edit.undo"); setEnabled(false); @@ -99,8 +95,6 @@ private class RedoAction extends AbstractAction { private static final long serialVersionUID = 1L; - - @FeatureEntryPoint(value = "UndoRedoManager_RedoAction") public RedoAction() { labels.configureAction(this, "edit.redo"); setEnabled(false); @@ -137,7 +131,6 @@ public static ResourceBundleUtil getLabels() { /** * Creates new UndoRedoManager */ - @FeatureEntryPoint(value = "UndoRedoManager") public UndoRedoManager() { getLabels(); undoAction = new UndoAction(); From 34ecbbdd8ee31d3b7dd57147450d0e53d9d15104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaes=20S=C3=B8rensen?= Date: Wed, 3 Jan 2024 17:37:33 +0100 Subject: [PATCH 68/71] Updated enums --- .../src/main/java/org/jhotdraw/action/edit/ActionIDs.java | 4 ++-- .../src/main/java/org/jhotdraw/action/edit/RedoAction.java | 2 +- .../src/main/java/org/jhotdraw/action/edit/UndoAction.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/ActionIDs.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/ActionIDs.java index 1ae50a153..ec4dd7ea0 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/ActionIDs.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/ActionIDs.java @@ -1,6 +1,6 @@ package org.jhotdraw.action.edit; enum ActionIDs {; - static final String undoID = "edit.undo"; - static final String redoID = "edit.redo"; + static final String UNDOID = "edit.undo"; + static final String REDOID = "edit.redo"; } diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java index 73e743926..a9b7c719b 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/RedoAction.java @@ -27,7 +27,7 @@ * @version $Id$ */ public class RedoAction extends UndoRedoAction { - public static final String ID = getID(ActionIDs.redoID); + public static final String ID = getID(ActionIDs.REDOID); /** * Creates a new instance. diff --git a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java index b3f95e177..3e8f09573 100644 --- a/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java +++ b/jhotdraw-actions/src/main/java/org/jhotdraw/action/edit/UndoAction.java @@ -27,7 +27,7 @@ * @version $Id$ */ public class UndoAction extends UndoRedoAction { - public static final String ID = getID(ActionIDs.undoID); + public static final String ID = getID(ActionIDs.UNDOID); /** * Creates a new instance. From 707fb5aa6e543fd3ae5f74cdc513bf2f45a74494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klaes=20S=C3=B8rensen?= Date: Wed, 3 Jan 2024 17:43:13 +0100 Subject: [PATCH 69/71] Removed unused imports --- .../undoredo/BDD/constructor/undo/GivenAnUndoActionTest.java | 1 - .../undoredo/BDD/getid/redo/ThenTheInsertedIDIsReturned.java | 1 - .../samples/svg/undoredo/BDD/getid/redo/WhenGetIDIsCalled.java | 2 -- .../samples/svg/undoredo/BDD/getid/undo/GivenARedoAction.java | 1 - .../samples/svg/undoredo/BDD/getid/undo/WhenGetIDIsCalled.java | 1 - .../samples/svg/undoredo/BDD/updateview/undo/GivenAView.java | 1 - .../svg/undoredo/BDD/updateview/undo/ThenViewIsUpdated.java | 1 - 7 files changed, 8 deletions(-) diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/GivenAnUndoActionTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/GivenAnUndoActionTest.java index 301a28ad0..6f0bca14b 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/GivenAnUndoActionTest.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/constructor/undo/GivenAnUndoActionTest.java @@ -1,7 +1,6 @@ package org.jhotdraw.samples.svg.undoredo.BDD.constructor.undo; import com.tngtech.jgiven.junit.ScenarioTest; -import org.jhotdraw.samples.svg.undoredo.BDD.constructor.redo.GivenAnRedoAction; import org.jhotdraw.samples.svg.undoredo.BDD.constructor.redo.ThenExists; import org.jhotdraw.samples.svg.undoredo.BDD.constructor.redo.WhenInitialized; import org.junit.Test; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/ThenTheInsertedIDIsReturned.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/ThenTheInsertedIDIsReturned.java index 1ba18cb22..5d8f21c4c 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/ThenTheInsertedIDIsReturned.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/ThenTheInsertedIDIsReturned.java @@ -3,7 +3,6 @@ import com.tngtech.jgiven.Stage; import com.tngtech.jgiven.annotation.ExpectedScenarioState; import org.jhotdraw.action.edit.RedoAction; -import org.jhotdraw.api.app.View; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/WhenGetIDIsCalled.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/WhenGetIDIsCalled.java index 467242186..0c4baf441 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/WhenGetIDIsCalled.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/redo/WhenGetIDIsCalled.java @@ -3,8 +3,6 @@ import com.tngtech.jgiven.Stage; import com.tngtech.jgiven.annotation.ExpectedScenarioState; import org.jhotdraw.action.edit.RedoAction; -import org.jhotdraw.api.app.View; -import org.mockito.Mockito; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/GivenARedoAction.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/GivenARedoAction.java index a14233e71..089a1f3f9 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/GivenARedoAction.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/GivenARedoAction.java @@ -2,7 +2,6 @@ import com.tngtech.jgiven.Stage; import com.tngtech.jgiven.annotation.ExpectedScenarioState; -import org.jhotdraw.action.edit.RedoAction; import org.jhotdraw.action.edit.UndoAction; import org.jhotdraw.api.app.Application; import org.jhotdraw.api.app.View; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/WhenGetIDIsCalled.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/WhenGetIDIsCalled.java index 9268ee6b2..3818a3625 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/WhenGetIDIsCalled.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/getid/undo/WhenGetIDIsCalled.java @@ -2,7 +2,6 @@ import com.tngtech.jgiven.Stage; import com.tngtech.jgiven.annotation.ExpectedScenarioState; -import org.jhotdraw.action.edit.RedoAction; import org.jhotdraw.action.edit.UndoAction; import java.lang.reflect.InvocationTargetException; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/GivenAView.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/GivenAView.java index b3251bdc9..eb1ceb576 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/GivenAView.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/GivenAView.java @@ -2,7 +2,6 @@ import com.tngtech.jgiven.Stage; import com.tngtech.jgiven.annotation.ExpectedScenarioState; -import org.jhotdraw.action.edit.RedoAction; import org.jhotdraw.action.edit.UndoAction; import org.jhotdraw.api.app.Application; import org.jhotdraw.api.app.View; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/ThenViewIsUpdated.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/ThenViewIsUpdated.java index 9e215a7a6..efb47bc9c 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/ThenViewIsUpdated.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/undoredo/BDD/updateview/undo/ThenViewIsUpdated.java @@ -2,7 +2,6 @@ import com.tngtech.jgiven.Stage; import com.tngtech.jgiven.annotation.ExpectedScenarioState; -import org.jhotdraw.action.edit.RedoAction; import org.jhotdraw.action.edit.UndoAction; import org.jhotdraw.api.app.View; From cd72cc0ec379687a530c6f4d9c1042101d4addf6 Mon Sep 17 00:00:00 2001 From: Jesper Isgaard Hansen Date: Thu, 4 Jan 2024 00:59:53 +0100 Subject: [PATCH 70/71] Everything All the work I've done, essentially. --- jhotdraw-actions/jhotdraw-actions.iml | 6 - jhotdraw-api/jhotdraw-api.iml | 6 - jhotdraw-app/jhotdraw-app.iml | 6 - jhotdraw-core/jhotdraw-core.iml | 6 - .../org/jhotdraw/draw/tool/ImageTool.java | 8 + .../jhotdraw-datatransfer.iml | 6 - jhotdraw-gui/jhotdraw-gui.iml | 6 - .../jhotdraw-samples-mini.iml | 6 - .../jhotdraw-samples-misc.iml | 6 - .../jhotdraw-samples-misc/pom.xml | 37 ++-- .../samples/draw/DrawApplicationModel.java | 11 +- .../java/org/jhotdraw/samples/svg/Main.java | 1 + .../samples/svg/SVGCreateFromFileTool.java | 176 ++++++++++-------- .../svg/SVGCreateFromFileToolTest.java | 156 ++++++++++++++++ jhotdraw-samples/jhotdraw-samples.iml | 6 - jhotdraw-utils/jhotdraw-utils.iml | 6 - .../main/java/org/jhotdraw/util/Images.java | 8 - jhotdraw-xml/jhotdraw-xml.iml | 6 - 18 files changed, 292 insertions(+), 171 deletions(-) delete mode 100644 jhotdraw-actions/jhotdraw-actions.iml delete mode 100644 jhotdraw-api/jhotdraw-api.iml delete mode 100644 jhotdraw-app/jhotdraw-app.iml delete mode 100644 jhotdraw-core/jhotdraw-core.iml delete mode 100644 jhotdraw-datatransfer/jhotdraw-datatransfer.iml delete mode 100644 jhotdraw-gui/jhotdraw-gui.iml delete mode 100644 jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml delete mode 100644 jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml create mode 100644 jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/SVGCreateFromFileToolTest.java delete mode 100644 jhotdraw-samples/jhotdraw-samples.iml delete mode 100644 jhotdraw-utils/jhotdraw-utils.iml delete mode 100644 jhotdraw-xml/jhotdraw-xml.iml diff --git a/jhotdraw-actions/jhotdraw-actions.iml b/jhotdraw-actions/jhotdraw-actions.iml deleted file mode 100644 index 52d5deadd..000000000 --- a/jhotdraw-actions/jhotdraw-actions.iml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/jhotdraw-api/jhotdraw-api.iml b/jhotdraw-api/jhotdraw-api.iml deleted file mode 100644 index 6719176b5..000000000 --- a/jhotdraw-api/jhotdraw-api.iml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/jhotdraw-app/jhotdraw-app.iml b/jhotdraw-app/jhotdraw-app.iml deleted file mode 100644 index 161f59237..000000000 --- a/jhotdraw-app/jhotdraw-app.iml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/jhotdraw-core/jhotdraw-core.iml b/jhotdraw-core/jhotdraw-core.iml deleted file mode 100644 index 54bba967e..000000000 --- a/jhotdraw-core/jhotdraw-core.iml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/tool/ImageTool.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/tool/ImageTool.java index 6671e2f9f..416959d85 100644 --- a/jhotdraw-core/src/main/java/org/jhotdraw/draw/tool/ImageTool.java +++ b/jhotdraw-core/src/main/java/org/jhotdraw/draw/tool/ImageTool.java @@ -7,6 +7,7 @@ */ package org.jhotdraw.draw.tool; +import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import java.awt.*; import java.io.*; import java.util.*; @@ -53,6 +54,7 @@ public class ImageTool extends CreationTool { /** * Creates a new instance. */ + @FeatureEntryPoint("ImageTool1") public ImageTool(ImageHolderFigure prototype) { super(prototype); } @@ -60,10 +62,12 @@ public ImageTool(ImageHolderFigure prototype) { /** * Creates a new instance. */ + @FeatureEntryPoint("ImageTool2") public ImageTool(ImageHolderFigure prototype, Map, Object> attributes) { super(prototype, attributes); } + @FeatureEntryPoint("ImageTool3") public void setUseFileDialog(boolean newValue) { useFileDialog = newValue; if (useFileDialog) { @@ -73,10 +77,12 @@ public void setUseFileDialog(boolean newValue) { } } + @FeatureEntryPoint("ImageTool4") public boolean isUseFileDialog() { return useFileDialog; } + @FeatureEntryPoint("ImageTool5") @Override public void activate(DrawingEditor editor) { super.activate(editor); @@ -140,6 +146,7 @@ protected void done() { } } + @FeatureEntryPoint("ImageTool6") private JFileChooser getFileChooser() { if (fileChooser == null) { fileChooser = new JFileChooser(); @@ -147,6 +154,7 @@ private JFileChooser getFileChooser() { return fileChooser; } + @FeatureEntryPoint("ImageTool7") private FileDialog getFileDialog() { if (fileDialog == null) { fileDialog = new FileDialog(new Frame()); diff --git a/jhotdraw-datatransfer/jhotdraw-datatransfer.iml b/jhotdraw-datatransfer/jhotdraw-datatransfer.iml deleted file mode 100644 index dc448b11e..000000000 --- a/jhotdraw-datatransfer/jhotdraw-datatransfer.iml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/jhotdraw-gui/jhotdraw-gui.iml b/jhotdraw-gui/jhotdraw-gui.iml deleted file mode 100644 index 241c0000d..000000000 --- a/jhotdraw-gui/jhotdraw-gui.iml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml b/jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml deleted file mode 100644 index fe598d9cf..000000000 --- a/jhotdraw-samples/jhotdraw-samples-mini/jhotdraw-samples-mini.iml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml b/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml deleted file mode 100644 index c99373f7a..000000000 --- a/jhotdraw-samples/jhotdraw-samples-misc/jhotdraw-samples-misc.iml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml index 10c38c645..d89483dbb 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/pom.xml +++ b/jhotdraw-samples/jhotdraw-samples-misc/pom.xml @@ -55,30 +55,31 @@ - - org.codehaus.mojo - exec-maven-plugin - 3.1.0 - - - run-java - install - - java - - - - - org.jhotdraw.samples.svg.Main - - + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + + run-java + install + + java + + + + + org.jhotdraw.samples.svg.Main + + org.apache.maven.plugins maven-surefire-plugin 2.22.2 - -javaagent:/Users/jespe/.m2/repository/org/aspectj/aspectjweaver/1.9.9/aspectjweaver-1.9.9.jar --add-opens java.base/java.lang=ALL-UNNAMED + -javaagent:"/Users/jespe/.m2/repository/org/aspectj/aspectjweaver/1.9.9/aspectjweaver-1.9.9.jar" + --add-opens java.base/java.lang=ALL-UNNAMED true always diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/DrawApplicationModel.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/DrawApplicationModel.java index ae9f128a2..df675375d 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/DrawApplicationModel.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/DrawApplicationModel.java @@ -15,6 +15,8 @@ import org.jhotdraw.api.app.View; import org.jhotdraw.api.gui.URIChooser; import org.jhotdraw.app.DefaultApplicationModel; +import org.jhotdraw.draw.AttributeKey; +import org.jhotdraw.draw.AttributeKeys; import org.jhotdraw.draw.figure.AbstractAttributedFigure; import static org.jhotdraw.draw.AttributeKeys.*; import org.jhotdraw.draw.figure.BezierFigure; @@ -42,6 +44,9 @@ import org.jhotdraw.draw.tool.TextCreationTool; import org.jhotdraw.gui.JFileURIChooser; import org.jhotdraw.gui.action.ButtonFactory; +import org.jhotdraw.samples.svg.SVGCreateFromFileTool; +import org.jhotdraw.samples.svg.figures.SVGGroupFigure; +import org.jhotdraw.samples.svg.figures.SVGImageFigure; import org.jhotdraw.util.*; /** @@ -147,7 +152,11 @@ public void addDefaultCreationButtonsTo(JToolBar tb, final DrawingEditor editor, ButtonFactory.addToolTo(tb, editor, new BezierTool(new BezierFigure(true)), "edit.createPolygon", labels); ButtonFactory.addToolTo(tb, editor, new TextCreationTool(new TextFigure()), "edit.createText", labels); ButtonFactory.addToolTo(tb, editor, new TextAreaCreationTool(new TextAreaFigure()), "edit.createTextArea", labels); - ButtonFactory.addToolTo(tb, editor, new ImageTool(new ImageFigure()), "edit.createImage", labels); + HashMap, Object> attributes; + attributes = new HashMap, Object>(); + attributes.put(AttributeKeys.FILL_COLOR, null); + attributes.put(AttributeKeys.STROKE_COLOR, null); + ButtonFactory.addToolTo(tb, editor, new SVGCreateFromFileTool(new SVGImageFigure(), new SVGGroupFigure(), attributes), "edit.createImage", labels); } @Override diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java index effd37fd2..ca929d3ab 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/Main.java @@ -27,6 +27,7 @@ public class Main { * Creates a new instance. */ + public static void main(String[] args) { // Debug resource bundle ResourceBundleUtil.setVerbose(true); diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/SVGCreateFromFileTool.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/SVGCreateFromFileTool.java index a222f482c..8cf9059e1 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/SVGCreateFromFileTool.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/SVGCreateFromFileTool.java @@ -14,6 +14,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; + +import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.draw.AttributeKey; import org.jhotdraw.draw.figure.CompositeFigure; import org.jhotdraw.draw.DefaultDrawing; @@ -53,6 +55,7 @@ public class SVGCreateFromFileTool extends CreationTool { /** * Creates a new instance. */ + @FeatureEntryPoint("SVGTool1") public SVGCreateFromFileTool(ImageHolderFigure imagePrototype, CompositeFigure groupPrototype) { super(imagePrototype); this.groupPrototype = groupPrototype; @@ -62,12 +65,14 @@ public SVGCreateFromFileTool(ImageHolderFigure imagePrototype, CompositeFigure g /** * Creates a new instance. */ + @FeatureEntryPoint("SVGTool2") public SVGCreateFromFileTool(ImageHolderFigure imagePrototype, CompositeFigure groupPrototype, Map, Object> attributes) { super(imagePrototype, attributes); this.groupPrototype = groupPrototype; this.imagePrototype = imagePrototype; } + @FeatureEntryPoint("SVGTool3") public void setUseFileDialog(boolean newValue) { useFileDialog = newValue; if (useFileDialog) { @@ -77,10 +82,12 @@ public void setUseFileDialog(boolean newValue) { } } + @FeatureEntryPoint("SVGTool4") public boolean isUseFileDialog() { return useFileDialog; } + @FeatureEntryPoint("SVGTool5") @Override public void activate(DrawingEditor editor) { super.activate(editor); @@ -107,99 +114,110 @@ public void activate(DrawingEditor editor) { if (file.getName().toLowerCase().endsWith(".svg") || file.getName().toLowerCase().endsWith(".svgz")) { prototype = groupPrototype.clone(); - new SwingWorker() { - @Override - protected Drawing doInBackground() throws Exception { - Drawing drawing = new DefaultDrawing(); - InputFormat in = (file.getName().toLowerCase().endsWith(".svg")) ? new SVGInputFormat() : new SVGZInputFormat(); - in.read(file.toURI(), drawing); - return drawing; - } - - @Override - protected void done() { - try { - Drawing drawing = get(); - CompositeFigure parent; - if (createdFigure == null) { - parent = (CompositeFigure) prototype; - for (Figure f : drawing.getChildren()) { - parent.basicAdd(f); - } - } else { - parent = (CompositeFigure) createdFigure; - parent.willChange(); - for (Figure f : drawing.getChildren()) { - parent.add(f); - } - parent.changed(); - } - } catch (InterruptedException | ExecutionException ex) { - Logger.getLogger(SVGCreateFromFileTool.class.getName()).log(Level.SEVERE, null, ex); - failed(ex); - } - } - - protected void failed(Throwable t) { - JOptionPane.showMessageDialog(v.getComponent(), - t.getMessage(), - null, - JOptionPane.ERROR_MESSAGE); - getDrawing().remove(createdFigure); - fireToolDone(); - } - }.execute(); + SVGSwingWorker(file, v); } else { prototype = imagePrototype; - final ImageHolderFigure loaderFigure = ((ImageHolderFigure) prototype.clone()); - new SwingWorker() { - @Override - protected Object doInBackground() throws Exception { - loaderFigure.loadImage(file); - return null; - } + imageSwingWorker(file, v); + } + } else { + if (isToolDoneAfterCreation()) { + fireToolDone(); + } + } + } + + protected void SVGSwingWorker(File file, DrawingView v) { + new SwingWorker() { - @Override - protected void done() { - try { - get(); - try { - if (createdFigure == null) { - ((ImageHolderFigure) prototype).setImage(loaderFigure.getImageData(), loaderFigure.getBufferedImage()); - } else { - ((ImageHolderFigure) createdFigure).setImage(loaderFigure.getImageData(), loaderFigure.getBufferedImage()); - } - } catch (IOException ex) { - JOptionPane.showMessageDialog(v.getComponent(), - ex.getMessage(), - null, - JOptionPane.ERROR_MESSAGE); - } - } catch (InterruptedException | ExecutionException ex) { - Logger.getLogger(SVGCreateFromFileTool.class.getName()).log( Level.SEVERE, null, ex); - failed(ex); + @Override + protected Drawing doInBackground() throws Exception { + Drawing drawing = new DefaultDrawing(); + InputFormat in = (file.getName().toLowerCase().endsWith(".svg")) ? new SVGInputFormat() : new SVGZInputFormat(); + in.read(file.toURI(), drawing); + return drawing; + } + + @Override + protected void done() { + try { + Drawing drawing = get(); + CompositeFigure parent; + if (createdFigure == null) { + parent = (CompositeFigure) prototype; + for (Figure f : drawing.getChildren()) { + parent.basicAdd(f); + } + } else { + parent = (CompositeFigure) createdFigure; + parent.willChange(); + for (Figure f : drawing.getChildren()) { + parent.add(f); } - + parent.changed(); } + } catch (InterruptedException | ExecutionException ex) { + Logger.getLogger(SVGCreateFromFileTool.class.getName()).log(Level.SEVERE, null, ex); + failed(ex); + } + } + + protected void failed(Throwable t) { + JOptionPane.showMessageDialog(v.getComponent(), + t.getMessage(), + null, + JOptionPane.ERROR_MESSAGE); + getDrawing().remove(createdFigure); + fireToolDone(); + } + + }.execute(); + } - protected void failed(Throwable t) { + protected void imageSwingWorker(File file, DrawingView v) { + final ImageHolderFigure loaderFigure = ((ImageHolderFigure) prototype.clone()); + new SwingWorker() { + + @Override + protected Object doInBackground() throws Exception { + loaderFigure.loadImage(file); + return null; + } + + @Override + protected void done() { + try { + get(); + try { + if (createdFigure == null) { + ((ImageHolderFigure) prototype).setImage(loaderFigure.getImageData(), loaderFigure.getBufferedImage()); + } else { + ((ImageHolderFigure) createdFigure).setImage(loaderFigure.getImageData(), loaderFigure.getBufferedImage()); + } + } catch (IOException ex) { JOptionPane.showMessageDialog(v.getComponent(), - t.getMessage(), + ex.getMessage(), null, JOptionPane.ERROR_MESSAGE); - getDrawing().remove(createdFigure); - fireToolDone(); } - }.execute(); + } catch (InterruptedException | ExecutionException ex) { + Logger.getLogger(SVGCreateFromFileTool.class.getName()).log(Level.SEVERE, null, ex); + failed(ex); + } + } - } else { - //getDrawing().remove(createdFigure); - if (isToolDoneAfterCreation()) { + protected void failed(Throwable t) { + JOptionPane.showMessageDialog(v.getComponent(), + t.getMessage(), + null, + JOptionPane.ERROR_MESSAGE); + getDrawing().remove(createdFigure); fireToolDone(); } - } + + }.execute(); } + @FeatureEntryPoint("SVGTool6") @Override protected Figure createFigure() { if (prototype instanceof CompositeFigure) { @@ -212,6 +230,7 @@ protected Figure createFigure() { } } + @FeatureEntryPoint("SVGTool7") private JFileChooser getFileChooser() { if (fileChooser == null) { fileChooser = new JFileChooser(); @@ -219,6 +238,7 @@ private JFileChooser getFileChooser() { return fileChooser; } + @FeatureEntryPoint("SVGTool8") private FileDialog getFileDialog() { if (fileDialog == null) { fileDialog = new FileDialog(new Frame()); diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/SVGCreateFromFileToolTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/SVGCreateFromFileToolTest.java new file mode 100644 index 000000000..dcfafc389 --- /dev/null +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/SVGCreateFromFileToolTest.java @@ -0,0 +1,156 @@ +package org.jhotdraw.samples.svg; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.jhotdraw.draw.DefaultDrawing; +import org.jhotdraw.draw.DefaultDrawingEditor; +import org.jhotdraw.draw.DefaultDrawingView; +import org.jhotdraw.draw.DrawingEditor; +import org.jhotdraw.draw.figure.CompositeFigure; +import org.jhotdraw.draw.figure.ImageFigure; +import org.jhotdraw.draw.figure.ImageHolderFigure; +import org.junit.Ignore; +import org.junit.Test; + +public class SVGCreateFromFileToolTest { + /** + * Method under test: {@link SVGCreateFromFileTool#SVGCreateFromFileTool(ImageHolderFigure, CompositeFigure, Map)} + */ + @Test + public void testConstructor() { + ImageFigure imagePrototype = new ImageFigure(); + DefaultDrawing groupPrototype = new DefaultDrawing(); + SVGCreateFromFileTool actualSvgCreateFromFileTool = new SVGCreateFromFileTool(imagePrototype, groupPrototype, + new HashMap<>()); + + assertNull(actualSvgCreateFromFileTool.getActionMap()); + ImageHolderFigure imageHolderFigure = actualSvgCreateFromFileTool.imagePrototype; + assertTrue(imageHolderFigure instanceof ImageFigure); + assertTrue(actualSvgCreateFromFileTool.groupPrototype instanceof DefaultDrawing); + assertNull(actualSvgCreateFromFileTool.getInputMap()); + assertSame(imageHolderFigure, actualSvgCreateFromFileTool.getPrototype()); + assertEquals(0, actualSvgCreateFromFileTool.getPropertyChangeListeners().length); + assertTrue(actualSvgCreateFromFileTool.isToolDoneAfterCreation()); + } + + /** + * Method under test: {@link SVGCreateFromFileTool#activate(DrawingEditor)} + */ + @Test + public void testActivate() { + ImageFigure imagePrototype = new ImageFigure(); + SVGCreateFromFileTool svgCreateFromFileTool = new SVGCreateFromFileTool(imagePrototype, new DefaultDrawing()); + svgCreateFromFileTool.activate(new DefaultDrawingEditor()); + assertTrue(svgCreateFromFileTool.isActive()); + } + + /** + * Method under test: {@link SVGCreateFromFileTool#activate(DrawingEditor)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testActivate2() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // Diffblue Cover tried to run the arrange/act section, but the method under + // test threw + // java.lang.NullPointerException + // at org.jhotdraw.draw.tool.AbstractTool.activate(AbstractTool.java:91) + // at org.jhotdraw.draw.tool.CreationTool.activate(CreationTool.java:169) + // at org.jhotdraw.samples.svg.SVGCreateFromFileTool.activate(SVGCreateFromFileTool.java:93) + // In order to prevent activate(DrawingEditor) + // from throwing NullPointerException, add constructors or factory + // methods that make it easier to construct fully initialized objects used in + // activate(DrawingEditor). + // See https://diff.blue/R013 to resolve this issue. + + ImageFigure imagePrototype = new ImageFigure(); + (new SVGCreateFromFileTool(imagePrototype, new DefaultDrawing())).activate(null); + } + + /** + * Method under test: {@link SVGCreateFromFileTool#activate(DrawingEditor)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testActivate3() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // Diffblue Cover tried to run the arrange/act section, but the method under + // test threw + // java.awt.HeadlessException + // at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:208) + // at java.awt.Window.(Window.java:548) + // at java.awt.Frame.(Frame.java:423) + // at java.awt.Frame.(Frame.java:388) + // at javax.swing.SwingUtilities$SharedOwnerFrame.(SwingUtilities.java:1919) + // at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1995) + // at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1689) + // at javax.swing.JOptionPane.getWindowForComponent(JOptionPane.java:1630) + // at javax.swing.JOptionPane.getWindowForComponent(JOptionPane.java:1633) + // at javax.swing.JFileChooser.createDialog(JFileChooser.java:813) + // at javax.swing.JFileChooser.showDialog(JFileChooser.java:760) + // at javax.swing.JFileChooser.showOpenDialog(JFileChooser.java:666) + // at org.jhotdraw.samples.svg.SVGCreateFromFileTool.activate(SVGCreateFromFileTool.java:107) + // In order to prevent activate(DrawingEditor) + // from throwing HeadlessException, add constructors or factory + // methods that make it easier to construct fully initialized objects used in + // activate(DrawingEditor). + // See https://diff.blue/R013 to resolve this issue. + + ImageFigure imagePrototype = new ImageFigure(); + SVGCreateFromFileTool svgCreateFromFileTool = new SVGCreateFromFileTool(imagePrototype, new DefaultDrawing()); + + DefaultDrawingEditor defaultDrawingEditor = new DefaultDrawingEditor(); + defaultDrawingEditor.add(new DefaultDrawingView()); + svgCreateFromFileTool.activate(defaultDrawingEditor); + } + + /** + * Method under test: {@link SVGCreateFromFileTool#activate(DrawingEditor)} + */ + @Test + @Ignore("TODO: Complete this test") + public void testActivate4() { + // TODO: Complete this test. + // Reason: R013 No inputs found that don't throw a trivial exception. + // Diffblue Cover tried to run the arrange/act section, but the method under + // test threw + // java.awt.HeadlessException + // at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:208) + // at java.awt.Window.(Window.java:548) + // at java.awt.Frame.(Frame.java:423) + // at java.awt.Frame.(Frame.java:388) + // at javax.swing.SwingUtilities$SharedOwnerFrame.(SwingUtilities.java:1919) + // at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1995) + // at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1689) + // at javax.swing.JOptionPane.getWindowForComponent(JOptionPane.java:1630) + // at javax.swing.JOptionPane.getWindowForComponent(JOptionPane.java:1633) + // at javax.swing.JFileChooser.createDialog(JFileChooser.java:813) + // at javax.swing.JFileChooser.showDialog(JFileChooser.java:760) + // at javax.swing.JFileChooser.showOpenDialog(JFileChooser.java:666) + // at org.jhotdraw.samples.svg.SVGCreateFromFileTool.activate(SVGCreateFromFileTool.java:107) + // In order to prevent activate(DrawingEditor) + // from throwing HeadlessException, add constructors or factory + // methods that make it easier to construct fully initialized objects used in + // activate(DrawingEditor). + // See https://diff.blue/R013 to resolve this issue. + + ImageFigure imagePrototype = new ImageFigure(); + SVGCreateFromFileTool svgCreateFromFileTool = new SVGCreateFromFileTool(imagePrototype, new DefaultDrawing()); + + DefaultDrawingView defaultDrawingView = new DefaultDrawingView(); + defaultDrawingView.addToSelection(new DefaultDrawing()); + + DefaultDrawingEditor defaultDrawingEditor = new DefaultDrawingEditor(); + defaultDrawingEditor.add(defaultDrawingView); + svgCreateFromFileTool.activate(defaultDrawingEditor); + } +} + diff --git a/jhotdraw-samples/jhotdraw-samples.iml b/jhotdraw-samples/jhotdraw-samples.iml deleted file mode 100644 index d054ca213..000000000 --- a/jhotdraw-samples/jhotdraw-samples.iml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/jhotdraw-utils/jhotdraw-utils.iml b/jhotdraw-utils/jhotdraw-utils.iml deleted file mode 100644 index 858e47629..000000000 --- a/jhotdraw-utils/jhotdraw-utils.iml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/jhotdraw-utils/src/main/java/org/jhotdraw/util/Images.java b/jhotdraw-utils/src/main/java/org/jhotdraw/util/Images.java index d31ee3cd8..b99accda0 100644 --- a/jhotdraw-utils/src/main/java/org/jhotdraw/util/Images.java +++ b/jhotdraw-utils/src/main/java/org/jhotdraw/util/Images.java @@ -24,11 +24,9 @@ public class Images { /** * Prevent instance creation. */ - @FeatureEntryPoint("InsertImage") private Images() { } - @FeatureEntryPoint("InsertImage") public static Image createImage(Class baseClass, String resourceName) { URL resource = baseClass.getResource(resourceName); if (resource == null) { @@ -38,7 +36,6 @@ public static Image createImage(Class baseClass, String resourceName) { return image; } - @FeatureEntryPoint("InsertImage") public static Image createImage(URL resource) { if (resource == null) { throw new IllegalArgumentException("resource must not be null"); @@ -54,7 +51,6 @@ public static Image createImage(URL resource) { * @param rImg An Image. * @return A BufferedImage. */ - @FeatureEntryPoint("InsertImage") public static BufferedImage toBufferedImage(RenderedImage rImg) { BufferedImage image; if (rImg instanceof BufferedImage) { @@ -73,7 +69,6 @@ public static BufferedImage toBufferedImage(RenderedImage rImg) { return image; } - @FeatureEntryPoint("InsertImage") public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; @@ -139,7 +134,6 @@ public static BufferedImage toBufferedImage(Image image) { * Code taken from the Java Developers Almanac 1.4 * http://javaalmanac.com/egs/java.awt.image/HasAlpha.html */ - @FeatureEntryPoint("InsertImage") public static boolean hasAlpha(Image image) { // If buffered image, the color model is readily available if (image instanceof BufferedImage) { @@ -162,7 +156,6 @@ public static boolean hasAlpha(Image image) { /** * Splits an image into count subimages. */ - @FeatureEntryPoint("InsertImage") public static BufferedImage[] split(Image image, int count, boolean isHorizontal) { BufferedImage src = Images.toBufferedImage(image); if (count == 1) { @@ -199,7 +192,6 @@ public static BufferedImage[] split(Image image, int count, boolean isHorizontal * @param width the width to which to scale the image. * @param height the height to which to scale the image. */ - @FeatureEntryPoint("InsertImage") public static BufferedImage getScaledInstance(Image image, int width, int height) { int w, h; if (width < 0 && height < 0) { diff --git a/jhotdraw-xml/jhotdraw-xml.iml b/jhotdraw-xml/jhotdraw-xml.iml deleted file mode 100644 index 228779b5e..000000000 --- a/jhotdraw-xml/jhotdraw-xml.iml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file From f0662fca447b484408d1dc81f156338feabfd322 Mon Sep 17 00:00:00 2001 From: Jesper Isgaard Hansen Date: Thu, 4 Jan 2024 11:03:45 +0100 Subject: [PATCH 71/71] Last Minute Changes --- .../draw/figure/ImageHolderFigure.java | 4 +- .../org/jhotdraw/draw/tool/ImageTool.java | 164 ------------------ .../samples/draw/DrawApplicationModel.java | 2 - .../java/org/jhotdraw/samples/draw/Main.java | 1 + .../samples/svg/SVGCreateFromFileTool.java | 22 ++- .../svg/SVGCreateFromFileToolTest.java | 141 ++++----------- 6 files changed, 52 insertions(+), 282 deletions(-) delete mode 100644 jhotdraw-core/src/main/java/org/jhotdraw/draw/tool/ImageTool.java diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/figure/ImageHolderFigure.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/figure/ImageHolderFigure.java index 60b27fe9b..faa8bc1fa 100644 --- a/jhotdraw-core/src/main/java/org/jhotdraw/draw/figure/ImageHolderFigure.java +++ b/jhotdraw-core/src/main/java/org/jhotdraw/draw/figure/ImageHolderFigure.java @@ -13,7 +13,7 @@ /** * The interface of a {@link Figure} which has some editable image contents. *

- * The {@link org.jhotdraw.draw.tool.ImageTool} can be used to create figures which implement this + * The {@link org.jhotdraw.samples.svg.SVGCreateFromFileTool} can be used to create figures which implement this * interface. * *


@@ -25,7 +25,7 @@ * That's the reason why {@code Figure} extends the {@code Cloneable} interface. *
* Prototype: {@link ImageHolderFigure}; - * Client: {@link org.jhotdraw.draw.tool.ImageTool}. + * Client: {@link org.jhotdraw.samples.svg.SVGCreateFromFileTool}. * * *

diff --git a/jhotdraw-core/src/main/java/org/jhotdraw/draw/tool/ImageTool.java b/jhotdraw-core/src/main/java/org/jhotdraw/draw/tool/ImageTool.java deleted file mode 100644 index 416959d85..000000000 --- a/jhotdraw-core/src/main/java/org/jhotdraw/draw/tool/ImageTool.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * @(#)ImageTool.java - * - * Copyright (c) 1996-2010 The authors and contributors of JHotDraw. - * You may not use, copy or modify this file, except in compliance with the - * accompanying license terms. - */ -package org.jhotdraw.draw.tool; - -import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; -import java.awt.*; -import java.io.*; -import java.util.*; -import java.util.concurrent.ExecutionException; -import javax.swing.*; -import org.jhotdraw.draw.AttributeKey; -import org.jhotdraw.draw.DrawingEditor; -import org.jhotdraw.draw.DrawingView; -import org.jhotdraw.draw.figure.ImageHolderFigure; - -/** - * A tool to create new figures that implement the ImageHolderFigure - * interface, such as ImageFigure. The figure to be created is specified by a - * prototype. - *

- * Immediately, after the ImageTool has been activated, it opens a JFileChooser, - * letting the user specify an image file. The the user then performs - * the following mouse gesture: - *

    - *
  1. Press the mouse button and drag the mouse over the DrawingView. - * This defines the bounds of the created figure.
  2. - *
- * - *
- * Design Patterns - * - *

- * Prototype
- * The {@code ImageTool} creates new figures by cloning a prototype - * {@code ImageHolderFigure} object.
- * Prototype: {@link ImageHolderFigure}; Client: {@link ImageTool}. - *


- * - * @author Werner Randelshofer - * @version $Id$ - */ -public class ImageTool extends CreationTool { - - private static final long serialVersionUID = 1L; - protected FileDialog fileDialog; - protected JFileChooser fileChooser; - protected boolean useFileDialog; - - /** - * Creates a new instance. - */ - @FeatureEntryPoint("ImageTool1") - public ImageTool(ImageHolderFigure prototype) { - super(prototype); - } - - /** - * Creates a new instance. - */ - @FeatureEntryPoint("ImageTool2") - public ImageTool(ImageHolderFigure prototype, Map, Object> attributes) { - super(prototype, attributes); - } - - @FeatureEntryPoint("ImageTool3") - public void setUseFileDialog(boolean newValue) { - useFileDialog = newValue; - if (useFileDialog) { - fileChooser = null; - } else { - fileDialog = null; - } - } - - @FeatureEntryPoint("ImageTool4") - public boolean isUseFileDialog() { - return useFileDialog; - } - - @FeatureEntryPoint("ImageTool5") - @Override - public void activate(DrawingEditor editor) { - super.activate(editor); - final DrawingView v = getView(); - if (v == null) { - return; - } - final File file; - if (useFileDialog) { - getFileDialog().setVisible(true); - if (getFileDialog().getFile() != null) { - file = new File(getFileDialog().getDirectory(), getFileDialog().getFile()); - } else { - file = null; - } - } else { - if (getFileChooser().showOpenDialog(v.getComponent()) == JFileChooser.APPROVE_OPTION) { - file = getFileChooser().getSelectedFile(); - } else { - file = null; - } - } - if (file != null) { - final ImageHolderFigure loaderFigure = ((ImageHolderFigure) prototype.clone()); - new SwingWorker() { - @Override - protected Object doInBackground() throws Exception { - loaderFigure.loadImage(file); - return null; - } - - @Override - protected void done() { - try { - get(); //will throw an ExecutionException if in doInBackground something went wrong. - if (createdFigure == null) { - ((ImageHolderFigure) prototype).setImage(loaderFigure.getImageData(), loaderFigure.getBufferedImage()); - } else { - ((ImageHolderFigure) createdFigure).setImage(loaderFigure.getImageData(), loaderFigure.getBufferedImage()); - } - } catch (IOException ex) { - JOptionPane.showMessageDialog(v.getComponent(), - ex.getMessage(), - null, - JOptionPane.ERROR_MESSAGE); - } catch (InterruptedException | ExecutionException ex) { - JOptionPane.showMessageDialog(v.getComponent(), - ex.getMessage(), - null, - JOptionPane.ERROR_MESSAGE); - getDrawing().remove(createdFigure); - fireToolDone(); - } - } - }.execute(); - } else { - //getDrawing().remove(createdFigure); - if (isToolDoneAfterCreation()) { - fireToolDone(); - } - } - } - - @FeatureEntryPoint("ImageTool6") - private JFileChooser getFileChooser() { - if (fileChooser == null) { - fileChooser = new JFileChooser(); - } - return fileChooser; - } - - @FeatureEntryPoint("ImageTool7") - private FileDialog getFileDialog() { - if (fileDialog == null) { - fileDialog = new FileDialog(new Frame()); - } - return fileDialog; - } -} diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/DrawApplicationModel.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/DrawApplicationModel.java index df675375d..c74ff29c2 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/DrawApplicationModel.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/DrawApplicationModel.java @@ -25,7 +25,6 @@ import org.jhotdraw.draw.figure.DiamondFigure; import org.jhotdraw.draw.DrawingEditor; import org.jhotdraw.draw.figure.EllipseFigure; -import org.jhotdraw.draw.figure.ImageFigure; import org.jhotdraw.draw.figure.LineConnectionFigure; import org.jhotdraw.draw.figure.LineFigure; import org.jhotdraw.draw.figure.RectangleFigure; @@ -39,7 +38,6 @@ import org.jhotdraw.draw.tool.BezierTool; import org.jhotdraw.draw.tool.ConnectionTool; import org.jhotdraw.draw.tool.CreationTool; -import org.jhotdraw.draw.tool.ImageTool; import org.jhotdraw.draw.tool.TextAreaCreationTool; import org.jhotdraw.draw.tool.TextCreationTool; import org.jhotdraw.gui.JFileURIChooser; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java index b125a5d05..208c1ab81 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/draw/Main.java @@ -7,6 +7,7 @@ */ package org.jhotdraw.samples.draw; +import dk.sdu.mmmi.featuretracer.lib.FeatureEntryPoint; import org.jhotdraw.api.app.Application; import org.jhotdraw.app.OSXApplication; import org.jhotdraw.app.SDIApplication; diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/SVGCreateFromFileTool.java b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/SVGCreateFromFileTool.java index 8cf9059e1..5eef1d00e 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/SVGCreateFromFileTool.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/main/java/org/jhotdraw/samples/svg/SVGCreateFromFileTool.java @@ -91,8 +91,12 @@ public boolean isUseFileDialog() { @Override public void activate(DrawingEditor editor) { super.activate(editor); - final DrawingView v = getView(); - if (v == null) { + final DrawingView v; + try { + v = getView(); + } + catch(NullPointerException e) + { return; } final File file; @@ -104,10 +108,16 @@ public void activate(DrawingEditor editor) { file = null; } } else { - if (getFileChooser().showOpenDialog(v.getComponent()) == JFileChooser.APPROVE_OPTION) { - file = getFileChooser().getSelectedFile(); - } else { - file = null; + try { + if (getFileChooser().showOpenDialog(v.getComponent()) == JFileChooser.APPROVE_OPTION) { + file = getFileChooser().getSelectedFile(); + } else { + file = null; + } + } + catch(NullPointerException e) + { + return; } } if (file != null) { diff --git a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/SVGCreateFromFileToolTest.java b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/SVGCreateFromFileToolTest.java index dcfafc389..d3235b713 100644 --- a/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/SVGCreateFromFileToolTest.java +++ b/jhotdraw-samples/jhotdraw-samples-misc/src/test/java/org/jhotdraw/samples/svg/SVGCreateFromFileToolTest.java @@ -1,156 +1,81 @@ package org.jhotdraw.samples.svg; +import static org.junit.Assert.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; - +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; +import org.jhotdraw.draw.AttributeKey; + import org.jhotdraw.draw.DefaultDrawing; import org.jhotdraw.draw.DefaultDrawingEditor; import org.jhotdraw.draw.DefaultDrawingView; import org.jhotdraw.draw.DrawingEditor; +import org.jhotdraw.draw.DrawingView; +import org.jhotdraw.draw.event.CompositeFigureEvent; +import org.jhotdraw.draw.event.CompositeFigureListener; import org.jhotdraw.draw.figure.CompositeFigure; +import org.jhotdraw.draw.figure.Figure; import org.jhotdraw.draw.figure.ImageFigure; import org.jhotdraw.draw.figure.ImageHolderFigure; import org.junit.Ignore; import org.junit.Test; public class SVGCreateFromFileToolTest { + + /** - * Method under test: {@link SVGCreateFromFileTool#SVGCreateFromFileTool(ImageHolderFigure, CompositeFigure, Map)} + * Method under test: {@link SVGCreateFromFileTool#SVGCreateFromFileTool(ImageHolderFigure, CompositeFigure)} */ @Test public void testConstructor() { ImageFigure imagePrototype = new ImageFigure(); - DefaultDrawing groupPrototype = new DefaultDrawing(); - SVGCreateFromFileTool actualSvgCreateFromFileTool = new SVGCreateFromFileTool(imagePrototype, groupPrototype, - new HashMap<>()); + SVGCreateFromFileTool actualSvgCreateFromFileTool = new SVGCreateFromFileTool(imagePrototype, new DefaultDrawing()); - assertNull(actualSvgCreateFromFileTool.getActionMap()); ImageHolderFigure imageHolderFigure = actualSvgCreateFromFileTool.imagePrototype; assertTrue(imageHolderFigure instanceof ImageFigure); assertTrue(actualSvgCreateFromFileTool.groupPrototype instanceof DefaultDrawing); - assertNull(actualSvgCreateFromFileTool.getInputMap()); assertSame(imageHolderFigure, actualSvgCreateFromFileTool.getPrototype()); - assertEquals(0, actualSvgCreateFromFileTool.getPropertyChangeListeners().length); - assertTrue(actualSvgCreateFromFileTool.isToolDoneAfterCreation()); - } - - /** - * Method under test: {@link SVGCreateFromFileTool#activate(DrawingEditor)} - */ - @Test - public void testActivate() { - ImageFigure imagePrototype = new ImageFigure(); - SVGCreateFromFileTool svgCreateFromFileTool = new SVGCreateFromFileTool(imagePrototype, new DefaultDrawing()); - svgCreateFromFileTool.activate(new DefaultDrawingEditor()); - assertTrue(svgCreateFromFileTool.isActive()); - } - - /** - * Method under test: {@link SVGCreateFromFileTool#activate(DrawingEditor)} - */ - @Test - @Ignore("TODO: Complete this test") - public void testActivate2() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // Diffblue Cover tried to run the arrange/act section, but the method under - // test threw - // java.lang.NullPointerException - // at org.jhotdraw.draw.tool.AbstractTool.activate(AbstractTool.java:91) - // at org.jhotdraw.draw.tool.CreationTool.activate(CreationTool.java:169) - // at org.jhotdraw.samples.svg.SVGCreateFromFileTool.activate(SVGCreateFromFileTool.java:93) - // In order to prevent activate(DrawingEditor) - // from throwing NullPointerException, add constructors or factory - // methods that make it easier to construct fully initialized objects used in - // activate(DrawingEditor). - // See https://diff.blue/R013 to resolve this issue. - - ImageFigure imagePrototype = new ImageFigure(); - (new SVGCreateFromFileTool(imagePrototype, new DefaultDrawing())).activate(null); } /** - * Method under test: {@link SVGCreateFromFileTool#activate(DrawingEditor)} + * Method under test: {@link SVGCreateFromFileTool#SVGCreateFromFileTool(ImageHolderFigure, CompositeFigure, Map)} */ @Test - @Ignore("TODO: Complete this test") - public void testActivate3() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // Diffblue Cover tried to run the arrange/act section, but the method under - // test threw - // java.awt.HeadlessException - // at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:208) - // at java.awt.Window.(Window.java:548) - // at java.awt.Frame.(Frame.java:423) - // at java.awt.Frame.(Frame.java:388) - // at javax.swing.SwingUtilities$SharedOwnerFrame.(SwingUtilities.java:1919) - // at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1995) - // at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1689) - // at javax.swing.JOptionPane.getWindowForComponent(JOptionPane.java:1630) - // at javax.swing.JOptionPane.getWindowForComponent(JOptionPane.java:1633) - // at javax.swing.JFileChooser.createDialog(JFileChooser.java:813) - // at javax.swing.JFileChooser.showDialog(JFileChooser.java:760) - // at javax.swing.JFileChooser.showOpenDialog(JFileChooser.java:666) - // at org.jhotdraw.samples.svg.SVGCreateFromFileTool.activate(SVGCreateFromFileTool.java:107) - // In order to prevent activate(DrawingEditor) - // from throwing HeadlessException, add constructors or factory - // methods that make it easier to construct fully initialized objects used in - // activate(DrawingEditor). - // See https://diff.blue/R013 to resolve this issue. - + public void testConstructor2() { ImageFigure imagePrototype = new ImageFigure(); - SVGCreateFromFileTool svgCreateFromFileTool = new SVGCreateFromFileTool(imagePrototype, new DefaultDrawing()); + DefaultDrawing groupPrototype = new DefaultDrawing(); + SVGCreateFromFileTool actualSvgCreateFromFileTool = new SVGCreateFromFileTool(imagePrototype, groupPrototype, + new HashMap<>()); - DefaultDrawingEditor defaultDrawingEditor = new DefaultDrawingEditor(); - defaultDrawingEditor.add(new DefaultDrawingView()); - svgCreateFromFileTool.activate(defaultDrawingEditor); + ImageHolderFigure imageHolderFigure = actualSvgCreateFromFileTool.imagePrototype; + assertTrue(imageHolderFigure instanceof ImageFigure); + assertTrue(actualSvgCreateFromFileTool.groupPrototype instanceof DefaultDrawing); + assertSame(imageHolderFigure, actualSvgCreateFromFileTool.getPrototype()); + assertTrue(actualSvgCreateFromFileTool.isToolDoneAfterCreation()); } /** * Method under test: {@link SVGCreateFromFileTool#activate(DrawingEditor)} */ @Test - @Ignore("TODO: Complete this test") - public void testActivate4() { - // TODO: Complete this test. - // Reason: R013 No inputs found that don't throw a trivial exception. - // Diffblue Cover tried to run the arrange/act section, but the method under - // test threw - // java.awt.HeadlessException - // at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:208) - // at java.awt.Window.(Window.java:548) - // at java.awt.Frame.(Frame.java:423) - // at java.awt.Frame.(Frame.java:388) - // at javax.swing.SwingUtilities$SharedOwnerFrame.(SwingUtilities.java:1919) - // at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1995) - // at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1689) - // at javax.swing.JOptionPane.getWindowForComponent(JOptionPane.java:1630) - // at javax.swing.JOptionPane.getWindowForComponent(JOptionPane.java:1633) - // at javax.swing.JFileChooser.createDialog(JFileChooser.java:813) - // at javax.swing.JFileChooser.showDialog(JFileChooser.java:760) - // at javax.swing.JFileChooser.showOpenDialog(JFileChooser.java:666) - // at org.jhotdraw.samples.svg.SVGCreateFromFileTool.activate(SVGCreateFromFileTool.java:107) - // In order to prevent activate(DrawingEditor) - // from throwing HeadlessException, add constructors or factory - // methods that make it easier to construct fully initialized objects used in - // activate(DrawingEditor). - // See https://diff.blue/R013 to resolve this issue. - + public void testActivate() { ImageFigure imagePrototype = new ImageFigure(); SVGCreateFromFileTool svgCreateFromFileTool = new SVGCreateFromFileTool(imagePrototype, new DefaultDrawing()); - - DefaultDrawingView defaultDrawingView = new DefaultDrawingView(); - defaultDrawingView.addToSelection(new DefaultDrawing()); - - DefaultDrawingEditor defaultDrawingEditor = new DefaultDrawingEditor(); - defaultDrawingEditor.add(defaultDrawingView); - svgCreateFromFileTool.activate(defaultDrawingEditor); + svgCreateFromFileTool.activate(new DefaultDrawingEditor()); + assertTrue(svgCreateFromFileTool.isActive()); } }