use of com.codename1.ui.List 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");
}
}
use of com.codename1.ui.List 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;
}
}
use of com.codename1.ui.List in project CodenameOne by codenameone.
the class ResourceEditorView method generateStateMachineCodeImpl.
private static String generateStateMachineCodeImpl(String uiResourceName, File destFile, boolean promptUserForPackageName, EditableResources loadResources, java.awt.Component errorParent) {
String packageString = "";
File currentFile = destFile;
while (currentFile.getParent() != null) {
String shortName = currentFile.getParentFile().getName();
if (shortName.equalsIgnoreCase("src")) {
break;
}
if (shortName.indexOf(':') > -1 || shortName.length() == 0) {
break;
}
if (shortName.equalsIgnoreCase("org") || shortName.equalsIgnoreCase("com") || shortName.equalsIgnoreCase("net") || shortName.equalsIgnoreCase("gov")) {
if (packageString.length() > 0) {
packageString = shortName + "." + packageString;
} else {
packageString = shortName;
}
break;
}
if (packageString.length() > 0) {
packageString = shortName + "." + packageString;
} else {
packageString = shortName;
}
currentFile = currentFile.getParentFile();
}
final Map<String, String> nameToClassLookup = new HashMap<String, String>();
final Map<String, Integer> commandMap = new HashMap<String, Integer>();
final List<Integer> unhandledCommands = new ArrayList<Integer>();
final List<String[]> actionComponents = new ArrayList<String[]>();
final Map<String, String> allComponents = new HashMap<String, String>();
initCommandMapAndNameToClassLookup(nameToClassLookup, commandMap, unhandledCommands, actionComponents, allComponents);
// list all the .ovr files and add them to the nameToClassLookup
if (loadedFile != null && loadedFile.getParentFile() != null) {
File overrideDir = new File(loadedFile.getParentFile().getParentFile(), "override");
if (overrideDir.exists()) {
File[] ovrFiles = overrideDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File file, String string) {
return string.endsWith(".ovr");
}
});
for (File ovr : ovrFiles) {
try {
EditableResources er = EditableResources.open(new FileInputStream(ovr));
for (String currentResourceName : er.getUIResourceNames()) {
UIBuilder b = new UIBuilder() {
protected com.codename1.ui.Component createComponentInstance(String componentType, Class cls) {
if (cls.getName().startsWith("com.codename1.ui.")) {
// subpackage of CodenameOne should be registered
if (cls.getName().lastIndexOf(".") > 15) {
nameToClassLookup.put(componentType, cls.getName());
}
} else {
nameToClassLookup.put(componentType, cls.getName());
}
return null;
}
};
b.createContainer(er, currentResourceName);
}
} catch (IOException ioErr) {
ioErr.printStackTrace();
}
}
}
}
if (promptUserForPackageName) {
JTextField packageName = new JTextField(packageString);
JOptionPane.showMessageDialog(errorParent, packageName, "Please Pick The Package Name", JOptionPane.PLAIN_MESSAGE);
packageString = packageName.getText();
}
List<String> createdMethodNames = new ArrayList<String>();
try {
Writer w = new FileWriter(destFile);
w.write("/**\n");
w.write(" * This class contains generated code from the Codename One Designer, DO NOT MODIFY!\n");
w.write(" * This class is designed for subclassing that way the code generator can overwrite it\n");
w.write(" * anytime without erasing your changes which should exist in a subclass!\n");
w.write(" * For details about this file and how it works please read this blog post:\n");
w.write(" * http://codenameone.blogspot.com/2010/10/ui-builder-class-how-to-actually-use.html\n");
w.write("*/\n");
if (packageString.length() > 0) {
w.write("package " + packageString + ";\n\n");
}
String className = destFile.getName().substring(0, destFile.getName().indexOf('.'));
boolean hasIo = false;
for (String currentName : nameToClassLookup.keySet()) {
if (nameToClassLookup.get(currentName).indexOf("com.codename1.ui.io") > -1) {
hasIo = true;
break;
}
}
w.write("import com.codename1.ui.*;\n");
w.write("import com.codename1.ui.util.*;\n");
w.write("import com.codename1.ui.plaf.*;\n");
w.write("import java.util.Hashtable;\n");
if (hasIo) {
w.write("import com.codename1.ui.io.*;\n");
w.write("import com.codename1.components*;\n");
}
w.write("import com.codename1.ui.events.*;\n\n");
w.write("public abstract class " + className + " extends UIBuilder {\n");
w.write(" private Container aboutToShowThisContainer;\n");
w.write(" /**\n");
w.write(" * this method should be used to initialize variables instead of\n");
w.write(" * the constructor/class scope to avoid race conditions\n");
w.write(" */\n");
w.write(" /**\n * @deprecated use the version that accepts a resource as an argument instead\n \n**/\n");
w.write(" protected void initVars() {}\n\n");
w.write(" protected void initVars(Resources res) {}\n\n");
w.write(" public " + className + "(Resources res, String resPath, boolean loadTheme) {\n");
w.write(" startApp(res, resPath, loadTheme);\n");
w.write(" }\n\n");
w.write(" public Container startApp(Resources res, String resPath, boolean loadTheme) {\n");
w.write(" initVars();\n");
if (hasIo) {
w.write(" NetworkManager.getInstance().start();\n");
}
for (String currentName : nameToClassLookup.keySet()) {
w.write(" UIBuilder.registerCustomComponent(\"" + currentName + "\", " + nameToClassLookup.get(currentName) + ".class);\n");
}
w.write(" if(loadTheme) {\n");
w.write(" if(res == null) {\n");
w.write(" try {\n");
w.write(" if(resPath.endsWith(\".res\")) {\n");
w.write(" res = Resources.open(resPath);\n");
w.write(" System.out.println(\"Warning: you should construct the state machine without the .res extension to allow theme overlays\");\n");
w.write(" } else {\n");
w.write(" res = Resources.openLayered(resPath);\n");
w.write(" }\n");
w.write(" } catch(java.io.IOException err) { err.printStackTrace(); }\n");
w.write(" }\n");
w.write(" initTheme(res);\n");
w.write(" }\n");
w.write(" if(res != null) {\n");
w.write(" setResourceFilePath(resPath);\n");
w.write(" setResourceFile(res);\n");
w.write(" initVars(res);\n");
w.write(" return showForm(getFirstFormName(), null);\n");
w.write(" } else {\n");
w.write(" Form f = (Form)createContainer(resPath, getFirstFormName());\n");
w.write(" initVars(fetchResourceFile());\n");
w.write(" beforeShow(f);\n");
w.write(" f.show();\n");
w.write(" postShow(f);\n");
w.write(" return f;\n");
w.write(" }\n");
w.write(" }\n\n");
w.write(" protected String getFirstFormName() {\n");
w.write(" return \"" + uiResourceName + "\";\n");
w.write(" }\n\n");
w.write(" public Container createWidget(Resources res, String resPath, boolean loadTheme) {\n");
w.write(" initVars();\n");
if (hasIo) {
w.write(" NetworkManager.getInstance().start();\n");
}
for (String currentName : nameToClassLookup.keySet()) {
w.write(" UIBuilder.registerCustomComponent(\"" + currentName + "\", " + nameToClassLookup.get(currentName) + ".class);\n");
}
w.write(" if(loadTheme) {\n");
w.write(" if(res == null) {\n");
w.write(" try {\n");
w.write(" res = Resources.openLayered(resPath);\n");
w.write(" } catch(java.io.IOException err) { err.printStackTrace(); }\n");
w.write(" }\n");
w.write(" initTheme(res);\n");
w.write(" }\n");
w.write(" return createContainer(resPath, \"" + uiResourceName + "\");\n");
w.write(" }\n\n");
w.write(" protected void initTheme(Resources res) {\n");
w.write(" String[] themes = res.getThemeResourceNames();\n");
w.write(" if(themes != null && themes.length > 0) {\n");
w.write(" UIManager.getInstance().setThemeProps(res.getTheme(themes[0]));\n");
w.write(" }\n");
w.write(" }\n\n");
w.write(" public " + className + "() {\n");
w.write(" }\n\n");
w.write(" public " + className + "(String resPath) {\n");
w.write(" this(null, resPath, true);\n");
w.write(" }\n\n");
w.write(" public " + className + "(Resources res) {\n");
w.write(" this(res, null, true);\n");
w.write(" }\n\n");
w.write(" public " + className + "(String resPath, boolean loadTheme) {\n");
w.write(" this(null, resPath, loadTheme);\n");
w.write(" }\n\n");
w.write(" public " + className + "(Resources res, boolean loadTheme) {\n");
w.write(" this(res, null, loadTheme);\n");
w.write(" }\n\n");
for (String componentName : allComponents.keySet()) {
String componentType = allComponents.get(componentName);
String methodName = " find" + normalizeFormName(componentName);
// exists without a space might trigger this situation and thus code that won't compile
if (!createdMethodNames.contains(methodName)) {
if (componentType.equals("com.codename1.ui.Form") || componentType.equals("com.codename1.ui.Dialog")) {
continue;
}
createdMethodNames.add(methodName);
w.write(" public " + componentType + methodName + "(Component root) {\n");
w.write(" return (" + componentType + ")" + "findByName(\"" + componentName + "\", root);\n");
w.write(" }\n\n");
w.write(" public " + componentType + methodName + "() {\n");
w.write(" " + componentType + " cmp = (" + componentType + ")" + "findByName(\"" + componentName + "\", Display.getInstance().getCurrent());\n");
w.write(" if(cmp == null && aboutToShowThisContainer != null) {\n");
w.write(" cmp = (" + componentType + ")" + "findByName(\"" + componentName + "\", aboutToShowThisContainer);\n");
w.write(" }\n");
w.write(" return cmp;\n");
w.write(" }\n\n");
}
}
if (commandMap.size() > 0) {
for (String key : commandMap.keySet()) {
w.write(" public static final int COMMAND_" + key + " = " + commandMap.get(key) + ";\n");
}
w.write("\n");
StringBuilder methodSwitch = new StringBuilder(" protected void processCommand(ActionEvent ev, Command cmd) {\n switch(cmd.getId()) {\n");
for (String key : commandMap.keySet()) {
String camelCase = "on" + key;
boolean isAbstract = unhandledCommands.contains(commandMap.get(key));
if (isAbstract) {
w.write(" protected abstract void ");
w.write(camelCase);
w.write("();\n\n");
} else {
w.write(" protected boolean ");
w.write(camelCase);
w.write("() {\n return false;\n }\n\n");
}
methodSwitch.append(" case COMMAND_");
methodSwitch.append(key);
methodSwitch.append(":\n");
methodSwitch.append(" ");
if (isAbstract) {
methodSwitch.append(camelCase);
methodSwitch.append("();\n break;\n\n");
} else {
methodSwitch.append("if(");
methodSwitch.append(camelCase);
methodSwitch.append("()) {\n ev.consume();\n return;\n }\n break;\n\n");
}
}
methodSwitch.append(" }\n if(ev.getComponent() != null) {\n handleComponentAction(ev.getComponent(), ev);\n }\n }\n\n");
w.write(methodSwitch.toString());
}
writeFormCallbackCode(w, " protected void exitForm(Form f) {\n", "f.getName()", "exit", "f", "Form f");
writeFormCallbackCode(w, " protected void beforeShow(Form f) {\n aboutToShowThisContainer = f;\n", "f.getName()", "before", "f", "Form f");
writeFormCallbackCode(w, " protected void beforeShowContainer(Container c) {\n aboutToShowThisContainer = c;\n", "c.getName()", "beforeContainer", "c", "Container c");
writeFormCallbackCode(w, " protected void postShow(Form f) {\n", "f.getName()", "post", "f", "Form f");
writeFormCallbackCode(w, " protected void postShowContainer(Container c) {\n", "c.getName()", "postContainer", "c", "Container c");
writeFormCallbackCode(w, " protected void onCreateRoot(String rootName) {\n", "rootName", "onCreate", "", "");
writeFormCallbackCode(w, " protected Hashtable getFormState(Form f) {\n Hashtable h = super.getFormState(f);\n", "f.getName()", "getState", "f, h", "Form f, Hashtable h", "return h;");
writeFormCallbackCode(w, " protected void setFormState(Form f, Hashtable state) {\n super.setFormState(f, state);\n", "f.getName()", "setState", "f, state", "Form f, Hashtable state");
List<String> listComponents = new ArrayList<String>();
for (String currentName : allComponents.keySet()) {
String value = allComponents.get(currentName);
if (value.equals("com.codename1.ui.List") || value.equals("com.codename1.ui.ComboBox") || value.equals("com.codename1.ui.list.MultiList") || value.equals("com.codename1.ui.Calendar")) {
listComponents.add(currentName);
}
}
List<String> containerListComponents = new ArrayList<String>();
for (String currentName : allComponents.keySet()) {
String value = allComponents.get(currentName);
if (value.equals("com.codename1.ui.list.ContainerList")) {
containerListComponents.add(currentName);
}
}
if (listComponents.size() > 0) {
w.write(" protected boolean setListModel(List cmp) {\n");
w.write(" String listName = cmp.getName();\n");
for (String listName : listComponents) {
w.write(" if(\"");
w.write(listName);
w.write("\".equals(listName)) {\n");
w.write(" return initListModel");
w.write(normalizeFormName(listName));
w.write("(cmp);\n }\n");
}
w.write(" return super.setListModel(cmp);\n }\n\n");
for (String listName : listComponents) {
w.write(" protected boolean initListModel");
w.write(normalizeFormName(listName));
w.write("(List cmp) {\n");
w.write(" return false;\n }\n\n");
}
}
if (containerListComponents.size() > 0) {
w.write(" protected boolean setListModel(com.codename1.ui.list.ContainerList cmp) {\n");
w.write(" String listName = cmp.getName();\n");
for (String listName : containerListComponents) {
w.write(" if(\"");
w.write(listName);
w.write("\".equals(listName)) {\n");
w.write(" return initListModel");
w.write(normalizeFormName(listName));
w.write("(cmp);\n }\n");
}
w.write(" return super.setListModel(cmp);\n }\n\n");
for (String listName : containerListComponents) {
w.write(" protected boolean initListModel");
w.write(normalizeFormName(listName));
w.write("(com.codename1.ui.list.ContainerList cmp) {\n");
w.write(" return false;\n }\n\n");
}
}
if (actionComponents.size() > 0) {
Object lastFormName = null;
StringBuilder methods = new StringBuilder();
w.write(" protected void handleComponentAction(Component c, ActionEvent event) {\n");
w.write(" Container rootContainerAncestor = getRootAncestor(c);\n");
w.write(" if(rootContainerAncestor == null) return;\n");
w.write(" String rootContainerName = rootContainerAncestor.getName();\n");
w.write(" Container leadParentContainer = c.getParent().getLeadParent();\n");
w.write(" if(leadParentContainer != null && leadParentContainer.getClass() != Container.class) {\n");
w.write(" c = c.getParent().getLeadParent();\n");
w.write(" }\n");
w.write(" if(rootContainerName == null) return;\n");
for (String[] currentCmp : actionComponents) {
if (lastFormName != currentCmp[1]) {
if (lastFormName != null) {
w.write(" }\n");
}
w.write(" if(rootContainerName.equals(\"");
w.write(currentCmp[1]);
w.write("\")) {\n");
lastFormName = currentCmp[1];
}
w.write(" if(\"");
w.write(currentCmp[0]);
w.write("\".equals(c.getName())) {\n");
String methodName = "on" + normalizeFormName(currentCmp[1]) + "_" + normalizeFormName(currentCmp[0]) + "Action";
w.write(" ");
w.write(methodName);
w.write("(c, event);\n");
w.write(" return;\n");
w.write(" }\n");
methods.append(" protected void ");
methods.append(methodName);
methods.append("(Component c, ActionEvent event) {\n }\n\n");
}
w.write(" }\n }\n\n");
w.write(methods.toString());
}
w.write("}\n");
w.close();
} catch (IOException ioErr) {
ioErr.printStackTrace();
JOptionPane.showMessageDialog(errorParent, "IO Error: " + ioErr, "IO Error", JOptionPane.ERROR_MESSAGE);
}
return packageString;
}
use of com.codename1.ui.List in project CodenameOne by codenameone.
the class ResourceEditorView method initImagesComboBox.
/**
* Creates a sorted image combo box that includes image previews. The combo box
* can be searched by typing a letter even when images are used for the values...
*/
public static void initImagesComboBox(JComboBox cb, final EditableResources res, boolean asString, final boolean includeNull, boolean blockTimelines) {
String[] imgs = res.getImageResourceNames();
if (blockTimelines) {
List<String> nonT = new ArrayList<String>();
for (String c : imgs) {
if (!(res.getImage(c) instanceof Timeline)) {
nonT.add(c);
}
}
imgs = new String[nonT.size()];
nonT.toArray(imgs);
}
final String[] images = imgs;
Arrays.sort(images, String.CASE_INSENSITIVE_ORDER);
if (asString) {
if (includeNull) {
String[] n = new String[images.length + 1];
System.arraycopy(images, 0, n, 1, images.length);
cb.setModel(new DefaultComboBoxModel(n));
} else {
cb.setModel(new DefaultComboBoxModel(images));
}
cb.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
boolean n = false;
if (value == null) {
value = "[null]";
n = true;
}
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (!n) {
setIcon(new CodenameOneImageIcon(res.getImage((String) value), 24, 24));
} else {
setIcon(null);
}
return this;
}
});
} else {
int offset = 0;
com.codename1.ui.Image[] arr;
if (includeNull) {
arr = new com.codename1.ui.Image[images.length + 1];
offset++;
} else {
arr = new com.codename1.ui.Image[images.length];
}
for (String c : images) {
arr[offset] = res.getImage(c);
offset++;
}
cb.setModel(new DefaultComboBoxModel(arr));
cb.setKeySelectionManager(new JComboBox.KeySelectionManager() {
private String current;
private long lastPress;
public int selectionForKey(char aKey, ComboBoxModel aModel) {
long t = System.currentTimeMillis();
aKey = Character.toLowerCase(aKey);
if (t - lastPress < 800) {
current += aKey;
} else {
current = "" + aKey;
}
lastPress = t;
for (int iter = 0; iter < images.length; iter++) {
if (images[iter].toLowerCase().startsWith(current)) {
if (includeNull) {
return iter + 1;
}
return iter;
}
}
return -1;
}
});
cb.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
com.codename1.ui.Image i = (com.codename1.ui.Image) value;
if (value == null) {
value = "[null]";
} else {
value = res.findId(value);
}
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (i != null) {
setIcon(new CodenameOneImageIcon(i, 24, 24));
} else {
setIcon(null);
}
return this;
}
});
}
}
use of com.codename1.ui.List in project CodenameOne by codenameone.
the class ResourceEditorView method imageSizesActionPerformed.
// GEN-LAST:event_pulsateEffectActionPerformed
private void imageSizesActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_imageSizesActionPerformed
class ImageSize {
String name;
int size;
}
int total = 0;
Vector images = new Vector();
for (String imageName : loadedResources.getImageResourceNames()) {
com.codename1.ui.Image img = loadedResources.getImage(imageName);
ImageSize size = new ImageSize();
size.name = imageName;
Object o = loadedResources.getResourceObject(imageName);
// special case for multi image which can be all of the internal images...
if (o instanceof EditableResources.MultiImage) {
for (Object c : ((EditableResources.MultiImage) o).getInternalImages()) {
size.size += ((com.codename1.ui.EncodedImage) c).getImageData().length;
}
images.add(size);
} else {
if (img instanceof com.codename1.ui.EncodedImage) {
size.size = ((com.codename1.ui.EncodedImage) img).getImageData().length;
images.add(size);
} else {
if (img.isSVG()) {
SVG s = (SVG) img.getSVGDocument();
size.size = s.getSvgData().length;
images.add(size);
}
}
}
total += size.size;
}
Collections.sort(images, new Comparator() {
public int compare(Object o1, Object o2) {
ImageSize i1 = (ImageSize) o1;
ImageSize i2 = (ImageSize) o2;
return i2.size - i1.size;
}
});
JPanel p = new JPanel(new java.awt.BorderLayout());
JList list = new JList(images);
p.add(java.awt.BorderLayout.NORTH, new JLabel("Total " + (total / 1024) + "kb in " + loadedResources.getImageResourceNames().length + " images"));
p.add(java.awt.BorderLayout.CENTER, new JScrollPane(list));
list.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
ImageSize s = (ImageSize) value;
value = s.name + " " + (s.size / 1024) + "kb (" + s.size + "b)";
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
JOptionPane.showMessageDialog(mainPanel, p, "Sizes", JOptionPane.PLAIN_MESSAGE);
}
Aggregations