|
@@ -168,27 +168,85 @@ public abstract class AbstractCanvas extends JPanel {
|
|
/**
|
|
/**
|
|
* draw and fill the supply Bar
|
|
* draw and fill the supply Bar
|
|
*/
|
|
*/
|
|
- if (model.getShowSupplyBars() && cps instanceof HolonObject) {
|
|
|
|
- HolonObject hl = (HolonObject) cps;
|
|
|
|
- if (hl != null && (hl.getState() == HolonObject.NOT_SUPPLIED
|
|
|
|
- || hl.getState() == HolonObject.PARTIALLY_SUPPLIED || hl.getState() == HolonObject.OVER_SUPPLIED
|
|
|
|
- /* || hl.getState() == HolonObject.SUPPLIED */)) {
|
|
|
|
- // calculate Positons:
|
|
|
|
- int barX = (int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20);
|
|
|
|
- int barY = (int) (cps.getPosition().y - controller.getScaleDiv2() + controller.getScale() + 1);
|
|
|
|
- int barWidth = (int) (controller.getScale() + ((scalediv20) * 2) - 1);
|
|
|
|
- int barHeight = (int) (controller.getScale() / 5);
|
|
|
|
-
|
|
|
|
- // draw Rectangle under the image
|
|
|
|
- g2.setStroke(new BasicStroke(1));
|
|
|
|
- g2.drawRect(barX, barY, barWidth, barHeight);
|
|
|
|
-
|
|
|
|
|
|
+ if (model.getShowSupplyBars() && (cps instanceof HolonObject || cps instanceof HolonBattery))
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // set Color & Percentage
|
|
|
|
+ float percentage = 0;
|
|
|
|
+ Color paintColor = Color.WHITE;
|
|
|
|
+ if(cps instanceof HolonObject)
|
|
|
|
+ {
|
|
|
|
+ HolonObject hl = (HolonObject) cps;
|
|
|
|
+ if (hl == null || !(hl.getState() == HolonObject.NOT_SUPPLIED
|
|
|
|
+ || hl.getState() == HolonObject.PARTIALLY_SUPPLIED || hl.getState() == HolonObject.OVER_SUPPLIED
|
|
|
|
+ /* || hl.getState() == HolonObject.SUPPLIED */))
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
// get supplied status
|
|
// get supplied status
|
|
- float percentage = hl.getSuppliedPercentage();
|
|
|
|
-
|
|
|
|
- // set Color
|
|
|
|
- g2.setColor(hl.getColor());
|
|
|
|
-
|
|
|
|
|
|
+ percentage = hl.getSuppliedPercentage();
|
|
|
|
+ paintColor = hl.getColor();
|
|
|
|
+ }
|
|
|
|
+ else if (cps instanceof HolonBattery)
|
|
|
|
+ {
|
|
|
|
+ HolonBattery hB = (HolonBattery) cps;
|
|
|
|
+ if(hB == null || hB.getCapacity() == 0)
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // get supplied status
|
|
|
|
+ percentage = hB.getNewStateOfCharge() / hB.getCapacity();
|
|
|
|
+ //Color lerping
|
|
|
|
+// float lerp(float point1, float point2, float alpha)
|
|
|
|
+// {
|
|
|
|
+// return point1 + alpha * (point2 - point1);
|
|
|
|
+// }
|
|
|
|
+ Color color1 = Color.RED;
|
|
|
|
+ Color color2 = Color.GREEN;
|
|
|
|
+ //
|
|
|
|
+ float colorPercentage;
|
|
|
|
+ if(percentage < 0.5f)
|
|
|
|
+ {
|
|
|
|
+ colorPercentage = percentage * 2;
|
|
|
|
+ color1 = Color.RED;
|
|
|
|
+ color2 = Color.YELLOW;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ colorPercentage = (percentage - 0.5f) * 2;
|
|
|
|
+ color1 = Color.YELLOW;
|
|
|
|
+ color2 = Color.GREEN;
|
|
|
|
+ }
|
|
|
|
+ final int dRed = color2.getRed() - color1.getRed();
|
|
|
|
+ final int dGreen = color2.getGreen() - color1.getGreen();
|
|
|
|
+ final int dBlue = color2.getBlue() - color1.getBlue();
|
|
|
|
+
|
|
|
|
+ int resultRed = color1.getRed() + (int)(colorPercentage * dRed);
|
|
|
|
+ int resultGreen = color1.getGreen() + (int)(colorPercentage * dGreen);
|
|
|
|
+ int resultBlue = color1.getBlue() + (int)( colorPercentage * dBlue);
|
|
|
|
+ //System.out.println("[r="+ resultRed + ",g="+ resultGreen + ",b=" + resultBlue+"]");
|
|
|
|
+ paintColor = new Color( resultRed,resultGreen,resultBlue);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // calculate Positons:
|
|
|
|
+ int barX = (int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20);
|
|
|
|
+ int barY = (int) (cps.getPosition().y - controller.getScaleDiv2() + controller.getScale() + 1);
|
|
|
|
+ int barWidth = (int) (controller.getScale() + ((scalediv20) * 2) - 1);
|
|
|
|
+ int barHeight = (int) (controller.getScale() / 5);
|
|
|
|
+
|
|
|
|
+ // draw Rectangle under the image
|
|
|
|
+ g2.setStroke(new BasicStroke(1));
|
|
|
|
+ g2.drawRect(barX, barY, barWidth, barHeight);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ g2.setColor(paintColor);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
// fill it accordingly if filled partially
|
|
// fill it accordingly if filled partially
|
|
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);
|
|
@@ -203,15 +261,15 @@ public abstract class AbstractCanvas extends JPanel {
|
|
|
|
|
|
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);
|
|
- }
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -241,7 +299,12 @@ public abstract class AbstractCanvas extends JPanel {
|
|
float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
|
|
float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
|
|
g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
|
|
g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
|
|
cps.getPosition().y - controller.getScaleDiv2() - 10);
|
|
cps.getPosition().y - controller.getScaleDiv2() - 10);
|
|
- }
|
|
|
|
|
|
+ }else if (showedInformation[1] && cps instanceof HolonBattery)
|
|
|
|
+ {
|
|
|
|
+ g2.setColor(Color.BLACK);
|
|
|
|
+ g2.drawString(((HolonBattery) cps).getCanvasBatteryString(), cps.getPosition().x - controller.getScaleDiv2(),
|
|
|
|
+ cps.getPosition().y - controller.getScaleDiv2() - 10);
|
|
|
|
+ }
|
|
} else if (cps instanceof HolonObject) {
|
|
} else if (cps instanceof HolonObject) {
|
|
g2.setColor(((HolonObject) cps).getColor());
|
|
g2.setColor(((HolonObject) cps).getColor());
|
|
|
|
|
|
@@ -256,7 +319,13 @@ public abstract class AbstractCanvas extends JPanel {
|
|
g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
|
|
g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
|
|
cps.getPosition().y - controller.getScaleDiv2() - 10);
|
|
cps.getPosition().y - controller.getScaleDiv2() - 10);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ }else if (cps instanceof HolonBattery) {
|
|
|
|
+ if (showedInformation[1]) {
|
|
|
|
+ g2.setColor(Color.BLACK);
|
|
|
|
+ g2.drawString(((HolonBattery) cps).getCanvasBatteryString(), cps.getPosition().x - controller.getScaleDiv2(),
|
|
|
|
+ cps.getPosition().y - controller.getScaleDiv2() - 10);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
// draw image
|
|
// draw image
|
|
File checkPath = new File(cps.getImage());
|
|
File checkPath = new File(cps.getImage());
|
|
if (checkPath.exists()) {
|
|
if (checkPath.exists()) {
|