X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fstyles%2FDistrictNetworkHoverInfoStyle.java;fp=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fstyles%2FDistrictNetworkHoverInfoStyle.java;h=ced9b9b50b9f03d4f1f14ae6a5a14614e21340fb;hb=f888cdd5d8d8e9b958de302c96cf6b013519eaca;hp=a5fa89d42b952415f25fb527d2e36c962b32d5ce;hpb=932a9b82b349d8e63a36df1cdc5cbb37bdd8ff80;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkHoverInfoStyle.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkHoverInfoStyle.java index a5fa89d4..ced9b9b5 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkHoverInfoStyle.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkHoverInfoStyle.java @@ -1,6 +1,7 @@ package org.simantics.district.network.ui.styles; import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; import java.util.Collections; import java.util.List; @@ -10,28 +11,21 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.common.utils.CommonDBUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.exception.MissingVariableException; import org.simantics.db.layer0.exception.MissingVariableValueException; import org.simantics.db.layer0.exception.PendingVariableException; -import org.simantics.db.layer0.util.Layer0Utils; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; -import org.simantics.diagram.profile.StyleBase; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.district.network.DistrictNetworkUtil; import org.simantics.district.network.ontology.DistrictNetworkResource; -import org.simantics.district.network.ui.nodes.DeferredRenderingNode; -import org.simantics.district.network.ui.nodes.DistrictNetworkHoverInfoNode; +import org.simantics.district.network.ui.nodes.DistrictNetworkEdgeNode; import org.simantics.district.network.ui.nodes.DistrictNetworkNodeUtils; +import org.simantics.district.network.ui.nodes.DistrictNetworkVertexNode; import org.simantics.layer0.Layer0; -import org.simantics.modeling.ModelingResources; import org.simantics.scenegraph.INode; -import org.simantics.scenegraph.ParentNode; -import org.simantics.scenegraph.g2d.nodes.spatial.RTreeNode; -import org.simantics.scenegraph.profile.EvaluationContext; -import org.simantics.scenegraph.profile.common.ProfileVariables; -import org.simantics.scenegraph.utils.NodeUtil; import org.simantics.scl.compiler.top.ValueNotFound; import org.simantics.scl.osgi.SCLOsgi; import org.simantics.scl.runtime.SCLContext; @@ -41,52 +35,29 @@ import org.simantics.structural.stubs.StructuralResource2; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class DistrictNetworkHoverInfoStyle extends StyleBase { - - public static final String HOVER_INFO_DEFERRED = "hoverInfo"; - - private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkHoverInfoStyle.class); - - private static final String ACTIONS_MODULE = "Actions"; - private static final String HOVER_CONTRIBUTION = "hoverContribution"; - - public static class StyleResult { - Point2D origin; - List labels; - - public StyleResult(Point2D origin, List labels) { - this.origin = origin; - this.labels = labels; - } - - public Point2D getOrigin() { - return origin; - } - - public List getLabels() { - return labels; - } - } - - public DistrictNetworkHoverInfoStyle(Resource style) throws DatabaseException { - super(style); - } - - String currentRowKey; - - protected Resource getConfigurationComponent(ReadGraph graph, Resource element) throws DatabaseException { - ModelingResources MOD = ModelingResources.getInstance(graph); - DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); - - Resource mappedElement = graph.getPossibleObject(element, DN.MappedComponent); - return mappedElement != null ? graph.getPossibleObject(mappedElement, MOD.ElementToComponent) : null; - } - - @Override - public StyleResult calculateStyle(ReadGraph graph, Resource runtimeDiagram, Resource entry, Resource mapElement, - Variable configuration) throws DatabaseException { - //return doCalculateStyleResult(graph, runtimeDiagram, mapElement); - return new StyleResult(calculatePoint(graph, mapElement), Collections.emptyList()); +public class DistrictNetworkHoverInfoStyle { + + private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkHoverInfoStyle.class); + + private static final String ACTIONS_MODULE = "Actions"; + private static final String HOVER_CONTRIBUTION = "hoverContribution"; + + public static class StyleResult { + Point2D origin; + List labels; + + public StyleResult(Point2D origin, List labels) { + this.origin = origin; + this.labels = labels; + } + + public Point2D getOrigin() { + return origin; + } + + public List getLabels() { + return labels; + } } public static StyleResult doCalculateStyleResult(ReadGraph graph, Resource runtimeDiagram, Resource mapElement) throws DatabaseException { @@ -132,7 +103,7 @@ public class DistrictNetworkHoverInfoStyle extends StyleBase root = (ParentNode) NodeUtil.getNearestParentOfType(parent, RTreeNode.class); -// if (root != null) { -// DeferredRenderingNode deferred = ProfileVariables.claimChild(root, "", HOVER_INFO_DEFERRED, DeferredRenderingNode.class, observer); -// deferred.setZIndex(Integer.MAX_VALUE); -// } -// -// node.setLabels(results.getLabels()); -// node.setOrigin(results.getOrigin()); - } - - @Override - protected void cleanupStyleForNode(EvaluationContext observer, INode node) { - ProfileVariables.denyChild(node, "*", DistrictNetworkHoverInfoNode.NODE_KEY); - } - - private static Function1> getUCTextGridFunctionCached(ReadGraph graph, Resource componentType) - throws DatabaseException { - return graph.syncRequest(new UCTextGridFunctionRequest(componentType), TransientCacheListener.instance()); - } - - private static final class UCTextGridFunctionRequest extends ResourceRead>> { - public UCTextGridFunctionRequest(Resource resource) { - super(resource); - } - - @SuppressWarnings("unchecked") - @Override - public Function1> perform(ReadGraph graph) throws DatabaseException { - Resource actionsModule = Layer0Utils.getPossibleChild(graph, resource, ACTIONS_MODULE); - if (actionsModule == null || !graph.isInstanceOf(actionsModule, Layer0.getInstance(graph).SCLModule)) - return null; - - String uri = graph.getURI(actionsModule); - SCLContext sclContext = SCLContext.getCurrent(); - Object oldGraph = sclContext.get("graph"); - try { - sclContext.put("graph", graph); - return (Function1>) SCLOsgi.MODULE_REPOSITORY.getValue(uri, HOVER_CONTRIBUTION); - } catch (ValueNotFound e1) { - return null; - } finally { - sclContext.put("graph", oldGraph); - } - } - } + public static Point2D calculatePoint(INode node, int zoomLevel) { + if (node instanceof DistrictNetworkVertexNode) { + DistrictNetworkVertexNode vertex = (DistrictNetworkVertexNode) node; + Rectangle2D b = vertex.getBounds(); + return new Point2D.Double(b.getCenterX(), b.getCenterY()); + } else if (node instanceof DistrictNetworkEdgeNode) { + DistrictNetworkEdgeNode edge = (DistrictNetworkEdgeNode) node; + return (Point2D) edge.getCenterPoint(zoomLevel).clone(); + } + return null; + } + + private static Function1> getUCTextGridFunctionCached(ReadGraph graph, Resource componentType) + throws DatabaseException { + return graph.syncRequest(new UCTextGridFunctionRequest(componentType), TransientCacheListener.instance()); + } + + private static final class UCTextGridFunctionRequest extends ResourceRead>> { + public UCTextGridFunctionRequest(Resource resource) { + super(resource); + } + + @SuppressWarnings("unchecked") + @Override + public Function1> perform(ReadGraph graph) throws DatabaseException { + Resource actionsModule = CommonDBUtils.getPossibleChild(graph, resource, ACTIONS_MODULE); + if (actionsModule == null || !graph.isInstanceOf(actionsModule, Layer0.getInstance(graph).SCLModule)) + return null; + + String uri = graph.getURI(actionsModule); + SCLContext sclContext = SCLContext.getCurrent(); + Object oldGraph = sclContext.get("graph"); + try { + sclContext.put("graph", graph); + return (Function1>) SCLOsgi.MODULE_REPOSITORY.getValue(uri, HOVER_CONTRIBUTION); + } catch (ValueNotFound e1) { + return null; + } finally { + sclContext.put("graph", oldGraph); + } + } + } + }