]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkHoverInfoNode.java
Add white background for hover & static info on district network diagram
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / nodes / DistrictNetworkHoverInfoNode.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) {