]> gerrit.simantics Code Review - simantics/district.git/commitdiff
Add white background for hover & static info on district network diagram
authorJani Simomaa <jani.simomaa@gmail.com>
Thu, 11 Jul 2019 13:12:22 +0000 (16:12 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Sat, 31 Aug 2019 20:08:43 +0000 (23:08 +0300)
gitlab #44
gitlab #47

Change-Id: I96375c6abba3f1e9a0981b12d3055e1109bd53a3

org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkHoverInfoNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkStaticInfoNode.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkHoverInfoStyle.java
org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkStaticInfoStyle.java

index b8a1617bab12bafa050dd8bba2c21b19d4a4e572..4fc1bebae4ec12f3e013ff1f42ad187c11589447 100644 (file)
@@ -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<Integer> 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) {
index fb7041e7f5f57a4b32eae0af006a2fbdefcf7cd9..347261c43a9dc462e8e4c56b77947c9eaa26690a 100644 (file)
@@ -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);
        }
 
index f01fa2aeece9cdd63dc1e340908307f98158399d..c5e3a6f6a19dc7df6bd50092b20b6f7cac3a5bc5 100644 (file)
@@ -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<DistrictNetworkHoverInfoStyle.StyleResult> {
 
+    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<DistrictNetworkHove
                        result = Simantics.applySCLRead(graph, function, moduleVariable);
                } catch (PendingVariableException | MissingVariableValueException e) {
                        result = Collections.singletonList(new Tuple3("<pending>", "", ""));
-               }
+               } 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);
index e452a17b1f52188d8ab43b48de2a4302c5ad2a8a..8a4a143ce39050875d4d930b2f015420015024c8 100644 (file)
@@ -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<DistrictNetworkStaticInfoStyle.StyleResult> {
 
+    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<DistrictNetworkSta
                        result = Simantics.applySCLRead(graph, function, moduleVariable);
                } catch (PendingVariableException | MissingVariableValueException e) {
                        result = null;
+               } 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 = "<" + message + ">";
                }
                
                if (isVertex) {