Examples of TestHandler


Examples of org.locationtech.udig.tools.edit.support.TestHandler

    private TestHandler handler;
    private Map map;
   
    @Before
    public void setUp() throws Exception {
        handler=new TestHandler();
        map=(Map) handler.getContext().getMap();
        GeometryFactory fac=new GeometryFactory();
        Point geom=fac.createPoint(new Coordinate(-564121,-1632497));
        SimpleFeature[] feature = UDIGTestUtil.createTestFeatures("test", new Point[]{geom}, new String[]{"name"}, CRS.decode("EPSG:2065")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Layer layer = map.getLayerFactory().createLayer(CatalogTests.createGeoResource(feature, true));
View Full Code Here

Examples of org.locationtech.udig.tools.edit.support.TestHandler

    /*
     * Test method for 'org.locationtech.udig.tools.edit.commands.SelectHoleCommand.run(IProgressMonitor)'
     */
    @Test
    public void testRun() throws Exception {
        TestHandler handler=new TestHandler();
       
        EditBlackboard editBlackboard = handler.getEditBlackboard();
        PrimitiveShape shape = editBlackboard.getGeoms().get(0).getShell();
        editBlackboard.addPoint(0,0, shape);
        editBlackboard.addPoint(100,0, shape);
        editBlackboard.addPoint(100,100, shape);
        editBlackboard.addPoint(0,100, shape);
        editBlackboard.addPoint(0,0, shape);
       
        PrimitiveShape hole = shape.getEditGeom().newHole();
        editBlackboard.addPoint(5,5, hole);
        editBlackboard.addPoint(20,5, hole);
        editBlackboard.addPoint(20,20, hole);
        editBlackboard.addPoint(5,20, hole);
        editBlackboard.addPoint(5,5, hole);
       
        PrimitiveShape hole2 = shape.getEditGeom().newHole();
        editBlackboard.addPoint(30,30, hole2);
        editBlackboard.addPoint(80,30, hole2);
        editBlackboard.addPoint(80,80, hole2);
        editBlackboard.addPoint(30,80, hole2);
        editBlackboard.addPoint(30,30, hole2);
       
        handler.setCurrentShape(shape);
       
        MapMouseEvent event=new MapMouseEvent(null, 10,10, MapMouseEvent.NONE, MapMouseEvent.NONE, MapMouseEvent.NONE);
        SelectHoleCommand command=new SelectHoleCommand(handler, event);
       
        command.setMap((Map) handler.getContext().getMap());
        NullProgressMonitor nullProgressMonitor = new NullProgressMonitor();
        command.run(nullProgressMonitor);

        assertEquals(hole, handler.getCurrentShape());
       
        command.rollback(nullProgressMonitor);
        assertEquals(shape, handler.getCurrentShape());

        command.run(nullProgressMonitor);
        assertEquals(hole, handler.getCurrentShape());

        event=new MapMouseEvent(null, 40,40, MapMouseEvent.NONE, MapMouseEvent.NONE, MapMouseEvent.NONE);
        command=new SelectHoleCommand(handler, event);
       
        command.setMap((Map) handler.getContext().getMap());
        command.run(nullProgressMonitor);

        assertEquals(hole2, handler.getCurrentShape());
       
        command.rollback(nullProgressMonitor);
        assertEquals(hole, handler.getCurrentShape());
    }
View Full Code Here

Examples of org.locationtech.udig.tools.edit.support.TestHandler

    /*
     * Test method for 'org.locationtech.udig.tools.edit.behaviour.SelectHoleBehaviour.isValid(EditToolHandler, MapMouseEvent, EventType)'
     */
    @Test
    public void testIsValid() throws Exception {
        TestHandler handler=new TestHandler();
        handler.getTestEditBlackboard().util.setVertexRadius(4);
       
        SelectHoleBehaviour behavior=new SelectHoleBehaviour();

        handler.setCurrentState(EditState.MODIFYING);

        //Current Shape must be set
        MapMouseEvent event = new MapMouseEvent(null, 10,10, MapMouseEvent.NONE, MapMouseEvent.NONE, MapMouseEvent.BUTTON1);
        assertFalse(behavior.isValid(handler, event, EventType.RELEASED));
       
        EditGeom editGeom = handler.getEditBlackboard().getGeoms().get(0);
        handler.setCurrentShape(editGeom.getShell());
        handler.getEditBlackboard().addPoint(11,11, handler.getCurrentShape());
       
        event = new MapMouseEvent(null, 10,10, MapMouseEvent.NONE, MapMouseEvent.NONE, MapMouseEvent.BUTTON1);
        assertTrue(behavior.isValid(handler, event, EventType.RELEASED));
       
        // no buttons should be down
        event = new MapMouseEvent(null, 10,10, MapMouseEvent.NONE, MapMouseEvent.BUTTON2, MapMouseEvent.BUTTON1);
        assertFalse(behavior.isValid(handler, event, EventType.RELEASED));
       
        // button2 isn't legal
        event = new MapMouseEvent(null, 10,10, MapMouseEvent.NONE, MapMouseEvent.NONE, MapMouseEvent.BUTTON2);
        assertFalse(behavior.isValid(handler, event, EventType.RELEASED));

        // no modifiers only
        event = new MapMouseEvent(null, 10,10, MapMouseEvent.ALT_DOWN_MASK, MapMouseEvent.NONE, MapMouseEvent.BUTTON1);
        assertFalse(behavior.isValid(handler, event, EventType.RELEASED));

        // works only with MODIFYING
        handler.setCurrentState(EditState.NONE);
        event = new MapMouseEvent(null, 10,10, MapMouseEvent.NONE, MapMouseEvent.NONE, MapMouseEvent.BUTTON1);
        assertFalse(behavior.isValid(handler, event, EventType.RELEASED));
       
        // works only with MODIFYING
        handler.setCurrentState(EditState.CREATING);
        event = new MapMouseEvent(null, 10,10, MapMouseEvent.NONE, MapMouseEvent.NONE, MapMouseEvent.BUTTON1);
        assertFalse(behavior.isValid(handler, event, EventType.RELEASED));
       
        // should work, just checking state is still good;
        handler.setCurrentState(EditState.MODIFYING);
        event = new MapMouseEvent(null, 10,10, MapMouseEvent.NONE, MapMouseEvent.NONE, MapMouseEvent.BUTTON1);
        assertTrue(behavior.isValid(handler, event, EventType.RELEASED));
       
        // doesn't work with event pressed
        assertFalse(behavior.isValid(handler, event, EventType.PRESSED));

        // doesn't work when shapetype is POINT
        handler.getCurrentGeom().setShapeType(ShapeType.POINT);
        assertFalse(behavior.isValid(handler, event, EventType.RELEASED));

        // doesn't work when shapetype is LINE
        handler.getCurrentGeom().setShapeType(ShapeType.LINE);
        assertFalse(behavior.isValid(handler, event, EventType.RELEASED));

    }
View Full Code Here

Examples of org.locationtech.udig.tools.edit.support.TestHandler

    private FreeHandPolygonDrawBehaviour behav;
    private TestAcceptBehaviour acceptor;

    @Before
    public void setUp() throws Exception {
        handler=new TestHandler();
        behav = new FreeHandPolygonDrawBehaviour();
        handler.getBehaviours().add(behav);
        handler.getTestEditBlackboard().util.setVertexRadius(4);
        acceptor=new TestAcceptBehaviour();
        handler.getAcceptBehaviours().add(acceptor);
View Full Code Here

Examples of org.locationtech.udig.tools.edit.support.TestHandler

    private PolygonCreationValidator validator;
    private PrimitiveShape shell;

    @Before
    public void setUp() throws Exception {
        handler=new TestHandler();
        bb=handler.getEditBlackboard();
        geom=bb.newGeom("id", ShapeType.POLYGON); //$NON-NLS-1$
        validator=new PolygonCreationValidator();
       
        shell=geom.getShell();
View Full Code Here

Examples of org.locationtech.udig.tools.edit.support.TestHandler

    private TestHandler handler;
    static final String FEATURE_TYPE_NAME = "AddFeaturesCommandTestFeatures"; //$NON-NLS-1$

    @Before
    public void setUp() throws Exception {
        handler=new TestHandler(5, FEATURE_TYPE_NAME);
    }
View Full Code Here

Examples of org.locationtech.udig.tools.edit.support.TestHandler

    private ValidHoleValidator validator;
    private PrimitiveShape hole;

    @Before
    public void setUp() throws Exception {
        handler=new TestHandler();
        bb=handler.getEditBlackboard();
        geom=bb.newGeom("id", ShapeType.POLYGON); //$NON-NLS-1$
        bb.addPoint(0, 0, geom.getShell());
        bb.addPoint(100, 0, geom.getShell());
        bb.addPoint(100, 100, geom.getShell());
View Full Code Here

Examples of org.locationtech.udig.tools.edit.support.TestHandler

*/
public class ShapeCreationBehaviourTest {

    @Test
    public void testIsValid() throws Exception {
        TestHandler handler=new TestHandler();
       
        CreateShapeBehaviour behav=new CreateShapeBehaviour(new ShapeFactory(){
            @Override
            public GeneralPath create( int width, int height ) {
                GeneralPath path=new GeneralPath();
                path.append(new Rectangle(width, height), false);
                return path;
            }
        });
       
        MapMouseEvent event=new MapMouseEvent( null, 0,0, MapMouseEvent.NONE,
                MapMouseEvent.BUTTON1, MapMouseEvent.BUTTON1);
        assertTrue(behav.isValid(handler, event, EventType.DRAGGED));
       
        //released no legal
        event=new MapMouseEvent( null, 0,0, MapMouseEvent.NONE,
                MapMouseEvent.BUTTON1, MapMouseEvent.BUTTON1);
        assertFalse(behav.isValid(handler, event, EventType.RELEASED));

        // must be mouse button 1
        event=new MapMouseEvent( null, 0,0, MapMouseEvent.NONE,
                MapMouseEvent.BUTTON2, MapMouseEvent.BUTTON1);
        assertFalse(behav.isValid(handler, event, EventType.DRAGGED));

        // cannot be Modify state
        handler.setCurrentState(EditState.MODIFYING);
        event=new MapMouseEvent( null, 0,0, MapMouseEvent.NONE,
                MapMouseEvent.BUTTON1, MapMouseEvent.BUTTON1);
        assertFalse(behav.isValid(handler, event, EventType.DRAGGED));

        // cannot be creating state
        handler.setCurrentState(EditState.CREATING);
        event=new MapMouseEvent( null, 0,0, MapMouseEvent.NONE,
                MapMouseEvent.BUTTON1, MapMouseEvent.BUTTON1);
        assertFalse(behav.isValid(handler, event, EventType.DRAGGED));
       
        // make sure state is good
        handler.setCurrentState(EditState.NONE);
        event=new MapMouseEvent( null, 0,0, MapMouseEvent.NONE,
                MapMouseEvent.BUTTON1, MapMouseEvent.BUTTON1);
        assertTrue(behav.isValid(handler, event, EventType.DRAGGED));

        // Alt down is not legal
        handler.setCurrentState(EditState.NONE);
        event=new MapMouseEvent( null, 0,0, MapMouseEvent.ALT_DOWN_MASK,
                MapMouseEvent.BUTTON2, MapMouseEvent.BUTTON1);
        assertFalse(behav.isValid(handler, event, EventType.DRAGGED));

   
View Full Code Here

Examples of org.locationtech.udig.tools.edit.support.TestHandler

    /*
     * Test method for 'org.locationtech.udig.tools.edit.behaviour.ShapeCreationBehaviour.getCommand(EditToolHandler, MapMouseEvent, EventType)'
     */
    @Test
    public void testRectangleShape() throws Exception {
        final TestHandler handler=new TestHandler();
        ILayer layer = handler.getContext().getMapLayers().get(0);
        FeatureSource<SimpleFeatureType, SimpleFeature> resource = layer.getResource(FeatureSource.class, null);
        SimpleFeature feature = resource.getFeatures().features().next();
        ((EditManager)handler.getContext().getEditManager()).setEditFeature(feature, (Layer) layer);
       
        final EditBlackboard editBlackboard = handler.getEditBlackboard();
        PrimitiveShape shell = editBlackboard.getGeoms().get(0).getShell();
        editBlackboard.addPoint(100,100,shell);
        shell.getEditGeom().setShapeType(ShapeType.POINT);
        editBlackboard.newGeom("newone", null); //$NON-NLS-1$
       
        CreateShapeBehaviour behav=new CreateShapeBehaviour(new ShapeFactory(){
            @Override
            public GeneralPath create( int width, int height ) {
                GeneralPath path=new GeneralPath();
                path.append(new Rectangle(width, height), false);
                return path;
            }
        });
       
        handler.getBehaviours().add(behav);
       
        assertNotNull( handler.getContext().getEditManager().getEditFeature());

        handler.getAcceptBehaviours().add(new AcceptChangesBehaviour(Polygon.class, false));
        handler.getMouseTracker().setDragStarted(Point.valueOf(10,0));
        MapMouseEvent event=new MapMouseEvent( null, 20, 20, MapMouseEvent.NONE,
                MapMouseEvent.BUTTON1, MapMouseEvent.BUTTON1);
        handler.handleEvent(event, EventType.DRAGGED);
       
        assertTrue( handler.isLocked() );
        assertTrue( handler.isLockOwner(behav) );

        event=new MapMouseEvent( null, 20, 20, MapMouseEvent.NONE,
                MapMouseEvent.NONE, MapMouseEvent.BUTTON1);
        handler.setTesting(false);
        handler.handleEvent(event, EventType.RELEASED);

        UDIGTestUtil.inDisplayThreadWait(1000, new WaitCondition(){

            public boolean isTrue() {
                return handler.getCurrentState()==EditState.NONE && editBlackboard.getGeoms().size()==1
                && 2==editBlackboard.getCoords(10,0).size();
            }
        }, false);
       
        assertNotSame( feature, handler.getContext().getEditManager().getEditFeature());
        assertFalse( handler.isLocked() );
        assertEquals( 1, editBlackboard.getGeoms().size());
        assertEquals( 2, editBlackboard.getCoords(10,0).size() );
        assertEquals( 1, editBlackboard.getCoords(20,0).size() );
        assertEquals( 1, editBlackboard.getCoords(20,20).size() );
        assertEquals( 1, editBlackboard.getCoords(10,20).size() );
        assertEquals(ShapeType.POLYGON, editBlackboard.getGeoms().get(0).getShapeType());
       
        ((CommandManager)((Map)handler.getContext().getMap()).getCommandStack()).undo(false);
       
        assertNotSame(feature, handler.getContext().getEditManager().getEditFeature());
        assertFalse( handler.isLocked() );
        assertEquals(2, editBlackboard.getGeoms().size());
        assertEquals(ShapeType.POINT, editBlackboard.getGeoms().get(0).getShapeType());
        assertEquals(Point.valueOf(100,100), editBlackboard.getGeoms().get(0).getShell().getPoint(0));
       
    }
View Full Code Here

Examples of org.locationtech.udig.tools.edit.support.TestHandler

   
    @Test
    public void testRunAndUndo() throws Exception {
        EditBlackboard map=new EditBlackboard(SCREEN.x, SCREEN.y, transform, layerToWorld);
        PrimitiveShape hole=map.getGeoms().get(0).newHole();
        AddVertexCommand command1=new AddVertexCommand(new TestHandler(), map, new StaticBlockingProvider<PrimitiveShape>(hole), Point.valueOf(10,10), true );
        AddVertexCommand command2=new AddVertexCommand(new TestHandler(), map, new StaticBlockingProvider<PrimitiveShape>(hole), Point.valueOf(10,15), true );

        assertEquals(0, map.getCoords(10,10).size());
        assertEquals(0, map.getCoords(10,15).size());       
       
        command1.run(new NullProgressMonitor());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.