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;
}
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);
}
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;
}
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);
}
}
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;
}
Aggregations