Search in sources :

Example 6 with TextArea

use of com.codename1.ui.TextArea in project CodenameOne by codenameone.

the class DefaultLookAndFeel method drawTextField.

/**
 * {@inheritDoc}
 */
public void drawTextField(Graphics g, TextArea ta) {
    setFG(g, ta);
    // display ******** if it is a password field
    String displayText = getTextFieldString(ta);
    Style style = ta.getStyle();
    int x = 0;
    // ta.getCursorX();
    int cursorCharPosition = ta.getCursorPosition();
    Font f = style.getFont();
    int cursorX = 0;
    int xPos = 0;
    int align = reverseAlignForBidi(ta);
    int displayX = 0;
    String inputMode = ta.getInputMode();
    int inputModeWidth = f.stringWidth(inputMode);
    // QWERTY devices don't quite have an input mode hide it also when we have a VK
    if (ta.isQwertyInput() || Display.getInstance().isVirtualKeyboardShowing()) {
        inputMode = "";
        inputModeWidth = 0;
    }
    if (ta.isSingleLineTextArea()) {
        // there is currently no support for CENTER aligned text fields
        if (align == Component.LEFT) {
            if (cursorCharPosition > 0) {
                cursorCharPosition = Math.min(displayText.length(), cursorCharPosition);
                xPos = f.stringWidth(displayText.substring(0, cursorCharPosition));
                cursorX = ta.getX() + style.getPaddingLeft(ta.isRTL()) + xPos;
                // no point in showing the input mode when there is only one input mode...
                if (inputModeWidth > 0 && ta.getInputModeOrder() != null && ta.getInputModeOrder().length == 1) {
                    inputModeWidth = 0;
                }
                if (ta.isEnableInputScroll()) {
                    if (ta.getWidth() > (f.getHeight() * 2) && cursorX >= ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL())) {
                        if (x + xPos >= ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL()) * 2) {
                            x = ta.getWidth() - inputModeWidth - style.getPaddingLeft(ta.isRTL()) * 2 - xPos - 1;
                        }
                    }
                }
            }
            displayX = ta.getX() + x + style.getPaddingLeft(ta.isRTL());
        } else {
            x = 0;
            cursorX = getTextFieldCursorX(ta);
            int baseX = ta.getX() + style.getPaddingLeftNoRTL() + inputModeWidth;
            int endX = ta.getX() + ta.getWidth() - style.getPaddingRightNoRTL();
            if (cursorX < baseX) {
                x = baseX - cursorX;
            } else {
                if (cursorX > endX) {
                    x = endX - cursorX;
                }
            }
            displayX = ta.getX() + ta.getWidth() - style.getPaddingRightNoRTL() - style.getPaddingLeftNoRTL() - f.stringWidth(displayText) + x;
        }
        int cx = g.getClipX();
        int cy = g.getClipY();
        int cw = g.getClipWidth();
        int ch = g.getClipHeight();
        int clipx = ta.getX() + style.getPaddingLeft(ta.isRTL());
        int clipw = ta.getWidth() - style.getPaddingLeft(ta.isRTL()) - style.getPaddingRight(ta.isRTL());
        // g.pushClip();
        g.clipRect(clipx, cy, clipw, ch);
        switch(ta.getVerticalAlignment()) {
            case Component.BOTTOM:
                g.drawString(displayText, displayX, ta.getY() + ta.getHeight() - style.getPaddingBottom() - f.getHeight(), style.getTextDecoration());
                break;
            case Component.CENTER:
                g.drawString(displayText, displayX, ta.getY() + ta.getHeight() / 2 - f.getHeight() / 2, style.getTextDecoration());
                break;
            default:
                g.drawString(displayText, displayX, ta.getY() + style.getPaddingTop(), style.getTextDecoration());
                break;
        }
        g.setClip(cx, cy, cw, ch);
    // g.popClip();
    } else {
        drawTextArea(g, ta);
    }
    // no point in showing the input mode when there is only one input mode...
    if (inputModeWidth > 0 && ta.getInputModeOrder() != null && ta.getInputModeOrder().length > 1) {
        if (ta.handlesInput() && ta.getWidth() / 2 > inputModeWidth) {
            int drawXPos = ta.getX() + style.getPaddingLeft(ta.isRTL());
            if ((!ta.isRTL() && style.getAlignment() == Component.LEFT) || (ta.isRTL() && style.getAlignment() == Component.RIGHT)) {
                drawXPos = drawXPos + ta.getWidth() - inputModeWidth - style.getPaddingRightNoRTL() - style.getPaddingLeftNoRTL();
            }
            g.setColor(style.getFgColor());
            int inputIndicatorY = ta.getY() + ta.getScrollY() + ta.getHeight() - style.getPaddingBottom() - f.getHeight();
            g.fillRect(drawXPos, inputIndicatorY, inputModeWidth, f.getHeight(), (byte) 140);
            g.setColor(style.getBgColor());
            g.drawString(inputMode, drawXPos, inputIndicatorY);
        }
    }
}
Also used : Font(com.codename1.ui.Font)

Example 7 with TextArea

use of com.codename1.ui.TextArea in project CodenameOne by codenameone.

the class MigLayout method checkCache.

/**
 * Check if something has changed and if so recreate it to the cached
 * objects.
 *
 * @param parent The parent that is the target for this layout manager.
 */
private void checkCache(Container parent) {
    if (parent == null) {
        return;
    }
    if (dirty) {
        grid = null;
    }
    cleanConstraintMaps(parent);
    // Check if the grid is valid
    int mc = PlatformDefaults.getModCount();
    if (lastModCount != mc) {
        grid = null;
        lastModCount = mc;
    }
    // if (!parent.isValid()) {
    if (!lastWasInvalid) {
        lastWasInvalid = true;
        int hash = 0;
        // Added in 3.7.3 to resolve a timing regression introduced in 3.7.1
        boolean resetLastInvalidOnParent = false;
        for (ComponentWrapper wrapper : ccMap.keySet()) {
            Object component = wrapper.getComponent();
            if (component instanceof TextArea) {
                resetLastInvalidOnParent = true;
            }
            hash ^= wrapper.getLayoutHashCode();
            hash += 285134905;
        }
        if (resetLastInvalidOnParent) {
            resetLastInvalidOnParent(parent);
        }
        if (hash != lastHash) {
            grid = null;
            lastHash = hash;
        }
        Dimension ps = new Dimension(parent.getWidth(), parent.getHeight());
        if (lastInvalidSize == null || !lastInvalidSize.equals(ps)) {
            grid = null;
            lastInvalidSize = ps;
        }
    }
    /*} else {
         lastWasInvalid = false;
         }*/
    ContainerWrapper par = checkParent(parent);
    setDebug(par, getDebugMillis() > 0);
    if (grid == null) {
        grid = new Grid(par, lc, rowSpecs, colSpecs, ccMap, callbackList);
    }
    dirty = false;
}
Also used : TextArea(com.codename1.ui.TextArea) Grid(com.codename1.ui.layouts.mig.Grid) Dimension(com.codename1.ui.geom.Dimension) ContainerWrapper(com.codename1.ui.layouts.mig.ContainerWrapper) ComponentWrapper(com.codename1.ui.layouts.mig.ComponentWrapper)

