Search in sources :

Example 36 with com.codename1.rad.ui

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

the class TimelineEditor method duplicateObjectActionPerformed.

// GEN-LAST:event_removeAnimationObjectActionPerformed
private void duplicateObjectActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_duplicateObjectActionPerformed
    Timeline t = cloneCurrentTimeline();
    AnimationObject o = AnimationAccessor.clone((AnimationObject) ((AnimationObjectTableModel) animationObjectList.getModel()).getElementAt(animationObjectList.getSelectedRow()));
    ((AnimationObjectTableModel) animationObjectList.getModel()).addElement(o);
    AnimationObject[] animations = new AnimationObject[t.getAnimationCount() + 1];
    for (int iter = 0; iter < animations.length - 1; iter++) {
        animations[iter] = t.getAnimation(iter);
    }
    animations[animations.length - 1] = o;
    Timeline nt = Timeline.createTimeline(getValue(duration), animations, new com.codename1.ui.geom.Dimension(getValue(width), getValue(height)));
    nt.setPause(t.isPause());
    setImage(nt);
    animationObjectList.clearSelection();
    duplicateObject.setEnabled(false);
    moveDown.setEnabled(false);
    moveUp.setEnabled(false);
    removeAnimationObject.setEnabled(false);
}
Also used : Timeline(com.codename1.ui.animations.Timeline) AnimationObject(com.codename1.ui.animations.AnimationObject) Point(java.awt.Point)

Example 37 with com.codename1.rad.ui

use of com.codename1.rad.ui 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 38 with com.codename1.rad.ui

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

the class UserInterfaceEditor method postCreateComponent.

public static void postCreateComponent(com.codename1.ui.Component cmp, DataOutputStream out, EditableResources res) throws IOException {
    if (isPropertyModified(cmp, PROPERTY_COMMAND) || isPropertyModified(cmp, PROPERTY_COMMAND_LEGACY)) {
        out.writeUTF(cmp.getName());
        out.writeInt(PROPERTY_COMMAND);
        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();
        }
        out.writeUTF(cmd.getCommandName());
        if (cmd.getIcon() != null) {
            out.writeUTF(res.findId(cmd.getIcon()));
        } else {
            out.writeUTF("");
        }
        if (cmd.getRolloverIcon() != null) {
            out.writeUTF(res.findId(cmd.getRolloverIcon()));
        } else {
            out.writeUTF("");
        }
        if (cmd.getPressedIcon() != null) {
            out.writeUTF(res.findId(cmd.getPressedIcon()));
        } else {
            out.writeUTF("");
        }
        if (cmd.getDisabledIcon() != null) {
            out.writeUTF(res.findId(cmd.getDisabledIcon()));
        } else {
            out.writeUTF("");
        }
        out.writeInt(cmd.getId());
        if (cmd.getAction() != null) {
            out.writeUTF(cmd.getAction());
            if (cmd.getAction().equals("$Execute")) {
                out.writeUTF(cmd.getArgument());
            }
        } else {
            out.writeUTF("");
        }
        out.writeBoolean(cmp.getComponentForm().getBackCommand() == cmd || cmd.isBackCommand());
    }
    if (isPropertyModified(cmp, PROPERTY_LABEL_FOR)) {
        if (cmp.getLabelForComponent() != null) {
            out.writeUTF(cmp.getName());
            out.writeInt(PROPERTY_LABEL_FOR);
            out.writeUTF(cmp.getLabelForComponent().getName());
        }
    }
    if (isPropertyModified(cmp, PROPERTY_LEAD_COMPONENT) && ((com.codename1.ui.Container) cmp).getLeadComponent() != null) {
        out.writeUTF(cmp.getName());
        out.writeInt(PROPERTY_LEAD_COMPONENT);
        out.writeUTF(((com.codename1.ui.Container) cmp).getLeadComponent().getName());
    }
    if (isPropertyModified(cmp, PROPERTY_NEXT_FOCUS_DOWN) && cmp.getNextFocusDown() != null) {
        out.writeUTF(cmp.getName());
        out.writeInt(PROPERTY_NEXT_FOCUS_DOWN);
        out.writeUTF(cmp.getNextFocusDown().getName());
    }
    if (isPropertyModified(cmp, PROPERTY_NEXT_FOCUS_UP) && cmp.getNextFocusUp() != null) {
        out.writeUTF(cmp.getName());
        out.writeInt(PROPERTY_NEXT_FOCUS_UP);
        out.writeUTF(cmp.getNextFocusUp().getName());
    }
    if (isPropertyModified(cmp, PROPERTY_NEXT_FOCUS_LEFT) && cmp.getNextFocusLeft() != null) {
        out.writeUTF(cmp.getName());
        out.writeInt(PROPERTY_NEXT_FOCUS_LEFT);
        out.writeUTF(cmp.getNextFocusLeft().getName());
    }
    if (isPropertyModified(cmp, PROPERTY_NEXT_FOCUS_RIGHT) && cmp.getNextFocusRight() != null) {
        out.writeUTF(cmp.getName());
        out.writeInt(PROPERTY_NEXT_FOCUS_RIGHT);
        out.writeUTF(cmp.getNextFocusRight().getName());
    }
    if (isActualContainer(cmp)) {
        com.codename1.ui.Container c = (com.codename1.ui.Container) cmp;
        for (int iter = 0; iter < c.getComponentCount(); iter++) {
            postCreateComponent(c.getComponentAt(iter), out, res);
        }
    }
}
Also used : EmbeddedContainer(com.codename1.ui.util.EmbeddedContainer) JButton(javax.swing.JButton) Point(java.awt.Point)

Example 39 with com.codename1.rad.ui

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

the class UserInterfaceEditor method createCustomComponentButton.

