|
@@ -16,6 +16,7 @@ import java.awt.geom.Line2D;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.LinkedList;
|
|
import java.util.Timer;
|
|
import java.util.Timer;
|
|
import java.util.TimerTask;
|
|
import java.util.TimerTask;
|
|
|
|
|
|
@@ -48,7 +49,8 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
private Model model;
|
|
private Model model;
|
|
private final Control controller;
|
|
private final Control controller;
|
|
Graphics2D g2; // For Painting
|
|
Graphics2D g2; // For Painting
|
|
- private int cx, cy, sx, sy;
|
|
|
|
|
|
+ private int cx, cy;
|
|
|
|
+ private int sx, sy; // Mark Coords
|
|
|
|
|
|
ArrayList<HolonElement> dataSelected = new ArrayList<HolonElement>();
|
|
ArrayList<HolonElement> dataSelected = new ArrayList<HolonElement>();
|
|
|
|
|
|
@@ -64,15 +66,15 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
private JPopupMenu popmenu = new JPopupMenu();
|
|
private JPopupMenu popmenu = new JPopupMenu();
|
|
private JMenuItem itemDelete = new JMenuItem("Delete Object");
|
|
private JMenuItem itemDelete = new JMenuItem("Delete Object");
|
|
private JToolTip objectTT = new JToolTip();
|
|
private JToolTip objectTT = new JToolTip();
|
|
-
|
|
|
|
- //contains the value of the Capacity for new created Edges
|
|
|
|
|
|
+
|
|
|
|
+ // contains the value of the Capacity for new created Edges
|
|
private float edgeCapacity;
|
|
private float edgeCapacity;
|
|
|
|
|
|
public MyCanvas(final Model model, Control control) {
|
|
public MyCanvas(final Model model, Control control) {
|
|
this.add(objectTT);
|
|
this.add(objectTT);
|
|
this.controller = control;
|
|
this.controller = control;
|
|
this.model = model;
|
|
this.model = model;
|
|
-
|
|
|
|
|
|
+
|
|
edgeCapacity = 100;
|
|
edgeCapacity = 100;
|
|
popmenu.add(itemDelete);
|
|
popmenu.add(itemDelete);
|
|
itemDelete.setEnabled(false);
|
|
itemDelete.setEnabled(false);
|
|
@@ -180,23 +182,27 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
((HolonSwitch) cps).setState(false);
|
|
((HolonSwitch) cps).setState(false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (cps == tempCps) {
|
|
|
|
|
|
+ if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0)
|
|
|
|
+ || model.getSelectedCpsObjects().contains(cps)) {
|
|
g2.setColor(Color.BLUE);
|
|
g2.setColor(Color.BLUE);
|
|
- g2.fillRect((int) selectRect.getX(), (int) selectRect.getY(), (int) selectRect.getWidth(),
|
|
|
|
- (int) selectRect.getHeight());
|
|
|
|
|
|
+ g2.fillRect(cps.getPosition().x - (controller.getScale() / 20),
|
|
|
|
+ cps.getPosition().y - (controller.getScale() / 20),
|
|
|
|
+ controller.getScale() + ((controller.getScale() / 20) * 2),
|
|
|
|
+ controller.getScale() + ((controller.getScale() / 20) * 2));
|
|
} else if (cps instanceof HolonObject) {
|
|
} else if (cps instanceof HolonObject) {
|
|
- if(((HolonObject) cps).getState() == 3){
|
|
|
|
|
|
+ if (((HolonObject) cps).getState() == 3) {
|
|
g2.setColor(Color.lightGray);
|
|
g2.setColor(Color.lightGray);
|
|
}
|
|
}
|
|
- if(((HolonObject) cps).getState() == 2) {
|
|
|
|
|
|
+ if (((HolonObject) cps).getState() == 2) {
|
|
g2.setColor(Color.GREEN);
|
|
g2.setColor(Color.GREEN);
|
|
- }
|
|
|
|
- if(((HolonObject) cps).getState() == 1){
|
|
|
|
|
|
+ }
|
|
|
|
+ if (((HolonObject) cps).getState() == 1) {
|
|
g2.setColor(Color.ORANGE);
|
|
g2.setColor(Color.ORANGE);
|
|
}
|
|
}
|
|
- if(((HolonObject) cps).getState() == 0){
|
|
|
|
|
|
+ if (((HolonObject) cps).getState() == 0) {
|
|
g2.setColor(Color.WHITE);
|
|
g2.setColor(Color.WHITE);
|
|
}
|
|
}
|
|
|
|
+
|
|
g2.fillRect(cps.getPosition().x - (controller.getScale() / 20),
|
|
g2.fillRect(cps.getPosition().x - (controller.getScale() / 20),
|
|
cps.getPosition().y - (controller.getScale() / 20),
|
|
cps.getPosition().y - (controller.getScale() / 20),
|
|
controller.getScale() + ((controller.getScale() / 20) * 2),
|
|
controller.getScale() + ((controller.getScale() / 20) * 2),
|
|
@@ -228,10 +234,22 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
+ * // Testing for (CpsObject cps : markSelect) {
|
|
|
|
+ * g2.setColor(Color.BLUE); g2.fillRect(cps.getPosition().x -
|
|
|
|
+ * (controller.getScale() / 20), cps.getPosition().y -
|
|
|
|
+ * (controller.getScale() / 20), controller.getScale() +
|
|
|
|
+ * ((controller.getScale() / 20) * 2), controller.getScale() +
|
|
|
|
+ * ((controller.getScale() / 20) * 2)); }
|
|
|
|
+ */
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mouseClicked(MouseEvent e) {
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
|
+ // clear SelectedObjects
|
|
|
|
+ if (!e.isControlDown() && dragging == false) {
|
|
|
|
+ model.getSelectedCpsObjects().clear();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -260,7 +278,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
HolonObject tempObj = ((HolonObject) tempCps);
|
|
HolonObject tempObj = ((HolonObject) tempCps);
|
|
dataSelected = tempObj.getElements();
|
|
dataSelected = tempObj.getElements();
|
|
}
|
|
}
|
|
- if (e.isControlDown()) {
|
|
|
|
|
|
+ if (e.isShiftDown()) {
|
|
drawEdge = true;
|
|
drawEdge = true;
|
|
dragging = false;
|
|
dragging = false;
|
|
}
|
|
}
|
|
@@ -319,30 +337,86 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
y = e.getY();
|
|
y = e.getY();
|
|
if (dragging) {
|
|
if (dragging) {
|
|
try {
|
|
try {
|
|
- // Au�erhalb des Randes gedragged?
|
|
|
|
- x = e.getX() - controller.getScaleDiv2();
|
|
|
|
- y = e.getY() - controller.getScaleDiv2();
|
|
|
|
- if (e.getX() < controller.getScaleDiv2())
|
|
|
|
- x = 0;
|
|
|
|
- else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
|
|
|
|
- x = this.getWidth() - controller.getScale();
|
|
|
|
- if (e.getY() < controller.getScaleDiv2())
|
|
|
|
- y = 0;
|
|
|
|
- else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
|
|
|
|
- y = this.getHeight() - controller.getScale();
|
|
|
|
- // Drag Position
|
|
|
|
- tempCps.setPosition(x, y);
|
|
|
|
- // Highlighting Position
|
|
|
|
- selectRect.setLocation(x - (controller.getScale() / 20), y - (controller.getScale() / 20));
|
|
|
|
- // TipText Position and name
|
|
|
|
- objectTT.setTipText(tempCps.getName());
|
|
|
|
- objectTT.setLocation(x, y + controller.getScale());
|
|
|
|
|
|
+ if (model.getSelectedCpsObjects().size() > 0) {
|
|
|
|
+ for (CpsObject cps : model.getSelectedCpsObjects()) {
|
|
|
|
+ // Au�erhalb des Randes gedragged?
|
|
|
|
+ if (cps == tempCps) {
|
|
|
|
+ x = e.getX() - controller.getScaleDiv2();
|
|
|
|
+ y = e.getY() - controller.getScaleDiv2();
|
|
|
|
+ } else {
|
|
|
|
+ x = e.getX() - (cps.getPosition().x - e.getX()) - controller.getScaleDiv2();
|
|
|
|
+ y = e.getY() - (cps.getPosition().y - e.getY()) - controller.getScaleDiv2();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (x < controller.getScaleDiv2())
|
|
|
|
+ x = 0;
|
|
|
|
+ else if (x > this.getWidth() - controller.getScaleDiv2())
|
|
|
|
+ x = this.getWidth() - controller.getScale();
|
|
|
|
+ if (y < controller.getScaleDiv2())
|
|
|
|
+ y = 0;
|
|
|
|
+ else if (y > this.getHeight() - controller.getScaleDiv2())
|
|
|
|
+ y = this.getHeight() - controller.getScale();
|
|
|
|
+
|
|
|
|
+ System.out.println(x + ", " + y);
|
|
|
|
+ // Drag Position
|
|
|
|
+ cps.setPosition(x, y);
|
|
|
|
+ // TipText Position and name
|
|
|
|
+ objectTT.setTipText(tempCps.getName());
|
|
|
|
+ objectTT.setLocation(e.getX() - controller.getScaleDiv2(),
|
|
|
|
+ e.getY() - controller.getScaleDiv2() + controller.getScale());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // Au�erhalb des Randes gedragged?
|
|
|
|
+ x = e.getX() - controller.getScaleDiv2();
|
|
|
|
+ y = e.getY() - controller.getScaleDiv2();
|
|
|
|
+
|
|
|
|
+ if (e.getX() < controller.getScaleDiv2())
|
|
|
|
+ x = 0;
|
|
|
|
+ else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
|
|
|
|
+ x = this.getWidth() - controller.getScale();
|
|
|
|
+ if (e.getY() < controller.getScaleDiv2())
|
|
|
|
+ y = 0;
|
|
|
|
+ else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
|
|
|
|
+ y = this.getHeight() - controller.getScale();
|
|
|
|
+ // Drag Position
|
|
|
|
+ tempCps.setPosition(x, y);
|
|
|
|
+ // Highlighting Position
|
|
|
|
+ selectRect.setLocation(x - (controller.getScale() / 20), y - (controller.getScale() / 20));
|
|
|
|
+ // TipText Position and name
|
|
|
|
+ objectTT.setTipText(tempCps.getName());
|
|
|
|
+ objectTT.setLocation(x, y + controller.getScale());
|
|
|
|
+ }
|
|
repaint();
|
|
repaint();
|
|
} catch (Exception e2) {
|
|
} catch (Exception e2) {
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Mark Objects
|
|
|
|
+ if (doMark) {
|
|
|
|
+ for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
|
+ if (!model.getSelectedCpsObjects().contains(cps)) {
|
|
|
|
+
|
|
|
|
+ int x1 = sx, x2 = x, y1 = sy, y2 = y;
|
|
|
|
+
|
|
|
|
+ if (sx >= x) {
|
|
|
|
+ x1 = x;
|
|
|
|
+ x2 = sx;
|
|
|
|
+ }
|
|
|
|
+ if (sy >= y) {
|
|
|
|
+ y1 = y;
|
|
|
|
+ y2 = sy;
|
|
|
|
+ }
|
|
|
|
+ if (x1 <= cps.getPosition().x && y1 <= cps.getPosition().y && x2 >= cps.getPosition().x
|
|
|
|
+ && y2 >= cps.getPosition().y) {
|
|
|
|
+ controller.addSelectedObject(cps);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
repaint();
|
|
repaint();
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -548,8 +622,8 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
|
|
}
|
|
}
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
-
|
|
|
|
- public void setEdgeCapacity(float cap){
|
|
|
|
|
|
+
|
|
|
|
+ public void setEdgeCapacity(float cap) {
|
|
edgeCapacity = cap;
|
|
edgeCapacity = cap;
|
|
}
|
|
}
|
|
}
|
|
}
|