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

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


    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

*/
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

    /*
     * 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

   
    @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

       
    }

    @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

    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

   
    @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

     * 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

     * 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

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.