}
private UndoableMapCommand init( final EditToolHandler handler, MapMouseEvent e, EventType eventType ) {
if( !handler.isLockOwner(this) )
handler.lock(this);
Point dragStarted = handler.getMouseTracker().getDragStarted();
if( creator!=null )
handler.getBehaviours().remove(creator);
creator = new Creator(dragStarted);
initDrawCommands(handler, dragStarted);
handler.getBehaviours().add(creator);
ILayer selectedLayer = handler.getEditLayer();
EditBlackboard editBlackboard = handler.getEditBlackboard(selectedLayer);
int vertexRadius = PreferenceUtil.instance().getVertexRadius();
Point nearestPoint = editBlackboard.overVertex(dragStarted, vertexRadius);
if( nearestPoint==null )
nearestPoint=dragStarted;
initShapePath(nearestPoint);
SimpleFeatureType schema = selectedLayer.getSchema();
determineShapeType(schema);
if( type==ShapeType.POLYGON && EditPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_FILL_POLYGONS) ){
drawShapeCommand.setFill(PreferenceUtil.instance().getDrawGeomsFill());
}
EditBlackboard blackboard = editBlackboard;
PrimitiveShape currentShape = handler.getCurrentShape();
if (currentShape == null) {
UndoableComposite undoableComposite = startNewShape(handler, blackboard);
return undoableComposite;
}
currentShape=currentShape.getEditGeom().getShell();
//if current shape is a line and point matches up with one of the end points then
// continue line.
if( currentShape.getEditGeom().getShapeType()==ShapeType.LINE ){
if( currentShape.getNumPoints()>0 && nearestPoint.equals(currentShape.getPoint(0)) ){
// over the first end point so reverse order and return;
EditUtils.instance.reverseOrder(currentShape);
return null;
}
if( currentShape.getNumPoints()>1 && !nearestPoint.equals(currentShape.getPoint(currentShape.getNumPoints()-1)) ){
// not over one of the end points
return createNewGeom(handler);
}
return null;
}