|
@@ -6,7 +6,17 @@ import com.google.gson.JsonParseException;
|
|
|
|
|
|
import ui.controller.Control;
|
|
import ui.controller.Control;
|
|
import ui.controller.UpdateController;
|
|
import ui.controller.UpdateController;
|
|
|
|
+import ui.model.Consumer;
|
|
|
|
+import ui.model.DecoratedCable;
|
|
|
|
+import ui.model.DecoratedGroupNode;
|
|
|
|
+import ui.model.DecoratedHolonObject;
|
|
|
|
+import ui.model.DecoratedSwitch;
|
|
import ui.model.Model;
|
|
import ui.model.Model;
|
|
|
|
+import ui.model.Passiv;
|
|
|
|
+import ui.model.Supplier;
|
|
|
|
+import ui.model.VisualRepresentationalState;
|
|
|
|
+import ui.model.DecoratedHolonObject.HolonObjectState;
|
|
|
|
+import ui.model.DecoratedSwitch.SwitchState;
|
|
|
|
|
|
import javax.swing.*;
|
|
import javax.swing.*;
|
|
|
|
|
|
@@ -16,9 +26,11 @@ import java.awt.event.MouseEvent;
|
|
import java.awt.event.MouseListener;
|
|
import java.awt.event.MouseListener;
|
|
import java.awt.event.MouseMotionListener;
|
|
import java.awt.event.MouseMotionListener;
|
|
import java.awt.geom.Line2D;
|
|
import java.awt.geom.Line2D;
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
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.HashSet;
|
|
|
|
|
|
/**
|
|
/**
|
|
* This Class is the Canvas. All Objects will be visualized here
|
|
* This Class is the Canvas. All Objects will be visualized here
|
|
@@ -35,7 +47,9 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
int code;
|
|
int code;
|
|
private JLabel breadCrumb;
|
|
private JLabel breadCrumb;
|
|
private int upperNodeID;
|
|
private int upperNodeID;
|
|
-
|
|
|
|
|
|
+ private Component parent;
|
|
|
|
+ private BufferedImage parentPreview;
|
|
|
|
+ public boolean disable = false;
|
|
/**
|
|
/**
|
|
* Constructor.
|
|
* Constructor.
|
|
*
|
|
*
|
|
@@ -43,7 +57,7 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
* @param control the Controller
|
|
* @param control the Controller
|
|
* @param unitGraph
|
|
* @param unitGraph
|
|
*/
|
|
*/
|
|
- UpperNodeCanvas(Model mod, Control control, UnitGraph unitGraph, CpsUpperNode UpperNode, String parentPath) {
|
|
|
|
|
|
+ UpperNodeCanvas(Model mod, Control control, UnitGraph unitGraph, CpsUpperNode UpperNode, String parentPath, Component parentComponent) {
|
|
toolTip = false;
|
|
toolTip = false;
|
|
|
|
|
|
this.controller = control;
|
|
this.controller = control;
|
|
@@ -53,11 +67,13 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
this.code = UpperNode.hashCode();
|
|
this.code = UpperNode.hashCode();
|
|
this.path = parentPath + upperNode.getName();
|
|
this.path = parentPath + upperNode.getName();
|
|
this.breadCrumb = new JLabel(path);
|
|
this.breadCrumb = new JLabel(path);
|
|
|
|
+ this.parent = parentComponent;
|
|
|
|
+ parentPreview = this.getScaledImageOfComponent(parentComponent, 1f);
|
|
// this.add(breadCrumb);
|
|
// this.add(breadCrumb);
|
|
scalediv20 = model.getScale() / 20;
|
|
scalediv20 = model.getScale() / 20;
|
|
|
|
|
|
// Cps objecte aus dem border links schieben
|
|
// Cps objecte aus dem border links schieben
|
|
- upperNode.setLeftBorder((int) (50 + scalediv20 + scalediv20 + 10));
|
|
|
|
|
|
+ upperNode.setLeftBorder(/*(int) (50 + scalediv20 + scalediv20 + 10)*/ 0);
|
|
for (AbstractCpsObject cps : upperNode.getNodes()) {
|
|
for (AbstractCpsObject cps : upperNode.getNodes()) {
|
|
if (cps.getPosition().x < model.getScaleDiv2() + upperNode.getLeftBorder() + 5) {
|
|
if (cps.getPosition().x < model.getScaleDiv2() + upperNode.getLeftBorder() + 5) {
|
|
cps.setPosition(
|
|
cps.setPosition(
|
|
@@ -138,8 +154,8 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
animCps.get(i).getPosition().x = savePos.get(i).x;
|
|
animCps.get(i).getPosition().x = savePos.get(i).x;
|
|
animCps.get(i).getPosition().y = savePos.get(i).y;
|
|
animCps.get(i).getPosition().y = savePos.get(i).y;
|
|
}
|
|
}
|
|
- controller.addUpperNode("NodeOfNode", upperNode, model.getSelectedCpsObjects());
|
|
|
|
- controller.calculateStateForCurrentTimeStep();
|
|
|
|
|
|
+ controller.addUpperNode("GroupNode", upperNode, model.getSelectedCpsObjects());
|
|
|
|
+ controller.calculateStateAndVisualForCurrentTimeStep();
|
|
repaint();
|
|
repaint();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -186,7 +202,7 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
animCps.get(i).getPosition().y = savePos.get(i).y;
|
|
animCps.get(i).getPosition().y = savePos.get(i).y;
|
|
}
|
|
}
|
|
|
|
|
|
- controller.calculateStateForCurrentTimeStep();
|
|
|
|
|
|
+ controller.calculateStateAndVisualForCurrentTimeStep();
|
|
repaint();
|
|
repaint();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -210,12 +226,6 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
controller.addTrackingObj(o);
|
|
controller.addTrackingObj(o);
|
|
((HolonObject) o).updateTrackingInfo();
|
|
((HolonObject) o).updateTrackingInfo();
|
|
}
|
|
}
|
|
- if (model.getShowConsoleLog()) {
|
|
|
|
- controller.addTextToConsole("Tracking: ", Color.BLACK, 12, false, false, false);
|
|
|
|
- controller.addTextToConsole("" + o.getName(), Color.BLUE, 12, true, false, false);
|
|
|
|
- controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
|
|
|
|
- controller.addTextToConsole("" + o.getId(), Color.RED, 12, true, false, true);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -334,264 +344,338 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
this.addMouseMotionListener(this);
|
|
this.addMouseMotionListener(this);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Paints all Components on the Canvas.
|
|
|
|
- *
|
|
|
|
- * @param g Graphics
|
|
|
|
- */
|
|
|
|
- public void paintComponent(Graphics g) {
|
|
|
|
- String maxCap = null;
|
|
|
|
- super.paintComponent(g);
|
|
|
|
- ((JScrollPane) this.getParent().getParent()).setColumnHeaderView(breadCrumb);
|
|
|
|
- // Rendering
|
|
|
|
- g2 = (Graphics2D) g;
|
|
|
|
- RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
|
- g2.setRenderingHints(rh);
|
|
|
|
-
|
|
|
|
- // Paint the Background
|
|
|
|
- if (!upperNode.getImagePath().isEmpty()) {
|
|
|
|
- img = new ImageIcon(upperNode.getImagePath()).getImage();
|
|
|
|
- switch (upperNode.getBackgroundMode()) {
|
|
|
|
- case BackgroundPopUp.IMAGE_PIXELS:
|
|
|
|
- g2.drawImage(img, upperNode.getLeftBorder(), 0, img.getWidth(null), img.getHeight(null), null);
|
|
|
|
- break;
|
|
|
|
- case BackgroundPopUp.STRETCHED:
|
|
|
|
- g2.drawImage(img, upperNode.getLeftBorder(), 0, model.getCanvasX(), model.getCanvasY(), null);
|
|
|
|
- break;
|
|
|
|
- case BackgroundPopUp.CUSTOM:
|
|
|
|
- g2.drawImage(img, upperNode.getLeftBorder(), 0, upperNode.getImageWidht(), upperNode.getImageHeight(),
|
|
|
|
- null);
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Draw Left Border
|
|
|
|
- g2.setColor(new Color(230, 230, 230));
|
|
|
|
- g2.fillRect(0, 0, upperNode.getLeftBorder(), this.getHeight());
|
|
|
|
- g2.setColor(Color.BLACK);
|
|
|
|
- g2.drawLine(0, 0, this.getWidth(), 0);
|
|
|
|
-
|
|
|
|
- // Test SubNet Coloring
|
|
|
|
- int i = 0;
|
|
|
|
- for (SubNet s : controller.getSimManager().getSubNets()) {
|
|
|
|
-
|
|
|
|
- if (model.getSubNetColors().size() - 1 < i) {
|
|
|
|
- controller.addSubNetColor(new Color((int) (Math.random() * 255), (int) (Math.random() * 255),
|
|
|
|
- (int) (Math.random() * 255)));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (HolonObject cps : s.getObjects()) {
|
|
|
|
- cps.setBorderColor(model.getSubNetColors().get(i));
|
|
|
|
- }
|
|
|
|
- i++;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // drawEdges that is being dragged
|
|
|
|
- if (drawEdge) {
|
|
|
|
- g2.setColor(Color.BLACK);
|
|
|
|
- g2.setStroke(new BasicStroke(2));
|
|
|
|
-
|
|
|
|
- // If TempCps is an outside Object
|
|
|
|
- if (!upperNode.getNodes().contains(tempCps)) {
|
|
|
|
- int count = 0;
|
|
|
|
- for (CpsEdge e : upperNode.getConnections()) {
|
|
|
|
- if (e.getA().equals(tempCps)) {
|
|
|
|
- g2.drawLine(upperNode.getLeftBorder() >> 1, (int) (model.getScaleDiv2() + scalediv20 + 5
|
|
|
|
- + (model.getScale() + scalediv20 + 10) * count), x, y);
|
|
|
|
- } else if (e.getB().equals(tempCps)) {
|
|
|
|
- g2.drawLine(upperNode.getLeftBorder() >> 1, (int) (model.getScaleDiv2() + scalediv20 + 5
|
|
|
|
- + (model.getScale() + scalediv20 + 10) * count), x, y);
|
|
|
|
- }
|
|
|
|
- count++;
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- g2.drawLine(tempCps.getPosition().x, tempCps.getPosition().y, x, y);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // draw Edges
|
|
|
|
- for (CpsEdge con : upperNode.getNodeEdges()) {
|
|
|
|
- maxCap = paintEdge(con, maxCap);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Objects connected to upperNode
|
|
|
|
- int count = 0;
|
|
|
|
- for (CpsEdge e : upperNode.getConnections()) {
|
|
|
|
- AbstractCpsObject cps;
|
|
|
|
- if (e.getA().equals(this.upperNode)) {
|
|
|
|
- cps = e.getB();
|
|
|
|
- } else {
|
|
|
|
- cps = e.getA();
|
|
|
|
- }
|
|
|
|
- // Show and Highlight
|
|
|
|
- if (model.getSelectedCpsObjects().contains(cps) || showedInformation[4]) {
|
|
|
|
- for (CpsEdge ed : cps.getConnections()) {
|
|
|
|
- AbstractCpsObject obj = null;
|
|
|
|
- if (upperNode.getNodes().contains(ed.getA())) {
|
|
|
|
- obj = ed.getA();
|
|
|
|
- } else if (upperNode.getNodes().contains(ed.getB())) {
|
|
|
|
- obj = ed.getB();
|
|
|
|
- }
|
|
|
|
- if (obj != null) {
|
|
|
|
- if (ed.getConnected() == 0) {
|
|
|
|
-
|
|
|
|
- setEdgeState(ed);
|
|
|
|
-
|
|
|
|
- if (ed.getA().getId() == model.getSelectedObjectID()
|
|
|
|
- || ed.getB().getId() == model.getSelectedObjectID() || edgeHighlight == ed)
|
|
|
|
- g2.setColor(Color.BLUE);
|
|
|
|
- } else {
|
|
|
|
- g2.setColor(Color.DARK_GRAY);
|
|
|
|
- g2.setStroke(new BasicStroke(2));
|
|
|
|
- }
|
|
|
|
- g2.drawLine(obj.getPosition().x, obj.getPosition().y, (upperNode.getLeftBorder() >> 1),
|
|
|
|
- (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count) + 25);
|
|
|
|
- if (showedInformation[0]) {
|
|
|
|
-
|
|
|
|
- maxCap = setCapacityString(ed, maxCap);
|
|
|
|
-
|
|
|
|
- if (ed.getConnected() == 0 || ed.getConnected() == 1) {
|
|
|
|
- g2.drawString(ed.getFlow() + "/" + maxCap,
|
|
|
|
- (obj.getPosition().x + (upperNode.getLeftBorder() >> 1)) / 2,
|
|
|
|
- (obj.getPosition().y + (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count)
|
|
|
|
- + 25) / 2);
|
|
|
|
- } else {
|
|
|
|
- g2.drawString("not connected",
|
|
|
|
- (obj.getPosition().x + (upperNode.getLeftBorder() >> 1)) / 2,
|
|
|
|
- (obj.getPosition().y + (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count)
|
|
|
|
- + 25) / 2);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Border Highlighting
|
|
|
|
- if (showedInformation[3]) {
|
|
|
|
- g2.setColor(cps.getBorderColor());
|
|
|
|
- if (g2.getColor() != Color.WHITE) {
|
|
|
|
- g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20) - 3,
|
|
|
|
- (int) (scalediv20 + 5 + (25 + scalediv20 + 10) * count - scalediv20) - 3,
|
|
|
|
- (int) (50 + ((scalediv20 + 3) * 2)), (int) (50 + ((scalediv20 + 3) * 2)));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // node image
|
|
|
|
- if (cps instanceof CpsNode && (cps == tempCps || model.getSelectedCpsObject() == cps
|
|
|
|
- || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps))) {
|
|
|
|
- img = Util.loadImage("/Images/node_selected.png");
|
|
|
|
- } else {
|
|
|
|
- if (cps instanceof HolonSwitch) {
|
|
|
|
- if (((HolonSwitch) cps).getState(model.getCurIteration())) {
|
|
|
|
- ((HolonSwitch) cps).setAutoState(true);
|
|
|
|
- } else {
|
|
|
|
- ((HolonSwitch) cps).setAutoState(false);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // Highlighting
|
|
|
|
- if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
|
|
|
|
- || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
|
|
|
|
- g2.setColor(Color.BLUE);
|
|
|
|
- g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20),
|
|
|
|
- (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
|
|
|
|
- (int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
|
|
|
|
- } else if (cps instanceof HolonObject) {
|
|
|
|
- g2.setColor(((HolonObject) cps).getColor());
|
|
|
|
-
|
|
|
|
- g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20),
|
|
|
|
- (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
|
|
|
|
- (int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
|
|
|
|
- }
|
|
|
|
- // draw image
|
|
|
|
- File checkPath = new File(cps.getImage());
|
|
|
|
- if (checkPath.exists()) {
|
|
|
|
- img = new ImageIcon(cps.getImage()).getImage();
|
|
|
|
- } else {
|
|
|
|
- img = Util.loadImage(cps.getImage());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- g2.drawImage(img, (upperNode.getLeftBorder() >> 1) - 25,
|
|
|
|
- (int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count), 50, 50, null);
|
|
|
|
- count++;
|
|
|
|
- }
|
|
|
|
- // Highlighted Edge
|
|
|
|
- if (model.getSelectedObjectID() > 0 || !model.getSelectedCpsObjects().isEmpty() || !tempSelected.isEmpty()) {
|
|
|
|
- g2.setColor(Color.BLUE);
|
|
|
|
- for (CpsEdge con : upperNode.getNodeEdges()) {
|
|
|
|
- if (con.getFlow() <= con.getCapacity()) {
|
|
|
|
- g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 3) + 1, 4)));
|
|
|
|
- } else {
|
|
|
|
- g2.setStroke(new BasicStroke(2));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- maxCap = drawEdgeLine(con, maxCap);
|
|
|
|
- }
|
|
|
|
- } else if (edgeHighlight != null) {
|
|
|
|
- g2.setColor(Color.BLUE);
|
|
|
|
- if (edgeHighlight.getFlow() <= edgeHighlight.getCapacity()) {
|
|
|
|
- g2.setStroke(
|
|
|
|
- new BasicStroke(Math.min((edgeHighlight.getFlow() / edgeHighlight.getCapacity() * 3) + 1, 4)));
|
|
|
|
- } else {
|
|
|
|
- g2.setStroke(new BasicStroke(2));
|
|
|
|
- }
|
|
|
|
- if (upperNode.getNodeEdges().contains(edgeHighlight)) {
|
|
|
|
- g2.drawLine(edgeHighlight.getA().getPosition().x, edgeHighlight.getA().getPosition().y,
|
|
|
|
- edgeHighlight.getB().getPosition().x, edgeHighlight.getB().getPosition().y);
|
|
|
|
-
|
|
|
|
- maxCap = setCapacityString(edgeHighlight, maxCap);
|
|
|
|
-
|
|
|
|
- if (showedInformation[0]) {
|
|
|
|
- g2.drawString(edgeHighlight.getFlow() + "/" + maxCap,
|
|
|
|
- (edgeHighlight.getA().getPosition().x + edgeHighlight.getB().getPosition().x) / 2,
|
|
|
|
- (edgeHighlight.getA().getPosition().y + edgeHighlight.getB().getPosition().y) / 2);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //Draw ReplaceHighlight
|
|
|
|
- highlightMayBeReplaced(g2);
|
|
|
|
-
|
|
|
|
- // Objects in upper node
|
|
|
|
- for (AbstractCpsObject cps : upperNode.getNodes()) {
|
|
|
|
- // Border Highlighting
|
|
|
|
- if (showedInformation[3]) {
|
|
|
|
- g2.setColor(cps.getBorderColor());
|
|
|
|
- if (g2.getColor() != Color.WHITE) {
|
|
|
|
- g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20 - 3),
|
|
|
|
- (int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20 - 3),
|
|
|
|
- (int) (controller.getScale() + ((scalediv20 + 3) * 2)),
|
|
|
|
- (int) (controller.getScale() + ((scalediv20 + 3) * 2)));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- setEdgePictureAndHighlighting(cps);
|
|
|
|
-
|
|
|
|
- g2.drawImage(img, cps.getPosition().x - model.getScaleDiv2(), cps.getPosition().y - model.getScaleDiv2(),
|
|
|
|
- controller.getScale(), controller.getScale(), null);
|
|
|
|
- paintSupplyBar(g2,cps);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Dragged marker Highlighting
|
|
|
|
- g2.setStroke(new BasicStroke(1));
|
|
|
|
- if (doMark) {
|
|
|
|
- g2.setColor(Color.BLACK);
|
|
|
|
- drawMarker();
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Paints all Components on the Canvas.
|
|
|
|
+ *
|
|
|
|
+ * @param g
|
|
|
|
+ * Graphics
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ private Color getStateColor(HolonObjectState state) {
|
|
|
|
+ switch(state) {
|
|
|
|
+ case NOT_SUPPLIED:
|
|
|
|
+ return new Color(230, 120, 100);
|
|
|
|
+ case NO_ENERGY:
|
|
|
|
+ return Color.white;
|
|
|
|
+ case OVER_SUPPLIED:
|
|
|
|
+ return new Color(166, 78, 229);
|
|
|
|
+ case PARTIALLY_SUPPLIED:
|
|
|
|
+ return Color.yellow;
|
|
|
|
+ case PRODUCER:
|
|
|
|
+ return Color.lightGray;
|
|
|
|
+ case SUPPLIED:
|
|
|
|
+ return new Color(13, 175, 28);
|
|
|
|
+ default:
|
|
|
|
+ return Color.BLACK;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ private void paintCanvasObject(Graphics2D g, DecoratedHolonObject decoratedHolonObject){
|
|
|
|
+ Position pos = decoratedHolonObject.getModel().getPosition();
|
|
|
|
+ Color statecolor = getStateColor(decoratedHolonObject.getState());
|
|
|
|
+ g.setColor(statecolor);
|
|
|
|
+ g.fillRect(pos.x - controller.getScaleDiv2(), pos.y - controller.getScaleDiv2(), controller.getScale(), controller.getScale());
|
|
|
|
+ drawCanvasObject(g, decoratedHolonObject.getModel().getImage(), pos);
|
|
|
|
+ }
|
|
|
|
+ private void drawCanvasObjectString(Graphics2D g, Position posOfCanvasObject, float energy) {
|
|
|
|
+ g.setColor(Color.BLACK);
|
|
|
|
+ g.setFont(new Font("TimesNewRoman", Font.PLAIN, (int) (controller.getScale() / 4f) ));
|
|
|
|
+ g.drawString((energy > 0)? "+" + Float.toString(energy): Float.toString(energy), posOfCanvasObject.x - controller.getScaleDiv2(), posOfCanvasObject.y - controller.getScaleDiv2() - 1);
|
|
|
|
+ }
|
|
|
|
+ private void paintConsumer(Graphics2D g, Consumer con){
|
|
|
|
+ paintCanvasObject(g, con);
|
|
|
|
+ paintSupplyBar(g,con.getSupplyBarPercentage(), getStateColor(con.getState()), con.getModel().getPosition());
|
|
|
|
+ drawCanvasObjectString(g, con.getModel().getPosition(), -con.getEnergyNeededFromNetwork());
|
|
|
|
+ }
|
|
|
|
+ private void paintSupplier(Graphics2D g, Supplier sup){
|
|
|
|
+ paintCanvasObject(g, sup);
|
|
|
|
+ drawCanvasObjectString(g, sup.getModel().getPosition(), sup.getEnergyToSupplyNetwork());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void drawCanvasObject(Graphics2D g, String Image, Position pos) {
|
|
|
|
+ g.drawImage(Util.loadImage(Image, controller.getScale(), controller.getScale()) ,
|
|
|
|
+ pos.x - controller.getScaleDiv2(),
|
|
|
|
+ pos.y - controller.getScaleDiv2(),
|
|
|
|
+ controller.getScale(), controller.getScale() , null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void paintCable(Graphics2D g, DecoratedCable cable, boolean isSelected)
|
|
|
|
+ {
|
|
|
|
+ Position start = cable.getModel().getA().getPosition();
|
|
|
|
+ Position end = cable.getModel().getB().getPosition();
|
|
|
|
+ float currentEnergy = cable.getFlowEnergy();
|
|
|
|
+ float capacity = cable.getModel().getCapacity();
|
|
|
|
+ boolean unlimited = cable.getModel().isUnlimitedCapacity();
|
|
|
|
+ switch(cable.getState()) {
|
|
|
|
+ case Burned:
|
|
|
|
+ g.setColor(Color.RED);
|
|
|
|
+ g.setStroke(new BasicStroke(2));
|
|
|
|
+ break;
|
|
|
|
+ case Working:
|
|
|
|
+ g.setColor(new Color(13, 175, 28));
|
|
|
|
+ g.setStroke(new BasicStroke(unlimited?2f:(currentEnergy / capacity * 2f) + 1));
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if(isSelected){
|
|
|
|
+ g.setColor(Color.lightGray);
|
|
|
|
+ }
|
|
|
|
+ g.drawLine(start.x, start.y, end.x, end.y);
|
|
|
|
+ Position middle = new Position((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
|
|
+ g.setFont(new Font("TimesRoman", Font.PLAIN, Math.max((int) (controller.getScale() / 3.5f), 10) ));
|
|
|
|
+ g.drawString(currentEnergy + "/" + (unlimited?"\u221E":capacity) , middle.x, middle.y);
|
|
|
|
+ }
|
|
|
|
+ private void paintSwitch(Graphics2D g, DecoratedSwitch dSwitch)
|
|
|
|
+ {
|
|
|
|
+ drawCanvasObject(g, dSwitch.getState() == SwitchState.Open ? HolonSwitch.getSwitchOpenImage(): HolonSwitch.getSwitchClosedImage() , dSwitch.getModel().getPosition());
|
|
|
|
+ }
|
|
|
|
+ private void paintGroupNode(Graphics2D g, DecoratedGroupNode dGroupNode) {
|
|
|
|
+ Position pos = dGroupNode.getModel().getPosition();
|
|
|
|
+ g.setColor(Color.lightGray);
|
|
|
|
+ g.fillRect(pos.x - controller.getScaleDiv2(), pos.y - controller.getScaleDiv2(), controller.getScale(), controller.getScale());
|
|
|
|
+ drawCanvasObject(g, "/Images/upper_node.png" , pos);
|
|
|
|
+ paintGroupNodeBar(g, dGroupNode, pos);
|
|
|
|
+ }
|
|
|
|
+ private void paintGroupNodeBar(Graphics2D g, DecoratedGroupNode dGroupNode , Position pos) {
|
|
|
|
+ // +1, -2, -1 little Adjustment for pixel perfect alignment
|
|
|
|
+ int barWidth = (int) (controller.getScale());
|
|
|
|
+ int barHeight = (int) (controller.getScale() / 5);
|
|
|
|
+ g.setColor(Color.WHITE);
|
|
|
|
+ g.fillRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, (int) barWidth, barHeight);
|
|
|
|
+ float[] percentages = getGroupNodeBarPercentages(dGroupNode);
|
|
|
|
+ Color[] colors = new Color[6];
|
|
|
|
+ colors[0] = getStateColor(HolonObjectState.PRODUCER);
|
|
|
|
+ colors[1] = getStateColor(HolonObjectState.NOT_SUPPLIED);
|
|
|
|
+ colors[2] = getStateColor(HolonObjectState.PARTIALLY_SUPPLIED);
|
|
|
|
+ colors[3] = getStateColor(HolonObjectState.SUPPLIED);
|
|
|
|
+ colors[4] = getStateColor(HolonObjectState.OVER_SUPPLIED);
|
|
|
|
+ colors[5] = getStateColor(HolonObjectState.NO_ENERGY);
|
|
|
|
+
|
|
|
|
+ for(int i = 5; i>=0; i--) {
|
|
|
|
+ g.setColor(colors[i]);
|
|
|
|
+ g.fillRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, (int) (barWidth * percentages[i] - 1), barHeight);
|
|
|
|
+ }
|
|
|
|
+// g.setColor(color);
|
|
|
|
+// g.fillRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, (int) (barWidth * (percentage < 1 ? percentage : 1.0f) - 1), barHeight);
|
|
|
|
+ g.setColor(Color.BLACK);
|
|
|
|
+ g.setStroke(new BasicStroke(1));
|
|
|
|
+ g.drawRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, barWidth - 1 , barHeight);
|
|
|
|
+ }
|
|
|
|
+ /**
|
|
|
|
+ * HardCoded Stuff dont try at Home ;)
|
|
|
|
+ * @param dGroupNode
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public float[] getGroupNodeBarPercentages(DecoratedGroupNode dGroupNode) {
|
|
|
|
+ int[] amountOfObjects = new int[6];
|
|
|
|
+ amountOfObjects[0] = dGroupNode.getAmountOfSupplier();
|
|
|
|
+ amountOfObjects[1] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
|
|
|
|
+ amountOfObjects[2] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
|
|
|
|
+ amountOfObjects[3] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
|
|
|
|
+ amountOfObjects[4] = dGroupNode.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
|
|
|
|
+ amountOfObjects[5] = dGroupNode.getAmountOfPassiv();
|
|
|
|
+ int countHolonObjects = amountOfObjects[0] + amountOfObjects[1] + amountOfObjects[2] + amountOfObjects[3] + amountOfObjects[4] + amountOfObjects[5];
|
|
|
|
+ float[] percentages = new float[6];
|
|
|
|
+ int count = 0;
|
|
|
|
+ for(int i = 0; i < 6; i++) {
|
|
|
|
+ count += amountOfObjects[i];
|
|
|
|
+ percentages[i] = (float)count / (float)countHolonObjects;
|
|
|
|
+ }
|
|
|
|
+ return percentages;
|
|
|
|
+ }
|
|
|
|
+ private void paintExitCable(Graphics2D g, ExitCable eCable) {
|
|
|
|
+ Position start = eCable.getStart().getPosition();
|
|
|
|
+ Position end = eCable.getFinish().getPosition();
|
|
|
|
+ float currentEnergy = eCable.getCable().getFlowEnergy();
|
|
|
|
+ float capacity = eCable.getCable().getModel().getCapacity();
|
|
|
|
+ boolean unlimited = eCable.getCable().getModel().isUnlimitedCapacity();
|
|
|
|
+ switch(eCable.getCable().getState()) {
|
|
|
|
+ case Burned:
|
|
|
|
+ g.setColor(Color.RED);
|
|
|
|
+ g.setStroke(new BasicStroke(2));
|
|
|
|
+ break;
|
|
|
|
+ case Working:
|
|
|
|
+ g.setColor(new Color(13, 175, 28));
|
|
|
|
+ g.setStroke(new BasicStroke(unlimited?2f:(currentEnergy / capacity * 2f) + 1));
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ switch(eCable.getState()) {
|
|
|
|
+ case DOWN:
|
|
|
|
+ case DOWNDOWN:
|
|
|
|
+ g.drawLine(start.x, start.y, end.x, end.y);
|
|
|
|
+ Position middle = new Position((start.x + end.x) / 2, (start.y + end.y) / 2);
|
|
|
|
+ g.setFont(new Font("TimesRoman", Font.PLAIN, Math.max((int) (controller.getScale() / 3.5f), 10) ));
|
|
|
|
+ g.drawString(currentEnergy + "/" + (unlimited?"\u221E":capacity) , middle.x, middle.y);
|
|
|
|
+ break;
|
|
|
|
+ case DOWNUP:
|
|
|
|
+ case UP:
|
|
|
|
+ Vector2d vStart = new Vector2d(start.x, start.y);
|
|
|
|
+ Vector2d vEnd = new Vector2d(end.x, end.y);
|
|
|
|
+ float stretchFactor = 4 * model.getScale();
|
|
|
|
+ stretchFactor = (stretchFactor > vStart.getDistance(vEnd))? vStart.getDistance(vEnd) : stretchFactor;
|
|
|
|
+ Vector2d vPosition = vStart.add((vEnd.subtract(vStart)).normalize().multiply(stretchFactor));
|
|
|
|
+ Position result = new Position(Math.round(vPosition.getX()),Math.round(vPosition.getY()));
|
|
|
|
+ g.drawLine(start.x, start.y, result.x, result.y);
|
|
|
|
+ Position middle1 = new Position((start.x +result.x) / 2, (start.y + +result.y) / 2);
|
|
|
|
+ g.setFont(new Font("TimesRoman", Font.PLAIN, Math.max((int) (controller.getScale() / 3.5f), 10) ));
|
|
|
|
+ g.drawString(currentEnergy + "/" + (unlimited?"\u221E":capacity) , middle1.x, middle1.y);
|
|
|
|
+ drawCanvasObject(g, "/Images/arrowUp.png" , result);
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ System.out.println("Error");
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ private void paintSupplyBar(Graphics2D g, float percentage, Color color, Position pos) {
|
|
|
|
+ // +1, -2, -1 little Adjustment for pixel perfect alignment
|
|
|
|
+ int barWidth = (int) (controller.getScale());
|
|
|
|
+ int barHeight = (int) (controller.getScale() / 5);
|
|
|
|
+ g.setColor(Color.WHITE);
|
|
|
|
+ g.fillRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, (int) barWidth, barHeight);
|
|
|
|
+ g.setColor(color);
|
|
|
|
+ g.fillRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, (int) (barWidth * (percentage < 1 ? percentage : 1.0f) - 1), barHeight);
|
|
|
|
+ g.setColor(Color.BLACK);
|
|
|
|
+ g.setStroke(new BasicStroke(1));
|
|
|
|
+ g.drawRect(pos.x - controller.getScaleDiv2(), pos.y + controller.getScaleDiv2() - 1, barWidth - 1 , barHeight);
|
|
|
|
+ g.setFont(new Font("TimesNewRoman", Font.PLAIN, (int) (barHeight * 1.5) - 2));
|
|
|
|
+ String percentageString = (Math.round((percentage * 100))) + "%";
|
|
|
|
+ int stringWidth = (int) g.getFontMetrics().getStringBounds(percentageString, g).getWidth();
|
|
|
|
+ if(percentage > 1.0f) g.setColor(Color.WHITE); //Just to see better on purple
|
|
|
|
+ g.drawString(percentageString, pos.x + 1 - stringWidth / 2, pos.y + controller.getScaleDiv2() - 1+ barHeight);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //old code
|
|
|
|
+ void drawMarker(Graphics2D g) {
|
|
|
|
+ Color transparentGrey = new Color(128, 174, 247, 40);
|
|
|
|
+ if (sx > x && sy > y) {
|
|
|
|
+ g.drawRect(x, y, sx - x, sy - y);
|
|
|
|
+ g.setColor(transparentGrey);
|
|
|
|
+ g.fillRect(x, y, sx - x, sy - y);
|
|
|
|
+ } else if (sx < x && sy < y) {
|
|
|
|
+ g.drawRect(sx, sy, x - sx, y - sy);
|
|
|
|
+ g.setColor(transparentGrey);
|
|
|
|
+ g.fillRect(sx, sy, x - sx, y - sy);
|
|
|
|
+ } else if (sx >= x) {
|
|
|
|
+ g.drawRect(x, sy, sx - x, y - sy);
|
|
|
|
+ g.setColor(transparentGrey);
|
|
|
|
+ g.fillRect(x, sy, sx - x, y - sy);
|
|
|
|
+ } else if (sy >= y) {
|
|
|
|
+ g.drawRect(sx, y, x - sx, sy - y);
|
|
|
|
+ g.setColor(transparentGrey);
|
|
|
|
+ g.fillRect(sx, y, x - sx, sy - y);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ private BufferedImage getScaledImageOfComponent(Component component, double scale) {
|
|
|
|
+ BufferedImage bi = new BufferedImage(
|
|
|
|
+ (int)(component.getWidth()*scale),
|
|
|
|
+ (int)(component.getHeight()*scale),
|
|
|
|
+ BufferedImage.TYPE_INT_RGB);
|
|
|
|
+ Graphics2D gNew = bi.createGraphics();
|
|
|
|
+ gNew.scale(scale, scale);
|
|
|
|
+ component.paint(gNew);
|
|
|
|
+ gNew.dispose();
|
|
|
|
+
|
|
|
|
+ return bi;
|
|
}
|
|
}
|
|
|
|
+ public void paintComponent(Graphics g) {
|
|
|
|
+ super.paintComponent(g);
|
|
|
|
+ Graphics2D g2d = (Graphics2D) g;
|
|
|
|
+ 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().x, tempCps.getPosition().y, x, y);
|
|
|
|
+ }
|
|
|
|
+ //<--
|
|
|
|
+ //SelectedCable
|
|
|
|
+ HashSet<CpsEdge> selectedEdges = new HashSet<CpsEdge>();
|
|
|
|
+ for(AbstractCpsObject aCps: model.getSelectedCpsObjects()) {
|
|
|
|
+ for(CpsEdge edge: aCps.getConnections()) {
|
|
|
|
+ selectedEdges.add(edge);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(model.getSelectedEdge() != null) selectedEdges.add(model.getSelectedEdge());
|
|
|
|
|
|
- // Border Line
|
|
|
|
- g2.setColor(Color.BLACK);
|
|
|
|
- g2.drawLine(upperNode.getLeftBorder(), 0, upperNode.getLeftBorder(), this.getHeight());
|
|
|
|
|
|
+
|
|
|
|
+ DecoratedGroupNode actualGroupNode = controller.getSimManager().getActualVisualRepresentationalState().getCreatedGroupNodes().get(upperNode);
|
|
|
|
+ //VisualState Representation:
|
|
|
|
+ for(ExitCable cable : actualGroupNode.getExitCableList()) {
|
|
|
|
+ paintExitCable(g2d, cable);
|
|
|
|
+ }
|
|
|
|
+ for(DecoratedCable cable : actualGroupNode.getInternCableList()) {
|
|
|
|
+ paintCable(g2d, cable, selectedEdges.contains(cable.getModel()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for(DecoratedGroupNode dGroupNode : actualGroupNode.getGroupNodeList()) {
|
|
|
|
+ paintGroupNode(g2d, dGroupNode);
|
|
|
|
+ }
|
|
|
|
+ for(Consumer con: actualGroupNode.getConsumerList()) {
|
|
|
|
+ paintConsumer(g2d, con);
|
|
|
|
+ }
|
|
|
|
+ for(Supplier sup: actualGroupNode.getSupplierList()) {
|
|
|
|
+ paintSupplier(g2d, sup);
|
|
|
|
+ }
|
|
|
|
+ for(Passiv pas: actualGroupNode.getPassivList()) {
|
|
|
|
+ paintCanvasObject(g2d, pas);
|
|
|
|
+ }
|
|
|
|
+ for(DecoratedSwitch dSwitch : actualGroupNode.getSwitchList()) {
|
|
|
|
+ paintSwitch(g2d, dSwitch);
|
|
|
|
+ }
|
|
|
|
+ for(CpsNode node : actualGroupNode.getNodeList()) {
|
|
|
|
+ drawCanvasObject(g2d, "/Images/node.png" , node.getPosition());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //-->oldCode
|
|
|
|
+ if (doMark) {
|
|
|
|
+ g2d.setColor(Color.BLACK);
|
|
|
|
+ g2d.setStroke(new BasicStroke(0));
|
|
|
|
+ drawMarker(g2d);
|
|
|
|
+ }
|
|
|
|
+ //Test Selection
|
|
|
|
+ //Objects:
|
|
|
|
+ g2d.setColor(Color.BLUE);
|
|
|
|
+ g2d.setStroke(new BasicStroke(1));
|
|
|
|
+ Color transparentGrey = new Color(128, 174, 247, 40);
|
|
|
|
+ for(AbstractCpsObject aCps: model.getSelectedCpsObjects()) {
|
|
|
|
+ if(aCps instanceof CpsNode) {
|
|
|
|
+ Position pos = aCps.getPosition();
|
|
|
|
+ g2d.setColor(transparentGrey);
|
|
|
|
+ g2d.fillOval(pos.x - (int) (controller.getScaleDiv2()), pos.y - (int) (controller.getScaleDiv2()), controller.getScale(), controller.getScale());
|
|
|
|
+ g2d.setColor(Color.LIGHT_GRAY);
|
|
|
|
+ g2d.setStroke(new BasicStroke(2));
|
|
|
|
+ g2d.drawOval(pos.x - (int) (controller.getScaleDiv2()), pos.y - (int) (controller.getScaleDiv2()), controller.getScale(), controller.getScale());
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ Position pos = aCps.getPosition();
|
|
|
|
+ g2d.setColor(transparentGrey);
|
|
|
|
+ g2d.fillRect(pos.x - (int) (controller.getScaleDiv2()* 1.5f), pos.y - (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.x - (int) (controller.getScaleDiv2()* 1.5f), pos.y - (int) (controller.getScaleDiv2()* 1.5f), (int) (controller.getScale()* 1.5f) , (int) (controller.getScale()* 1.5f));
|
|
|
|
+ }
|
|
|
|
|
|
- // Tooltip
|
|
|
|
- showTooltip(g);
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ //maybeReplace:
|
|
|
|
+ if(mayBeReplaced != null){
|
|
|
|
+ g2d.setColor(Color.RED);
|
|
|
|
+ Position pos = mayBeReplaced.getPosition();
|
|
|
|
+ g.drawImage(Util.loadImage("/Images/replace.png") ,
|
|
|
|
+ pos.x + controller.getScaleDiv2(),
|
|
|
|
+ pos.y - controller.getScale(),
|
|
|
|
+ controller.getScaleDiv2(), controller.getScaleDiv2(), null);
|
|
|
|
+ }
|
|
|
|
+ //<-- OldCode
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mouseClicked(MouseEvent e) {
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
|
+ if(!disable){
|
|
triggerUpdateController();
|
|
triggerUpdateController();
|
|
stopEditing();
|
|
stopEditing();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -604,6 +688,7 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mousePressed(MouseEvent e) {
|
|
public void mousePressed(MouseEvent e) {
|
|
|
|
+ if(!disable){
|
|
stopEditing();
|
|
stopEditing();
|
|
tempCps = null;
|
|
tempCps = null;
|
|
dataSelected = null;
|
|
dataSelected = null;
|
|
@@ -626,7 +711,6 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
tempCps = cps;
|
|
tempCps = cps;
|
|
|
|
|
|
- setConsoleTextAfterSelect(cps);
|
|
|
|
|
|
|
|
dragging = true;
|
|
dragging = true;
|
|
if (e.isControlDown() && tempCps != null) {
|
|
if (e.isControlDown() && tempCps != null) {
|
|
@@ -666,13 +750,6 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
&& x >= (upperNode.getLeftBorder() >> 1) - model.getScaleDiv2()
|
|
&& x >= (upperNode.getLeftBorder() >> 1) - model.getScaleDiv2()
|
|
&& y >= (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count)) {
|
|
&& y >= (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count)) {
|
|
tempCps = cps;
|
|
tempCps = cps;
|
|
- if (model.getShowConsoleLog()) {
|
|
|
|
- controller.addTextToConsole("Selected: ", Color.BLACK, 12, false, false, false);
|
|
|
|
- controller.addTextToConsole("" + cps.getName(), Color.BLUE, 12, true, false, false);
|
|
|
|
- controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
|
|
|
|
- controller.addTextToConsole("" + cps.getId(), Color.RED, 12, true, false, true);
|
|
|
|
- controller.setSelectedObjectID(tempCps.getId());
|
|
|
|
- }
|
|
|
|
// If drawing an Edge (CTRL down)
|
|
// If drawing an Edge (CTRL down)
|
|
if (tempCps.getClass() == HolonObject.class) {
|
|
if (tempCps.getClass() == HolonObject.class) {
|
|
HolonObject tempObj = ((HolonObject) tempCps);
|
|
HolonObject tempObj = ((HolonObject) tempCps);
|
|
@@ -713,10 +790,12 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
// }
|
|
// }
|
|
repaint();
|
|
repaint();
|
|
}
|
|
}
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mouseReleased(MouseEvent e) {
|
|
public void mouseReleased(MouseEvent e) {
|
|
|
|
+ if(!disable){
|
|
x = e.getX();
|
|
x = e.getX();
|
|
y = e.getY();
|
|
y = e.getY();
|
|
dragging = false;
|
|
dragging = false;
|
|
@@ -776,14 +855,15 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
((HolonSwitch) tempCps).switchState();
|
|
((HolonSwitch) tempCps).switchState();
|
|
}
|
|
}
|
|
|
|
|
|
- controller.calculateStateForTimeStep(model.getCurIteration());
|
|
|
|
|
|
+ controller.calculateStateAndVisualForTimeStep(model.getCurIteration());
|
|
triggerUpdateController();
|
|
triggerUpdateController();
|
|
repaint();
|
|
repaint();
|
|
-
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mouseDragged(MouseEvent e) {
|
|
public void mouseDragged(MouseEvent e) {
|
|
|
|
+ if(!disable){
|
|
// If Edge is drawn
|
|
// If Edge is drawn
|
|
x = e.getX();
|
|
x = e.getX();
|
|
y = e.getY();
|
|
y = e.getY();
|
|
@@ -852,10 +932,11 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
if(model.getSelectedCpsObjects().size()==1)
|
|
if(model.getSelectedCpsObjects().size()==1)
|
|
checkForReplacement(upperNode.getNodes(), tempCps, x, y);
|
|
checkForReplacement(upperNode.getNodes(), tempCps, x, y);
|
|
|
|
|
|
- repaint();
|
|
|
|
|
|
+ repaint();
|
|
} catch (Exception eex) {
|
|
} catch (Exception eex) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
// Mark Objects
|
|
// Mark Objects
|
|
@@ -910,14 +991,14 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
}
|
|
}
|
|
|
|
|
|
repaint();
|
|
repaint();
|
|
-
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mouseMoved(MouseEvent e) {
|
|
public void mouseMoved(MouseEvent e) {
|
|
|
|
+ {
|
|
x = e.getX();
|
|
x = e.getX();
|
|
y = e.getY();
|
|
y = e.getY();
|
|
-
|
|
|
|
// Everything for the tooltip :)
|
|
// Everything for the tooltip :)
|
|
boolean on = false;
|
|
boolean on = false;
|
|
for (AbstractCpsObject cps : upperNode.getNodes()) {
|
|
for (AbstractCpsObject cps : upperNode.getNodes()) {
|
|
@@ -952,6 +1033,7 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
|
|
|
|
toolTip = on;
|
|
toolTip = on;
|
|
repaint();
|
|
repaint();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -997,12 +1079,32 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
deleteNode = true;
|
|
deleteNode = true;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- e = new CpsEdge(cps, tempCps, model.getMaxCapacity());
|
|
|
|
- if (outsideCon) {
|
|
|
|
- controller.connectNodes(e, upperNode);
|
|
|
|
- } else {
|
|
|
|
- controller.addEdgeUpperNode(e, upperNode);
|
|
|
|
- }
|
|
|
|
|
|
+ if(!(cps instanceof CpsUpperNode || tempCps instanceof CpsUpperNode)) {
|
|
|
|
+ e = new CpsEdge(cps, tempCps, model.getMaxCapacity());
|
|
|
|
+ if (outsideCon) {
|
|
|
|
+ controller.connectNodes(e, upperNode);
|
|
|
|
+ } else {
|
|
|
|
+ controller.addEdgeUpperNode(e, upperNode);
|
|
|
|
+ }
|
|
|
|
+ }else if (cps instanceof CpsUpperNode && !(tempCps instanceof CpsUpperNode)){
|
|
|
|
+ CpsUpperNode thisUpperNode = (CpsUpperNode)cps;
|
|
|
|
+ Object[] possibilities = thisUpperNode.getNodes().stream().map(aCps -> new ACpsHandle(aCps)).filter(aCpsHandle -> !(aCpsHandle.object instanceof CpsUpperNode)).toArray();
|
|
|
|
+ if(possibilities.length != 0) {
|
|
|
|
+ ACpsHandle selected = (ACpsHandle) JOptionPane.showInputDialog(this, "Select a inside Object:", "Connection To?", JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , possibilities, "");
|
|
|
|
+ if(selected != null) {
|
|
|
|
+ e = new CpsEdge(selected.object, tempCps, model.getMaxCapacity());
|
|
|
|
+ controller.addEdgeUpperNode(e, (CpsUpperNode)cps);
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ CpsNode n = new CpsNode("Node");
|
|
|
|
+
|
|
|
|
+ n.setPosition(x, y);
|
|
|
|
+ controller.addObjUpperNode(n, thisUpperNode);
|
|
|
|
+ e = new CpsEdge(n, tempCps, model.getMaxCapacity());
|
|
|
|
+ controller.addEdgeUpperNode(e, (CpsUpperNode)cps);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1203,23 +1305,7 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
|
-// * sets the Edge Capacity.
|
|
|
|
-// *
|
|
|
|
-// * @param cap capacity
|
|
|
|
-// */
|
|
|
|
-// public void setEdgeCapacity(float cap) {
|
|
|
|
-// controller.setMaxCapacity(cap);
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// /**
|
|
|
|
-// * Returns if Information should be shown.
|
|
|
|
-// *
|
|
|
|
-// * @return Array of boolean [0] = connection, [1] = objects
|
|
|
|
-// */
|
|
|
|
-// public boolean[] getShowedInformation() {
|
|
|
|
-// return showedInformation;
|
|
|
|
-// }
|
|
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* copies a set of given informations
|
|
* copies a set of given informations
|
|
@@ -1230,17 +1316,6 @@ public class UpperNodeCanvas extends AbstractCanvas implements MouseListener, Mo
|
|
showedInformation = informations;
|
|
showedInformation = informations;
|
|
}
|
|
}
|
|
|
|
|
|
-// /**
|
|
|
|
-// * Set the Background Image;
|
|
|
|
-// *
|
|
|
|
-// * @param imagePath Image Path
|
|
|
|
-// * @param mode Image Mode
|
|
|
|
-// * @param width Image custom width
|
|
|
|
-// * @param height Image custom height
|
|
|
|
-// */
|
|
|
|
-// public void setBackgroundImage(String imagePath, int mode, int width, int height) {
|
|
|
|
-// upperNode.setBackgroundImage(imagePath, mode, width, height);
|
|
|
|
-// }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* set tooltIp
|
|
* set tooltIp
|