}
}
}
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!
}
}
}
List<IMapObject> mapobjs = refEditor.getIMapObjects();
//WorldPos UL = new WorldPos(1000,1000); // TODO: Use MAX SCREEN COORDS
//WorldPos LR = new WorldPos(0,0); // MIN SCREEN COORDS
int refX = 10000;// TODO: Use MAX SCREEN COORDS
int refY = 10000;// TODO: Use MAX SCREEN COORDS
// Get outer bounding for ALL SELECTED shapes
for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
if(mo instanceof ShapeMapObject){
ShapeMapObject refSMO = (ShapeMapObject)mo;
if(refSMO.isSelected()){
if(refSMO.getUpperLeft().getX()<refX){
refX = refSMO.getUpperLeft().getX();
}
if(refSMO.getUpperLeft().getY()<refY){
refY = refSMO.getUpperLeft().getY();
}
}
}
}
WorldPos diff = new WorldPos(refX, refY);
if(currentMode == MODE_DRAW_COPY){
List<ShapeMapObject> copyLst = new ArrayList<ShapeMapObject>();
if(dragInitiated==true){
diff.setPosition(0, 0);
pos.setPosition(0, 0);
}
for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
if(mo instanceof ShapeMapObject){
ShapeMapObject refSMO = (ShapeMapObject)mo;
if(refSMO.isSelected()){
ShapeMapObject copySMO = refSMO.copy();
copySMO.moveShape(diff, pos);
//refSMO.setPosition();
copyLst.add(copySMO);
if(dragInitiated==true){
copySMO.setSelected(true);
refSMO.setSelected(false);
}
}
}
}
dragInitiated=false;
for(ShapeMapObject smoCopy : Collections.unmodifiableCollection(copyLst)){
refEditor.addMapObject(smoCopy);
}
} else {
for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
if(mo instanceof ShapeMapObject){
ShapeMapObject refSMO = (ShapeMapObject)mo;
if(refSMO.isSelected()){
refSMO.moveShape(diff, pos);
//refSMO.setPosition();
}
}
if(mo instanceof SelectMapObject){
SelectMapObject refSMO = (SelectMapObject)mo;
if(refSMO.getAnchorPos() != null){
refSMO.getAnchorPos().setX(refSMO.getAnchorPos().getX()-diff.getX()+pos.getX());
refSMO.getAnchorPos().setY(refSMO.getAnchorPos().getY()-diff.getY()+pos.getY());
}
}
}
}
dragButton = MouseEvent.NOBUTTON;
// Reset state
if(oldMode != MODE_DRAW_NO && oldMode != currentMode && e != null){
currentMode = oldMode;
}
break;
case MODE_SEL_AREA:
case MODE_SEL_SINGLE:
//List<IMapObject> mapobjs;
WorldPos anchorPos = null;
mapobjs = refEditor.getIMapObjects();
// RIGHT CLICK => REMOVE ALL SELECTION!
if(e.getButton() == MouseEvent.BUTTON3){
for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
if(mo instanceof ShapeMapObject){
ShapeMapObject refSMO = (ShapeMapObject)mo;
refSMO.setSelected(false);
}
}
if(selMO != null){
refEditor.delMapObject(selMO);
selMO = null;
}
}
if(currentMode == MODE_SEL_SINGLE){
mapobjs = refEditor.getIMapObjects();
for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
if(mo instanceof ShapeMapObject){
ShapeMapObject refSMO = (ShapeMapObject)mo;
if(refSMO.isPointInShape(pos)){
refSMO.setSelected(!refSMO.isSelected());
}
if(refSMO.isSelected()){
if(anchorPos == null){
anchorPos = new WorldPos(10000,10000);
}
if(anchorPos.getX()>refSMO.getUpperLeft().getX()){
anchorPos.setX(refSMO.getUpperLeft().getX());
}
if(anchorPos.getY()>refSMO.getUpperLeft().getY()){
anchorPos.setY(refSMO.getUpperLeft().getY());
}
}
}
}
if(anchorPos == null){
if(selMO != null){
refEditor.delMapObject(selMO);
selMO = null;
}
} else {
if(selMO == null){
selMO = new SelectMapObject();
refEditor.addMapObject(selMO);
}
selMO.setStartPos(pos);
selMO.setEndPos(pos);
selMO.setAnchorPos(anchorPos);
}
} else {
if(dragButton == MouseEvent.BUTTON1){
mapobjs = refEditor.getIMapObjects();
for (IMapObject mo : Collections.unmodifiableCollection(mapobjs)){
if(mo instanceof ShapeMapObject){
ShapeMapObject refSMO = (ShapeMapObject)mo;
if( (refSMO.getUpperLeft().getX()>=selMO.getUpperLeft().getX() &&
refSMO.getUpperLeft().getX()<=pos.getX() &&
refSMO.getUpperLeft().getY()>=selMO.getUpperLeft().getY() &&
refSMO.getUpperLeft().getY()<=pos.getY() )
||
(refSMO.getLowerRight().getX()>=selMO.getUpperLeft().getX() &&
refSMO.getLowerRight().getX()<=pos.getX() &&
refSMO.getLowerRight().getY()>=selMO.getUpperLeft().getY() &&
refSMO.getLowerRight().getY()<=pos.getY() ) )
{
refSMO.setSelected(!refSMO.isSelected());
}
if(refSMO.isSelected()){
if(anchorPos == null){
anchorPos = new WorldPos(10000,10000);
}
if(anchorPos.getX()>refSMO.getUpperLeft().getX()){
anchorPos.setX(refSMO.getUpperLeft().getX());
}
if(anchorPos.getY()>refSMO.getUpperLeft().getY()){
anchorPos.setY(refSMO.getUpperLeft().getY());
}
}
}
}
if(anchorPos == null){