};
@Override
public void update(Observable obj, Object arg) {
if (arg instanceof Vehicle) {
Vehicle addedVehicle = (Vehicle) arg;
String id = addedVehicle.getID();
String type = addedVehicle.getPrettyName();
Double latitude = GlobalPosition.from(Point2DUtils.convertPoint(addedVehicle.getPosition())).getLatitude();
Double longitude = GlobalPosition.from(Point2DUtils.convertPoint(addedVehicle.getPosition()))
.getLongitude();
String speed = Double.toString(Math.round(addedVehicle.getSpeed() * 100.) / 100.);
String direction = Double.toString(Math.round(addedVehicle.getDirection() * 100.) / 100.) + " ("
+ Utilities.getCardinalDirection(addedVehicle.getDirection()) + ")";
String coveredDistance = Double.toString(Math.round(addedVehicle.getDistance() * 100.) / 100.);
String communicationCount = addedVehicle.getSentCount() + "/" + addedVehicle.getReceivedCount();
Object[] addedData = new Object[] { id, type, latitude, longitude, speed, direction, coveredDistance,
communicationCount };
// Add a new model to the table
if (!modelsToRows.containsKey(addedVehicle.getID())) {
// No speed and direction yet
addedData[columns.get("Speed [km/h]")] = "Awaiting...";
addedData[columns.get("Direction [\u00b0]")] = "Awaiting...";
tableModel.addRow(addedData);
modelsToRows.put(addedVehicle.getID(), tableModel.getRowCount() - 1);
tableModel.setValueAt(true, modelsToRows.get(addedVehicle.getID()), columns.get("Annotation"));
tableModel.setValueAt(true, modelsToRows.get(addedVehicle.getID()), columns.get("Radius"));
tableModel.setValueAt(false, modelsToRows.get(addedVehicle.getID()), columns.get("Destination"));
tableModel.setValueAt(false, modelsToRows.get(addedVehicle.getID()), columns.get("V2X-Tracing"));
tableModel.setValueAt(false, modelsToRows.get(addedVehicle.getID()), columns.get("Hide"));
updateGlobalSettings(modelsToRows.get(addedVehicle.getID()), modelsToRows.get(addedVehicle.getID()));
}
// Modify an existing model in the table
else {
tableModel.setValueAt(id, modelsToRows.get(addedVehicle.getID()), columns.get("ID"));
tableModel.setValueAt(type, modelsToRows.get(addedVehicle.getID()), columns.get("Type"));
tableModel.setValueAt(latitude, modelsToRows.get(addedVehicle.getID()), columns.get("Latitude"));
tableModel.setValueAt(longitude, modelsToRows.get(addedVehicle.getID()), columns.get("Longitude"));
tableModel.setValueAt(speed, modelsToRows.get(addedVehicle.getID()), columns.get("Speed [km/h]"));
tableModel.setValueAt(direction, modelsToRows.get(addedVehicle.getID()), columns.get("Direction [\u00b0]"));
tableModel.setValueAt(coveredDistance, modelsToRows.get(addedVehicle.getID()),
columns.get("Distance [km]"));
tableModel.setValueAt(communicationCount, modelsToRows.get(addedVehicle.getID()),
columns.get("# Sent/Received"));
Boolean displayAnnotations = (Boolean) tableModel.getValueAt(modelsToRows.get(addedVehicle.getID()),
columns.get("Annotation"));
if (displayAnnotations)
addedVehicle.setDisplayingAnnotations(true);
else
addedVehicle.setDisplayingAnnotations(false);
Boolean displayRadius = (Boolean) tableModel.getValueAt(modelsToRows.get(addedVehicle.getID()),
columns.get("Radius"));
if (displayRadius)
addedVehicle.setDisplayingRadius(true);
else
addedVehicle.setDisplayingRadius(false);
Boolean displayDestination = (Boolean) tableModel.getValueAt(modelsToRows.get(addedVehicle.getID()),
columns.get("Destination"));
if (displayDestination)
addedVehicle.setDisplayingDestination(true);
else
addedVehicle.setDisplayingDestination(false);
Boolean v2xTracing = (Boolean) tableModel.getValueAt(modelsToRows.get(addedVehicle.getID()),
columns.get("V2X-Tracing"));
if (v2xTracing)
addedVehicle.setV2XTracing(true);
else
addedVehicle.setV2XTracing(false);
Boolean hidden = (Boolean) tableModel.getValueAt(modelsToRows.get(addedVehicle.getID()),
columns.get("Hide"));
if (hidden)
addedVehicle.setHidden(true);
else
addedVehicle.setHidden(false);
}
}
else if (arg instanceof RoadsideUnit) {
RoadsideUnit addedRoadsideUnit = (RoadsideUnit) arg;