Search in sources :

Example 6 with Command

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

the class LazyValueC method back.

/**
 * This method effectively pops the form navigation stack and goes back
 * to the previous form if back navigation is enabled and there is
 * a previous form.
 *
 * @param sourceComponent the component that triggered the back command which effectively
 * allows us to find the EmbeddedContainer for a case of container navigation. Null
 * can be used if not applicable.
 */
public void back(Component sourceComponent) {
    Vector formNavigationStack = getFormNavigationStackForComponent(sourceComponent);
    if (formNavigationStack != null && formNavigationStack.size() > 0) {
        Hashtable h = (Hashtable) formNavigationStack.elementAt(formNavigationStack.size() - 1);
        if (h.containsKey(FORM_STATE_KEY_CONTAINER)) {
            Form currentForm = Display.getInstance().getCurrent();
            if (currentForm != null) {
                exitForm(currentForm);
            }
        }
        String formName = (String) h.get(FORM_STATE_KEY_NAME);
        if (!h.containsKey(FORM_STATE_KEY_CONTAINER)) {
            Form f = (Form) createContainer(fetchResourceFile(), formName);
            initBackForm(f);
            onBackNavigation();
            beforeShow(f);
            f.showBack();
            postShowImpl(f);
        } else {
            showContainerImpl(formName, null, sourceComponent, true);
        }
    }
}
Also used : Form(com.codename1.ui.Form) Hashtable(java.util.Hashtable) Vector(java.util.Vector)

Example 7 with Command

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

the class LazyValueC method processCommandImpl.

private void processCommandImpl(ActionEvent ev, Command cmd) {
    processCommand(ev, cmd);
    if (ev.isConsumed()) {
        return;
    }
    if (globalCommandListeners != null) {
        globalCommandListeners.fireActionEvent(ev);
        if (ev.isConsumed()) {
            return;
        }
    }
    if (localCommandListeners != null) {
        Form f = Display.getInstance().getCurrent();
        EventDispatcher e = (EventDispatcher) localCommandListeners.get(f.getName());
        if (e != null) {
            e.fireActionEvent(ev);
        }
    }
}
Also used : Form(com.codename1.ui.Form)

Example 8 with Command

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

the class DefaultListCellRenderer method getCellRendererComponent.

/**
 * {@inheritDoc}
 */
public Component getCellRendererComponent(Component list, Object model, T value, int index, boolean isSelected) {
    if (!alwaysRenderSelection && !Display.getInstance().shouldRenderSelection(list)) {
        isSelected = false;
    }
    setFocus(isSelected);
    if (showNumbers) {
        String text = "" + value;
        Map<String, String> t = UIManager.getInstance().getBundle();
        if (t != null && value != null) {
            Object o = t.get(value.toString());
            if (o != null) {
                text = (String) o;
            }
        }
        if (isRTL()) {
            setText(text + " ." + (index + 1));
        } else {
            setText("" + (index + 1) + ". " + text);
        }
    } else {
        if (value != null) {
            String v = value.toString();
            setText(v);
            if (isRightAlignNumbers()) {
                char c = v.charAt(0);
                Style s = getStyle();
                if (c >= '0' && c <= '9') {
                    s.setAlignment(RIGHT);
                } else {
                    s.setAlignment(LEFT);
                }
            }
        } else {
            setText("null");
        }
    }
    if (value instanceof Command) {
        setIcon(((Command) value).getIcon());
        setEnabled(((Command) value).isEnabled());
    }
    return this;
}
Also used : Command(com.codename1.ui.Command) Style(com.codename1.ui.plaf.Style)

Example 9 with Command

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

the class UserInterfaceEditor method persistToXML.