Example 8 with TextArea

use of com.codename1.ui.TextArea in project CodenameOne by codenameone.

the class Table method createCellImpl.

private Component createCellImpl(Object value, final int row, final int column, boolean editable) {
    Component c = createCell(value, row, column, editable);
    c.putClientProperty("row", new Integer(row));
    c.putClientProperty("column", new Integer(column));
    // we do this here to allow subclasses to return a text area or its subclass
    if (c instanceof TextArea) {
        ((TextArea) c).addActionListener(listener);
    }
    Style s = c.getSelectedStyle();
    // s.setMargin(0, 0, 0, 0);
    s.setMargin(verticalBorderSpacing, verticalBorderSpacing, horizontalBorderSpacing, horizontalBorderSpacing);
    if ((drawBorder) && (innerBorder != INNER_BORDERS_NONE)) {
        s.setBorder(null);
        s = c.getUnselectedStyle();
        s.setBorder(null);
    } else {
        s = c.getUnselectedStyle();
    }
    // s.setBgTransparency(0);
    // s.setMargin(0, 0, 0, 0);
    s.setMargin(verticalBorderSpacing, verticalBorderSpacing, horizontalBorderSpacing, horizontalBorderSpacing);
    return c;
}
Also used : TextArea(com.codename1.ui.TextArea) Style(com.codename1.ui.plaf.Style) Component(com.codename1.ui.Component)

Example 9 with TextArea

use of com.codename1.ui.TextArea in project CodenameOne by codenameone.

the class UIBuilderOverride method createInstance.

/**
 * Create a component instance from XML
 */
