Package org.locationtech.udig.tools.edit.support

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


    /*
     * Test method for 'org.locationtech.udig.tools.edit.latest.MouseTracker.updateState(MapMouseEvent, EventType)'
     */
    @Test
    public void testUpdateState() throws Exception {
        TestMouseTracker tracker=new TestMouseTracker(new TestHandler() );

        MapMouseEvent event=new MapMouseEvent( DISPLAY, 10,15,NONE,BUTTON1, BUTTON1 );
        tracker.updateState(event, EventType.MOVED);
       
        assertEquals(Point.valueOf(10,15), tracker.getDragStarted());
View Full Code Here


            }

        };

        TestActivator activator = new TestActivator();
        TestHandler testHandler = new TestHandler();
        testHandler.getActivators().add(activator);
        assertFalse(activator.activated);
        testHandler.setActive(true);
        assertTrue(activator.activated);
        testHandler.setActive(false);
        assertFalse(activator.activated);

    }
View Full Code Here

        }

        TrueMode trueMode = new TrueMode();
        FalseMode falseMode = new FalseMode();

        TestHandler handler = new TestHandler();
        assertFalse(trueMode.run);
        assertFalse(falseMode.run);
        handler.getBehaviours().add(trueMode);
        handler.getBehaviours().add(falseMode);
        handler.handleEvent(null, null);
        assertTrue(trueMode.run);
        assertFalse(falseMode.run);

    }
