public void paint(Graphics g) {
super.paint(g);
Graphics2D g2;
DPoint graphOrigin;
g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(LINES_COLOR);
try {
graphOrigin = new DPoint(GRAPH_LEFT_MARGIN, getHeight()
- GRAPH_BOTTOM_MARGIN);
plane = new CartesianPositivePlane(
g2,
graphOrigin,
(int) (getWidth() - GRAPH_LEFT_MARGIN - GRAPH_RIGHT_MARGIN),
(int) (getHeight() - GRAPH_TOP_MARGIN - GRAPH_BOTTOM_MARGIN),
1, yMaxValue);
} catch (Exception e) {
return;
}
g2.setStroke(DOTTED_LINES);
ArrayList<DPoint> valuesOnX = new ArrayList<DPoint>();
Vector<Object> sectors = data.getResults().getSaturationSectors();
for (int i = 0; i < sectors.size() && sectors.size() != 1; i++) {
FinalSect2D sect;// Current sector
sect = (FinalSect2D) sectors.get(i);
plane.drawProjectionOnTheXAxis(new DPoint(sect.getBeta1(),
yMaxValue));
valuesOnX.add(new DPoint(sect.getBeta1(), sect.getBeta11()));
}
g2.setStroke(LINES);
if (!valuesOnX.contains(new DPoint(1, 0)))
valuesOnX.add(new DPoint(1, 0));
if (!valuesOnX.contains(new DPoint(0, 0)))
valuesOnX.add(0, new DPoint(0, 0));
plane.drawValuesOnXAxis(valuesOnX);
ArrayList<DPoint>[] util;
util = data.getResults().getUtilization();
ArrayList<DPoint> valuesOnLeftY = new ArrayList<DPoint>();
ArrayList<DPoint> valuesOnRightY = new ArrayList<DPoint>();
g2.setStroke(BOLD_LINES);
int numOfSectors = util[0].size() / 2;
int numOfSaturatedStationPerSector[] = new int[numOfSectors];
for (int j = 0; j < data.getStationNames().length; j++) {
if (!showStation[j])
continue;
g.setColor(stationColors.get(j));
int i;
for (i = 0; i < util[j].size(); i = i + 2) {
if (i == 0) {
valuesOnLeftY.add(util[j].get(i));
}
//If the station j is saturated
if( Math.abs(util[j].get(i).getY() - util[j].get(i + 1).getY()) < EPSILON &&
Math.abs(util[j].get(i).getY() - 1) < EPSILON) {
if(numOfSaturatedStationPerSector[i/2]>=1)
g2.setStroke(DOTTED_LINES2);
numOfSaturatedStationPerSector[i/2] = numOfSaturatedStationPerSector[i/2]+1;
}
plane.drawSegment(util[j].get(i), util[j].get(i + 1));
g2.setStroke(BOLD_LINES);
}
i = i - 2;
valuesOnRightY.add(util[j].get(i + 1));
}
// g2.setColor(Color.black);
// plane.drawSegment(new DPoint(0, 1), new DPoint(1, 1));
g2.setStroke(LINES);
drawSummary(g, stationColors);
g.setColor(Color.black);
{// we always draw certain points
if (!valuesOnLeftY.contains(new DPoint(0, 1)))
valuesOnLeftY.add(new DPoint(0, 1));
if (!valuesOnRightY.contains(new DPoint(1, 1)))
valuesOnRightY.add(new DPoint(1, 1));
}
plane.drawValuesOnYAxis(valuesOnLeftY);
{// we draw the last points in another axis
ArrayList<String> labels;
ArrayList<DPoint> truePoints;
YAxisPlacer placer;
DecimalFormat formatter = new DecimalFormat("0.000");
labels = new ArrayList<String>();
truePoints = new ArrayList<DPoint>();
for (int i = 0; i < valuesOnRightY.size(); i++) {
labels.add(formatter.format(valuesOnRightY.get(i).getY()));
truePoints.add(plane.getTruePoint(valuesOnRightY.get(i)));
}
placer = new YAxisPlacer(labels, truePoints);
placer.place((Graphics2D) g, plane.getTrueX(1) + 10);
plane.drawSegment(new DPoint(1, 0), new DPoint(1, 1));
}
plane.draw("% " + data.getClassNames()[0], "Utilization");
if (tooltip != null) {
DPoint graphPoint = plane.getGraphPointFromTruePoint(tooltip);
String content = FORMATTER.format(graphPoint.getX()) + ", "
+ FORMATTER.format(graphPoint.getY());
Rectangle2D bounds = g.getFontMetrics().getStringBounds(content, g);
g.setColor(TOOL_TIP_COLOR);
g.fillRect((int) tooltip.getX(), (int) tooltip.getY()
- (int) bounds.getHeight() + 1, (int) bounds.getWidth(),
(int) bounds.getHeight() + 2);