Skip to content

Commit

Permalink
Avoid using com.sun.javafx.Utils.
Browse files Browse the repository at this point in the history
Fixes #155.
  • Loading branch information
TomasMikula committed Jun 25, 2015
1 parent 207bc71 commit 07fc7a1
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions richtextfx/src/main/java/org/fxmisc/richtext/StyledTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
import org.reactfx.value.Val;
import org.reactfx.value.Var;

import com.sun.javafx.Utils;

/**
* Text editing control. Accepts user input (keyboard, mouse) and
* provides API to assign style to text ranges. It is suitable for
Expand Down Expand Up @@ -109,6 +107,15 @@ public class StyledTextArea<S> extends Control
*/
public static final IndexRange EMPTY_RANGE = new IndexRange(0, 0);

/**
* Private helper method.
*/
private static int clamp(int min, int val, int max) {
return val < min ? min
: val > max ? max
: val;
}


/* ********************************************************************** *
* *
Expand Down Expand Up @@ -693,8 +700,8 @@ public void clearStyle(int paragraph, int from, int to) {
@Override
public void replaceText(int start, int end, String text) {
try(Guard g = omniSuspendable.suspend()) {
start = Utils.clamp(0, start, getLength());
end = Utils.clamp(0, end, getLength());
start = clamp(0, start, getLength());
end = clamp(0, end, getLength());

content.replaceText(start, end, text);

Expand All @@ -706,8 +713,8 @@ public void replaceText(int start, int end, String text) {
@Override
public void replace(int start, int end, StyledDocument<S> replacement) {
try(Guard g = omniSuspendable.suspend()) {
start = Utils.clamp(0, start, getLength());
end = Utils.clamp(0, end, getLength());
start = clamp(0, start, getLength());
end = clamp(0, end, getLength());

content.replace(start, end, replacement);

Expand All @@ -722,8 +729,8 @@ public void selectRange(int anchor, int caretPosition) {
this.caretPosition, currentParagraph,
caretColumn, this.anchor,
selection, selectedText)) {
this.internalCaretPosition.setValue(Utils.clamp(0, caretPosition, getLength()));
this.anchor.setValue(Utils.clamp(0, anchor, getLength()));
this.internalCaretPosition.setValue(clamp(0, caretPosition, getLength()));
this.anchor.setValue(clamp(0, anchor, getLength()));
this.internalSelection.setValue(IndexRange.normalize(getAnchor(), getCaretPosition()));
}
}
Expand Down

0 comments on commit 07fc7a1

Please sign in to comment.