Examples of TestHandler


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

       
    }

    @Test
    public void testDonut() throws Exception {
        TestHandler handler=new TestHandler();
       
        CreateShapeBehaviour behav=new CreateShapeBehaviour(new ShapeFactory(){
            @Override
            public GeneralPath create( int width, int height ) {
               
                Rectangle2D shell =new Rectangle2D.Float(0,0,width,height);
                float i = ((float)width)/4;
                float j = ((float)height)/4;
                Rectangle2D hole =new Rectangle2D.Float(i,j,((float)width)/2,((float)height)/2);
                GeneralPath path=new GeneralPath();
                path.append(shell, false);
                path.append(hole, false);
               
                return path;
            }
        });
       
        handler.getBehaviours().add(behav);
       
        handler.getAcceptBehaviours().add(new AcceptChangesBehaviour(Polygon.class, false));
        handler.getMouseTracker().setDragStarted(Point.valueOf(10,0));
        MapMouseEvent event=new MapMouseEvent( null, 26, 16, MapMouseEvent.NONE,
                MapMouseEvent.BUTTON1, MapMouseEvent.BUTTON1);
        handler.handleEvent(event, EventType.DRAGGED);
       
        assertTrue( handler.isLocked() );
        assertTrue( handler.isLockOwner(behav) );

        event=new MapMouseEvent( null, 26, 16, MapMouseEvent.NONE,
                MapMouseEvent.NONE, MapMouseEvent.BUTTON1);
        handler.handleEvent(event, EventType.RELEASED);
       
        assertFalse( handler.isLocked() );
        assertEquals( 2, handler.getEditBlackboard().getCoords(10,0).size() );
        assertEquals( 1, handler.getEditBlackboard().getCoords(26,0).size() );
        assertEquals( 1, handler.getEditBlackboard().getCoords(26,16).size() );
        assertEquals( 1, handler.getEditBlackboard().getCoords(10,16).size() );
       
        assertEquals( 2, handler.getEditBlackboard().getCoords(14,4).size() );
        assertEquals( 1, handler.getEditBlackboard().getCoords(22,4).size() );
        assertEquals( 1, handler.getEditBlackboard().getCoords(22,12).size() );
        assertEquals( 1, handler.getEditBlackboard().getCoords(14,12).size() );
    }
View Full Code Here

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

    private EditBlackboard bb;
    private LegalShapeValidator validator;

    @Before
    public void setUp() throws Exception {
        handler = new TestHandler();
        bb=handler.getEditBlackboard();
        bb.clear();
       
        validator=new LegalShapeValidator();
    }
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);
       
        InsertVertexCommand command1=new InsertVertexCommand(new TestHandler(), map, new TestViewportPane(new Dimension(500,500)),
                new EditUtils.StaticShapeProvider(map.getGeoms().get(0).getShell()), Point.valueOf(10,10), 0, true );
        InsertVertexCommand command2=new InsertVertexCommand(new TestHandler(), map, new TestViewportPane(new Dimension(500,500)),
                new EditUtils.StaticShapeProvider(map.getGeoms().get(0).getShell()), Point.valueOf(10,15),0, true );

        assertEquals(0, map.getCoords(10,10).size());
        assertEquals(0, map.getCoords(10,15).size());       
       
View Full Code Here

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

     * Test method for 'org.locationtech.udig.tools.edit.EventBehaviourCommand.run(IProgressMonitor)'
     */
    @Test
    public void testRun() throws Exception {

        TestHandler handler=new TestHandler();
       
        RunBehaviour runBehaviour = new RunBehaviour();
        RunBehaviour runBehaviour2 = new RunBehaviour();
        List<EventBehaviour> list=new ArrayList<EventBehaviour>();
       
        list.add( runBehaviour);
        list.add( runBehaviour2);
        list.add( new NoRunBehaviour());
       
        MapMouseEvent event = new MapMouseEvent(null, 0,0,0,0,0);
       
        EventBehaviourCommand command=new EventBehaviourCommand(list, handler, event, EventType.RELEASED);
        command.setMap( (Map) handler.getContext().getMap());
        assertFalse( runBehaviour.ran );
        assertFalse( runBehaviour2.ran );
       
        NullProgressMonitor nullProgressMonitor = new NullProgressMonitor();
        command.execute(nullProgressMonitor);
View Full Code Here

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

     * Test method for 'org.locationtech.udig.tools.edit.EventBehaviourCommand.run(IProgressMonitor)'
     */
    @Test
    public void testRun() throws Exception {

        TestHandler handler=new TestHandler();
       
        RunBehaviour runBehaviour = new RunBehaviour();
        RunBehaviour runBehaviour2 = new RunBehaviour();
        List<Behaviour> list=new ArrayList<Behaviour>();
       
        list.add( runBehaviour);
        list.add( runBehaviour2);
        list.add( new NoRunBehaviour());
       
       
        BehaviourCommand command=new BehaviourCommand(list, handler );
        command.setMap( (Map) handler.getContext().getMap());
        assertFalse( runBehaviour.ran );
        assertFalse( runBehaviour2.ran );
       
        NullProgressMonitor nullProgressMonitor = new NullProgressMonitor();
        command.execute(nullProgressMonitor);
View Full Code Here

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

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

            }

        };

        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

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

        }

        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

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

    }

    @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

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

        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
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.