@@ -148,6 +156,8 @@ private double pressX, pressY; // For dragging handles on embedded + private NodeOrientation baseDirection = LEFT_TO_RIGHT; + /** * Create a new TextFieldSkin. * @param textField not null @@ -517,32 +530,45 @@ return getInsets().getTop() + fontMetrics.getAscent(); } + private void updateBaseDirection() { + Bidi bidi = + new Bidi(getSkinnable().getText(), + (getSkinnable().getNodeOrientation() == LEFT_TO_RIGHT) + ? Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT + : Bidi.DIRECTION_DEFAULT_RIGHT_TO_LEFT); + baseDirection = bidi.baseIsLeftToRight() ? LEFT_TO_RIGHT : RIGHT_TO_LEFT; + } + private void updateTextPos() { - switch (getAlignment().getHpos()) { + updateBaseDirection(); + switch (getHAlignment()) { case CENTER: double midPoint = (textRight.get() - textLeft.get()) / 2; @@ -789,25 +841,29 @@ selectionHandle2.setLayoutY(b.getMaxY() - 1); } } - private Pos getAlignment() { - Pos pos = getSkinnable().getAlignment(); - if (getSkinnable().getEffectiveNodeOrientation() == NodeOrientation.RIGHT_TO_LEFT) { - //TODO - what about BOTTOM_LEFT and other hAlignments? - if (pos == Pos.CENTER_LEFT) { - pos = Pos.CENTER_RIGHT; - } else { - pos = Pos.CENTER_LEFT; + + private HPos getHAlignment() { + HPos hPos = getSkinnable().getAlignment().getHpos(); + if (hPos != HPos.CENTER) { + if (getSkinnable().getEffectiveNodeOrientation() != baseDirection) { + hPos = (hPos == HPos.LEFT) ? HPos.RIGHT : HPos.LEFT; } } - return pos; + return hPos; }