Graphics g = createCanvas(width, height);
g.setColor(TangoColors.ORANGE_2);
g.setFont(g.getFont().deriveFont((float) TEXT_SIZE));
for (VrpCustomer customer : schedule.getCustomerList()) {
VrpLocation location = customer.getLocation();
int x = translator.translateLongitudeToX(location.getLongitude());
int y = translator.translateLatitudeToY(location.getLatitude());
g.fillRect(x - 1, y - 1, 3, 3);
g.drawString(Integer.toString(customer.getDemand()), x + 3, y - 3);
}
g.setColor(TangoColors.ALUMINIUM_4);
for (VrpDepot depot : schedule.getDepotList()) {
int x = translator.translateLongitudeToX(depot.getLocation().getLongitude());
int y = translator.translateLatitudeToY(depot.getLocation().getLatitude());
g.fillRect(x - 2, y - 2, 5, 5);
g.drawImage(depotImageIcon.getImage(),
x - depotImageIcon.getIconWidth() / 2, y - 2 - depotImageIcon.getIconHeight(), imageObserver);
}
int colorIndex = 0;
// TODO Too many nested for loops
for (VrpVehicle vehicle : schedule.getVehicleList()) {
g.setColor(TangoColors.SEQUENCE_2[colorIndex]);
VrpCustomer vehicleInfoCustomer = null;
int longestNonDepotDistance = -1;
int load = 0;
for (VrpCustomer customer : schedule.getCustomerList()) {
if (customer.getPreviousAppearance() != null && customer.getVehicle() == vehicle) {
load += customer.getDemand();
VrpLocation previousLocation = customer.getPreviousAppearance().getLocation();
int previousX = translator.translateLongitudeToX(previousLocation.getLongitude());
int previousY = translator.translateLatitudeToY(previousLocation.getLatitude());
VrpLocation location = customer.getLocation();
int x = translator.translateLongitudeToX(location.getLongitude());
int y = translator.translateLatitudeToY(location.getLatitude());
g.drawLine(previousX, previousY, x, y);
// Determine where to draw the vehicle info
int distance = customer.getDistanceToPreviousAppearance();
if (customer.getPreviousAppearance() instanceof VrpCustomer) {
if (longestNonDepotDistance < distance) {
longestNonDepotDistance = distance;
vehicleInfoCustomer = customer;
}
} else if (vehicleInfoCustomer == null) {
// If there is only 1 customer in this chain, draw it on a line to the Depot anyway
vehicleInfoCustomer = customer;
}
// Line back to the vehicle depot
boolean needsBackToVehicleLineDraw = true;
for (VrpCustomer trailingCustomer : schedule.getCustomerList()) {
if (trailingCustomer.getPreviousAppearance() == customer) {
needsBackToVehicleLineDraw = false;
break;
}
}
if (needsBackToVehicleLineDraw) {
VrpLocation vehicleLocation = vehicle.getLocation();
int vehicleX = translator.translateLongitudeToX(vehicleLocation.getLongitude());
int vehicleY = translator.translateLatitudeToY(vehicleLocation.getLatitude());
g.drawLine(x, y,vehicleX, vehicleY);
}
}
}
// Draw vehicle info
if (vehicleInfoCustomer != null) {
if (load > vehicle.getCapacity()) {
g.setColor(TangoColors.SCARLET_2);
}
VrpLocation previousLocation = vehicleInfoCustomer.getPreviousAppearance().getLocation();
VrpLocation location = vehicleInfoCustomer.getLocation();
double longitude = (previousLocation.getLongitude() + location.getLongitude()) / 2.0;
int x = translator.translateLongitudeToX(longitude);
double latitude = (previousLocation.getLatitude() + location.getLatitude()) / 2.0;
int y = translator.translateLatitudeToY(latitude);
boolean ascending = (previousLocation.getLongitude() < location.getLongitude())
^ (previousLocation.getLatitude() < location.getLatitude());
ImageIcon vehicleImageIcon = vehicleImageIcons[colorIndex];
int vehicleInfoHeight = vehicleImageIcon.getIconHeight() + 2 + TEXT_SIZE;
g.drawImage(vehicleImageIcon.getImage(), x + 1, (ascending ? y - vehicleInfoHeight - 1 : y + 1), imageObserver);
g.drawString(load + " / " + vehicle.getCapacity(), x + 1, (ascending ? y - 1 : y + vehicleInfoHeight + 1));