List<UndoableMapCommand> commands=new ArrayList<UndoableMapCommand>();
commands.add(new StartBatchingCommand(bb));
float[] coords=new float[6];
boolean started=false;
float[] start=new float[2];
AddVertexCommand addVertexCommand=null;
while( !iter.isDone() ){
int type=iter.currentSegment(coords);
switch(type){
case PathIterator.SEG_MOVETO:
if( !started ){
started=true;
} else {
if( shapeType!=ShapeType.POLYGON )
throw new IllegalArgumentException("Holes can not to shapes that are not Polygons. Current shape is a "+shapeType); //$NON-NLS-1$
CreateAndSelectHoleCommand command = new CreateAndSelectHoleCommand(currentProvider);
currentProvider=command.getHoleProvider();
commands.add(command);
}
start[0]=coords[0];
start[1]=coords[1];
// no break is intentional. It has to fall through and add a vertext to the shape
case PathIterator.SEG_LINETO:
addVertexCommand = new AddVertexCommand(handler, bb, currentProvider, Point.valueOf((int)coords[0], (int)coords[1]), false);
addVertexCommand.setShowAnimation(false);
commands.add( addVertexCommand);
break;
case PathIterator.SEG_CLOSE:
if (!Point.valueOf((int) coords[0], (int) coords[1]).equals(
Point.valueOf((int) start[0], (int) start[1]))) {
addVertexCommand = new AddVertexCommand(handler, bb, currentProvider, Point
.valueOf((int) start[0], (int) start[1]), false);
addVertexCommand.setShowAnimation(false);
commands.add(addVertexCommand);
}
break;
default:
throw new UnsupportedOperationException("not supported"); //$NON-NLS-1$
}
iter.next();
}
if (shapeType==ShapeType.POLYGON && addVertexCommand!=null && !addVertexCommand.getPointToAdd().equals(Point.valueOf((int)start[0], (int)start[1]))){
commands.add( new AddVertexCommand(handler, bb, currentProvider, Point.valueOf((int)start[0], (int)start[1]), false));
}
UndoableComposite undoableComposite = new UndoableComposite(commands);
undoableComposite.getFinalizerCommands().add(new FireEventsCommand(bb));