private static void persistToXML(com.codename1.ui.Container containerInstance, com.codename1.ui.Component cmp, StringBuilder build, EditableResources res, String indent, String tabTitle) {
    build.append(indent);
    build.append("<component type=\"");
    build.append((String) cmp.getClientProperty(TYPE_KEY));
    build.append("\" name=\"");
    if (cmp.getName() != null) {
        build.append(xmlize(cmp.getName()));
    }
    build.append("\" ");
    if (exportToNewGuiBuilderMode) {
        String cmpName = cmp.getName();
        Class cls = componentNames.get(cmpName);
        if (cls == null) {
            componentNames.put(cmpName, cmp.getClass());
        } else {
            if (cls != cmp.getClass()) {
                componentNames.put(cmpName, com.codename1.ui.Component.class);
            }
        }
        if (cmp instanceof List) {
            listNames.add(cmp.getName());
        }
        if (cmp instanceof com.codename1.ui.Button || cmp instanceof com.codename1.ui.TextArea || cmp instanceof com.codename1.ui.Slider || cmp instanceof com.codename1.ui.List || cmp instanceof com.codename1.components.MultiButton || cmp instanceof com.codename1.components.SpanButton || cmp instanceof com.codename1.components.OnOffSwitch || cmp instanceof com.codename1.ui.Calendar || cmp instanceof com.codename1.ui.list.ContainerList) {
            // add action listener XML
            actionEventNames.add(cmp.getName());
            build.append(" actionEvent=\"true\" ");
        }
    }
    if (cmp.getClientProperty("cn1$Properties") != null) {
        String[] p = ((String) cmp.getClientProperty("cn1$Properties")).split(",");
        if (p.length > 0) {
            build.append("clientProperties=\"");
            boolean first = true;
            for (String c : p) {
                if (!first) {
                    build.append(",");
                }
                first = false;
                build.append(c);
                build.append("=");
                build.append((String) cmp.getClientProperty(c));
            }
            build.append("\" ");
        }
    }
    if (tabTitle != null) {
        build.append("tabTitle=\"");
        build.append(xmlize(tabTitle));
        build.append("\" ");
    }
    if (cmp.getClientProperty("%base_form%") != null) {
        build.append("baseForm=\"");
        build.append(xmlize((String) cmp.getClientProperty("%base_form%")));
        build.append("\" ");
    }
    if (cmp.getCloudBoundProperty() != null) {
        build.append("cloudBoundProperty=\"");
        build.append(xmlize(cmp.getCloudBoundProperty()));
        build.append("\" ");
    }
    if (cmp.getCloudDestinationProperty() != null) {
        build.append("cloudDestinationProperty=\"");
        build.append(xmlize(cmp.getCloudDestinationProperty()));
        build.append("\" ");
    }
    if (isPropertyModified(cmp, PROPERTY_COMMAND) || isPropertyModified(cmp, PROPERTY_COMMAND_LEGACY)) {
        ActionCommand cmd;
        if (cmp instanceof com.codename1.ui.Container) {
            cmd = (ActionCommand) ((com.codename1.ui.Button) ((com.codename1.ui.Container) cmp).getLeadComponent()).getCommand();
        } else {
            cmd = (ActionCommand) ((com.codename1.ui.Button) cmp).getCommand();
        }
        build.append("commandName=\"");
        build.append(xmlize(cmd.getCommandName()));
        build.append("\" ");
        if (cmd.getIcon() != null) {
            build.append("commandIcon=\"");
            build.append(xmlize(res.findId(cmd.getIcon())));
            build.append("\" ");
        }
        if (cmd.getRolloverIcon() != null) {
            build.append("commandRolloverIcon=\"");
            build.append(xmlize(res.findId(cmd.getRolloverIcon())));
            build.append("\" ");
        }
        if (cmd.getPressedIcon() != null) {
            build.append("commandPressedIcon=\"");
            build.append(xmlize(res.findId(cmd.getPressedIcon())));
            build.append("\" ");
        }
        if (cmd.getDisabledIcon() != null) {
            build.append("commandDisabledIcon=\"");
            build.append(xmlize(res.findId(cmd.getDisabledIcon())));
            build.append("\" ");
        }
        build.append("commandId=\"");
        build.append(cmd.getId());
        build.append("\" ");
        if (cmd.getAction() != null) {
            build.append("commandAction=\"");
            build.append(xmlize(cmd.getAction()));
            build.append("\" ");
            if (cmd.getAction().equals("$Execute")) {
                build.append("commandArgument=\"");
                build.append(xmlize(cmd.getArgument()));
                build.append("\" ");
            }
        }
        build.append("commandBack=\"");
        build.append(cmp.getComponentForm().getBackCommand() == cmd);
        build.append("\" ");
        if (exportToNewGuiBuilderMode) {
            build.append(" varName=\"");
            String varName;
            if (cmd.getCommandName() == null || cmd.getCommandName().length() == 0) {
                varName = ResourceEditorView.normalizeFormName(cmd.getCommandName());
                build.append(varName);
            } else {
                varName = "Command" + commandCounter;
                build.append(varName);
                commandCounter++;
            }
            build.append("\" ");
            String action = cmd.getAction();
            if (action != null) {
                if (cmp.getComponentForm() != null) {
                    commandList.add(cmd);
                    cmd.putClientProperty("FORMNAME", cmp.getComponentForm().getName());
                }
            }
        }
    }
    if (isPropertyModified(cmp, PROPERTY_LABEL_FOR)) {
        if (cmp.getLabelForComponent() != null) {
            build.append("labelFor=\"");
            build.append(xmlize(cmp.getLabelForComponent().getName()));
            build.append("\" ");
        }
    }
    if (isPropertyModified(cmp, PROPERTY_LEAD_COMPONENT) && ((com.codename1.ui.Container) cmp).getLeadComponent() != null) {
        build.append("leadComponent=\"");
        build.append(xmlize(((com.codename1.ui.Container) cmp).getLeadComponent().getName()));
        build.append("\" ");
    }
    if (isPropertyModified(cmp, PROPERTY_NEXT_FOCUS_DOWN) && cmp.getNextFocusDown() != null) {
        build.append("nextFocusDown=\"");
        build.append(xmlize(cmp.getNextFocusDown().getName()));
        build.append("\" ");
    }
    if (isPropertyModified(cmp, PROPERTY_NEXT_FOCUS_UP) && cmp.getNextFocusUp() != null) {
        build.append("nextFocusUp=\"");
        build.append(xmlize(cmp.getNextFocusUp().getName()));
        build.append("\" ");
    }
    if (isPropertyModified(cmp, PROPERTY_NEXT_FOCUS_LEFT) && cmp.getNextFocusLeft() != null) {
        build.append("nextFocusLeft=\"");
        build.append(xmlize(cmp.getNextFocusLeft().getName()));
        build.append("\" ");
    }
    if (isPropertyModified(cmp, PROPERTY_NEXT_FOCUS_RIGHT) && cmp.getNextFocusRight() != null) {
        build.append("nextFocusRight=\"");
        build.append(xmlize(cmp.getNextFocusRight().getName()));
        build.append("\" ");
    }
    if (isPropertyModified(cmp, PROPERTY_EMBED)) {
        build.append("embed=\"");
        build.append(xmlize(((EmbeddedContainer) cmp).getEmbed()));
        build.append("\" ");
    }
    if (isPropertyModified(cmp, PROPERTY_UIID)) {
        build.append("uiid=\"");
        build.append(cmp.getUIID());
        build.append("\" ");
    }
    if (isPropertyModified(cmp, PROPERTY_FOCUSABLE)) {
        build.append("focusable=\"");
        build.append(cmp.isFocusable());
        build.append("\" ");
    }
    if (isPropertyModified(cmp, PROPERTY_ENABLED)) {
        build.append("enabled=\"");
        build.append(cmp.isEnabled());
        build.append("\" ");
    }
    if (isPropertyModified(cmp, PROPERTY_RTL)) {
        build.append("rtl=\"");
        build.append(cmp.isRTL());
        build.append("\" ");
    }
    if (isPropertyModified(cmp, PROPERTY_SCROLL_VISIBLE)) {
        build.append("scrollVisible=\"");
        build.append(cmp.isScrollVisible());
        build.append("\" ");
    }
    /*if(isPropertyModified(cmp, PROPERTY_PREFERRED_WIDTH)) {
            out.writeInt(PROPERTY_PREFERRED_WIDTH);
            out.writeInt(cmp.getPreferredW());
        }

        if(isPropertyModified(cmp, PROPERTY_PREFERRED_HEIGHT)) {
            out.writeInt(PROPERTY_PREFERRED_HEIGHT);
            out.writeInt(cmp.getPreferredH());
        }*/
    if (isPropertyModified(cmp, PROPERTY_TENSILE_DRAG_ENABLED)) {
        build.append("tensileDragEnabled=\"");
        build.append(cmp.isTensileDragEnabled());
        build.append("\" ");
    }
    if (isPropertyModified(cmp, PROPERTY_TACTILE_TOUCH)) {
        build.append("tactileTouch=\"");
        build.append(cmp.isTactileTouch());
        build.append("\" ");
    }
    if (isPropertyModified(cmp, PROPERTY_SNAP_TO_GRID)) {
        build.append("snapToGrid=\"");
        build.append(cmp.isSnapToGrid());
        build.append("\" ");
    }
    if (isPropertyModified(cmp, PROPERTY_FLATTEN)) {
        build.append("flatten=\"");
        build.append(cmp.isFlatten());
        build.append("\" ");
    }
    if (isActualContainer(cmp) || cmp instanceof com.codename1.ui.list.ContainerList) {
        com.codename1.ui.Container cnt = (com.codename1.ui.Container) cmp;
        if (isPropertyModified(cnt, PROPERTY_SCROLLABLE_X)) {
            build.append("scrollableX=\"");
            build.append(CodenameOneAccessor.isScrollableX(cnt));
            build.append("\" ");
        }
        if (isPropertyModified(cnt, PROPERTY_SCROLLABLE_Y)) {
            build.append("scrollableY=\"");
            build.append(CodenameOneAccessor.isScrollableY(cnt));
            build.append("\" ");
        }
        if (cmp instanceof com.codename1.ui.Tabs) {
            com.codename1.ui.Tabs tab = (com.codename1.ui.Tabs) cmp;
            if (isPropertyModified(cmp, PROPERTY_TAB_PLACEMENT)) {
                build.append("tabPlacement=\"");
                build.append(((com.codename1.ui.Tabs) cmp).getTabPlacement());
                build.append("\" ");
            }
            if (isPropertyModified(cmp, PROPERTY_TAB_TEXT_POSITION)) {
                build.append("tabTextPosition=\"");
                build.append(((com.codename1.ui.Tabs) cmp).getTabTextPosition());
                build.append("\" ");
            }
            build.append(">\n");
            appendComponentXMLBody(containerInstance, cmp, build, res, indent + "  ");
            for (int iter = 0; iter < tab.getTabCount(); iter++) {
                persistToXML(containerInstance, tab.getTabComponentAt(iter), build, res, indent + "  ", tab.getTabTitle(iter));
            }
            build.append(indent);
            build.append("</component>\n");
        } else {
            if (isPropertyModified(cmp, PROPERTY_LAYOUT)) {
                com.codename1.ui.layouts.Layout l = cnt.getLayout();
                build.append("layout=\"");
                if (l instanceof com.codename1.ui.layouts.FlowLayout) {
                    com.codename1.ui.layouts.FlowLayout f = (com.codename1.ui.layouts.FlowLayout) l;
                    build.append("FlowLayout\" flowLayoutFillRows=\"");
                    build.append(f.isFillRows());
                    build.append("\" flowLayoutAlign=\"");
                    build.append(f.getAlign());
                    build.append("\" flowLayoutValign=\"");
                    build.append(f.getValign());
                    build.append("\" ");
                } else {
                    if (l instanceof com.codename1.ui.layouts.BorderLayout) {
                        com.codename1.ui.layouts.BorderLayout b = (com.codename1.ui.layouts.BorderLayout) l;
                        build.append("BorderLayout\" borderLayoutAbsoluteCenter=\"");
                        build.append(b.isAbsoluteCenter());
                        build.append("\" ");
                        String north = b.getLandscapeSwap(com.codename1.ui.layouts.BorderLayout.NORTH);
                        String east = b.getLandscapeSwap(com.codename1.ui.layouts.BorderLayout.EAST);
                        String west = b.getLandscapeSwap(com.codename1.ui.layouts.BorderLayout.WEST);
                        String south = b.getLandscapeSwap(com.codename1.ui.layouts.BorderLayout.SOUTH);
                        String center = b.getLandscapeSwap(com.codename1.ui.layouts.BorderLayout.CENTER);
                        if (north != null) {
                            build.append("borderLayoutSwapNorth=\"");
                            build.append(north);
                            build.append("\" ");
                        }
                        if (east != null) {
                            build.append("borderLayoutSwapEast=\"");
                            build.append(east);
                            build.append("\" ");
                        }
                        if (west != null) {
                            build.append("borderLayoutSwapWest=\"");
                            build.append(west);
                            build.append("\" ");
                        }
                        if (south != null) {
                            build.append("borderLayoutSwapSouth=\"");
                            build.append(south);
                            build.append("\" ");
                        }
                        if (center != null) {
                            build.append("borderLayoutSwapCenter=\"");
                            build.append(center);
                            build.append("\" ");
                        }
                    } else {
                        if (l instanceof com.codename1.ui.layouts.GridLayout) {
                            build.append("GridLayout\" gridLayoutRows=\"");
                            build.append(((com.codename1.ui.layouts.GridLayout) l).getRows());
                            build.append("\" gridLayoutColumns=\"");
                            build.append(((com.codename1.ui.layouts.GridLayout) l).getColumns());
                            build.append("\" ");
                        } else {
                            if (l instanceof com.codename1.ui.layouts.BoxLayout) {
                                if (getInt("axis", l.getClass(), l) == com.codename1.ui.layouts.BoxLayout.X_AXIS) {
                                    build.append("BoxLayout\" boxLayoutAxis=\"X\" ");
                                } else {
                                    build.append("BoxLayout\" boxLayoutAxis=\"Y\" ");
                                }
                            } else {
                                if (l instanceof com.codename1.ui.table.TableLayout) {
                                    build.append("TableLayout\" tableLayoutRows=\"");
                                    build.append(((com.codename1.ui.table.TableLayout) l).getRows());
                                    build.append("\" tableLayoutColumns=\"");
                                    build.append(((com.codename1.ui.table.TableLayout) l).getColumns());
                                    build.append("\" ");
                                } else {
                                    if (l instanceof com.codename1.ui.layouts.LayeredLayout) {
                                        build.append("LayeredLayout\" ");
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (cmp instanceof com.codename1.ui.Form) {
                com.codename1.ui.Form frm = (com.codename1.ui.Form) cmp;
                if (isPropertyModified(cmp, PROPERTY_NEXT_FORM) && frm.getClientProperty("%next_form%") != null) {
                    build.append("nextForm=\"");
                    build.append(xmlize((String) frm.getClientProperty("%next_form%")));
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_TITLE)) {
                    build.append("title=\"");
                    build.append(xmlize(frm.getTitle()));
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_CYCLIC_FOCUS)) {
                    build.append("cyclicFocus=\"");
                    build.append(frm.isCyclicFocus());
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_DIALOG_UIID) && cmp instanceof com.codename1.ui.Dialog) {
                    com.codename1.ui.Dialog dlg = (com.codename1.ui.Dialog) cmp;
                    build.append("dialogUIID=\"");
                    build.append(dlg.getDialogUIID());
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_DISPOSE_WHEN_POINTER_OUT) && cmp instanceof com.codename1.ui.Dialog) {
                    com.codename1.ui.Dialog dlg = (com.codename1.ui.Dialog) cmp;
                    build.append("disposeWhenPointerOutOfBounds=\"");
                    build.append(dlg.isDisposeWhenPointerOutOfBounds());
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_DIALOG_POSITION) && cmp instanceof com.codename1.ui.Dialog) {
                    com.codename1.ui.Dialog dlg = (com.codename1.ui.Dialog) cmp;
                    if (dlg.getDialogPosition() != null) {
                        build.append("dialogPosition=\"");
                        build.append(dlg.getDialogPosition());
                        build.append("\" ");
                    }
                }
                build.append(">\n");
                appendComponentXMLBody(containerInstance, cmp, build, res, indent + "  ");
                if (frm.getCommandCount() > 0 || frm.getBackCommand() != null) {
                    if (isPropertyModified(cmp, PROPERTY_COMMANDS) || isPropertyModified(cmp, PROPERTY_COMMANDS_LEGACY)) {
                        if (frm.getBackCommand() != null && !hasBackCommand(frm, frm.getBackCommand())) {
                            build.append("<command name=\"");
                            ActionCommand cmd = (ActionCommand) frm.getBackCommand();
                            if (exportToNewGuiBuilderMode) {
                                if (cmp.getComponentForm() != null) {
                                    commandList.add(cmd);
                                    cmd.putClientProperty("FORMNAME", cmp.getComponentForm().getName());
                                }
                            }
                            build.append(xmlize(cmd.getCommandName()));
                            build.append("\" ");
                            if (cmd.getIcon() != null) {
                                build.append("icon=\"");
                                build.append(xmlize(res.findId(cmd.getIcon())));
                                build.append("\" ");
                            }
                            if (cmd.getRolloverIcon() != null) {
                                build.append("rolloverIcon=\"");
                                build.append(xmlize(res.findId(cmd.getRolloverIcon())));
                                build.append("\" ");
                            }
                            if (cmd.getPressedIcon() != null) {
                                build.append("pressedIcon=\"");
                                build.append(xmlize(res.findId(cmd.getPressedIcon())));
                                build.append("\" ");
                            }
                            if (cmd.getDisabledIcon() != null) {
                                build.append("disabledIcon=\"");
                                build.append(xmlize(res.findId(cmd.getDisabledIcon())));
                                build.append("\" ");
                            }
                            build.append("id=\"");
                            build.append(cmd.getId());
                            build.append("\" ");
                            if (cmd.getAction() != null) {
                                build.append("action=\"");
                                build.append(xmlize(cmd.getAction()));
                                build.append("\" ");
                                if (cmd.getAction().equals("$Execute")) {
                                    build.append("argument=\"");
                                    build.append(xmlize(cmd.getArgument()));
                                    build.append("\" ");
                                }
                            }
                            build.append("backCommand=\"");
                            build.append(frm.getBackCommand() == cmd);
                            build.append("\" />");
                        }
                        for (int iter = frm.getCommandCount() - 1; iter >= 0; iter--) {
                            ActionCommand cmd = (ActionCommand) frm.getCommand(iter);
                            if (exportToNewGuiBuilderMode) {
                                if (cmp.getComponentForm() != null) {
                                    commandList.add(cmd);
                                    cmd.putClientProperty("FORMNAME", cmp.getComponentForm().getName());
                                }
                            }
                            build.append("<command name=\"");
                            build.append(xmlize(cmd.getCommandName()));
                            build.append("\" ");
                            if (cmd.getIcon() != null) {
                                build.append("icon=\"");
                                build.append(xmlize(res.findId(cmd.getIcon())));
                                build.append("\" ");
                            }
                            if (cmd.getRolloverIcon() != null) {
                                build.append("rolloverIcon=\"");
                                build.append(xmlize(res.findId(cmd.getRolloverIcon())));
                                build.append("\" ");
                            }
                            if (cmd.getPressedIcon() != null) {
                                build.append("pressedIcon=\"");
                                build.append(xmlize(res.findId(cmd.getPressedIcon())));
                                build.append("\" ");
                            }
                            if (cmd.getDisabledIcon() != null) {
                                build.append("disabledIcon=\"");
                                build.append(xmlize(res.findId(cmd.getDisabledIcon())));
                                build.append("\" ");
                            }
                            build.append("id=\"");
                            build.append(cmd.getId());
                            build.append("\" ");
                            if (cmd.getAction() != null) {
                                build.append("action=\"");
                                build.append(xmlize(cmd.getAction()));
                                build.append("\" ");
                                if (cmd.getAction().equals("$Execute")) {
                                    build.append("argument=\"");
                                    build.append(xmlize(cmd.getArgument()));
                                    build.append("\" ");
                                }
                            }
                            build.append("backCommand=\"");
                            build.append(frm.getBackCommand() == cmd);
                            build.append("\" />");
                        }
                    }
                }
                build.append(indent);
                build.append("</component>\n");
            } else {
                if (!(cmp instanceof com.codename1.ui.list.ContainerList)) {
                    build.append(">\n");
                    appendComponentXMLBody(containerInstance, cmp, build, res, indent + "  ");
                    build.append(indent);
                    build.append("</component>\n");
                } else {
                    com.codename1.ui.list.ContainerList lst = ((com.codename1.ui.list.ContainerList) cmp);
                    if (isPropertyModified(cmp, PROPERTY_LIST_RENDERER) && lst.getRenderer() instanceof com.codename1.ui.list.GenericListCellRenderer) {
                        com.codename1.ui.list.GenericListCellRenderer g = (com.codename1.ui.list.GenericListCellRenderer) lst.getRenderer();
                        if (g.getSelectedEven() == null) {
                            build.append(" selectedRenderer=\"");
                            build.append(xmlize(g.getSelected().getName()));
                            build.append("\" unselectedRenderer=\"");
                            build.append(xmlize(g.getUnselected().getName()));
                            build.append("\" ");
                        } else {
                            build.append(" selectedRenderer=\"");
                            build.append(xmlize(g.getSelected().getName()));
                            build.append("\" unselectedRenderer=\"");
                            build.append(xmlize(g.getUnselected().getName()));
                            build.append(" selectedRendererEven=\"");
                            build.append(xmlize(g.getSelectedEven().getName()));
                            build.append("\" unselectedRendererEven=\"");
                            build.append(xmlize(g.getUnselectedEven().getName()));
                            build.append("\" ");
                        }
                    }
                    build.append(">\n");
                    appendComponentXMLBody(containerInstance, cmp, build, res, indent + "  ");
                    build.append(indent);
                    build.append("</component>\n");
                }
            }
        }
    } else {
        if (cmp instanceof com.codename1.ui.Label) {
            com.codename1.ui.Label lbl = (com.codename1.ui.Label) cmp;
            build.append("text=\"");
            build.append(xmlize(lbl.getText()));
            build.append("\" ");
            if (isPropertyModified(cmp, PROPERTY_ALIGNMENT)) {
                build.append("alignment=\"");
                build.append(lbl.getAlignment());
                build.append("\" ");
            }
            if (isPropertyModified(cmp, PROPERTY_ICON) && lbl.getIcon() != null) {
                build.append("icon=\"");
                build.append(xmlize(res.findId(lbl.getIcon())));
                build.append("\" ");
            }
            if (lbl instanceof com.codename1.ui.Button) {
                com.codename1.ui.Button button = (com.codename1.ui.Button) lbl;
                if (isPropertyModified(cmp, PROPERTY_ROLLOVER_ICON) && button.getRolloverIcon() != null) {
                    build.append("rolloverIcon=\"");
                    build.append(xmlize(res.findId(button.getRolloverIcon())));
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_PRESSED_ICON) && button.getPressedIcon() != null) {
                    build.append("pressedIcon=\"");
                    build.append(xmlize(res.findId(button.getPressedIcon())));
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_DISABLED_ICON) && button.getDisabledIcon() != null) {
                    build.append("disabledIcon=\"");
                    build.append(xmlize(res.findId(button.getDisabledIcon())));
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_TOGGLE_BUTTON)) {
                    build.append("toggle=\"");
                    build.append(button.isToggle());
                    build.append("\" ");
                }
            } else {
                if (lbl instanceof com.codename1.ui.Slider) {
                    com.codename1.ui.Slider sld = (com.codename1.ui.Slider) lbl;
                    if (isPropertyModified(cmp, PROPERTY_EDITABLE)) {
                        build.append("editable=\"");
                        build.append(sld.isEditable());
                        build.append("\" ");
                    }
                    if (isPropertyModified(cmp, PROPERTY_INFINITE)) {
                        build.append("infinite=\"");
                        build.append(sld.isInfinite());
                        build.append("\" ");
                    }
                    if (isPropertyModified(cmp, PROPERTY_SLIDER_THUMB) && sld.getThumbImage() != null) {
                        build.append("thumbImage=\"");
                        build.append(xmlize(res.findId(sld.getThumbImage())));
                        build.append("\" ");
                    }
                    if (isPropertyModified(cmp, PROPERTY_PROGRESS)) {
                        build.append("progress=\"");
                        build.append(sld.getProgress());
                        build.append("\" ");
                    }
                    if (isPropertyModified(cmp, PROPERTY_VERTICAL)) {
                        build.append("vertical=\"");
                        build.append(sld.isVertical());
                        build.append("\" ");
                    }
                    if (isPropertyModified(cmp, PROPERTY_INCREMENTS)) {
                        build.append("increments=\"");
                        build.append(sld.getIncrements());
                        build.append("\" ");
                    }
                    if (isPropertyModified(cmp, PROPERTY_MAX_VALUE)) {
                        build.append("maxValue=\"");
                        build.append(sld.getMaxValue());
                        build.append("\" ");
                    }
                    if (isPropertyModified(cmp, PROPERTY_MIN_VALUE)) {
                        build.append("minValue=\"");
                        build.append(sld.getMinValue());
                        build.append("\" ");
                    }
                    if (isPropertyModified(cmp, PROPERTY_RENDER_PERCENTAGE_ON_TOP)) {
                        build.append("renderPercentageOnTop=\"");
                        build.append(sld.isRenderPercentageOnTop());
                        build.append("\" ");
                    }
                }
            }
            if (isPropertyModified(cmp, PROPERTY_RADIO_GROUP)) {
                build.append("group=\"");
                build.append(xmlize(((com.codename1.ui.RadioButton) cmp).getGroup()));
                build.append("\" ");
            }
            if (isPropertyModified(cmp, PROPERTY_SELECTED)) {
                build.append("selected=\"");
                build.append(((com.codename1.ui.Button) cmp).isSelected());
                build.append("\" ");
            }
            if (isPropertyModified(cmp, PROPERTY_GAP)) {
                build.append("gap=\"");
                build.append(lbl.getGap());
                build.append("\" ");
            }
            if (isPropertyModified(cmp, PROPERTY_VERTICAL_ALIGNMENT)) {
                build.append("verticalAlignment=\"");
                build.append(lbl.getVerticalAlignment());
                build.append("\" ");
            }
            if (isPropertyModified(cmp, PROPERTY_TEXT_POSITION)) {
                build.append("textPosition=\"");
                build.append(lbl.getTextPosition());
                build.append("\" ");
            }
        } else {
            if (cmp instanceof com.codename1.ui.TextArea) {
                com.codename1.ui.TextArea txt = (com.codename1.ui.TextArea) cmp;
                if (isPropertyModified(cmp, PROPERTY_VERTICAL_ALIGNMENT)) {
                    build.append("verticalAlignment=\"");
                    build.append(txt.getVerticalAlignment());
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_TEXT)) {
                    build.append("text=\"");
                    build.append(xmlize(txt.getText()));
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_TEXT_AREA_GROW)) {
                    build.append("growByContent=\"");
                    build.append(txt.isGrowByContent());
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_TEXT_CONSTRAINT)) {
                    build.append("constraint=\"");
                    build.append(txt.getConstraint());
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_TEXT_MAX_LENGTH)) {
                    build.append("maxSize=\"");
                    build.append(txt.getMaxSize());
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_EDITABLE)) {
                    build.append("editable=\"");
                    build.append(txt.isEditable());
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_ALIGNMENT)) {
                    build.append("alignment=\"");
                    build.append(txt.getAlignment());
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_HINT)) {
                    build.append("hint=\"");
                    build.append(xmlize(txt.getHint()));
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_HINT_ICON) && txt.getHintIcon() != null) {
                    build.append("hintIcon=\"");
                    build.append(xmlize(res.findId(txt.getHintIcon())));
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_COLUMNS)) {
                    build.append("columns=\"");
                    build.append(txt.getColumns());
                    build.append("\" ");
                }
                if (isPropertyModified(cmp, PROPERTY_ROWS)) {
                    build.append("rows=\"");
                    build.append(txt.getRows());
                    build.append("\" ");
                }
            } else {
                if (cmp instanceof com.codename1.ui.List) {
                    com.codename1.ui.List lst = (com.codename1.ui.List) cmp;
                    if (isPropertyModified(cmp, PROPERTY_ITEM_GAP)) {
                        build.append("itemGap=\"");
                        build.append(lst.getItemGap());
                        build.append("\" ");
                    }
                    if (isPropertyModified(cmp, PROPERTY_LIST_FIXED)) {
                        build.append("fixedSelection=\"");
                        build.append(lst.getFixedSelection());
                        build.append("\" ");
                    }
                    if (isPropertyModified(cmp, PROPERTY_LIST_ORIENTATION)) {
                        build.append("orientation=\"");
                        build.append(lst.getOrientation());
                        build.append("\" ");
                    }
                    if (isPropertyModified(cmp, PROPERTY_HINT)) {
                        build.append("hint=\"");
                        build.append(xmlize(lst.getHint()));
                        build.append("\" ");
                    }
                    if (isPropertyModified(cmp, PROPERTY_HINT_ICON) && lst.getHintIcon() != null) {
                        build.append("hintIcon=\"");
                        build.append(xmlize(res.findId(lst.getHintIcon())));
                        build.append("\" ");
                    }
                    if (isPropertyModified(cmp, PROPERTY_LIST_RENDERER) && lst.getRenderer() instanceof com.codename1.ui.list.GenericListCellRenderer) {
                        com.codename1.ui.list.GenericListCellRenderer g = (com.codename1.ui.list.GenericListCellRenderer) lst.getRenderer();
                        if (g.getSelectedEven() == null) {
                            build.append(" selectedRenderer=\"");
                            build.append(xmlize(g.getSelected().getName()));
                            build.append("\" unselectedRenderer=\"");
                            build.append(xmlize(g.getUnselected().getName()));
                            build.append("\" ");
                        } else {
                            build.append(" selectedRenderer=\"");
                            build.append(xmlize(g.getSelected().getName()));
                            build.append("\" unselectedRenderer=\"");
                            build.append(xmlize(g.getUnselected().getName()));
                            build.append(" selectedRendererEven=\"");
                            build.append(xmlize(g.getSelectedEven().getName()));
                            build.append("\" unselectedRendererEven=\"");
                            build.append(xmlize(g.getUnselectedEven().getName()));
                            build.append("\" ");
                        }
                    }
                }
            }
        }
        build.append(">\n");
        appendComponentXMLBody(containerInstance, cmp, build, res, indent + "  ");
        build.append(indent);
        build.append("</component>\n");
    }
}
Also used : JLabel(javax.swing.JLabel) EmbeddedContainer(com.codename1.ui.util.EmbeddedContainer) BorderLayout(com.codename1.ui.layouts.BorderLayout) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) List(java.util.List) JList(javax.swing.JList) EmbeddedContainer(com.codename1.ui.util.EmbeddedContainer) BorderLayout(com.codename1.ui.layouts.BorderLayout) TableLayout(com.codename1.ui.table.TableLayout) Hashtable(java.util.Hashtable) Point(java.awt.Point)

Example 10 with Command

use of com.codename1.ui.Command 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)

Aggregations

BorderLayout (com.codename1.ui.layouts.BorderLayout)25 Command (com.codename1.ui.Command)24 ActionEvent (com.codename1.ui.events.ActionEvent)22 Form (com.codename1.ui.Form)20 Hashtable (java.util.Hashtable)13 UIManager (com.codename1.ui.plaf.UIManager)11 Container (com.codename1.ui.Container)10 ActionListener (com.codename1.ui.events.ActionListener)10 GridLayout (com.codename1.ui.layouts.GridLayout)9 Button (com.codename1.ui.Button)8 Style (com.codename1.ui.plaf.Style)8 IOException (java.io.IOException)7 Vector (java.util.Vector)7 Component (com.codename1.ui.Component)6 Dialog (com.codename1.ui.Dialog)6 BoxLayout (com.codename1.ui.layouts.BoxLayout)6 ArrayList (java.util.ArrayList)6 RadioButton (com.codename1.ui.RadioButton)5 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)5 CheckBox (com.codename1.ui.CheckBox)4