use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.
the class UserInterfaceEditor method appendComponentXMLBody.
private static void appendComponentXMLBody(com.codename1.ui.Container containerInstance, com.codename1.ui.Component cmp, StringBuilder build, EditableResources res, String indent) {
if (isPropertyModified(cmp, PROPERTY_LAYOUT_CONSTRAINT) || (cmp.getParent() != null && cmp.getParent().getLayout() instanceof com.codename1.ui.layouts.BorderLayout)) {
if (cmp.getParent() != null && cmp != containerInstance && cmp.getClientProperty("%base_form%") == null) {
com.codename1.ui.layouts.Layout l = cmp.getParent().getLayout();
if (l instanceof com.codename1.ui.layouts.BorderLayout) {
build.append(indent);
build.append("<layoutConstraint value=\"");
build.append((String) l.getComponentConstraint(cmp));
build.append("\" />\n");
} else {
if (l instanceof com.codename1.ui.table.TableLayout) {
build.append(indent);
com.codename1.ui.table.TableLayout.Constraint con = (com.codename1.ui.table.TableLayout.Constraint) l.getComponentConstraint(cmp);
build.append("<layoutConstraint row=\"");
build.append(getInt("row", con.getClass(), con));
build.append("\" column=\"");
build.append(getInt("column", con.getClass(), con));
build.append("\" height=\"");
build.append(getInt("height", con.getClass(), con));
build.append("\" width=\"");
build.append(getInt("width", con.getClass(), con));
build.append("\" align=\"");
build.append(getInt("align", con.getClass(), con));
build.append("\" spanHorizontal=\"");
build.append(getInt("spanHorizontal", con.getClass(), con));
build.append("\" valign=\"");
build.append(getInt("valign", con.getClass(), con));
build.append("\" spanVertical=\"");
build.append(getInt("spanVertical", con.getClass(), con));
build.append("\" />\n");
}
}
}
}
// don't persist children of subclasses like Table etc.
if (cmp.getClass() == com.codename1.ui.Container.class || cmp instanceof com.codename1.ui.Form || cmp instanceof com.codename1.ui.ComponentGroup) {
com.codename1.ui.Container cnt = (com.codename1.ui.Container) cmp;
if (cnt instanceof com.codename1.ui.Form) {
cnt = ((com.codename1.ui.Form) cnt).getContentPane();
}
for (int iter = 0; iter < cnt.getComponentCount(); iter++) {
persistToXML(containerInstance, cnt.getComponentAt(iter), build, res, indent);
}
}
if (cmp instanceof com.codename1.ui.List && !(cmp instanceof com.codename1.components.RSSReader)) {
com.codename1.ui.List lst = (com.codename1.ui.List) cmp;
for (int iter = 0; iter < lst.getModel().getSize(); iter++) {
Object o = lst.getModel().getItemAt(iter);
appendMapOrString(o, build, indent, res);
}
}
if (isPropertyModified(cmp, PROPERTY_CUSTOM)) {
for (String propName : cmp.getPropertyNames()) {
if (isCustomPropertyModified(cmp, propName) && !propName.startsWith("$")) {
build.append(indent);
build.append("<custom name=\"");
build.append(propName);
Class type = getPropertyCustomType(cmp, propName);
Object value = cmp.getPropertyValue(propName);
if (value == null) {
build.append("\" />\n");
continue;
}
if (type.isArray()) {
// 2d array
if (type.getComponentType().isArray()) {
build.append("\" type=\"");
build.append(type.getComponentType().getComponentType().getName());
build.append("\" array=\"true\" dimensions=\"2");
} else {
build.append("\" type=\"");
build.append(type.getComponentType().getName());
build.append("\" array=\"true\" dimensions=\"1");
}
} else {
build.append("\" type=\"");
build.append(type.getName());
}
build.append("\" ");
if (type == String.class) {
build.append("value=\"");
build.append(xmlize((String) value));
build.append("\" />\n");
continue;
}
if (type == String[].class) {
build.append(">\n");
String[] result = (String[]) value;
for (int i = 0; i < result.length; i++) {
build.append(indent);
build.append(" ");
build.append("<str>");
build.append(xmlize(result[i]));
build.append("</str>\n");
}
build.append(indent);
build.append("</custom>\n");
continue;
}
if (type == String[][].class) {
String[][] result = (String[][]) value;
build.append(">\n");
for (int i = 0; i < result.length; i++) {
build.append(indent);
build.append(" ");
build.append("<arr>");
for (int j = 0; j < result[i].length; j++) {
build.append(indent);
build.append(" ");
build.append("<str>");
build.append(xmlize(result[i][j]));
build.append("</str>\n");
}
build.append(indent);
build.append(" ");
build.append("</arr>\n");
}
build.append(indent);
build.append("</custom>\n");
continue;
}
if (type == Integer.class) {
build.append("value=\"");
build.append(((Number) value).intValue());
build.append("\" />\n");
continue;
}
if (type == Long.class) {
build.append("value=\"");
build.append(((Number) value).longValue());
build.append("\" />\n");
continue;
}
if (type == Double.class) {
build.append("value=\"");
build.append(((Number) value).doubleValue());
build.append("\" />\n");
continue;
}
if (type == Date.class) {
build.append("value=\"");
build.append(((Date) value).getTime());
build.append("\" />\n");
continue;
}
if (type == Float.class) {
build.append("value=\"");
build.append(((Number) value).floatValue());
build.append("\" />\n");
continue;
}
if (type == Byte.class) {
build.append("value=\"");
build.append(((Number) value).byteValue());
build.append("\" />\n");
continue;
}
if (type == Boolean.class) {
build.append("value=\"");
build.append(((Boolean) value).booleanValue());
build.append("\" />\n");
continue;
}
if (type == com.codename1.ui.Image[].class) {
com.codename1.ui.Image[] result = (com.codename1.ui.Image[]) value;
build.append(">\n");
for (int i = 0; i < result.length; i++) {
build.append(indent);
build.append(" ");
if (result[i] == null) {
build.append("<str/>\n");
} else {
String id = res.findId(result[i]);
if (id == null) {
build.append("<str/>\n");
} else {
build.append("<str>");
build.append(xmlize(id));
build.append("</str>\n");
}
}
}
build.append(indent);
build.append("</custom>\n");
continue;
}
if (type == com.codename1.ui.Image.class) {
com.codename1.ui.Image result = (com.codename1.ui.Image) value;
String id = res.findId(result);
if (id != null) {
build.append("value=\"");
build.append(xmlize(id));
}
build.append("\" />\n");
continue;
}
if (type == com.codename1.ui.Container.class) {
build.append("value=\"");
build.append(xmlize(((com.codename1.ui.Container) value).getName()));
build.append("\" />\n");
continue;
}
if (type == com.codename1.ui.list.CellRenderer.class) {
com.codename1.ui.list.GenericListCellRenderer g = (com.codename1.ui.list.GenericListCellRenderer) value;
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");
continue;
}
if (type == Object[].class) {
build.append(">\n");
Object[] arr = (Object[]) value;
for (int iter = 0; iter < arr.length; iter++) {
Object o = arr[iter];
appendMapOrString(o, build, indent, res);
}
build.append(indent);
build.append("</custom>\n");
continue;
}
// none of the above then its a char
build.append("value=\"");
build.append(xmlize("" + ((Character) value).charValue()));
build.append("\" />\n");
}
}
}
}
use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.
the class UserInterfaceEditor method persistComponent.
public static void persistComponent(com.codename1.ui.Container containerInstance, com.codename1.ui.Component cmp, DataOutputStream out, EditableResources res) throws IOException {
if (cmp.getClientProperty("%base_form%") != null) {
out.writeUTF((String) cmp.getClientProperty("%base_form%"));
out.writeInt(PROPERTY_BASE_FORM);
}
out.writeUTF((String) cmp.getClientProperty(TYPE_KEY));
out.writeInt(PROPERTY_NAME);
if (cmp.getName() != null) {
out.writeUTF(cmp.getName());
} else {
out.writeUTF("");
}
if (cmp.getClientProperty("cn1$Properties") != null) {
String[] p = ((String) cmp.getClientProperty("cn1$Properties")).split(",");
if (p.length > 0) {
out.writeInt(PROPERTY_CLIENT_PROPERTIES);
out.writeInt(p.length);
for (String c : p) {
out.writeUTF(c);
out.writeUTF((String) cmp.getClientProperty(c));
}
}
}
if (cmp.getCloudBoundProperty() != null) {
out.writeInt(PROPERTY_CLOUD_BOUND_PROPERTY);
out.writeUTF(cmp.getCloudBoundProperty());
}
if (cmp.getCloudDestinationProperty() != null) {
out.writeInt(PROPERTY_CLOUD_DESTINATION_PROPERTY);
out.writeUTF(cmp.getCloudDestinationProperty());
}
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)) {
out.writeInt(PROPERTY_SCROLLABLE_X);
out.writeBoolean(CodenameOneAccessor.isScrollableX(cnt));
}
if (isPropertyModified(cnt, PROPERTY_SCROLLABLE_Y)) {
out.writeInt(PROPERTY_SCROLLABLE_Y);
out.writeBoolean(CodenameOneAccessor.isScrollableY(cnt));
}
if (cmp instanceof com.codename1.ui.Tabs) {
com.codename1.ui.Tabs tab = (com.codename1.ui.Tabs) cmp;
out.writeInt(PROPERTY_COMPONENTS);
out.writeInt(tab.getTabCount());
for (int iter = 0; iter < tab.getTabCount(); iter++) {
out.writeUTF(tab.getTabTitle(iter));
persistComponent(containerInstance, tab.getTabComponentAt(iter), out, res);
}
if (isPropertyModified(cmp, PROPERTY_TAB_PLACEMENT)) {
out.writeInt(PROPERTY_TAB_PLACEMENT);
out.writeInt(((com.codename1.ui.Tabs) cmp).getTabPlacement());
}
if (isPropertyModified(cmp, PROPERTY_TAB_TEXT_POSITION)) {
out.writeInt(PROPERTY_TAB_TEXT_POSITION);
out.writeInt(((com.codename1.ui.Tabs) cmp).getTabTextPosition());
}
} else {
if (isPropertyModified(cmp, PROPERTY_LAYOUT)) {
com.codename1.ui.layouts.Layout l = cnt.getLayout();
out.writeInt(PROPERTY_LAYOUT);
if (l instanceof com.codename1.ui.layouts.FlowLayout) {
out.writeShort(LAYOUT_FLOW);
com.codename1.ui.layouts.FlowLayout f = (com.codename1.ui.layouts.FlowLayout) l;
out.writeBoolean(f.isFillRows());
out.writeInt(f.getAlign());
out.writeInt(f.getValign());
} else {
if (l instanceof com.codename1.ui.layouts.BorderLayout) {
out.writeShort(LAYOUT_BORDER);
com.codename1.ui.layouts.BorderLayout b = (com.codename1.ui.layouts.BorderLayout) l;
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);
out.writeBoolean(north != null);
if (north != null) {
out.writeUTF(north);
}
out.writeBoolean(east != null);
if (east != null) {
out.writeUTF(east);
}
out.writeBoolean(west != null);
if (west != null) {
out.writeUTF(west);
}
out.writeBoolean(south != null);
if (south != null) {
out.writeUTF(south);
}
out.writeBoolean(center != null);
if (center != null) {
out.writeUTF(center);
}
out.writeBoolean(b.isAbsoluteCenter());
} else {
if (l instanceof com.codename1.ui.layouts.GridLayout) {
out.writeShort(LAYOUT_GRID);
out.writeInt(((com.codename1.ui.layouts.GridLayout) l).getRows());
out.writeInt(((com.codename1.ui.layouts.GridLayout) l).getColumns());
} else {
if (l instanceof com.codename1.ui.layouts.BoxLayout) {
if (getInt("axis", l.getClass(), l) == com.codename1.ui.layouts.BoxLayout.X_AXIS) {
out.writeShort(LAYOUT_BOX_X);
} else {
out.writeShort(LAYOUT_BOX_Y);
}
} else {
if (l instanceof com.codename1.ui.table.TableLayout) {
out.writeShort(LAYOUT_TABLE);
out.writeInt(((com.codename1.ui.table.TableLayout) l).getRows());
out.writeInt(((com.codename1.ui.table.TableLayout) l).getColumns());
} else {
if (l instanceof com.codename1.ui.layouts.LayeredLayout) {
out.writeShort(LAYOUT_LAYERED);
}
}
}
}
}
}
}
if (cmp instanceof com.codename1.ui.Form) {
com.codename1.ui.Form frm = (com.codename1.ui.Form) cmp;
out.writeInt(PROPERTY_COMPONENTS);
out.writeInt(frm.getContentPane().getComponentCount());
for (int iter = 0; iter < frm.getContentPane().getComponentCount(); iter++) {
persistComponent(containerInstance, frm.getContentPane().getComponentAt(iter), out, res);
}
if (isPropertyModified(cmp, PROPERTY_NEXT_FORM) && frm.getClientProperty("%next_form%") != null) {
out.writeInt(PROPERTY_NEXT_FORM);
out.writeUTF((String) frm.getClientProperty("%next_form%"));
}
if (isPropertyModified(cmp, PROPERTY_TITLE)) {
out.writeInt(PROPERTY_TITLE);
out.writeUTF(frm.getTitle());
}
if (isPropertyModified(cmp, PROPERTY_CYCLIC_FOCUS)) {
out.writeInt(PROPERTY_CYCLIC_FOCUS);
out.writeBoolean(frm.isCyclicFocus());
}
if (isPropertyModified(cmp, PROPERTY_DIALOG_UIID) && cmp instanceof com.codename1.ui.Dialog) {
com.codename1.ui.Dialog dlg = (com.codename1.ui.Dialog) cmp;
out.writeInt(PROPERTY_DIALOG_UIID);
out.writeUTF(dlg.getDialogUIID());
}
if (isPropertyModified(cmp, PROPERTY_DISPOSE_WHEN_POINTER_OUT) && cmp instanceof com.codename1.ui.Dialog) {
com.codename1.ui.Dialog dlg = (com.codename1.ui.Dialog) cmp;
out.writeInt(PROPERTY_DISPOSE_WHEN_POINTER_OUT);
out.writeBoolean(dlg.isDisposeWhenPointerOutOfBounds());
}
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) {
out.writeInt(PROPERTY_DIALOG_POSITION);
out.writeUTF(dlg.getDialogPosition());
}
}
if (frm.getCommandCount() > 0 || frm.getBackCommand() != null) {
if (isPropertyModified(cmp, PROPERTY_COMMANDS) || isPropertyModified(cmp, PROPERTY_COMMANDS_LEGACY)) {
out.writeInt(PROPERTY_COMMANDS);
if (frm.getBackCommand() != null && !hasBackCommand(frm, frm.getBackCommand())) {
out.writeInt(frm.getCommandCount() + 1);
ActionCommand cmd = (ActionCommand) frm.getBackCommand();
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(frm.getBackCommand() == cmd);
} else {
out.writeInt(frm.getCommandCount());
}
for (int iter = frm.getCommandCount() - 1; iter >= 0; iter--) {
ActionCommand cmd = (ActionCommand) frm.getCommand(iter);
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(frm.getBackCommand() == cmd);
}
}
}
} else {
if (!(cmp instanceof com.codename1.ui.list.ContainerList)) {
out.writeInt(PROPERTY_COMPONENTS);
out.writeInt(cnt.getComponentCount());
for (int iter = 0; iter < cnt.getComponentCount(); iter++) {
persistComponent(containerInstance, cnt.getComponentAt(iter), out, res);
}
} 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) {
out.writeInt(PROPERTY_LIST_RENDERER);
com.codename1.ui.list.GenericListCellRenderer g = (com.codename1.ui.list.GenericListCellRenderer) lst.getRenderer();
if (g.getSelectedEven() == null) {
out.writeByte(2);
out.writeUTF(g.getSelected().getName());
out.writeUTF(g.getUnselected().getName());
} else {
out.writeByte(4);
out.writeUTF(g.getSelected().getName());
out.writeUTF(g.getUnselected().getName());
out.writeUTF(g.getSelectedEven().getName());
out.writeUTF(g.getUnselectedEven().getName());
}
}
}
}
}
} else {
if (cmp instanceof com.codename1.ui.Label) {
com.codename1.ui.Label lbl = (com.codename1.ui.Label) cmp;
out.writeInt(PROPERTY_TEXT);
out.writeUTF(lbl.getText());
if (isPropertyModified(cmp, PROPERTY_ALIGNMENT)) {
out.writeInt(PROPERTY_ALIGNMENT);
out.writeInt(lbl.getAlignment());
}
if (isPropertyModified(cmp, PROPERTY_ICON)) {
if (lbl.getIcon() != null) {
out.writeInt(PROPERTY_ICON);
out.writeUTF(res.findId(lbl.getIcon()));
}
}
if (lbl instanceof com.codename1.ui.Button) {
com.codename1.ui.Button button = (com.codename1.ui.Button) lbl;
if (isPropertyModified(cmp, PROPERTY_ROLLOVER_ICON)) {
if (button.getRolloverIcon() != null) {
out.writeInt(PROPERTY_ROLLOVER_ICON);
out.writeUTF(res.findId(button.getRolloverIcon()));
}
}
if (isPropertyModified(cmp, PROPERTY_PRESSED_ICON)) {
if (button.getPressedIcon() != null) {
out.writeInt(PROPERTY_PRESSED_ICON);
out.writeUTF(res.findId(button.getPressedIcon()));
}
}
if (isPropertyModified(cmp, PROPERTY_DISABLED_ICON)) {
if (button.getDisabledIcon() != null) {
out.writeInt(PROPERTY_DISABLED_ICON);
out.writeUTF(res.findId(button.getDisabledIcon()));
}
}
if (isPropertyModified(cmp, PROPERTY_TOGGLE_BUTTON)) {
out.writeInt(PROPERTY_TOGGLE_BUTTON);
out.writeBoolean(((com.codename1.ui.Button) cmp).isToggle());
}
} else {
if (lbl instanceof com.codename1.ui.Slider) {
com.codename1.ui.Slider sld = (com.codename1.ui.Slider) lbl;
if (isPropertyModified(cmp, PROPERTY_EDITABLE)) {
out.writeInt(PROPERTY_EDITABLE);
out.writeBoolean(sld.isEditable());
}
if (isPropertyModified(cmp, PROPERTY_INFINITE)) {
out.writeInt(PROPERTY_INFINITE);
out.writeBoolean(sld.isInfinite());
}
if (isPropertyModified(cmp, PROPERTY_SLIDER_THUMB) && sld.getThumbImage() != null) {
out.writeInt(PROPERTY_SLIDER_THUMB);
out.writeUTF(res.findId(sld.getThumbImage()));
}
if (isPropertyModified(cmp, PROPERTY_PROGRESS)) {
out.writeInt(PROPERTY_PROGRESS);
out.writeInt(sld.getProgress());
}
if (isPropertyModified(cmp, PROPERTY_VERTICAL)) {
out.writeInt(PROPERTY_VERTICAL);
out.writeBoolean(sld.isVertical());
}
if (isPropertyModified(cmp, PROPERTY_INCREMENTS)) {
out.writeInt(PROPERTY_INCREMENTS);
out.writeInt(sld.getIncrements());
}
if (isPropertyModified(cmp, PROPERTY_MAX_VALUE)) {
out.writeInt(PROPERTY_MAX_VALUE);
out.writeInt(sld.getMaxValue());
}
if (isPropertyModified(cmp, PROPERTY_MIN_VALUE)) {
out.writeInt(PROPERTY_MIN_VALUE);
out.writeInt(sld.getMinValue());
}
if (isPropertyModified(cmp, PROPERTY_RENDER_PERCENTAGE_ON_TOP)) {
out.writeInt(PROPERTY_RENDER_PERCENTAGE_ON_TOP);
out.writeBoolean(sld.isRenderPercentageOnTop());
}
}
}
if (isPropertyModified(cmp, PROPERTY_RADIO_GROUP)) {
out.writeInt(PROPERTY_RADIO_GROUP);
out.writeUTF(((com.codename1.ui.RadioButton) cmp).getGroup());
}
if (isPropertyModified(cmp, PROPERTY_SELECTED)) {
out.writeInt(PROPERTY_SELECTED);
out.writeBoolean(((com.codename1.ui.Button) cmp).isSelected());
}
if (isPropertyModified(cmp, PROPERTY_GAP)) {
out.writeInt(PROPERTY_GAP);
out.writeInt(lbl.getGap());
}
if (isPropertyModified(cmp, PROPERTY_VERTICAL_ALIGNMENT)) {
out.writeInt(PROPERTY_VERTICAL_ALIGNMENT);
out.writeInt(lbl.getVerticalAlignment());
}
if (isPropertyModified(cmp, PROPERTY_TEXT_POSITION)) {
out.writeInt(PROPERTY_TEXT_POSITION);
out.writeInt(lbl.getTextPosition());
}
} else {
if (cmp instanceof com.codename1.ui.TextArea) {
com.codename1.ui.TextArea txt = (com.codename1.ui.TextArea) cmp;
if (isPropertyModified(cmp, PROPERTY_VERTICAL_ALIGNMENT)) {
out.writeInt(PROPERTY_VERTICAL_ALIGNMENT);
out.writeInt(txt.getVerticalAlignment());
}
if (isPropertyModified(cmp, PROPERTY_TEXT)) {
out.writeInt(PROPERTY_TEXT);
out.writeUTF(txt.getText());
}
if (isPropertyModified(cmp, PROPERTY_TEXT_AREA_GROW)) {
out.writeInt(PROPERTY_TEXT_AREA_GROW);
out.writeBoolean(txt.isGrowByContent());
}
if (isPropertyModified(cmp, PROPERTY_TEXT_CONSTRAINT)) {
out.writeInt(PROPERTY_TEXT_CONSTRAINT);
out.writeInt(txt.getConstraint());
}
if (isPropertyModified(cmp, PROPERTY_TEXT_MAX_LENGTH)) {
out.writeInt(PROPERTY_TEXT_MAX_LENGTH);
out.writeInt(txt.getMaxSize());
}
if (isPropertyModified(cmp, PROPERTY_EDITABLE)) {
out.writeInt(PROPERTY_EDITABLE);
out.writeBoolean(txt.isEditable());
}
if (isPropertyModified(cmp, PROPERTY_ALIGNMENT)) {
out.writeInt(PROPERTY_ALIGNMENT);
out.writeInt(txt.getAlignment());
}
if (isPropertyModified(cmp, PROPERTY_HINT)) {
out.writeInt(PROPERTY_HINT);
out.writeUTF(txt.getHint());
}
if (isPropertyModified(cmp, PROPERTY_HINT_ICON) && txt.getHintIcon() != null) {
out.writeInt(PROPERTY_HINT_ICON);
out.writeUTF(res.findId(txt.getHintIcon()));
}
if (isPropertyModified(cmp, PROPERTY_COLUMNS)) {
out.writeInt(PROPERTY_COLUMNS);
out.writeInt(txt.getColumns());
}
if (isPropertyModified(cmp, PROPERTY_ROWS)) {
out.writeInt(PROPERTY_ROWS);
out.writeInt(txt.getRows());
}
} else {
if (cmp instanceof com.codename1.ui.List) {
com.codename1.ui.List lst = (com.codename1.ui.List) cmp;
if (isPropertyModified(cmp, PROPERTY_ITEM_GAP)) {
out.writeInt(PROPERTY_ITEM_GAP);
out.writeInt(lst.getItemGap());
}
if (isPropertyModified(cmp, PROPERTY_LIST_FIXED)) {
out.writeInt(PROPERTY_LIST_FIXED);
out.writeInt(lst.getFixedSelection());
}
if (isPropertyModified(cmp, PROPERTY_LIST_ORIENTATION)) {
out.writeInt(PROPERTY_LIST_ORIENTATION);
out.writeInt(lst.getOrientation());
}
if (isPropertyModified(cmp, PROPERTY_HINT)) {
out.writeInt(PROPERTY_HINT);
out.writeUTF(lst.getHint());
}
if (isPropertyModified(cmp, PROPERTY_HINT_ICON) && lst.getHintIcon() != null) {
out.writeInt(PROPERTY_HINT_ICON);
out.writeUTF(res.findId(lst.getHintIcon()));
}
if (isPropertyModified(cmp, PROPERTY_LIST_RENDERER) && lst.getRenderer() instanceof com.codename1.ui.list.GenericListCellRenderer) {
out.writeInt(PROPERTY_LIST_RENDERER);
com.codename1.ui.list.GenericListCellRenderer g = (com.codename1.ui.list.GenericListCellRenderer) lst.getRenderer();
if (g.getSelectedEven() == null) {
out.writeByte(2);
out.writeUTF(g.getSelected().getName());
out.writeUTF(g.getUnselected().getName());
} else {
out.writeByte(4);
out.writeUTF(g.getSelected().getName());
out.writeUTF(g.getUnselected().getName());
out.writeUTF(g.getSelectedEven().getName());
out.writeUTF(g.getUnselectedEven().getName());
}
}
if (!(cmp instanceof com.codename1.components.RSSReader)) {
out.writeInt(PROPERTY_LIST_ITEMS);
out.writeInt(lst.getModel().getSize());
for (int iter = 0; iter < lst.getModel().getSize(); iter++) {
Object o = lst.getModel().getItemAt(iter);
if (o instanceof String) {
out.writeByte(1);
out.writeUTF((String) o);
} else {
out.writeByte(2);
Hashtable h = (Hashtable) o;
out.writeInt(h.size());
for (Object key : h.keySet()) {
Object val = h.get(key);
if (val instanceof com.codename1.ui.Image) {
out.writeInt(2);
out.writeUTF((String) key);
out.writeUTF(res.findId(val));
} else {
out.writeInt(1);
out.writeUTF((String) key);
if (val instanceof ActionCommand) {
out.writeUTF(((ActionCommand) val).getAction());
} else {
out.writeUTF((String) val);
}
}
}
}
}
}
}
}
}
}
if (isPropertyModified(cmp, PROPERTY_LAYOUT_CONSTRAINT) || (cmp.getParent() != null && cmp.getParent().getLayout() instanceof com.codename1.ui.layouts.BorderLayout)) {
if (cmp.getParent() != null && cmp != containerInstance && cmp.getClientProperty("%base_form%") == null) {
com.codename1.ui.layouts.Layout l = cmp.getParent().getLayout();
if (l instanceof com.codename1.ui.layouts.BorderLayout) {
out.writeInt(PROPERTY_LAYOUT_CONSTRAINT);
out.writeUTF((String) l.getComponentConstraint(cmp));
} else {
if (l instanceof com.codename1.ui.table.TableLayout) {
out.writeInt(PROPERTY_LAYOUT_CONSTRAINT);
com.codename1.ui.table.TableLayout.Constraint con = (com.codename1.ui.table.TableLayout.Constraint) l.getComponentConstraint(cmp);
out.writeInt(getInt("row", con.getClass(), con));
out.writeInt(getInt("column", con.getClass(), con));
out.writeInt(getInt("height", con.getClass(), con));
out.writeInt(getInt("width", con.getClass(), con));
out.writeInt(getInt("align", con.getClass(), con));
out.writeInt(getInt("spanHorizontal", con.getClass(), con));
out.writeInt(getInt("valign", con.getClass(), con));
out.writeInt(getInt("spanVertical", con.getClass(), con));
}
}
}
}
if (isPropertyModified(cmp, PROPERTY_EMBED)) {
out.writeInt(PROPERTY_EMBED);
out.writeUTF(((EmbeddedContainer) cmp).getEmbed());
}
if (isPropertyModified(cmp, PROPERTY_UIID)) {
out.writeInt(PROPERTY_UIID);
out.writeUTF(cmp.getUIID());
}
if (isPropertyModified(cmp, PROPERTY_FOCUSABLE)) {
out.writeInt(PROPERTY_FOCUSABLE);
out.writeBoolean(cmp.isFocusable());
}
if (isPropertyModified(cmp, PROPERTY_ENABLED)) {
out.writeInt(PROPERTY_ENABLED);
out.writeBoolean(cmp.isEnabled());
}
if (isPropertyModified(cmp, PROPERTY_RTL)) {
out.writeInt(PROPERTY_RTL);
out.writeBoolean(cmp.isRTL());
}
if (isPropertyModified(cmp, PROPERTY_SCROLL_VISIBLE)) {
out.writeInt(PROPERTY_SCROLL_VISIBLE);
out.writeBoolean(cmp.isScrollVisible());
}
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)) {
out.writeInt(PROPERTY_TENSILE_DRAG_ENABLED);
out.writeBoolean(cmp.isTensileDragEnabled());
}
if (isPropertyModified(cmp, PROPERTY_TACTILE_TOUCH)) {
out.writeInt(PROPERTY_TACTILE_TOUCH);
out.writeBoolean(cmp.isTactileTouch());
}
if (isPropertyModified(cmp, PROPERTY_SNAP_TO_GRID)) {
out.writeInt(PROPERTY_SNAP_TO_GRID);
out.writeBoolean(cmp.isSnapToGrid());
}
if (isPropertyModified(cmp, PROPERTY_FLATTEN)) {
out.writeInt(PROPERTY_FLATTEN);
out.writeBoolean(cmp.isFlatten());
}
if (isPropertyModified(cmp, PROPERTY_CUSTOM)) {
for (String propName : cmp.getPropertyNames()) {
if (isCustomPropertyModified(cmp, propName) && !propName.startsWith("$")) {
out.writeInt(PROPERTY_CUSTOM);
out.writeUTF(propName);
Class type = getPropertyCustomType(cmp, propName);
Object value = cmp.getPropertyValue(propName);
if (value == null) {
out.writeBoolean(true);
continue;
}
out.writeBoolean(false);
if (type == String.class) {
out.writeUTF((String) value);
continue;
}
if (type == String[].class) {
String[] result = (String[]) value;
out.writeInt(result.length);
for (int i = 0; i < result.length; i++) {
out.writeUTF(result[i]);
}
continue;
}
if (type == String[][].class) {
String[][] result = (String[][]) value;
out.writeInt(result.length);
for (int i = 0; i < result.length; i++) {
out.writeInt(result[i].length);
for (int j = 0; j < result[i].length; j++) {
out.writeUTF(result[i][j]);
}
}
continue;
}
if (type == Integer.class) {
out.writeInt(((Number) value).intValue());
continue;
}
if (type == Long.class) {
out.writeLong(((Number) value).longValue());
continue;
}
if (type == Double.class) {
out.writeDouble(((Number) value).doubleValue());
continue;
}
if (type == Date.class) {
if (value == null) {
out.writeBoolean(false);
continue;
}
out.writeBoolean(true);
out.writeLong(((Date) value).getTime());
continue;
}
if (type == Float.class) {
out.writeFloat(((Number) value).floatValue());
continue;
}
if (type == Byte.class) {
out.writeByte(((Number) value).byteValue());
continue;
}
if (type == Boolean.class) {
out.writeBoolean(((Boolean) value).booleanValue());
continue;
}
if (type == com.codename1.ui.Image[].class) {
com.codename1.ui.Image[] result = (com.codename1.ui.Image[]) value;
out.writeInt(result.length);
for (int i = 0; i < result.length; i++) {
if (result[i] == null) {
out.writeUTF("");
} else {
String id = res.findId(result[i]);
if (id == null) {
out.writeUTF("");
} else {
out.writeUTF(id);
}
}
}
continue;
}
if (type == com.codename1.ui.Image.class) {
com.codename1.ui.Image result = (com.codename1.ui.Image) value;
if (result == null) {
out.writeUTF("");
} else {
String id = res.findId(result);
if (id == null) {
out.writeUTF("");
} else {
out.writeUTF(id);
}
}
continue;
}
if (type == com.codename1.ui.Container.class) {
out.writeUTF(((com.codename1.ui.Container) value).getName());
continue;
}
if (type == com.codename1.ui.list.CellRenderer.class) {
com.codename1.ui.list.GenericListCellRenderer g = (com.codename1.ui.list.GenericListCellRenderer) value;
if (g.getSelectedEven() == null) {
out.writeByte(2);
out.writeUTF(g.getSelected().getName());
out.writeUTF(g.getUnselected().getName());
} else {
out.writeByte(4);
out.writeUTF(g.getSelected().getName());
out.writeUTF(g.getUnselected().getName());
out.writeUTF(g.getSelectedEven().getName());
out.writeUTF(g.getUnselectedEven().getName());
}
continue;
}
if (type == Object[].class) {
Object[] arr = (Object[]) value;
out.writeInt(arr.length);
for (int iter = 0; iter < arr.length; iter++) {
Object o = arr[iter];
if (o instanceof String) {
out.writeByte(1);
out.writeUTF((String) o);
} else {
out.writeByte(2);
Hashtable h = (Hashtable) o;
out.writeInt(h.size());
for (Object key : h.keySet()) {
Object val = h.get(key);
if (val instanceof com.codename1.ui.Image) {
out.writeInt(2);
out.writeUTF((String) key);
out.writeUTF(res.findId(val));
} else {
out.writeInt(1);
out.writeUTF((String) key);
out.writeUTF((String) val);
}
}
}
}
continue;
}
// none of the above then its a char
out.writeChar(((Character) value).charValue());
}
}
}
out.writeInt(-1);
}
use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.
the class EditableResources method save.
/**
* Allows us to store a modified resource file
*/
public void save(OutputStream out) throws IOException {
if (overrideFile != null) {
overrideResource.save(new FileOutputStream(overrideFile));
}
// disable override for the duration of the save so stuff from the override doesn't
// get into the main resource file
File overrideFileBackup = overrideFile;
EditableResources overrideResourceBackup = overrideResource;
overrideResource = null;
overrideFile = null;
try {
DataOutputStream output = new DataOutputStream(out);
String[] resourceNames = getResourceNames();
keyOffset = 0;
if (currentPassword != null) {
output.writeShort(resourceNames.length + 2);
output.writeByte(MAGIC_PASSWORD);
output.writeUTF("" + ((char) encode('l')) + ((char) encode('w')));
output.writeByte(encode(MAGIC_HEADER & 0xff));
} else {
output.writeShort(resourceNames.length + 1);
// write the header of the resource file
output.writeByte(MAGIC_HEADER);
}
output.writeUTF("");
// the size of the header
output.writeShort(6);
output.writeShort(MAJOR_VERSION);
output.writeShort(MINOR_VERSION);
// currently resource file meta-data isn't supported
output.writeShort(0);
for (int iter = 0; iter < resourceNames.length; iter++) {
// write the magic number
byte magic = getResourceType(resourceNames[iter]);
switch(magic) {
case MAGIC_TIMELINE:
case MAGIC_ANIMATION_LEGACY:
case MAGIC_IMAGE_LEGACY:
case MAGIC_INDEXED_IMAGE_LEGACY:
magic = MAGIC_IMAGE;
break;
case MAGIC_THEME_LEGACY:
magic = MAGIC_THEME;
break;
case MAGIC_FONT_LEGACY:
magic = MAGIC_FONT;
break;
}
if (currentPassword != null) {
output.writeByte(encode(magic & 0xff));
char[] chars = resourceNames[iter].toCharArray();
for (int i = 0; i < chars.length; i++) {
chars[i] = (char) encode(chars[i] & 0xffff);
}
output.writeUTF(new String(chars));
} else {
output.writeByte(magic);
output.writeUTF(resourceNames[iter]);
}
switch(magic) {
case MAGIC_IMAGE:
Object o = getResourceObject(resourceNames[iter]);
if (!(o instanceof MultiImage)) {
o = null;
}
saveImage(output, getImage(resourceNames[iter]), (MultiImage) o, BufferedImage.TYPE_INT_ARGB);
continue;
case MAGIC_THEME:
saveTheme(output, getTheme(resourceNames[iter]), magic == MAGIC_THEME_LEGACY);
continue;
case MAGIC_FONT:
saveFont(output, false, resourceNames[iter]);
continue;
case MAGIC_DATA:
{
InputStream i = getData(resourceNames[iter]);
ByteArrayOutputStream outArray = new ByteArrayOutputStream();
int val = i.read();
while (val != -1) {
outArray.write(val);
val = i.read();
}
byte[] data = outArray.toByteArray();
output.writeInt(data.length);
output.write(data);
continue;
}
case MAGIC_UI:
{
InputStream i = getUi(resourceNames[iter]);
ByteArrayOutputStream outArray = new ByteArrayOutputStream();
int val = i.read();
while (val != -1) {
outArray.write(val);
val = i.read();
}
byte[] data = outArray.toByteArray();
output.writeInt(data.length);
output.write(data);
continue;
}
case MAGIC_L10N:
// we are getting the theme which allows us to acces the l10n data
saveL10N(output, getTheme(resourceNames[iter]));
continue;
default:
throw new IOException("Corrupt theme file unrecognized magic number: " + Integer.toHexString(magic & 0xff));
}
}
modified = false;
updateModified();
undoQueue.clear();
redoQueue.clear();
} finally {
overrideFile = overrideFileBackup;
overrideResource = overrideResourceBackup;
}
}
use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.
the class ToastBar method showMessage.
/**
* Simplifies a common use case of showing a message with an icon that fades out after a few seconds
* @param msg the message
* @param icon the material icon to show from {@link com.codename1.ui.FontImage}
* @param timeout the timeout value in milliseconds
* @param listener the action to perform when the ToastBar is tapped
* @return the status if we want to clear it before timeout elapses
*/
public static Status showMessage(String msg, char icon, int timeout, ActionListener listener) {
Status s = ToastBar.getInstance().createStatus();
Style stl = UIManager.getInstance().getComponentStyle(s.getMessageUIID());
s.setIcon(FontImage.createMaterial(icon, stl, 4));
s.setMessage(msg);
if (listener != null) {
s.setListener(listener);
}
s.setExpires(timeout);
s.show();
return s;
}
use of com.codename1.ui.TextSelection.Char in project CodenameOne by codenameone.
the class L10nEditor method importResourceActionPerformed.
// GEN-LAST:event_exportResourceActionPerformed
private void importResourceActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_importResourceActionPerformed
final String locale = (String) locales.getSelectedItem();
int val = JOptionPane.showConfirmDialog(this, "This will overwrite existing values for " + locale + "\nAre you sure?", "Import", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (val == JOptionPane.YES_OPTION) {
File[] files = ResourceEditorView.showOpenFileChooser("Properties, XML, CSV", "prop", "properties", "l10n", "locale", "xml", "csv");
if (files != null) {
FileInputStream f = null;
try {
f = new FileInputStream(files[0]);
if (files[0].getName().toLowerCase().endsWith("xml")) {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser saxParser = spf.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
xmlReader.setErrorHandler(new ErrorHandler() {
public void warning(SAXParseException exception) throws SAXException {
exception.printStackTrace();
}
public void error(SAXParseException exception) throws SAXException {
exception.printStackTrace();
}
public void fatalError(SAXParseException exception) throws SAXException {
exception.printStackTrace();
}
});
xmlReader.setContentHandler(new ContentHandler() {
private String currentName;
private StringBuilder chars = new StringBuilder();
@Override
public void setDocumentLocator(Locator locator) {
}
@Override
public void startDocument() throws SAXException {
}
@Override
public void endDocument() throws SAXException {
}
@Override
public void startPrefixMapping(String prefix, String uri) throws SAXException {
}
@Override
public void endPrefixMapping(String prefix) throws SAXException {
}
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
if ("string".equals(localName) || "string".equals(qName)) {
currentName = atts.getValue("name");
chars.setLength(0);
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if ("string".equals(localName) || "string".equals(qName)) {
String str = chars.toString();
if (str.startsWith("\"") && str.endsWith("\"")) {
str = str.substring(1);
str = str.substring(0, str.length() - 1);
res.setLocaleProperty(localeName, locale, currentName, str);
return;
}
str = str.replace("\\'", "'");
res.setLocaleProperty(localeName, locale, currentName, str);
}
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
chars.append(ch, start, length);
}
@Override
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
}
@Override
public void processingInstruction(String target, String data) throws SAXException {
}
@Override
public void skippedEntity(String name) throws SAXException {
}
});
xmlReader.parse(new InputSource(new InputStreamReader(f, "UTF-8")));
} else {
if (files[0].getName().toLowerCase().endsWith("csv")) {
CSVParserOptions po = new CSVParserOptions(this);
if (po.isCanceled()) {
f.close();
return;
}
CSVParser p = new CSVParser(po.getDelimiter());
String[][] data = p.parse(new InputStreamReader(f, po.getEncoding()));
for (int iter = 1; iter < data.length; iter++) {
if (data[iter].length > 0) {
String key = data[iter][0];
for (int col = 1; col < data[iter].length; col++) {
if (res.getL10N(localeName, data[0][col]) == null) {
res.addLocale(localeName, data[0][col]);
}
res.setLocaleProperty(localeName, data[0][col], key, data[iter][col]);
}
}
}
} else {
Properties prop = new Properties();
prop.load(f);
for (Object key : prop.keySet()) {
res.setLocaleProperty(localeName, locale, (String) key, prop.getProperty((String) key));
}
}
}
f.close();
initLocaleList();
for (Object localeObj : localeList) {
Hashtable current = res.getL10N(localeName, (String) localeObj);
for (Object key : current.keySet()) {
if (!keys.contains(key)) {
keys.add(key);
}
}
}
Collections.sort(keys);
initTable();
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(this, "Error: " + ex, "Error Occured", JOptionPane.ERROR_MESSAGE);
}
}
}
}
Aggregations