1 package org.simantics.district.network.ui.styles;
3 import java.awt.geom.Rectangle2D;
4 import java.util.Collection;
5 import java.util.Collections;
7 import org.simantics.db.RequestProcessor;
8 import org.simantics.db.Resource;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.district.network.ui.nodes.ElevationServerNode;
11 import org.simantics.maps.elevation.server.SingletonTiffTileInterface;
12 import org.simantics.scenegraph.g2d.IG2DNode;
13 import org.simantics.scenegraph.profile.EvaluationContext;
14 import org.simantics.scenegraph.profile.Group;
15 import org.simantics.scenegraph.profile.Style;
16 import org.simantics.scenegraph.profile.common.ObserverGroupListener;
17 import org.simantics.scenegraph.utils.NodeUtil;
19 public class ElevationRectangleStyle implements Style {
21 private ObserverGroupListener listener = null;
22 private double priority;
25 public void activate(RequestProcessor backend, Resource runtimeDiagram, Resource entry, Group group, EvaluationContext observer) throws DatabaseException {
26 if (listener != null && !listener.isDisposed())
28 listener = new ObserverGroupListener(this, group, observer);
29 group.trackItems(backend, runtimeDiagram, listener);
33 public void deactivate(Resource runtimeDiagram, Resource entry, Group group, EvaluationContext observer) {
34 if (listener != null && !listener.isDisposed()) {
35 setRectangles(observer, Collections.emptyList());
42 public void apply(Resource entry, Group group, EvaluationContext observer) {
43 apply2(entry, observer);
47 public void apply2(Object item, EvaluationContext observer) {
48 setRectangles(observer, SingletonTiffTileInterface.getBoundingBoxes());
51 private void setRectangles(EvaluationContext observer, Collection<Rectangle2D> rectangles) {
52 IG2DNode node = NodeUtil.getNearestChildByClass(observer.getSceneGraph(), ElevationServerNode.class);
54 ((ElevationServerNode) node).setRectangles(rectangles);
59 public void setPriority(double priority) {
60 this.priority = priority;
64 public double getPriority() {