use of org.apache.pivot.wtk.TextArea in project pivot by apache.
the class TextAreaSkin method paint.
@Override
public void paint(Graphics2D graphics) {
TextArea textArea = (TextArea) getComponent();
int width = getWidth();
int height = getHeight();
// Draw the background
if (backgroundColor != null) {
graphics.setPaint(backgroundColor);
graphics.fillRect(0, 0, width, height);
}
// Draw the caret/selection
if (selection == null) {
if (caretOn && textArea.isFocused()) {
graphics.setColor(textArea.isEditable() ? color : inactiveColor);
graphics.fill(caret);
}
} else {
graphics.setColor(textArea.isFocused() && textArea.isEditable() ? selectionBackgroundColor : inactiveSelectionBackgroundColor);
graphics.fill(selection);
}
// Draw the text
graphics.setFont(font);
graphics.translate(0, margin.top);
int breakWidth = (wrapText) ? Math.max(width - margin.getWidth(), 0) : Integer.MAX_VALUE;
for (int i = 0, n = paragraphViews.getLength(); i < n; i++) {
TextAreaSkinParagraphView paragraphView = paragraphViews.get(i);
paragraphView.setBreakWidth(breakWidth);
paragraphView.validate();
int x = paragraphView.getX();
graphics.translate(x, 0);
paragraphView.paint(graphics);
graphics.translate(-x, 0);
graphics.translate(0, paragraphView.getHeight());
}
}
use of org.apache.pivot.wtk.TextArea in project pivot by apache.
the class TextAreaSkin method getCharacterBounds.
@Override
public Bounds getCharacterBounds(int index) {
Bounds characterBounds = null;
if (paragraphViews.getLength() > 0) {
TextArea textArea = (TextArea) getComponent();
TextAreaSkinParagraphView paragraphView = paragraphViews.get(textArea.getParagraphAt(index));
characterBounds = paragraphView.getCharacterBounds(index - paragraphView.getParagraph().getOffset());
characterBounds = new Bounds(characterBounds.x + paragraphView.getX(), characterBounds.y + paragraphView.getY(), characterBounds.width, characterBounds.height);
}
return characterBounds;
}
use of org.apache.pivot.wtk.TextArea in project pivot by apache.
the class TextAreaSkin method mouseDown.
@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
boolean consumed = super.mouseDown(component, button, x, y);
TextArea textArea = (TextArea) component;
if (button == Mouse.Button.LEFT) {
anchor = getInsertionPoint(x, y);
if (anchor != -1) {
if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)) {
// Select the range
int selectionStart = textArea.getSelectionStart();
if (anchor > selectionStart) {
textArea.setSelection(selectionStart, anchor - selectionStart);
} else {
textArea.setSelection(anchor, selectionStart - anchor);
}
} else {
// Move the caret to the insertion point
textArea.setSelection(anchor, 0);
consumed = true;
}
}
caretX = caret.x;
// Set focus to the text input
textArea.requestFocus();
}
return consumed;
}
use of org.apache.pivot.wtk.TextArea in project pivot by apache.
the class TextAreaSkin method keyTyped.
@Override
public boolean keyTyped(Component component, char character) {
boolean consumed = super.keyTyped(component, character);
if (paragraphViews.getLength() > 0) {
TextArea textArea = (TextArea) getComponent();
if (textArea.isEditable()) {
// character as well as meta key presses
if (character > 0x1F && character != 0x7F && !Keyboard.isPressed(Keyboard.Modifier.META)) {
int selectionLength = textArea.getSelectionLength();
if (textArea.getCharacterCount() - selectionLength + 1 > textArea.getMaximumLength()) {
Toolkit.getDefaultToolkit().beep();
} else {
int selectionStart = textArea.getSelectionStart();
textArea.removeText(selectionStart, selectionLength);
textArea.insertText(Character.toString(character), selectionStart);
}
showCaret(true);
}
}
}
return consumed;
}
use of org.apache.pivot.wtk.TextArea in project pivot by apache.
the class TextAreaSkin method getRowOffset.
@Override
public int getRowOffset(int index) {
int rowOffset = -1;
if (paragraphViews.getLength() > 0) {
TextArea textArea = (TextArea) getComponent();
TextAreaSkinParagraphView paragraphView = paragraphViews.get(textArea.getParagraphAt(index));
rowOffset = paragraphView.getRowOffset(index - paragraphView.getParagraph().getOffset()) + paragraphView.getParagraph().getOffset();
}
return rowOffset;
}
Aggregations