if(ds.isAttachToGrid()){
List<IMapObject> mapobjs = refEditor.getIMapObjects();
for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
if(mo instanceof GridMapObject){
PresentationSettings ps = ((GridMapObject)mo).getPresentationSettings();
int x = (pos.getX()/ps.getGridWidth())*ps.getGridWidth();
if(pos.getX()%ps.getGridWidth()>(ps.getGridWidth()/2)){
x += ps.getGridWidth();
}
int y = (pos.getY()/ps.getGridHeight())*ps.getGridHeight();
if(pos.getY()%ps.getGridHeight()>(ps.getGridHeight()/2)){
y += ps.getGridHeight();
}
WorldPos gridAttachPos = new WorldPos(x,y);
pos = gridAttachPos; // Replace with adjusted pos!
}
}
}
if (smo == null) {
smo = new ShapeMapObject(ds);
smo.setPosition(pos);
refEditor.addMapObject(smo);
}
if(e.getClickCount() > 1){ // READY! DOUBLE CLICK
smo = null;
} else {
smo.addVertex(pos);
if(ds.isEnableAutocomplete() && smo.getNumberOfVertices()>=ds.getNrOfAutocompleteVertices()){
smo = null;
}
}
} else if(e.getButton() == MouseEvent.BUTTON3){ // CANCEL - UNDO/DEL LATEST VERTEX
if(smo != null && smo.getNumberOfVertices()>0){
smo.delVertex();
if(smo.getNumberOfVertices()==0){
refEditor.delMapObject(smo);
smo = null;
}
}
}
break;
case MODE_DRAW_COPY:
case MODE_DRAW_MOVE:
if(cs.isAttachToGrid()){
List<IMapObject> mapobjs = refEditor.getIMapObjects();
for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
if(mo instanceof GridMapObject){
PresentationSettings ps = ((GridMapObject)mo).getPresentationSettings();
int x = (pos.getX()/ps.getGridWidth())*ps.getGridWidth();
if(pos.getX()%ps.getGridWidth()>(ps.getGridWidth()/2)){
x += ps.getGridWidth();
}
int y = (pos.getY()/ps.getGridHeight())*ps.getGridHeight();
if(pos.getY()%ps.getGridHeight()>(ps.getGridHeight()/2)){
y += ps.getGridHeight();
}
WorldPos gridAttachPos = new WorldPos(x,y);
pos = gridAttachPos; // Replace with adjusted pos!
}
}