Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent wrap text from being set true for text fields. #895

Merged
merged 2 commits into from
Jan 9, 2020
Merged
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions richtextfx/src/main/java/org/fxmisc/richtext/StyledTextField.java
Original file line number Diff line number Diff line change
@@ -24,6 +24,16 @@
import javafx.scene.layout.Pane;
import javafx.scene.text.TextFlow;

/**
* A text field whose segment generic has been specified to be a {@link String}. How the text
* will be styled is not yet specified in this class, but use {@link StyleClassedTextField} for a style class
* approach to styling the text and {@link InlineCssTextField} for an inline css approach to styling the text.
*
* @param <PS> type of paragraph style
* @param <S> type of style that can be applied to text.
*
* @author Jurgen
*/
public class StyledTextField<PS, S> extends StyledTextArea
{
private final Pattern VERTICAL_WHITESPACE = Pattern.compile( "\\v+" );
@@ -82,6 +92,14 @@ else if ( ! focused && was ) {
}
selectAll = true;
});

super.setWrapText( false );
wrapTextProperty().addListener( (ob,ov,wrap) -> {
if ( wrap ) { // veto any changes
wrapTextProperty().unbind();
super.setWrapText(false);
}
});
}

/*
@@ -155,4 +173,9 @@ public void replaceText( int start, int end, String text )
{
super.replaceText( start, end, VERTICAL_WHITESPACE.matcher( text ).replaceAll( " " ) );
}

/** This is a <b>no op</b> for text fields and therefore marked as <i>deprecated</i>. */
@Override @Deprecated public void setWrapText( boolean value ) {}
/** This <u>always</u> returns <b>false</b> for styled text fields. */
@Override public boolean isWrapText() { return false; }
}
Original file line number Diff line number Diff line change
@@ -10,6 +10,11 @@
* {@link org.fxmisc.richtext.StyleClassedTextArea} and {@link org.fxmisc.richtext.InlineCssTextArea}.
* For those looking to use a base for a code editor, see {@link org.fxmisc.richtext.CodeArea}.
* </p>
* <p>
* For text fields there is {@link org.fxmisc.richtext.StyledTextField} using {@link java.lang.String}-only segments,
* and styling them are also already supported in the two most common ways via
* {@link org.fxmisc.richtext.StyleClassedTextField} and {@link org.fxmisc.richtext.InlineCssTextField}.
* </p>
*
* @see org.fxmisc.richtext.model.EditableStyledDocument
* @see org.fxmisc.richtext.model.TwoDimensional