close

Filter

loading table of contents...

Site Manager Developer Manual / Version 2304

Table Of Contents

4.8.6 Add Action to RichTextPane

You can use custom actions to perform some actions in the RichTextPane. To this end, you have to perform the following steps:

Step Description
1 Create the command.
 

public class InsertElementCommand extends TagActionCommand {

public static String COMMAND_NAME = "insert-element";

public InsertElementCommand() {

super(COMMAND_NAME);

}

}

2 Register the command (see Section 4.8.1, “Register Commands” for details):
3 Create the action you want to perform. The name of the action must match the name of the command above. The following code shows an example action which inserts an image into the RichTextPane.
 

public class InsertElementAction extends AbstractLinkAction { 

public InsertElementAction() {

    super(InsertElementCommand.COMMAND_NAME);

  }

  public void actionPerformed(ActionEvent event) {

    JEditorPane editor = getEditor(event);

    StyledEditorKit kit = getStyledEditorKit(editor);

    XHTMLDocument document = getXHTMLDocument(editor);

    document.removeSelection(editor);

    String uri = getReferenceToInternalDocument(12) + "/" + "blobDataPropertyName";

    document.insertImage(kit, editor, uri);

  }

}

4 Subclass hox.corem.editor.toolkit.property.RichTextPane (for example as MyRichTextPane) and override the createDefaultEditorKit() method to return your own RichTextEditorKit.
5 Define your Action in the EditorKit class and override getActions to add your custom action to the action array.
 

private final Action insertElementAction = new InsertElementAction();

public Action[] getActions() {

return TextAction.augmentList(super.getActions(), insertElementAction);

}

6 Configure your MyRichTextPane in the editor.xml file as described in Section 4.5, “Program Own PropertyEditors”.

Table 4.11. How to integrate actions into the RichTextPane


Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.