Skip to content

Commit

Permalink
Prevent wrap text from being set true for text fields. (#895)
Browse files Browse the repository at this point in the history
* Prevent wrap text from being set true for text fields.
* Updated package info for styled text fields.
  • Loading branch information
Jugen authored Jan 9, 2020
1 parent 2f8a72b commit ef547eb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
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
Expand Up @@ -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+" );
Expand Down Expand Up @@ -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);
}
});
}

/*
Expand Down Expand Up @@ -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
Expand Up @@ -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
Expand Down

0 comments on commit ef547eb

Please sign in to comment.