]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "Customisable selection padding on diagrams"
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 7 Feb 2018 07:08:13 +0000 (09:08 +0200)
committerGerrit Code Review <gerrit2@www.simantics.org>
Wed, 7 Feb 2018 07:08:13 +0000 (09:08 +0200)
bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/DiagramHints.java
bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/participant/ElementPainter.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/nodes/SelectionNode.java

index 6152c168e70f09e57d517249c92d8c9a01804972..367cebcce67fb91caba55ad502c9c1050e75508e 100644 (file)
@@ -179,4 +179,11 @@ public class DiagramHints {
      */
     public static final Key POPUP_MENU_HIDDEN              = new KeyOf(Long.class, "POPUP_MENU_HIDDEN");
 
+    /**
+     * For specifying a user-defined padding for selections
+     *
+     * @since 1.33.0
+     */
+    public static final Key SELECTION_PADDING_SCALE_FACTOR = new KeyOf(Double.class, "SELECTION_PADDING_SCALE_FACTOR");
+
 }
index d35bfadb04ba2fd7e92eefaaa4b5f7feda40440d..ba575c630ffb1aff08024fe8e482d2f5423c8116 100644 (file)
@@ -1090,6 +1090,9 @@ public class ElementPainter extends AbstractDiagramParticipant implements Compos
         } else {
             SelectionNode s = selectionNode.getOrCreateNode(getNodeId("shape", e), SelectionNode.class);
             s.init(selectionTransform, bounds, color);
+            Double paddingFactor = diagram.getHint(DiagramHints.SELECTION_PADDING_SCALE_FACTOR);
+            if (paddingFactor != null)
+                s.setPaddingFactor(paddingFactor);
         }
     }
 
index 445a66fe3e9b5a7d431042c677f7323f12ee1ba5..bd09c45745be9ab675d25f0bb073caca8cc85b0d 100644 (file)
@@ -36,10 +36,15 @@ public class SelectionNode extends G2DNode implements Decoration {
     protected transient BasicStroke scaledStroke;
     protected transient double previousScaleRecip = Double.NaN;
     private boolean ignore = false;
+    private double paddingFactor = 5.0;
 
     public void setIgnore(boolean value) {
         ignore = value;
     }
+    
+    public void setPaddingFactor(double factor) {
+        paddingFactor = factor;
+    }
   
     @SyncField({"transform", "bounds", "color"})
     public void init(AffineTransform transform, Rectangle2D bounds, Color color) {
@@ -78,7 +83,7 @@ public class SelectionNode extends G2DNode implements Decoration {
         }
         g.setStroke(scaledStroke);
 
-        double padding = 5.0 * scaleRecip;
+        double padding = paddingFactor * scaleRecip;
         double paddingX = padding;
         double paddingY = padding;