|
@@ -89,7 +89,7 @@ public abstract class AbstractCanvas extends JPanel {
|
|
|
|
|
|
|
|
|
|
String paintEdge(CpsEdge con, String maxCap) {
|
|
String paintEdge(CpsEdge con, String maxCap) {
|
|
- if (con.getA().getId() != model.getSelectedObjectID() && con.getB().getId() != model.getSelectedObjectID()
|
|
+ if (con!=null && con.getA().getId() != model.getSelectedObjectID() && con.getB().getId() != model.getSelectedObjectID()
|
|
&& con != edgeHighlight) {
|
|
&& con != edgeHighlight) {
|
|
if (con.getConnected() == CpsEdge.CON_UPPER_NODE
|
|
if (con.getConnected() == CpsEdge.CON_UPPER_NODE
|
|
|| con.getConnected() == CpsEdge.CON_UPPER_NODE_AND_INSIDE) {
|
|
|| con.getConnected() == CpsEdge.CON_UPPER_NODE_AND_INSIDE) {
|
|
@@ -182,47 +182,54 @@ public abstract class AbstractCanvas extends JPanel {
|
|
*/
|
|
*/
|
|
if (model.getShowSupplyBars() && (cps instanceof HolonObject || cps instanceof HolonBattery))
|
|
if (model.getShowSupplyBars() && (cps instanceof HolonObject || cps instanceof HolonBattery))
|
|
{
|
|
{
|
|
-
|
|
+
|
|
|
|
+
|
|
|
|
+ * percentage the SupplyBar is representing
|
|
|
|
+ */
|
|
float percentage = 0;
|
|
float percentage = 0;
|
|
|
|
+
|
|
|
|
+ * color of the SupplyBar
|
|
|
|
+ */
|
|
Color paintColor = Color.WHITE;
|
|
Color paintColor = Color.WHITE;
|
|
if(cps instanceof HolonObject)
|
|
if(cps instanceof HolonObject)
|
|
{
|
|
{
|
|
HolonObject hl = (HolonObject) cps;
|
|
HolonObject hl = (HolonObject) cps;
|
|
if (hl == null || !(hl.getState() == HolonObject.NOT_SUPPLIED
|
|
if (hl == null || !(hl.getState() == HolonObject.NOT_SUPPLIED
|
|
- || hl.getState() == HolonObject.PARTIALLY_SUPPLIED || hl.getState() == HolonObject.OVER_SUPPLIED))
|
|
+ || hl.getState() == HolonObject.PARTIALLY_SUPPLIED || hl.getState() == HolonObject.OVER_SUPPLIED)) {
|
|
- {
|
|
+
|
|
|
|
+ * don't show Bars for unsupplied oder fully supplied Objects
|
|
|
|
+ */
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
+
|
|
|
|
+ * calculate Percentage & set Color
|
|
|
|
+ */
|
|
percentage = hl.getSuppliedPercentage();
|
|
percentage = hl.getSuppliedPercentage();
|
|
paintColor = hl.getColor();
|
|
paintColor = hl.getColor();
|
|
}
|
|
}
|
|
- else if (cps instanceof HolonBattery)
|
|
+ else if (cps instanceof HolonBattery){
|
|
- {
|
|
|
|
HolonBattery hB = (HolonBattery) cps;
|
|
HolonBattery hB = (HolonBattery) cps;
|
|
- if(hB == null || hB.getCapacity() == 0)
|
|
+ if(hB == null || hB.getCapacity() == 0){
|
|
- {
|
|
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
+
|
|
|
|
+ * get percentage filled
|
|
|
|
+ */
|
|
percentage = hB.getStateOfChargeAtTimeStep(model.getCurIteration()-1) / hB.getCapacity();
|
|
percentage = hB.getStateOfChargeAtTimeStep(model.getCurIteration()-1) / hB.getCapacity();
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+ * calculate the Color (Red->Yellow->Green)
|
|
-
|
|
+ */
|
|
-
|
|
|
|
Color color1 = Color.RED;
|
|
Color color1 = Color.RED;
|
|
Color color2 = Color.GREEN;
|
|
Color color2 = Color.GREEN;
|
|
|
|
|
|
float colorPercentage;
|
|
float colorPercentage;
|
|
- if(percentage < 0.5f)
|
|
+ if(percentage < 0.5f){
|
|
- {
|
|
|
|
colorPercentage = percentage * 2;
|
|
colorPercentage = percentage * 2;
|
|
color1 = Color.RED;
|
|
color1 = Color.RED;
|
|
color2 = Color.YELLOW;
|
|
color2 = Color.YELLOW;
|
|
}
|
|
}
|
|
- else
|
|
+ else {
|
|
- {
|
|
|
|
colorPercentage = (percentage - 0.5f) * 2;
|
|
colorPercentage = (percentage - 0.5f) * 2;
|
|
color1 = Color.YELLOW;
|
|
color1 = Color.YELLOW;
|
|
color2 = Color.GREEN;
|
|
color2 = Color.GREEN;
|
|
@@ -234,45 +241,65 @@ public abstract class AbstractCanvas extends JPanel {
|
|
int resultRed = color1.getRed() + (int)(colorPercentage * dRed);
|
|
int resultRed = color1.getRed() + (int)(colorPercentage * dRed);
|
|
int resultGreen = color1.getGreen() + (int)(colorPercentage * dGreen);
|
|
int resultGreen = color1.getGreen() + (int)(colorPercentage * dGreen);
|
|
int resultBlue = color1.getBlue() + (int)( colorPercentage * dBlue);
|
|
int resultBlue = color1.getBlue() + (int)( colorPercentage * dBlue);
|
|
-
|
|
+
|
|
paintColor = new Color( resultRed,resultGreen,resultBlue);
|
|
paintColor = new Color( resultRed,resultGreen,resultBlue);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
|
|
+ * Starting position x of the bar
|
|
|
|
+ */
|
|
int barX = (int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20);
|
|
int barX = (int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * Starting position y of the bar
|
|
|
|
+ */
|
|
int barY = (int) (cps.getPosition().y - controller.getScaleDiv2() + controller.getScale() + 1);
|
|
int barY = (int) (cps.getPosition().y - controller.getScaleDiv2() + controller.getScale() + 1);
|
|
|
|
+
|
|
|
|
|
|
* if object should be replaced -> move bar below the ReplacementIndicator
|
|
* if object should be replaced -> move bar below the ReplacementIndicator
|
|
*/
|
|
*/
|
|
if(mayBeReplaced==cps) barY += 6;
|
|
if(mayBeReplaced==cps) barY += 6;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * Width of the bar
|
|
|
|
+ */
|
|
int barWidth = (int) (controller.getScale() + ((scalediv20) * 2) - 1);
|
|
int barWidth = (int) (controller.getScale() + ((scalediv20) * 2) - 1);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * Height of the bar
|
|
|
|
+ */
|
|
int barHeight = (int) (controller.getScale() / 5);
|
|
int barHeight = (int) (controller.getScale() / 5);
|
|
|
|
|
|
-
|
|
+
|
|
|
|
+ * draw Rectangle below the image
|
|
|
|
+ */
|
|
g2.setStroke(new BasicStroke(1));
|
|
g2.setStroke(new BasicStroke(1));
|
|
g2.drawRect(barX, barY, barWidth, barHeight);
|
|
g2.drawRect(barX, barY, barWidth, barHeight);
|
|
|
|
|
|
g2.setColor(paintColor);
|
|
g2.setColor(paintColor);
|
|
|
|
|
|
-
|
|
+
|
|
if (percentage < 1)
|
|
if (percentage < 1)
|
|
g2.fillRect(barX + 1, barY + 1, (int) ((barWidth - 1) * percentage), barHeight - 1);
|
|
g2.fillRect(barX + 1, barY + 1, (int) ((barWidth - 1) * percentage), barHeight - 1);
|
|
- else
|
|
+ else
|
|
g2.fillRect(barX + 1, barY + 1, (int) (barWidth - 1), barHeight - 1);
|
|
g2.fillRect(barX + 1, barY + 1, (int) (barWidth - 1), barHeight - 1);
|
|
|
|
|
|
-
|
|
+
|
|
if(percentage>1)
|
|
if(percentage>1)
|
|
g2.setColor(Color.WHITE);
|
|
g2.setColor(Color.WHITE);
|
|
else
|
|
else
|
|
g2.setColor(Color.BLACK);
|
|
g2.setColor(Color.BLACK);
|
|
|
|
|
|
|
|
+
|
|
Font oldFont = g2.getFont();
|
|
Font oldFont = g2.getFont();
|
|
|
|
+
|
|
g.setFont(new Font("TimesRoman", Font.PLAIN, (int) (barHeight * 1.5) - 2));
|
|
g.setFont(new Font("TimesRoman", Font.PLAIN, (int) (barHeight * 1.5) - 2));
|
|
|
|
|
|
String percentageString = (Math.round((percentage * 100))) + "%";
|
|
String percentageString = (Math.round((percentage * 100))) + "%";
|
|
int stringWidth = (int) g2.getFontMetrics().getStringBounds(percentageString, g2).getWidth();
|
|
int stringWidth = (int) g2.getFontMetrics().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);
|
|
g2.setColor(Color.BLACK);
|
|
|
|
|