Package org.apache.pivot.wtk

Examples of org.apache.pivot.wtk.TextArea


        @Override
        public void run() {
            caretOn = !caretOn;

            if (selection == null) {
                TextArea textArea = (TextArea) getComponent();
                textArea.repaint(caret.x, caret.y, caret.width, caret.height);
            }
        }
View Full Code Here


    }

    private class ScrollSelectionCallback implements Runnable {
        @Override
        public void run() {
            TextArea textArea = (TextArea)getComponent();
            int selectionStart = textArea.getSelectionStart();
            int selectionLength = textArea.getSelectionLength();
            int selectionEnd = selectionStart + selectionLength - 1;

            switch (scrollDirection) {
                case UP: {
                    // Get previous offset
                    int index = getNextInsertionPoint(mouseX, selectionStart, scrollDirection);

                    if (index != -1) {
                        textArea.setSelection(index, selectionEnd - index + 1);
                        scrollCharacterToVisible(index + 1);
                    }

                    break;
                }

                case DOWN: {
                    // Get next offset
                    int index = getNextInsertionPoint(mouseX, selectionEnd, scrollDirection);

                    if (index != -1) {
                        // If the next character is a paragraph terminator, increment
                        // the selection
                        if (index < textArea.getCharacterCount()
                            && textArea.getCharacterAt(index) == '\n') {
                            index++;
                        }

                        textArea.setSelection(selectionStart, index - selectionStart);
                        scrollCharacterToVisible(index - 1);
                    }

                    break;
                }
View Full Code Here

            invalidate();
        }
    }

    public void paint(Graphics2D graphics) {
        TextArea textArea = (TextArea)textAreaSkin.getComponent();

        int selectionStart = textArea.getSelectionStart();
        int selectionLength = textArea.getSelectionLength();
        Span selectionRange = new Span(selectionStart, selectionStart + selectionLength - 1);

        int paragraphOffset = paragraph.getOffset();
        Span characterRange = new Span(paragraphOffset, paragraphOffset
            + paragraph.getCharacters().length() - 1);

        if (selectionLength > 0
            && characterRange.intersects(selectionRange)) {
            boolean focused = textArea.isFocused();
            boolean editable = textArea.isEditable();

            // Determine the selected and unselected areas
            Area selection = textAreaSkin.getSelection();
            Area selectedArea = selection.createTransformedArea(AffineTransform.getTranslateInstance(-x, -y));
            Area unselectedArea = new Area();
            unselectedArea.add(new Area(new Rectangle2D.Float(0, 0, width, height)));
            unselectedArea.subtract(new Area(selectedArea));

            // Paint the unselected text
            Graphics2D unselectedGraphics = (Graphics2D)graphics.create();
            unselectedGraphics.clip(unselectedArea);
            paint(unselectedGraphics, focused, editable, false);
            unselectedGraphics.dispose();

            // Paint the selected text
            Graphics2D selectedGraphics = (Graphics2D)graphics.create();
            selectedGraphics.clip(selectedArea);
            paint(selectedGraphics, focused, editable, true);
            selectedGraphics.dispose();
        } else {
            paint(graphics, textArea.isFocused(), textArea.isEditable(), false);
        }
    }
View Full Code Here

        TableViewRowEditor tableViewRowEditor = new TableViewRowEditor();
        tableViewRowEditor.setEditEffect(CardPaneSkin.SelectionChangeEffect.HORIZONTAL_SLIDE);
        tableView.setRowEditor(tableViewRowEditor);

        TextArea textArea = new TextArea();
        textArea.setTextKey("value");
        tableViewRowEditor.getCellEditors().put("value", textArea);

        window.open(display);
    }
View Full Code Here

