use of org.apache.pivot.wtk.text.ComponentNode in project pivot by apache.
the class TextPane method insertComponent.
public void insertComponent(Component component) {
Utils.checkNull(component, "component");
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 ComponentNode(component));
} 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 ComponentNode(component), index + 1);
}
}
// Set the selection start to the character following the insertion
setSelection(selectionStart + 1, selectionLength);
}
use of org.apache.pivot.wtk.text.ComponentNode in project pivot by apache.
the class TextPaneSkinComponentNodeView method setSkinLocation.
@Override
protected void setSkinLocation(int skinX, int skinY) {
ComponentNode componentNode = (ComponentNode) getNode();
Component component = componentNode.getComponent();
if (component != null) {
// I have to un-translate the x and y coordinates because the
// component is painted by the Container object, and it's
// co-ordinates
// are relative to the Container object, not to the document node
// hierarchy.
component.setLocation(skinX, skinY);
}
}
use of org.apache.pivot.wtk.text.ComponentNode in project pivot by apache.
the class TextPaneSkinComponentNodeView method childLayout.
@Override
protected void childLayout(int breakWidth) {
ComponentNode componentNode = (ComponentNode) getNode();
Component component = componentNode.getComponent();
if (component == null) {
setSize(0, 0);
} else {
component.validate();
component.setSize(component.getPreferredWidth(), component.getPreferredHeight());
setSize(component.getWidth(), component.getHeight());
}
}
use of org.apache.pivot.wtk.text.ComponentNode in project pivot by apache.
the class TextPaneSkinComponentNodeView method getPreferredSize.
@Override
public Dimensions getPreferredSize(int breakWidth) {
ComponentNode componentNode = (ComponentNode) getNode();
Component component = componentNode.getComponent();
if (component == null) {
return new Dimensions(0, 0);
}
return new Dimensions(component.getPreferredWidth(), component.getPreferredHeight());
}
Aggregations