private void createCustomComponentButton(final CustomComponent c) {
    try {
        final JButton b = new JButton(c.getType());
        b.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/jdesktop/swingx/resources/placeholder32.png")));
        b.setHorizontalAlignment(SwingConstants.LEFT);
        b.setBorder(null);
        userComponents.add(b);
        b.putClientProperty("CustomComponent", c);
        final Class codenameOneBaseClass = c.getCls();
        makeDraggable(b, codenameOneBaseClass, c.getType(), c);
        b.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (lockForDragging) {
                    lockForDragging = false;
                    return;
                }
                try {
                    if (c.isUiResource()) {
                        UIBuilderOverride u = new UIBuilderOverride();
                        com.codename1.ui.Component cmp = u.createContainer(res, c.getType());
                        String t = (String) cmp.getClientProperty(TYPE_KEY);
                        if (t == null) {
                            cmp.putClientProperty(TYPE_KEY, c.getType());
                            t = c.getType();
                        }
                        addComponentToContainer(cmp, t);
                        return;
                    }
                    com.codename1.ui.Component cmp = (com.codename1.ui.Component) codenameOneBaseClass.newInstance();
                    cmp.putClientProperty("CustomComponent", c);
                    cmp.putClientProperty(TYPE_KEY, c.getType());
                    initializeComponentText(cmp);
                    addComponentToContainer(cmp, c.getType());
                } catch (Exception err) {
                    err.printStackTrace();
                    JOptionPane.showMessageDialog(UserInterfaceEditor.this, err.getClass().getName() + ": " + err, "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });
    /*b.addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    if(BaseForm.isRightClick(e)) {
                        JPopupMenu p = new JPopupMenu();
                        AbstractAction deleteAction = new AbstractAction("Delete") {
                            public void actionPerformed(ActionEvent e) {
                                componentPalette.remove(b);
                                componentPalette.revalidate();
                                customComponents.remove(c);
                                res.setUi(name, persistContainer(containerInstance));
                            }
                        };
                        p.add(deleteAction);
                        p.show(b, e.getPoint().x, e.getPoint().y);
                    }
                }
            });*/
    } catch (Exception err) {
        err.printStackTrace();
        JOptionPane.showMessageDialog(UserInterfaceEditor.this, err.getClass().getName() + ": " + err, "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : UIBuilderOverride(com.codename1.ui.util.UIBuilderOverride) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) ActionListener(java.awt.event.ActionListener) ImageIcon(javax.swing.ImageIcon) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 40 with com.codename1.rad.ui

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

the class UserInterfaceEditor method addComponentToContainer.

private void addComponentToContainer(com.codename1.ui.Component c, String name) {
    if (c instanceof com.codename1.ui.Label || c instanceof com.codename1.ui.TextArea) {
        setPropertyModified(c, PROPERTY_TEXT);
    }
    c.putClientProperty(TYPE_KEY, name);
    c.setName(findUniqueName(name));
    com.codename1.ui.Container destContainer = containerInstance;
    if (componentHierarchy.getSelectionPath() != null) {
        com.codename1.ui.Component cmp = (com.codename1.ui.Component) componentHierarchy.getSelectionPath().getLastPathComponent();
        if (isActualContainer(cmp)) {
            destContainer = (com.codename1.ui.Container) cmp;
        } else {
            destContainer = cmp.getParent();
        }
    }
    if (destContainer instanceof com.codename1.ui.Tabs) {
        ((com.codename1.ui.Tabs) destContainer).addTab("Tab", c);
    } else {
        if (destContainer.getLayout() instanceof com.codename1.ui.layouts.BorderLayout) {
            destContainer.addComponent(findAvailableSpotInBorderLayout(destContainer), c);
        } else {
            destContainer.addComponent(c);
        }
    }
    containerInstance.revalidate();
    destContainer.revalidate();
    /*int[] index = new int[] {componentHierarchy.getModel().getIndexOfChild(c.getParent(), c)};
        Object[] children = new Object[] {c};
        c = c.getParent();
        Object[] path = pathToComponent(c);
        if(path != null && path.length > 0) {
            ((ComponentHierarchyModel)componentHierarchy.getModel()).fireTreeNodesInserted(
                    new TreeModelEvent(componentHierarchy.getModel(), new TreePath(path), index, children));
            uiPreview.repaint();
            saveUI();
        }*/
    ((ComponentHierarchyModel) componentHierarchy.getModel()).fireTreeStructureChanged(new TreeModelEvent(componentHierarchy.getModel(), new TreePath(componentHierarchy.getModel().getRoot())));
    uiPreview.repaint();
    saveUI();
}
Also used : TreeModelEvent(javax.swing.event.TreeModelEvent) BorderLayout(com.codename1.ui.layouts.BorderLayout) TreePath(javax.swing.tree.TreePath) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Aggregations

IOException (java.io.IOException)34 EncodedImage (com.codename1.ui.EncodedImage)28 ArrayList (java.util.ArrayList)27 Point (java.awt.Point)25 File (java.io.File)24 AnimationObject (com.codename1.ui.animations.AnimationObject)22 BufferedImage (java.awt.image.BufferedImage)22 Hashtable (java.util.Hashtable)19 Component (com.codename1.ui.Component)18 Form (com.codename1.ui.Form)18 Image (com.codename1.ui.Image)16 EditableResources (com.codename1.ui.util.EditableResources)16 FileInputStream (java.io.FileInputStream)16 Timeline (com.codename1.ui.animations.Timeline)15 BorderLayout (com.codename1.ui.layouts.BorderLayout)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 UIBuilderOverride (com.codename1.ui.util.UIBuilderOverride)11 FileOutputStream (java.io.FileOutputStream)10 AttributedString (java.text.AttributedString)10 EditorFont (com.codename1.ui.EditorFont)9