|
@@ -14,154 +14,155 @@ import java.util.ArrayList;
|
|
import java.util.TimerTask;
|
|
import java.util.TimerTask;
|
|
|
|
|
|
|
|
|
|
- * Collection of methods and values needed in both <code>MyCanvas</code> and <code>UpperNodeCanvas</code>
|
|
+ * Collection of methods and values needed in both <code>MyCanvas</code> and
|
|
|
|
+ * <code>UpperNodeCanvas</code>
|
|
* <p>
|
|
* <p>
|
|
- * Although Java works on references we chose to add explicit return values for clearer code understanding in most cases
|
|
+ * Although Java works on references we chose to add explicit return values for
|
|
|
|
+ * clearer code understanding in most cases
|
|
*
|
|
*
|
|
* @author: I. Dix
|
|
* @author: I. Dix
|
|
*/
|
|
*/
|
|
public abstract class AbstractCanvas extends JPanel {
|
|
public abstract class AbstractCanvas extends JPanel {
|
|
- final JMenuItem itemDelete = new JMenuItem(Languages.getLanguage()[98]);
|
|
+ final JMenuItem itemDelete = new JMenuItem(Languages.getLanguage()[98]);
|
|
- final JMenuItem itemCut = new JMenuItem(Languages.getLanguage()[95]);
|
|
+ final JMenuItem itemCut = new JMenuItem(Languages.getLanguage()[95]);
|
|
- final JMenuItem itemCopy = new JMenuItem(Languages.getLanguage()[96]);
|
|
+ final JMenuItem itemCopy = new JMenuItem(Languages.getLanguage()[96]);
|
|
- final JMenuItem itemPaste = new JMenuItem(Languages.getLanguage()[97]);
|
|
+ final JMenuItem itemPaste = new JMenuItem(Languages.getLanguage()[97]);
|
|
- final JMenuItem itemGroup = new JMenuItem(Languages.getLanguage()[99]);
|
|
+ final JMenuItem itemGroup = new JMenuItem(Languages.getLanguage()[99]);
|
|
- final JMenuItem itemUngroup = new JMenuItem(Languages.getLanguage()[100]);
|
|
+ final JMenuItem itemUngroup = new JMenuItem(Languages.getLanguage()[100]);
|
|
- final JMenuItem itemTrack = new JMenuItem(Languages.getLanguage()[101]);
|
|
+ final JMenuItem itemTrack = new JMenuItem(Languages.getLanguage()[101]);
|
|
- final JMenuItem itemUntrack = new JMenuItem(Languages.getLanguage()[102]);
|
|
+ final JMenuItem itemUntrack = new JMenuItem(Languages.getLanguage()[102]);
|
|
- final JMenuItem itemCreateTemplate = new JMenuItem(Languages.getLanguage()[Languages.right_click_create_template]);
|
|
+ final JMenuItem itemCreateTemplate = new JMenuItem(Languages.getLanguage()[Languages.right_click_create_template]);
|
|
- final int ANIMTIME = 500;
|
|
+ final int ANIMTIME = 500;
|
|
- private final int animFPS = 60;
|
|
+ private final int animFPS = 60;
|
|
- final int animDelay = 1000 / animFPS;
|
|
+ final int animDelay = 1000 / animFPS;
|
|
- protected Model model;
|
|
+ protected Model model;
|
|
- protected Control controller;
|
|
+ protected Control controller;
|
|
- protected int x = 0;
|
|
+ protected int x = 0;
|
|
- protected int y = 0;
|
|
+ protected int y = 0;
|
|
-
|
|
+
|
|
- AbstractCpsObject tempCps = null;
|
|
+ AbstractCpsObject tempCps = null;
|
|
- UpdateController updCon;
|
|
+ UpdateController updCon;
|
|
-
|
|
+
|
|
- JPopupMenu popmenu = new JPopupMenu();
|
|
+ JPopupMenu popmenu = new JPopupMenu();
|
|
-
|
|
+
|
|
- boolean toolTip;
|
|
+ boolean toolTip;
|
|
- Position toolTipPos = new Position();
|
|
+ Position toolTipPos = new Position();
|
|
- String toolTipText = "";
|
|
+ String toolTipText = "";
|
|
- ArrayList<HolonElement> dataSelected = new ArrayList<>();
|
|
+ ArrayList<HolonElement> dataSelected = new ArrayList<>();
|
|
- ArrayList<AbstractCpsObject> tempSelected = new ArrayList<>();
|
|
+ ArrayList<AbstractCpsObject> tempSelected = new ArrayList<>();
|
|
- boolean[] showedInformation = new boolean[5];
|
|
+ boolean[] showedInformation = new boolean[5];
|
|
- boolean dragging = false;
|
|
+ boolean dragging = false;
|
|
- boolean dragged = false;
|
|
+ boolean dragged = false;
|
|
- boolean drawEdge = false;
|
|
+ boolean drawEdge = false;
|
|
- boolean doMark = false;
|
|
+ boolean doMark = false;
|
|
- CpsEdge edgeHighlight = null;
|
|
+ CpsEdge edgeHighlight = null;
|
|
- Point mousePosition = new Point();
|
|
+ Point mousePosition = new Point();
|
|
- ArrayList<Position> savePos;
|
|
+ ArrayList<Position> savePos;
|
|
-
|
|
+
|
|
- int cx, cy;
|
|
+ int cx, cy;
|
|
- int sx, sy;
|
|
+ int sx, sy;
|
|
- Position unPos;
|
|
+ Position unPos;
|
|
-
|
|
+
|
|
- Timer animT;
|
|
+ Timer animT;
|
|
- int animDuration = ANIMTIME;
|
|
+ int animDuration = ANIMTIME;
|
|
- int animSteps = animDuration / animDelay;
|
|
+ int animSteps = animDuration / animDelay;
|
|
- ArrayList<AbstractCpsObject> animCps = null;
|
|
+ ArrayList<AbstractCpsObject> animCps = null;
|
|
-
|
|
+
|
|
- Image img = null;
|
|
+ Image img = null;
|
|
- Graphics2D g2;
|
|
+ Graphics2D g2;
|
|
- float scalediv20;
|
|
+ float scalediv20;
|
|
-
|
|
+
|
|
- private boolean click = false;
|
|
+ private boolean click = false;
|
|
-
|
|
+
|
|
-
|
|
+
|
|
- String paintEdge(CpsEdge con, String maxCap) {
|
|
+
|
|
- if (con.getA().getId() != model.getSelectedObjectID() && con.getB().getId() != model.getSelectedObjectID()
|
|
+ String paintEdge(CpsEdge con, String maxCap) {
|
|
- && con != edgeHighlight) {
|
|
+ if (con.getA().getId() != model.getSelectedObjectID() && con.getB().getId() != model.getSelectedObjectID()
|
|
- if (con.getConnected() == CpsEdge.CON_UPPER_NODE || con.getConnected() == CpsEdge.CON_UPPER_NODE_AND_INSIDE) {
|
|
+ && con != edgeHighlight) {
|
|
- setEdgeState(con);
|
|
+ if (con.getConnected() == CpsEdge.CON_UPPER_NODE
|
|
- } else {
|
|
+ || con.getConnected() == CpsEdge.CON_UPPER_NODE_AND_INSIDE) {
|
|
- g2.setColor(Color.DARK_GRAY);
|
|
+ setEdgeState(con);
|
|
- g2.setStroke(new BasicStroke(2));
|
|
+ } else {
|
|
- }
|
|
+ g2.setColor(Color.DARK_GRAY);
|
|
- g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
|
|
+ g2.setStroke(new BasicStroke(2));
|
|
- con.getB().getPosition().y);
|
|
+ }
|
|
-
|
|
+ g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
|
|
- maxCap = setCapacityString(con, maxCap);
|
|
+ con.getB().getPosition().y);
|
|
-
|
|
+
|
|
- if (showedInformation[0]) {
|
|
+ maxCap = setCapacityString(con, maxCap);
|
|
- if (con.getConnected() == CpsEdge.CON_UPPER_NODE
|
|
+
|
|
- || con.getConnected() == CpsEdge.CON_UPPER_NODE_AND_INSIDE) {
|
|
+ if (showedInformation[0]) {
|
|
- g2.drawString(con.getFlow() + "/" + maxCap,
|
|
+ if (con.getConnected() == CpsEdge.CON_UPPER_NODE
|
|
- (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
|
|
+ || con.getConnected() == CpsEdge.CON_UPPER_NODE_AND_INSIDE) {
|
|
- (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
|
|
+ g2.drawString(con.getFlow() + "/" + maxCap,
|
|
- } else {
|
|
+ (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
|
|
- g2.drawString("not connected", (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
|
|
+ (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
|
|
- (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
|
|
+ } else {
|
|
- }
|
|
+ g2.drawString("not connected", (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
|
|
- }
|
|
+ (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
|
|
- }
|
|
+ }
|
|
-
|
|
+ }
|
|
- return maxCap;
|
|
+ }
|
|
- }
|
|
+
|
|
-
|
|
+ return maxCap;
|
|
-
|
|
+ }
|
|
- void setEdgeState(CpsEdge con) {
|
|
+
|
|
- if (con.isWorking()) {
|
|
+ void setEdgeState(CpsEdge con) {
|
|
- g2.setColor(Color.GREEN);
|
|
+ if (con.isWorking()) {
|
|
- if (con.getCapacity() != CpsEdge.CAPACITY_INFINITE) {
|
|
+ g2.setColor(Color.GREEN);
|
|
- g2.setStroke(new BasicStroke(Math.min(((con.getFlow() / con.getCapacity() * 3) + 1), 4)));
|
|
+ if (con.getCapacity() != CpsEdge.CAPACITY_INFINITE) {
|
|
- }
|
|
+ g2.setStroke(new BasicStroke(Math.min(((con.getFlow() / con.getCapacity() * 3) + 1), 4)));
|
|
- } else {
|
|
+ }
|
|
- g2.setColor(Color.RED);
|
|
+ } else {
|
|
- g2.setStroke(new BasicStroke(2));
|
|
+ g2.setColor(Color.RED);
|
|
- }
|
|
+ g2.setStroke(new BasicStroke(2));
|
|
- }
|
|
+ }
|
|
-
|
|
+ }
|
|
-
|
|
+
|
|
- String setCapacityString(CpsEdge con, String maxCap) {
|
|
+ String setCapacityString(CpsEdge con, String maxCap) {
|
|
- if (con.getCapacity() == -1) {
|
|
+ if (con.getCapacity() == -1) {
|
|
- maxCap = Character.toString('\u221e');
|
|
+ maxCap = Character.toString('\u221e');
|
|
- } else if (con.getCapacity() == -2) {
|
|
+ } else if (con.getCapacity() == -2) {
|
|
- maxCap = "???";
|
|
+ maxCap = "???";
|
|
- } else {
|
|
+ } else {
|
|
- maxCap = String.valueOf(con.getCapacity());
|
|
+ maxCap = String.valueOf(con.getCapacity());
|
|
- }
|
|
+ }
|
|
- return maxCap;
|
|
+ return maxCap;
|
|
- }
|
|
+ }
|
|
-
|
|
+
|
|
-
|
|
+ String drawEdgeLine(CpsEdge con, String maxCap) {
|
|
- String drawEdgeLine(CpsEdge con, String maxCap) {
|
|
+ if (con.getA().getId() == model.getSelectedObjectID() || model.getSelectedCpsObjects().contains(con.getA())
|
|
- if (con.getA().getId() == model.getSelectedObjectID()
|
|
+ || tempSelected.contains(con.getA()) || con.getB().getId() == model.getSelectedObjectID()
|
|
- || model.getSelectedCpsObjects().contains(con.getA()) || tempSelected.contains(con.getA())
|
|
+ || model.getSelectedCpsObjects().contains(con.getB())
|
|
- || con.getB().getId() == model.getSelectedObjectID()
|
|
+ || tempSelected.contains(con.getB()) && con != edgeHighlight) {
|
|
- || model.getSelectedCpsObjects().contains(con.getB())
|
|
+ g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
|
|
- || tempSelected.contains(con.getB()) && con != edgeHighlight) {
|
|
+ con.getB().getPosition().y);
|
|
- g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
|
|
+
|
|
- con.getB().getPosition().y);
|
|
+ maxCap = setCapacityString(con, maxCap);
|
|
-
|
|
+
|
|
- maxCap = setCapacityString(con, maxCap);
|
|
+ if (showedInformation[0]) {
|
|
-
|
|
+ if (con.getConnected() == CpsEdge.CON_UPPER_NODE
|
|
- if (showedInformation[0]) {
|
|
+ || con.getConnected() == CpsEdge.CON_UPPER_NODE_AND_INSIDE) {
|
|
- if (con.getConnected() == CpsEdge.CON_UPPER_NODE
|
|
+ g2.drawString(con.getFlow() + "/" + maxCap,
|
|
- || con.getConnected() == CpsEdge.CON_UPPER_NODE_AND_INSIDE) {
|
|
+ (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
|
|
- g2.drawString(con.getFlow() + "/" + maxCap,
|
|
+ (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
|
|
- (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
|
|
+ } else {
|
|
- (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
|
|
+ g2.drawString("not connected", (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
|
|
- } else {
|
|
+ (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
|
|
- g2.drawString("not connected",
|
|
+ }
|
|
- (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
|
|
+ }
|
|
- (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
|
|
+ }
|
|
- }
|
|
+
|
|
- }
|
|
+ return maxCap;
|
|
- }
|
|
+ }
|
|
-
|
|
+
|
|
- return maxCap;
|
|
+
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
* Paints the SupplyBar for the given cps object on the canvas
|
|
* Paints the SupplyBar for the given cps object on the canvas
|
|
*
|
|
*
|
|
- * @param g Graphics used
|
|
+ * @param g
|
|
- * @param cps cpsObject which the supplyBar should be drawn for
|
|
+ * Graphics used
|
|
|
|
+ * @param cps
|
|
|
|
+ * cpsObject which the supplyBar should be drawn for
|
|
*/
|
|
*/
|
|
protected void paintSupplyBar(Graphics g, AbstractCpsObject cps) {
|
|
protected void paintSupplyBar(Graphics g, AbstractCpsObject cps) {
|
|
|
|
|
|
@@ -169,16 +170,13 @@ public abstract class AbstractCanvas extends JPanel {
|
|
*/
|
|
*/
|
|
if (model.getShowSupplyBars() && cps instanceof HolonObject) {
|
|
if (model.getShowSupplyBars() && cps instanceof HolonObject) {
|
|
HolonObject hl = (HolonObject) cps;
|
|
HolonObject hl = (HolonObject) cps;
|
|
- if (hl != null
|
|
+ if (hl != null && (hl.getState() == HolonObject.NOT_SUPPLIED
|
|
- && (hl.getState() == HolonObject.NOT_SUPPLIED || hl
|
|
+ || hl.getState() == HolonObject.PARTIALLY_SUPPLIED || hl.getState() == HolonObject.OVER_SUPPLIED
|
|
- .getState() == HolonObject.PARTIALLY_SUPPLIED)) {
|
|
+ )) {
|
|
|
|
|
|
- int barX = (int) (cps.getPosition().x
|
|
+ int barX = (int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20);
|
|
- - controller.getScaleDiv2() - scalediv20);
|
|
+ int barY = (int) (cps.getPosition().y - controller.getScaleDiv2() + controller.getScale() + 1);
|
|
- int barY = (int) (cps.getPosition().y
|
|
+ int barWidth = (int) (controller.getScale() + ((scalediv20) * 2) - 1);
|
|
- - controller.getScaleDiv2() + controller.getScale() + 1);
|
|
|
|
- int barWidth = (int) (controller.getScale()
|
|
|
|
- + ((scalediv20) * 2) - 1);
|
|
|
|
int barHeight = (int) (controller.getScale() / 5);
|
|
int barHeight = (int) (controller.getScale() / 5);
|
|
|
|
|
|
|
|
|
|
@@ -191,270 +189,252 @@ public abstract class AbstractCanvas extends JPanel {
|
|
|
|
|
|
g2.setColor(hl.getColor());
|
|
g2.setColor(hl.getColor());
|
|
|
|
|
|
-
|
|
+
|
|
- g2.fillRect(barX + 1, barY + 1,
|
|
+ if (percentage < 1)
|
|
- (int) ((barWidth - 1) * percentage), barHeight - 1);
|
|
+ g2.fillRect(barX + 1, barY + 1, (int) ((barWidth - 1) * percentage), barHeight - 1);
|
|
-
|
|
+ else
|
|
|
|
+ g2.fillRect(barX + 1, barY + 1, (int) (barWidth - 1), barHeight - 1);
|
|
|
|
+
|
|
|
|
|
|
- g2.setColor(Color.BLACK);
|
|
+ if(percentage>1)
|
|
|
|
+ g2.setColor(Color.WHITE);
|
|
|
|
+ else
|
|
|
|
+ g2.setColor(Color.BLACK);
|
|
|
|
+
|
|
Font oldFont = g2.getFont();
|
|
Font oldFont = g2.getFont();
|
|
- g.setFont(new Font("TimesRoman", Font.PLAIN,
|
|
+ g.setFont(new Font("TimesRoman", Font.PLAIN, (int) (barHeight * 1.5) - 2));
|
|
- (int) (barHeight * 1.5) - 2));
|
|
|
|
|
|
|
|
- String percentageString = (Math.round((percentage * 100)))
|
|
+ String percentageString = (Math.round((percentage * 100))) + "%";
|
|
- + "%";
|
|
|
|
|
|
|
|
- int stringWidth = (int) g2.getFontMetrics()
|
|
+ int stringWidth = (int) g2.getFontMetrics().getStringBounds(percentageString, g2).getWidth();
|
|
- .getStringBounds(percentageString, g2).getWidth();
|
|
+ g2.drawString(percentageString, barX + barWidth / 2 + 1 - stringWidth / 2, barY + barHeight);
|
|
- g2.drawString(percentageString, barX + barWidth / 2 + 1
|
|
|
|
- - stringWidth / 2, barY + barHeight);
|
|
|
|
|
|
|
|
g2.setFont(oldFont);
|
|
g2.setFont(oldFont);
|
|
|
|
+ g2.setColor(Color.BLACK);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void setEdgePictureAndHighlighting(AbstractCpsObject cps) {
|
|
|
|
+
|
|
|
|
+ if (cps instanceof CpsNode && (cps == tempCps || model.getSelectedCpsObject() == cps
|
|
|
|
+ || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps))) {
|
|
|
|
+ img = Util.loadImage(this, "/Images/node_selected.png");
|
|
|
|
+ } else {
|
|
|
|
+ if (cps instanceof HolonSwitch) {
|
|
|
|
+ if (((HolonSwitch) cps).getActiveAt()[model.getCurIteration()]) {
|
|
|
|
+ ((HolonSwitch) cps).setAutoState(true);
|
|
|
|
+ } else {
|
|
|
|
+ ((HolonSwitch) cps).setAutoState(false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
|
|
|
|
+ || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
|
|
|
|
+ g2.setColor(Color.BLUE);
|
|
|
|
+ g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20),
|
|
|
|
+ (int) (cps.getPosition().y - controller.getScaleDiv2() - scalediv20),
|
|
|
|
+ (int) (controller.getScale() + (scalediv20 * 2)),
|
|
|
|
+ (int) (controller.getScale() + (scalediv20 * 2)));
|
|
|
|
+ if (showedInformation[1] && cps instanceof HolonObject) {
|
|
|
|
+ g2.setColor(Color.BLACK);
|
|
|
|
+ float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
|
|
|
|
+ g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
|
|
|
|
+ cps.getPosition().y - controller.getScaleDiv2() - 10);
|
|
|
|
+ }
|
|
|
|
+ } else if (cps instanceof HolonObject) {
|
|
|
|
+ g2.setColor(((HolonObject) cps).getColor());
|
|
|
|
+
|
|
|
|
+ g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20),
|
|
|
|
+ (int) (cps.getPosition().y - controller.getScaleDiv2() - scalediv20),
|
|
|
|
+ (int) (controller.getScale() + (scalediv20 * 2)),
|
|
|
|
+ (int) (controller.getScale() + (scalediv20 * 2)));
|
|
|
|
+
|
|
|
|
+ if (showedInformation[1]) {
|
|
|
|
+ g2.setColor(Color.BLACK);
|
|
|
|
+ float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
|
|
|
|
+ g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
|
|
|
|
+ cps.getPosition().y - controller.getScaleDiv2() - 10);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ File checkPath = new File(cps.getImage());
|
|
|
|
+ if (checkPath.exists()) {
|
|
|
|
+ img = new ImageIcon(cps.getImage()).getImage();
|
|
|
|
+ } else {
|
|
|
|
+ img = Util.loadImage(this, cps.getImage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void drawMarker() {
|
|
|
|
+ if (sx > x && sy > y) {
|
|
|
|
+ g2.drawRect(x, y, sx - x, sy - y);
|
|
|
|
+ } else if (sx < x && sy < y) {
|
|
|
|
+ g2.drawRect(sx, sy, x - sx, y - sy);
|
|
|
|
+ } else if (sx >= x) {
|
|
|
|
+ g2.drawRect(x, sy, sx - x, y - sy);
|
|
|
|
+ } else if (sy >= y) {
|
|
|
|
+ g2.drawRect(sx, y, x - sx, sy - y);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- void setEdgePictureAndHighlighting(AbstractCpsObject cps) {
|
|
+ void showTooltip(Graphics g) {
|
|
-
|
|
+ if (toolTip) {
|
|
- if (cps instanceof CpsNode && (cps == tempCps || model.getSelectedCpsObject() == cps
|
|
+ g2.setColor(new Color(255, 225, 150));
|
|
- || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps))) {
|
|
+ g2.setStroke(new BasicStroke(1));
|
|
- img = Util.loadImage(this, "/Images/node_selected.png");
|
|
+ int textWidth = g.getFontMetrics().stringWidth(toolTipText) + 2;
|
|
- } else {
|
|
+
|
|
- if (cps instanceof HolonSwitch) {
|
|
+
|
|
- if (((HolonSwitch) cps).getActiveAt()[model.getCurIteration()]) {
|
|
+
|
|
- ((HolonSwitch) cps).setAutoState(true);
|
|
+ int fixXPos = toolTipPos.x - (textWidth >> 1) + model.getScaleDiv2();
|
|
- } else {
|
|
+ int fixYPos = toolTipPos.y;
|
|
- ((HolonSwitch) cps).setAutoState(false);
|
|
+
|
|
- }
|
|
+ if (fixXPos < 0) {
|
|
- }
|
|
+ fixXPos = 0;
|
|
-
|
|
+ } else if (fixXPos + textWidth + 1 > this.getWidth()) {
|
|
- if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
|
|
+ fixXPos -= (fixXPos + textWidth + 1) - this.getWidth();
|
|
- || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
|
|
+ }
|
|
- g2.setColor(Color.BLUE);
|
|
+ if (fixYPos + 16 > this.getHeight()) {
|
|
- g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20),
|
|
+ fixYPos -= (fixYPos + 16) - this.getHeight();
|
|
- (int) (cps.getPosition().y - controller.getScaleDiv2() - scalediv20),
|
|
+ }
|
|
- (int) (controller.getScale() + (scalediv20 * 2)),
|
|
+ g2.fillRect(fixXPos, fixYPos, textWidth, 15);
|
|
- (int) (controller.getScale() + (scalediv20 * 2)));
|
|
+ g2.setColor(Color.BLACK);
|
|
- if (showedInformation[1] && cps instanceof HolonObject) {
|
|
+ g2.drawRect(fixXPos, fixYPos, textWidth, 15);
|
|
- g2.setColor(Color.BLACK);
|
|
+ g2.drawString(toolTipText, fixXPos + 2, fixYPos + 12);
|
|
- float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
|
|
+ }
|
|
- g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
|
|
+ }
|
|
- cps.getPosition().y - controller.getScaleDiv2() - 10);
|
|
+
|
|
- }else if (showedInformation[1] && cps instanceof HolonBattery)
|
|
+ void setConsoleTextAfterSelect(AbstractCpsObject cps) {
|
|
- {
|
|
+ if (model.getShowConsoleLog()) {
|
|
- g2.setColor(Color.BLACK);
|
|
+ controller.addTextToConsole("Selected: ", Color.BLACK, 12, false, false, false);
|
|
- g2.drawString(((HolonBattery) cps).getCanvasBatteryString(), cps.getPosition().x - controller.getScaleDiv2(),
|
|
+ controller.addTextToConsole("" + cps.getName(), Color.BLUE, 12, true, false, false);
|
|
- cps.getPosition().y - controller.getScaleDiv2() - 10);
|
|
+ controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
|
|
- }
|
|
+ controller.addTextToConsole("" + cps.getId(), Color.RED, 12, true, false, true);
|
|
- } else if (cps instanceof HolonObject) {
|
|
+ }
|
|
- g2.setColor(((HolonObject) cps).getColor());
|
|
+ }
|
|
-
|
|
+
|
|
- g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20),
|
|
+ void setRightClickMenu(MouseEvent e) {
|
|
- (int) (cps.getPosition().y - controller.getScaleDiv2() - scalediv20),
|
|
+ if (e.getButton() == MouseEvent.BUTTON3) {
|
|
- (int) (controller.getScale() + (scalediv20 * 2)),
|
|
+ itemPaste.setEnabled(true);
|
|
- (int) (controller.getScale() + (scalediv20 * 2)));
|
|
+ if (tempCps != null) {
|
|
-
|
|
+ itemPaste.setEnabled(true);
|
|
- if (showedInformation[1]) {
|
|
+ itemDelete.setEnabled(true);
|
|
- g2.setColor(Color.BLACK);
|
|
+ itemCut.setEnabled(true);
|
|
- float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
|
|
+ itemCopy.setEnabled(true);
|
|
- g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
|
|
+
|
|
- cps.getPosition().y - controller.getScaleDiv2() - 10);
|
|
+ if (tempCps != null) {
|
|
- }
|
|
+ itemGroup.setEnabled(true);
|
|
- }
|
|
+ itemTrack.setEnabled(true);
|
|
- else if (cps instanceof HolonBattery) {
|
|
+ itemUntrack.setEnabled(true);
|
|
- if (showedInformation[1]) {
|
|
+ }
|
|
- g2.setColor(Color.BLACK);
|
|
+
|
|
- g2.drawString(((HolonBattery) cps).getCanvasBatteryString(), cps.getPosition().x - controller.getScaleDiv2(),
|
|
+ if (tempCps instanceof CpsUpperNode)
|
|
- cps.getPosition().y - controller.getScaleDiv2() - 10);
|
|
+ itemUngroup.setEnabled(true);
|
|
- }
|
|
+ else
|
|
- }
|
|
+ itemUngroup.setEnabled(false);
|
|
-
|
|
+ if (model.getSelectedCpsObjects().size() == 0) {
|
|
- File checkPath = new File(cps.getImage());
|
|
+ controller.addSelectedObject(tempCps);
|
|
- if (checkPath.exists()) {
|
|
+ }
|
|
- img = new ImageIcon(cps.getImage()).getImage();
|
|
+ if (tempCps instanceof HolonObject) {
|
|
- } else {
|
|
+ itemCreateTemplate.setEnabled(true);
|
|
- img = Util.loadImage(this, cps.getImage());
|
|
+ } else {
|
|
- }
|
|
+ itemCreateTemplate.setEnabled(false);
|
|
- }
|
|
+ }
|
|
- }
|
|
+ } else {
|
|
-
|
|
+ itemCut.setEnabled(false);
|
|
-
|
|
+ itemCopy.setEnabled(false);
|
|
- void drawMarker() {
|
|
+ itemGroup.setEnabled(false);
|
|
- if (sx > x && sy > y) {
|
|
+ itemUngroup.setEnabled(false);
|
|
- g2.drawRect(x, y, sx - x, sy - y);
|
|
+ itemTrack.setEnabled(false);
|
|
- } else if (sx < x && sy < y) {
|
|
+ itemUntrack.setEnabled(false);
|
|
- g2.drawRect(sx, sy, x - sx, y - sy);
|
|
+ itemCreateTemplate.setEnabled(false);
|
|
- } else if (sx >= x) {
|
|
+ if (edgeHighlight != null) {
|
|
- g2.drawRect(x, sy, sx - x, y - sy);
|
|
+ itemDelete.setEnabled(true);
|
|
- } else if (sy >= y) {
|
|
+ itemPaste.setEnabled(false);
|
|
- g2.drawRect(sx, y, x - sx, sy - y);
|
|
+ } else {
|
|
- }
|
|
+ itemDelete.setEnabled(false);
|
|
- }
|
|
+ itemPaste.setEnabled(true);
|
|
-
|
|
+ }
|
|
-
|
|
+ }
|
|
- void showTooltip(Graphics g) {
|
|
+ mousePosition = this.getMousePosition();
|
|
- if (toolTip) {
|
|
+ popmenu.show(e.getComponent(), e.getX(), e.getY());
|
|
- g2.setColor(new Color(255, 225, 150));
|
|
+ }
|
|
- g2.setStroke(new BasicStroke(1));
|
|
+ }
|
|
- int textWidth = g.getFontMetrics().stringWidth(toolTipText) + 2;
|
|
+
|
|
-
|
|
+ void markObjects() {
|
|
-
|
|
+ if (doMark) {
|
|
-
|
|
+ doMark = false;
|
|
- int fixXPos = toolTipPos.x - (textWidth >> 1) + model.getScaleDiv2();
|
|
+ for (AbstractCpsObject cps : tempSelected) {
|
|
- int fixYPos = toolTipPos.y;
|
|
+ if (!model.getSelectedCpsObjects().contains(cps)) {
|
|
-
|
|
+ controller.addSelectedObject(cps);
|
|
- if (fixXPos < 0) {
|
|
+ }
|
|
- fixXPos = 0;
|
|
+ }
|
|
- } else if (fixXPos + textWidth + 1 > this.getWidth()) {
|
|
+ controller.getObjectsInDepth();
|
|
- fixXPos -= (fixXPos + textWidth + 1) - this.getWidth();
|
|
+ tempSelected.clear();
|
|
- }
|
|
+ }
|
|
- if (fixYPos + 16 > this.getHeight()) {
|
|
+ }
|
|
- fixYPos -= (fixYPos + 16) - this.getHeight();
|
|
+
|
|
- }
|
|
+
|
|
- g2.fillRect(fixXPos, fixYPos, textWidth, 15);
|
|
+ int[] determineMousePositionOnEdge(CpsEdge p) {
|
|
- g2.setColor(Color.BLACK);
|
|
+ int lx, ly, hx, hy;
|
|
- g2.drawRect(fixXPos, fixYPos, textWidth, 15);
|
|
+
|
|
- g2.drawString(toolTipText, fixXPos + 2, fixYPos + 12);
|
|
+ if (p.getA().getPosition().x > p.getB().getPosition().x) {
|
|
- }
|
|
+ hx = p.getA().getPosition().x + model.getScaleDiv2() + 7;
|
|
- }
|
|
+ lx = p.getB().getPosition().x + model.getScaleDiv2() - 7;
|
|
-
|
|
+ } else {
|
|
-
|
|
+ lx = p.getA().getPosition().x + model.getScaleDiv2() - 7;
|
|
- void setConsoleTextAfterSelect(AbstractCpsObject cps) {
|
|
+ hx = p.getB().getPosition().x + model.getScaleDiv2() + 7;
|
|
- if (model.getShowConsoleLog()) {
|
|
+ }
|
|
- controller.addTextToConsole("Selected: ", Color.BLACK, 12, false, false, false);
|
|
+ if (p.getA().getPosition().y > p.getB().getPosition().y) {
|
|
- controller.addTextToConsole("" + cps.getName(), Color.BLUE, 12, true, false, false);
|
|
+ hy = p.getA().getPosition().y + model.getScaleDiv2() + 7;
|
|
- controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
|
|
+ ly = p.getB().getPosition().y + model.getScaleDiv2() - 7;
|
|
- controller.addTextToConsole("" + cps.getId(), Color.RED, 12, true, false, true);
|
|
+ } else {
|
|
- }
|
|
+ ly = p.getA().getPosition().y + model.getScaleDiv2() - 7;
|
|
- }
|
|
+ hy = p.getB().getPosition().y + model.getScaleDiv2() + 7;
|
|
-
|
|
+ }
|
|
-
|
|
+
|
|
- void setRightClickMenu(MouseEvent e) {
|
|
+ return new int[] { lx, ly, hx, hy };
|
|
- if (e.getButton() == MouseEvent.BUTTON3) {
|
|
+ }
|
|
- itemPaste.setEnabled(true);
|
|
+
|
|
- if (tempCps != null) {
|
|
+
|
|
- itemPaste.setEnabled(true);
|
|
+ * Checks if a double click was made.
|
|
- itemDelete.setEnabled(true);
|
|
+ *
|
|
- itemCut.setEnabled(true);
|
|
+ * @return true if doublecklick, false if not
|
|
- itemCopy.setEnabled(true);
|
|
+ */
|
|
-
|
|
+ boolean doubleClick() {
|
|
- if (tempCps != null) {
|
|
+ if (click) {
|
|
- itemGroup.setEnabled(true);
|
|
+ click = false;
|
|
- itemTrack.setEnabled(true);
|
|
+ return true;
|
|
- itemUntrack.setEnabled(true);
|
|
+ } else {
|
|
- }
|
|
+ click = true;
|
|
-
|
|
+ java.util.Timer t = new java.util.Timer("doubleclickTimer", false);
|
|
- if (tempCps instanceof CpsUpperNode)
|
|
+ t.schedule(new TimerTask() {
|
|
- itemUngroup.setEnabled(true);
|
|
+ @Override
|
|
- else
|
|
+ public void run() {
|
|
- itemUngroup.setEnabled(false);
|
|
+ click = false;
|
|
- if (model.getSelectedCpsObjects().size() == 0) {
|
|
+ }
|
|
- controller.addSelectedObject(tempCps);
|
|
+ }, 500);
|
|
- }
|
|
+ }
|
|
- if(tempCps instanceof HolonObject){
|
|
+ return false;
|
|
- itemCreateTemplate.setEnabled(true);
|
|
+ }
|
|
- }else{
|
|
+
|
|
- itemCreateTemplate.setEnabled(false);
|
|
+ boolean setToolTipInfoAndPosition(boolean on, AbstractCpsObject cps) {
|
|
- }
|
|
+ if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
- }else{
|
|
+ on = true;
|
|
- itemCut.setEnabled(false);
|
|
+ toolTipPos.x = cps.getPosition().x - controller.getScaleDiv2();
|
|
- itemCopy.setEnabled(false);
|
|
+ toolTipPos.y = cps.getPosition().y + controller.getScaleDiv2();
|
|
- itemGroup.setEnabled(false);
|
|
+ toolTipText = cps.getName() + ", " + cps.getId();
|
|
- itemUngroup.setEnabled(false);
|
|
+ }
|
|
- itemTrack.setEnabled(false);
|
|
+
|
|
- itemUntrack.setEnabled(false);
|
|
+ return on;
|
|
- itemCreateTemplate.setEnabled(false);
|
|
+ }
|
|
- if(edgeHighlight != null)
|
|
+
|
|
- {
|
|
+ abstract void drawDeleteEdge();
|
|
- itemDelete.setEnabled(true);
|
|
+
|
|
- itemPaste.setEnabled(false);
|
|
+ void triggerUpdateController() {
|
|
- }
|
|
+ updCon.paintProperties(tempCps);
|
|
- else
|
|
+ updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
|
|
- {
|
|
+ updCon.refreshTableProperties(model.getPropertyTable());
|
|
- itemDelete.setEnabled(false);
|
|
+ }
|
|
- itemPaste.setEnabled(true);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- mousePosition = this.getMousePosition();
|
|
|
|
- popmenu.show(e.getComponent(), e.getX(), e.getY());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- void markObjects() {
|
|
|
|
- if (doMark) {
|
|
|
|
- doMark = false;
|
|
|
|
- for (AbstractCpsObject cps : tempSelected) {
|
|
|
|
- if (!model.getSelectedCpsObjects().contains(cps)) {
|
|
|
|
- controller.addSelectedObject(cps);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- controller.getObjectsInDepth();
|
|
|
|
- tempSelected.clear();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- int[] determineMousePositionOnEdge(CpsEdge p) {
|
|
|
|
- int lx, ly, hx, hy;
|
|
|
|
-
|
|
|
|
- if (p.getA().getPosition().x > p.getB().getPosition().x) {
|
|
|
|
- hx = p.getA().getPosition().x + model.getScaleDiv2() + 7;
|
|
|
|
- lx = p.getB().getPosition().x + model.getScaleDiv2() - 7;
|
|
|
|
- } else {
|
|
|
|
- lx = p.getA().getPosition().x + model.getScaleDiv2() - 7;
|
|
|
|
- hx = p.getB().getPosition().x + model.getScaleDiv2() + 7;
|
|
|
|
- }
|
|
|
|
- if (p.getA().getPosition().y > p.getB().getPosition().y) {
|
|
|
|
- hy = p.getA().getPosition().y + model.getScaleDiv2() + 7;
|
|
|
|
- ly = p.getB().getPosition().y + model.getScaleDiv2() - 7;
|
|
|
|
- } else {
|
|
|
|
- ly = p.getA().getPosition().y + model.getScaleDiv2() - 7;
|
|
|
|
- hy = p.getB().getPosition().y + model.getScaleDiv2() + 7;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return new int[]{lx, ly, hx, hy};
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- * Checks if a double click was made.
|
|
|
|
- *
|
|
|
|
- * @return true if doublecklick, false if not
|
|
|
|
- */
|
|
|
|
- boolean doubleClick() {
|
|
|
|
- if (click) {
|
|
|
|
- click = false;
|
|
|
|
- return true;
|
|
|
|
- } else {
|
|
|
|
- click = true;
|
|
|
|
- java.util.Timer t = new java.util.Timer("doubleclickTimer", false);
|
|
|
|
- t.schedule(new TimerTask() {
|
|
|
|
- @Override
|
|
|
|
- public void run() {
|
|
|
|
- click = false;
|
|
|
|
- }
|
|
|
|
- }, 500);
|
|
|
|
- }
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- boolean setToolTipInfoAndPosition(boolean on, AbstractCpsObject cps) {
|
|
|
|
- if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
|
|
- on = true;
|
|
|
|
- toolTipPos.x = cps.getPosition().x - controller.getScaleDiv2();
|
|
|
|
- toolTipPos.y = cps.getPosition().y + controller.getScaleDiv2();
|
|
|
|
- toolTipText = cps.getName() + ", " + cps.getId();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return on;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- abstract void drawDeleteEdge();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- void triggerUpdateController() {
|
|
|
|
- updCon.paintProperties(tempCps);
|
|
|
|
- updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
|
|
|
|
- updCon.refreshTableProperties(model.getPropertyTable());
|
|
|
|
- }
|
|
|
|
}
|
|
}
|