changeset 5176:4d3df4e0c494

RT-32966 : Multiline text is rendered outside of control bounds, reviewed by Leif
author mickf
date Fri, 27 Sep 2013 16:11:37 +0100
parents 240636b0c18c
children bdc3f404c931
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/LabeledSkinBase.java
diffstat 1 files changed, 36 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/LabeledSkinBase.java	Thu Sep 26 14:14:55 2013 +1200
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/LabeledSkinBase.java	Fri Sep 27 16:11:37 2013 +0100
@@ -45,6 +45,7 @@
 import javafx.scene.input.KeyCombination;
 import javafx.scene.input.Mnemonic;
 import javafx.scene.shape.Line;
+import javafx.scene.shape.Rectangle;
 import javafx.scene.text.Font;
 
 import com.sun.javafx.scene.control.behavior.BehaviorBase;
@@ -106,6 +107,7 @@
         }
     };
 
+    private Rectangle textClip;
     private double wrapWidth;
     private double wrapHeight;
 
@@ -1166,5 +1168,38 @@
             }
             graphic.relocate(snapPosition(graphicX), snapPosition(graphicY));
         }
-    }   
+
+        /**
+         * check if the label text overflows it's bounds.
+         * If there's an overflow, and no text clip then
+         * we'll clip it. 
+         * If there is no overflow, and the label text has a
+         * clip, then remove it.
+         */
+        if ((text != null) && 
+            ((text.getLayoutBounds().getHeight() > wrapHeight) ||
+             (text.getLayoutBounds().getWidth() > wrapWidth))) {
+
+            if (textClip == null) {
+                textClip = new Rectangle();
+            }
+
+            textClip.setX(text.getLayoutBounds().getMinX());
+            textClip.setY(text.getLayoutBounds().getMinY());
+            textClip.setWidth(wrapWidth);
+            textClip.setHeight(wrapHeight);
+            if (text.getClip() == null) {
+                text.setClip(textClip);
+            }
+        }
+        else {
+            /**
+             * content fits inside bounds, no need
+             * for a clip
+             */
+            if (text.getClip() != null) {
+                text.setClip(null);
+            }
+        }
+    }
 }