|
@@ -28,28 +28,26 @@ import ui.model.Supplier;
|
|
|
import utility.ImageImport;
|
|
|
import utility.Vector2Int;
|
|
|
|
|
|
+
|
|
|
+//TODO delete GroupNodeCanvas completely and only have canvas Class
|
|
|
public class GroupNodeCanvas extends Canvas {
|
|
|
- private GroupNode upperNode;
|
|
|
private String parentPath;
|
|
|
private Component parentComponent;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
GroupNodeCanvas(Model mod, Control control, UnitGraph unitGraph, GroupNode groupNode, String parentPath,
|
|
|
Component parentComponent) {
|
|
|
super(mod, control, unitGraph);
|
|
|
- this.upperNode = groupNode;
|
|
|
+ this.groupNode = groupNode;
|
|
|
this.parentPath = parentPath;
|
|
|
this.parentComponent = parentComponent;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void setUpperNode(GroupNode upperNode) {
|
|
|
- this.upperNode = upperNode;
|
|
|
+ public void setGroupNode(GroupNode upperNode) {
|
|
|
+ this.groupNode = upperNode;
|
|
|
}
|
|
|
-
|
|
|
- public GroupNode getUpperNode() {
|
|
|
- return upperNode;
|
|
|
+
|
|
|
+ public GroupNode getGroupNode() {
|
|
|
+ return groupNode;
|
|
|
}
|
|
|
|
|
|
public String getParentPath() {
|
|
@@ -59,440 +57,445 @@ public class GroupNodeCanvas extends Canvas {
|
|
|
public Component getParentComponent() {
|
|
|
return parentComponent;
|
|
|
}
|
|
|
-
|
|
|
- public void paintComponent(Graphics g) {
|
|
|
- //super.paintComponent(g);
|
|
|
+
|
|
|
+ public void paintComponent(Graphics g) {
|
|
|
+ // super.paintComponent(g);
|
|
|
Graphics2D g2d = (Graphics2D) g;
|
|
|
g2d.clearRect(0, 0, this.getWidth(), this.getHeight());
|
|
|
- g2d.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING,
|
|
|
- RenderingHints.VALUE_ANTIALIAS_ON));
|
|
|
- //-->Old code
|
|
|
+ g2d.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
|
|
|
+ // -->Old code
|
|
|
if (drawEdge) {
|
|
|
g2d.setColor(Color.BLACK);
|
|
|
g2d.setStroke(new BasicStroke(1));
|
|
|
g2d.drawLine(tempCps.getPosition().getX(), tempCps.getPosition().getY(), x, y);
|
|
|
}
|
|
|
- //<--
|
|
|
- //SelectedCable
|
|
|
+ // <--
|
|
|
+ // SelectedCable
|
|
|
HashSet<Edge> selectedEdges = new HashSet<Edge>();
|
|
|
- for(AbstractCanvasObject aCps: model.getSelectedCpsObjects()) {
|
|
|
- for(Edge edge: aCps.getConnections()) {
|
|
|
+ for (AbstractCanvasObject aCps : model.getSelectedCpsObjects()) {
|
|
|
+ for (Edge edge : aCps.getConnections()) {
|
|
|
selectedEdges.add(edge);
|
|
|
}
|
|
|
}
|
|
|
- if(model.getSelectedEdge() != null) selectedEdges.add(model.getSelectedEdge());
|
|
|
+ if (model.getSelectedEdge() != null)
|
|
|
+ selectedEdges.add(model.getSelectedEdge());
|
|
|
|
|
|
-
|
|
|
- DecoratedGroupNode actualGroupNode = controller.getSimManager().getActualVisualRepresentationalState().getCreatedGroupNodes().get(upperNode);
|
|
|
- //VisualState Representation:
|
|
|
- for(ExitCable cable : actualGroupNode.getExitCableList()) {
|
|
|
+ DecoratedGroupNode actualGroupNode = controller.getSimManager().getActualVisualRepresentationalState()
|
|
|
+ .getCreatedGroupNodes().get(groupNode);
|
|
|
+ // VisualState Representation:
|
|
|
+ for (ExitCable cable : actualGroupNode.getExitCableList()) {
|
|
|
paintExitCable(g2d, cable);
|
|
|
}
|
|
|
- for(DecoratedCable cable : actualGroupNode.getInternCableList()) {
|
|
|
+ for (DecoratedCable cable : actualGroupNode.getInternCableList()) {
|
|
|
paintCable(g2d, cable, selectedEdges.contains(cable.getModel()));
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- for(DecoratedGroupNode dGroupNode : actualGroupNode.getGroupNodeList()) {
|
|
|
+
|
|
|
+ for (DecoratedGroupNode dGroupNode : actualGroupNode.getGroupNodeList()) {
|
|
|
paintGroupNode(g2d, dGroupNode);
|
|
|
}
|
|
|
- for(Consumer con: actualGroupNode.getConsumerList()) {
|
|
|
- paintConsumer(g2d, con);
|
|
|
+ for (Consumer con : actualGroupNode.getConsumerList()) {
|
|
|
+ paintConsumer(g2d, con);
|
|
|
}
|
|
|
- for(Supplier sup: actualGroupNode.getSupplierList()) {
|
|
|
- paintSupplier(g2d, sup);
|
|
|
+ for (Supplier sup : actualGroupNode.getSupplierList()) {
|
|
|
+ paintSupplier(g2d, sup);
|
|
|
}
|
|
|
- for(Passiv pas: actualGroupNode.getPassivList()) {
|
|
|
+ for (Passiv pas : actualGroupNode.getPassivList()) {
|
|
|
paintCanvasObject(g2d, pas);
|
|
|
}
|
|
|
- for(DecoratedSwitch dSwitch : actualGroupNode.getSwitchList()) {
|
|
|
- paintSwitch(g2d, dSwitch);
|
|
|
+ for (DecoratedSwitch dSwitch : actualGroupNode.getSwitchList()) {
|
|
|
+ paintSwitch(g2d, dSwitch);
|
|
|
}
|
|
|
- for(Node node : actualGroupNode.getNodeList()) {
|
|
|
- drawCanvasObject(g2d, "/Images/node.png" , node.getPosition());
|
|
|
+ for (Node node : actualGroupNode.getNodeList()) {
|
|
|
+ drawCanvasObject(g2d, "/Images/node.png", node.getPosition());
|
|
|
}
|
|
|
-
|
|
|
- //-->oldCode
|
|
|
+
|
|
|
+ // -->oldCode
|
|
|
if (doMark) {
|
|
|
g2d.setColor(Color.BLACK);
|
|
|
g2d.setStroke(new BasicStroke(0));
|
|
|
drawMarker(g2d);
|
|
|
}
|
|
|
- //Test Selection
|
|
|
- //Objects:
|
|
|
+ // Test Selection
|
|
|
+ // Objects:
|
|
|
g2d.setColor(Color.BLUE);
|
|
|
g2d.setStroke(new BasicStroke(1));
|
|
|
Color transparentGrey = new Color(128, 174, 247, 40);
|
|
|
- for(AbstractCanvasObject aCps: model.getSelectedCpsObjects()) {
|
|
|
- if(aCps instanceof Node) {
|
|
|
+ for (AbstractCanvasObject aCps : model.getSelectedCpsObjects()) {
|
|
|
+ if (aCps instanceof Node) {
|
|
|
Vector2Int pos = aCps.getPosition();
|
|
|
g2d.setColor(transparentGrey);
|
|
|
- g2d.fillOval(pos.getX() - (int) (controller.getScaleDiv2()), pos.getY() - (int) (controller.getScaleDiv2()), controller.getScale(), controller.getScale());
|
|
|
+ g2d.fillOval(pos.getX() - (int) (controller.getScaleDiv2()),
|
|
|
+ pos.getY() - (int) (controller.getScaleDiv2()), controller.getScale(), controller.getScale());
|
|
|
g2d.setColor(Color.LIGHT_GRAY);
|
|
|
g2d.setStroke(new BasicStroke(2));
|
|
|
- g2d.drawOval(pos.getX() - (int) (controller.getScaleDiv2()), pos.getY() - (int) (controller.getScaleDiv2()), controller.getScale(), controller.getScale());
|
|
|
- }
|
|
|
- else {
|
|
|
+ g2d.drawOval(pos.getX() - (int) (controller.getScaleDiv2()),
|
|
|
+ pos.getY() - (int) (controller.getScaleDiv2()), controller.getScale(), controller.getScale());
|
|
|
+ } else {
|
|
|
Vector2Int pos = aCps.getPosition();
|
|
|
g2d.setColor(transparentGrey);
|
|
|
- g2d.fillRect(pos.getX() - (int) (controller.getScaleDiv2()* 1.5f), pos.getY() - (int) (controller.getScaleDiv2()* 1.5f), (int) (controller.getScale()* 1.5f) , (int) (controller.getScale()* 1.5f));
|
|
|
+ g2d.fillRect(pos.getX() - (int) (controller.getScaleDiv2() * 1.5f),
|
|
|
+ pos.getY() - (int) (controller.getScaleDiv2() * 1.5f), (int) (controller.getScale() * 1.5f),
|
|
|
+ (int) (controller.getScale() * 1.5f));
|
|
|
g2d.setColor(Color.LIGHT_GRAY);
|
|
|
g2d.setStroke(new BasicStroke(2));
|
|
|
- g2d.drawRect(pos.getX() - (int) (controller.getScaleDiv2()* 1.5f), pos.getY() - (int) (controller.getScaleDiv2()* 1.5f), (int) (controller.getScale()* 1.5f) , (int) (controller.getScale()* 1.5f));
|
|
|
+ g2d.drawRect(pos.getX() - (int) (controller.getScaleDiv2() * 1.5f),
|
|
|
+ pos.getY() - (int) (controller.getScaleDiv2() * 1.5f), (int) (controller.getScale() * 1.5f),
|
|
|
+ (int) (controller.getScale() * 1.5f));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- //maybeReplace:
|
|
|
- if(mayBeReplaced != null){
|
|
|
+ // maybeReplace:
|
|
|
+ if (mayBeReplaced != null) {
|
|
|
g2d.setColor(Color.RED);
|
|
|
Vector2Int pos = mayBeReplaced.getPosition();
|
|
|
- g.drawImage(ImageImport.loadImage("/Images/replace.png") ,
|
|
|
- pos.getX() + controller.getScaleDiv2(),
|
|
|
- pos.getY() - controller.getScale(),
|
|
|
- controller.getScaleDiv2(), controller.getScaleDiv2(), null);
|
|
|
+ g.drawImage(ImageImport.loadImage("/Images/replace.png"), pos.getX() + controller.getScaleDiv2(),
|
|
|
+ pos.getY() - controller.getScale(), controller.getScaleDiv2(), controller.getScaleDiv2(), null);
|
|
|
+ }
|
|
|
+ // <-- OldCode
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void mousePressed(MouseEvent e) {
|
|
|
+ this.grabFocus();
|
|
|
+ if (!disabled) {
|
|
|
+ stopEditing();
|
|
|
+ tempCps = null;
|
|
|
+ dataSelected = null;
|
|
|
+ edgeHighlight = null;
|
|
|
+ controller.setSelecteEdge(null);
|
|
|
+ controller.setSelectedObjectID(-1);
|
|
|
+ // Object Selection
|
|
|
+
|
|
|
+ // Erase old data in the PropertyTable
|
|
|
+ if (model.getPropertyTable().getRowCount() > 0) {
|
|
|
+ for (int i = model.getPropertyTable().getRowCount() - 1; i > -1; i--) {
|
|
|
+ model.getPropertyTable().removeRow(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (e.getX() > groupNode.getLeftBorder()) {
|
|
|
+ for (AbstractCanvasObject cps : groupNode.getNodes()) {
|
|
|
+ cx = cps.getPosition().getX() - model.getScaleDiv2();
|
|
|
+ cy = cps.getPosition().getY() - model.getScaleDiv2();
|
|
|
+ if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
|
+ tempCps = cps;
|
|
|
+
|
|
|
+ dragging = true;
|
|
|
+ if (e.isControlDown() && tempCps != null) {
|
|
|
+ if (model.getSelectedCpsObjects().contains(tempCps)) {
|
|
|
+ controller.deleteSelectedObject(tempCps);
|
|
|
+ } else {
|
|
|
+ controller.addSelectedObject(tempCps);
|
|
|
+ if (tempCps instanceof GroupNode)
|
|
|
+ controller.getObjectsInDepth();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // If drawing an Edge (CTRL down)
|
|
|
+ if (tempCps.getClass() == HolonObject.class) {
|
|
|
+ HolonObject tempObj = ((HolonObject) tempCps);
|
|
|
+ dataSelected = tempObj.getElements();
|
|
|
+ }
|
|
|
+ if (e.isShiftDown()) {
|
|
|
+ drawEdge = true;
|
|
|
+ dragging = false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // look for objects connected to uppernode
|
|
|
+ int count = 0;
|
|
|
+ for (Edge ed : groupNode.getConnections()) {
|
|
|
+ AbstractCanvasObject cps;
|
|
|
+ if (ed.getA().equals(this.groupNode)) {
|
|
|
+ cps = ed.getB();
|
|
|
+ } else {
|
|
|
+ cps = ed.getA();
|
|
|
+ }
|
|
|
+ if (x - controller.getScale() <= ((groupNode.getLeftBorder() >> 1) - model.getScaleDiv2())
|
|
|
+ && y - controller.getScale() <= (scalediv20 + 5
|
|
|
+ + (model.getScale() + scalediv20 + 10) * count)
|
|
|
+ && x >= (groupNode.getLeftBorder() >> 1) - model.getScaleDiv2()
|
|
|
+ && y >= (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count)) {
|
|
|
+ tempCps = cps;
|
|
|
+ // If drawing an Edge (CTRL down)
|
|
|
+ if (tempCps.getClass() == HolonObject.class) {
|
|
|
+ HolonObject tempObj = ((HolonObject) tempCps);
|
|
|
+ dataSelected = tempObj.getElements();
|
|
|
+ }
|
|
|
+ if (e.isShiftDown()) {
|
|
|
+ drawEdge = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // Edge Selection
|
|
|
+ if (e.getButton() == MouseEvent.BUTTON1) {
|
|
|
+ if (tempCps == null) {
|
|
|
+ edgeHighlight = mousePositionOnEdge(x, y);
|
|
|
+ controller.setSelecteEdge(edgeHighlight);
|
|
|
+ controller.setSelectedObjectID(0);
|
|
|
+ if (!e.isControlDown() && e.getButton() != MouseEvent.BUTTON3) {
|
|
|
+ model.getSelectedCpsObjects().clear();
|
|
|
+ }
|
|
|
+ updCon.deleteRows(model.getMultiTable());
|
|
|
+ updCon.deleteRows(model.getSingleTable());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (edgeHighlight == null && tempCps == null) {
|
|
|
+ sx = e.getX();
|
|
|
+ sy = e.getY();
|
|
|
+ doMark = true;
|
|
|
+ }
|
|
|
+ repaint();
|
|
|
+ }
|
|
|
}
|
|
|
- //<-- OldCode
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public void mousePressed(MouseEvent e) {
|
|
|
- if(!disabled){
|
|
|
- stopEditing();
|
|
|
- tempCps = null;
|
|
|
- dataSelected = null;
|
|
|
- edgeHighlight = null;
|
|
|
- controller.setSelecteEdge(null);
|
|
|
- controller.setSelectedObjectID(-1);
|
|
|
- // Object Selection
|
|
|
-
|
|
|
- // Erase old data in the PropertyTable
|
|
|
- if (model.getPropertyTable().getRowCount() > 0) {
|
|
|
- for (int i = model.getPropertyTable().getRowCount() - 1; i > -1; i--) {
|
|
|
- model.getPropertyTable().removeRow(i);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (e.getX() > upperNode.getLeftBorder()) {
|
|
|
- for (AbstractCanvasObject cps : upperNode.getNodes()) {
|
|
|
- cx = cps.getPosition().getX() - model.getScaleDiv2();
|
|
|
- cy = cps.getPosition().getY() - model.getScaleDiv2();
|
|
|
- if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
|
- tempCps = cps;
|
|
|
-
|
|
|
-
|
|
|
- dragging = true;
|
|
|
- if (e.isControlDown() && tempCps != null) {
|
|
|
- if (model.getSelectedCpsObjects().contains(tempCps)) {
|
|
|
- controller.deleteSelectedObject(tempCps);
|
|
|
- } else {
|
|
|
- controller.addSelectedObject(tempCps);
|
|
|
- if(tempCps instanceof GroupNode)
|
|
|
- controller.getObjectsInDepth();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // If drawing an Edge (CTRL down)
|
|
|
- if (tempCps.getClass() == HolonObject.class) {
|
|
|
- HolonObject tempObj = ((HolonObject) tempCps);
|
|
|
- dataSelected = tempObj.getElements();
|
|
|
- }
|
|
|
- if (e.isShiftDown()) {
|
|
|
- drawEdge = true;
|
|
|
- dragging = false;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- // look for objects connected to uppernode
|
|
|
- int count = 0;
|
|
|
- for (Edge ed : upperNode.getConnections()) {
|
|
|
- AbstractCanvasObject cps;
|
|
|
- if (ed.getA().equals(this.upperNode)) {
|
|
|
- cps = ed.getB();
|
|
|
- } else {
|
|
|
- cps = ed.getA();
|
|
|
- }
|
|
|
- if (x - controller.getScale() <= ((upperNode.getLeftBorder() >> 1) - model.getScaleDiv2())
|
|
|
- && y - controller.getScale() <= (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count)
|
|
|
- && x >= (upperNode.getLeftBorder() >> 1) - model.getScaleDiv2()
|
|
|
- && y >= (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count)) {
|
|
|
- tempCps = cps;
|
|
|
- // If drawing an Edge (CTRL down)
|
|
|
- if (tempCps.getClass() == HolonObject.class) {
|
|
|
- HolonObject tempObj = ((HolonObject) tempCps);
|
|
|
- dataSelected = tempObj.getElements();
|
|
|
- }
|
|
|
- if (e.isShiftDown()) {
|
|
|
- drawEdge = true;
|
|
|
- }
|
|
|
- }
|
|
|
- count++;
|
|
|
- }
|
|
|
- }
|
|
|
- // Edge Selection
|
|
|
- if (e.getButton() == MouseEvent.BUTTON1) {
|
|
|
- if (tempCps == null) {
|
|
|
- edgeHighlight = mousePositionOnEdge(x, y);
|
|
|
- controller.setSelecteEdge(edgeHighlight);
|
|
|
- controller.setSelectedObjectID(0);
|
|
|
- if (!e.isControlDown() && e.getButton() != MouseEvent.BUTTON3) {
|
|
|
- model.getSelectedCpsObjects().clear();
|
|
|
- }
|
|
|
- updCon.deleteRows(model.getMultiTable());
|
|
|
- updCon.deleteRows(model.getSingleTable());
|
|
|
- }
|
|
|
-
|
|
|
- if (edgeHighlight == null && tempCps == null) {
|
|
|
- sx = e.getX();
|
|
|
- sy = e.getY();
|
|
|
- doMark = true;
|
|
|
- }
|
|
|
- repaint();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void mouseReleased(MouseEvent e) {
|
|
|
- if(!disabled){
|
|
|
- x = e.getX();
|
|
|
- y = e.getY();
|
|
|
- dragging = false;
|
|
|
- if (model.getSelectedCpsObjects().size() > 1) {
|
|
|
- model.getTableHolonElement().setModel(model.getMultiTable());
|
|
|
- } else if (model.getSelectedCpsObjects().size() == 1) {
|
|
|
- model.getTableHolonElement().setModel(model.getSingleTable());
|
|
|
- }
|
|
|
-
|
|
|
- if (drawEdge) {
|
|
|
- drawEdge = false;
|
|
|
- drawDeleteEdge();
|
|
|
- }
|
|
|
-
|
|
|
- if (dragged) {
|
|
|
- try {
|
|
|
- /**
|
|
|
- * Save State before performing NodePlacement, replacement e.g.
|
|
|
- */
|
|
|
- controller.autoSave();
|
|
|
- } catch (IOException ex) {
|
|
|
- ex.printStackTrace();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * check if tempCps could replace an Object on the UpperNodeanvas
|
|
|
- */
|
|
|
- if(model.getSelectedCpsObjects().size() == 1 && checkForReplacement(upperNode.getNodes(), tempCps, tempCps.getPosition().getX(), tempCps.getPosition().getY())){
|
|
|
- /**
|
|
|
- * if UpperNode would be replaced, close its tabs
|
|
|
- */
|
|
|
- if(mayBeReplaced instanceof GroupNode)
|
|
|
- closeUpperNodeTab(mayBeReplaced.getId());
|
|
|
- /**
|
|
|
- * replace on canvas
|
|
|
- */
|
|
|
- controller.replaceObjUpperNode(mayBeReplaced, tempCps, upperNode);
|
|
|
- mayBeReplaced=null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!e.isControlDown() && !dragged && tempCps != null && MouseEvent.BUTTON3 != e.getButton()) {
|
|
|
- model.getSelectedCpsObjects().clear();
|
|
|
- controller.addSelectedObject(tempCps);
|
|
|
- if(tempCps instanceof GroupNode)
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void mouseReleased(MouseEvent e) {
|
|
|
+ if (!disabled) {
|
|
|
+ x = e.getX();
|
|
|
+ y = e.getY();
|
|
|
+ dragging = false;
|
|
|
+ if (model.getSelectedCpsObjects().size() > 1) {
|
|
|
+ model.getTableHolonElement().setModel(model.getMultiTable());
|
|
|
+ } else if (model.getSelectedCpsObjects().size() == 1) {
|
|
|
+ model.getTableHolonElement().setModel(model.getSingleTable());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (drawEdge) {
|
|
|
+ drawEdge = false;
|
|
|
+ drawDeleteEdge();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dragged) {
|
|
|
+ try {
|
|
|
+ /**
|
|
|
+ * Save State before performing NodePlacement, replacement e.g.
|
|
|
+ */
|
|
|
+ controller.autoSave();
|
|
|
+ } catch (IOException ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * check if tempCps could replace an Object on the UpperNodeanvas
|
|
|
+ */
|
|
|
+ if (model.getSelectedCpsObjects().size() == 1 && checkForReplacement(groupNode.getNodes(), tempCps,
|
|
|
+ tempCps.getPosition().getX(), tempCps.getPosition().getY())) {
|
|
|
+ /**
|
|
|
+ * if UpperNode would be replaced, close its tabs
|
|
|
+ */
|
|
|
+ if (mayBeReplaced instanceof GroupNode)
|
|
|
+ closeUpperNodeTab(mayBeReplaced.getId());
|
|
|
+ /**
|
|
|
+ * replace on canvas
|
|
|
+ */
|
|
|
+ controller.replaceObjUpperNode(mayBeReplaced, tempCps, groupNode);
|
|
|
+ mayBeReplaced = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!e.isControlDown() && !dragged && tempCps != null && MouseEvent.BUTTON3 != e.getButton()) {
|
|
|
+ model.getSelectedCpsObjects().clear();
|
|
|
+ controller.addSelectedObject(tempCps);
|
|
|
+ if (tempCps instanceof GroupNode)
|
|
|
controller.getObjectsInDepth();
|
|
|
- }
|
|
|
-
|
|
|
- dragged = false;
|
|
|
-
|
|
|
- // Rightclick List
|
|
|
- setRightClickMenu(e);
|
|
|
-
|
|
|
- markObjects();
|
|
|
-
|
|
|
- if (doubleClick() && tempCps != null && tempCps instanceof HolonSwitch) {
|
|
|
- ((HolonSwitch) tempCps).switchState();
|
|
|
- }
|
|
|
-
|
|
|
- controller.calculateStateAndVisualForTimeStep(model.getCurIteration());
|
|
|
- triggerUpdateController();
|
|
|
- repaint();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void mouseDragged(MouseEvent e) {
|
|
|
- if(!disabled){
|
|
|
- // If Edge is drawn
|
|
|
- x = e.getX();
|
|
|
- y = e.getY();
|
|
|
- if (!model.getSelectedCpsObjects().contains(tempCps) && !doMark) {
|
|
|
- model.getSelectedCpsObjects().clear();
|
|
|
- if (tempCps != null) {
|
|
|
- controller.addSelectedObject(tempCps);
|
|
|
- }
|
|
|
- }
|
|
|
- if (dragging) {
|
|
|
- try {
|
|
|
- // tempCps in the upperNode? else its a connected Object from
|
|
|
- // outside
|
|
|
- if (upperNode.getNodes().contains(tempCps)) {
|
|
|
- dragged = true;
|
|
|
- float xDist, yDist; // Distance
|
|
|
-
|
|
|
- x = e.getX();
|
|
|
- y = e.getY();
|
|
|
-
|
|
|
- // Make sure its in bounds
|
|
|
- if (e.getX() < controller.getScaleDiv2() + upperNode.getLeftBorder() + 5)
|
|
|
- x = controller.getScaleDiv2() + upperNode.getLeftBorder() + 5;
|
|
|
- else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
|
|
|
- x = this.getWidth() - controller.getScaleDiv2();
|
|
|
- if (e.getY() < controller.getScaleDiv2())
|
|
|
- y = controller.getScaleDiv2();
|
|
|
- else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
|
|
|
- y = this.getHeight() - controller.getScaleDiv2();
|
|
|
-
|
|
|
- // Distance
|
|
|
- xDist = x - tempCps.getPosition().getX();
|
|
|
- yDist = y - tempCps.getPosition().getY();
|
|
|
-
|
|
|
- tempCps.setPosition(x, y); // Drag Position
|
|
|
-
|
|
|
- // TipText Position and name
|
|
|
- toolTip = true;
|
|
|
- toolTipText = tempCps.getName() + ", " + tempCps.getId();
|
|
|
- toolTipPos.setX(tempCps.getPosition().getX() - model.getScaleDiv2());
|
|
|
- toolTipPos.setY(tempCps.getPosition().getY() - model.getScaleDiv2());
|
|
|
-
|
|
|
- // All Selected Objects
|
|
|
- for (AbstractCanvasObject cps : model.getSelectedCpsObjects()) {
|
|
|
- if (cps != tempCps) {
|
|
|
- x = (int) (cps.getPosition().getX() + xDist);
|
|
|
- y = (int) (cps.getPosition().getY() + yDist);
|
|
|
-
|
|
|
- // Make sure its in bounds
|
|
|
- if (x < upperNode.getLeftBorder() + 5 + controller.getScaleDiv2())
|
|
|
- x = controller.getScaleDiv2() + upperNode.getLeftBorder() + 5;
|
|
|
- else if (x > this.getWidth() - controller.getScaleDiv2())
|
|
|
- x = this.getWidth() - controller.getScaleDiv2();
|
|
|
- if (y <= controller.getScaleDiv2())
|
|
|
- y = controller.getScaleDiv2();
|
|
|
- else if (y > this.getHeight() - controller.getScaleDiv2())
|
|
|
- y = this.getHeight() - controller.getScaleDiv2();
|
|
|
-
|
|
|
- cps.setPosition(x, y);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- /**
|
|
|
- * check if something would be replaced
|
|
|
- */
|
|
|
- if(model.getSelectedCpsObjects().size()==1)
|
|
|
- checkForReplacement(upperNode.getNodes(), tempCps, x, y);
|
|
|
-
|
|
|
- repaint();
|
|
|
- } catch (Exception eex) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- // Mark Objects
|
|
|
- if (doMark) {
|
|
|
- tempSelected.clear();
|
|
|
- for (AbstractCanvasObject cps : upperNode.getNodes()) {
|
|
|
- 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().getX() + model.getScaleDiv2() && y1 <= cps.getPosition().getY() + model.getScaleDiv2()
|
|
|
- && x2 >= cps.getPosition().getX() && y2 >= cps.getPosition().getY()) {
|
|
|
- tempSelected.add(cps);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- int count = 0;
|
|
|
- for (Edge ed : upperNode.getConnections()) {
|
|
|
- AbstractCanvasObject cps;
|
|
|
- if (ed.getA().equals(upperNode)) {
|
|
|
- cps = ed.getB();
|
|
|
- } else {
|
|
|
- cps = ed.getA();
|
|
|
- }
|
|
|
-
|
|
|
- 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 <= upperNode.getLeftBorder() >> 1
|
|
|
- && y1 <= (int) (5 + (model.getScale() + scalediv20 + 10) * count) + model.getScaleDiv2()
|
|
|
- && x2 >= upperNode.getLeftBorder() >> 1
|
|
|
- && y2 >= (int) (5 + (model.getScale() + scalediv20 + 10) * count)) {
|
|
|
- tempSelected.add(cps);
|
|
|
-
|
|
|
- }
|
|
|
- count++;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- repaint();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void mouseMoved(MouseEvent e) {
|
|
|
- {
|
|
|
- x = e.getX();
|
|
|
- y = e.getY();
|
|
|
- // Everything for the tooltip :)
|
|
|
- boolean on = false;
|
|
|
- for (AbstractCanvasObject cps : upperNode.getNodes()) {
|
|
|
-
|
|
|
- cx = cps.getPosition().getX() - controller.getScaleDiv2();
|
|
|
- cy = cps.getPosition().getY() - controller.getScaleDiv2();
|
|
|
-
|
|
|
- on = setToolTipInfoAndPosition(on, cps);
|
|
|
- }
|
|
|
- int count = 0;
|
|
|
- for (Edge ed : upperNode.getConnections()) {
|
|
|
-
|
|
|
- AbstractCanvasObject cps;
|
|
|
- if (ed.getA().equals(this.upperNode)) {
|
|
|
- cps = ed.getB();
|
|
|
- } else {
|
|
|
- cps = ed.getA();
|
|
|
- }
|
|
|
-
|
|
|
- cx = upperNode.getLeftBorder() >> 1;
|
|
|
- cy = (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count);
|
|
|
- if (x - 50 <= cx && y - 50 <= cy && x >= cx && y >= cy) {
|
|
|
-
|
|
|
- on = true;
|
|
|
- toolTipPos.setX(cx - 25);
|
|
|
- toolTipPos.setY(cy + 50);
|
|
|
- toolTipText = cps.getName() + ", " + cps.getId();
|
|
|
-
|
|
|
- }
|
|
|
- count++;
|
|
|
- }
|
|
|
-
|
|
|
- toolTip = on;
|
|
|
- repaint();
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ dragged = false;
|
|
|
+
|
|
|
+ // Rightclick List
|
|
|
+ setRightClickMenu(e);
|
|
|
+
|
|
|
+ markObjects();
|
|
|
+
|
|
|
+ if (doubleClick() && tempCps != null && tempCps instanceof HolonSwitch) {
|
|
|
+ ((HolonSwitch) tempCps).switchState();
|
|
|
+ }
|
|
|
+
|
|
|
+ controller.calculateStateAndVisualForTimeStep(model.getCurIteration());
|
|
|
+ triggerUpdateController();
|
|
|
+ repaint();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void mouseDragged(MouseEvent e) {
|
|
|
+ if (!disabled) {
|
|
|
+ // If Edge is drawn
|
|
|
+ x = e.getX();
|
|
|
+ y = e.getY();
|
|
|
+ if (!model.getSelectedCpsObjects().contains(tempCps) && !doMark) {
|
|
|
+ model.getSelectedCpsObjects().clear();
|
|
|
+ if (tempCps != null) {
|
|
|
+ controller.addSelectedObject(tempCps);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (dragging) {
|
|
|
+ try {
|
|
|
+ // tempCps in the upperNode? else its a connected Object from
|
|
|
+ // outside
|
|
|
+ if (groupNode.getNodes().contains(tempCps)) {
|
|
|
+ dragged = true;
|
|
|
+ float xDist, yDist; // Distance
|
|
|
+
|
|
|
+ x = e.getX();
|
|
|
+ y = e.getY();
|
|
|
+
|
|
|
+ // Make sure its in bounds
|
|
|
+ if (e.getX() < controller.getScaleDiv2() + groupNode.getLeftBorder() + 5)
|
|
|
+ x = controller.getScaleDiv2() + groupNode.getLeftBorder() + 5;
|
|
|
+ else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
|
|
|
+ x = this.getWidth() - controller.getScaleDiv2();
|
|
|
+ if (e.getY() < controller.getScaleDiv2())
|
|
|
+ y = controller.getScaleDiv2();
|
|
|
+ else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
|
|
|
+ y = this.getHeight() - controller.getScaleDiv2();
|
|
|
+
|
|
|
+ // Distance
|
|
|
+ xDist = x - tempCps.getPosition().getX();
|
|
|
+ yDist = y - tempCps.getPosition().getY();
|
|
|
+
|
|
|
+ tempCps.setPosition(x, y); // Drag Position
|
|
|
+
|
|
|
+ // TipText Position and name
|
|
|
+ toolTip = true;
|
|
|
+ toolTipText = tempCps.getName() + ", " + tempCps.getId();
|
|
|
+ toolTipPos.setX(tempCps.getPosition().getX() - model.getScaleDiv2());
|
|
|
+ toolTipPos.setY(tempCps.getPosition().getY() - model.getScaleDiv2());
|
|
|
+
|
|
|
+ // All Selected Objects
|
|
|
+ for (AbstractCanvasObject cps : model.getSelectedCpsObjects()) {
|
|
|
+ if (cps != tempCps) {
|
|
|
+ x = (int) (cps.getPosition().getX() + xDist);
|
|
|
+ y = (int) (cps.getPosition().getY() + yDist);
|
|
|
+
|
|
|
+ // Make sure its in bounds
|
|
|
+ if (x < groupNode.getLeftBorder() + 5 + controller.getScaleDiv2())
|
|
|
+ x = controller.getScaleDiv2() + groupNode.getLeftBorder() + 5;
|
|
|
+ else if (x > this.getWidth() - controller.getScaleDiv2())
|
|
|
+ x = this.getWidth() - controller.getScaleDiv2();
|
|
|
+ if (y <= controller.getScaleDiv2())
|
|
|
+ y = controller.getScaleDiv2();
|
|
|
+ else if (y > this.getHeight() - controller.getScaleDiv2())
|
|
|
+ y = this.getHeight() - controller.getScaleDiv2();
|
|
|
+
|
|
|
+ cps.setPosition(x, y);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * check if something would be replaced
|
|
|
+ */
|
|
|
+ if (model.getSelectedCpsObjects().size() == 1)
|
|
|
+ checkForReplacement(groupNode.getNodes(), tempCps, x, y);
|
|
|
+
|
|
|
+ repaint();
|
|
|
+ } catch (Exception eex) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // Mark Objects
|
|
|
+ if (doMark) {
|
|
|
+ tempSelected.clear();
|
|
|
+ for (AbstractCanvasObject cps : groupNode.getNodes()) {
|
|
|
+ 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().getX() + model.getScaleDiv2()
|
|
|
+ && y1 <= cps.getPosition().getY() + model.getScaleDiv2() && x2 >= cps.getPosition().getX()
|
|
|
+ && y2 >= cps.getPosition().getY()) {
|
|
|
+ tempSelected.add(cps);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int count = 0;
|
|
|
+ for (Edge ed : groupNode.getConnections()) {
|
|
|
+ AbstractCanvasObject cps;
|
|
|
+ if (ed.getA().equals(groupNode)) {
|
|
|
+ cps = ed.getB();
|
|
|
+ } else {
|
|
|
+ cps = ed.getA();
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 <= groupNode.getLeftBorder() >> 1
|
|
|
+ && y1 <= (int) (5 + (model.getScale() + scalediv20 + 10) * count) + model.getScaleDiv2()
|
|
|
+ && x2 >= groupNode.getLeftBorder() >> 1
|
|
|
+ && y2 >= (int) (5 + (model.getScale() + scalediv20 + 10) * count)) {
|
|
|
+ tempSelected.add(cps);
|
|
|
+
|
|
|
+ }
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ repaint();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void mouseMoved(MouseEvent e) {
|
|
|
+ {
|
|
|
+ x = e.getX();
|
|
|
+ y = e.getY();
|
|
|
+ // Everything for the tooltip :)
|
|
|
+ boolean on = false;
|
|
|
+ for (AbstractCanvasObject cps : groupNode.getNodes()) {
|
|
|
+
|
|
|
+ cx = cps.getPosition().getX() - controller.getScaleDiv2();
|
|
|
+ cy = cps.getPosition().getY() - controller.getScaleDiv2();
|
|
|
+
|
|
|
+ on = setToolTipInfoAndPosition(on, cps);
|
|
|
+ }
|
|
|
+ int count = 0;
|
|
|
+ for (Edge ed : groupNode.getConnections()) {
|
|
|
+
|
|
|
+ AbstractCanvasObject cps;
|
|
|
+ if (ed.getA().equals(this.groupNode)) {
|
|
|
+ cps = ed.getB();
|
|
|
+ } else {
|
|
|
+ cps = ed.getA();
|
|
|
+ }
|
|
|
+
|
|
|
+ cx = groupNode.getLeftBorder() >> 1;
|
|
|
+ cy = (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count);
|
|
|
+ if (x - 50 <= cx && y - 50 <= cy && x >= cx && y >= cy) {
|
|
|
+
|
|
|
+ on = true;
|
|
|
+ toolTipPos.setX(cx - 25);
|
|
|
+ toolTipPos.setY(cy + 50);
|
|
|
+ toolTipText = cps.getName() + ", " + cps.getId();
|
|
|
+
|
|
|
+ }
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+
|
|
|
+ toolTip = on;
|
|
|
+ repaint();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|