/*
* 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));
}