// Used to avoid station label overlapping
float previousFirstPos = Float.POSITIVE_INFINITY;
for (int i = 0; i < s3d.size(); i++) {
// Current sector
FinalSect2D sect = (FinalSect2D) s3d.get(i);
double pb11 = sect.getBeta11();
double pb12 = sect.getBeta1();
double pb21 = sect.getBeta22();
double pb22 = sect.getBeta2();
// Station's number
int numstat = sect.countStation();
if (numstat > 2) {
sectorcolor = MORE;
} else if (numstat == 2) {
sectorcolor = DOUBLE;
} else {
sectorcolor = SINGLE;
}
g2.setStroke(SECTORS);
g2.setColor(sectorcolor);
g2.draw(new Line2D.Double(getX(pb11), getY(pb12), getX(pb21), getY(pb22)));
// Dotted line
g2.setStroke(DOTTED);
sectorcolor = GREY;
g2.setColor(sectorcolor);
g2.draw(new Line2D.Double(getX(pb21), getY(pb22), getX(0), getY(pb22)));
g2.draw(new Line2D.Double(getX(pb21), getY(pb22), getX(pb21), getY(0)));
// Values on X-axis
g2.setColor(BLACK);
String coordx = formatter.format(pb21);
if (i % 2 == 1 || s3d.size() == 1) {
g2.drawString(coordx, (float) (getX(pb21) - fontBounds.getWidth() / 2), (float) getY(0) + 15);
} else {
g2.drawString(coordx, (float) (getX(pb21) - fontBounds.getWidth() / 2), (float) (getY(0) + 17 + fontBounds.getHeight()));
g2.setStroke(DOTTED);
g2.setColor(GREY);
g2.draw(new Line2D.Double(getX(pb21), getY(0), getX(pb21), (float) (getY(0) + fontBounds.getHeight() + 2)));
}
// Values on Y-axis
g2.setColor(BLACK);
String coordy = formatter.format(pb12);
g2.drawString(coordy, (float) (getX(0) - fontBounds.getWidth() - 5), (float) (getY(pb12) + fontBounds.getHeight() / 2 - 2));
// Now draws station name labels. They are centered on the line of the caption (if possible)
g2.setColor(BLACK);
String etichetta = (sect.getstation()).get(0).getName();
// position of first label. Try to center with the middle of the sector but avoids overlapping with previous ones
boolean overlapping = false;
float firstpos = (float) (getY((pb12 + pb22) / 2) - (numstat - 1) * (fontBounds.getHeight()) / 2) + 3;
if (firstpos + (numstat + .5) * (float) fontBounds.getHeight() > previousFirstPos) {
// Labels are overlapping
firstpos = (float) (previousFirstPos - (numstat + .5) * fontBounds.getHeight());
overlapping = true;
}
// Updates previousFirstPos value
previousFirstPos = firstpos;
g2.drawString(etichetta, xetich, firstpos);
// Next labels
for (int j = 1; j < numstat; j++) {
String etich = (sect.getstation()).get(j).getName();
g2.drawString(etich, xetich, firstpos + j * (float) fontBounds.getHeight());
}
// Draws the line of the caption. Prefers horizontal line if possible
g2.setColor(BLACK);