{

    @Override
    public void startup(Display display, Map<String, String> properties) throws Exception
    {
        TextArea textArea = new TextArea();
        textArea.setText("abcxyz");

        final ParagraphListener paragraphListener = new ParagraphListener.Adapter() {
            @Override
            public void textInserted(Paragraph paragraph, int index, int count) {
                System.out.println("Text inserted\n\tparagraph content: '" + paragraph.getCharacters() + "" + "'\n\tindex: " + index + "\n\tcount: " + count);
            }

            @Override
            public void textRemoved(Paragraph paragraph, int index, int count) {
                System.out.println("Text removed\n\tparagraph content: '" + paragraph.getCharacters() + "'\n\tindex: " + index + "\n\tcount: " + count);
            }
        };

        textArea.getParagraphs().get(0).getParagraphListeners().add(paragraphListener);
        textArea.getTextAreaContentListeners().add(new TextAreaContentListener.Adapter() {
            @Override
            public void paragraphInserted(TextArea textAreaArgument, int index)
            {
                Paragraph paragraph = textAreaArgument.getParagraphs().get(index);
                System.out.println("Paragraph inserted\n\tparagraph content: '" + paragraph.getCharacters() + "'\n\tindex: " + index);
View Full Code Here

    }

    static void displayLoadException(Throwable exception, Window window) {
        String message = exception.getClass().getName();

        TextArea body = null;
        String bodyText = exception.getMessage();
        if (bodyText != null
            && bodyText.length() > 0) {
            body = new TextArea();
            body.setText(bodyText);
            body.setEditable(false);
        }

        Alert.alert(MessageType.ERROR, message, null, body, window, null);
    }
View Full Code Here

            invalidate();
        }
    }

    public void paint(Graphics2D graphics) {
        TextArea textArea = (TextArea)textAreaSkin.getComponent();

        int selectionStart = textArea.getSelectionStart();
        int selectionLength = textArea.getSelectionLength();
        Span selectionRange = new Span(selectionStart, selectionStart + selectionLength - 1);

        int paragraphOffset = paragraph.getOffset();
        Span characterRange = new Span(paragraphOffset, paragraphOffset
            + paragraph.getCharacters().length() - 1);

        if (selectionLength > 0
            && characterRange.intersects(selectionRange)) {
            boolean focused = textArea.isFocused();
            boolean editable = textArea.isEditable();

            // Determine the selected and unselected areas
            Area selection = textAreaSkin.getSelection();
            Area selectedArea = selection.createTransformedArea(AffineTransform.getTranslateInstance(-x, -y));
            Area unselectedArea = new Area();
            unselectedArea.add(new Area(new Rectangle2D.Float(0, 0, width, height)));
            unselectedArea.subtract(new Area(selectedArea));

            // Paint the unselected text
            Graphics2D unselectedGraphics = (Graphics2D)graphics.create();
            unselectedGraphics.clip(unselectedArea);
            paint(unselectedGraphics, focused, editable, false);
            unselectedGraphics.dispose();

            // Paint the selected text
            Graphics2D selectedGraphics = (Graphics2D)graphics.create();
            selectedGraphics.clip(selectedArea);
            paint(selectedGraphics, focused, editable, true);
            selectedGraphics.dispose();
        } else {
            paint(graphics, textArea.isFocused(), textArea.isEditable(), false);
        }
    }
View Full Code Here

    @Override
    public void install(Component component) {
        super.install(component);

        TextArea textArea = (TextArea)component;
        textArea.getTextAreaListeners().add(this);
        textArea.getTextAreaContentListeners().add(this);
        textArea.getTextAreaSelectionListeners().add(this);
    }
View Full Code Here

    }

    @SuppressWarnings("unused")
    @Override
    public void layout() {
        TextArea textArea = (TextArea)getComponent();

        int width = getWidth();
        int breakWidth = (wrapText) ? Math.max(width - (margin.left + margin.right), 0)
            : Integer.MAX_VALUE;

        int y = margin.top;
        int lastY = 0;
        int lastHeight = 0;

        int rowOffset = 0;
        int index = 0;
        for (TextAreaSkinParagraphView paragraphView : paragraphViews) {
            paragraphView.setBreakWidth(breakWidth);
            paragraphView.setX(margin.left);
            paragraphView.setY(y);
            lastY = y;
            y += paragraphView.getHeight();
            lastHeight = paragraphView.getHeight();

            paragraphView.setRowOffset(rowOffset);
            rowOffset += paragraphView.getRowCount();
            index++;
        }

        updateSelection();
        caretX = caret.x;

        if (textArea.isFocused()) {
            scrollCharacterToVisible(textArea.getSelectionStart());
            showCaret(textArea.getSelectionLength() == 0);
        } else {
            showCaret(false);
        }
    }
View Full Code Here

        return Math.round(margin.top + lm.getAscent());
    }

    @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);
View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.TextArea

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.