Search in sources :

Example 96 with com.codename1.io

use of com.codename1.io 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);
}
Also used : JLabel(javax.swing.JLabel) EmbeddedContainer(com.codename1.ui.util.EmbeddedContainer) BorderLayout(com.codename1.ui.layouts.BorderLayout) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) List(java.util.List) JList(javax.swing.JList) BorderLayout(com.codename1.ui.layouts.BorderLayout) EventObject(java.util.EventObject) TableLayout(com.codename1.ui.table.TableLayout) Hashtable(java.util.Hashtable) Hashtable(java.util.Hashtable) Point(java.awt.Point)

Example 97 with com.codename1.io

use of com.codename1.io in project CodenameOne by codenameone.

the class CN1CSSCLI method compile.

private static void compile(File inputFile, File outputFile) throws IOException {
    File baseDir = inputFile.getParentFile().getParentFile();
    File checksumsFile = getChecksumsFile(baseDir);
    if (!checksumsFile.exists()) {
        saveChecksums(baseDir, new HashMap<String, String>());
    }
    if (!checksumsFile.exists()) {
        throw new RuntimeException("Failed to create checksums file");
    }
    FileChannel channel = new RandomAccessFile(checksumsFile, "rw").getChannel();
    FileLock lock = channel.lock();
    try {
        Map<String, String> checksums = loadChecksums(baseDir);
        if (outputFile.exists() && !isMavenProject(inputFile)) {
            String outputFileChecksum = getMD5Checksum(outputFile.getAbsolutePath());
            String previousChecksum = checksums.get(inputFile.getName());
            if (previousChecksum == null || !previousChecksum.equals(outputFileChecksum)) {
                File backups = new File(inputFile.getParentFile(), ".backups");
                backups.mkdirs();
                File bak = new File(backups, outputFile.getName() + "." + System.currentTimeMillis() + ".bak");
                Files.copy(outputFile.toPath(), bak.toPath(), StandardCopyOption.REPLACE_EXISTING);
                System.out.println(outputFile + " has been modified since it was last compiled.  Making copy at " + bak);
                outputFile.delete();
            }
        }
        if (outputFile.exists() && inputFile.lastModified() <= outputFile.lastModified()) {
            System.out.println("File has not changed since last compile.");
            return;
        }
        try {
            URL url = inputFile.toURI().toURL();
            // CSSTheme theme = CSSTheme.load(CSSTheme.class.getResource("test.css"));
            CSSTheme theme = CSSTheme.load(url);
            theme.cssFile = inputFile;
            theme.resourceFile = outputFile;
            JavaSEPort.setBaseResourceDir(outputFile.getParentFile());
            WebViewProvider webViewProvider = new WebViewProvider() {

                @Override
                public BrowserComponent getWebView() {
                    if (web == null) {
                        if (!CN1Bootstrap.isCEFLoaded()) /* && !CN1Bootstrap.isJavaFXLoaded()*/
                        {
                            // to output the correct bounds so we are killing FX support.  CEF only.
                            throw new MissingNativeBrowserException();
                        }
                        if (!CN.isEdt()) {
                            CN.callSerially(() -> {
                                getWebView();
                            });
                            int counter = 0;
                            while (web == null && counter++ < 50) {
                                Util.sleep(100);
                            }
                            return web;
                        }
                        web = new BrowserComponent();
                        ComponentSelector.select("*", web).add(web, true).selectAllStyles().setBgTransparency(0).setMargin(0).setPadding(0).setBorder(Border.createEmpty()).each(new ComponentClosure() {

                            @Override
                            public void call(Component c) {
                                c.setOpaque(false);
                            }
                        });
                        web.setOpaque(false);
                        Form f = new Form();
                        f.getContentPane().getStyle().setBgColor(0xff0000);
                        f.getContentPane().getStyle().setBgTransparency(0xff);
                        if (f.getToolbar() == null) {
                            f.setToolbar(new com.codename1.ui.Toolbar());
                        }
                        f.getToolbar().hideToolbar();
                        f.setLayout(new com.codename1.ui.layouts.BorderLayout());
                        f.add(CN.CENTER, web);
                        f.show();
                    }
                    return web;
                }
            };
            File cacheFile = new File(theme.cssFile.getParentFile(), theme.cssFile.getName() + ".checksums");
            if (outputFile.exists() && cacheFile.exists()) {
                theme.loadResourceFile();
                theme.loadSelectorCacheStatus(cacheFile);
            }
            theme.createImageBorders(webViewProvider);
            theme.updateResources();
            theme.save(outputFile);
            theme.saveSelectorChecksums(cacheFile);
            String checksum = getMD5Checksum(outputFile.getAbsolutePath());
            checksums.put(inputFile.getName(), checksum);
            saveChecksums(baseDir, checksums);
        } catch (MalformedURLException ex) {
            Logger.getLogger(CN1CSSCLI.class.getName()).log(Level.SEVERE, null, ex);
        }
    } finally {
        if (lock != null) {
            lock.release();
        }
        if (channel != null) {
            channel.close();
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Form(com.codename1.ui.Form) URL(java.net.URL) FileLock(java.nio.channels.FileLock) BrowserComponent(com.codename1.ui.BrowserComponent) Component(com.codename1.ui.Component) FileChannel(java.nio.channels.FileChannel) RandomAccessFile(java.io.RandomAccessFile) BrowserComponent(com.codename1.ui.BrowserComponent) WebViewProvider(com.codename1.designer.css.CSSTheme.WebViewProvider) ComponentClosure(com.codename1.ui.ComponentSelector.ComponentClosure) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 98 with com.codename1.io

use of com.codename1.io in project CodenameOne by codenameone.

the class CN1CSSCompiler method scaleMultiImage.

public static EditableResources.MultiImage scaleMultiImage(int fromDPI, int toDPI, int scaledWidth, int scaledHeight, EditableResources.MultiImage multi) {
    try {
        int[] dpis = multi.getDpi();
        com.codename1.ui.EncodedImage[] imgs = multi.getInternalImages();
        int fromOffset = -1;
        int toOffset = -1;
        for (int iter = 0; iter < dpis.length; iter++) {
            if (dpis[iter] == fromDPI) {
                fromOffset = iter;
            }
            if (dpis[iter] == toDPI) {
                toOffset = iter;
            }
        }
        if (fromOffset == -1) {
            return null;
        }
        EditableResources.MultiImage newImage = new EditableResources.MultiImage();
        if (toOffset == -1) {
            com.codename1.ui.EncodedImage[] newImages = new com.codename1.ui.EncodedImage[imgs.length + 1];
            System.arraycopy(imgs, 0, newImages, 0, imgs.length);
            toOffset = imgs.length;
            int[] newDpis = new int[dpis.length + 1];
            System.arraycopy(dpis, 0, newDpis, 0, dpis.length);
            newDpis[toOffset] = toDPI;
            newImage.setDpi(newDpis);
            newImage.setInternalImages(newImages);
        } else {
            com.codename1.ui.EncodedImage[] newImages = new com.codename1.ui.EncodedImage[imgs.length];
            System.arraycopy(multi.getInternalImages(), 0, newImages, 0, imgs.length);
            newImage.setDpi(dpis);
            newImage.setInternalImages(newImages);
        }
        com.codename1.ui.Image sourceImage = newImage.getInternalImages()[fromOffset];
        BufferedImage buffer = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
        buffer.setRGB(0, 0, sourceImage.getWidth(), sourceImage.getHeight(), sourceImage.getRGB(), 0, sourceImage.getWidth());
        sourceImage.getRGB();
        sourceImage.getWidth();
        BufferedImage scaled = getScaledInstance(buffer, scaledWidth, scaledHeight);
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        ImageIO.write(scaled, "png", output);
        output.close();
        byte[] bytes = output.toByteArray();
        com.codename1.ui.EncodedImage encoded = com.codename1.ui.EncodedImage.create(bytes);
        newImage.getInternalImages()[toOffset] = encoded;
        return newImage;
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return null;
}
Also used : BufferedImage(java.awt.image.BufferedImage) EditableResources(com.codename1.ui.util.EditableResources)

Example 99 with com.codename1.io

use of com.codename1.io in project CodenameOne by codenameone.

the class CSSTheme method createImageBorders.

public void createImageBorders(WebViewProvider webviewProvider) {
    if (res == null) {
        res = new EditableResourcesForCSS(resourceFile);
    }
    ArrayList<Border> borders = new ArrayList<Border>();
    ResourcesMutator resm = new ResourcesMutator(res, Display.DENSITY_VERY_HIGH, minDpi, maxDpi);
    resm.targetDensity = targetDensity;
    List<Runnable> onComplete = new ArrayList<Runnable>();
    for (String id : elements.keySet()) {
        try {
            if (!isModified(id)) {
                continue;
            }
            Element e = (Element) elements.get(id);
            Element unselected = e.getUnselected();
            Map<String, LexicalUnit> unselectedStyles = (Map<String, LexicalUnit>) unselected.getFlattenedStyle();
            Border b = unselected.createBorder(unselectedStyles);
            Border unselectedBorder = b;
            currentId = id;
            if (e.requiresImageBorder(unselectedStyles)) {
                if (!borders.contains(b)) {
                    borders.add(b);
                    resm.addImageProcessor(id, (img) -> {
                        Insets insets = unselected.getImageBorderInsets(unselectedStyles, img.getWidth(), img.getHeight());
                        resm.targetDensity = getSourceDensity(unselectedStyles, resm.targetDensity);
                        com.codename1.ui.plaf.Border border = resm.create9PieceBorder(img, id, (int) insets.top, (int) insets.right, (int) insets.bottom, (int) insets.left);
                        resm.put(id + ".border", border);
                        unselectedBorder.border = border;
                        resm.targetDensity = targetDensity;
                    });
                } else {
                    onComplete.add(() -> {
                        resm.put(id + ".border", borders.get(borders.indexOf(unselectedBorder)).border);
                    });
                }
            } else if (e.requiresBackgroundImageGeneration(unselectedStyles)) {
                if (!borders.contains(b)) {
                    borders.add(b);
                    resm.addImageProcessor(id, (img) -> {
                        int i = 1;
                        while (res.containsResource(id + "_" + i + ".png")) {
                            i++;
                        }
                        String prefix = id + "_" + i + ".png";
                        resm.targetDensity = getSourceDensity(unselectedStyles, resm.targetDensity);
                        Image im = resm.storeImage(EncodedImage.create(ResourcesMutator.toPngOrJpeg(img)), prefix, false);
                        unselectedBorder.image = im;
                        resm.put(id + ".bgImage", im);
                        resm.targetDensity = targetDensity;
                    // resm.put(id+".press#bgType", Style.B)
                    });
                } else {
                    onComplete.add(() -> {
                        resm.put(id + ".bgImage", unselectedBorder.image);
                    });
                }
            }
            Element selected = e.getSelected();
            Map<String, LexicalUnit> selectedStyles = (Map<String, LexicalUnit>) selected.getFlattenedStyle();
            b = selected.createBorder(selectedStyles);
            Border selectedBorder = b;
            if (e.requiresImageBorder(selectedStyles)) {
                if (!borders.contains(b)) {
                    borders.add(b);
                    resm.addImageProcessor(id + ".sel", (img) -> {
                        Insets insets = selected.getImageBorderInsets(selectedStyles, img.getWidth(), img.getHeight());
                        resm.targetDensity = getSourceDensity(selectedStyles, resm.targetDensity);
                        com.codename1.ui.plaf.Border border = resm.create9PieceBorder(img, id, (int) insets.top, (int) insets.right, (int) insets.bottom, (int) insets.left);
                        resm.put(id + ".sel#border", border);
                        selectedBorder.border = border;
                        resm.targetDensity = targetDensity;
                    });
                } else {
                    onComplete.add(() -> {
                        resm.put(id + ".sel#border", borders.get(borders.indexOf(selectedBorder)).border);
                    });
                }
            } else if (e.requiresBackgroundImageGeneration(selectedStyles)) {
                if (!borders.contains(b)) {
                    borders.add(b);
                    resm.addImageProcessor(id + ".sel", (img) -> {
                        int i = 1;
                        while (res.containsResource(id + "_" + i + ".png")) {
                            i++;
                        }
                        String prefix = id + "_" + i + ".png";
                        resm.targetDensity = getSourceDensity(selectedStyles, resm.targetDensity);
                        Image im = resm.storeImage(EncodedImage.create(ResourcesMutator.toPngOrJpeg(img)), prefix, false);
                        selectedBorder.image = im;
                        resm.put(id + ".sel#bgImage", im);
                        // resm.put(id+".press#bgType", Style.B)
                        resm.targetDensity = targetDensity;
                    });
                } else {
                    onComplete.add(() -> {
                        resm.put(id + ".sel#bgImage", selectedBorder.image);
                    });
                }
            }
            Element pressed = e.getPressed();
            Map<String, LexicalUnit> pressedStyles = (Map<String, LexicalUnit>) pressed.getFlattenedStyle();
            b = pressed.createBorder(pressedStyles);
            Border pressedBorder = b;
            if (e.requiresImageBorder(pressedStyles)) {
                if (!borders.contains(b)) {
                    borders.add(b);
                    resm.addImageProcessor(id + ".press", (img) -> {
                        Insets insets = pressed.getImageBorderInsets(pressedStyles, img.getWidth(), img.getHeight());
                        resm.targetDensity = getSourceDensity(pressedStyles, resm.targetDensity);
                        com.codename1.ui.plaf.Border border = resm.create9PieceBorder(img, id, (int) insets.top, (int) insets.right, (int) insets.bottom, (int) insets.left);
                        resm.put(id + ".press#border", border);
                        pressedBorder.border = border;
                        resm.targetDensity = targetDensity;
                    });
                } else {
                    onComplete.add(() -> {
                        resm.put(id + ".press#border", borders.get(borders.indexOf(pressedBorder)).border);
                    });
                }
            } else if (e.requiresBackgroundImageGeneration(pressedStyles)) {
                if (!borders.contains(b)) {
                    borders.add(b);
                    resm.addImageProcessor(id + ".press", (img) -> {
                        int i = 1;
                        while (res.containsResource(id + "_" + i + ".png")) {
                            i++;
                        }
                        String prefix = id + "_" + i + ".png";
                        resm.targetDensity = getSourceDensity(pressedStyles, resm.targetDensity);
                        Image im = resm.storeImage(EncodedImage.create(ResourcesMutator.toPngOrJpeg(img)), prefix, false);
                        pressedBorder.imageId = prefix;
                        resm.put(id + ".press#bgImage", im);
                        resm.targetDensity = targetDensity;
                    // resm.put(id+".press#bgType", Style.B)
                    });
                } else {
                    onComplete.add(() -> {
                        resm.put(id + ".press#bgImage", res.findId(pressedBorder.imageId, true));
                    });
                }
            }
            Element disabled = e.getDisabled();
            Map<String, LexicalUnit> disabledStyles = (Map<String, LexicalUnit>) disabled.getFlattenedStyle();
            b = disabled.createBorder(disabledStyles);
            Border disabledBorder = b;
            if (e.requiresImageBorder(disabledStyles)) {
                if (!borders.contains(b)) {
                    borders.add(b);
                    resm.addImageProcessor(id + ".dis", (img) -> {
                        Insets disabledInsets = disabled.getImageBorderInsets(disabledStyles, img.getWidth(), img.getHeight());
                        resm.targetDensity = getSourceDensity(disabledStyles, resm.targetDensity);
                        com.codename1.ui.plaf.Border border = resm.create9PieceBorder(img, id, (int) disabledInsets.top, (int) disabledInsets.right, (int) disabledInsets.bottom, (int) disabledInsets.left);
                        disabledBorder.border = border;
                        resm.put(id + ".dis#border", border);
                        resm.targetDensity = targetDensity;
                    });
                } else {
                    onComplete.add(() -> {
                        resm.put(id + ".dis#border", borders.get(borders.indexOf(disabledBorder)).border);
                    });
                }
            } else if (e.requiresBackgroundImageGeneration(disabledStyles)) {
                if (!borders.contains(b)) {
                    borders.add(b);
                    resm.addImageProcessor(id + ".dis", (img) -> {
                        int i = 1;
                        while (res.containsResource(id + "_" + i + ".png")) {
                            i++;
                        }
                        String prefix = id + "_" + i + ".png";
                        resm.targetDensity = getSourceDensity(disabledStyles, resm.targetDensity);
                        Image im = resm.storeImage(EncodedImage.create(ResourcesMutator.toPngOrJpeg(img)), prefix, false);
                        disabledBorder.image = im;
                        resm.put(id + ".dis#bgImage", im);
                        resm.targetDensity = targetDensity;
                    // resm.put(id+".press#bgType", Style.B)
                    });
                } else {
                    onComplete.add(() -> {
                        resm.put(id + ".dis#bgImage", disabledBorder.image);
                    });
                }
            }
        } catch (Exception ex) {
            throw new RuntimeException("An exception occurred while processing the image border for element " + id, ex);
        }
    }
    if (requiresCaptureHtml()) {
        resm.createScreenshots(webviewProvider.getWebView(), generateCaptureHtml(), this.baseURL.toExternalForm());
    }
    for (Runnable r : onComplete) {
        r.run();
    }
}
Also used : Arrays(java.util.Arrays) CharArrayReader(java.io.CharArrayReader) URL(java.net.URL) ConditionalSelector(org.w3c.css.sac.ConditionalSelector) URISyntaxException(java.net.URISyntaxException) ObjectInputStream(java.io.ObjectInputStream) IIOMetadata(javax.imageio.metadata.IIOMetadata) SelectorList(org.w3c.css.sac.SelectorList) CSSParseException(org.w3c.css.sac.CSSParseException) IIOMetadataNode(javax.imageio.metadata.IIOMetadataNode) DocumentHandler(org.w3c.css.sac.DocumentHandler) ParserFactory(org.w3c.css.sac.helpers.ParserFactory) EditorTTFFont(com.codename1.ui.EditorTTFFont) Vector(java.util.Vector) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) Display(com.codename1.ui.Display) RoundRectBorder(com.codename1.ui.plaf.RoundRectBorder) Locale(java.util.Locale) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) Condition(org.w3c.css.sac.Condition) LexicalUnit(org.w3c.css.sac.LexicalUnit) Set(java.util.Set) InputSource(org.w3c.css.sac.InputSource) Logger(java.util.logging.Logger) Style(com.codename1.ui.plaf.Style) FileNotFoundException(java.io.FileNotFoundException) ImageInputStream(javax.imageio.stream.ImageInputStream) List(java.util.List) SACMediaList(org.w3c.css.sac.SACMediaList) ParseException(org.w3c.flute.parser.ParseException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CSSBorder(com.codename1.ui.plaf.CSSBorder) Util(com.codename1.io.Util) EditableResources(com.codename1.ui.util.EditableResources) MessageDigest(java.security.MessageDigest) CSSException(org.w3c.css.sac.CSSException) ElementSelector(org.w3c.css.sac.ElementSelector) HashMap(java.util.HashMap) AttributeCondition(org.w3c.css.sac.AttributeCondition) Selector(org.w3c.css.sac.Selector) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Accessor(com.codename1.ui.plaf.Accessor) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Parser(org.w3c.css.sac.Parser) SimpleSelector(org.w3c.css.sac.SimpleSelector) Component(com.codename1.ui.Component) Node(org.w3c.dom.Node) EncodedImage(com.codename1.ui.EncodedImage) ObjectOutputStream(java.io.ObjectOutputStream) NamedNodeMap(org.w3c.dom.NamedNodeMap) LinkedList(java.util.LinkedList) Hashtable(java.util.Hashtable) OutputStream(java.io.OutputStream) EditableResourcesForCSS(com.codename1.ui.util.EditableResourcesForCSS) ImageReader(javax.imageio.ImageReader) ErrorHandler(org.w3c.css.sac.ErrorHandler) NodeList(org.w3c.dom.NodeList) Iterator(java.util.Iterator) Image(com.codename1.ui.Image) AnimationAccessor(com.codename1.ui.animations.AnimationAccessor) Resources(com.codename1.ui.util.Resources) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) JSONParser(com.codename1.io.JSONParser) RoundBorder(com.codename1.ui.plaf.RoundBorder) InputStreamReader(java.io.InputStreamReader) File(java.io.File) StringReader(java.io.StringReader) Font(com.codename1.ui.Font) Result(com.codename1.processing.Result) Collections(java.util.Collections) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) EncodedImage(com.codename1.ui.EncodedImage) Image(com.codename1.ui.Image) URISyntaxException(java.net.URISyntaxException) CSSParseException(org.w3c.css.sac.CSSParseException) FileNotFoundException(java.io.FileNotFoundException) ParseException(org.w3c.flute.parser.ParseException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CSSException(org.w3c.css.sac.CSSException) IOException(java.io.IOException) EditableResourcesForCSS(com.codename1.ui.util.EditableResourcesForCSS) RoundRectBorder(com.codename1.ui.plaf.RoundRectBorder) CSSBorder(com.codename1.ui.plaf.CSSBorder) RoundBorder(com.codename1.ui.plaf.RoundBorder) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) LexicalUnit(org.w3c.css.sac.LexicalUnit)

Example 100 with com.codename1.io

use of com.codename1.io in project CodenameOne by codenameone.

the class CSSTheme method isInUse.

private boolean isInUse(String imageName) {
    if (isImageReferencedInCSS(imageName)) {
        return true;
    }
    Object multi = res.getResourceObject(imageName);
    if (multi instanceof EditableResources.MultiImage) {
        EditableResources.MultiImage m = (EditableResources.MultiImage) multi;
        for (com.codename1.ui.Image i : m.getInternalImages()) {
            if (isInUse(i)) {
                return true;
            }
        }
        return false;
    }
    com.codename1.ui.Image resourceValue = res.getImage(imageName);
    return isInUse(resourceValue);
}
Also used : Image(com.codename1.ui.Image) EditableResources(com.codename1.ui.util.EditableResources)

Aggregations

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