Skip to content

Commit

Permalink
Merge pull request #523 from JordanMartinez/cleanup
Browse files Browse the repository at this point in the history
Cleanup some aspects of the code
  • Loading branch information
JordanMartinez authored Jun 18, 2017
2 parents 58d4a1e + d8aafe7 commit 9db6f92
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.fxmisc.richtext;

import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.input.MouseButton;
import javafx.stage.Stage;
import javafx.stage.Window;
import org.testfx.api.FxRobotInterface;
import org.testfx.framework.junit.ApplicationTest;
import org.testfx.service.query.PointQuery;
Expand Down Expand Up @@ -56,8 +58,24 @@ public void start(Stage stage) throws Exception {
area.requestFocus();
}

public final PointQuery position(Scene scene, Pos pos, double xOffset, double yOffset) {
return point(scene).atPosition(pos).atOffset(xOffset, yOffset);
}

public final PointQuery position(Window window, Pos pos, double xOffset, double yOffset) {
return point(window).atPosition(pos).atOffset(xOffset, yOffset);
}

public final PointQuery position(Node node, Pos pos, double xOffset, double yOffset) {
return point(node).atPosition(pos).atOffset(xOffset, yOffset);
}

public final PointQuery position(Pos pos, double xOffset, double yOffset) {
return position(area, pos, xOffset, yOffset);
}

public final PointQuery firstLineOfArea() {
return point(area).atPosition(Pos.TOP_LEFT).atOffset(5, 5);
return position(Pos.TOP_LEFT, 5, 5);
}

public final FxRobotInterface clickOnFirstLine(MouseButton... buttons) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ public void testMoveCaretWithoutFollowingIt() {

public class HitTests extends InlineCssTextAreaAppTest {

private PointQuery position(Pos position, double offsetX, double offsetY) {
return point(area).atPosition(position).atOffset(offsetX, offsetY);
}

private void moveCaretToAreaEnd() {
area.moveTo(area.getLength());
}
Expand Down
20 changes: 9 additions & 11 deletions richtextfx/src/main/java/org/fxmisc/richtext/CssProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import javafx.beans.property.SimpleBooleanProperty;
import javafx.css.CssMetaData;
import javafx.css.PseudoClass;
import javafx.css.StyleConverter;
import javafx.css.Styleable;
import javafx.css.StyleableObjectProperty;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.util.Duration;

import java.util.function.Supplier;
Expand Down Expand Up @@ -37,16 +35,16 @@ private static class CustomStyleablePropertyBase<T> extends StyleableObjectPrope

private final GenericStyledArea<?, ?, ?> area;
private final String name;
private final Supplier<CssMetaData<? extends Styleable, T>> cssMetaDataSupplier;
private final CssMetaData<? extends Styleable, T> cssMetaData;

public CustomStyleablePropertyBase(T initialValue,
String name,
GenericStyledArea<?, ?, ?> area,
Supplier<CssMetaData<? extends Styleable, T>> cssMetaDataSupplier) {
CssMetaData<? extends Styleable, T> cssMetaData) {
super(initialValue);
this.area = area;
this.name = name;
this.cssMetaDataSupplier = cssMetaDataSupplier;
this.cssMetaData = cssMetaData;
}

@Override
Expand All @@ -61,15 +59,15 @@ public String getName() {

@Override
public CssMetaData<? extends Styleable, T> getCssMetaData() {
return cssMetaDataSupplier.get();
return cssMetaData;
}

}

static class HighlightFillProperty extends CustomStyleablePropertyBase<Paint> {

public HighlightFillProperty(GenericStyledArea<?, ?, ?> area,
Supplier<CssMetaData<? extends Styleable, Paint>> cssMetaDataSupplier) {
CssMetaData<? extends Styleable, Paint> cssMetaDataSupplier) {
super(Color.DODGERBLUE, "highlightFill", area, cssMetaDataSupplier);
}

Expand All @@ -78,17 +76,17 @@ public HighlightFillProperty(GenericStyledArea<?, ?, ?> area,
static class HighlightTextFillProperty extends CustomStyleablePropertyBase<Paint> {

public HighlightTextFillProperty(GenericStyledArea<?, ?, ?> area,
Supplier<CssMetaData<? extends Styleable, Paint>> cssMetaDataSupplier) {
super(Color.WHITE, "highlightTextFill", area, cssMetaDataSupplier);
CssMetaData<? extends Styleable, Paint> cssMetaData) {
super(Color.WHITE, "highlightTextFill", area, cssMetaData);
}

}

static class CaretBlinkRateProperty extends CustomStyleablePropertyBase<Duration> {

public CaretBlinkRateProperty(GenericStyledArea<?, ?, ?> area,
Supplier<CssMetaData<? extends Styleable, Duration>> cssMetaDataSupplier) {
super(Duration.millis(500), "caretBlinkRate", area, cssMetaDataSupplier);
CssMetaData<? extends Styleable, Duration> cssMetaData) {
super(Duration.millis(500), "caretBlinkRate", area, cssMetaData);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,20 +283,20 @@ private static int clamp(int min, int val, int max) {
* Background fill for highlighted text.
*/
private final StyleableObjectProperty<Paint> highlightFill
= new CssProperties.HighlightFillProperty(this, () -> HIGHLIGHT_FILL);
= new CssProperties.HighlightFillProperty(this, HIGHLIGHT_FILL);

/**
* Text color for highlighted text.
*/
private final StyleableObjectProperty<Paint> highlightTextFill
= new CssProperties.HighlightTextFillProperty(this, () -> HIGHLIGHT_TEXT_FILL);
= new CssProperties.HighlightTextFillProperty(this, HIGHLIGHT_TEXT_FILL);

/**
* Controls the blink rate of the caret, when one is displayed. Setting
* the duration to zero disables blinking.
*/
private final StyleableObjectProperty<javafx.util.Duration> caretBlinkRate
= new CssProperties.CaretBlinkRateProperty(this, () -> CARET_BLINK_RATE);
= new CssProperties.CaretBlinkRateProperty(this, CARET_BLINK_RATE);

// editable property
private final BooleanProperty editable = new CssProperties.EditableProperty<>(this);
Expand Down Expand Up @@ -1233,12 +1233,6 @@ public void lineEnd(SelectionPolicy policy) {
moveTo(getCurrentParagraph(), columnPos, policy);
}

@Override
public void selectLine() {
lineStart(SelectionPolicy.CLEAR);
lineEnd(SelectionPolicy.ADJUST);
}

@Override
public void prevPage(SelectionPolicy selectionPolicy) {
showCaretAtBottom();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,10 @@ public static enum CaretVisibility {
/**
* Selects the current line of a multi-line paragraph.
*/
void selectLine();
default void selectLine() {
lineStart(NavigationActions.SelectionPolicy.CLEAR);
lineEnd(NavigationActions.SelectionPolicy.ADJUST);
};

/**
* Moves caret to the previous page (i.e. page up)
Expand Down

0 comments on commit 9db6f92

Please sign in to comment.