sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Add a package for visualization tools used for debugging purpose. For now only show a java.awt.Shape. More may be added in the future.
Date Wed, 15 May 2019 07:59:19 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 00feca6  Add a package for visualization tools used for debugging purpose. For now
only show a java.awt.Shape. More may be added in the future.
00feca6 is described below

commit 00feca6f5439213b37c1c583638bcd21428d7fcd
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed May 15 09:50:12 2019 +0200

    Add a package for visualization tools used for debugging purpose.
    For now only show a java.awt.Shape. More may be added in the future.
---
 .../referencing/j2d/ShapeUtilitiesViewer.java      |  3 +-
 .../org/apache/sis/test/widget/ShapeViewer.java    | 74 ++++++++++++++++++++
 .../apache/sis/test/widget/SwingAssertions.java    | 80 ++++++++++++++++++++++
 .../org/apache/sis/test/widget/VisualCheck.java    | 75 ++++++++++++++++++++
 .../org/apache/sis/test/widget/package-info.java   | 40 +++++++++++
 .../src/test/java/org/apache/sis/test/Assert.java  | 43 ------------
 6 files changed, 271 insertions(+), 44 deletions(-)

diff --git a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesViewer.java
b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesViewer.java
index c765c34..b2a3e4c 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesViewer.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/j2d/ShapeUtilitiesViewer.java
@@ -45,7 +45,7 @@ import org.apache.sis.util.CharSequences;
  * @module
  */
 @SuppressWarnings("serial")
