Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
01b2f61
Patched TextFlowExt to access Java9 hidden code
imario42 Sep 26, 2017
749db5e
use reflection for JavaFX 8 and 9 compatibility of StyledTextArea and…
DevCharly Oct 14, 2017
9f3c604
made TextFlowExt compatible to JavaFX 8
DevCharly Oct 14, 2017
93be11a
use StyleConverter.getEnumConverter() instead of reflection
DevCharly Oct 14, 2017
69b2b1b
made TextHyperlinkArea compatible to JavaFX 8
DevCharly Oct 14, 2017
ec81245
fixed javadoc error in class JavaFXCompatibility
DevCharly Oct 14, 2017
62335ea
Travis: also build on Java 9 to detect compatibility issues
DevCharly Oct 14, 2017
7fde186
use TestFX 4.0.8-alpha for Java 9 compatibility
DevCharly Oct 14, 2017
a2d7da3
cache methods in GenericIceBreaker for performance
DevCharly Oct 15, 2017
9fcfb4e
moved ParagraphText specific code from createStyledTextNode() methods…
DevCharly Oct 15, 2017
a590bb3
invoke m.setAccessible(true) only once for cached method
DevCharly Oct 16, 2017
81b41ec
Merge remote-tracking branch 'origin/createStyledTextNode-cleanup' in…
DevCharly Oct 17, 2017
631ea2c
made class JavaFXCompatibility package private again (no longer neede…
DevCharly Oct 17, 2017
06a7bdf
Travis: set gradle source/targetCompatibility to 9 when building on o…
DevCharly Oct 17, 2017
80ad8b6
include testfx-internal-java9 when Gradle is running in Java 9 VM
DevCharly Oct 17, 2017
b083c72
exclude package org.fxmisc.richtext.j9adapters from javadoc
DevCharly Oct 17, 2017
df0eca7
changed tabs to spaces; changed line endings of HitInfo.java from CRL…
DevCharly Oct 17, 2017
aaee833
moved classes/interfaces from package j9adapters into class TextFlowE…
DevCharly Oct 18, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ matrix:
- os: linux
dist: trusty
jdk: oraclejdk8
- os: linux
dist: trusty
jdk: oraclejdk9
env: _JAVA_OPTIONS="-DcheckSourceCompatibility=9"

# Headless Build: xvfb + TestFX does not work on Travis OSX environments (as of 2017-05-24)
- os: osx
Expand Down
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@ subprojects {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'

// allow setting source/target compatibility from command line
// for checking Java 9+ compatibility in Travis CI
def checkSourceCompatibility = System.properties["checkSourceCompatibility"]
if (checkSourceCompatibility != null) {
sourceCompatibility = checkSourceCompatibility
targetCompatibility = checkSourceCompatibility
}

compileJava.options.deprecation = true
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.fxmisc.richtext.demo.hyperlink;

import com.sun.deploy.uitoolkit.impl.fx.HostServicesFactory;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import org.fxmisc.flowless.VirtualizedScrollPane;

import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.function.Consumer;

/**
Expand All @@ -21,7 +24,16 @@ public static void main(String[] args) {

@Override
public void start(Stage primaryStage) {
Consumer<String> showLink = HostServicesFactory.getInstance(this)::showDocument;
Consumer<String> showLink = (string) -> {
try
{
Desktop.getDesktop().browse(new URI(string));
}
catch (IOException | URISyntaxException e)
{
throw new RuntimeException(e);
}
};
TextHyperlinkArea area = new TextHyperlinkArea(showLink);

area.appendText("Some text in the area\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ public static TextExt createStyledTextNode(Consumer<TextExt> applySegment) {
TextExt t = new TextExt();
t.setTextOrigin(VPos.TOP);
applySegment.accept(t);

// XXX: binding selectionFill to textFill,
// see the note at highlightTextFill
t.impl_selectionFillProperty().bind(t.fillProperty());
return t;
}
}
7 changes: 5 additions & 2 deletions richtextfx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ dependencies {

integrationTestCompile group: 'junit', name: 'junit', version: '4.12'
integrationTestCompile group: 'com.nitorcreations', name: 'junit-runners', version: '1.2'
integrationTestCompile "org.testfx:testfx-core:4.0.6-alpha"
integrationTestCompile ("org.testfx:testfx-junit:4.0.6-alpha") {
integrationTestCompile "org.testfx:testfx-core:4.0.8-alpha"
if (org.gradle.api.JavaVersion.current().isJava9()) {
integrationTestCompile "org.testfx:testfx-internal-java9:4.0.8-alpha"
}
integrationTestCompile ("org.testfx:testfx-junit:4.0.8-alpha") {
exclude(group: "junit", module: "junit")
}
integrationTestCompile "org.testfx:openjfx-monocle:8u76-b04"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.fxmisc.richtext;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.StringTokenizer;
import javafx.beans.property.ObjectProperty;
import javafx.css.StyleConverter;
import javafx.scene.paint.Paint;
import javafx.scene.text.Text;

class JavaFXCompatibility {

private static boolean isJava9orLater;

static {
try {
// Java 9 version-String Scheme: http://openjdk.java.net/jeps/223
StringTokenizer st = new StringTokenizer(System.getProperty("java.version"), "._-+");
int majorVersion = Integer.parseInt(st.nextToken());
isJava9orLater = majorVersion >= 9;
} catch (Exception e) {
// Java 8 or older
}
}

/**
* Java 8: javafx.scene.text.Text.impl_selectionFillProperty()
* Java 9+: javafx.scene.text.Text.selectionFillProperty()
*/
@SuppressWarnings("unchecked")
static ObjectProperty<Paint> Text_selectionFillProperty(Text text) {
try {
if (mText_selectionFillProperty == null) {
mText_selectionFillProperty = Text.class.getMethod(
isJava9orLater ? "selectionFillProperty" : "impl_selectionFillProperty");
}
return (ObjectProperty<Paint>) mText_selectionFillProperty.invoke(text);
} catch(NoSuchMethodException | SecurityException | IllegalAccessException |
IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
throw new Error(e);
}
}

private static Method mText_selectionFillProperty;

/**
* Java 8: com.sun.javafx.css.converters.SizeConverter.SequenceConverter.getInstance()
* Java 9+: javafx.css.converter.SizeConverter.SequenceConverter.getInstance()
*/
@SuppressWarnings("unchecked")
static StyleConverter<?, Number[]> SizeConverter_SequenceConverter_getInstance() {
try {
if (mSizeConverter_SequenceConverter_getInstance == null) {
Class<?> c = Class.forName(isJava9orLater
? "javafx.css.converter.SizeConverter$SequenceConverter"
: "com.sun.javafx.css.converters.SizeConverter$SequenceConverter");
mSizeConverter_SequenceConverter_getInstance = c.getMethod("getInstance");
}
return (StyleConverter<?, Number[]>) mSizeConverter_SequenceConverter_getInstance.invoke(null);
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException |
IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
throw new Error(e);
}
}

private static Method mSizeConverter_SequenceConverter_getInstance;
}
14 changes: 11 additions & 3 deletions richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,15 @@ public ObjectProperty<Paint> highlightTextFillProperty() {
// });

// populate with text nodes
par.getStyledSegments().stream().map(nodeFactory).forEach(getChildren()::add);
par.getStyledSegments().stream().map(nodeFactory).forEach(n -> {
if (n instanceof TextExt) {
TextExt t = (TextExt) n;
// XXX: binding selectionFill to textFill,
// see the note at highlightTextFill
JavaFXCompatibility.Text_selectionFillProperty(t).bind(t.fillProperty());
}
getChildren().add(n);
});

// set up custom css shape helpers
Supplier<Path> createBackgroundShape = () -> {
Expand Down Expand Up @@ -406,8 +414,8 @@ private void updateSharedShapeRange(T value, int start, int end) {
T lastShapeValue = lastShapeValueRange._1;

// calculate smallest possible position which is consecutive to the given start position
final int prevEndNext = lastShapeValueRange.get2().getEnd() + 1;
if (start <= prevEndNext && // Consecutive?
final int prevEndNext = lastShapeValueRange.get2().getEnd() + 1;
if (start <= prevEndNext && // Consecutive?
lastShapeValue.equals(value)) { // Same style?

IndexRange lastRange = lastShapeValueRange._2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ public static <S> Node createStyledTextNode(String text, S style,
t.setTextOrigin(VPos.TOP);
t.getStyleClass().add("text");
applyStyle.accept(t, style);

// XXX: binding selectionFill to textFill,
// see the note at highlightTextFill
t.impl_selectionFillProperty().bind(t.fillProperty());
return t;
}
}
13 changes: 5 additions & 8 deletions richtextfx/src/main/java/org/fxmisc/richtext/TextExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import java.util.Collections;
import java.util.List;

import com.sun.javafx.css.converters.EnumConverter;
import com.sun.javafx.css.converters.SizeConverter;

import javafx.beans.property.ObjectProperty;
import javafx.css.CssMetaData;
import javafx.css.StyleConverter;
Expand Down Expand Up @@ -226,7 +223,7 @@ public ObjectProperty<Paint> borderStrokeColorProperty() {
*/
public ObjectProperty<Number> underlineWidthProperty() { return underlineWidth; }

// Dash array for the text underline
// Dash array for the text underline
public Number[] getUnderlineDashArray() { return underlineDashArray.get(); }
public void setUnderlineDashArray(Number[] dashArray) { underlineDashArray.set(dashArray); }

Expand Down Expand Up @@ -275,12 +272,12 @@ private static class StyleableProperties {
);

private static final CssMetaData<TextExt, StrokeType> BORDER_TYPE = new CustomCssMetaData<>(
"-rtfx-border-stroke-type", new EnumConverter<>(StrokeType.class),
"-rtfx-border-stroke-type", (StyleConverter<?, StrokeType>) StyleConverter.getEnumConverter(StrokeType.class),
StrokeType.INSIDE, n -> n.borderStrokeType
);

private static final CssMetaData<TextExt, Number[]> BORDER_DASH_ARRAY = new CustomCssMetaData<>(
"-rtfx-border-stroke-dash-array", SizeConverter.SequenceConverter.getInstance(),
"-rtfx-border-stroke-dash-array", JavaFXCompatibility.SizeConverter_SequenceConverter_getInstance(),
new Double[0], n -> n.borderStrokeDashArray
);

Expand All @@ -295,12 +292,12 @@ private static class StyleableProperties {
);

private static final CssMetaData<TextExt, Number[]> UNDERLINE_DASH_ARRAY = new CustomCssMetaData<>(
"-rtfx-underline-dash-array", SizeConverter.SequenceConverter.getInstance(),
"-rtfx-underline-dash-array", JavaFXCompatibility.SizeConverter_SequenceConverter_getInstance(),
new Double[0], n -> n.underlineDashArray
);

private static final CssMetaData<TextExt, StrokeLineCap> UNDERLINE_CAP = new CustomCssMetaData<>(
"-rtfx-underline-cap", new EnumConverter<StrokeLineCap>(StrokeLineCap.class),
"-rtfx-underline-cap", (StyleConverter<?, StrokeLineCap>) StyleConverter.getEnumConverter(StrokeLineCap.class),
StrokeLineCap.SQUARE, n -> n.underlineCap
);
}
Expand Down
Loading