|
@@ -598,6 +598,47 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
|
|
|
if (dragged) {
|
|
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 : model.getObjectsOnCanvas()){
|
|
|
|
+
|
|
|
|
+ /** 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){
|
|
|
|
+ System.out.println(toBeReplaced.getName() + " should be replaced by " + tempCps.getName());
|
|
|
|
+ //TODO: replace
|
|
|
|
+ }
|
|
|
|
+
|
|
controller.autoSave();
|
|
controller.autoSave();
|
|
} catch (IOException ex) {
|
|
} catch (IOException ex) {
|
|
System.err.println("AutoSave error by dragging");
|
|
System.err.println("AutoSave error by dragging");
|