-final strictfp class ShapeUtilitiesViewer extends JPanel {
+public final strictfp class ShapeUtilitiesViewer extends JPanel {
     /**
      * The {@link ShapeUtilities} methods to test.
      */
@@ -93,6 +93,7 @@ final strictfp class ShapeUtilitiesViewer extends JPanel {
     /**
      * Creates a new panel where to paint the input and output values.
      */
+    @SuppressWarnings("UseOfSystemOutOrSystemErr")
     private ShapeUtilitiesViewer() {
         setBackground(Color.BLACK);
         input  = new Path2D.Float();
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/test/widget/ShapeViewer.java
b/core/sis-referencing/src/test/java/org/apache/sis/test/widget/ShapeViewer.java
new file mode 100644
index 0000000..7e2d8ef
--- /dev/null
+++ b/core/sis-referencing/src/test/java/org/apache/sis/test/widget/ShapeViewer.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.test.widget;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.Rectangle2D;
+import javax.swing.JPanel;
+
+
+/**
+ * A simple viewer of {@link Shape} object. The shape is resized to fill most of the window,
+ * with <var>y</var> axis oriented toward up. The bounding box is drawn in gray
color behind.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+@SuppressWarnings("serial")
+final strictfp class ShapeViewer extends JPanel {
+    /**
+     * Margin to keep on each side of the window.
+     */
+    private static final int MARGIN = 20;
+
+    /**
+     * The shape to visualize.
+     */
+    private final Shape shape;
+
+    /**
+     * Creates a new panel for rendering the given shape.
+     */
+    ShapeViewer(final Shape shape) {
+        setBackground(Color.BLACK);
+        this.shape = shape;
+    }
+
+    /**
+     * Paints the shape.
+     */
+    @Override
+    protected void paintComponent(final Graphics graphics) {
+        super.paintComponent(graphics);
+        final Graphics2D g = (Graphics2D) graphics;
+        Rectangle2D bounds = shape.getBounds2D();
+        g.translate(MARGIN, MARGIN);
+        g.scale((getWidth() - 2*MARGIN) / bounds.getWidth(), (2*MARGIN - getHeight()) / bounds.getHeight());
+        g.translate(-bounds.getMinX(), -bounds.getMaxY());
+        g.setStroke(new BasicStroke(0));
+        g.setColor(Color.GRAY);
+        g.draw(bounds);
+        g.setColor(Color.RED);
+        g.draw(shape);
+    }
+}
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/test/widget/SwingAssertions.java
b/core/sis-referencing/src/test/java/org/apache/sis/test/widget/SwingAssertions.java
new file mode 100644
index 0000000..afbf9b4
--- /dev/null
+++ b/core/sis-referencing/src/test/java/org/apache/sis/test/widget/SwingAssertions.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.test.widget;
+
+import java.util.Enumeration;
+import javax.swing.tree.TreeNode;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Assertions on Swing objects.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public final strictfp class SwingAssertions {
+    /**
+     * Do not allow instantiation of this class.
+     */
+    private SwingAssertions() {
+    }
+
+    /**
+     * Ensures that a tree is equals to an other tree.
+     * This method invokes itself recursively for every child nodes.
+     *
+     * @param  expected  the expected tree, or {@code null}.
+     * @param  actual    the tree to compare with the expected one, or {@code null}.
+     * @return the number of nodes.
+     */
+    public static int assertTreeEquals(final TreeNode expected, final TreeNode actual) {
+        if (expected == null) {
+            assertNull(actual);
+            return 0;
+        }
+        int n = 1;
+        assertNotNull(actual);
+        assertEquals("isLeaf()",            expected.isLeaf(),            actual.isLeaf());
+        assertEquals("getAllowsChildren()", expected.getAllowsChildren(), actual.getAllowsChildren());
+        assertEquals("getChildCount()",     expected.getChildCount(),     actual.getChildCount());
+        @SuppressWarnings("unchecked") final Enumeration<? extends TreeNode> ec = expected.children();
+        @SuppressWarnings("unchecked") final Enumeration<? extends TreeNode> ac = actual
 .children();
+
+        int childIndex = 0;
+        while (ec.hasMoreElements()) {
+            assertTrue("hasMoreElements()", ac.hasMoreElements());
+            final TreeNode nextExpected = ec.nextElement();
+            final TreeNode nextActual   = ac.nextElement();
+            final String message = "getChildAt(" + childIndex + ')';
+            assertSame(message, nextExpected, expected.getChildAt(childIndex));
+            assertSame(message, nextActual,   actual  .getChildAt(childIndex));
+            assertSame("getParent()", expected, nextExpected.getParent());
+            assertSame("getParent()", actual,   nextActual  .getParent());
+            assertSame("getIndex(TreeNode)", childIndex, expected.getIndex(nextExpected));
+            assertSame("getIndex(TreeNode)", childIndex, actual  .getIndex(nextActual));
+            n += assertTreeEquals(nextExpected, nextActual);
+            childIndex++;
+        }
+        assertFalse("hasMoreElements()", ac.hasMoreElements());
+        assertEquals("toString()", expected.toString(), actual.toString());
+        return n;
+    }
+}
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/test/widget/VisualCheck.java
b/core/sis-referencing/src/test/java/org/apache/sis/test/widget/VisualCheck.java
new file mode 100644
index 0000000..32714c3
--- /dev/null
+++ b/core/sis-referencing/src/test/java/org/apache/sis/test/widget/VisualCheck.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.test.widget;
+
+import java.awt.Shape;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+
+/**
+ * Methods showing windows for performing visual checks.
+ * Methods in this class block until user closes the window.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+public final strictfp class VisualCheck {
+    /**
+     * Do not allows instantiation of this class.
+     */
+    private VisualCheck() {
+    }
+
+    /**
+     * Visualizes the given shape in its own window. The shape is resized to fill most of
the window,
+     * with <var>y</var> axis oriented toward up. The bounding box is drawn in
gray color behind the shape.
+     *
+     * @param  shape  the shape to visualize.
+     */
+    public static void show(final Shape shape) {
+        show(new ShapeViewer(shape));
+    }
+
+    /**
+     * Shows the given panel and blocks current thread until user closes the window.
+     */
+    private static void show(final JPanel viewer) {
+        final WindowAdapter lock = new WindowAdapter() {
+            @Override public synchronized void windowClosed(WindowEvent e) {
+                notifyAll();
+            }
+        };
+        final JFrame frame = new JFrame("ShapeViewer");
+        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+        frame.addWindowListener(lock);
+        frame.add(viewer);
+        frame.setSize(600, 400);
+        frame.setVisible(true);
+        try {
+            synchronized (lock) {
+                lock.wait();
+            }
+        } catch (InterruptedException e) {
+            // Ignore.
+        }
+    }
+}
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/test/widget/package-info.java
b/core/sis-referencing/src/test/java/org/apache/sis/test/widget/package-info.java
new file mode 100644
index 0000000..a774ab7
--- /dev/null
+++ b/core/sis-referencing/src/test/java/org/apache/sis/test/widget/package-info.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/**
+ * Swing widgets for some visual verifications. This is used for debugging purposes only.
+ * The visualization tools in this package are not related to any particular SIS objects.
+ * This package may seem unused by code on the repository because it is often used only
+ * temporarily during debugging phase.
+ *
+ * <div class="section">Other visualization tools</div>
+ * This package does not contains all visualization tools. Some debugging tools specific
+ * to a particular class are provided in the package of that class. Examples:
+ *
+ * <ul>
+ *   <li>{@link org.apache.sis.internal.referencing.j2d.ShapeUtilitiesViewer}</li>
+ *   <li>{@link org.apache.sis.referencing.gazetteer.LocationViewer}</li>
+ *   <li>{@link org.apache.sis.image.ImageTestCase}</li>
+ * </ul>
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ * @since   1.0
+ * @module
+ */
+package org.apache.sis.test.widget;
diff --git a/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java b/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java
index 93bb208..30aef61 100644
--- a/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java
+++ b/core/sis-utility/src/test/java/org/apache/sis/test/Assert.java
@@ -21,7 +21,6 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.Iterator;
 import java.util.Collection;
-import java.util.Enumeration;
 import java.util.LinkedHashSet;
 import java.util.LinkedHashMap;
 import java.util.stream.Stream;
@@ -33,7 +32,6 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import javax.swing.tree.TreeNode;
 import org.apache.sis.util.Utilities;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.ComparisonMode;
@@ -311,47 +309,6 @@ public strictfp class Assert extends org.opengis.test.Assert {
     }
 
     /**
-     * Ensures that a tree is equals to an other tree.
-     * This method invokes itself recursively for every child nodes.
-     *
-     * @param  expected  the expected tree, or {@code null}.
-     * @param  actual    the tree to compare with the expected one, or {@code null}.
-     * @return the number of nodes.
-     */
-    public static int assertTreeEquals(final TreeNode expected, final TreeNode actual) {
-        if (expected == null) {
-            assertNull(actual);
-            return 0;
-        }
-        int n = 1;
-        assertNotNull(actual);
-        assertEquals("isLeaf()",            expected.isLeaf(),            actual.isLeaf());
-        assertEquals("getAllowsChildren()", expected.getAllowsChildren(), actual.getAllowsChildren());
-        assertEquals("getChildCount()",     expected.getChildCount(),     actual.getChildCount());
-        @SuppressWarnings("unchecked") final Enumeration<? extends TreeNode> ec = expected.children();
-        @SuppressWarnings("unchecked") final Enumeration<? extends TreeNode> ac = actual
 .children();
-
-        int childIndex = 0;
-        while (ec.hasMoreElements()) {
-            assertTrue("hasMoreElements()", ac.hasMoreElements());
-            final TreeNode nextExpected = ec.nextElement();
-            final TreeNode nextActual   = ac.nextElement();
-            final String message = "getChildAt(" + childIndex + ')';
-            assertSame(message, nextExpected, expected.getChildAt(childIndex));
-            assertSame(message, nextActual,   actual  .getChildAt(childIndex));
-            assertSame("getParent()", expected, nextExpected.getParent());
-            assertSame("getParent()", actual,   nextActual  .getParent());
-            assertSame("getIndex(TreeNode)", childIndex, expected.getIndex(nextExpected));
-            assertSame("getIndex(TreeNode)", childIndex, actual  .getIndex(nextActual));
-            n += assertTreeEquals(nextExpected, nextActual);
-            childIndex++;
-        }
-        assertFalse("hasMoreElements()", ac.hasMoreElements());
-        assertEquals("toString()", expected.toString(), actual.toString());
-        return n;
-    }
-
-    /**
      * Serializes the given object in memory, deserializes it and ensures that the deserialized
      * object is equals to the original one. This method does not write anything to the disk.
      *


Mime
View raw message