use of com.codename1.processing.Result in project CodenameOne by codenameone.
the class FaceBookAccess method getUsersDetails.
/**
* Gets users requested details ((this method uses the legacy rest api see http://developers.facebook.com/docs/reference/rest/))
*
* @param usersIds the users to query
* @param fields which fields to query on the users see http://developers.facebook.com/docs/reference/rest/users.getInfo/
* @param callback the result will call the callback with the result
* to extrct the data preform the following:
* public void actionPerformed(ActionEvent evt) {
* Vector data = (Vector) ((NetworkEvent) evt).getMetaData();
* Vector users = (Vector) data.elementAt(0);
* }
*/
public void getUsersDetails(String[] usersIds, String[] fields, final ActionListener callback) throws IOException {
checkAuthentication();
final FacebookRESTService con = new FacebookRESTService(token, "https://api.facebook.com/method/users.getInfo", false);
String ids = usersIds[0];
int ulen = usersIds.length;
for (int i = 1; i < ulen; i++) {
ids += "," + usersIds[i];
}
con.addArgumentNoEncoding("uids", ids);
String fieldsStr = fields[0];
int flen = fields.length;
for (int i = 1; i < flen; i++) {
fieldsStr += "," + fields[i];
}
con.addArgumentNoEncoding("fields", fieldsStr);
con.addArgument("format", "json");
con.addResponseListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (!con.isAlive()) {
return;
}
if (callback != null) {
callback.actionPerformed(evt);
}
}
});
if (slider != null) {
SliderBridge.bindProgress(con, slider);
}
for (int i = 0; i < responseCodeListeners.size(); i++) {
con.addResponseCodeListener((ActionListener) responseCodeListeners.elementAt(i));
}
current = con;
NetworkManager.getInstance().addToQueue(con);
}
use of com.codename1.processing.Result 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.processing.Result 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.processing.Result in project CodenameOne by codenameone.
the class EditableResources method openFileWithXMLSupport.
public void openFileWithXMLSupport(File f) throws IOException {
if (xmlEnabled && f.getParentFile().getName().equals("src")) {
File res = new File(f.getParentFile().getParentFile(), "res");
if (res.exists()) {
File xml = new File(res, f.getName().substring(0, f.getName().length() - 3) + "xml");
if (xml.exists()) {
loadingMode = true;
com.codename1.ui.Font.clearBitmapCache();
clear();
try {
File resDir = new File(res, f.getName().substring(0, f.getName().length() - 4));
// open the XML file...
JAXBContext ctx = JAXBContext.newInstance(ResourceFileXML.class);
ResourceFileXML xmlData = (ResourceFileXML) ctx.createUnmarshaller().unmarshal(xml);
boolean normalize = xmlData.getMajorVersion() > 1 || xmlData.getMinorVersion() > 5;
majorVersion = (short) xmlData.getMajorVersion();
minorVersion = (short) xmlData.getMinorVersion();
xmlUI = xmlData.isUseXmlUI();
if (xmlData.getData() != null) {
for (Data d : xmlData.getData()) {
setResource(d.getName(), MAGIC_DATA, readFile(resDir, d.getName(), normalize));
}
}
if (xmlData.getLegacyFont() != null) {
for (LegacyFont d : xmlData.getLegacyFont()) {
String name = d.getName();
if (normalize) {
name = normalizeFileName(name);
}
DataInputStream fi = new DataInputStream(new FileInputStream(new File(resDir, name)));
setResource(d.getName(), MAGIC_FONT, loadFont(fi, d.getName(), false));
fi.close();
}
}
if (xmlData.getImage() != null) {
for (com.codename1.ui.util.xml.Image d : xmlData.getImage()) {
if (d.getType() == null) {
// standara JPG or PNG
String name = d.getName();
if (normalize) {
name = normalizeFileName(name);
}
FileInputStream fi = new FileInputStream(new File(resDir, name));
EncodedImage e = EncodedImage.create(fi);
fi.close();
setResource(d.getName(), MAGIC_IMAGE, e);
continue;
}
if ("svg".equals(d.getType())) {
setResource(d.getName(), MAGIC_IMAGE, Image.createSVG(d.getType(), false, readFile(resDir, d.getName(), normalize)));
continue;
}
if ("timeline".equals(d.getType())) {
String name = d.getName();
if (normalize) {
name = normalizeFileName(name);
}
DataInputStream fi = new DataInputStream(new FileInputStream(new File(resDir, name)));
setResource(d.getName(), MAGIC_IMAGE, readTimeline(fi));
fi.close();
continue;
}
if ("multi".equals(d.getType())) {
String name = d.getName();
if (normalize) {
name = normalizeFileName(name);
}
File multiImageDir = new File(resDir, name);
File hd4k = new File(multiImageDir, "4k.png");
File hd2 = new File(multiImageDir, "2hd.png");
File hd560 = new File(multiImageDir, "560.png");
File hd = new File(multiImageDir, "hd.png");
File veryhigh = new File(multiImageDir, "veryhigh.png");
File high = new File(multiImageDir, "high.png");
File medium = new File(multiImageDir, "medium.png");
File low = new File(multiImageDir, "low.png");
File veryLow = new File(multiImageDir, "verylow.png");
Map<Integer, EncodedImage> images = new HashMap<Integer, EncodedImage>();
if (hd4k.exists()) {
images.put(new Integer(Display.DENSITY_4K), EncodedImage.create(readFileNoNormal(hd4k)));
}
if (hd2.exists()) {
images.put(new Integer(Display.DENSITY_2HD), EncodedImage.create(readFileNoNormal(hd2)));
}
if (hd560.exists()) {
images.put(new Integer(Display.DENSITY_560), EncodedImage.create(readFileNoNormal(hd560)));
}
if (hd.exists()) {
images.put(new Integer(Display.DENSITY_HD), EncodedImage.create(readFileNoNormal(hd)));
}
if (veryhigh.exists()) {
images.put(new Integer(Display.DENSITY_VERY_HIGH), EncodedImage.create(readFileNoNormal(veryhigh)));
}
if (high.exists()) {
images.put(new Integer(Display.DENSITY_HIGH), EncodedImage.create(readFileNoNormal(high)));
}
if (medium.exists()) {
images.put(new Integer(Display.DENSITY_MEDIUM), EncodedImage.create(readFileNoNormal(medium)));
}
if (low.exists()) {
images.put(new Integer(Display.DENSITY_LOW), EncodedImage.create(readFileNoNormal(low)));
}
if (veryLow.exists()) {
images.put(new Integer(Display.DENSITY_VERY_LOW), EncodedImage.create(readFileNoNormal(veryLow)));
}
int[] dpis = new int[images.size()];
EncodedImage[] imageArray = new EncodedImage[images.size()];
int count = 0;
for (Map.Entry<Integer, EncodedImage> m : images.entrySet()) {
dpis[count] = m.getKey().intValue();
imageArray[count] = m.getValue();
count++;
}
MultiImage result = new MultiImage();
result.setDpi(dpis);
result.setInternalImages(imageArray);
setResource(d.getName(), MAGIC_IMAGE, result);
continue;
}
}
}
if (xmlData.getL10n() != null) {
for (L10n d : xmlData.getL10n()) {
Hashtable<String, Hashtable<String, String>> l10n = new Hashtable<String, Hashtable<String, String>>();
for (Lang l : d.getLang()) {
Hashtable<String, String> language = new Hashtable<String, String>();
if (l != null && l.getEntry() != null) {
for (Entry e : l.getEntry()) {
language.put(e.getKey(), e.getValue());
}
}
l10n.put(l.getName(), language);
}
setResource(d.getName(), MAGIC_L10N, l10n);
}
}
if (xmlData.getTheme() != null) {
for (Theme d : xmlData.getTheme()) {
Hashtable<String, Object> theme = new Hashtable<String, Object>();
theme.put("uninitialized", Boolean.TRUE);
if (d.getVal() != null) {
for (Val v : d.getVal()) {
String key = v.getKey();
if (key.endsWith("align") || key.endsWith("textDecoration")) {
theme.put(key, Integer.valueOf(v.getValue()));
continue;
}
if (key.endsWith(Style.BACKGROUND_TYPE) || key.endsWith(Style.BACKGROUND_ALIGNMENT)) {
theme.put(key, Byte.valueOf(v.getValue()));
continue;
}
// padding and or margin type
if (key.endsWith("Unit")) {
String[] s = v.getValue().split(",");
theme.put(key, new byte[] { Byte.parseByte(s[0]), Byte.parseByte(s[1]), Byte.parseByte(s[2]), Byte.parseByte(s[3]) });
continue;
}
theme.put(key, v.getValue());
}
}
if (d.getBorder() != null) {
for (com.codename1.ui.util.xml.Border b : d.getBorder()) {
if ("empty".equals(b.getType())) {
theme.put(b.getKey(), Border.createEmpty());
continue;
}
if ("round".equals(b.getType())) {
RoundBorder rb = RoundBorder.create();
rb = rb.color(b.getRoundBorderColor());
rb = rb.rectangle(b.isRectangle());
rb = rb.shadowBlur(b.getShadowBlur());
rb = rb.shadowOpacity(b.getShadowOpacity());
rb = rb.shadowSpread((int) b.getShadowSpread(), b.isShadowMM());
rb = rb.shadowX(b.getShadowX());
rb = rb.shadowY(b.getShadowY());
rb = rb.stroke(b.getStrokeThickness(), b.isStrokeMM());
rb = rb.strokeColor(b.getStrokeColor());
rb = rb.strokeOpacity(b.getStrokeOpacity());
theme.put(b.getKey(), rb);
continue;
}
if ("roundRect".equals(b.getType())) {
RoundRectBorder rb = RoundRectBorder.create();
rb = rb.shadowBlur(b.getShadowBlur());
rb = rb.shadowOpacity(b.getShadowOpacity());
rb = rb.shadowSpread(b.getShadowSpread());
rb = rb.shadowX(b.getShadowX());
rb = rb.shadowY(b.getShadowY());
rb = rb.stroke(b.getStrokeThickness(), b.isStrokeMM());
rb = rb.strokeColor(b.getStrokeColor());
rb = rb.strokeOpacity(b.getStrokeOpacity());
rb = rb.bezierCorners(b.isBezierCorners());
rb = rb.bottomOnlyMode(b.isBottomOnlyMode());
rb = rb.topOnlyMode(b.isTopOnlyMode());
rb = rb.cornerRadius(b.getCornerRadius());
theme.put(b.getKey(), rb);
continue;
}
if ("line".equals(b.getType())) {
if (b.getColor() == null) {
if (b.isMillimeters()) {
theme.put(b.getKey(), Border.createLineBorder(b.getThickness().floatValue()));
} else {
theme.put(b.getKey(), Border.createLineBorder(b.getThickness().intValue()));
}
} else {
if (b.isMillimeters()) {
theme.put(b.getKey(), Border.createLineBorder(b.getThickness().floatValue(), b.getColor().intValue()));
} else {
theme.put(b.getKey(), Border.createLineBorder(b.getThickness().intValue(), b.getColor().intValue()));
}
}
continue;
}
if ("underline".equals(b.getType())) {
if (b.getColor() == null) {
theme.put(b.getKey(), Border.createUndelineBorder(b.getThickness().intValue()));
} else {
theme.put(b.getKey(), Border.createUnderlineBorder(b.getThickness().intValue(), b.getColor().intValue()));
}
continue;
}
if ("rounded".equals(b.getType())) {
if (b.getColor() == null) {
theme.put(b.getKey(), Border.createRoundBorder(b.getArcW().intValue(), b.getArcH().intValue()));
} else {
theme.put(b.getKey(), Border.createRoundBorder(b.getArcW().intValue(), b.getArcH().intValue(), b.getColor().intValue()));
}
continue;
}
if ("etchedRaised".equals(b.getType())) {
if (b.getColor() == null) {
theme.put(b.getKey(), Border.createEtchedRaised());
} else {
theme.put(b.getKey(), Border.createEtchedRaised(b.getColor().intValue(), b.getColorB().intValue()));
}
continue;
}
if ("etchedLowered".equals(b.getType())) {
if (b.getColor() == null) {
theme.put(b.getKey(), Border.createEtchedLowered());
} else {
theme.put(b.getKey(), Border.createEtchedLowered(b.getColor().intValue(), b.getColorB().intValue()));
}
continue;
}
if ("bevelLowered".equals(b.getType())) {
if (b.getColor() == null) {
theme.put(b.getKey(), Border.createBevelLowered());
} else {
theme.put(b.getKey(), Border.createBevelLowered(b.getColor().intValue(), b.getColorB().intValue(), b.getColorC().intValue(), b.getColorD().intValue()));
}
continue;
}
if ("bevelRaised".equals(b.getType())) {
if (b.getColor() == null) {
theme.put(b.getKey(), Border.createBevelRaised());
} else {
theme.put(b.getKey(), Border.createBevelRaised(b.getColor().intValue(), b.getColorB().intValue(), b.getColorC().intValue(), b.getColorD().intValue()));
}
continue;
}
if ("image".equals(b.getType())) {
int imageCount = 2;
if (b.getI9() != null) {
imageCount = 9;
} else {
if (b.getI8() != null) {
imageCount = 8;
} else {
if (b.getI3() != null) {
imageCount = 3;
}
}
}
String[] borderInstance;
switch(imageCount) {
case 2:
borderInstance = new String[] { b.getI1(), b.getI2() };
break;
case 3:
borderInstance = new String[] { b.getI1(), b.getI2(), b.getI3() };
break;
case 8:
borderInstance = new String[] { b.getI1(), b.getI2(), b.getI3(), b.getI4(), b.getI5(), b.getI6(), b.getI7(), b.getI8() };
break;
default:
borderInstance = new String[] { b.getI1(), b.getI2(), b.getI3(), b.getI4(), b.getI5(), b.getI6(), b.getI7(), b.getI8(), b.getI9() };
break;
}
theme.put(b.getKey(), borderInstance);
continue;
}
if ("imageH".equals(b.getType())) {
theme.put(b.getKey(), new String[] { "h", b.getI1(), b.getI2(), b.getI3() });
continue;
}
if ("imageV".equals(b.getType())) {
theme.put(b.getKey(), new String[] { "v", b.getI1(), b.getI2(), b.getI3() });
continue;
}
}
}
if (d.getFont() != null) {
for (com.codename1.ui.util.xml.Font b : d.getFont()) {
if ("ttf".equals(b.getType())) {
com.codename1.ui.Font system = com.codename1.ui.Font.createSystemFont(b.getFace().intValue(), b.getStyle().intValue(), b.getSize().intValue());
EditorTTFFont t;
if (b.getName().startsWith("native:")) {
t = new EditorTTFFont(b.getName(), b.getSizeSettings().intValue(), b.getActualSize().floatValue(), system);
} else {
t = new EditorTTFFont(new File(f.getParentFile(), b.getName()), b.getSizeSettings().intValue(), b.getActualSize().floatValue(), system);
}
theme.put(b.getKey(), t);
continue;
}
if ("system".equals(b.getType())) {
com.codename1.ui.Font system = com.codename1.ui.Font.createSystemFont(b.getFace().intValue(), b.getStyle().intValue(), b.getSize().intValue());
theme.put(b.getKey(), system);
continue;
}
// bitmap fonts aren't supported right now
}
}
if (d.getGradient() != null) {
for (com.codename1.ui.util.xml.Gradient b : d.getGradient()) {
theme.put(b.getKey(), new Object[] { b.getColor1(), b.getColor2(), b.getPosX(), b.getPosY(), b.getRadius() });
}
}
setResource(d.getName(), MAGIC_THEME, theme);
}
}
// we load the UI last since it might depend on images or other elements in the future
if (xmlData.getUi() != null) {
if (xmlData.isUseXmlUI()) {
ArrayList<ComponentEntry> guiElements = new ArrayList<ComponentEntry>();
// place renderers first
final ArrayList<String> renderers = new ArrayList<String>();
for (Ui d : xmlData.getUi()) {
JAXBContext componentContext = JAXBContext.newInstance(ComponentEntry.class);
File uiFile = new File(resDir, normalizeFileName(d.getName()) + ".ui");
ComponentEntry uiXMLData = (ComponentEntry) componentContext.createUnmarshaller().unmarshal(uiFile);
guiElements.add(uiXMLData);
uiXMLData.findRendererers(renderers);
}
Collections.sort(guiElements, new Comparator<ComponentEntry>() {
private final ArrayList<String> entries1 = new ArrayList<String>();
private final ArrayList<String> entries2 = new ArrayList<String>();
@Override
public int compare(ComponentEntry o1, ComponentEntry o2) {
if (renderers.contains(o1.getName())) {
return -1;
}
if (renderers.contains(o2.getName())) {
return 1;
}
entries1.clear();
entries2.clear();
o1.findEmbeddedDependencies(entries1);
o2.findEmbeddedDependencies(entries2);
if (entries1.size() == 0) {
if (entries2.size() == 0) {
return 0;
}
return -1;
} else {
if (entries2.size() == 0) {
return 1;
}
}
for (String e : entries1) {
if (e.equals(o2.getName())) {
return 1;
}
}
for (String e : entries2) {
if (e.equals(o1.getName())) {
return -1;
}
}
return 0;
}
});
for (ComponentEntry uiXMLData : guiElements) {
UIBuilderOverride uib = new UIBuilderOverride();
com.codename1.ui.Container cnt = uib.createInstance(uiXMLData, this);
// encountered an error loading the component fallback to loading with the binary types
if (cnt == null) {
for (Ui ui : xmlData.getUi()) {
setResource(uiXMLData.getName(), MAGIC_UI, readFile(resDir, ui.getName(), normalize));
}
break;
} else {
byte[] data = UserInterfaceEditor.persistContainer(cnt, this);
setResource(uiXMLData.getName(), MAGIC_UI, data);
}
}
} else {
for (Ui d : xmlData.getUi()) {
setResource(d.getName(), MAGIC_UI, readFile(resDir, d.getName(), normalize));
}
}
}
loadingMode = false;
modified = false;
updateModified();
// can occure when a resource file is opened via the constructor
if (undoQueue != null) {
undoQueue.clear();
redoQueue.clear();
}
return;
} catch (JAXBException err) {
err.printStackTrace();
}
}
}
}
openFile(new FileInputStream(f));
}
use of com.codename1.processing.Result in project CodenameOne by codenameone.
the class JavaSEPort method loadSkinFile.
private void loadSkinFile(InputStream skin, final JFrame frm) {
try {
ZipInputStream z = new ZipInputStream(skin);
ZipEntry e = z.getNextEntry();
final Properties props = new Properties();
BufferedImage map = null;
BufferedImage landscapeMap = null;
// if we load the native theme imediately the multi-image's will be loaded with the size of the old skin
byte[] nativeThemeData = null;
nativeThemeRes = null;
nativeTheme = null;
while (e != null) {
String name = e.getName();
if (name.equals("skin.png")) {
portraitSkin = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("header.png")) {
header = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("header_l.png")) {
headerLandscape = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin.properties")) {
props.load(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin_l.png")) {
landscapeSkin = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin_map.png")) {
map = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.equals("skin_map_l.png")) {
landscapeMap = ImageIO.read(z);
e = z.getNextEntry();
continue;
}
if (name.endsWith(".res")) {
long esize = e.getSize();
if (esize > 0) {
nativeThemeData = new byte[(int) esize];
readFully(z, nativeThemeData);
} else {
ByteArrayOutputStream b = new ByteArrayOutputStream();
Util.copyNoClose(z, b, 8192);
nativeThemeData = b.toByteArray();
}
e = z.getNextEntry();
continue;
}
if (name.endsWith(".ttf")) {
try {
java.awt.Font result = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, z);
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(result);
} catch (FontFormatException ex) {
ex.printStackTrace();
}
e = z.getNextEntry();
continue;
}
e = z.getNextEntry();
}
z.close();
String ppi = props.getProperty("ppi");
if (ppi != null) {
double ppiD = Double.valueOf(ppi);
pixelMilliRatio = ppiD / 25.4;
} else {
String pix = props.getProperty("pixelRatio");
if (pix != null && pix.length() > 0) {
try {
pixelMilliRatio = Double.valueOf(pix);
} catch (NumberFormatException err) {
err.printStackTrace();
pixelMilliRatio = null;
}
} else {
pixelMilliRatio = null;
}
}
portraitSkinHotspots = new HashMap<Point, Integer>();
portraitScreenCoordinates = new Rectangle();
landscapeSkinHotspots = new HashMap<Point, Integer>();
landscapeScreenCoordinates = new Rectangle();
if (props.getProperty("roundScreen", "false").equalsIgnoreCase("true")) {
portraitScreenCoordinates.x = Integer.parseInt(props.getProperty("displayX"));
portraitScreenCoordinates.y = Integer.parseInt(props.getProperty("displayY"));
portraitScreenCoordinates.width = Integer.parseInt(props.getProperty("displayWidth"));
portraitScreenCoordinates.height = Integer.parseInt(props.getProperty("displayHeight"));
landscapeScreenCoordinates.x = portraitScreenCoordinates.y;
landscapeScreenCoordinates.y = portraitScreenCoordinates.x;
landscapeScreenCoordinates.width = portraitScreenCoordinates.height;
landscapeScreenCoordinates.height = portraitScreenCoordinates.width;
roundedSkin = true;
} else {
initializeCoordinates(map, props, portraitSkinHotspots, portraitScreenCoordinates);
initializeCoordinates(landscapeMap, props, landscapeSkinHotspots, landscapeScreenCoordinates);
}
platformName = props.getProperty("platformName", "se");
platformOverrides = props.getProperty("overrideNames", "").split(",");
String ua = null;
if (platformName.equals("and")) {
ua = "Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
} else if (platformName.equals("rim")) {
ua = "Mozilla/5.0 (BlackBerry; U; BlackBerry 9860; en-GB) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.296 Mobile Safari/534.11+";
} else if (platformName.equals("ios")) {
if (isTablet()) {
ua = "Mozilla/5.0 (iPad; U; CPU OS 4_3_1 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8G4 Safari/6533.18.5";
} else {
ua = "Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5";
}
} else if (platformName.equals("me")) {
ua = "Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124";
} else {
if (platformName.equals("win")) {
ua = "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 800)";
} else {
ua = "Mozilla/5.0 (Linux; U; Android 2.2; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1";
}
}
Display.getInstance().setProperty("User-Agent", ua);
isIOS = props.getProperty("systemFontFamily", "Arial").toLowerCase().contains("helvetica");
setFontFaces(props.getProperty("systemFontFamily", "Arial"), props.getProperty("proportionalFontFamily", "SansSerif"), props.getProperty("monospaceFontFamily", "Monospaced"));
int med;
int sm;
int la;
if (pixelMilliRatio == null) {
float factor = ((float) getDisplayHeightImpl()) / 480.0f;
med = (int) (15.0f * factor);
sm = (int) (11.0f * factor);
la = (int) (19.0f * factor);
} else {
med = (int) Math.round(2.6 * pixelMilliRatio.doubleValue());
sm = (int) Math.round(2 * pixelMilliRatio.doubleValue());
la = (int) Math.round(3.3 * pixelMilliRatio.doubleValue());
}
setFontSize(Integer.parseInt(props.getProperty("mediumFontSize", "" + med)), Integer.parseInt(props.getProperty("smallFontSize", "" + sm)), Integer.parseInt(props.getProperty("largeFontSize", "" + la)));
tablet = props.getProperty("tablet", "false").equalsIgnoreCase("true");
rotateTouchKeysOnLandscape = props.getProperty("rotateKeys", "false").equalsIgnoreCase("true");
touchDevice = props.getProperty("touch", "true").equalsIgnoreCase("true");
keyboardType = Integer.parseInt(props.getProperty("keyboardType", "0"));
softkeyCount = Integer.parseInt(props.getProperty("softbuttonCount", "1"));
if (softkeyCount < 2) {
// the values of the static variables to be correct!
try {
Field f = com.codename1.ui.MenuBar.class.getDeclaredField("leftSK");
f.setAccessible(true);
f.setInt(null, KeyEvent.VK_F1);
f = com.codename1.ui.MenuBar.class.getDeclaredField("rightSK");
f.setAccessible(true);
f.setInt(null, KeyEvent.VK_F2);
} catch (Throwable t) {
t.printStackTrace();
}
}
final byte[] nativeThemeFinalData = nativeThemeData;
Display.getInstance().callSerially(new Runnable() {
public void run() {
if (nativeThemeFinalData != null) {
try {
nativeThemeRes = Resources.open(new ByteArrayInputStream(nativeThemeFinalData));
} catch (IOException ex) {
ex.printStackTrace();
}
} else {
try {
boolean isJ2me = props.getProperty("platformName", "").equals("me");
String t = props.getProperty("nativeThemeAttribute", null);
if (t != null) {
Properties cnop = new Properties();
File cnopFile = new File("codenameone_settings.properties");
if (cnopFile.exists()) {
cnop.load(new FileInputStream(cnopFile));
int themeConst = Integer.parseInt(cnop.getProperty("codename1.j2me.nativeThemeConst", "3"));
t = cnop.getProperty(t, null);
if (isJ2me && themeConst == 3 && t != null && new File(t).exists()) {
nativeThemeRes = Resources.open(new FileInputStream(t));
}
}
}
} catch (IOException ioErr) {
ioErr.printStackTrace();
}
}
}
});
installMenu(frm, false);
} catch (IOException err) {
err.printStackTrace();
}
}
Aggregations