View Full Code Here

    }

    @Test
    public void testBehaviourLocking() throws Exception {
        TestHandler handler = new TestHandler();

        final boolean[] locked = new boolean[1];
        locked[0] = false;

        final boolean[] ran = new boolean[3];
        ran[0] = false;
        ran[1] = false;
        ran[2] = false;

        handler.getBehaviours().add(new EventBehaviour(){

            public boolean isValid( EditToolHandler handler, MapMouseEvent e, EventType eventType ) {
                return true;
            }

            public UndoableMapCommand getCommand( EditToolHandler handler, MapMouseEvent e,
                    EventType eventType ) {
                if (locked[0])
                    fail("handler should be locked so this should not be ran"); //$NON-NLS-1$
                else {
                    ran[0] = true;
                }
                return null;
            }

            public void handleError( EditToolHandler handler, Throwable error, UndoableMapCommand command ) {
                throw new RuntimeException(error);
            }

        });

        handler.getBehaviours().add(new LockingBehaviour(){

            public boolean isValid( EditToolHandler handler, MapMouseEvent e, EventType eventType ) {
                return true;
            }

            public UndoableMapCommand getCommand( EditToolHandler handler, MapMouseEvent e,
                    EventType eventType ) {

                if (locked[0])
                    fail("handler should be locked with a different key so this should not be ran"); //$NON-NLS-1$
                else
                    ran[1] = true;
                return null;
            }

            public void handleError( EditToolHandler handler, Throwable error, UndoableMapCommand command ) {
                throw new RuntimeException(error);
            }

            public Object getKey(EditToolHandler handler) {
                return this;
            }

        });

        LockingBehaviour locker = new LockingBehaviour(){

            public boolean isValid( EditToolHandler handler, MapMouseEvent e, EventType eventType ) {
                return true;
            }

            public UndoableMapCommand getCommand( EditToolHandler handler, MapMouseEvent e,
                    EventType eventType ) {
                // this should be ran
                ran[2] = true;
                return null;
            }

            public void handleError( EditToolHandler handler, Throwable error, UndoableMapCommand command ) {
                throw new RuntimeException(error);
            }

            public Object getKey(EditToolHandler handler) {
                return this;
            }

        };

        handler.getBehaviours().add(locker);

        MapMouseEvent event = new MapMouseEvent(null, 0, 0, 0, 0, 0);
        handler.handleEvent(event, EventType.RELEASED);

        assertTrue(ran[0]);
        assertTrue(ran[1]);
        assertTrue(ran[2]);
        ran[0] = false;
        ran[1] = false;
        ran[2] = false;

        assertFalse(handler.isLockOwner(locker));
        assertFalse(handler.isLockOwner(object));

        handler.lock(locker);
       
        locked[0]=true;
        assertTrue(handler.isLocked());
        assertTrue(handler.isLockOwner(locker));
        assertFalse(handler.isLockOwner(object));
        handler.handleEvent(event, EventType.RELEASED);

        assertFalse(ran[0]);
        assertFalse(ran[1]);
        assertTrue(ran[2]);
        try {

            handler.unlock(object);
            fail("only a behaviour with the same key as the locking behaviour should be able" + //$NON-NLS-1$
                    "to unlock the handler"); //$NON-NLS-1$
        } catch (Exception e) {
            // good
        }

        try {
            handler.lock(locker);
            fail("not implemented as a reentrant lock."); //$NON-NLS-1$
        } catch (Exception e) {
            // good
        }

        handler.unlock(locker);
        locked[0]=false;

        assertFalse(handler.isLocked());

        ran[0] = false;
        ran[1] = false;
        ran[2] = false;
        handler.handleEvent(event, EventType.RELEASED);

        assertTrue(ran[0]);
        assertTrue(ran[1]);
        assertTrue(ran[2]);

        try{
            handler.lock(new LockingBehaviour(){

                public Object getKey(EditToolHandler handler) {
                    return null;
                }
View Full Code Here

        final int shift = MapMouseEvent.SHIFT_DOWN_MASK;
        final int alt = MapMouseEvent.ALT_DOWN_MASK;
        final int button1 = MapMouseEvent.BUTTON1;
        final int button2 = MapMouseEvent.BUTTON2;
       
        TestHandler handler=new TestHandler();
        assertFalse(mode.isValid(handler, new MapMouseEvent(null, 0, 0, none, none, 0), EventType.DOUBLE_CLICK));
        assertFalse(mode.isValid(handler, new MapMouseEvent(null, 0, 0, none, none, button1), EventType.PRESSED));

        handler.setCurrentShape(handler.getEditBlackboard().getGeoms().get(0).getShell());
        handler.getEditBlackboard().addPoint(10,0, handler.getCurrentGeom().getShell());

       
        assertFalse(mode.isValid(handler,  new MapMouseEvent(null, 10, 0, none, none, button1), EventType.PRESSED));
        assertFalse(mode.isValid(handler, new MapMouseEvent(null, 10, 0, none, none, button1), EventType.DRAGGED));
        assertFalse(mode.isValid(handler, new MapMouseEvent(null, 10, 0, none, none, button1), EventType.DRAGGED));
View Full Code Here

        final int none=MapMouseEvent.NONE;
        final int ctrl = MapMouseEvent.CTRL_DOWN_MASK;
        final int shift = MapMouseEvent.SHIFT_DOWN_MASK;
        final int button1 = MapMouseEvent.BUTTON1;
       
        TestHandler handler=new TestHandler();
        handler.getBehaviours().add(mode);
        handler.getTestEditBlackboard().util.setVertexRadius(4);
        handler.setCurrentShape(handler.getEditBlackboard().getGeoms().get(0).getShell());
        handler.getEditBlackboard().addPoint(10,10, handler.getCurrentGeom().getShell());
        handler.getEditBlackboard().addPoint(15,15, handler.getCurrentGeom().getShell());
        handler.getEditBlackboard().addPoint(20,15, handler.getCurrentGeom().getShell());
        handler.getEditBlackboard().addPoint(30,25, handler.getCurrentGeom().getShell());
       
        //test click on point
        handler.handleEvent(new MapMouseEvent(null, 9, 10, none, none, button1), EventType.RELEASED);
        assertEquals(1, handler.getEditBlackboard().getSelection().size());
        assertEquals(Point.valueOf(10,10), handler.getEditBlackboard().getSelection().iterator().next());

        //test click on same point
        handler.handleEvent(new MapMouseEvent(null, 10, 10, none, none, button1), EventType.RELEASED);
        assertEquals(Point.valueOf(10,10), handler.getEditBlackboard().getSelection().iterator().next());
        assertEquals(1, handler.getEditBlackboard().getSelection().size());
       
        //test click on new point
        handler.handleEvent( new MapMouseEvent(null, 15, 15, none, none, button1), EventType.RELEASED);
        assertEquals(Point.valueOf(15,15), handler.getEditBlackboard().getSelection().iterator().next());
        assertEquals(1, handler.getEditBlackboard().getSelection().size());
       
        //test add to selection via SHIFT-click
        MapMouseEvent event = new MapMouseEvent(null, 10, 10, shift, none, button1);
        handler.handleEvent( event, EventType.RELEASED);
        assertEquals(2, handler.getEditBlackboard().getSelection().size());
        assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(10,10)));
        assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(15,15)));
       
        //test no change to selection if SHIFT-click on selected vertex
        event= new MapMouseEvent(null, 15, 15, shift, none, button1);
        handler.handleEvent( event, EventType.RELEASED);
        assertEquals(2, handler.getEditBlackboard().getSelection().size());
        assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(10,10)));
        assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(15,15)));
       
        //test add to selection via CTRL-click
        event= new MapMouseEvent(null, 20, 15, ctrl, none, button1);
        handler.handleEvent( event, EventType.RELEASED);
        assertEquals(3, handler.getEditBlackboard().getSelection().size());
        assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(10,10)));
        assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(15,15)));
        assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(20,15)));
       
        //test remove from selection via CTRL-click
        event= new MapMouseEvent(null, 15, 15, ctrl, none, button1);
        handler.handleEvent( event, EventType.RELEASED);
        assertEquals(2, handler.getEditBlackboard().getSelection().size());
        assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(10,10)));
        assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(20,15)));
       
        //test no change when SHIFT-click and CTRL-click on nothing
        event= new MapMouseEvent(null, 300, 300, shift, none, button1);
        handler.handleEvent( event, EventType.RELEASED);
        assertEquals(2, handler.getEditBlackboard().getSelection().size());
        assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(10,10)));
        assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(20,15)));
       
        event= new MapMouseEvent(null, 300, 300, ctrl, none, button1);
        handler.handleEvent( event, EventType.RELEASED);
        assertEquals(2, handler.getEditBlackboard().getSelection().size());
        assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(10,10)));
        assertTrue(handler.getEditBlackboard().getSelection().contains(Point.valueOf(20,15)));
       
        handler.getEditBlackboard().selectionClear();
       
        //test no add when click SHIFT-click and CTRL-click on nothing
        event= new MapMouseEvent(null, 300, 300, shift, none, button1);
        handler.handleEvent( event, EventType.RELEASED);
        assertEquals(0, handler.getEditBlackboard().getSelection().size());

        event= new MapMouseEvent(null, 300, 300, ctrl, none, button1);
        handler.handleEvent( event, EventType.RELEASED);
        assertEquals(0, handler.getEditBlackboard().getSelection().size());

    }
