From 06872940f47032c84fe2fb681f7e52b38ae1e1ce Mon Sep 17 00:00:00 2001 From: Sebastian Schulz Date: Mon, 8 Nov 2021 13:27:56 +0100 Subject: [PATCH 1/2] Replace deprecated XMLReaderFactory by SAXParserFactory --- .../interceptor/CacheInterceptor.java | 13 +- .../interceptor/ShowViewInterceptor.java | 13 +- .../edit/support/EditBlackboardTest.java | 1336 +++++++++-------- .../udig/tools/edit/support/TimingTests.java | 112 +- .../udig/internal/ui/FeatureTextTransfer.java | 11 +- .../udig/internal/ui/FilterTextTransfer.java | 83 +- 6 files changed, 816 insertions(+), 752 deletions(-) diff --git a/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/CacheInterceptor.java b/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/CacheInterceptor.java index 47660ad20e..6bd1d8292b 100644 --- a/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/CacheInterceptor.java +++ b/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/CacheInterceptor.java @@ -20,6 +20,8 @@ import java.net.URLDecoder; import java.net.URLEncoder; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.TransformerException; import org.eclipse.core.runtime.IProgressMonitor; @@ -42,7 +44,6 @@ import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; /** * If a cache flag is set in the layer style blackboard this interceptor will return a @@ -213,10 +214,16 @@ private Filter readFilter(String textData) { GMLFilterDocument filterDocument = new GMLFilterDocument(filterGeometry); try { - // parse xml - XMLReader reader = XMLReaderFactory.createXMLReader(); + + // parse XML + + SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParser parser = factory.newSAXParser(); + XMLReader reader = parser.getXMLReader(); + reader.setContentHandler(filterDocument); reader.parse(input); + } catch (Exception e) { return Filter.INCLUDE; } diff --git a/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/ShowViewInterceptor.java b/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/ShowViewInterceptor.java index d7b1503b33..d536ff03ad 100644 --- a/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/ShowViewInterceptor.java +++ b/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/ShowViewInterceptor.java @@ -20,6 +20,8 @@ import java.net.URLDecoder; import java.net.URLEncoder; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.TransformerException; import org.eclipse.core.runtime.IProgressMonitor; @@ -49,7 +51,6 @@ import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; /** * If a filter or a query is in the layer style blackboard under the key: the {@link #KEY} then this @@ -302,10 +303,16 @@ private Filter readFilter(String textData) { GMLFilterDocument filterDocument = new GMLFilterDocument(filterGeometry); try { - // parse xml - XMLReader reader = XMLReaderFactory.createXMLReader(); + + // parse XML + + SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParser parser = factory.newSAXParser(); + XMLReader reader = parser.getXMLReader(); + reader.setContentHandler(filterDocument); reader.parse(input); + } catch (Exception e) { return Filter.INCLUDE; } diff --git a/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/EditBlackboardTest.java b/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/EditBlackboardTest.java index d0fe457fe7..b063113611 100644 --- a/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/EditBlackboardTest.java +++ b/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/EditBlackboardTest.java @@ -1,7 +1,7 @@ -/* - * uDig - User Friendly Desktop Internet GIS client - * http://udig.refractions.net - * (C) 2012, Refractions Research Inc. +/** + * uDig - User Friendly Desktop Internet GIS client + * http://udig.refractions.net + * (C) 2012, Refractions Research Inc. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -29,12 +29,9 @@ import java.util.List; import java.util.Map; -import org.locationtech.udig.project.internal.render.impl.ScaleUtils; -import org.locationtech.udig.tool.edit.tests.TestsPlugin; -import org.locationtech.udig.tools.edit.preferences.PreferenceUtil; -import org.locationtech.udig.tools.edit.support.EditBlackboardEvent.EventType; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; -import org.geotools.data.simple.SimpleFeatureCollection; import org.geotools.feature.DefaultFeatureCollection; import org.geotools.geometry.jts.JTS; import org.geotools.geometry.jts.ReferencedEnvelope; @@ -47,1041 +44,1064 @@ import org.geotools.referencing.operation.transform.IdentityTransform; import org.junit.Before; import org.junit.Test; -import org.opengis.feature.simple.SimpleFeature; -import org.opengis.referencing.operation.MathTransform; -import org.xml.sax.InputSource; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; - import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.LinearRing; import org.locationtech.jts.geom.MultiPolygon; import org.locationtech.jts.geom.Polygon; +import org.locationtech.udig.project.internal.render.impl.ScaleUtils; +import org.locationtech.udig.tool.edit.tests.TestsPlugin; +import org.locationtech.udig.tools.edit.preferences.PreferenceUtil; +import org.locationtech.udig.tools.edit.support.EditBlackboardEvent.EventType; +import org.opengis.feature.simple.SimpleFeature; +import org.opengis.referencing.operation.MathTransform; +import org.xml.sax.InputSource; +import org.xml.sax.XMLReader; public class EditBlackboardTest { static { - new PreferenceUtil(){ + new PreferenceUtil() { { - instance=this; + instance = this; } + @Override public int getVertexRadius() { return 0; } }; } - - AffineTransform transform=AffineTransform.getTranslateInstance(10,5); + + AffineTransform transform = AffineTransform.getTranslateInstance(10, 5); + private MathTransform layerToWorld; - java.awt.Point SCREEN=new java.awt.Point(500,500); + java.awt.Point SCREEN = new java.awt.Point(500, 500); @Before public void setUp() throws Exception { - layerToWorld=IdentityTransform.create(2); + layerToWorld = IdentityTransform.create(2); } @Test public void testSetup() throws Exception { - EventListener l=new EventListener(); - EditBlackboard map = new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); + EventListener l = new EventListener(); + EditBlackboard map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); map.getListeners().add(l); - assertPixMapState(map,1,0,0,0); + assertPixMapState(map, 1, 0, 0, 0); - map.addPoint(10,5,map.getGeoms().get(0).getShell()); - assertPixMapState(map,1,1,0,0); - assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getX() ); - assertEquals(5, map.getGeoms().get(0).getShell().getPoint(0).getY() ); + map.addPoint(10, 5, map.getGeoms().get(0).getShell()); + assertPixMapState(map, 1, 1, 0, 0); + assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getX()); + assertEquals(5, map.getGeoms().get(0).getShell().getPoint(0).getY()); assertEquals(EventType.ADD_POINT, l.event.getType()); EditBlackboardEvent editBlackboardEvent = l.getEditBlackboardEvent(); assertEquals(null, editBlackboardEvent.getOldValue()); - assertEquals(Point.valueOf(10,5), editBlackboardEvent.getNewValue()); + assertEquals(Point.valueOf(10, 5), editBlackboardEvent.getNewValue()); assertEquals(map.getGeoms().get(0).getShell(), editBlackboardEvent.getSource()); - - map.addPoint(10,10,map.getGeoms().get(0).getShell()); - assertPixMapState(map,1,2,0,0); - assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getX() ); - assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getY() ); + map.addPoint(10, 10, map.getGeoms().get(0).getShell()); + + assertPixMapState(map, 1, 2, 0, 0); + assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getX()); + assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getY()); assertEquals(EventType.ADD_POINT, l.event.getType()); editBlackboardEvent = l.getEditBlackboardEvent(); assertEquals(null, editBlackboardEvent.getOldValue()); - assertEquals(Point.valueOf(10,10), editBlackboardEvent.getNewValue()); + assertEquals(Point.valueOf(10, 10), editBlackboardEvent.getNewValue()); assertEquals(map.getGeoms().get(0).getShell(), editBlackboardEvent.getSource()); - GeometryFactory factory=new GeometryFactory(); - Geometry geom=factory.createPoint(new Coordinate(10,5)); - map=new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); + GeometryFactory factory = new GeometryFactory(); + Geometry geom = factory.createPoint(new Coordinate(10, 5)); + map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); map.getListeners().add(l); Map mapping = map.setGeometries(geom, null); assertNotNull(mapping.get(geom)); assertEquals(ShapeType.POINT, mapping.get(geom).getShapeType()); - assertPixMapState(map,1,1,0,0); - assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX() ); - assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY() ); + assertPixMapState(map, 1, 1, 0, 0); + assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX()); + assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY()); assertEquals(EventType.SET_GEOMS, l.event.getType()); editBlackboardEvent = l.getEditBlackboardEvent(); - assertEquals(1, ((List)editBlackboardEvent.getOldValue()).size()); - assertEquals(1, ((List)editBlackboardEvent.getNewValue()).size()); + assertEquals(1, ((List) editBlackboardEvent.getOldValue()).size()); + assertEquals(1, ((List) editBlackboardEvent.getNewValue()).size()); assertEquals(map, editBlackboardEvent.getSource()); - - geom=factory.createMultiPoint(new Coordinate[]{new Coordinate(10,5), new Coordinate(20,10)}); - map=new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); + + geom = factory.createMultiPoint( + new Coordinate[] { new Coordinate(10, 5), new Coordinate(20, 10) }); + map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); map.getListeners().add(l); String string = "featureID"; //$NON-NLS-1$ - mapping=map.setGeometries(geom, string); + mapping = map.setGeometries(geom, string); EditGeom next = mapping.values().iterator().next(); assertEquals(ShapeType.POINT, next.getShapeType()); assertEquals(string, next.getFeatureIDRef().get()); assertNotNull(mapping.get(geom.getGeometryN(0))); assertNotNull(mapping.get(geom.getGeometryN(1))); - assertPixMapState(map,2,1,0,0); - assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX() ); - assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY() ); - assertEquals(30, map.getGeoms().get(1).getShell().getPoint(0).getX() ); - assertEquals(15, map.getGeoms().get(1).getShell().getPoint(0).getY() ); - assertEquals(new Coordinate(10,5), map.getGeoms().get(0).getShell().getCoord(0)); - assertEquals(new Coordinate(20,10), map.getGeoms().get(1).getShell().getCoord(0)); + assertPixMapState(map, 2, 1, 0, 0); + assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX()); + assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY()); + assertEquals(30, map.getGeoms().get(1).getShell().getPoint(0).getX()); + assertEquals(15, map.getGeoms().get(1).getShell().getPoint(0).getY()); + assertEquals(new Coordinate(10, 5), map.getGeoms().get(0).getShell().getCoord(0)); + assertEquals(new Coordinate(20, 10), map.getGeoms().get(1).getShell().getCoord(0)); editBlackboardEvent = l.getEditBlackboardEvent(); assertEquals(2, ((List) editBlackboardEvent.getNewValue()).size()); assertEquals(map, editBlackboardEvent.getSource()); - LinearRing ring = createShellRing(factory, 10); - - map=new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); + + map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); map.getListeners().add(l); - mapping=map.setGeometries(ring, null); + mapping = map.setGeometries(ring, null); assertEquals(ShapeType.LINE, mapping.get(ring).getShapeType()); assertNotNull(mapping.get(ring)); - assertPixMapState(map,1,5,0,0); - assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX() ); - assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY() ); - assertEquals(30, map.getGeoms().get(0).getShell().getPoint(1).getX() ); - assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getY() ); - assertEquals(30, map.getGeoms().get(0).getShell().getPoint(2).getX() ); - assertEquals(15, map.getGeoms().get(0).getShell().getPoint(2).getY() ); - assertEquals(20, map.getGeoms().get(0).getShell().getPoint(3).getX() ); - assertEquals(15, map.getGeoms().get(0).getShell().getPoint(3).getY() ); - assertEquals(20, map.getGeoms().get(0).getShell().getPoint(4).getX() ); - assertEquals(10, map.getGeoms().get(0).getShell().getPoint(4).getY() ); + assertPixMapState(map, 1, 5, 0, 0); + assertEquals(20, map.getGeoms().get(0).getShell().getPoint(0).getX()); + assertEquals(10, map.getGeoms().get(0).getShell().getPoint(0).getY()); + assertEquals(30, map.getGeoms().get(0).getShell().getPoint(1).getX()); + assertEquals(10, map.getGeoms().get(0).getShell().getPoint(1).getY()); + assertEquals(30, map.getGeoms().get(0).getShell().getPoint(2).getX()); + assertEquals(15, map.getGeoms().get(0).getShell().getPoint(2).getY()); + assertEquals(20, map.getGeoms().get(0).getShell().getPoint(3).getX()); + assertEquals(15, map.getGeoms().get(0).getShell().getPoint(3).getY()); + assertEquals(20, map.getGeoms().get(0).getShell().getPoint(4).getX()); + assertEquals(10, map.getGeoms().get(0).getShell().getPoint(4).getY()); editBlackboardEvent = l.getEditBlackboardEvent(); assertEquals(1, ((List) editBlackboardEvent.getNewValue()).size()); assertEquals(map, editBlackboardEvent.getSource()); - - map=new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); + + map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); map.getListeners().add(l); Polygon polygon = createPolygon(factory, 10); - mapping=map.setGeometries(polygon, null); + mapping = map.setGeometries(polygon, null); assertEquals(ShapeType.POLYGON, mapping.get(polygon).getShapeType()); assertNotNull(mapping.get(polygon)); - assertPixMapState(map,1,5,1,5); - assertEquals(Point.valueOf(20,10), map.getGeoms().get(0).getShell().getPoint(0) ); - assertEquals(Point.valueOf(25,12), map.getGeoms().get(0).getHoles().get(0).getPoint(0) ); - assertEquals(Point.valueOf(30,10), map.getGeoms().get(0).getShell().getPoint(1) ); - assertEquals(Point.valueOf(28,12), map.getGeoms().get(0).getHoles().get(0).getPoint(1) ); - assertEquals(new Coordinate(15,7), map.getGeoms().get(0).getHoles().get(0).getCoord(0)); - assertEquals(new Coordinate(18,7), map.getGeoms().get(0).getHoles().get(0).getCoord(1)); + assertPixMapState(map, 1, 5, 1, 5); + assertEquals(Point.valueOf(20, 10), map.getGeoms().get(0).getShell().getPoint(0)); + assertEquals(Point.valueOf(25, 12), map.getGeoms().get(0).getHoles().get(0).getPoint(0)); + assertEquals(Point.valueOf(30, 10), map.getGeoms().get(0).getShell().getPoint(1)); + assertEquals(Point.valueOf(28, 12), map.getGeoms().get(0).getHoles().get(0).getPoint(1)); + assertEquals(new Coordinate(15, 7), map.getGeoms().get(0).getHoles().get(0).getCoord(0)); + assertEquals(new Coordinate(18, 7), map.getGeoms().get(0).getHoles().get(0).getCoord(1)); editBlackboardEvent = l.getEditBlackboardEvent(); assertEquals(1, ((List) editBlackboardEvent.getNewValue()).size()); assertEquals(map, editBlackboardEvent.getSource()); - geom=factory.createMultiPolygon(new Polygon[]{ - createPolygon(factory, 0), createPolygon(factory, 20) - }); + geom = factory.createMultiPolygon( + new Polygon[] { createPolygon(factory, 0), createPolygon(factory, 20) }); - map=new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); + map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); map.getListeners().add(l); - mapping=map.setGeometries(geom, null); - assertPixMapState(map,2,5,1,5); + mapping = map.setGeometries(geom, null); + assertPixMapState(map, 2, 5, 1, 5); editBlackboardEvent = l.getEditBlackboardEvent(); assertEquals(2, ((List) editBlackboardEvent.getNewValue()).size()); assertEquals(map, editBlackboardEvent.getSource()); - + } - private Polygon createPolygon( GeometryFactory factory, int i ) { - return factory.createPolygon(createShellRing(factory, i), new LinearRing[]{createHoleRing(factory, i)}); + private Polygon createPolygon(GeometryFactory factory, int i) { + return factory.createPolygon(createShellRing(factory, i), + new LinearRing[] { createHoleRing(factory, i) }); } - private LinearRing createHoleRing( GeometryFactory factory, int offset) { - return factory.createLinearRing(new Coordinate[]{ - new Coordinate(offset+5, 7), - new Coordinate(offset+8, 7), - new Coordinate(offset+8, 8), - new Coordinate(offset+5, 8), - new Coordinate(offset+5, 7) - }); + private LinearRing createHoleRing(GeometryFactory factory, int offset) { + return factory.createLinearRing(new Coordinate[] { new Coordinate(offset + 5, 7), + new Coordinate(offset + 8, 7), new Coordinate(offset + 8, 8), + new Coordinate(offset + 5, 8), new Coordinate(offset + 5, 7) }); } - private LinearRing createShellRing( GeometryFactory factory, int offset ) { - return factory.createLinearRing(new Coordinate[]{ - new Coordinate(offset+0,5), - new Coordinate(offset+10,5), - new Coordinate(offset+10,10), - new Coordinate(offset+0,10), - new Coordinate(offset+0,5) - }); + private LinearRing createShellRing(GeometryFactory factory, int offset) { + return factory.createLinearRing(new Coordinate[] { new Coordinate(offset + 0, 5), + new Coordinate(offset + 10, 5), new Coordinate(offset + 10, 10), + new Coordinate(offset + 0, 10), new Coordinate(offset + 0, 5) }); } /** * @param numGeoms number of expected geometries * @param numShellPoints expected number of points in shells of each geometry - * @param numHoles expected number of holes of each geometry + * @param numHoles expected number of holes of each geometry * @param numHolesPoints expected number of points in all holes of each geometry */ - private void assertPixMapState( EditBlackboard map, int numGeoms, int numShellPoints, int numHoles, int numHolesPoints) { + private void assertPixMapState(EditBlackboard map, int numGeoms, int numShellPoints, + int numHoles, int numHolesPoints) { assertEquals("numGeoms", numGeoms, map.getGeoms().size()); //$NON-NLS-1$ - for( EditGeom geom : map.getGeoms() ) { - assertEquals("numShellPoints", numShellPoints, geom.getShell().getNumPoints() ); //$NON-NLS-1$ - assertEquals("numHoles", numHoles, geom.getHoles().size() ); //$NON-NLS-1$ - for( PrimitiveShape hole : geom.getHoles() ) { - assertEquals("numHolesPoints ", numHolesPoints, hole.getNumPoints() ); //$NON-NLS-1$ + for (EditGeom geom : map.getGeoms()) { + assertEquals("numShellPoints", numShellPoints, geom.getShell().getNumPoints()); //$NON-NLS-1$ + assertEquals("numHoles", numHoles, geom.getHoles().size()); //$NON-NLS-1$ + for (PrimitiveShape hole : geom.getHoles()) { + assertEquals("numHolesPoints ", numHolesPoints, hole.getNumPoints()); //$NON-NLS-1$ } } } - + @Test public void testGetCandidate() throws Exception { - GeometryFactory factory=new GeometryFactory(); - LinearRing ring1=createShellRing(factory, 10); - LinearRing ring2=createShellRing(factory, 30); - LinearRing ring3=createShellRing(factory, 32); - EditBlackboard map = new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); + GeometryFactory factory = new GeometryFactory(); + LinearRing ring1 = createShellRing(factory, 10); + LinearRing ring2 = createShellRing(factory, 30); + LinearRing ring3 = createShellRing(factory, 32); + EditBlackboard map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); Map mapping = map.setGeometries(ring1, null); mapping.putAll(map.addGeometry(ring2, null)); mapping.putAll(map.addGeometry(ring3, null)); - assertPixMapState(map,3,5,0,0); - - List candidates = map.getCandidates(22,0, true); + assertPixMapState(map, 3, 5, 0, 0); + + List candidates = map.getCandidates(22, 0, true); assertEquals(1, candidates.size()); - assertSame( candidates.get(0).getGeom(), mapping.get(ring1)); + assertSame(candidates.get(0).getGeom(), mapping.get(ring1)); - candidates = map.getCandidates(32,0, true); + candidates = map.getCandidates(32, 0, true); assertEquals(0, candidates.size()); - candidates = map.getCandidates(42,0, true); + candidates = map.getCandidates(42, 0, true); assertEquals(1, candidates.size()); - assertSame( candidates.get(0).getGeom(), mapping.get(ring2)); - - candidates = map.getCandidates(51,12, true); + assertSame(candidates.get(0).getGeom(), mapping.get(ring2)); + + candidates = map.getCandidates(51, 12, true); assertEquals(2, candidates.size()); - assertTrue( candidates.get(0).getGeom()==mapping.get(ring3) || candidates.get(1).getGeom()==mapping.get(ring3)); - assertTrue( candidates.get(0).getGeom()==mapping.get(ring2) || candidates.get(1).getGeom()==mapping.get(ring2)); - + assertTrue(candidates.get(0).getGeom() == mapping.get(ring3) + || candidates.get(1).getGeom() == mapping.get(ring3)); + assertTrue(candidates.get(0).getGeom() == mapping.get(ring2) + || candidates.get(1).getGeom() == mapping.get(ring2)); + // now testing geoms with holes - Polygon polygon=createPolygon(factory, 10); - mapping=map.setGeometries(ring1, null); + Polygon polygon = createPolygon(factory, 10); + mapping = map.setGeometries(ring1, null); mapping.putAll(map.addGeometry(polygon, null)); - candidates = map.getCandidates(26,12, true); + candidates = map.getCandidates(26, 12, true); assertEquals(1, candidates.size()); - assertSame( candidates.get(0).getGeom(), mapping.get(polygon)); + assertSame(candidates.get(0).getGeom(), mapping.get(polygon)); } - + /* - * Test method for 'org.locationtech.udig.tools.edit.support.PixelCoordMap.addCoord(int, int, Coordinate)' + * Test method for 'org.locationtech.udig.tools.edit.support.PixelCoordMap.addCoord(int, int, + * Coordinate)' */ @Test public void testAddCoord() { - EventListener l=new EventListener(); - - GeometryFactory factory=new GeometryFactory(); - Geometry geom=factory.createPoint(new Coordinate(10,5)); - EditBlackboard map = new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); + EventListener l = new EventListener(); + + GeometryFactory factory = new GeometryFactory(); + Geometry geom = factory.createPoint(new Coordinate(10, 5)); + EditBlackboard map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); map.getListeners().add(l); map.setGeometries(geom, null); - assertPixMapState(map,1,1,0,0); - + assertPixMapState(map, 1, 1, 0, 0); + EditGeom geomShape = map.getGeoms().get(0); - map.addPoint(10,5,geomShape.getShell()); - assertPixMapState(map,1,2,0,0); - assertEquals(1, map.getCoords(10,5).size()); + map.addPoint(10, 5, geomShape.getShell()); + assertPixMapState(map, 1, 2, 0, 0); + assertEquals(1, map.getCoords(10, 5).size()); assertEquals(EventType.ADD_POINT, l.getEditBlackboardEvent().getType()); EditBlackboardEvent editBlackboardEvent = l.getEditBlackboardEvent(); assertEquals(null, editBlackboardEvent.getOldValue()); - assertEquals(Point.valueOf(10,5), editBlackboardEvent.getNewValue()); - + assertEquals(Point.valueOf(10, 5), editBlackboardEvent.getNewValue()); + LinearRing ring = createShellRing(factory, 10); - - map=new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); + + map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); map.getListeners().add(l); Map mapping = map.setGeometries(ring, null); - assertPixMapState(map,1,5,0,0); - - //add at a particular index. - map.insertCoord(25,15, 3, mapping.get(ring).getShell()); - assertEquals(Point.valueOf(20,10),mapping.get(ring).getShell().getPoint(0)); - assertEquals(Point.valueOf(30,10),mapping.get(ring).getShell().getPoint(1)); - assertEquals(Point.valueOf(30,15),mapping.get(ring).getShell().getPoint(2)); - assertEquals(Point.valueOf(25,15),mapping.get(ring).getShell().getPoint(3)); - assertEquals(Point.valueOf(20,15),mapping.get(ring).getShell().getPoint(4)); + assertPixMapState(map, 1, 5, 0, 0); + + // add at a particular index. + map.insertCoord(25, 15, 3, mapping.get(ring).getShell()); + assertEquals(Point.valueOf(20, 10), mapping.get(ring).getShell().getPoint(0)); + assertEquals(Point.valueOf(30, 10), mapping.get(ring).getShell().getPoint(1)); + assertEquals(Point.valueOf(30, 15), mapping.get(ring).getShell().getPoint(2)); + assertEquals(Point.valueOf(25, 15), mapping.get(ring).getShell().getPoint(3)); + assertEquals(Point.valueOf(20, 15), mapping.get(ring).getShell().getPoint(4)); assertEquals(EventType.ADD_POINT, l.event.getType()); editBlackboardEvent = l.getEditBlackboardEvent(); assertEquals(null, editBlackboardEvent.getOldValue()); - assertEquals(Point.valueOf(25,15), editBlackboardEvent.getNewValue()); + assertEquals(Point.valueOf(25, 15), editBlackboardEvent.getNewValue()); assertEquals(mapping.get(ring).getShell(), editBlackboardEvent.getSource()); - //create a geom one point at a time test ordering of geometries - map=new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); + // create a geom one point at a time test ordering of geometries + map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); map.getListeners().add(l); geomShape = map.getGeoms().get(0); - map.addPoint(0,0, geomShape.getShell()); - map.addPoint(0,100, geomShape.getShell()); - map.addPoint(50,100, geomShape.getShell()); - map.addPoint(100,100, geomShape.getShell()); - map.addPoint(50,150, geomShape.getShell()); - - assertEquals(Point.valueOf(0,0), geomShape.getShell().getPoint(0)); - assertEquals(Point.valueOf(0,100), geomShape.getShell().getPoint(1)); - assertEquals(Point.valueOf(50,100), geomShape.getShell().getPoint(2)); - assertEquals(Point.valueOf(100,100), geomShape.getShell().getPoint(3)); - assertEquals(Point.valueOf(50,150), geomShape.getShell().getPoint(4)); - - //test the coordinates were created correcly - assertEquals(new Coordinate(-9.5,-4.5), geomShape.getShell().getCoord(0)); - assertEquals(new Coordinate(-9.5,95.5), geomShape.getShell().getCoord(1)); - assertEquals(new Coordinate(40.5,95.5), geomShape.getShell().getCoord(2)); - assertEquals(new Coordinate(90.5,95.5), geomShape.getShell().getCoord(3)); - assertEquals(new Coordinate(40.5,145.5), geomShape.getShell().getCoord(4)); - + map.addPoint(0, 0, geomShape.getShell()); + map.addPoint(0, 100, geomShape.getShell()); + map.addPoint(50, 100, geomShape.getShell()); + map.addPoint(100, 100, geomShape.getShell()); + map.addPoint(50, 150, geomShape.getShell()); + + assertEquals(Point.valueOf(0, 0), geomShape.getShell().getPoint(0)); + assertEquals(Point.valueOf(0, 100), geomShape.getShell().getPoint(1)); + assertEquals(Point.valueOf(50, 100), geomShape.getShell().getPoint(2)); + assertEquals(Point.valueOf(100, 100), geomShape.getShell().getPoint(3)); + assertEquals(Point.valueOf(50, 150), geomShape.getShell().getPoint(4)); + + // test the coordinates were created correcly + assertEquals(new Coordinate(-9.5, -4.5), geomShape.getShell().getCoord(0)); + assertEquals(new Coordinate(-9.5, 95.5), geomShape.getShell().getCoord(1)); + assertEquals(new Coordinate(40.5, 95.5), geomShape.getShell().getCoord(2)); + assertEquals(new Coordinate(90.5, 95.5), geomShape.getShell().getCoord(3)); + assertEquals(new Coordinate(40.5, 145.5), geomShape.getShell().getCoord(4)); + // now making sure the the CoordMap is correctly updated too. - assertEquals(1, map.getCoords(0,0).size()); - assertEquals(new Coordinate(-9.5,-4.5), map.getCoords(0,0).get(0)); - assertEquals(1, map.getCoords(0,100).size()); - assertEquals(new Coordinate(-9.5,95.5), map.getCoords(0,100).get(0)); - assertEquals(1, map.getCoords(0,100).size()); - assertEquals(new Coordinate(40.5,95.5), map.getCoords(50,100).get(0)); - assertEquals(1, map.getCoords(0,100).size()); - assertEquals(new Coordinate(90.5,95.5), map.getCoords(100,100).get(0)); - assertEquals(1, map.getCoords(50,150).size()); - assertEquals(new Coordinate(40.5,145.5), map.getCoords(50,150).get(0)); - - //insert a vertex in a hole - Polygon polygon=createPolygon(factory, 10); - map=new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); + assertEquals(1, map.getCoords(0, 0).size()); + assertEquals(new Coordinate(-9.5, -4.5), map.getCoords(0, 0).get(0)); + assertEquals(1, map.getCoords(0, 100).size()); + assertEquals(new Coordinate(-9.5, 95.5), map.getCoords(0, 100).get(0)); + assertEquals(1, map.getCoords(0, 100).size()); + assertEquals(new Coordinate(40.5, 95.5), map.getCoords(50, 100).get(0)); + assertEquals(1, map.getCoords(0, 100).size()); + assertEquals(new Coordinate(90.5, 95.5), map.getCoords(100, 100).get(0)); + assertEquals(1, map.getCoords(50, 150).size()); + assertEquals(new Coordinate(40.5, 145.5), map.getCoords(50, 150).get(0)); + + // insert a vertex in a hole + Polygon polygon = createPolygon(factory, 10); + map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); map.getListeners().add(l); mapping = map.setGeometries(polygon, null); - assertPixMapState(map,1,5,1,5); - - //add at a particular index. + assertPixMapState(map, 1, 5, 1, 5); + + // add at a particular index. PrimitiveShape hole = mapping.get(polygon).getHoles().get(0); - map.insertCoord(26,13, 3, hole); - assertEquals(Point.valueOf(25,12),hole.getPoint(0)); - assertEquals(Point.valueOf(28,12),hole.getPoint(1)); - assertEquals(Point.valueOf(28,13),hole.getPoint(2)); - assertEquals(Point.valueOf(26,13),hole.getPoint(3)); - assertEquals(Point.valueOf(25,13),hole.getPoint(4)); + map.insertCoord(26, 13, 3, hole); + assertEquals(Point.valueOf(25, 12), hole.getPoint(0)); + assertEquals(Point.valueOf(28, 12), hole.getPoint(1)); + assertEquals(Point.valueOf(28, 13), hole.getPoint(2)); + assertEquals(Point.valueOf(26, 13), hole.getPoint(3)); + assertEquals(Point.valueOf(25, 13), hole.getPoint(4)); editBlackboardEvent = l.getEditBlackboardEvent(); assertEquals(null, editBlackboardEvent.getOldValue()); - assertEquals(Point.valueOf(26,13), editBlackboardEvent.getNewValue()); + assertEquals(Point.valueOf(26, 13), editBlackboardEvent.getNewValue()); assertEquals(hole, editBlackboardEvent.getSource()); + // add on an edge test ordering of geometries + LinearRing ring2 = createShellRing(factory, 30); + LinearRing ring3 = createShellRing(factory, 32); - - //add on an edge test ordering of geometries - LinearRing ring2=createShellRing(factory, 30); - LinearRing ring3=createShellRing(factory, 32); - - ring3.getCoordinateN(2).y=20; - - mapping=map.setGeometries(ring2, null); + ring3.getCoordinateN(2).y = 20; + + mapping = map.setGeometries(ring2, null); mapping.putAll(map.addGeometry(ring3, null)); - - map.addToNearestEdge(54,12, mapping.get(ring2), true); - assertEquals(1, map.getCoords(54,12).size()); - assertEquals(new Coordinate(44.5,7.5), mapping.get(ring2).getShell().getCoord(2)); + + map.addToNearestEdge(54, 12, mapping.get(ring2), true); + assertEquals(1, map.getCoords(54, 12).size()); + assertEquals(new Coordinate(44.5, 7.5), mapping.get(ring2).getShell().getCoord(2)); editBlackboardEvent = l.getEditBlackboardEvent(); assertEquals(null, editBlackboardEvent.getOldValue()); - assertEquals(Point.valueOf(54,12), editBlackboardEvent.getNewValue()); + assertEquals(Point.valueOf(54, 12), editBlackboardEvent.getNewValue()); assertEquals(mapping.get(ring2).getShell(), editBlackboardEvent.getSource()); - - - mapping=map.setGeometries(ring2, null); + + mapping = map.setGeometries(ring2, null); mapping.putAll(map.addGeometry(ring3, null)); - - List added = map.addToNearestEdge(51,12,true); + + List added = map.addToNearestEdge(51, 12, true); assertEquals(2, added.size()); - assertTrue( added.get(0).getGeom()==mapping.get(ring3) || added.get(1).getGeom()==mapping.get(ring3)); - assertTrue( added.get(0).getGeom()==mapping.get(ring2) || added.get(1).getGeom()==mapping.get(ring2)); - assertEquals(2, map.getCoords(51,12).size()); - assertEquals(new Coordinate(41.5,7.5), mapping.get(ring2).getShell().getCoord(2)); - assertEquals(new Coordinate(41.5,7.5), mapping.get(ring3).getShell().getCoord(2)); + assertTrue(added.get(0).getGeom() == mapping.get(ring3) + || added.get(1).getGeom() == mapping.get(ring3)); + assertTrue(added.get(0).getGeom() == mapping.get(ring2) + || added.get(1).getGeom() == mapping.get(ring2)); + assertEquals(2, map.getCoords(51, 12).size()); + assertEquals(new Coordinate(41.5, 7.5), mapping.get(ring2).getShell().getCoord(2)); + assertEquals(new Coordinate(41.5, 7.5), mapping.get(ring3).getShell().getCoord(2)); editBlackboardEvent = l.getEditBlackboardEvent(); assertEquals(null, editBlackboardEvent.getOldValue()); - assertEquals(Point.valueOf(51,12), editBlackboardEvent.getNewValue()); - assertTrue(((Collection) l.event.getSource()).contains(added.get(0).getPart()) ); - assertTrue(((Collection) l.event.getSource()).contains(added.get(1).getPart()) ); - + assertEquals(Point.valueOf(51, 12), editBlackboardEvent.getNewValue()); + assertTrue(((Collection) l.event.getSource()).contains(added.get(0).getPart())); + assertTrue(((Collection) l.event.getSource()).contains(added.get(1).getPart())); + // create hole one point at a time - map=new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); + map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); map.getListeners().add(l); geomShape = map.getGeoms().get(0); hole = geomShape.newHole(); - try{ - map.addPoint(0,0, null); + try { + map.addPoint(0, 0, null); fail(); - }catch (Exception e) { - //good + } catch (Exception e) { + // good } - - map.addPoint(0,0, hole); - assertEquals(Point.valueOf(0,0), l.getEditBlackboardEvent().getNewValue()); - map.addPoint(0,100, hole); - assertEquals(Point.valueOf(0,100), l.getEditBlackboardEvent().getNewValue()); - map.addPoint(50,100, hole); - assertEquals(Point.valueOf(50,100), l.getEditBlackboardEvent().getNewValue()); - map.addPoint(100,100, hole); - assertEquals(Point.valueOf(100,100), l.getEditBlackboardEvent().getNewValue()); - map.addPoint(50,150, hole); + + map.addPoint(0, 0, hole); + assertEquals(Point.valueOf(0, 0), l.getEditBlackboardEvent().getNewValue()); + map.addPoint(0, 100, hole); + assertEquals(Point.valueOf(0, 100), l.getEditBlackboardEvent().getNewValue()); + map.addPoint(50, 100, hole); + assertEquals(Point.valueOf(50, 100), l.getEditBlackboardEvent().getNewValue()); + map.addPoint(100, 100, hole); + assertEquals(Point.valueOf(100, 100), l.getEditBlackboardEvent().getNewValue()); + map.addPoint(50, 150, hole); assertEquals(null, l.getEditBlackboardEvent().getOldValue()); - assertEquals(Point.valueOf(50,150), l.getEditBlackboardEvent().getNewValue()); + assertEquals(Point.valueOf(50, 150), l.getEditBlackboardEvent().getNewValue()); assertEquals(hole, l.getEditBlackboardEvent().getSource()); - - - assertEquals(Point.valueOf(0,0), geomShape.getHoles().get(0).getPoint(0)); - assertEquals(Point.valueOf(0,100), geomShape.getHoles().get(0).getPoint(1)); - assertEquals(Point.valueOf(50,100), geomShape.getHoles().get(0).getPoint(2)); - assertEquals(Point.valueOf(100,100), geomShape.getHoles().get(0).getPoint(3)); - assertEquals(Point.valueOf(50,150), geomShape.getHoles().get(0).getPoint(4)); - - //test the coordinates were created correcly - assertEquals(new Coordinate(-9.5,-4.5), geomShape.getHoles().get(0).getCoord(0)); - assertEquals(new Coordinate(-9.5,95.5), geomShape.getHoles().get(0).getCoord(1)); - assertEquals(new Coordinate(40.5,95.5), geomShape.getHoles().get(0).getCoord(2)); - assertEquals(new Coordinate(90.5,95.5), geomShape.getHoles().get(0).getCoord(3)); - assertEquals(new Coordinate(40.5,145.5), geomShape.getHoles().get(0).getCoord(4)); + + assertEquals(Point.valueOf(0, 0), geomShape.getHoles().get(0).getPoint(0)); + assertEquals(Point.valueOf(0, 100), geomShape.getHoles().get(0).getPoint(1)); + assertEquals(Point.valueOf(50, 100), geomShape.getHoles().get(0).getPoint(2)); + assertEquals(Point.valueOf(100, 100), geomShape.getHoles().get(0).getPoint(3)); + assertEquals(Point.valueOf(50, 150), geomShape.getHoles().get(0).getPoint(4)); + + // test the coordinates were created correcly + assertEquals(new Coordinate(-9.5, -4.5), geomShape.getHoles().get(0).getCoord(0)); + assertEquals(new Coordinate(-9.5, 95.5), geomShape.getHoles().get(0).getCoord(1)); + assertEquals(new Coordinate(40.5, 95.5), geomShape.getHoles().get(0).getCoord(2)); + assertEquals(new Coordinate(90.5, 95.5), geomShape.getHoles().get(0).getCoord(3)); + assertEquals(new Coordinate(40.5, 145.5), geomShape.getHoles().get(0).getCoord(4)); // now making sure the the CoordMap is correctly updated too. - assertEquals(1, map.getCoords(0,0).size()); - assertEquals(new Coordinate(-9.5,-4.5), map.getCoords(0,0).get(0)); - assertEquals(1, map.getCoords(0,100).size()); - assertEquals(new Coordinate(-9.5,95.5), map.getCoords(0,100).get(0)); - assertEquals(1, map.getCoords(0,100).size()); - assertEquals(new Coordinate(40.5,95.5), map.getCoords(50,100).get(0)); - assertEquals(1, map.getCoords(0,100).size()); - assertEquals(new Coordinate(90.5,95.5), map.getCoords(100,100).get(0)); - assertEquals(1, map.getCoords(50,150).size()); - assertEquals(new Coordinate(40.5,145.5), map.getCoords(50,150).get(0)); - + assertEquals(1, map.getCoords(0, 0).size()); + assertEquals(new Coordinate(-9.5, -4.5), map.getCoords(0, 0).get(0)); + assertEquals(1, map.getCoords(0, 100).size()); + assertEquals(new Coordinate(-9.5, 95.5), map.getCoords(0, 100).get(0)); + assertEquals(1, map.getCoords(0, 100).size()); + assertEquals(new Coordinate(40.5, 95.5), map.getCoords(50, 100).get(0)); + assertEquals(1, map.getCoords(0, 100).size()); + assertEquals(new Coordinate(90.5, 95.5), map.getCoords(100, 100).get(0)); + assertEquals(1, map.getCoords(50, 150).size()); + assertEquals(new Coordinate(40.5, 145.5), map.getCoords(50, 150).get(0)); + // call add to edge so that it is added to a hole - polygon=createPolygon(factory, 10); - LinearRing ring1=createShellRing(factory, 10); - mapping=map.setGeometries(ring1, null); + polygon = createPolygon(factory, 10); + LinearRing ring1 = createShellRing(factory, 10); + mapping = map.setGeometries(ring1, null); mapping.putAll(map.addGeometry(polygon, null)); - added=map.addToNearestEdge(26,12, true); + added = map.addToNearestEdge(26, 12, true); assertEquals(1, added.size()); assertEquals(6, added.iterator().next().getGeom().getHoles().get(0).getNumCoords()); - - map=new EditBlackboard(SCREEN.x,SCREEN.y, transform, this.layerToWorld ); + + map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, this.layerToWorld); map.getListeners().add(l); - added=map.addToNearestEdge(26,12, true); - assertEquals(Point.valueOf(26,12), map.getGeoms().get(0).getShell().getPoint(0)); + added = map.addToNearestEdge(26, 12, true); + assertEquals(Point.valueOf(26, 12), map.getGeoms().get(0).getShell().getPoint(0)); } - /* - * Test method for 'org.locationtech.udig.tools.edit.support.PixelCoordMap.moveCoords(int, int, int, int)' + * Test method for 'org.locationtech.udig.tools.edit.support.PixelCoordMap.moveCoords(int, int, + * int, int)' */ @Test public void testMoveCoords() throws Exception, Exception { - EventListener l=new EventListener(); - GeometryFactory factory=new GeometryFactory(); - LinearRing ring1=createShellRing(factory, 10); - LinearRing ring2=createShellRing(factory, 10); - LinearRing ring3=createShellRing(factory, 10); - LinearRing ring4=createShellRing(factory, 40); - - EditBlackboard map = new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); + EventListener l = new EventListener(); + GeometryFactory factory = new GeometryFactory(); + LinearRing ring1 = createShellRing(factory, 10); + LinearRing ring2 = createShellRing(factory, 10); + LinearRing ring3 = createShellRing(factory, 10); + LinearRing ring4 = createShellRing(factory, 40); + + EditBlackboard map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); map.getListeners().add(l); Map mapping = map.setGeometries(ring1, null); mapping.putAll(map.addGeometry(ring2, null)); mapping.putAll(map.addGeometry(ring3, null)); mapping.putAll(map.addGeometry(ring4, null)); - assertPixMapState(map,4,5,0,0); - + assertPixMapState(map, 4, 5, 0, 0); + // move a vertex List modified = map.moveCoords(20, 10, 15, 0); assertEquals(6, modified.size()); - assertEquals(6, map.getCoords(15,0).size()); - assertEquals(0,map.getCoords(20,10).size()); + assertEquals(6, map.getCoords(15, 0).size()); + assertEquals(0, map.getCoords(20, 10).size()); assertEquals(new Coordinate(5, -5), mapping.get(ring1).getShell().getCoord(0)); assertEquals(new Coordinate(5, -5), mapping.get(ring1).getShell().getCoord(4)); EditBlackboardEvent editBlackboardEvent = l.getEditBlackboardEvent(); assertEquals(EventType.MOVE_POINT, l.event.getType()); - assertEquals(Point.valueOf(20,10), editBlackboardEvent.getOldValue()); - assertEquals(Point.valueOf(15,0), editBlackboardEvent.getNewValue()); + assertEquals(Point.valueOf(20, 10), editBlackboardEvent.getOldValue()); + assertEquals(Point.valueOf(15, 0), editBlackboardEvent.getNewValue()); assertEquals(new Coordinate(5, -5), mapping.get(ring2).getShell().getCoord(0)); assertEquals(new Coordinate(5, -5), mapping.get(ring2).getShell().getCoord(4)); - + assertEquals(new Coordinate(5, -5), mapping.get(ring3).getShell().getCoord(0)); assertEquals(new Coordinate(5, -5), mapping.get(ring3).getShell().getCoord(4)); - - assertEquals(3, map.getGeoms(15,0).size()); - assertEquals(0, map.getGeoms(20,10).size()); - - assertEquals( Point.valueOf(15,0), map.getGeoms().get(0).getShell().getPoint(0)); - - //put back - map.moveCoords(15,0, 20,10); + + assertEquals(3, map.getGeoms(15, 0).size()); + assertEquals(0, map.getGeoms(20, 10).size()); + + assertEquals(Point.valueOf(15, 0), map.getGeoms().get(0).getShell().getPoint(0)); + + // put back + map.moveCoords(15, 0, 20, 10); // move an edge (can't do it) - modified = map.moveCoords(25,10, 30, 0); + modified = map.moveCoords(25, 10, 30, 0); assertEquals(0, modified.size()); // move to location that contains coords... don't clobber - modified=map.moveCoords(20,10, 30, 10); + modified = map.moveCoords(20, 10, 30, 10); assertEquals(6, modified.size()); - assertEquals(9, map.getCoords(30,10).size()); - assertEquals(3, map.getGeoms(30,10).size()); - - map.moveCoords(50,10, 30, 10); - assertEquals(4, map.getGeoms(30,10).size()); - + assertEquals(9, map.getCoords(30, 10).size()); + assertEquals(3, map.getGeoms(30, 10).size()); + + map.moveCoords(50, 10, 30, 10); + assertEquals(4, map.getGeoms(30, 10).size()); + // test the case where the layer is not in the same projection as the map. - MathTransform albersToWGS84 = CRS.findMathTransform(CRS.decode("EPSG:3005"), DefaultGeographicCRS.WGS84, true); //$NON-NLS-1$ - map = new EditBlackboard(SCREEN.x,SCREEN.y, AffineTransform.getTranslateInstance(0,0), albersToWGS84); - - map.addPoint(0,0, map.getGeoms().get(0).getShell()); - map.addPoint(0,0, map.getGeoms().get(0).getShell()); - + MathTransform albersToWGS84 = CRS.findMathTransform(CRS.decode("EPSG:3005"), //$NON-NLS-1$ + DefaultGeographicCRS.WGS84, true); + map = new EditBlackboard(SCREEN.x, SCREEN.y, AffineTransform.getTranslateInstance(0, 0), + albersToWGS84); + + map.addPoint(0, 0, map.getGeoms().get(0).getShell()); + map.addPoint(0, 0, map.getGeoms().get(0).getShell()); + Coordinate c = new Coordinate(); - JTS.transform(map.getCoords(0,0).get(0), c, albersToWGS84); - - assertEquals(0, (int)c.x); - assertEquals(0, (int)c.y); - - map.moveCoords(0,0, 10,5); - - JTS.transform(map.getCoords(10,5).get(0), c, albersToWGS84); - - assertEquals(10, (int)c.x); - assertEquals(5, (int)c.y); - - JTS.transform(map.getCoords(10,5).get(1), c, albersToWGS84); - - assertEquals(10, (int)c.x); - assertEquals(5, (int)c.y); - + JTS.transform(map.getCoords(0, 0).get(0), c, albersToWGS84); + + assertEquals(0, (int) c.x); + assertEquals(0, (int) c.y); + + map.moveCoords(0, 0, 10, 5); + + JTS.transform(map.getCoords(10, 5).get(0), c, albersToWGS84); + + assertEquals(10, (int) c.x); + assertEquals(5, (int) c.y); + + JTS.transform(map.getCoords(10, 5).get(1), c, albersToWGS84); + + assertEquals(10, (int) c.x); + assertEquals(5, (int) c.y); + } /* - * Test method for 'org.locationtech.udig.tools.edit.support.PixelCoordMap.deleteCoords(int, int)' + * Test method for 'org.locationtech.udig.tools.edit.support.PixelCoordMap.deleteCoords(int, + * int)' */ @Test public void testDeleteCoords() { - - GeometryFactory factory=new GeometryFactory(); - LinearRing ring1=createShellRing(factory, 10); - LinearRing ring2=createShellRing(factory, 10); - LinearRing ring3=createShellRing(factory, 10); - EditBlackboard map = new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); - EventListener l=new EventListener(); + + GeometryFactory factory = new GeometryFactory(); + LinearRing ring1 = createShellRing(factory, 10); + LinearRing ring2 = createShellRing(factory, 10); + LinearRing ring3 = createShellRing(factory, 10); + EditBlackboard map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); + EventListener l = new EventListener(); map.getListeners().add(l); Map mapping = map.setGeometries(ring1, null); mapping.putAll(map.addGeometry(ring2, null)); mapping.putAll(map.addGeometry(ring3, null)); - assertPixMapState(map,3,5,0,0); - - List modified = map.removeCoordsAtPoint(20,10); + assertPixMapState(map, 3, 5, 0, 0); + + List modified = map.removeCoordsAtPoint(20, 10); assertEquals(6, modified.size()); assertEquals(3, mapping.get(ring1).getShell().getNumPoints()); - assertEquals(3, mapping.get(ring1).getShell().getNumCoords()); + assertEquals(3, mapping.get(ring1).getShell().getNumCoords()); EditBlackboardEvent editBlackboardEvent = l.getEditBlackboardEvent(); assertEquals(EventType.REMOVE_POINT, l.event.getType()); - assertEquals(Point.valueOf(20,10), editBlackboardEvent.getOldValue()); + assertEquals(Point.valueOf(20, 10), editBlackboardEvent.getOldValue()); assertEquals(null, editBlackboardEvent.getNewValue()); - assertEquals(3, mapping.get(ring2).getShell().getNumPoints()); assertEquals(3, mapping.get(ring2).getShell().getNumCoords()); assertEquals(3, mapping.get(ring3).getShell().getNumPoints()); assertEquals(3, mapping.get(ring3).getShell().getNumCoords()); - - assertEquals(0, map.getGeoms(20,10).size()); - + + assertEquals(0, map.getGeoms(20, 10).size()); + // delete nothing - modified=map.removeCoordsAtPoint(0,0); + modified = map.removeCoordsAtPoint(0, 0); assertEquals(0, modified.size()); - + // make sure this works on holes Polygon poly = createPolygon(factory, 10); - mapping=map.setGeometries(poly, null); - modified=map.removeCoordsAtPoint(25,12); + mapping = map.setGeometries(poly, null); + modified = map.removeCoordsAtPoint(25, 12); assertEquals(2, modified.size()); - assertEquals(3,mapping.get(poly).getHoles().get(0).getNumCoords()); - assertEquals(new Coordinate(15,7), modified.get(0)); - assertEquals(new Coordinate(15,7), modified.get(1)); + assertEquals(3, mapping.get(poly).getHoles().get(0).getNumCoords()); + assertEquals(new Coordinate(15, 7), modified.get(0)); + assertEquals(new Coordinate(15, 7), modified.get(1)); } - + @Test public void testTransform() throws Exception { - MathTransform t=CRS.findMathTransform(CRS.decode("EPSG:3005"), DefaultGeographicCRS.WGS84); //$NON-NLS-1$ + MathTransform t = CRS.findMathTransform(CRS.decode("EPSG:3005"), //$NON-NLS-1$ + DefaultGeographicCRS.WGS84); AffineTransform translateInstance = AffineTransform.getTranslateInstance(180, 90); - EditBlackboard map=new EditBlackboard( SCREEN.x, SCREEN.y, translateInstance, t); - - int x=-12+180; - int y=52+90; - - map.addPoint(x,y, map.getGeoms().get(0).getShell()); - double [] tmp=new double[]{ x+.5,y+.5 }; - double [] expected=new double[2]; - translateInstance.inverseTransform(tmp, 0,tmp,0,1); - t.inverse().transform(tmp, 0, expected,0,1); - assertEquals(new Coordinate(expected[0], expected[1]),map.getCoords(x,y).get(0)); + EditBlackboard map = new EditBlackboard(SCREEN.x, SCREEN.y, translateInstance, t); + + int x = -12 + 180; + int y = 52 + 90; + + map.addPoint(x, y, map.getGeoms().get(0).getShell()); + double[] tmp = new double[] { x + .5, y + .5 }; + double[] expected = new double[2]; + translateInstance.inverseTransform(tmp, 0, tmp, 0, 1); + t.inverse().transform(tmp, 0, expected, 0, 1); + assertEquals(new Coordinate(expected[0], expected[1]), map.getCoords(x, y).get(0)); } - + @Test public void testAddOverlappingVertex() throws Exception { - new PreferenceUtil(){ + new PreferenceUtil() { { - instance=this; + instance = this; } + @Override public int getVertexRadius() { return 4; } }; - EventListener l=new EventListener(); - EditBlackboard map = new EditBlackboard(SCREEN.x,SCREEN.y, transform, layerToWorld); + EventListener l = new EventListener(); + EditBlackboard map = new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld); map.getListeners().add(l); - + PrimitiveShape shell = map.getGeoms().get(0).getShell(); - - map.addPoint(10,10, shell); - map.addPoint(9,9, shell); - map.addPoint(9,10, shell); - map.addPoint(9,11, shell); - map.addPoint(10,9, shell); - map.addPoint(11,10, shell); - map.addPoint(11,9, shell); - map.addPoint(11,10, shell); - map.addPoint(11,11, shell); - - assertEquals(9, map.getCoords(10,10).size()); - assertEquals(0, map.getCoords(9,9).size()); - assertEquals(0, map.getCoords(9,10).size()); - assertEquals(0, map.getCoords(9,11).size()); - assertEquals(0, map.getCoords(10,9).size()); - assertEquals(0, map.getCoords(10,11).size()); - assertEquals(0, map.getCoords(11,9).size()); - assertEquals(0, map.getCoords(11,10).size()); - assertEquals(0, map.getCoords(11,11).size()); - new PreferenceUtil(){ + + map.addPoint(10, 10, shell); + map.addPoint(9, 9, shell); + map.addPoint(9, 10, shell); + map.addPoint(9, 11, shell); + map.addPoint(10, 9, shell); + map.addPoint(11, 10, shell); + map.addPoint(11, 9, shell); + map.addPoint(11, 10, shell); + map.addPoint(11, 11, shell); + + assertEquals(9, map.getCoords(10, 10).size()); + assertEquals(0, map.getCoords(9, 9).size()); + assertEquals(0, map.getCoords(9, 10).size()); + assertEquals(0, map.getCoords(9, 11).size()); + assertEquals(0, map.getCoords(10, 9).size()); + assertEquals(0, map.getCoords(10, 11).size()); + assertEquals(0, map.getCoords(11, 9).size()); + assertEquals(0, map.getCoords(11, 10).size()); + assertEquals(0, map.getCoords(11, 11).size()); + new PreferenceUtil() { { - instance=this; + instance = this; } + @Override public int getVertexRadius() { return 0; } - }; + }; } - + @Test public void testLakeDrawingCase() throws Exception { URL url = TestsPlugin.getDefault().getBundle().getResource("data/lake.gml"); //$NON-NLS-1$ InputStream in = url.openConnection().getInputStream(); - - InputStreamReader filereader=new InputStreamReader(in); - + + InputStreamReader filereader = new InputStreamReader(in); + InputSource input = new InputSource(filereader); DefaultFeatureCollection collection = new DefaultFeatureCollection(); - GMLReceiver receiver=new GMLReceiver(collection); + GMLReceiver receiver = new GMLReceiver(collection); GMLFilterFeature filterFeature = new GMLFilterFeature(receiver); GMLFilterGeometry filterGeometry = new GMLFilterGeometry(filterFeature); GMLFilterDocument filterDocument = new GMLFilterDocument(filterGeometry); try { - // parse xml - XMLReader reader = XMLReaderFactory.createXMLReader(); + + // parse XML + + SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParser parser = factory.newSAXParser(); + XMLReader reader = parser.getXMLReader(); + reader.setContentHandler(filterDocument); reader.parse(input); + } catch (Exception e) { throw new RuntimeException(e); } - SimpleFeature feature=collection.features().next(); + SimpleFeature feature = collection.features().next(); ReferencedEnvelope bounds = new ReferencedEnvelope(feature.getBounds()); - bounds=new ReferencedEnvelope( bounds.getMinX()-(bounds.getWidth()/8), - bounds.getMaxX()+(bounds.getWidth()/8), - bounds.getMinY()-(bounds.getHeight()/4), - bounds.getMaxY()+(bounds.getHeight()/4), DefaultGeographicCRS.WGS84 ); - EditBlackboard map=new EditBlackboard(SCREEN.x, SCREEN.y, ScaleUtils.worldToScreenTransform(bounds, new Dimension(100,100)), layerToWorld); - + bounds = new ReferencedEnvelope(bounds.getMinX() - (bounds.getWidth() / 8), + bounds.getMaxX() + (bounds.getWidth() / 8), + bounds.getMinY() - (bounds.getHeight() / 4), + bounds.getMaxY() + (bounds.getHeight() / 4), DefaultGeographicCRS.WGS84); + EditBlackboard map = new EditBlackboard(SCREEN.x, SCREEN.y, + ScaleUtils.worldToScreenTransform(bounds, new Dimension(100, 100)), layerToWorld); + map.setGeometries((Geometry) feature.getDefaultGeometry(), null); - - Polygon poly=(Polygon) ((MultiPolygon) feature.getDefaultGeometry()).getGeometryN(0); - + + Polygon poly = (Polygon) ((MultiPolygon) feature.getDefaultGeometry()).getGeometryN(0); + PrimitiveShape shell = map.getGeoms().get(0).getShell(); assertEquals(poly.getExteriorRing().getCoordinates().length, shell.getNumCoords()); - for (int i=0; i batched; + // only the events that are raised by changed() - List allEvents=new ArrayList(); - - EditBlackboardEvent getEditBlackboardEvent(){ + List allEvents = new ArrayList<>(); + + EditBlackboardEvent getEditBlackboardEvent() { EditBlackboardEvent result = event; return result; } - public void changed( EditBlackboardEvent e ) { - event=e; + @Override + public void changed(EditBlackboardEvent e) { + event = e; allEvents.add(e); } - - public void batchChange( List e ) { - batched=e; + + @Override + public void batchChange(List e) { + batched = e; } } - - } diff --git a/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/TimingTests.java b/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/TimingTests.java index 0e5f4196b7..fd0db55df0 100644 --- a/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/TimingTests.java +++ b/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/TimingTests.java @@ -1,7 +1,7 @@ -/* - * uDig - User Friendly Desktop Internet GIS client - * http://udig.refractions.net - * (C) 2012, Refractions Research Inc. +/** + * uDig - User Friendly Desktop Internet GIS client + * http://udig.refractions.net + * (C) 2012, Refractions Research Inc. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -16,6 +16,9 @@ import java.net.URL; import java.util.Random; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + import org.geotools.feature.DefaultFeatureCollection; import org.geotools.geometry.jts.ReferencedEnvelope; import org.geotools.gml.GMLFilterDocument; @@ -33,77 +36,86 @@ import org.opengis.referencing.operation.MathTransform; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; public class TimingTests { - + private static final MathTransform layerToWorld; static { try { - layerToWorld=CRS.findMathTransform(DefaultGeographicCRS.WGS84, DefaultGeographicCRS.WGS84); + layerToWorld = CRS.findMathTransform(DefaultGeographicCRS.WGS84, + DefaultGeographicCRS.WGS84); } catch (FactoryException e) { - throw (RuntimeException) new RuntimeException( ).initCause( e ); - } + throw (RuntimeException) new RuntimeException().initCause(e); + } } @Test(timeout = 5000) - public void testPointCreation(){ - Random r=new Random(298719283471298L); - - for( int j=0; j<1000; j++){ - r=new Random(298719283471298L); - for( int i=0; i<100000;i++) - Point.valueOf(r.nextInt(1000),r.nextInt(1000)); - } + public void testPointCreation() { + Random r = new Random(298719283471298L); + + for (int j = 0; j < 1000; j++) { + r = new Random(298719283471298L); + for (int i = 0; i < 100000; i++) + Point.valueOf(r.nextInt(1000), r.nextInt(1000)); + } } - + @Test public void testPrimitiveShapeIterator() throws Exception { URL url = TestsPlugin.getDefault().getBundle().getResource("data/lake.gml"); //$NON-NLS-1$ InputStream in = url.openConnection().getInputStream(); - - InputStreamReader filereader=new InputStreamReader(in); - + + InputStreamReader filereader = new InputStreamReader(in); + InputSource input = new InputSource(filereader); DefaultFeatureCollection collection = new DefaultFeatureCollection(); - GMLReceiver receiver=new GMLReceiver(collection); + GMLReceiver receiver = new GMLReceiver(collection); GMLFilterFeature filterFeature = new GMLFilterFeature(receiver); GMLFilterGeometry filterGeometry = new GMLFilterGeometry(filterFeature); GMLFilterDocument filterDocument = new GMLFilterDocument(filterGeometry); try { - // parse xml - XMLReader reader = XMLReaderFactory.createXMLReader(); + + // parse XML + + SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParser parser = factory.newSAXParser(); + XMLReader reader = parser.getXMLReader(); + reader.setContentHandler(filterDocument); reader.parse(input); + } catch (Exception e) { throw new RuntimeException(e); } - SimpleFeature feature=collection.features().next(); - ReferencedEnvelope bounds = new ReferencedEnvelope( feature.getBounds() ); - bounds=new ReferencedEnvelope( bounds.getMinX()-(bounds.getWidth()/8), - bounds.getMaxX()+(bounds.getWidth()/8), - bounds.getMinY()-(bounds.getHeight()/4), - bounds.getMaxY()+(bounds.getHeight()/4), bounds.getCoordinateReferenceSystem() ); - EditBlackboard map=new EditBlackboard(500, 500, ScaleUtils.worldToScreenTransform(bounds, new Dimension(1000,1000)), layerToWorld); - - PrimitiveShape shell = map.setGeometries((Geometry)feature.getDefaultGeometry(), null).values().iterator().next().getShell(); - System.out.println( shell.getNumPoints()); - System.out.println( shell.getNumCoords()); - -// long start=System.currentTimeMillis(); -// -// for( int i=0; i<1000; i++){ -// for( Point point : shell ){ -// for( int j=0; j<1000; j++ ){ -// point.getX(); point.getY(); -// } -// } -// } -// -// long end=System.currentTimeMillis(); -// -// System.out.println("Time to iterate through 10000 points 1000 times is: " + (end-start) +" msec"); //$NON-NLS-1$ //$NON-NLS-2$ -// + SimpleFeature feature = collection.features().next(); + ReferencedEnvelope bounds = new ReferencedEnvelope(feature.getBounds()); + bounds = new ReferencedEnvelope(bounds.getMinX() - (bounds.getWidth() / 8), + bounds.getMaxX() + (bounds.getWidth() / 8), + bounds.getMinY() - (bounds.getHeight() / 4), + bounds.getMaxY() + (bounds.getHeight() / 4), bounds.getCoordinateReferenceSystem()); + EditBlackboard map = new EditBlackboard(500, 500, + ScaleUtils.worldToScreenTransform(bounds, new Dimension(1000, 1000)), layerToWorld); + + PrimitiveShape shell = map.setGeometries((Geometry) feature.getDefaultGeometry(), null) + .values().iterator().next().getShell(); + System.out.println(shell.getNumPoints()); + System.out.println(shell.getNumCoords()); + + // long start=System.currentTimeMillis(); + // + // for( int i=0; i<1000; i++){ + // for( Point point : shell ){ + // for( int j=0; j<1000; j++ ){ + // point.getX(); point.getY(); + // } + // } + // } + // + // long end=System.currentTimeMillis(); + // + // System.out.println("Time to iterate through 10000 points 1000 times is: " + (end-start) + // +" msec"); //$NON-NLS-1$ //$NON-NLS-2$ + // } } diff --git a/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FeatureTextTransfer.java b/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FeatureTextTransfer.java index d3295d7b06..abdfe56dd9 100644 --- a/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FeatureTextTransfer.java +++ b/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FeatureTextTransfer.java @@ -12,6 +12,8 @@ import java.io.StringReader; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.TransformerException; import org.eclipse.swt.dnd.TextTransfer; @@ -34,7 +36,6 @@ import org.opengis.feature.simple.SimpleFeatureType; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; -import org.xml.sax.helpers.XMLReaderFactory; public class FeatureTextTransfer extends AbstractTextStrategizedTransfer implements UDIGTransfer { private static FeatureTextTransfer _instance = new FeatureTextTransfer(); @@ -126,10 +127,16 @@ public Object nativeToJava(TransferData transferData) { GMLFilterGeometry filterGeometry = new GMLFilterGeometry(filterFeature); GMLFilterDocument filterDocument = new GMLFilterDocument(filterGeometry); try { + // parse XML - XMLReader reader = XMLReaderFactory.createXMLReader(); + + SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParser parser = factory.newSAXParser(); + XMLReader reader = parser.getXMLReader(); + reader.setContentHandler(filterDocument); reader.parse(input); + } catch (Exception e) { throw new RuntimeException(e); } diff --git a/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FilterTextTransfer.java b/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FilterTextTransfer.java index 1e54cd9513..8871f48b75 100644 --- a/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FilterTextTransfer.java +++ b/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FilterTextTransfer.java @@ -1,4 +1,5 @@ -/* uDig - User Friendly Desktop Internet GIS client +/** + * uDig - User Friendly Desktop Internet GIS client * http://udig.refractions.net * (C) 2004, Refractions Research Inc. * @@ -11,6 +12,8 @@ import java.io.StringReader; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.TransformerException; import org.eclipse.swt.dnd.TextTransfer; @@ -26,69 +29,68 @@ import org.xml.sax.InputSource; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; -import org.xml.sax.helpers.XMLReaderFactory; /** * To Transfer Filters in text form. - * + * * @author jones * @since 1.0.0 */ -public class FilterTextTransfer extends AbstractTextStrategizedTransfer implements UDIGTransfer{ +public class FilterTextTransfer extends AbstractTextStrategizedTransfer implements UDIGTransfer { private static FilterTextTransfer _instance = new FilterTextTransfer(); + private FilterTextTransfer() { } /** * Returns the singleton instance of the TextTransfer class. - * + * * @return the singleton instance of the TextTransfer class */ public static FilterTextTransfer getInstance() { return _instance; } - private TransferStrategy[] transferStrategies ; + private TransferStrategy[] transferStrategies; - @Override - public - synchronized TransferStrategy[] getAllStrategies() { - if( transferStrategies==null ){ - transferStrategies=new TransferStrategy[]{new GMLFilterStrategy()}; - } + @Override + public synchronized TransferStrategy[] getAllStrategies() { + if (transferStrategies == null) { + transferStrategies = new TransferStrategy[] { new GMLFilterStrategy() }; + } - TransferStrategy[] copy=new TransferStrategy[transferStrategies.length]; + TransferStrategy[] copy = new TransferStrategy[transferStrategies.length]; System.arraycopy(transferStrategies, 0, copy, 0, transferStrategies.length); - return copy; - } - + return copy; + } + @Override public String[] getStrategyNames() { - return new String[]{"GML"}; //$NON-NLS-1$ + return new String[] { "GML" }; //$NON-NLS-1$ } - + @Override public String getTransferName() { return "Filter"; //$NON-NLS-1$ } - - @Override - public TransferStrategy getDefaultStrategy() { - return getAllStrategies()[0]; - } + @Override + public TransferStrategy getDefaultStrategy() { + return getAllStrategies()[0]; + } @Override public TransferData[] getSupportedTypes() { - return TextTransfer.getInstance().getSupportedTypes(); + return TextTransfer.getInstance().getSupportedTypes(); } - + @Override public boolean isSupportedType(TransferData transferData) { - return TextTransfer.getInstance().isSupportedType(transferData); + return TextTransfer.getInstance().isSupportedType(transferData); } - - public boolean validate( Object object ) { + + @Override + public boolean validate(Object object) { return object instanceof Filter; } @@ -96,7 +98,8 @@ public static class SimpleFilterHandler extends DefaultHandler implements Filter private org.opengis.filter.Filter filter; - public void filter( org.opengis.filter.Filter filter ) { + @Override + public void filter(org.opengis.filter.Filter filter) { this.filter = filter; } @@ -106,11 +109,12 @@ public org.opengis.filter.Filter getFilter() { } - private static class GMLFilterStrategy implements TransferStrategy{ + private static class GMLFilterStrategy implements TransferStrategy { /** * @see Transfer#javaToNative */ - public void javaToNative( Object object, TransferData transferData ) { + @Override + public void javaToNative(Object object, TransferData transferData) { Filter filter = (Filter) object; FilterTransformer transformer = new FilterTransformer(); transformer.setIndentation(4); @@ -125,8 +129,9 @@ public void javaToNative( Object object, TransferData transferData ) { /** * @see Transfer#nativeToJava */ - public Object nativeToJava( TransferData transferData ) { - String string = (String) TextTransfer.getInstance().nativeToJava(transferData); + @Override + public Object nativeToJava(TransferData transferData) { + String string = (String) TextTransfer.getInstance().nativeToJava(transferData); InputSource input = new InputSource(new StringReader(string)); SimpleFilterHandler simpleFilterHandler = new SimpleFilterHandler(); FilterFilter filterFilter = new FilterFilter(simpleFilterHandler, null); @@ -134,15 +139,21 @@ public Object nativeToJava( TransferData transferData ) { GMLFilterDocument filterDocument = new GMLFilterDocument(filterGeometry); try { - // parse xml - XMLReader reader = XMLReaderFactory.createXMLReader(); + + // parse XML + + SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParser parser = factory.newSAXParser(); + XMLReader reader = parser.getXMLReader(); + reader.setContentHandler(filterDocument); reader.parse(input); + } catch (Exception e) { throw new RuntimeException(e); } return simpleFilterHandler.getFilter(); - } + } } } From 8b81d27f2ca50cf83b73a7110fa6b9acb7021e52 Mon Sep 17 00:00:00 2001 From: Sebastian Schulz Date: Wed, 29 Dec 2021 12:57:02 +0100 Subject: [PATCH 2/2] Add missing flag 'namespace aware' to new SAXParserFactory --- .../interceptor/CacheInterceptor.java | 2 + .../interceptor/ShowViewInterceptor.java | 2 + .../behaviour/MoveVertexBehaviorTest.java | 331 +++++++++--------- .../edit/support/EditBlackboardTest.java | 4 + .../udig/tools/edit/support/TimingTests.java | 2 + .../udig/internal/ui/FeatureTextTransfer.java | 2 + .../udig/internal/ui/FilterTextTransfer.java | 2 + 7 files changed, 183 insertions(+), 162 deletions(-) diff --git a/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/CacheInterceptor.java b/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/CacheInterceptor.java index 6bd1d8292b..0b4a865577 100644 --- a/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/CacheInterceptor.java +++ b/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/CacheInterceptor.java @@ -218,6 +218,8 @@ private Filter readFilter(String textData) { // parse XML SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); diff --git a/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/ShowViewInterceptor.java b/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/ShowViewInterceptor.java index d536ff03ad..2229facbc8 100644 --- a/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/ShowViewInterceptor.java +++ b/plugins/org.locationtech.udig.project/src/org/locationtech/udig/project/internal/interceptor/ShowViewInterceptor.java @@ -307,6 +307,8 @@ private Filter readFilter(String textData) { // parse XML SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); diff --git a/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/behaviour/MoveVertexBehaviorTest.java b/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/behaviour/MoveVertexBehaviorTest.java index 5c2e3f260d..11929af2a5 100644 --- a/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/behaviour/MoveVertexBehaviorTest.java +++ b/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/behaviour/MoveVertexBehaviorTest.java @@ -1,7 +1,7 @@ -/* - * uDig - User Friendly Desktop Internet GIS client - * http://udig.refractions.net - * (C) 2012, Refractions Research Inc. +/** + * uDig - User Friendly Desktop Internet GIS client + * http://udig.refractions.net + * (C) 2012, Refractions Research Inc. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -18,6 +18,14 @@ import java.awt.Dimension; import java.util.List; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.geotools.data.FeatureSource; +import org.geotools.geometry.jts.JTS; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.locationtech.jts.geom.Coordinate; +import org.locationtech.jts.geom.Geometry; import org.locationtech.udig.project.ILayer; import org.locationtech.udig.project.command.CommandManager; import org.locationtech.udig.project.internal.Map; @@ -32,277 +40,279 @@ import org.locationtech.udig.tools.edit.support.Point; import org.locationtech.udig.tools.edit.support.SnapBehaviour; import org.locationtech.udig.tools.edit.support.TestHandler; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.geotools.data.FeatureSource; -import org.geotools.geometry.jts.JTS; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; -import org.locationtech.jts.geom.Coordinate; -import org.locationtech.jts.geom.Geometry; - public class MoveVertexBehaviorTest { - static final int BUTTON1=MapMouseEvent.BUTTON1; - static final int BUTTON2=MapMouseEvent.BUTTON2; - static final int NONE=MapMouseEvent.NONE; - static final int SHIFT=MapMouseEvent.SHIFT_DOWN_MASK; - static final int CTRL=MapMouseEvent.CTRL_DOWN_MASK; - static final TestMapDisplay DISPLAY = new TestMapDisplay(new Dimension(500,500)); + static final int BUTTON1 = MapMouseEvent.BUTTON1; + + static final int BUTTON2 = MapMouseEvent.BUTTON2; + + static final int NONE = MapMouseEvent.NONE; + + static final int SHIFT = MapMouseEvent.SHIFT_DOWN_MASK; + + static final int CTRL = MapMouseEvent.CTRL_DOWN_MASK; + + static final TestMapDisplay DISPLAY = new TestMapDisplay(new Dimension(500, 500)); + private MoveVertexBehaviour mode; + private TestHandler handler; + private EditBlackboard editBlackboard; @Before public void setUp() throws Exception { - mode=new MoveVertexBehaviour(); - handler=new TestHandler(); + mode = new MoveVertexBehaviour(); + handler = new TestHandler(); handler.getTestEditBlackboard().util.setVertexRadius(4); handler.getTestEditBlackboard().util.setSnappingRadius(0); - MapMouseEvent event=new MapMouseEvent( DISPLAY, 10,10,NONE,BUTTON1, BUTTON1 ); + MapMouseEvent event = new MapMouseEvent(DISPLAY, 10, 10, NONE, BUTTON1, BUTTON1); assertFalse(mode.isValid(handler, event, EventType.DRAGGED)); editBlackboard = handler.getEditBlackboard(); EditGeom currentGeom = editBlackboard.getGeoms().get(0); - editBlackboard.addPoint(10,10, currentGeom.getShell()); - editBlackboard.addPoint(20,10, currentGeom.getShell()); - editBlackboard.addPoint(30,10, currentGeom.getShell()); + editBlackboard.addPoint(10, 10, currentGeom.getShell()); + editBlackboard.addPoint(20, 10, currentGeom.getShell()); + editBlackboard.addPoint(30, 10, currentGeom.getShell()); handler.setCurrentShape(currentGeom.getShell()); } - /* - * Test method for 'org.locationtech.udig.tools.edit.mode.MoveVertexMode.isValid(EditToolHandler, MapMouseEvent, EventType)' + /** + * Test method for + * 'org.locationtech.udig.tools.edit.mode.MoveVertexMode.isValid(EditToolHandler, MapMouseEvent, + * EventType)' */ @Test public void testIsValid() { - handler.getEditBlackboard().selectionAdd( Point.valueOf(10,10) ); - handler.getMouseTracker().setDragStarted(Point.valueOf(10,10)); + handler.getEditBlackboard().selectionAdd(Point.valueOf(10, 10)); + handler.getMouseTracker().setDragStarted(Point.valueOf(10, 10)); - MapMouseEvent event = new MapMouseEvent( DISPLAY, 10,10,NONE,BUTTON1, BUTTON1 ); + MapMouseEvent event = new MapMouseEvent(DISPLAY, 10, 10, NONE, BUTTON1, BUTTON1); assertTrue(mode.isValid(handler, event, EventType.DRAGGED)); handler.setCurrentState(EditState.MODIFYING); - event=new MapMouseEvent( DISPLAY, 10,10,NONE,BUTTON1, BUTTON1 ); + event = new MapMouseEvent(DISPLAY, 10, 10, NONE, BUTTON1, BUTTON1); assertTrue(mode.isValid(handler, event, EventType.DRAGGED)); // button isn't button1 - event=new MapMouseEvent( DISPLAY, 10,10,NONE, BUTTON2, BUTTON1 ); + event = new MapMouseEvent(DISPLAY, 10, 10, NONE, BUTTON2, BUTTON1); assertFalse(mode.isValid(handler, event, EventType.DRAGGED)); // not dragged event type - event=new MapMouseEvent( DISPLAY, 10,10,NONE,BUTTON1, BUTTON1 ); + event = new MapMouseEvent(DISPLAY, 10, 10, NONE, BUTTON1, BUTTON1); assertFalse(mode.isValid(handler, event, EventType.RELEASED)); // a modifier is down - event=new MapMouseEvent( DISPLAY, 10,10, CTRL, BUTTON1, BUTTON1 ); + event = new MapMouseEvent(DISPLAY, 10, 10, CTRL, BUTTON1, BUTTON1); assertFalse(mode.isValid(handler, event, EventType.DRAGGED)); // drag did not start over a selected vertex - handler.getMouseTracker().setDragStarted(Point.valueOf(0,10)); - event=new MapMouseEvent( DISPLAY, 10,10, NONE, BUTTON1, BUTTON1 ); + handler.getMouseTracker().setDragStarted(Point.valueOf(0, 10)); + event = new MapMouseEvent(DISPLAY, 10, 10, NONE, BUTTON1, BUTTON1); assertFalse(mode.isValid(handler, event, EventType.DRAGGED)); - handler.getMouseTracker().setDragStarted(Point.valueOf(10,10)); + handler.getMouseTracker().setDragStarted(Point.valueOf(10, 10)); // state is not MODIFIED or NONE handler.setCurrentState(EditState.CREATING); - event=new MapMouseEvent( DISPLAY, 10,10, NONE, BUTTON1, BUTTON1 ); + event = new MapMouseEvent(DISPLAY, 10, 10, NONE, BUTTON1, BUTTON1); assertFalse(mode.isValid(handler, event, EventType.DRAGGED)); - handler.setCurrentState(EditState.MODIFYING); assertTrue(mode.isValid(handler, event, EventType.DRAGGED)); } - /* - * Test method for 'org.locationtech.udig.tools.edit.mode.MoveVertexMode.run(EditToolHandler, MapMouseEvent, EventType)' + /** + * Test method for 'org.locationtech.udig.tools.edit.mode.MoveVertexMode.run(EditToolHandler, + * MapMouseEvent, EventType)' */ @Test public void testRun() throws Exception { - handler.getEditBlackboard().selectionAdd(Point.valueOf(10,10)); + handler.getEditBlackboard().selectionAdd(Point.valueOf(10, 10)); - MapMouseEvent event=new MapMouseEvent( DISPLAY, 10,15,NONE,BUTTON1, BUTTON1 ); - try{ + MapMouseEvent event = new MapMouseEvent(DISPLAY, 10, 15, NONE, BUTTON1, BUTTON1); + try { mode.getCommand(handler, event, EventType.RELEASED); fail(); - }catch (Exception e) { + } catch (Exception e) { // good behaviour because mode only works on EventType.DRAGGED } - handler.getMouseTracker().setDragStarted(Point.valueOf(10,10)); + handler.getMouseTracker().setDragStarted(Point.valueOf(10, 10)); mode.getCommand(handler, event, EventType.DRAGGED); - assertEquals(1, editBlackboard.getCoords(10,15).size()); - assertEquals(0, editBlackboard.getCoords(10,10).size()); + assertEquals(1, editBlackboard.getCoords(10, 15).size()); + assertEquals(0, editBlackboard.getCoords(10, 10).size()); assertEquals(1, handler.getEditBlackboard().getSelection().size()); - assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(10,15))); + assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(10, 15))); - //return to original position. - event=new MapMouseEvent( DISPLAY, 10,10,NONE,BUTTON1, BUTTON1 ); - handler.getMouseTracker().setDragStarted(Point.valueOf(10,15)); + // return to original position. + event = new MapMouseEvent(DISPLAY, 10, 10, NONE, BUTTON1, BUTTON1); + handler.getMouseTracker().setDragStarted(Point.valueOf(10, 15)); mode.getCommand(handler, event, EventType.DRAGGED); - assertEquals(1, editBlackboard.getCoords(10,10).size()); - assertEquals(0, editBlackboard.getCoords(10,15).size()); + assertEquals(1, editBlackboard.getCoords(10, 10).size()); + assertEquals(0, editBlackboard.getCoords(10, 15).size()); - //move 2 points - handler.getEditBlackboard().selectionAdd(Point.valueOf(20,10)); + // move 2 points + handler.getEditBlackboard().selectionAdd(Point.valueOf(20, 10)); assertEquals(2, handler.getEditBlackboard().getSelection().size()); handler.unlock(mode); - mode=new MoveVertexBehaviour(); + mode = new MoveVertexBehaviour(); - handler.getMouseTracker().setDragStarted(Point.valueOf(10,10)); - event=new MapMouseEvent( DISPLAY, 10,15,NONE,BUTTON1, BUTTON1 ); + handler.getMouseTracker().setDragStarted(Point.valueOf(10, 10)); + event = new MapMouseEvent(DISPLAY, 10, 15, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); - assertEquals(1, editBlackboard.getCoords(10,15).size()); - assertEquals(0, editBlackboard.getCoords(10,10).size()); - assertEquals(1, editBlackboard.getCoords(20,15).size()); - assertEquals(0, editBlackboard.getCoords(20,10).size()); - handler.getMouseTracker().setDragStarted(Point.valueOf(10,15)); - event=new MapMouseEvent( DISPLAY, 10,10,NONE,BUTTON1, BUTTON1 ); + assertEquals(1, editBlackboard.getCoords(10, 15).size()); + assertEquals(0, editBlackboard.getCoords(10, 10).size()); + assertEquals(1, editBlackboard.getCoords(20, 15).size()); + assertEquals(0, editBlackboard.getCoords(20, 10).size()); + handler.getMouseTracker().setDragStarted(Point.valueOf(10, 15)); + event = new MapMouseEvent(DISPLAY, 10, 10, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); - assertEquals(1, editBlackboard.getCoords(10,10).size()); - assertEquals(0, editBlackboard.getCoords(10,15).size()); - + assertEquals(1, editBlackboard.getCoords(10, 10).size()); + assertEquals(0, editBlackboard.getCoords(10, 15).size()); } @Test public void testUndo() throws Exception { - editBlackboard.selectionAdd(Point.valueOf(10,10)); - editBlackboard.selectionAdd(Point.valueOf(20,10)); + editBlackboard.selectionAdd(Point.valueOf(10, 10)); + editBlackboard.selectionAdd(Point.valueOf(20, 10)); EditBlackboard bb = handler.getEditBlackboard(); - handler.getMouseTracker().setDragStarted(Point.valueOf(10,10)); - MapMouseEvent event = new MapMouseEvent( DISPLAY, 10,11,NONE,BUTTON1, BUTTON1 ); + handler.getMouseTracker().setDragStarted(Point.valueOf(10, 10)); + MapMouseEvent event = new MapMouseEvent(DISPLAY, 10, 11, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); - assertEquals(1, bb.getCoords(10,11).size()); - assertTrue(handler.getCurrentShape().hasVertex(Point.valueOf(10,11))); + assertEquals(1, bb.getCoords(10, 11).size()); + assertTrue(handler.getCurrentShape().hasVertex(Point.valueOf(10, 11))); - event = new MapMouseEvent( DISPLAY, 10,12,NONE,BUTTON1, BUTTON1 ); + event = new MapMouseEvent(DISPLAY, 10, 12, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); - assertEquals(1, bb.getCoords(10,12).size()); - assertTrue(handler.getCurrentShape().hasVertex(Point.valueOf(10,12))); + assertEquals(1, bb.getCoords(10, 12).size()); + assertTrue(handler.getCurrentShape().hasVertex(Point.valueOf(10, 12))); - event = new MapMouseEvent( DISPLAY, 10,13,NONE,BUTTON1, BUTTON1 ); + event = new MapMouseEvent(DISPLAY, 10, 13, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); - assertEquals(1, bb.getCoords(10,13).size()); - assertTrue(handler.getCurrentShape().hasVertex(Point.valueOf(10,13))); + assertEquals(1, bb.getCoords(10, 13).size()); + assertTrue(handler.getCurrentShape().hasVertex(Point.valueOf(10, 13))); - event = new MapMouseEvent( DISPLAY, 10,14,NONE,BUTTON1, BUTTON1 ); + event = new MapMouseEvent(DISPLAY, 10, 14, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); - assertEquals(1, bb.getCoords(10,14).size()); - assertTrue(handler.getCurrentShape().hasVertex(Point.valueOf(10,14))); + assertEquals(1, bb.getCoords(10, 14).size()); + assertTrue(handler.getCurrentShape().hasVertex(Point.valueOf(10, 14))); - event = new MapMouseEvent( DISPLAY, 10,15,NONE,BUTTON1, BUTTON1 ); + event = new MapMouseEvent(DISPLAY, 10, 15, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); - assertEquals(1, bb.getCoords(10,15).size()); - assertTrue(handler.getCurrentShape().hasVertex(Point.valueOf(10,15))); + assertEquals(1, bb.getCoords(10, 15).size()); + assertTrue(handler.getCurrentShape().hasVertex(Point.valueOf(10, 15))); - assertEquals(1, editBlackboard.getCoords(10,15).size()); - assertEquals(1, editBlackboard.getCoords(20,15).size()); - assertEquals(0, editBlackboard.getCoords(10,10).size()); - assertEquals(0, editBlackboard.getCoords(20,10).size()); + assertEquals(1, editBlackboard.getCoords(10, 15).size()); + assertEquals(1, editBlackboard.getCoords(20, 15).size()); + assertEquals(0, editBlackboard.getCoords(10, 10).size()); + assertEquals(0, editBlackboard.getCoords(20, 10).size()); - //test undo first button must release so the Position tracker will execute: - event=new MapMouseEvent( DISPLAY, 10,10,NONE,BUTTON1, BUTTON1 ); + // test undo first button must release so the Position tracker will execute: + event = new MapMouseEvent(DISPLAY, 10, 10, NONE, BUTTON1, BUTTON1); EventBehaviour tracker = findPositionTracker(); - handler.getContext().getMap().sendCommandSync(tracker.getCommand(handler, event, EventType.RELEASED)); + handler.getContext().getMap() + .sendCommandSync(tracker.getCommand(handler, event, EventType.RELEASED)); - assertEquals(1, editBlackboard.getCoords(10,15).size()); - assertEquals(1, editBlackboard.getCoords(20,15).size()); - assertEquals(0, editBlackboard.getCoords(10,10).size()); - assertEquals(0, editBlackboard.getCoords(20,10).size()); + assertEquals(1, editBlackboard.getCoords(10, 15).size()); + assertEquals(1, editBlackboard.getCoords(20, 15).size()); + assertEquals(0, editBlackboard.getCoords(10, 10).size()); + assertEquals(0, editBlackboard.getCoords(20, 10).size()); - ((CommandManager)((Map)handler.getContext().getMap()).getCommandStack()).undo(false); + ((CommandManager) ((Map) handler.getContext().getMap()).getCommandStack()).undo(false); - assertEquals(0, editBlackboard.getCoords(10,15).size()); - assertEquals(0, editBlackboard.getCoords(20,15).size()); - assertEquals(1, editBlackboard.getCoords(10,10).size()); - assertEquals(1, editBlackboard.getCoords(20,10).size()); + assertEquals(0, editBlackboard.getCoords(10, 15).size()); + assertEquals(0, editBlackboard.getCoords(20, 15).size()); + assertEquals(1, editBlackboard.getCoords(10, 10).size()); + assertEquals(1, editBlackboard.getCoords(20, 10).size()); - ((CommandManager)((Map)handler.getContext().getMap()).getCommandStack()).redo(false); + ((CommandManager) ((Map) handler.getContext().getMap()).getCommandStack()).redo(false); - assertEquals(1, editBlackboard.getCoords(10,15).size()); - assertEquals(1, editBlackboard.getCoords(20,15).size()); - assertEquals(0, editBlackboard.getCoords(10,10).size()); - assertEquals(0, editBlackboard.getCoords(20,10).size()); + assertEquals(1, editBlackboard.getCoords(10, 15).size()); + assertEquals(1, editBlackboard.getCoords(20, 15).size()); + assertEquals(0, editBlackboard.getCoords(10, 10).size()); + assertEquals(0, editBlackboard.getCoords(20, 10).size()); } @Ignore @Test public void testPostSnapping() throws Exception { EditGeom newGeom = editBlackboard.newGeom("id", null); //$NON-NLS-1$ - editBlackboard.addPoint(30,20, newGeom.getShell()); - editBlackboard.addPoint(30,40, newGeom.getShell()); + editBlackboard.addPoint(30, 20, newGeom.getShell()); + editBlackboard.addPoint(30, 40, newGeom.getShell()); PreferenceUtil.instance().setSnapBehaviour(SnapBehaviour.ALL_LAYERS); handler.getTestEditBlackboard().util.setSnappingRadius(12); - editBlackboard.selectionAdd(Point.valueOf(10,10)); + editBlackboard.selectionAdd(Point.valueOf(10, 10)); - handler.getMouseTracker().setDragStarted(Point.valueOf(10,12)); - MapMouseEvent event = new MapMouseEvent( DISPLAY, 10,13,NONE,BUTTON1, BUTTON1 ); + handler.getMouseTracker().setDragStarted(Point.valueOf(10, 12)); + MapMouseEvent event = new MapMouseEvent(DISPLAY, 10, 13, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); - assertEquals(1, editBlackboard.getCoords(10,13).size()); + assertEquals(1, editBlackboard.getCoords(10, 13).size()); - event = new MapMouseEvent( DISPLAY, 40,10,NONE,BUTTON1, BUTTON1 ); + event = new MapMouseEvent(DISPLAY, 40, 10, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); handler.handleEvent(event, EventType.RELEASED); - assertEquals(2, editBlackboard.getCoords(30,20).size()); - assertEquals(0, editBlackboard.getCoords(10,10).size()); + assertEquals(2, editBlackboard.getCoords(30, 20).size()); + assertEquals(0, editBlackboard.getCoords(10, 10).size()); - handler.getEditBlackboard().removeCoordsAtPoint(20,10); + handler.getEditBlackboard().removeCoordsAtPoint(20, 10); - //Testing searching through the layer for the closest point. - assertEquals(2, editBlackboard.getCoords(30,20).size()); + // Testing searching through the layer for the closest point. + assertEquals(2, editBlackboard.getCoords(30, 20).size()); ILayer editLayer = handler.getEditLayer(); - FeatureSource source = editLayer.getResource(FeatureSource.class, new NullProgressMonitor()); + FeatureSource source = editLayer + .getResource(FeatureSource.class, new NullProgressMonitor()); SimpleFeature feature = source.getFeatures().features().next(); Coordinate coord = ((Geometry) feature.getDefaultGeometry()).getCoordinates()[1]; Coordinate t = JTS.transform(coord, new Coordinate(), editLayer.layerToMapTransform()); java.awt.Point pointOnScreen = handler.getContext().worldToPixel(t); - handler.getMouseTracker().setDragStarted(Point.valueOf(30,20)); - event = new MapMouseEvent( DISPLAY, pointOnScreen.x+5,pointOnScreen.y,NONE,BUTTON1, BUTTON1 ); + handler.getMouseTracker().setDragStarted(Point.valueOf(30, 20)); + event = new MapMouseEvent(DISPLAY, pointOnScreen.x + 5, pointOnScreen.y, NONE, BUTTON1, + BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); handler.handleEvent(event, EventType.RELEASED); - assertEquals(1, editBlackboard.getCoords(pointOnScreen.x,pointOnScreen.y).size()); - assertEquals(1, editBlackboard.getCoords(30,20).size()); + assertEquals(1, editBlackboard.getCoords(pointOnScreen.x, pointOnScreen.y).size()); + assertEquals(1, editBlackboard.getCoords(30, 20).size()); assertEquals(t, editBlackboard.getCoords(pointOnScreen.x, pointOnScreen.y).get(0)); } @Test public void testSnappingDuringDragging() throws Exception { - editBlackboard.selectionAdd(Point.valueOf(10,10)); - editBlackboard.selectionAdd(Point.valueOf(20,10)); + editBlackboard.selectionAdd(Point.valueOf(10, 10)); + editBlackboard.selectionAdd(Point.valueOf(20, 10)); - handler.getMouseTracker().setDragStarted(Point.valueOf(10,12)); - MapMouseEvent event = new MapMouseEvent( DISPLAY, 10,13,NONE,BUTTON1, BUTTON1 ); + handler.getMouseTracker().setDragStarted(Point.valueOf(10, 12)); + MapMouseEvent event = new MapMouseEvent(DISPLAY, 10, 13, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); - assertEquals(1, editBlackboard.getCoords(10,13).size()); - assertEquals(1, editBlackboard.getCoords(20,13).size()); - assertEquals(0, editBlackboard.getCoords(10,10).size()); - assertEquals(0, editBlackboard.getCoords(20,10).size()); + assertEquals(1, editBlackboard.getCoords(10, 13).size()); + assertEquals(1, editBlackboard.getCoords(20, 13).size()); + assertEquals(0, editBlackboard.getCoords(10, 10).size()); + assertEquals(0, editBlackboard.getCoords(20, 10).size()); } - private EventBehaviour findPositionTracker( ){ + private EventBehaviour findPositionTracker() { List behaviours = handler.getBehaviours(); - for( EventBehaviour behaviour : behaviours ) { - if( behaviour instanceof MoveVertexBehaviour.PositionTracker ){ + for (EventBehaviour behaviour : behaviours) { + if (behaviour instanceof MoveVertexBehaviour.PositionTracker) { return behaviour; } } @@ -311,54 +321,51 @@ private EventBehaviour findPositionTracker( ){ @Test public void testDragAcrossAnotherVertex() throws Exception { - editBlackboard.selectionAdd(Point.valueOf(10,10)); - + editBlackboard.selectionAdd(Point.valueOf(10, 10)); - handler.getMouseTracker().setDragStarted(Point.valueOf(10,12)); - MapMouseEvent event = new MapMouseEvent( DISPLAY, 12,10,NONE,BUTTON1, BUTTON1 ); + handler.getMouseTracker().setDragStarted(Point.valueOf(10, 12)); + MapMouseEvent event = new MapMouseEvent(DISPLAY, 12, 10, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); - assertEquals(1, editBlackboard.getCoords(12,10).size()); - assertEquals(0, editBlackboard.getCoords(10,10).size()); + assertEquals(1, editBlackboard.getCoords(12, 10).size()); + assertEquals(0, editBlackboard.getCoords(10, 10).size()); - event = new MapMouseEvent( DISPLAY, 20,10,NONE,BUTTON1, BUTTON1 ); + event = new MapMouseEvent(DISPLAY, 20, 10, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); - assertEquals(2, editBlackboard.getCoords(20,10).size()); - assertEquals(0, editBlackboard.getCoords(12,10).size()); + assertEquals(2, editBlackboard.getCoords(20, 10).size()); + assertEquals(0, editBlackboard.getCoords(12, 10).size()); - event = new MapMouseEvent( DISPLAY, 20,15,NONE,BUTTON1, BUTTON1 ); + event = new MapMouseEvent(DISPLAY, 20, 15, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); - assertEquals(1, editBlackboard.getCoords(20,10).size()); - assertEquals(1, editBlackboard.getCoords(20,15).size()); - assertTrue( handler.getCurrentShape().hasVertex(Point.valueOf(20,10))); - assertTrue( handler.getCurrentShape().hasVertex(Point.valueOf(20,15))); - assertTrue( handler.getCurrentShape().hasVertex(Point.valueOf(20,10))); -// assertTrue( handler.getCurrentShape().hasVertex(Point.valueOf(20,10), handler.getEditBlackboard().getCoords(20,10).get(0))); -// assertTrue( handler.getCurrentShape().hasVertex(Point.valueOf(20,15), handler.getEditBlackboard().getCoords(20,15).get(0))); + assertEquals(1, editBlackboard.getCoords(20, 10).size()); + assertEquals(1, editBlackboard.getCoords(20, 15).size()); + assertTrue(handler.getCurrentShape().hasVertex(Point.valueOf(20, 10))); + assertTrue(handler.getCurrentShape().hasVertex(Point.valueOf(20, 15))); + assertTrue(handler.getCurrentShape().hasVertex(Point.valueOf(20, 10))); } @Test - public void testSnapToVertex() throws Exception{ + public void testSnapToVertex() throws Exception { MapMouseEvent event; - //drag close to point and it should snap to a coord in point. + // drag close to point and it should snap to a coord in point. - assertEquals(1, editBlackboard.getCoords(20,10).size()); + assertEquals(1, editBlackboard.getCoords(20, 10).size()); handler.getEditBlackboard().selectionClear(); - handler.getEditBlackboard().selectionAdd(Point.valueOf(10,10)); - handler.getMouseTracker().setDragStarted(Point.valueOf(10,10)); - event=new MapMouseEvent( DISPLAY, 13,10,NONE,BUTTON1, BUTTON1 ); + handler.getEditBlackboard().selectionAdd(Point.valueOf(10, 10)); + handler.getMouseTracker().setDragStarted(Point.valueOf(10, 10)); + event = new MapMouseEvent(DISPLAY, 13, 10, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); - event=new MapMouseEvent( DISPLAY, 18,10,NONE,BUTTON1, BUTTON1 ); + event = new MapMouseEvent(DISPLAY, 18, 10, NONE, BUTTON1, BUTTON1); mode.getCommand(handler, event, EventType.DRAGGED); handler.handleEvent(event, EventType.RELEASED); - assertEquals(2, editBlackboard.getCoords(20,10).size()); - assertEquals(0, editBlackboard.getCoords(10,10).size()); + assertEquals(2, editBlackboard.getCoords(20, 10).size()); + assertEquals(0, editBlackboard.getCoords(10, 10).size()); } } diff --git a/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/EditBlackboardTest.java b/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/EditBlackboardTest.java index b063113611..98591ed009 100644 --- a/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/EditBlackboardTest.java +++ b/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/EditBlackboardTest.java @@ -702,6 +702,8 @@ public void testLakeDrawingCase() throws Exception { // parse XML SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); @@ -712,6 +714,8 @@ public void testLakeDrawingCase() throws Exception { throw new RuntimeException(e); } + assertTrue(collection.features().hasNext()); + SimpleFeature feature = collection.features().next(); ReferencedEnvelope bounds = new ReferencedEnvelope(feature.getBounds()); bounds = new ReferencedEnvelope(bounds.getMinX() - (bounds.getWidth() / 8), diff --git a/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/TimingTests.java b/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/TimingTests.java index fd0db55df0..5193736cd0 100644 --- a/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/TimingTests.java +++ b/plugins/org.locationtech.udig.tool.edit.tests/src/org/locationtech/udig/tools/edit/support/TimingTests.java @@ -78,6 +78,8 @@ public void testPrimitiveShapeIterator() throws Exception { // parse XML SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); diff --git a/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FeatureTextTransfer.java b/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FeatureTextTransfer.java index abdfe56dd9..e60e599d1f 100644 --- a/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FeatureTextTransfer.java +++ b/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FeatureTextTransfer.java @@ -131,6 +131,8 @@ public Object nativeToJava(TransferData transferData) { // parse XML SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader(); diff --git a/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FilterTextTransfer.java b/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FilterTextTransfer.java index 8871f48b75..99bb2e1758 100644 --- a/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FilterTextTransfer.java +++ b/plugins/org.locationtech.udig.ui/src/org/locationtech/udig/internal/ui/FilterTextTransfer.java @@ -143,6 +143,8 @@ public Object nativeToJava(TransferData transferData) { // parse XML SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + SAXParser parser = factory.newSAXParser(); XMLReader reader = parser.getXMLReader();