richtexteditor-javafx

WYSIWYG editor for JavafX supporting all common formatting options.

License

License

Categories

Categories

Net JavaFX User Interface
GroupId

GroupId

net.dankito.richtexteditor
ArtifactId

ArtifactId

richtexteditor-javafx
Last Version

Last Version

2.0.20
Release Date

Release Date

Type

Type

jar
Description

Description

richtexteditor-javafx
WYSIWYG editor for JavafX supporting all common formatting options.
Project URL

Project URL

https://github.com/dankito/RichTextEditor
Source Code Management

Source Code Management

https://github.com/dankito/RichTextEditor

Download richtexteditor-javafx

How to add to project

<!-- https://jarcasting.com/artifacts/net.dankito.richtexteditor/richtexteditor-javafx/ -->
<dependency>
    <groupId>net.dankito.richtexteditor</groupId>
    <artifactId>richtexteditor-javafx</artifactId>
    <version>2.0.20</version>
</dependency>
// https://jarcasting.com/artifacts/net.dankito.richtexteditor/richtexteditor-javafx/
implementation 'net.dankito.richtexteditor:richtexteditor-javafx:2.0.20'
// https://jarcasting.com/artifacts/net.dankito.richtexteditor/richtexteditor-javafx/
implementation ("net.dankito.richtexteditor:richtexteditor-javafx:2.0.20")
'net.dankito.richtexteditor:richtexteditor-javafx:jar:2.0.20'
<dependency org="net.dankito.richtexteditor" name="richtexteditor-javafx" rev="2.0.20">
  <artifact name="richtexteditor-javafx" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.dankito.richtexteditor', module='richtexteditor-javafx', version='2.0.20')
)
libraryDependencies += "net.dankito.richtexteditor" % "richtexteditor-javafx" % "2.0.20"
[net.dankito.richtexteditor/richtexteditor-javafx "2.0.20"]

Dependencies

compile (6)

Group / Artifact Type Version
net.dankito.richtexteditor : richtexteditor-common jar 2.0.20
no.tornado : tornadofx jar 1.7.17
no.tornado : tornadofx-controls jar 1.0.6
com.drewnoakes : metadata-extractor jar 2.11.0
ch.qos.logback : logback-core jar 1.2.3
ch.qos.logback : logback-classic jar 1.2.3

Project Modules

There are no modules declared in this project.

RichTextEditor

Maven Central

WYSIWYG editor for Android and JavaFX with a rich set of supported formatting options.

Based on https://github.com/wasabeef/richeditor-android, but with more options like setting the font and text foreground and background color. And it also has ready to use UI elements implemented for these.

Features

  • Bold, Italic, Underline, Strike through, Subscript, Superscript
  • Heading 1 - 6, Text body, Preformatted, Block quote
  • Font (reads all system fonts)
  • Font Size
  • Text Color
  • Text Background Color
  • Highlight text
  • Justify Left, Center, Right, Blockquote
  • Indent, Outdent
  • Undo, Redo
  • Unordered List (Bullets)
  • Ordered List (Numbers)
  • Insert local or remote Image
  • Insert Link
  • Insert Checkbox
  • Search
  • For all those it has predefined commands. You can use the standard toolbar or create your own within minutes.
  • All commands have a Material Design icon. But of course you can give all of them your custom icon.

Demo application

You can download it from PlayStore, can use the precompiled .apk or compile the DemoApp project yourself.

Setup

Gradle:

dependencies {
  implementation 'net.dankito.richtexteditor:richtexteditor-android:2.0.14'
}

Maven:

<dependency>
   <groupId>net.dankito.richtexteditor</groupId>
   <artifactId>richtexteditor-android</artifactId>
   <version>2.0.14</version>
</dependency>

Usage

