Search in sources :

Example 1 with ImageNode

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

the class TextPaneSkinImageNodeView method getPreferredSize.

@Override
public Dimensions getPreferredSize(int breakWidth) {
    ImageNode imageNode = (ImageNode) getNode();
    Image image = imageNode.getImage();
    if (image == null) {
        return Dimensions.ZERO;
    }
    return image.getSize();
}
Also used : ImageNode(org.apache.pivot.wtk.text.ImageNode) Image(org.apache.pivot.wtk.media.Image)

Example 2 with ImageNode

use of org.apache.pivot.wtk.text.ImageNode 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 3 with ImageNode

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

the class TextPane method insertImage.

public void insertImage(Image image) {
    Utils.checkNull(image, "image");
    checkDocumentExists();
    if (selectionLength > 0) {
        removeDocumentRange(selectionStart, selectionLength);
    }
    // If the insertion is at the end of the document, then just add
    if (selectionStart >= document.getCharacterCount() - 1) {
        document.add(new ImageNode(image));
    } else {
        // Walk up the tree until we find a block
        Node descendant = document.getDescendantAt(selectionStart);
        while (!(descendant instanceof Block)) {
            descendant = descendant.getParent();
        }
        Element parent = descendant.getParent();
        if (parent != null) {
            int index = parent.indexOf(descendant);
            parent.insert(new ImageNode(image), index + 1);
        }
    }
    // Set the selection start to the character following the insertion
    setSelection(selectionStart + 1, selectionLength);
}
Also used : ImageNode(org.apache.pivot.wtk.text.ImageNode) ComponentNode(org.apache.pivot.wtk.text.ComponentNode) Node(org.apache.pivot.wtk.text.Node) TextNode(org.apache.pivot.wtk.text.TextNode) Element(org.apache.pivot.wtk.text.Element) Block(org.apache.pivot.wtk.text.Block) ImageNode(org.apache.pivot.wtk.text.ImageNode)

Example 4 with ImageNode

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

the class TextPaneSkinImageNodeView method attach.

@Override
protected void attach() {
    super.attach();
    ImageNode imageNode = (ImageNode) getNode();
    imageNode.getImageNodeListeners().add(this);
    Image image = imageNode.getImage();
    if (image != null) {
        image.getImageListeners().add(this);
    }
}
Also used : ImageNode(org.apache.pivot.wtk.text.ImageNode) Image(org.apache.pivot.wtk.media.Image)

Example 5 with ImageNode

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

the class TextPaneSkinImageNodeView method getBaseline.

@Override
public int getBaseline() {
    ImageNode imageNode = (ImageNode) getNode();
    Image image = imageNode.getImage();
    int baseline = -1;
    if (image != null) {
        baseline = image.getBaseline();
    }
    return baseline;
}
Also used : ImageNode(org.apache.pivot.wtk.text.ImageNode) Image(org.apache.pivot.wtk.media.Image)

Aggregations

ImageNode (org.apache.pivot.wtk.text.ImageNode)8 Image (org.apache.pivot.wtk.media.Image)5 ComponentNode (org.apache.pivot.wtk.text.ComponentNode)2 TextNode (org.apache.pivot.wtk.text.TextNode)2 Frame (org.apache.pivot.wtk.Frame)1 HyperlinkButton (org.apache.pivot.wtk.HyperlinkButton)1 TextPane (org.apache.pivot.wtk.TextPane)1 Block (org.apache.pivot.wtk.text.Block)1 Document (org.apache.pivot.wtk.text.Document)1 Element (org.apache.pivot.wtk.text.Element)1 Node (org.apache.pivot.wtk.text.Node)1 Paragraph (org.apache.pivot.wtk.text.Paragraph)1