1 package org.simantics.district.network.ui.participants;
3 import java.awt.geom.AffineTransform;
6 import org.simantics.district.network.ui.DistrictDiagramViewer;
7 import org.simantics.district.network.ui.nodes.DynamicVisualisationContributionsNode;
8 import org.simantics.district.network.visualisations.model.ColorBarOptions;
9 import org.simantics.district.network.visualisations.model.DynamicColorContribution;
10 import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
11 import org.simantics.district.network.visualisations.model.SizeBarOptions;
12 import org.simantics.g2d.canvas.ICanvasContext;
13 import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;
14 import org.simantics.g2d.canvas.impl.SGNodeReflection.SGInit;
15 import org.simantics.scenegraph.g2d.G2DParentNode;
16 import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;
17 import org.simantics.scenegraph.g2d.events.command.CommandEvent;
18 import org.simantics.utils.datastructures.hints.HintListenerAdapter;
19 import org.simantics.utils.datastructures.hints.IHintContext.Key;
20 import org.simantics.utils.datastructures.hints.IHintListener;
21 import org.simantics.utils.datastructures.hints.IHintObservable;
23 public class DynamicVisualisationContributionsParticipant extends AbstractCanvasParticipant {
25 IHintListener hintListener = new HintListenerAdapter() {
26 public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {
27 ICanvasContext cc = getContext();
30 cc.getContentContext().setDirty();
35 private DynamicVisualisationContributionsNode node;
36 private AffineTransform transform;
38 public DynamicVisualisationContributionsParticipant(AffineTransform tr) {
43 public void addedToContext(ICanvasContext ctx) {
44 super.addedToContext(ctx);
45 getHintStack().addKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_COLORING_OBJECTS, hintListener);
46 getHintStack().addKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_COLOR_BAR_OPTIONS, hintListener);
47 getHintStack().addKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_SIZING_OBJECTS, hintListener);
48 getHintStack().addKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_SIZE_BAR_OPTIONS, hintListener);
52 public void removedFromContext(ICanvasContext ctx) {
53 getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_COLORING_OBJECTS, hintListener);
54 getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_COLOR_BAR_OPTIONS, hintListener);
55 getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_SIZING_OBJECTS, hintListener);
56 getHintStack().removeKeyHintListener(getThread(), DistrictDiagramViewer.KEY_MAP_SIZE_BAR_OPTIONS, hintListener);
57 super.removedFromContext(ctx);
61 public void initSG(G2DParentNode parent) {
62 node = parent.addNode(DynamicVisualisationContributionsNode.ID, DynamicVisualisationContributionsNode.class);
63 node.setTransform(transform);
64 node.setEnabled(true);
68 @EventHandler(priority = 0)
69 protected boolean handleKeyEvent(CommandEvent e) {
70 if (e.command.equals(DistrictDiagramViewer.MAP_COLOR_BAR_OPTIONS_CHANGE)) {
71 System.out.println(e);
78 // protected boolean handleCommand(CommandEvent e) {
79 // if (e.command.equals(DistrictDiagramViewer.MAP_COLOR_BAR_OPTIONS_CHANGE)) {
80 // ICanvasContext context = (ICanvasContext) e.getContext();
81 // ColorBarOptions options = context.getHintStack().getHint(DistrictDiagramViewer.KEY_MAP_COLOR_BAR_OPTIONS);
82 // this.colorBarsOptions = options;
86 // return super.handleCommand(e);
90 protected void updateNode() {
91 node.setDynamicColoringObjects(getDynamicColoringObjects());
92 node.setColorBarOptions(getColorBarOptions());
93 node.setDynamicSizingObjects(getDynamicSizingObjects());
94 node.setSizeBarOptions(getSizeBarOptions());
97 private Map<String,DynamicColorContribution> getDynamicColoringObjects() {
98 Map<String,DynamicColorContribution> objects = getHint(DistrictDiagramViewer.KEY_MAP_COLORING_OBJECTS);
102 private ColorBarOptions getColorBarOptions() {
103 ColorBarOptions options = getHint(DistrictDiagramViewer.KEY_MAP_COLOR_BAR_OPTIONS);
107 private Map<String, DynamicSizeContribution> getDynamicSizingObjects() {
108 Map<String, DynamicSizeContribution> objects = getHint(DistrictDiagramViewer.KEY_MAP_SIZING_OBJECTS);
112 private SizeBarOptions getSizeBarOptions() {
113 SizeBarOptions options = getHint(DistrictDiagramViewer.KEY_MAP_SIZE_BAR_OPTIONS);