-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Java 9 files and modified gradle build to accommodate
- Loading branch information
Showing
10 changed files
with
426 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
richtextfx/src/integrationTest/java/org/fxmisc/richtext/MultiReleaseJarTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.fxmisc.richtext; | ||
|
||
import org.fxmisc.richtext.JavaFXCompatibility; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.assertFalse; | ||
|
||
public class MultiReleaseJarTest | ||
{ | ||
@Test | ||
public void tests_correct_classes_are_used() { | ||
|
||
if ( System.getProperty( "javafx.version" ).split("\\.")[0].equals("8") ) { | ||
assertTrue( JavaFXCompatibility.isJavaEight() ); | ||
} | ||
else { | ||
assertFalse( JavaFXCompatibility.isJavaEight() ); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
richtextfx/src/main/java9/org/fxmisc/richtext/JavaFXCompatibility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.fxmisc.richtext; | ||
|
||
import javafx.beans.property.ObjectProperty; | ||
import javafx.css.converter.SizeConverter; | ||
import javafx.css.StyleConverter; | ||
import javafx.scene.paint.Paint; | ||
import javafx.scene.text.Text; | ||
|
||
/* ************************************************* * | ||
* * | ||
* Also look for and remove deprecated methods !!! * | ||
* * | ||
* ************************************************* */ | ||
/** | ||
* Used to use reflection to make this project's code work on Java 8 and Java 9 in a single jar | ||
*/ | ||
@Deprecated | ||
public class JavaFXCompatibility { | ||
|
||
static public boolean isJavaEight() { | ||
return false; | ||
} | ||
|
||
static ObjectProperty<Paint> Text_selectionFillProperty(Text text) { | ||
return text.selectionFillProperty(); | ||
} | ||
|
||
static StyleConverter<?, Number[]> SizeConverter_SequenceConverter_getInstance() { | ||
return SizeConverter.SequenceConverter.getInstance(); | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
richtextfx/src/main/java9/org/fxmisc/richtext/TextFlowExt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package org.fxmisc.richtext; | ||
|
||
import static org.fxmisc.richtext.model.TwoDimensional.Bias.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javafx.geometry.Point2D; | ||
import javafx.geometry.Rectangle2D; | ||
import javafx.scene.control.IndexRange; | ||
import org.fxmisc.richtext.model.TwoLevelNavigator; | ||
|
||
import javafx.scene.shape.PathElement; | ||
import javafx.scene.text.HitInfo; | ||
import javafx.scene.text.TextFlow; | ||
import javafx.scene.shape.LineTo; | ||
import javafx.scene.shape.MoveTo; | ||
|
||
/** | ||
* Adds additional API to {@link TextFlow}. | ||
*/ | ||
class TextFlowExt extends TextFlow { | ||
|
||
private TextFlowLayout layout; | ||
|
||
private TextFlowLayout textLayout() | ||
{ | ||
if ( layout == null ) { | ||
layout = new TextFlowLayout( this, getManagedChildren() ); | ||
} | ||
return layout; | ||
} | ||
|
||
int getLineCount() { | ||
return textLayout().getLineCount(); | ||
} | ||
|
||
int getLineStartPosition(int charIdx) { | ||
TwoLevelNavigator navigator = textLayout().getTwoLevelNavigator(); | ||
int currentLineIndex = navigator.offsetToPosition(charIdx, Forward).getMajor(); | ||
return navigator.position(currentLineIndex, 0).toOffset(); | ||
} | ||
|
||
int getLineEndPosition(int charIdx) { | ||
TwoLevelNavigator navigator = textLayout().getTwoLevelNavigator(); | ||
int currentLineIndex = navigator.offsetToPosition(charIdx, Forward).getMajor(); | ||
int minor = (currentLineIndex == getLineCount() - 1) ? 0 : -1; | ||
return navigator.position(currentLineIndex + 1, minor).toOffset(); | ||
} | ||
|
||
int getLineOfCharacter(int charIdx) { | ||
TwoLevelNavigator navigator = textLayout().getTwoLevelNavigator(); | ||
return navigator.offsetToPosition(charIdx, Forward).getMajor(); | ||
} | ||
|
||
PathElement[] getCaretShape(int charIdx, boolean isLeading) { | ||
return caretShape(charIdx, isLeading); | ||
} | ||
|
||
PathElement[] getRangeShape(IndexRange range) { | ||
return getRangeShape(range.getStart(), range.getEnd()); | ||
} | ||
|
||
PathElement[] getRangeShape(int from, int to) { | ||
return rangeShape(from, to); | ||
} | ||
|
||
PathElement[] getUnderlineShape(IndexRange range) { | ||
return getUnderlineShape(range.getStart(), range.getEnd()); | ||
} | ||
|
||
/** | ||
* @param from The index of the first character. | ||
* @param to The index of the last character. | ||
* @return An array with the PathElement objects which define an | ||
* underline from the first to the last character. | ||
*/ | ||
PathElement[] getUnderlineShape(int from, int to) { | ||
// get a Path for the text underline | ||
List<PathElement> result = new ArrayList<>(); | ||
|
||
PathElement[] shape = rangeShape( from, to ); | ||
// The shape is a closed Path for one or more rectangles AROUND the selected text. | ||
// shape: [MoveTo origin, LineTo top R, LineTo bottom R, LineTo bottom L, LineTo origin, *] | ||
|
||
// Extract the bottom left and right coordinates for each rectangle to get the underline path. | ||
for ( int ele = 2; ele < shape.length; ele += 5 ) | ||
{ | ||
LineTo bl = (LineTo) shape[ele+1]; | ||
LineTo br = (LineTo) shape[ele]; | ||
double y = br.getY() - 2.5; | ||
|
||
result.add( new MoveTo( bl.getX(), y ) ); | ||
result.add( new LineTo( br.getX(), y ) ); | ||
} | ||
|
||
return result.toArray(new PathElement[0]); | ||
} | ||
|
||
CharacterHit hitLine(double x, int lineIndex) { | ||
return hit(x, textLayout().getLineCenter( lineIndex )); | ||
} | ||
|
||
CharacterHit hit(double x, double y) { | ||
TextFlowSpan span = textLayout().getLineSpan( (float) y ); | ||
Rectangle2D lineBounds = span.getBounds(); | ||
|
||
HitInfo hit = hitTest(new Point2D(x, y)); | ||
int charIdx = hit.getCharIndex(); | ||
boolean leading = hit.isLeading(); | ||
|
||
if ( ! leading ) { | ||
// If this is a wrapped paragraph and hit character is at end of hit line, make sure that the | ||
// "character hit" stays at the end of the hit line (and not at the beginning of the next line). | ||
leading = (getLineCount() > 1 && charIdx + 1 >= span.getStart() + span.getLength()); | ||
} | ||
|
||
if(x < lineBounds.getMinX() || x > lineBounds.getMaxX()) { | ||
if(leading) { | ||
return CharacterHit.insertionAt(charIdx); | ||
} else { | ||
return CharacterHit.insertionAt(charIdx + 1); | ||
} | ||
} else { | ||
if(leading) { | ||
return CharacterHit.leadingHalfOf(charIdx); | ||
} else { | ||
return CharacterHit.trailingHalfOf(charIdx); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.