Search in sources :

Example 1 with TextArea

use of org.apache.pivot.wtk.TextArea in project pivot by apache.

the class BXMLExplorer method displayLoadException.

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

Example 2 with TextArea

use of org.apache.pivot.wtk.TextArea in project pivot by apache.

the class Pivot841 method startup.

@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() {

        @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);
            paragraph.getParagraphListeners().add(paragraphListener);
        }
    });
    Window window = new Window(textArea);
    window.open(display);
}
Also used : Window(org.apache.pivot.wtk.Window) TextArea(org.apache.pivot.wtk.TextArea) TextAreaContentListener(org.apache.pivot.wtk.TextAreaContentListener) ParagraphListener(org.apache.pivot.wtk.TextArea.ParagraphListener) Paragraph(org.apache.pivot.wtk.TextArea.Paragraph)

Example 3 with TextArea

use of org.apache.pivot.wtk.TextArea in project pivot by apache.

the class TableViewTest2 method startup.

@Override
public void startup(final Display display, final Map<String, String> properties) throws Exception {
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    System.out.println("Double Click on Table elements to open the Row Editor");
    window = (Window) bxmlSerializer.readObject(TableViewTest2.class, "table_view_test2.bxml");
    tableView = (TableView) bxmlSerializer.getNamespace().get("tableView");
    menu = (Window) bxmlSerializer.readObject(TableViewTest2.class, "context_menus.bxml");
    tableView.setMenuHandler(new ContextMenusSampleMenuHandlerAdapter());
    System.out.println("Right  Click on Table elements to display Contextual Menu: " + menu);
    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);
}
Also used : TableViewRowEditor(org.apache.pivot.wtk.content.TableViewRowEditor) TextArea(org.apache.pivot.wtk.TextArea) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 4 with TextArea

use of org.apache.pivot.wtk.TextArea in project pivot by apache.

the class TextAreaSkinParagraphView method paint.

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);
    }
}
Also used : TextArea(org.apache.pivot.wtk.TextArea) Area(java.awt.geom.Area) TextArea(org.apache.pivot.wtk.TextArea) Span(org.apache.pivot.wtk.Span) Graphics2D(java.awt.Graphics2D)

Example 5 with TextArea

use of org.apache.pivot.wtk.TextArea in project pivot by apache.

the class TextAreaSkin method layout.

@SuppressWarnings("unused")
@Override
public void layout() {
    TextArea textArea = (TextArea) getComponent();
    int width = getWidth();
    int breakWidth = (wrapText) ? Math.max(width - margin.getWidth(), 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);
    }
}
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