View Full Code Here

    private SimpleFeature feature;
    private SimpleFeature feature2;

    @Before
    public void setUp() throws Exception {
        handler=new TestHandler(2);
        layer = (Layer) handler.getContext().getMap().getMapLayers().get(0);
        FeatureIterator<SimpleFeature> features = layer.getResource(FeatureSource.class, null).getFeatures().features();
        feature = features.next();
        feature2 = features.next();
        ((Map)handler.getContext().getMap()).getEditManagerInternal().setEditFeature(feature, layer);   
View Full Code Here

        final int shift = MapMouseEvent.SHIFT_DOWN_MASK;
        final int alt = MapMouseEvent.ALT_DOWN_MASK;
        final int button1 = MapMouseEvent.BUTTON1;
        final int button2 = MapMouseEvent.BUTTON2;
       
        TestHandler handler=new TestHandler();
        assertFalse(mode.isValid(handler, new MapMouseEvent(null, 0, 0, none, none, 0), EventType.DOUBLE_CLICK));
        assertFalse(mode.isValid(handler, new MapMouseEvent(null, 0, 0, none, button1, button1), EventType.PRESSED));

        handler.setCurrentShape(handler.getEditBlackboard().getGeoms().get(0).getShell());
        handler.getEditBlackboard().addPoint(10,0, handler.getCurrentGeom().getShell());

       
        assertTrue(mode.isValid(handler,  new MapMouseEvent(null, 10, 0, none, button1, button1), EventType.PRESSED));
        assertFalse(mode.isValid(handler, new MapMouseEvent(null, 10, 0, none, button1, button1), EventType.DRAGGED));
        assertFalse(mode.isValid(handler, new MapMouseEvent(null, 10, 0, none, button1, button1), EventType.DRAGGED));
View Full Code Here

        SelectVertexOnMouseDownBehaviour mode=new SelectVertexOnMouseDownBehaviour();

        final int none=MapMouseEvent.NONE;
        final int button1 = MapMouseEvent.BUTTON1;
       
        TestHandler handler=new TestHandler();
        handler.getBehaviours().add(mode);
        handler.getTestEditBlackboard().util.setVertexRadius(4);
        handler.setCurrentShape(handler.getEditBlackboard().getGeoms().get(0).getShell());
        handler.getEditBlackboard().addPoint(10,10, handler.getCurrentGeom().getShell());
        handler.getEditBlackboard().addPoint(15,15, handler.getCurrentGeom().getShell());
        handler.getEditBlackboard().addPoint(20,15, handler.getCurrentGeom().getShell());
        handler.getEditBlackboard().addPoint(30,25, handler.getCurrentGeom().getShell());
       
        //test click on point
        handler.handleEvent( new MapMouseEvent(null, 9, 10, none, button1, button1), EventType.PRESSED);
        assertEquals(1, handler.getEditBlackboard().getSelection().size());
        assertEquals(Point.valueOf(10,10), handler.getEditBlackboard().getSelection().iterator().next());

        //test click on same point
        handler.handleEvent( new MapMouseEvent(null, 10, 10, none, button1, button1), EventType.PRESSED);
        assertEquals(Point.valueOf(10,10), handler.getEditBlackboard().getSelection().iterator().next());
        assertEquals(1, handler.getEditBlackboard().getSelection().size());
       
        //test click on new point
        handler.handleEvent( new MapMouseEvent(null, 15, 15, none, button1, button1), EventType.PRESSED);
        assertEquals(Point.valueOf(15,15), handler.getEditBlackboard().getSelection().iterator().next());
        assertEquals(1, handler.getEditBlackboard().getSelection().size());
       
        //do nothing on click on nothing
        MapMouseEvent event = new MapMouseEvent(null, 300, 300, none, button1, button1);
        handler.handleEvent( event, EventType.PRESSED);
        assertEquals(1, handler.getEditBlackboard().getSelection().size());
       
    }
View Full Code Here

TOP

Related Classes of org.locationtech.udig.tools.edit.support.TestHandler

Copyright © 2018 www.massapicom. 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.