|
@@ -34,6 +34,7 @@ import java.awt.font.LineMetrics;
|
|
|
import java.awt.geom.Line2D;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
|
|
|
/**
|
|
|
* This Class is the Canvas. All Objects will be visualized here
|
|
@@ -387,13 +388,13 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
case NO_ENERGY:
|
|
|
return Color.white;
|
|
|
case OVER_SUPPLIED:
|
|
|
- return new Color(138, 43, 226);
|
|
|
+ return new Color(166, 78, 229);
|
|
|
case PARTIALLY_SUPPLIED:
|
|
|
return Color.yellow;
|
|
|
case PRODUCER:
|
|
|
return Color.lightGray;
|
|
|
case SUPPLIED:
|
|
|
- return Color.green;
|
|
|
+ return new Color(13, 175, 28);
|
|
|
default:
|
|
|
return Color.BLACK;
|
|
|
}
|
|
@@ -427,24 +428,25 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
controller.getScale(), controller.getScale(), null);
|
|
|
}
|
|
|
|
|
|
- private void paintCable(Graphics2D g, DecoratedCable cable)
|
|
|
+ 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();
|
|
|
- g.setColor(Color.BLACK);
|
|
|
- g.setStroke(new BasicStroke(2));
|
|
|
+ float capacity = cable.getModel().getCapacity();
|
|
|
switch(cable.getState()) {
|
|
|
case Burned:
|
|
|
g.setColor(Color.RED);
|
|
|
g.setStroke(new BasicStroke(2));
|
|
|
break;
|
|
|
case Working:
|
|
|
- g.setColor(Color.GREEN);
|
|
|
- g.setStroke(new BasicStroke((currentEnergy / capacity* 3) + 1));
|
|
|
+ g.setColor(new Color(13, 175, 28));
|
|
|
+ g.setStroke(new BasicStroke((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) ));
|
|
@@ -455,7 +457,7 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
drawCanvasObject(g, dSwitch.getState() == SwitchState.Open ? HolonSwitch.getSwitchOpenImage(): HolonSwitch.getSwitchClosedImage() , dSwitch.getModel().getPosition());
|
|
|
}
|
|
|
private void paintSupplyBar(Graphics2D g, float percentage, Color color, Position pos) {
|
|
|
- // +1, -2, -1 little Ajustment for pixelperfect allignment
|
|
|
+ // +1, -2, -1 little Adjustment for pixelperfect alignment
|
|
|
int barWidth = (int) (controller.getScale());
|
|
|
int barHeight = (int) (controller.getScale() / 5);
|
|
|
g.setColor(Color.WHITE);
|
|
@@ -475,14 +477,23 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
|
|
|
//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);
|
|
|
}
|
|
|
}
|
|
|
public void paintComponent(Graphics g) {
|
|
@@ -497,16 +508,24 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
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());
|
|
|
//timstep:
|
|
|
g.setFont(new Font("TimesNewRoman", Font.PLAIN, Math.max((int) (controller.getScale() / 3.5f), 10) ));
|
|
|
g.drawString("DEBUG Timestep:" + controller.getSimManager().getActualDecorState().getTimestepOfState() + ((displayOther != 0) ? " " + ((displayOther > 0) ? "+" + displayOther: displayOther): "") , 10, 10);
|
|
|
g2d.setColor(Color.BLACK);
|
|
|
for(DecoratedCable cable : controller.getSimManager().getActualDecorStateWithOffSet(displayOther).getLeftOverEdges()) {
|
|
|
- paintCable(g2d, cable);
|
|
|
+ paintCable(g2d, cable, selectedEdges.contains(cable.getModel()));
|
|
|
}
|
|
|
for(DecoratedNetwork network : controller.getSimManager().getActualDecorStateWithOffSet(displayOther).getNetworkList()) {
|
|
|
for(DecoratedCable cable : network.getDecoratedCableList()) {
|
|
|
- paintCable(g2d, cable);
|
|
|
+ paintCable(g2d, cable, selectedEdges.contains(cable.getModel()));
|
|
|
}
|
|
|
for(Consumer con: network.getConsumerList()) {
|
|
|
paintConsumer(g2d, con);
|
|
@@ -527,15 +546,48 @@ public class MyCanvas extends AbstractCanvas implements MouseListener,
|
|
|
}
|
|
|
//should be in DecorState
|
|
|
for(CpsNode node : controller.getSimManager().getActualDecorStateWithOffSet(displayOther).getNodeList()) {
|
|
|
- drawCanvasObject(g2d, "/Images/node_selected.png" , node.getPosition());
|
|
|
+ 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:
|
|
|
+ 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));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //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
|