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;
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) {