Search in sources :

Example 6 with TextArea

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());
    }
}
Also used : TextArea(org.apache.pivot.wtk.TextArea)

Example 7 with TextArea

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;
}
Also used : TextArea(org.apache.pivot.wtk.TextArea) Bounds(org.apache.pivot.wtk.Bounds)

Example 8 with TextArea

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;
}
Also used : TextArea(org.apache.pivot.wtk.TextArea)

Example 9 with TextArea

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;
}
Also used : TextArea(org.apache.pivot.wtk.TextArea)

Example 10 with TextArea

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;
}
Also used : TextArea(org.apache.pivot.wtk.TextArea)

Aggregations

TextArea (org.apache.pivot.wtk.TextArea)22 Bounds (org.apache.pivot.wtk.Bounds)5 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)3 Span (org.apache.pivot.wtk.Span)3 Area (java.awt.geom.Area)2 IOException (java.io.IOException)2 ArrayList (org.apache.pivot.collections.ArrayList)2 List (org.apache.pivot.collections.List)2 Sequence (org.apache.pivot.collections.Sequence)2 SerializationException (org.apache.pivot.serialization.SerializationException)2 Button (org.apache.pivot.wtk.Button)2 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)2 Component (org.apache.pivot.wtk.Component)2 ComponentKeyListener (org.apache.pivot.wtk.ComponentKeyListener)2 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)2 ComponentTooltipListener (org.apache.pivot.wtk.ComponentTooltipListener)2 Container (org.apache.pivot.wtk.Container)2 Display (org.apache.pivot.wtk.Display)2 FocusTraversalDirection (org.apache.pivot.wtk.FocusTraversalDirection)2 Keyboard (org.apache.pivot.wtk.Keyboard)2