}
}
public void draw( MapGraphicContext context ) {
// get this map's flock and listener
IBlackboard blackboard = getActiveBlackBoard(context);
List<SeagullFlock> flocks = (List<SeagullFlock>) blackboard.get(SeagullFlock.BLACKBOARD_KEY);
TrackingItemListenerImpl listener = (TrackingItemListenerImpl) blackboard.get(LISTENER_BLACKBOARD_KEY);
// if no flocks, nothing to draw
if (flocks == null) {
return; // no seagull flocks to draw
}
// if no listener, or the old one points to a different layer, then create a new one
boolean isNewListener = false;
TrackingItemListenerImpl oldListener = null;
if (listener == null || listener.getLayer() != context.getLayer()) {
oldListener = listener;
ILayer layer = context.getLayer();
listener = new TrackingItemListenerImpl(layer);
blackboard.put(LISTENER_BLACKBOARD_KEY, listener);
isNewListener = true;
}
// for each flock, draw it and ensure it has our listener added (new flocks
// added since the last draw will not have them yet)
for (SeagullFlock flock : flocks) {
flock.draw(context);
// if there is a new listener, remove any previous one first
if (isNewListener) {
flock.removeListener(oldListener);
}
flock.addListener(listener); // won't be added if it already has it
}
// set the graphic to look at refreshing every 0.5 secs if it is not already
CheckRefreshJob job = (CheckRefreshJob) blackboard.get(REFRESHJOB_BLACKBOARD_KEY);
if (job != null) {
job.cancel();
}
long delay = 500;
job = new CheckRefreshJob(context.getLayer(), null, delay);
blackboard.put(REFRESHJOB_BLACKBOARD_KEY, job);
job.schedule(delay);
}