Skip to content

Commit

Permalink
Code cleanup: this should eventually go into a JIRA issue...
Browse files Browse the repository at this point in the history
Small changes to allow ComponentNode and ImageNode to actually work inside
a TextPane.  Not sure of the reasons, but it was very difficult to get this
to work without turning both into subclasses of Block instead of Node.

Now, at least, one can insert either straight into a Document and then into
a TextPane and they will work.  Update the HyperlinkButtonTest program to
illustrate this.


git-svn-id: https://svn.apache.org/repos/asf/pivot/trunk@1694754 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Roger Lee Whitcomb committed Aug 8, 2015
1 parent cf983c4 commit 369622e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
28 changes: 24 additions & 4 deletions tests/src/org/apache/pivot/tests/HyperlinkButtonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
import org.apache.pivot.wtk.Frame;
import org.apache.pivot.wtk.Orientation;
import org.apache.pivot.wtk.HyperlinkButton;
import org.apache.pivot.wtk.TextPane;
import org.apache.pivot.wtk.text.ComponentNode;
import org.apache.pivot.wtk.text.Document;
import org.apache.pivot.wtk.text.ImageNode;
import org.apache.pivot.wtk.text.Paragraph;
import org.apache.pivot.wtk.text.TextNode;


public class HyperlinkButtonTest extends Application.Adapter {
Expand All @@ -37,11 +43,25 @@ public void startup(Display display, Map<String, String> properties) throws Exce

HyperlinkButton button1 = new HyperlinkButton("http://pivot.apache.org");
HyperlinkButton button2 = new HyperlinkButton("Apache website", "http://apache.org");
BoxPane bp = new BoxPane(Orientation.VERTICAL);
bp.add(button1);
bp.add(button2);
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(bp);
frame.setContent(textPane);

frame.open(display);
}
Expand Down
6 changes: 3 additions & 3 deletions wtk/src/org/apache/pivot/wtk/text/ComponentNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* Node representing a live pivot component.
*/
public class ComponentNode extends Node {
public class ComponentNode extends Block {

private static class ComponentNodeListenerList extends ListenerList<ComponentNodeListener>
implements ComponentNodeListener {
Expand Down Expand Up @@ -83,7 +83,7 @@ public Node removeRange(int offset, int span) {
}

@Override
public Node getRange(int offset, int characterCount) {
public Element getRange(int offset, int characterCount) {
if (offset < 0 || offset > 1) {
throw new IndexOutOfBoundsException();
}
Expand All @@ -96,7 +96,7 @@ public Node getRange(int offset, int characterCount) {
}

@Override
public Node duplicate(boolean recursive) {
public Element duplicate(boolean recursive) {
return new ComponentNode(this);
}

Expand Down
6 changes: 3 additions & 3 deletions wtk/src/org/apache/pivot/wtk/text/ImageNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* Node representing an image.
*/
public class ImageNode extends Node {
public class ImageNode extends Block {
private static class ImageNodeListenerList extends ListenerList<ImageNodeListener> implements
ImageNodeListener {
@Override
Expand Down Expand Up @@ -128,7 +128,7 @@ public Node removeRange(int offset, int span) {
}

@Override
public Node getRange(int offset, int characterCount) {
public Element getRange(int offset, int characterCount) {
if (offset < 0 || offset > 1) {
throw new IndexOutOfBoundsException();
}
Expand All @@ -141,7 +141,7 @@ public Node getRange(int offset, int characterCount) {
}

@Override
public Node duplicate(boolean recursive) {
public Element duplicate(boolean recursive) {
return new ImageNode(this);
}

Expand Down

0 comments on commit 369622e

Please sign in to comment.