for (final Parcel p : parcels) {
float rotation = AT_SITE_ROTATION;
int offsetX = 0;
int offsetY = 0;
@Nullable
final ParcelState ps = pdpModel.get().getParcelState(p);
if (ps == ParcelState.AVAILABLE) {
final Point pos = roadModel.get().getPosition(p);
final int x = vp.toCoordX(pos.x);
final int y = vp.toCoordY(pos.y);
offsetX = (int) img.atSiteOffset.x + x - image.getBounds().width / 2;
offsetY = (int) img.atSiteOffset.y + y - image.getBounds().height / 2;
} else if (ps == ParcelState.PICKING_UP || ps == ParcelState.DELIVERING) {
final Vehicle v = mapping.get(p);
final PDPModel.VehicleParcelActionInfo vpai = pdpModel.get()
.getVehicleActionInfo(v);
final Point pos = roadModel.get().getPosition(v);
final int x = vp.toCoordX(pos.x);
final int y = vp.toCoordY(pos.y);
final double percentage = 1d - vpai.timeNeeded()
/ (double) p.getPickupDuration();
final String text = ((int) (percentage * 100d)) + "%";
final float rotFac = (float) (ps == ParcelState.PICKING_UP ? percentage
: 1d - percentage);
rotation = IN_CARGO_ROTATION * rotFac;
final int textWidth = gc.textExtent(text).x;
gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_BLUE));
gc.drawText(text, (int) LABEL_OFFSET.x + x - textWidth / 2,
(int) LABEL_OFFSET.y + y, true);
Point from = new Point(img.atSiteOffset.x + x
- image.getBounds().width
/ 2d, img.atSiteOffset.y + y - image.getBounds().height / 2d);
Point to = new Point(img.inCargoOffset.x + x
- image.getBounds().width
/ 2d, img.inCargoOffset.y + y - image.getBounds().height / 2d);
if (ps == ParcelState.DELIVERING) {
final Point temp = from;
from = to;
to = temp;
}
final Point diff = Point.diff(to, from);
offsetX = (int) (from.x + (percentage * diff.x));
offsetY = (int) (from.y + (percentage * diff.y));
} else if (ps == ParcelState.IN_CARGO) {
rotation = IN_CARGO_ROTATION;
final Point pos = roadModel.get().getPosition(mapping.get(p));
final int x = vp.toCoordX(pos.x);
final int y = vp.toCoordY(pos.y);
offsetX = (int) img.inCargoOffset.x + x - image.getBounds().width / 2;
offsetY = (int) img.inCargoOffset.y + y - image.getBounds().height
/ 2;
}
if (ps != null && !ps.isDelivered()) {
if (rotation == 0f) {
gc.drawImage(image, offsetX, offsetY);
} else {
final Transform oldTransform = new Transform(gc.getDevice());
gc.getTransform(oldTransform);