private Component createInstance(final ComponentEntry root, final EditableResources res, Container rootCnt, final Container parentContainer, final ArrayList<Runnable> postCreateTasks) {
    try {
        final Component c = createComponentType(root.getType());
        if (rootCnt == null) {
            rootCnt = (Container) c;
        }
        final Container rootContainer = rootCnt;
        if (root.getBaseForm() != null) {
            c.putClientProperty("%base_form%", root.getBaseForm());
        }
        c.putClientProperty(TYPE_KEY, root.getType());
        c.setName(root.getName());
        String clientProps = root.getClientProperties();
        if (clientProps != null && clientProps.length() > 0) {
            String[] props = clientProps.split(",");
            StringBuilder b = new StringBuilder();
            for (String p : props) {
                String[] keyVal = p.split("=");
                c.putClientProperty(keyVal[0], keyVal[1]);
                if (b.length() > 0) {
                    b.append(",");
                }
                b.append(keyVal[0]);
            }
            c.putClientProperty("cn1$Properties", b.toString());
        }
        rootContainer.putClientProperty("%" + root.getName() + "%", c);
        // layout must be first since we might need to rely on it later on with things such as constraints
        if (root.getLayout() != null) {
            modifyingProperty(c, PROPERTY_LAYOUT);
            Layout l;
            if (root.getLayout().equals("BorderLayout")) {
                l = new BorderLayout();
                if (root.isBorderLayoutAbsoluteCenter() != null) {
                    ((BorderLayout) l).setAbsoluteCenter(root.isBorderLayoutAbsoluteCenter().booleanValue());
                }
                if (root.getBorderLayoutSwapCenter() != null) {
                    ((BorderLayout) l).defineLandscapeSwap(BorderLayout.CENTER, root.getBorderLayoutSwapCenter());
                }
                if (root.getBorderLayoutSwapNorth() != null) {
                    ((BorderLayout) l).defineLandscapeSwap(BorderLayout.NORTH, root.getBorderLayoutSwapNorth());
                }
                if (root.getBorderLayoutSwapSouth() != null) {
                    ((BorderLayout) l).defineLandscapeSwap(BorderLayout.SOUTH, root.getBorderLayoutSwapSouth());
                }
                if (root.getBorderLayoutSwapEast() != null) {
                    ((BorderLayout) l).defineLandscapeSwap(BorderLayout.EAST, root.getBorderLayoutSwapEast());
                }
                if (root.getBorderLayoutSwapWest() != null) {
                    ((BorderLayout) l).defineLandscapeSwap(BorderLayout.WEST, root.getBorderLayoutSwapWest());
                }
            } else {
                if (root.getLayout().equals("FlowLayout")) {
                    l = new FlowLayout();
                    ((FlowLayout) l).setFillRows(root.isFlowLayoutFillRows());
                    ((FlowLayout) l).setAlign(root.getFlowLayoutAlign());
                    ((FlowLayout) l).setValign(root.getFlowLayoutValign());
                } else {
                    if (root.getLayout().equals("GridLayout")) {
                        l = new GridLayout(root.getGridLayoutRows().intValue(), root.getGridLayoutColumns().intValue());
                    } else {
                        if (root.getLayout().equals("BoxLayout")) {
                            if (root.getBoxLayoutAxis().equals("X")) {
                                l = new BoxLayout(BoxLayout.X_AXIS);
                            } else {
                                l = new BoxLayout(BoxLayout.Y_AXIS);
                            }
                        } else {
                            if (root.getLayout().equals("TableLayout")) {
                                l = new TableLayout(root.getTableLayoutRows(), root.getTableLayoutColumns());
                            } else {
                                l = new LayeredLayout();
                            }
                        }
                    }
                }
            }
            ((Container) c).setLayout(l);
        }
        if (parentContainer != null && root.getLayoutConstraint() != null) {
            modifyingProperty(c, PROPERTY_LAYOUT_CONSTRAINT);
            if (parentContainer.getLayout() instanceof BorderLayout) {
                c.putClientProperty("layoutConstraint", root.getLayoutConstraint().getValue());
            } else {
                TableLayout tl = (TableLayout) parentContainer.getLayout();
                TableLayout.Constraint con = tl.createConstraint(root.getLayoutConstraint().getRow(), root.getLayoutConstraint().getColumn());
                con.setHeightPercentage(root.getLayoutConstraint().getHeight());
                con.setWidthPercentage(root.getLayoutConstraint().getWidth());
                con.setHorizontalAlign(root.getLayoutConstraint().getAlign());
                con.setHorizontalSpan(root.getLayoutConstraint().getSpanHorizontal());
                con.setVerticalAlign(root.getLayoutConstraint().getValign());
                con.setVerticalSpan(root.getLayoutConstraint().getSpanVertical());
                c.putClientProperty("layoutConstraint", con);
            }
        }
        if (root.getEmbed() != null && root.getEmbed().length() > 0) {
            modifyingProperty(c, PROPERTY_EMBED);
            rootContainer.putClientProperty(EMBEDDED_FORM_FLAG, "");
            ((EmbeddedContainer) c).setEmbed(root.getEmbed());
            Container embed = createContainer(res, root.getEmbed(), (EmbeddedContainer) c);
            if (embed != null) {
                if (embed instanceof Form) {
                    embed = formToContainer((Form) embed);
                }
                ((EmbeddedContainer) c).addComponent(BorderLayout.CENTER, embed);
                // this isn't exactly the "right thing" but its the best we can do to make all
                // use cases work
                beforeShowContainer(embed);
                postShowContainer(embed);
            }
        }
        if (root.isToggle() != null) {
            modifyingProperty(c, PROPERTY_TOGGLE_BUTTON);
            ((Button) c).setToggle(root.isToggle().booleanValue());
        }
        if (root.getGroup() != null) {
            modifyingProperty(c, PROPERTY_RADIO_GROUP);
            ((RadioButton) c).setGroup(root.getGroup());
        }
        if (root.isSelected() != null) {
            modifyingProperty(c, PROPERTY_SELECTED);
            if (c instanceof RadioButton) {
                ((RadioButton) c).setSelected(root.isSelected().booleanValue());
            } else {
                ((CheckBox) c).setSelected(root.isSelected().booleanValue());
            }
        }
        if (root.isScrollableX() != null) {
            modifyingProperty(c, PROPERTY_SCROLLABLE_X);
            ((Container) c).setScrollableX(root.isScrollableX().booleanValue());
        }
        if (root.isScrollableY() != null) {
            modifyingProperty(c, PROPERTY_SCROLLABLE_Y);
            ((Container) c).setScrollableY(root.isScrollableY().booleanValue());
        }
        if (root.isTensileDragEnabled() != null) {
            modifyingProperty(c, PROPERTY_TENSILE_DRAG_ENABLED);
            c.setTensileDragEnabled(root.isTensileDragEnabled().booleanValue());
        }
        if (root.isTactileTouch() != null) {
            modifyingProperty(c, PROPERTY_TACTILE_TOUCH);
            c.setTactileTouch(root.isTactileTouch().booleanValue());
        }
        if (root.isSnapToGrid() != null) {
            modifyingProperty(c, PROPERTY_SNAP_TO_GRID);
            c.setSnapToGrid(root.isSnapToGrid().booleanValue());
        }
        if (root.isFlatten() != null) {
            modifyingProperty(c, PROPERTY_FLATTEN);
            c.setFlatten(root.isFlatten().booleanValue());
        }
        if (root.getText() != null) {
            modifyingProperty(c, PROPERTY_TEXT);
            if (c instanceof Label) {
                ((Label) c).setText(root.getText());
            } else {
                ((TextArea) c).setText(root.getText());
            }
        }
        if (root.getMaxSize() != null) {
            modifyingProperty(c, PROPERTY_TEXT_MAX_LENGTH);
            ((TextArea) c).setMaxSize(root.getMaxSize().intValue());
        }
        if (root.getConstraint() != null) {
            modifyingProperty(c, PROPERTY_TEXT_CONSTRAINT);
            ((TextArea) c).setConstraint(root.getConstraint().intValue());
        }
        if (root.getAlignment() != null) {
            modifyingProperty(c, PROPERTY_ALIGNMENT);
            if (c instanceof Label) {
                ((Label) c).setAlignment(root.getAlignment().intValue());
            } else {
                ((TextArea) c).setAlignment(root.getAlignment().intValue());
            }
        }
        if (root.isGrowByContent() != null) {
            modifyingProperty(c, PROPERTY_TEXT_AREA_GROW);
            ((TextArea) c).setGrowByContent(root.isGrowByContent().booleanValue());
        }
        if (root.getTabPlacement() != null) {
            modifyingProperty(c, PROPERTY_TAB_PLACEMENT);
            ((Tabs) c).setTabPlacement(root.getTabPlacement().intValue());
        }
        if (root.getTabTextPosition() != null) {
            modifyingProperty(c, PROPERTY_TAB_TEXT_POSITION);
            ((Tabs) c).setTabTextPosition(root.getTabTextPosition().intValue());
        }
        if (root.getUiid() != null) {
            modifyingProperty(c, PROPERTY_UIID);
            c.setUIID(root.getUiid());
        }
        if (root.getDialogUIID() != null) {
            modifyingProperty(c, PROPERTY_DIALOG_UIID);
            ((Dialog) c).setDialogUIID(root.getDialogUIID());
        }
        if (root.isDisposeWhenPointerOutOfBounds() != null) {
            modifyingProperty(c, PROPERTY_DISPOSE_WHEN_POINTER_OUT);
            ((Dialog) c).setDisposeWhenPointerOutOfBounds(root.isDisposeWhenPointerOutOfBounds());
        }
        if (root.getCloudBoundProperty() != null) {
            modifyingProperty(c, PROPERTY_CLOUD_BOUND_PROPERTY);
            c.setCloudBoundProperty(root.getCloudBoundProperty());
        }
        if (root.getCloudDestinationProperty() != null) {
            modifyingProperty(c, PROPERTY_CLOUD_DESTINATION_PROPERTY);
            c.setCloudDestinationProperty(root.getCloudDestinationProperty());
        }
        if (root.getDialogPosition() != null && root.getDialogPosition().length() > 0) {
            modifyingProperty(c, PROPERTY_DIALOG_POSITION);
            ((Dialog) c).setDialogPosition(root.getDialogPosition());
        }
        if (root.isFocusable() != null) {
            modifyingProperty(c, PROPERTY_FOCUSABLE);
            c.setFocusable(root.isFocusable().booleanValue());
        }
        if (root.isEnabled() != null) {
            modifyingProperty(c, PROPERTY_ENABLED);
            c.setEnabled(root.isEnabled().booleanValue());
        }
        if (root.isScrollVisible() != null) {
            modifyingProperty(c, PROPERTY_SCROLL_VISIBLE);
            c.setScrollVisible(root.isScrollVisible().booleanValue());
        }
        if (root.getIcon() != null) {
            modifyingProperty(c, PROPERTY_ICON);
            ((Label) c).setIcon(res.getImage(root.getIcon()));
        }
        if (root.getRolloverIcon() != null) {
            modifyingProperty(c, PROPERTY_ROLLOVER_ICON);
            ((Button) c).setRolloverIcon(res.getImage(root.getRolloverIcon()));
        }
        if (root.getPressedIcon() != null) {
            modifyingProperty(c, PROPERTY_PRESSED_ICON);
            ((Button) c).setPressedIcon(res.getImage(root.getPressedIcon()));
        }
        if (root.getDisabledIcon() != null) {
            modifyingProperty(c, PROPERTY_DISABLED_ICON);
            ((Button) c).setDisabledIcon(res.getImage(root.getDisabledIcon()));
        }
        if (root.getGap() != null) {
            modifyingProperty(c, PROPERTY_GAP);
            ((Label) c).setGap(root.getGap().intValue());
        }
        if (root.getVerticalAlignment() != null) {
            modifyingProperty(c, PROPERTY_VERTICAL_ALIGNMENT);
            if (c instanceof Label) {
                ((Label) c).setVerticalAlignment(root.getVerticalAlignment().intValue());
            } else {
                ((TextArea) c).setVerticalAlignment(root.getVerticalAlignment().intValue());
            }
        }
        if (root.getTextPosition() != null) {
            modifyingProperty(c, PROPERTY_TEXT_POSITION);
            ((Label) c).setTextPosition(root.getTextPosition().intValue());
        }
        if (root.getTitle() != null) {
            modifyingProperty(c, PROPERTY_TITLE);
            ((Form) c).setTitle(root.getTitle());
        }
        // components should be added when we've set everything else up
        if (root.getComponent() != null) {
            modifyingProperty(c, PROPERTY_COMPONENTS);
            if (c instanceof Tabs) {
                for (ComponentEntry ent : root.getComponent()) {
                    Component newCmp = createInstance(ent, res, rootContainer, (Container) c, postCreateTasks);
                    ((Tabs) c).addTab(ent.getTabTitle(), newCmp);
                }
            } else {
                for (ComponentEntry ent : root.getComponent()) {
                    Component newCmp = createInstance(ent, res, rootContainer, (Container) c, postCreateTasks);
                    Object cons = newCmp.getClientProperty("layoutConstraint");
                    if (cons != null) {
                        modifyingProperty(c, PROPERTY_LAYOUT_CONSTRAINT);
                        ((Container) c).addComponent(cons, newCmp);
                    } else {
                        ((Container) c).addComponent(newCmp);
                    }
                }
            }
        }
        if (root.getColumns() != null) {
            modifyingProperty(c, PROPERTY_COLUMNS);
            ((TextArea) c).setColumns(root.getColumns().intValue());
        }
        if (root.getRows() != null) {
            modifyingProperty(c, PROPERTY_ROWS);
            ((TextArea) c).setRows(root.getRows().intValue());
        }
        if (root.getHint() != null) {
            modifyingProperty(c, PROPERTY_HINT);
            if (c instanceof List) {
                ((List) c).setHint(root.getHint());
            } else {
                ((TextArea) c).setHint(root.getHint());
            }
        }
        if (root.getHintIcon() != null) {
            modifyingProperty(c, PROPERTY_HINT_ICON);
            if (c instanceof List) {
                ((List) c).setHintIcon(res.getImage(root.getHint()));
            } else {
                ((TextArea) c).setHintIcon(res.getImage(root.getHint()));
            }
        }
        if (root.getItemGap() != null) {
            modifyingProperty(c, PROPERTY_ITEM_GAP);
            ((List) c).setItemGap(root.getItemGap().intValue());
        }
        if (root.getFixedSelection() != null) {
            modifyingProperty(c, PROPERTY_LIST_FIXED);
            ((List) c).setFixedSelection(root.getFixedSelection().intValue());
        }
        if (root.getOrientation() != null) {
            modifyingProperty(c, PROPERTY_LIST_ORIENTATION);
            ((List) c).setOrientation(root.getOrientation().intValue());
        }
        if (c instanceof com.codename1.ui.List && !(c instanceof com.codename1.components.RSSReader)) {
            modifyingProperty(c, PROPERTY_LIST_ITEMS);
            if (root.getStringItem() != null && root.getStringItem().length > 0) {
                String[] arr = new String[root.getStringItem().length];
                for (int iter = 0; iter < arr.length; iter++) {
                    arr[iter] = root.getStringItem()[iter].getValue();
                }
                ((List) c).setModel(new DefaultListModel<String>(arr));
            } else {
                if (root.getMapItems() != null && root.getMapItems().length > 0) {
                    Hashtable[] arr = new Hashtable[root.getMapItems().length];
                    for (int iter = 0; iter < arr.length; iter++) {
                        arr[iter] = new Hashtable();
                        if (root.getMapItems()[iter].getActionItem() != null) {
                            for (Val v : root.getMapItems()[iter].getActionItem()) {
                                Command cmd = createCommandImpl((String) v.getValue(), null, -1, v.getValue(), false, "");
                                cmd.putClientProperty(COMMAND_ACTION, (String) v.getValue());
                                arr[iter].put(v.getKey(), cmd);
                            }
                        }
                        if (root.getMapItems()[iter].getStringItem() != null) {
                            for (Val v : root.getMapItems()[iter].getActionItem()) {
                                arr[iter].put(v.getKey(), v.getValue());
                            }
                        }
                        if (root.getMapItems()[iter].getImageItem() != null) {
                            for (Val v : root.getMapItems()[iter].getActionItem()) {
                                arr[iter].put(v.getKey(), res.getImage(v.getValue()));
                            }
                        }
                    }
                    ((List) c).setModel(new DefaultListModel<java.util.Map>(arr));
                }
            }
        }
        if (root.getSelectedRenderer() != null) {
            modifyingProperty(c, PROPERTY_LIST_RENDERER);
            GenericListCellRenderer g;
            if (root.getSelectedRendererEven() == null) {
                Component selected = createContainer(res, root.getSelectedRenderer());
                Component unselected = createContainer(res, root.getUnselectedRenderer());
                g = new GenericListCellRenderer(selected, unselected);
                g.setFisheye(!root.getSelectedRenderer().equals(root.getUnselectedRenderer()));
            } else {
                Component selected = createContainer(res, root.getSelectedRenderer());
                Component unselected = createContainer(res, root.getUnselectedRenderer());
                Component even = createContainer(res, root.getSelectedRendererEven());
                Component evenU = createContainer(res, root.getUnselectedRendererEven());
                g = new GenericListCellRenderer(selected, unselected, even, evenU);
                g.setFisheye(!root.getSelectedRenderer().equals(root.getUnselectedRenderer()));
            }
            if (c instanceof ContainerList) {
                ((ContainerList) c).setRenderer(g);
            } else {
                ((List) c).setRenderer(g);
            }
        }
        if (root.getNextForm() != null && root.getNextForm().length() > 0) {
            modifyingProperty(c, PROPERTY_NEXT_FORM);
            setNextForm(c, root.getNextForm(), res, rootContainer);
        }
        if (root.getCommand() != null) {
            modifyingProperty(c, PROPERTY_COMMANDS);
            for (CommandEntry cmd : root.getCommand()) {
                Command currentCommand = createCommandImpl(cmd.getName(), res.getImage(cmd.getIcon()), cmd.getId(), cmd.getAction(), cmd.isBackCommand(), cmd.getArgument());
                if (cmd.getRolloverIcon() != null && cmd.getRolloverIcon().length() > 0) {
                    currentCommand.setRolloverIcon(res.getImage(cmd.getRolloverIcon()));
                }
                if (cmd.getPressedIcon() != null && cmd.getPressedIcon().length() > 0) {
                    currentCommand.setPressedIcon(res.getImage(cmd.getPressedIcon()));
                }
                if (cmd.getDisabledIcon() != null && cmd.getDisabledIcon().length() > 0) {
                    currentCommand.setDisabledIcon(res.getImage(cmd.getDisabledIcon()));
                }
                if (cmd.isBackCommand()) {
                    ((Form) c).setBackCommand(currentCommand);
                }
                ((Form) c).addCommand(currentCommand);
                currentCommand.putClientProperty(COMMAND_ARGUMENTS, cmd.getArgument());
                currentCommand.putClientProperty(COMMAND_ACTION, cmd.getAction());
            }
        }
        if (root.isCyclicFocus() != null) {
            modifyingProperty(c, PROPERTY_CYCLIC_FOCUS);
            ((Form) c).setCyclicFocus(root.isCyclicFocus().booleanValue());
        }
        if (root.isRtl() != null) {
            modifyingProperty(c, PROPERTY_RTL);
            c.setRTL(root.isRtl().booleanValue());
        }
        if (root.getThumbImage() != null) {
            modifyingProperty(c, PROPERTY_SLIDER_THUMB);
            ((Slider) c).setThumbImage(res.getImage(root.getThumbImage()));
        }
        if (root.isInfinite() != null) {
            modifyingProperty(c, PROPERTY_INFINITE);
            ((Slider) c).setInfinite(root.isInfinite().booleanValue());
        }
        if (root.getProgress() != null) {
            modifyingProperty(c, PROPERTY_PROGRESS);
            ((Slider) c).setProgress(root.getProgress().intValue());
        }
        if (root.isVertical() != null) {
            modifyingProperty(c, PROPERTY_VERTICAL);
            ((Slider) c).setVertical(root.isVertical().booleanValue());
        }
        if (root.isEditable() != null) {
            modifyingProperty(c, PROPERTY_EDITABLE);
            if (c instanceof TextArea) {
                ((TextArea) c).setEditable(root.isEditable().booleanValue());
            } else {
                ((Slider) c).setEditable(root.isEditable().booleanValue());
            }
        }
        if (root.getIncrements() != null) {
            modifyingProperty(c, PROPERTY_INCREMENTS);
            ((Slider) c).setIncrements(root.getIncrements().intValue());
        }
        if (root.isRenderPercentageOnTop() != null) {
            modifyingProperty(c, PROPERTY_RENDER_PERCENTAGE_ON_TOP);
            ((Slider) c).setRenderPercentageOnTop(root.isRenderPercentageOnTop().booleanValue());
        }
        if (root.getMaxValue() != null) {
            modifyingProperty(c, PROPERTY_MAX_VALUE);
            ((Slider) c).setMaxValue(root.getMaxValue().intValue());
        }
        if (root.getMinValue() != null) {
            modifyingProperty(c, PROPERTY_MIN_VALUE);
            ((Slider) c).setMinValue(root.getMinValue().intValue());
        }
        if (root.getCommandName() != null) {
            modifyingProperty(c, PROPERTY_COMMAND);
            postCreateTasks.add(new Runnable() {

                public void run() {
                    Command cmd = createCommandImpl(root.getCommandName(), res.getImage(root.getCommandIcon()), root.getCommandId().intValue(), root.getCommandAction(), root.isCommandBack().booleanValue(), root.getCommandArgument());
                    if (c instanceof Container) {
                        Button b = (Button) ((Container) c).getLeadComponent();
                        b.setCommand(cmd);
                        return;
                    }
                    ((Button) c).setCommand(cmd);
                }
            });
        }
        if (root.getLabelFor() != null) {
            modifyingProperty(c, PROPERTY_LABEL_FOR);
            postCreateTasks.add(new Runnable() {

                public void run() {
                    ((Label) c).setLabelForComponent((Label) findByName(root.getLabelFor(), rootContainer));
                }
            });
        }
        if (root.getLeadComponent() != null) {
            modifyingProperty(c, PROPERTY_LEAD_COMPONENT);
            postCreateTasks.add(new Runnable() {

                public void run() {
                    ((Container) c).setLeadComponent(findByName(root.getLeadComponent(), rootContainer));
                }
            });
        }
        if (root.getNextFocusUp() != null) {
            modifyingProperty(c, PROPERTY_NEXT_FOCUS_UP);
            postCreateTasks.add(new Runnable() {

                public void run() {
                    c.setNextFocusUp(findByName(root.getNextFocusUp(), rootContainer));
                }
            });
        }
        if (root.getNextFocusDown() != null) {
            modifyingProperty(c, PROPERTY_NEXT_FOCUS_DOWN);
            postCreateTasks.add(new Runnable() {

                public void run() {
                    c.setNextFocusDown(findByName(root.getNextFocusDown(), rootContainer));
                }
            });
        }
        if (root.getNextFocusLeft() != null) {
            modifyingProperty(c, PROPERTY_NEXT_FOCUS_LEFT);
            postCreateTasks.add(new Runnable() {

                public void run() {
                    c.setNextFocusLeft(findByName(root.getNextFocusLeft(), rootContainer));
                }
            });
        }
        if (root.getNextFocusRight() != null) {
            modifyingProperty(c, PROPERTY_NEXT_FOCUS_RIGHT);
            postCreateTasks.add(new Runnable() {

                public void run() {
                    c.setNextFocusRight(findByName(root.getNextFocusRight(), rootContainer));
                }
            });
        }
        // custom settings are always last after all other properties
        if (root.getCustom() != null && root.getCustom().length > 0) {
            modifyingProperty(c, PROPERTY_CUSTOM);
            for (Custom cust : root.getCustom()) {
                modifyingCustomProperty(c, cust.getName());
                Object value = null;
                Class customType = UserInterfaceEditor.getPropertyCustomType(c, cust.getName());
                if (customType.isArray()) {
                    if (customType == String[].class) {
                        if (cust.getStr() != null) {
                            String[] arr = new String[cust.getStr().length];
                            for (int iter = 0; iter < arr.length; iter++) {
                                arr[iter] = cust.getStr()[iter].getValue();
                            }
                            c.setPropertyValue(cust.getName(), arr);
                        } else {
                            c.setPropertyValue(cust.getName(), null);
                        }
                        continue;
                    }
                    if (customType == String[][].class) {
                        if (cust.getArr() != null) {
                            String[][] arr = new String[cust.getArr().length][];
                            for (int iter = 0; iter < arr.length; iter++) {
                                if (cust.getArr()[iter] != null && cust.getArr()[iter].getValue() != null) {
                                    arr[iter] = new String[cust.getArr()[iter].getValue().length];
                                    for (int inter = 0; inter < arr[iter].length; inter++) {
                                        arr[iter][inter] = cust.getArr()[iter].getValue()[inter].getValue();
                                    }
                                }
                            }
                            c.setPropertyValue(cust.getName(), arr);
                        } else {
                            c.setPropertyValue(cust.getName(), null);
                        }
                        continue;
                    }
                    if (customType == com.codename1.ui.Image[].class) {
                        if (cust.getStr() != null) {
                            com.codename1.ui.Image[] arr = new com.codename1.ui.Image[cust.getStr().length];
                            for (int iter = 0; iter < arr.length; iter++) {
                                arr[iter] = res.getImage(cust.getStr()[iter].getValue());
                            }
                            c.setPropertyValue(cust.getName(), arr);
                        } else {
                            c.setPropertyValue(cust.getName(), null);
                        }
                        continue;
                    }
                    if (customType == Object[].class) {
                        if (cust.getStringItem() != null) {
                            String[] arr = new String[cust.getStringItem().length];
                            for (int iter = 0; iter < arr.length; iter++) {
                                arr[iter] = cust.getStringItem()[iter].getValue();
                            }
                            c.setPropertyValue(cust.getName(), arr);
                            continue;
                        } else {
                            if (cust.getMapItems() != null) {
                                Hashtable[] arr = new Hashtable[cust.getMapItems().length];
                                for (int iter = 0; iter < arr.length; iter++) {
                                    arr[iter] = new Hashtable();
                                    if (cust.getMapItems()[iter].getActionItem() != null) {
                                        for (Val v : cust.getMapItems()[iter].getActionItem()) {
                                            Command cmd = createCommandImpl(v.getValue(), null, -1, v.getValue(), false, "");
                                            cmd.putClientProperty(COMMAND_ACTION, v.getValue());
                                            value = cmd;
                                            arr[iter].put(v.getKey(), cmd);
                                        }
                                    }
                                    if (cust.getMapItems()[iter].getStringItem() != null) {
                                        for (Val v : cust.getMapItems()[iter].getActionItem()) {
                                            arr[iter].put(v.getKey(), v.getValue());
                                        }
                                    }
                                    if (cust.getMapItems()[iter].getImageItem() != null) {
                                        for (Val v : cust.getMapItems()[iter].getActionItem()) {
                                            arr[iter].put(v.getKey(), res.getImage(v.getValue()));
                                        }
                                    }
                                }
                                c.setPropertyValue(cust.getName(), arr);
                                continue;
                            }
                        }
                        c.setPropertyValue(cust.getName(), null);
                        continue;
                    }
                }
                if (customType == String.class) {
                    c.setPropertyValue(cust.getName(), cust.getValue());
                    continue;
                }
                if (customType == Integer.class) {
                    if (cust.getValue() != null) {
                        c.setPropertyValue(cust.getName(), Integer.valueOf(cust.getValue()));
                    } else {
                        c.setPropertyValue(cust.getName(), null);
                    }
                    continue;
                }
                if (customType == Long.class) {
                    if (cust.getValue() != null) {
                        c.setPropertyValue(cust.getName(), Long.valueOf(cust.getValue()));
                    } else {
                        c.setPropertyValue(cust.getName(), null);
                    }
                    continue;
                }
                if (customType == Double.class) {
                    if (cust.getValue() != null) {
                        c.setPropertyValue(cust.getName(), Double.valueOf(cust.getValue()));
                    } else {
                        c.setPropertyValue(cust.getName(), null);
                    }
                    continue;
                }
                if (customType == Date.class) {
                    if (cust.getValue() != null) {
                        c.setPropertyValue(cust.getName(), new Date(Long.parseLong(cust.getValue())));
                    } else {
                        c.setPropertyValue(cust.getName(), null);
                    }
                    continue;
                }
                if (customType == Float.class) {
                    if (cust.getValue() != null) {
                        c.setPropertyValue(cust.getName(), Float.valueOf(cust.getValue()));
                    } else {
                        c.setPropertyValue(cust.getName(), null);
                    }
                    continue;
                }
                if (customType == Byte.class) {
                    if (cust.getValue() != null) {
                        c.setPropertyValue(cust.getName(), Byte.valueOf(cust.getValue()));
                    } else {
                        c.setPropertyValue(cust.getName(), null);
                    }
                    continue;
                }
                if (customType == Character.class) {
                    if (cust.getValue() != null && ((String) cust.getValue()).length() > 0) {
                        c.setPropertyValue(cust.getName(), new Character(((String) cust.getValue()).charAt(0)));
                    } else {
                        c.setPropertyValue(cust.getName(), null);
                    }
                    continue;
                }
                if (customType == Boolean.class) {
                    if (cust.getValue() != null) {
                        c.setPropertyValue(cust.getName(), Boolean.valueOf(cust.getValue()));
                    } else {
                        c.setPropertyValue(cust.getName(), null);
                    }
                    continue;
                }
                if (customType == com.codename1.ui.Image.class) {
                    if (cust.getValue() != null) {
                        c.setPropertyValue(cust.getName(), res.getImage(cust.getValue()));
                    } else {
                        c.setPropertyValue(cust.getName(), null);
                    }
                    continue;
                }
                if (customType == com.codename1.ui.Container.class) {
                    // resource might have been removed we need to fail gracefully
                    String[] uiNames = res.getUIResourceNames();
                    for (int iter = 0; iter < uiNames.length; iter++) {
                        if (uiNames[iter].equals(cust.getName())) {
                            c.setPropertyValue(cust.getName(), createContainer(res, cust.getName()));
                            continue;
                        }
                    }
                    c.setPropertyValue(cust.getName(), null);
                    continue;
                }
                if (customType == com.codename1.ui.list.CellRenderer.class) {
                    if (cust.getUnselectedRenderer() != null) {
                        GenericListCellRenderer g;
                        if (cust.getSelectedRendererEven() == null) {
                            Component selected = createContainer(res, cust.getSelectedRenderer());
                            Component unselected = createContainer(res, cust.getUnselectedRenderer());
                            g = new GenericListCellRenderer(selected, unselected);
                            g.setFisheye(!cust.getSelectedRenderer().equals(cust.getUnselectedRenderer()));
                        } else {
                            Component selected = createContainer(res, cust.getSelectedRenderer());
                            Component unselected = createContainer(res, cust.getUnselectedRenderer());
                            Component even = createContainer(res, cust.getSelectedRendererEven());
                            Component evenU = createContainer(res, cust.getUnselectedRendererEven());
                            g = new GenericListCellRenderer(selected, unselected, even, evenU);
                            g.setFisheye(!cust.getSelectedRenderer().equals(cust.getUnselectedRenderer()));
                        }
                        c.setPropertyValue(cust.getName(), g);
                        continue;
                    }
                    c.setPropertyValue(cust.getName(), null);
                    continue;
                }
            }
        }
        return c;
    } catch (Throwable t) {
        t.printStackTrace();
        JOptionPane.showMessageDialog(java.awt.Frame.getFrames()[0], "Error creating component: " + root.getName() + "\n" + t.toString() + "\ntrying to recover...", "Error", JOptionPane.ERROR_MESSAGE);
        return null;
    }
}
Also used : Val(com.codename1.ui.util.xml.Val) TextArea(com.codename1.ui.TextArea) Label(com.codename1.ui.Label) Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Button(com.codename1.ui.Button) RadioButton(com.codename1.ui.RadioButton) Dialog(com.codename1.ui.Dialog) ComponentEntry(com.codename1.ui.util.xml.comps.ComponentEntry) ArrayList(java.util.ArrayList) ContainerList(com.codename1.ui.list.ContainerList) List(com.codename1.ui.List) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) List(com.codename1.ui.List) RadioButton(com.codename1.ui.RadioButton) CheckBox(com.codename1.ui.CheckBox) Tabs(com.codename1.ui.Tabs) FlowLayout(com.codename1.ui.layouts.FlowLayout) Slider(com.codename1.ui.Slider) Form(com.codename1.ui.Form) BoxLayout(com.codename1.ui.layouts.BoxLayout) ContainerList(com.codename1.ui.list.ContainerList) GridLayout(com.codename1.ui.layouts.GridLayout) Component(com.codename1.ui.Component) TableLayout(com.codename1.ui.table.TableLayout) GenericListCellRenderer(com.codename1.ui.list.GenericListCellRenderer) Hashtable(java.util.Hashtable) Custom(com.codename1.ui.util.xml.comps.Custom) Date(java.util.Date) CommandEntry(com.codename1.ui.util.xml.comps.CommandEntry) BoxLayout(com.codename1.ui.layouts.BoxLayout) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) GridLayout(com.codename1.ui.layouts.GridLayout) Layout(com.codename1.ui.layouts.Layout) FlowLayout(com.codename1.ui.layouts.FlowLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout) TableLayout(com.codename1.ui.table.TableLayout) ActionCommand(com.codename1.designer.ActionCommand) Command(com.codename1.ui.Command)

