From 2f414faa80051f046a020840105847099c655195 Mon Sep 17 00:00:00 2001 From: Jani Simomaa Date: Thu, 11 Jul 2019 16:12:22 +0300 Subject: [PATCH] Add white background for hover & static info on district network diagram gitlab #44 gitlab #47 Change-Id: I96375c6abba3f1e9a0981b12d3055e1109bd53a3 --- .../ui/nodes/DistrictNetworkHoverInfoNode.java | 9 +++++++++ .../ui/nodes/DistrictNetworkStaticInfoNode.java | 7 ++++++- .../ui/styles/DistrictNetworkHoverInfoStyle.java | 12 +++++++++++- .../ui/styles/DistrictNetworkStaticInfoStyle.java | 10 ++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkHoverInfoNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkHoverInfoNode.java index b8a1617b..4fc1beba 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkHoverInfoNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkHoverInfoNode.java @@ -6,7 +6,9 @@ import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; +import java.util.Comparator; import java.util.List; +import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; import org.simantics.maps.MapScalingTransform; @@ -55,6 +57,13 @@ public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensit g.setFont(FONT); double rowHeight = g.getFontMetrics().getHeight() * 1.1; + // let's calculate the max width + Optional max = labels.stream().map(t -> g.getFontMetrics().stringWidth((String) t.c2)).max(Comparator.naturalOrder()); + int width = max.orElse(10); + g.setColor(Color.WHITE); + int totalHeight = (int)Math.round(rowHeight * labels.size()); + g.fillRect(-(W1 + PAD + W2 + 5), -(totalHeight + (int)Math.round(rowHeight)), (W1 + PAD + W2 + width + 10), totalHeight + 5); + g.setColor(Color.BLACK); for (Tuple3 t : labels) { diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkStaticInfoNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkStaticInfoNode.java index fb7041e7..347261c4 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkStaticInfoNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkStaticInfoNode.java @@ -68,13 +68,18 @@ public class DistrictNetworkStaticInfoNode extends G2DNode { double scale = 1.5 / g.getTransform().getScaleX(); g.scale(scale, scale); + int width1 = g.getFontMetrics().stringWidth(info); + int height = g.getFontMetrics().getHeight(); + + g.setColor(Color.WHITE); + g.fillRect(-width1/2 - 5, -2, width1, height); + g.setFont(FONT); g.setColor(Color.BLACK); g.transform(AffineTransform.getRotateInstance(direction.getX(), direction.getY())); g.translate(0, 10); - int width1 = g.getFontMetrics().stringWidth(info); g.drawString(info, -width1/2, 0); } 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 f01fa2ae..c5e3a6f6 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 @@ -11,6 +11,7 @@ import org.simantics.db.Resource; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.ResourceRead; 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; @@ -33,9 +34,13 @@ import org.simantics.scl.runtime.SCLContext; import org.simantics.scl.runtime.function.Function1; import org.simantics.scl.runtime.tuple.Tuple3; import org.simantics.structural.stubs.StructuralResource2; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class DistrictNetworkHoverInfoStyle extends StyleBase { + private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkHoverInfoStyle.class); + private static final String ACTIONS_MODULE = "Actions"; private static final String HOVER_CONTRIBUTION = "hoverContribution"; @@ -104,7 +109,12 @@ public class DistrictNetworkHoverInfoStyle extends StyleBase", "", "")); - } + } catch (MissingVariableException e) { + // the requested variable is missing from the UC + String message = e.getMessage(); + LOGGER.warn("Missing variable for calculating style with function {} {}", function, message); + result = Collections.singletonList(new Tuple3("<" + message +">", "", "")); + } Point2D point; DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkStaticInfoStyle.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkStaticInfoStyle.java index e452a17b..8a4a143c 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkStaticInfoStyle.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkStaticInfoStyle.java @@ -9,6 +9,7 @@ import org.simantics.db.Resource; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.ResourceRead; 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; @@ -30,9 +31,13 @@ import org.simantics.scl.osgi.SCLOsgi; import org.simantics.scl.runtime.SCLContext; import org.simantics.scl.runtime.function.Function1; import org.simantics.structural.stubs.StructuralResource2; +import org.slf4j.LoggerFactory; +import org.slf4j.Logger; public class DistrictNetworkStaticInfoStyle extends StyleBase { + private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkStaticInfoStyle.class); + private static final String ACTIONS_MODULE = "Actions"; private static final String PIPELINE_INFO = "pipelineInfo"; @@ -94,6 +99,11 @@ public class DistrictNetworkStaticInfoStyle extends StyleBase"; } if (isVertex) { -- 2.47.1