|
@@ -719,7 +719,46 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
|
}
|
|
|
|
|
|
if (dragged) {
|
|
|
- try {
|
|
|
+ try {
|
|
|
+ /** x of the dragged Object */
|
|
|
+ int x = tempCps.getPosition().x;
|
|
|
+
|
|
|
+ /** y of the dragged Object */
|
|
|
+ int y = tempCps.getPosition().y;
|
|
|
+
|
|
|
+ /** distance treshold for replacement */
|
|
|
+ int treshhold = controller.getScale()/4;
|
|
|
+
|
|
|
+ //System.out.println("Dragged "+tempCps.toString()+" to x: "+tempCps.getPosition().x+" y: "+tempCps.getPosition().y);
|
|
|
+
|
|
|
+ /** number of Objects that might be replaced (should be 1) */
|
|
|
+ int replaceCounter = 0;
|
|
|
+
|
|
|
+ /** last object that could be replaced */
|
|
|
+ AbstractCpsObject toBeReplaced = null;
|
|
|
+
|
|
|
+ /** for each cps on Canvas */
|
|
|
+ for (AbstractCpsObject cps : upperNode.getNodes()){
|
|
|
+
|
|
|
+ /** same object -> ignore */
|
|
|
+ if(cps == tempCps)continue;
|
|
|
+
|
|
|
+ /** x of object that might get replaced */
|
|
|
+ int c_x = cps.getPosition().x;
|
|
|
+
|
|
|
+ /** y of object that might get replaced */
|
|
|
+ int c_y = cps.getPosition().y;
|
|
|
+
|
|
|
+ /** if near enough */
|
|
|
+ if(Math.abs(x-c_x)<treshhold && Math.abs(y-c_y)<treshhold){
|
|
|
+ replaceCounter++;
|
|
|
+ toBeReplaced = cps;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /** if replacement of exactly one object possible */
|
|
|
+ if(replaceCounter == 1 && toBeReplaced != null){
|
|
|
+ controller.replaceCanvasObject(toBeReplaced, tempCps);
|
|
|
+ }
|
|
|
controller.autoSave();
|
|
|
} catch (IOException ex) {
|
|
|
ex.printStackTrace();
|