Example usage for javax.swing JEditorPane addKeyListener

List of usage examples for javax.swing JEditorPane addKeyListener

Introduction

In this page you can find the example usage for javax.swing JEditorPane addKeyListener.

Prototype

public synchronized void addKeyListener(KeyListener l) 

Source Link

Document

Adds the specified key listener to receive key events from this component.

Usage

From source file:org.mindswap.swoop.renderer.BaseEntityRenderer.java

/**
 * Create a JEditorPane given the contentType (text/plain or text/html)
 * and make other default settings (add hyperlink listener, editable false)
 * @param contentType//  ww  w .  java 2  s.c om
 * @return
 */
public static JEditorPane getEditorPane(String contentType, TermsDisplay TD) {
    JEditorPane editorPane = null;
    if (contentType.equals("text/plain"))
        editorPane = new JEditorPane();
    else if (contentType.equals("text/html")) {
        editorPane = new JEditorPane();
        editorPane.addHyperlinkListener(TD);
    } else if (contentType.equals("text/xml"))
        editorPane = new JEditorPane();
    else
        throw new RuntimeException("Cannot create an editor pane for content type " + contentType);

    editorPane.setEditable(false);
    editorPane.setContentType(contentType);

    // adding to UI listeners of TermsDisplay
    //editorPane.getDocument().addDocumentListener(TD);
    editorPane.addMouseListener(TD);
    editorPane.addKeyListener(TD);

    return editorPane;
}

From source file:org.mindswap.swoop.renderer.entity.TurtleEntityRenderer.java

public Component getDisplayComponent(SwoopDisplayPanel panel) {
    if (!(panel instanceof TermsDisplay))
        throw new IllegalArgumentException();

    JEditorPane editorPane = BaseEntityRenderer.getEditorPane(this.getContentType(), (TermsDisplay) panel);

    if (!editorEnabled) {
        return editorPane;
    } else {//from   ww  w .  j a  v a 2s.  c  om
        editorPane.setEditable(true);
        // adding to UI listeners of TermsDisplay
        //editorPane.getDocument().addDocumentListener((TermsDisplay)panel);
        editorPane.addMouseListener((TermsDisplay) panel);
        editorPane.addKeyListener((TermsDisplay) panel);
    }
    return editorPane;
}