Search in sources :

Example 6 with Document

use of org.apache.pivot.wtk.text.Document in project pivot by apache.

the class TextPaneSkin method mouseClick.

@Override
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
    boolean consumed = super.mouseClick(component, button, x, y, count);
    TextPane textPane = (TextPane) component;
    Document document = textPane.getDocument();
    if (button == Mouse.Button.LEFT) {
        int index = getInsertionPoint(x, y);
        if (index != -1) {
            if (count == 2) {
                CharSpan charSpan = CharUtils.selectWord(getRowCharacters(document, index), index);
                if (charSpan != null) {
                    textPane.setSelection(charSpan);
                }
            } else if (count == 3) {
                textPane.setSelection(getRowOffset(document, index), getRowLength(document, index));
            }
        }
    }
    return consumed;
}
Also used : TextPane(org.apache.pivot.wtk.TextPane) CharSpan(org.apache.pivot.text.CharSpan) Document(org.apache.pivot.wtk.text.Document)

Example 7 with Document

use of org.apache.pivot.wtk.text.Document in project pivot by apache.

the class HyperlinkButtonTest method startup.

@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
    frame = new Frame();
    frame.setTitle("Hyperlink Button Test");
    frame.setPreferredSize(480, 360);
    HyperlinkButton button1 = new HyperlinkButton("http://pivot.apache.org");
    HyperlinkButton button2 = new HyperlinkButton("Apache website", "http://apache.org");
    TextPane textPane = new TextPane();
    Document document = new Document();
    TextNode text1 = new TextNode("Link to the Apache Pivot site: ");
    TextNode text2 = new TextNode("Main Apache Software Foundation website: ");
    ComponentNode compNode1 = new ComponentNode(button1);
    ComponentNode compNode2 = new ComponentNode(button2);
    Paragraph para1 = new Paragraph();
    para1.add(text1);
    document.add(para1);
    document.add(compNode1);
    Paragraph para2 = new Paragraph();
    para2.add(text2);
    document.add(para2);
    document.add(compNode2);
    ImageNode image1 = new ImageNode("/org/apache/pivot/tests/house.png");
    document.add(image1);
    textPane.setDocument(document);
    frame.setContent(textPane);
    frame.open(display);
}
Also used : Frame(org.apache.pivot.wtk.Frame) HyperlinkButton(org.apache.pivot.wtk.HyperlinkButton) TextPane(org.apache.pivot.wtk.TextPane) TextNode(org.apache.pivot.wtk.text.TextNode) ImageNode(org.apache.pivot.wtk.text.ImageNode) Document(org.apache.pivot.wtk.text.Document) ComponentNode(org.apache.pivot.wtk.text.ComponentNode) Paragraph(org.apache.pivot.wtk.text.Paragraph)

Example 8 with Document

use of org.apache.pivot.wtk.text.Document in project pivot by apache.

the class TextPane method getText.

/**
 * Convenience method to get all the text from the current document into a
 * single string.
 *
 * @return The complete text of the document as a string.
 * @see #setText
 */
public String getText() {
    int count;
    Document doc = getDocument();
    if (doc != null && (count = getCharacterCount()) != 0) {
        StringBuilder text = new StringBuilder(count);
        addToText(text, doc, new Span(0, count - 1));
        return text.toString();
    }
    return null;
}
Also used : Document(org.apache.pivot.wtk.text.Document) CharSpan(org.apache.pivot.text.CharSpan) TextSpan(org.apache.pivot.wtk.text.TextSpan)

Example 9 with Document

use of org.apache.pivot.wtk.text.Document in project pivot by apache.

the class TextPane method setDocument.

/**
 * Sets the document that backs the text pane. Documents are not shareable
 * across multiple TextPanes; because a Document may contain Components, and
 * a Component may only be in one Container at a time.
 *
 * @param document The new document to be displayed by this text pane.
 */
public void setDocument(Document document) {
    Document previousDocument = this.document;
    if (previousDocument != document) {
        if (previousDocument != null) {
            previousDocument.getNodeListeners().remove(documentListener);
            removeComponentNodes(previousDocument);
        }
        if (document != null) {
            document.getNodeListeners().add(documentListener);
            addComponentNodes(document);
        }
        // Clear the edit history
        editHistory.clear();
        this.document = document;
        selectionStart = 0;
        selectionLength = 0;
        textPaneListeners.documentChanged(this, previousDocument);
    }
}
Also used : Document(org.apache.pivot.wtk.text.Document)

Example 10 with Document

use of org.apache.pivot.wtk.text.Document in project pivot by apache.

the class TextPaneSkin method keyTyped.

@Override
public boolean keyTyped(final Component component, char character) {
    boolean consumed = super.keyTyped(component, character);
    final TextPane textPane = getTextPane();
    if (textPane.isEditable()) {
        Document document = textPane.getDocument();
        if (document != null) {
            // character as well as meta key presses
            if (character > 0x1F && character != 0x7F && !Keyboard.isPressed(Keyboard.Modifier.META)) {
                textPane.insert(character);
                showCaret(true);
            }
        }
    }
    return consumed;
}
Also used : TextPane(org.apache.pivot.wtk.TextPane) Document(org.apache.pivot.wtk.text.Document)

Aggregations

Document (org.apache.pivot.wtk.text.Document)11 TextPane (org.apache.pivot.wtk.TextPane)5 CharSpan (org.apache.pivot.text.CharSpan)3 Paragraph (org.apache.pivot.wtk.text.Paragraph)3 ComponentNode (org.apache.pivot.wtk.text.ComponentNode)2 ImageNode (org.apache.pivot.wtk.text.ImageNode)2 TextNode (org.apache.pivot.wtk.text.TextNode)2 TextSpan (org.apache.pivot.wtk.text.TextSpan)2 IOException (java.io.IOException)1 Bounds (org.apache.pivot.wtk.Bounds)1 Frame (org.apache.pivot.wtk.Frame)1 HyperlinkButton (org.apache.pivot.wtk.HyperlinkButton)1 Node (org.apache.pivot.wtk.text.Node)1