OpenTiny for Java Swing integration
Users can easily configure the OpenTiny editor in Swing through the OpenTiny for Swing integration.
Getting the OpenTiny for Swing integration
To start using OpenTiny for Swing as your new rich text editor, the first step is to obtain a copy of the Integration.
Contact Tiny Support to discuss how to get started with our latest release.
Get started with our OpenTiny in Swing integration
To include our OpenTiny in Swing integration in your Java project just follow the steps below:
1. Copy OpenTiny in Swing libraries
From the release zip
file, select all the Java libraries under the lib
folder and import them into your project. This libraries contain everything needed to run our integration.
2. Select a deployment and create a configuration
The Swing integration allows the user to select the origin of the OpenTiny code: embedded (recommended), cloud, or external.
-
Embedded deployments use the version of OpenTiny prepackaged with the current release of the integration. This is guaranteed to be compatible with the integration specific plugins.
final Config myTinyConfiguration = Config.embedded();
-
Cloud deployments pull OpenTiny from the Tiny Cloud. Use this option by passing your API key and specifying the Tiny Cloud version.
final Config myTinyConfiguration = Config.cloud("<my_api_key>", "6-stable");
-
External deployments allow to use a local version of OpenTiny by giving the address of the location where OpenTiny is being served.
final Config myTinyConfiguration = Config.external("http://<my_server>/<path>/tinymce.min.js");
The configuration can be customized purely in Java:
final Path contentPath = Paths.get(System.getProperty("user.home"));
final Config myConfig = Config.embedded()
.setContentPath(contentPath)
.setImageSaverLocal(contentPath)
.addPlugins(
"advcode advlist autolink lists link image editimage charmap emoticons " +
"anchor searchreplace insertdatetime media table powerpaste help wordcount")
.putProperty("width", 800)
.putProperty("height", 600)
.putProperty("menubar", false)
.putProperty("toolbar",
"undo redo | blocks | bold italic backcolor | " +
"alignleft aligncenter alignright alignjustify | " +
"bullist numlist outdent indent | removeformat | link image | help")
.putProperty("images_reuse_filename", true);
Or by passing Javascript that returns a OpenTiny configuration object.
config.js:
(function() {
return {
width: 800,
height: 600,
plugins: [
'advcode', 'advlist', 'autolink', 'lists', 'link', 'image', 'editimage', 'charmap', 'emoticons',
'anchor', 'searchreplace', 'insertdatetime', 'media', 'table', 'powerpaste', 'help', 'wordcount'
],
menubar: false,
toolbar: [
'undo redo | blocks | bold italic backcolor | alignleft aligncenter ',
'alignright alignjustify | bullist numlist outdent indent | removeformat | ',
'link image | help'
].join(''),
images_reuse_filename: true
};
})();
Snippet of Edit.java:
final Path contentPath = Paths.get(System.getProperty("user.home"));
final Config myConfig = Config.embedded()
.setContentPath(contentPath)
.setImageSaverLocal(contentPath)
.setInitConf(Edit.class, "config.js"); // load config.js using class loader
3. Create the editor and add it to your view
Create the editor by passing a configuration object. The editor initialization is asynchronous so starting a new editor will return a future value that can be accessed as a normal future value.
final Config myConfig = Config.embedded();
final OpenTiny editor = OpenTiny.futureEditor(myConfig).get();
editor.setHtml("<p>Hello World!</p>");
final JPanel holder = new JPanel(new BorderLayout());
holder.add(editor.component(), BorderLayout.CENTER);
Once the editor has been extracted from the future value you can use its component (JComponent) to position it in your view.
For more examples check the GitHub repository.
Explore other resources
-
GitHub repository - Refer to this link for examples on how to use OpenTiny for Swing.
-
An additional set of documentation is shipped with the integration in a
zip
file containing a library ofJavadocs
and API reference guides which help in understanding and applying the concepts. Thezip
file includes the following documents:-
readme.txt
- This file has general information about OpenTiny for Swing integration. -
license.txt
- This file has all the license details about OpenTiny for Swing as a commercial software. -
release-notes.txt
- This file has information about the integrations and enhancements that have been implemented in OpenTiny for Swing integration. -
change-log.md
- This file lists all user impacting and major changes for every release of OpenTiny for Swing integration. -
jar
files - Thejar
files that implement the integration can be found underlib/
-
javadoc
- Thejavadoc
can be found atdocs/javadoc/index.html
.
-