Layout xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <net.dankito.richtexteditor.android.RichTextEditor
        android:id="@+id/editor"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="10"
    />

    <net.dankito.richtexteditor.android.toolbar.GroupedCommandsEditorToolbar
        android:id="@+id/editorToolbar"
        android:layout_width="match_parent"
        android:layout_height="36dp"
        android:background="@color/colorPrimary"
    />

</LinearLayout>

Activity

public class MainActivity extends AppCompatActivity {

    private RichTextEditor editor;

    private GroupedCommandsEditorToolbar bottomGroupedCommandsToolbar;

    private IPermissionsService permissionsService = new PermissionsService(this);


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        setContentView(R.layout.activity_main);

        editor = (RichTextEditor) findViewById(R.id.editor);

        // this is needed if you like to insert images so that the user gets asked for permission to access external storage if needed
        // see also onRequestPermissionsResult() below
        editor.setPermissionsService(permissionsService);

        bottomGroupedCommandsToolbar = (GroupedCommandsEditorToolbar) findViewById(R.id.bottomGroupedCommandsToolbar);
        bottomGroupedCommandsToolbar.setEditor(editor);

        // you can adjust predefined toolbars by removing single commands
//        bottomGroupedCommandsToolbar.removeCommandFromGroupedCommandsView(CommandName.TOGGLE_GROUPED_TEXT_STYLES_COMMANDS_VIEW, CommandName.BOLD);
//        bottomGroupedCommandsToolbar.removeSearchView();


        editor.setEditorFontSize(20);
        editor.setPadding((4 * (int) getResources().getDisplayMetrics().density));

        // some properties you also can set on editor
//        editor.setEditorBackgroundColor(Color.YELLOW)
//        editor.setEditorFontColor(Color.MAGENTA)
//        editor.setEditorFontFamily("cursive")

        // show keyboard right at start up
//        editor.focusEditorAndShowKeyboardDelayed()

        // only needed if you allow to automatically download remote images
        editor.setDownloadImageConfig(new DownloadImageConfig(DownloadImageUiSetting.AllowSelectDownloadFolderInCode,
            new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "downloaded_images")));
        
        
        /*      Set listeners on RichTextEditor         */
        
        // get informed when edited HTML changed
        editor.addDidHtmlChangeListener(new DidHtmlChangeListener() {
            @Override
            public void didHtmlChange(boolean didHtmlChange) {
                // e.g. set save button to enabled / disabled
                // btnSave.setEnabled(didHtmlChange);
            }
        });
        
        // use this listener with care, it may decreases performance tremendously
        editor.addHtmlChangedListener(new HtmlChangedListener() {
            @Override
            public void htmlChangedAsync(@NotNull String html) {
                // htmlChangedAsync() gets called on a background thread, so if you want to use it on UI thread you have to call runOnUiThread()
            }
        });
    }


    // Important: Overwrite onBackPressed and pass it to toolbar.There's no other way that it can get informed of back button presses.
    @Override
    public void onBackPressed() {
        if(bottomGroupedCommandsToolbar.handlesBackButtonPress() == false) {
            super.onBackPressed();
        }
    }

    // only needed if you like to insert images from local device so the user gets asked for permission to access external storage if needed

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        permissionsService.onRequestPermissionsResult(requestCode, permissions, grantResults);

        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }


    // then when you want to do something with edited html
    private void save() {
        editor.getCurrentHtmlAsync(new GetCurrentHtmlCallback() {

            @Override
            public void htmlRetrieved(@NotNull String html) {
                saveHtml(html);
            }
        });
    }

    private void saveHtml(String html) {
        // ...
    }

}

For an example see MainActivity in DemoApp project (it's written in Kotlin).

License

Copyright 2017 dankito

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
2.0.20
2.0.19
2.0.18
2.0.17
2.0.16
2.0.15
2.0.14
2.0.13
2.0.12
2.0.11
2.0.10
2.0.9
2.0.8
2.0.7
2.0.6
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.2.2
1.2.1
1.2.0
1.1.4
1.1.3