Git Product home page Git Product logo

richtextfx's Introduction

RichTextFX

RichTextFX provides a memory-efficient text area for JavaFX that allows the developer to style ranges of text, display custom objects in-line (no more HTMLEditor), and override specific default behaviors only where necessary.

The library does not follow the model-view-controller paradigm, which prevents access to view-specific APIs (e.g., obtaining caret/selection/character bounds, programmic scrolling, and such).

Use the library as a foundation for building rich text editors and code editors that offer syntax highlighting. Being a foundation, many features will not be implemented in this project (such as language-specific syntax highlighters, search-and-replace, hyperlink support, and similar). Rather, developers may implement these features then submit the work as a PR to the richtextfx-demos package.

For further details about RichTextFX, its design principles, how it works, and applying CSS styling, see the wiki.

Demos

Standalone applications that demonstrate RichTextFX features may be found in the RichTextFX demos directory.

Table of Contents

Who uses RichTextFX?

Let us know if you use RichTextFX in your project!

Features

  • Assign arbitrary styles to arbitrary ranges of text. A style can be an object, a CSS string, or a style class string.
  • Display line numbers or, more generally, any graphic in front of each paragraph. Can be used to show breakpoint toggles on each line of code.
  • Support for displaying other Nodes in-line.
  • Positioning a popup window relative to the caret or selection. Useful e.g. to position an autocompletion box.
  • Getting the character index under the mouse when the mouse stays still over the text for a specified period of time. Useful for displaying tooltips depending on the word under the mouse.
  • Overriding the default behavior only where necessary without overriding any other part.

Flavors

The following explains the different rich text area classes. The first one is the base class from which all others extend: it needs further customization before it can be used but provides all aspects of the project's features. The later ones extend this base class in various ways to provide out-of-box functionality for specific use cases. Most will use one of these subclasses.

GenericStyledArea

GenericStyledArea allows one to inline custom objects into the area alongside of text. As such, it uses generics and functional programming to accomplish this task in a completely type-safe way.

It has the following parameter types:

  • PS, the paragraph style. This can be used for text alignment or setting the background color for the entire paragraph. A paragraph is either one line when text wrap is off or a long text displayed over multiple lines in a narrow viewport when text wrap is on.
  • SEG, the segment object. This specifies what immutable object to store in the model part of the area: text, hyperlinks, images, emojis, or any combination thereof.
  • S, the segment style. This can be used for text and object styling. Usually, this will be a CSS style or CSS style class.

Functional programming via lambdas specify how to apply styles, how to create a Node for a given segment, and how to operate on a given segment (e.g., getting its length, combining it with another segment, etc.).

GenericStyledArea is used in the Rich-text demo.

See the wiki for a basic pattern that one must follow to implement custom objects correctly.

StyledTextArea

StyledTextArea<PS, S>, or one of its subclasses below, is the area you will most likely use if you don't need to display custom objects in your area.

It extends GenericStyledArea<PS, StyledText<S>, S>>. StyledText is simply a text (String) and a style object (S). A slightly-enhanced JavaFX Text node is used to display the StyledText<S>, so you can style it using its CSS properties and additional RichTextFX-specific CSS (see the wiki for more details).

It properly handles the aforementioned functional programming to properly display and operate on StyledText<S> objects.

The style object (S) can either be a CSS String (-fx-fill: red;), a CSS styleclass (.red { -fx-fill: red; }), or an object that handles this in a different way. Since most will use either the CSS String or CSS style class approach, there are two subclasses that already handle this correctly.

InlineCssTextArea

InlineCssTextArea uses the Node#setStyle(String cssStyle) method to style Text objects:

area.setStyle(from, to, "-fx-font-weight: bold;");

StyleClassedTextArea

StyleClassedTextArea uses the Node#setStyleClass(String styleClass) method to style Text objects. You can define the style classes in your stylesheet.

example.css:

.red { -fx-fill: red; }

Example.java:

area.setStyleClass(from, to, "red");

This renders the text in the range (from, to) in red.

CodeArea

CodeArea is a variant of StyleClassedTextArea that uses a fixed width font by default, making it a convenient base for source code editors. CodeArea is used in the Java Keywords demo.

Requirements

JDK11 or higher is required. (Can still be compiled with JDK9 if needed)

Download

Stable release

Current stable release is 0.11.0. which is ONLY compatible with Java 11 and UP without the need for add-exports or add-opens JVM arguments.

Maven coordinates

Group ID Artifact ID Version
org.fxmisc.richtext richtextfx 0.11.0

Gradle example

dependencies {
    compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '0.11.0'
}

Sbt example

libraryDependencies += "org.fxmisc.richtext" % "richtextfx" % "0.11.0"

Manual download

Download the JAR file or the fat JAR file (including dependencies) and place it on your classpath.

Snapshot releases

Snapshot releases are deployed to Sonatype snapshot repository.

Maven coordinates

Group ID Artifact ID Version
org.fxmisc.richtext richtextfx 1.0.0-SNAPSHOT

Gradle example

repositories {
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
}

dependencies {
    compile group: 'org.fxmisc.richtext', name: 'richtextfx', version: '1.0.0-SNAPSHOT'
}

Sbt example

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

libraryDependencies += "org.fxmisc.richtext" % "richtextfx" % "1.0.0-SNAPSHOT"

License

Dual-licensed under BSD 2-Clause License and GPLv2 with the Classpath Exception.

richtextfx's People

Contributors

jordanmartinez avatar tomasmikula avatar jugen avatar devcharly avatar afester avatar mewesk avatar neilccbrown avatar cemartins avatar uzielsilva avatar shoaniki avatar creativeartie avatar skyaphid avatar prat-man avatar jeffreyguenther avatar jformdesigner avatar scientificware avatar veita avatar alexp11223 avatar pariskol avatar rationalityfrontline avatar rohitawate avatar terjedahl avatar theandreim avatar amjdhsn avatar chrisf-london avatar finanzer avatar gaeqs avatar grigoriliev avatar iamgio avatar svkreml avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.