+
+ protected void addViewManipulationParticipants(CanvasContext ctx) {
+ // Let's replace with our special util
+ TransformUtil util = ctx.getAtMostOneItemOfClass(TransformUtil.class);
+ if (util != null)
+ ctx.remove(util);
+ ctx.add(new DistrictTransformUtil());
+ ctx.add(new DistrictPanZoomRotateHandler());
+ //ctx.add(new MousePanZoomInteractor());
+ //ctx.add(new MultitouchPanZoomRotateInteractor());
+ // ctx.add( new OrientationRestorer() );
+ ctx.add(new ZoomToAreaHandler());
+ }
+
+ @Override
+ protected void loadPageSettings(ICanvasContext ctx) {
+ super.loadPageSettings(ctx);
+ // this might be the wrong place to start such listening but at least
+ // super.loadPageSettings() does async-db-operations
+ setupDrawMapEnabled();
+ setupBackgroundColor();
+ }
+
+ private void setupDrawMapEnabled() {
+ sessionContext.getSession().asyncRequest(new DrawMapEnabledRequest(getInputResource()), new DrawMapEnabledListener(
+ result -> canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), result ? Commands.MAP_ENABLE : Commands.MAP_DISABLE)),
+ () -> DistrictDiagramViewer.this.isDisposed()));
+ }
+
+ private void setupBackgroundColor() {
+ sessionContext.getSession().asyncRequest(new MapBackgroundColorRequest(getInputResource()), new MapBackgroundColorListener(
+ result -> queueBackgroundColorChangeEvent(result),
+ () -> DistrictDiagramViewer.this.isDisposed()));
+ }
+
+ private void queueBackgroundColorChangeEvent(RGB.Integer result) {
+ if (result != null) {
+ Color backgroundColor = new Color(result.red, result.green, result.blue);
+ canvasContext.getDefaultHintContext().setHint(MapCommands.KEY_MAP_BACKGROUND_COLOR, backgroundColor);
+ canvasContext.getEventQueue().queueEvent(new CommandEvent(canvasContext, System.currentTimeMillis(), MapCommands.MAP_BACKGROUND_COLOR_CHANGE));
+ }
+ }
+
+ private static class DrawMapEnabledRequest extends UnaryRead<Resource, Boolean> {
+
+ public DrawMapEnabledRequest(Resource diagram) {
+ super(diagram);
+ }
+
+ @Override
+ public Boolean perform(ReadGraph graph) throws DatabaseException {
+ return DistrictNetworkUtil.drawMapEnabled(graph, parameter);
+ }
+ }
+
+ private static class DrawMapEnabledListener implements Listener<Boolean> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(DrawMapEnabledListener.class);
+
+ private Consumer<Boolean> callback;
+ private Supplier<Boolean> isDisposed;
+
+ public DrawMapEnabledListener(Consumer<Boolean> callback, Supplier<Boolean> isDisposed) {
+ this.callback = callback;
+ this.isDisposed = isDisposed;
+ }
+
+ @Override
+ public void execute(Boolean result) {
+ callback.accept(result);
+ }
+
+ @Override
+ public void exception(Throwable t) {
+ LOGGER.error("Could not listen if draw map is enabled", t);
+ }
+
+ @Override
+ public boolean isDisposed() {
+ return isDisposed.get();
+ }
+ }
+
+ private static class MapBackgroundColorRequest extends UnaryRead<Resource, RGB.Integer> {
+
+ public MapBackgroundColorRequest(Resource diagram) {
+ super(diagram);
+ }
+
+ @Override
+ public RGB.Integer perform(ReadGraph graph) throws DatabaseException {
+ return DistrictNetworkUtil.backgroundColor(graph, parameter);
+ }
+ }
+
+ private static class MapBackgroundColorListener implements Listener<RGB.Integer> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(DrawMapEnabledListener.class);
+
+ private Consumer<RGB.Integer> callback;
+ private Supplier<Boolean> isDisposed;
+
+ public MapBackgroundColorListener(Consumer<RGB.Integer> callback, Supplier<Boolean> isDisposed) {
+ this.callback = callback;
+ this.isDisposed = isDisposed;
+ }
+
+ @Override
+ public void execute(RGB.Integer result) {
+ callback.accept(result);
+ }
+
+ @Override
+ public void exception(Throwable t) {
+ LOGGER.error("Could not listen map background color", t);
+ }
+
+ @Override
+ public boolean isDisposed() {
+ return isDisposed.get();
+ }
+ }