Example 10 with TextArea

use of com.codename1.ui.TextArea in project CodenameOne by codenameone.

the class ResetableTextWatcher method edit.

/**
 * Entry point for using this class
 * @param impl The current running activity
 * @param component Any subclass of com.codename1.ui.TextArea
 * @param inputType One of the TextArea's input-type constants
 */
public static void edit(final AndroidImplementation impl, final Component component, final int inputType) {
    if (impl.getActivity() == null) {
        throw new IllegalArgumentException("activity is null");
    }
    if (component == null) {
        throw new IllegalArgumentException("component is null");
    }
    if (!(component instanceof TextArea)) {
        throw new IllegalArgumentException("component must be instance of TextArea");
    }
    final TextArea textArea = (TextArea) component;
    final String initialText = textArea.getText();
    textArea.putClientProperty("InPlaceEditView.initialText", initialText);
    // The very first time we try to edit a string, let's determine if the
    // system default is to do async editing.  If the system default
    // is not yet set, we set it here, and it will be used as the default from now on
    // We do this because the nativeInstance.isAsyncEditMode() value changes
    // to reflect the currently edited field so it isn't a good way to keep a
    // system default.
    String defaultAsyncEditingSetting = Display.getInstance().getProperty("android.VKBAlwaysOpen", null);
    if (defaultAsyncEditingSetting == null) {
        defaultAsyncEditingSetting = impl.isAsyncEditMode() ? "true" : "false";
        Display.getInstance().setProperty("android.VKBAlwaysOpen", defaultAsyncEditingSetting);
    }
    boolean asyncEdit = "true".equals(defaultAsyncEditingSetting) ? true : false;
    // Check if the form has any setting for asyncEditing that should override
    // the application defaults.
    final Form parentForm = component.getComponentForm();
    if (parentForm == null) {
        com.codename1.io.Log.p("Attempt to edit text area that is not on a form.  This is not supported");
        return;
    }
    if (parentForm.getClientProperty("asyncEditing") != null) {
        Object async = parentForm.getClientProperty("asyncEditing");
        if (async instanceof Boolean) {
            asyncEdit = ((Boolean) async).booleanValue();
        // Log.p("Form overriding asyncEdit due to asyncEditing client property: "+asyncEdit);
        }
    }
    if (parentForm.getClientProperty("android.asyncEditing") != null) {
        Object async = parentForm.getClientProperty("android.asyncEditing");
        if (async instanceof Boolean) {
            asyncEdit = ((Boolean) async).booleanValue();
        // Log.p("Form overriding asyncEdit due to ios.asyncEditing client property: "+asyncEdit);
        }
    }
    if (parentForm.isFormBottomPaddingEditingMode()) {
        asyncEdit = true;
    }
    // then this will override all other settings.
    if (component.getClientProperty("asyncEditing") != null) {
        Object async = component.getClientProperty("asyncEditing");
        if (async instanceof Boolean) {
            asyncEdit = ((Boolean) async).booleanValue();
        // Log.p("Overriding asyncEdit due to field asyncEditing client property: "+asyncEdit);
        }
    }
    if (component.getClientProperty("android.asyncEditing") != null) {
        Object async = component.getClientProperty("android.asyncEditing");
        if (async instanceof Boolean) {
            asyncEdit = ((Boolean) async).booleanValue();
        // Log.p("Overriding asyncEdit due to field ios.asyncEditing client property: "+asyncEdit);
        }
    }
    // if true, then in async mode we are currently editing and are switching to another field
    final boolean isEditedFieldSwitch;
    // If we are already editing, we need to finish that up before we proceed to edit the next field.
    synchronized (editingLock) {
        if (mIsEditing) {
            if (impl.isAsyncEditMode()) {
                // Using isEditedFieldSwitch was causing issues with cursors not showing up.
                // https://github.com/codenameone/CodenameOne/issues/2353
                // https://stackoverflow.com/questions/49004370/focus-behaviour-in-textarea-in-cn1
                // Disabling this feature by default now, but can be re-enabled by setting
                // Display.getInstance().setProperty("android.reuseTextEditorOnSwitch", "true");
                // This editedFieldSwitch feature was added a while back to improve experience on older
                // Android devices where the field switching was going too slow.
                // https://github.com/codenameone/CodenameOne/issues/2012
                // This issue was resolved in this commit (https://github.com/jaanushansen/CodenameOne/commit/f3e53a80704149e4d7cde276d01c1368bcdcfe2c)
                // which was submitted as part of a pull request.  This fix has been the source of several
                // regressions, mostly related to properties not being propagated properly when a text field is changed
                // However, this issue (with the cursor not showing up), doesn't appear to have a simple solution
                // so, I'm disabling this feature for now.
                isEditedFieldSwitch = "true".equals(Display.getInstance().getProperty("android.reuseTextEditorOnSwitch", "false"));
                final String[] out = new String[1];
                TextArea prevTextArea = null;
                if (sInstance != null && sInstance.mLastEditText != null) {
                    prevTextArea = sInstance.mLastEditText.getTextArea();
                }
                if (prevTextArea != null) {
                    final TextArea fPrevTextArea = prevTextArea;
                    final String retVal = sInstance.mLastEditText.getText().toString();
                    Display.getInstance().callSerially(new Runnable() {

                        public void run() {
                            Display.getInstance().onEditingComplete(fPrevTextArea, retVal);
                        }
                    });
                }
                InPlaceEditView.setEditedTextField(textArea);
                nextTextArea = null;
            } else {
                isEditedFieldSwitch = false;
                final InPlaceEditView instance = sInstance;
                if (instance != null && instance.mEditText != null && instance.mEditText.mTextArea == textArea) {
                    instance.showTextEditorAgain();
                    return;
                }
                if (!isClosing && sInstance != null && sInstance.mEditText != null) {
                    isClosing = true;
                    impl.getActivity().runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            instance.endEditing(REASON_UNDEFINED, true, 0);
                        }
                    });
                }
                afterClose = new Runnable() {

                    @Override
                    public void run() {
                        impl.callHideTextEditor();
                        Display.getInstance().editString(component, textArea.getMaxSize(), inputType, textArea.getText());
                    }
                };
                return;
            }
        } else {
            isEditedFieldSwitch = false;
        }
        mIsEditing = true;
        isClosing = false;
        afterClose = null;
    }
    impl.setAsyncEditMode(asyncEdit);
    // textArea.setPreferredSize(prefSize);
    if (!impl.isAsyncEditMode() && textArea instanceof TextField) {
        ((TextField) textArea).setEditable(false);
    }
    final boolean scrollableParent = isScrollableParent(textArea);
    // We wrap the text area so that we can safely pass data across to the
    // android UI thread.
    final TextAreaData textAreaData = new TextAreaData(textArea);
    impl.getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if (!isEditedFieldSwitch) {
                releaseEdit();
                if (sInstance == null) {
                    sInstance = new InPlaceEditView(impl);
                    impl.relativeLayout.addView(sInstance);
                }
            // Let's try something new here
            // We'll ALWAYS try resize edit mode (since it just works better)
            // But we'll detect whether the field is still covered by the keyboard
            // and switch to pan mode if necessary.
            }
            if (scrollableParent || parentForm.isFormBottomPaddingEditingMode()) {
                setEditMode(true);
            } else {
                trySetEditMode(true);
            }
            sInstance.startEditing(impl.getActivity(), textAreaData, initialText, inputType, isEditedFieldSwitch);
        }
    });
    final String[] out = new String[1];
    // In order to reuse the code the runs after edit completion, we will wrap it in a runnable
    // For sync edit mode, we will just run onComplete.run() at the end of this method.  For
    // Async mode we add the Runnable to the textarea as a client property, then run it
    // when editing eventually completes.
    Runnable onComplete = new Runnable() {

        public void run() {
            if (!impl.isAsyncEditMode() && textArea instanceof TextField) {
                ((TextField) textArea).setEditable(true);
            }
            textArea.setPreferredSize(null);
            if (sInstance != null && sInstance.mLastEditText != null && sInstance.mLastEditText.mTextArea == textArea) {
                String retVal = sInstance.mLastEditText.getText().toString();
                if (!impl.isAsyncEditMode()) {
                    sInstance.mLastEditText = null;
                    impl.getActivity().runOnUiThread(new Runnable() {

                        public void run() {
                            releaseEdit();
                        }
                    });
                }
                out[0] = retVal;
            } else {
                out[0] = initialText;
            }
            Display.getInstance().onEditingComplete(component, out[0]);
            if (impl.isAsyncEditMode()) {
                impl.callHideTextEditor();
            } else {
                // lock.
                if (sInstance != null) {
                    Display.getInstance().invokeAndBlock(new Runnable() {

                        public void run() {
                            while (sInstance != null) {
                                com.codename1.io.Util.sleep(5);
                            }
                        }
                    });
                }
            }
            // Release the editing flag
            synchronized (editingLock) {
                mIsEditing = false;
            }
            // as a runnable ... this should take priority over the "nextTextArea" setting
            if (afterClose != null) {
                Display.getInstance().callSerially(afterClose);
            } else if (nextTextArea != null) {
                final TextArea next = nextTextArea;
                nextTextArea = null;
                next.requestFocus();
                Display.getInstance().callSerially(new Runnable() {

                    public void run() {
                        Display.getInstance().editString(next, next.getMaxSize(), next.getConstraint(), next.getText());
                    }
                });
            }
        }
    };
    textArea.requestFocus();
    textArea.repaint();
    if (impl.isAsyncEditMode()) {
        component.putClientProperty("android.onAsyncEditingComplete", onComplete);
        return;
    }
    // Make this call synchronous
    // We set this flag so that waitForEditCompletion can block on it.
    // The flag will be released inside the endEditing method which will
    // allow the method to proceed.
    waitingForSynchronousEditingCompletion = true;
    waitForEditCompletion();
    onComplete.run();
}
Also used : TextArea(com.codename1.ui.TextArea) Form(com.codename1.ui.Form) TextField(com.codename1.ui.TextField)

Aggregations

TextArea (com.codename1.ui.TextArea)46 Component (com.codename1.ui.Component)22 Label (com.codename1.ui.Label)11 Button (com.codename1.ui.Button)10 Container (com.codename1.ui.Container)10 Form (com.codename1.ui.Form)10 RadioButton (com.codename1.ui.RadioButton)8 PeerComponent (com.codename1.ui.PeerComponent)6 TextField (com.codename1.ui.TextField)6 BorderLayout (com.codename1.ui.layouts.BorderLayout)6 Font (com.codename1.ui.Font)5 BoxLayout (com.codename1.ui.layouts.BoxLayout)5 CheckBox (com.codename1.ui.CheckBox)4 Dialog (com.codename1.ui.Dialog)4 List (com.codename1.ui.List)4 Hashtable (java.util.Hashtable)4 Paint (android.graphics.Paint)3 Command (com.codename1.ui.Command)3 Slider (com.codename1.ui.Slider)3 ActionEvent (com.codename1.ui.events.ActionEvent)3