Search in sources :

Example 26 with Resources

use of com.codename1.ui.util.Resources in project CodenameOne by codenameone.

the class DefaultDocumentRequestHandler method resourceRequested.

private InputStream resourceRequested(final DocumentInfo docInfo, final IOCallback callback) {
    String url = docInfo.getUrl();
    visitingURL(url);
    // trim anchors
    int hash = url.indexOf('#');
    if (hash != -1) {
        url = url.substring(0, hash);
    }
    if (url.startsWith("jar://")) {
        callback.streamReady(Display.getInstance().getResourceAsStream(getClass(), docInfo.getUrl().substring(6)), docInfo);
        return null;
    } else {
        try {
            if (url.startsWith("local://")) {
                Image img = resFile.getImage(url.substring(8));
                if (img instanceof EncodedImage) {
                    callback.streamReady(new ByteArrayInputStream(((EncodedImage) img).getImageData()), docInfo);
                }
            }
            if (url.startsWith("res://")) {
                InputStream i = Display.getInstance().getResourceAsStream(getClass(), docInfo.getUrl().substring(6));
                Resources r = Resources.open(i);
                i.close();
                i = r.getData(docInfo.getParams());
                if (i != null) {
                    callback.streamReady(i, docInfo);
                } else {
                    Image img = r.getImage(docInfo.getParams());
                    if (img instanceof EncodedImage) {
                        callback.streamReady(new ByteArrayInputStream(((EncodedImage) img).getImageData()), docInfo);
                    }
                }
                return null;
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    return null;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Resources(com.codename1.ui.util.Resources) IOException(java.io.IOException) Image(com.codename1.ui.Image) EncodedImage(com.codename1.ui.EncodedImage) EncodedImage(com.codename1.ui.EncodedImage)

Example 27 with Resources

use of com.codename1.ui.util.Resources in project CodenameOne by codenameone.

the class AndroidImplementation method installNativeTheme.

/**
 * Installs the native theme, this is only applicable if hasNativeTheme()
 * returned true. Notice that this method might replace the
 * DefaultLookAndFeel instance and the default transitions.
 */
public void installNativeTheme() {
    hasNativeTheme();
    if (nativeThemeAvailable) {
        try {
            InputStream is;
            if (android.os.Build.VERSION.SDK_INT < 14 && !isTablet() || Display.getInstance().getProperty("and.hololight", "false").equals("true")) {
                is = getResourceAsStream(getClass(), "/androidTheme.res");
            } else {
                is = getResourceAsStream(getClass(), "/android_holo_light.res");
            }
            Resources r = Resources.open(is);
            Hashtable h = r.getTheme(r.getThemeResourceNames()[0]);
            h.put("@commandBehavior", "Native");
            UIManager.getInstance().setThemeProps(h);
            is.close();
            Display.getInstance().setCommandBehavior(Display.COMMAND_BEHAVIOR_NATIVE);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
Also used : BufferedInputStream(com.codename1.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Hashtable(java.util.Hashtable) Resources(com.codename1.ui.util.Resources) IOException(java.io.IOException)

Example 28 with Resources

use of com.codename1.ui.util.Resources in project CodenameOne by codenameone.

the class Resources method readMultiImage.

Image readMultiImage(DataInputStream input, boolean skipAll) throws IOException {
    EncodedImage resultImage = null;
    if (dpi == -1) {
        dpi = Display.getInstance().getDeviceDensity();
    }
    int dpiCount = input.readInt();
    int bestFitOffset = 0;
    int bestFitDPI = 0;
    int[] lengths = new int[dpiCount];
    int[] dpis = new int[dpiCount];
    boolean found = false;
    for (int iter = 0; iter < dpiCount; iter++) {
        int currentDPI = input.readInt();
        lengths[iter] = input.readInt();
        dpis[iter] = currentDPI;
        if (bestFitDPI != dpi && dpi >= currentDPI && currentDPI >= bestFitDPI) {
            bestFitDPI = currentDPI;
            bestFitOffset = iter;
            found = true;
        }
    }
    if (!found) {
        // special case for low DPI devices when running with high resolution resources
        // we want to pick the loweset resolution possible
        bestFitDPI = dpis[0];
        bestFitOffset = 0;
        for (int iter = 1; iter < dpiCount; iter++) {
            if (dpis[iter] < bestFitDPI) {
                bestFitDPI = dpis[iter];
                bestFitOffset = iter;
            }
        }
    }
    if (runtimeMultiImages && !skipAll) {
        byte[][] data = new byte[dpiCount][];
        for (int iter = 0; iter < lengths.length; iter++) {
            int size = lengths[iter];
            data[iter] = new byte[size];
            input.readFully(data[iter], 0, size);
        }
        return EncodedImage.createMulti(dpis, data);
    } else {
        for (int iter = 0; iter < lengths.length; iter++) {
            int size = lengths[iter];
            if (!skipAll && bestFitOffset == iter) {
                byte[] multiImageData = new byte[size];
                input.readFully(multiImageData, 0, size);
                resultImage = EncodedImage.create(multiImageData);
            } else {
                while (size > 0) {
                    size -= input.skip(size);
                }
            }
        }
    }
    return resultImage;
}
Also used : EncodedImage(com.codename1.ui.EncodedImage)

Example 29 with Resources

use of com.codename1.ui.util.Resources in project CodenameOne by codenameone.

the class Resources method loadTheme.

Hashtable loadTheme(String id, boolean newerVersion) throws IOException {
    Hashtable theme = new Hashtable();
    theme.put("name", id);
    // marks the theme as uninitialized so we can finish "wiring" cached resources
    theme.put("uninitialized", Boolean.TRUE);
    int size = input.readShort();
    for (int iter = 0; iter < size; iter++) {
        String key = input.readUTF();
        if (key.startsWith("@")) {
            theme.put(key, input.readUTF());
            continue;
        }
        // if this is a simple numeric value
        if (key.endsWith("Color")) {
            theme.put(key, Integer.toHexString(input.readInt()));
            continue;
        }
        if (key.endsWith("align") || key.endsWith("textDecoration")) {
            theme.put(key, new Integer(input.readShort()));
            continue;
        }
        // if this is a short numeric value for transparency
        if (key.endsWith("ransparency")) {
            theme.put(key, "" + (input.readByte() & 0xff));
            continue;
        }
        if (key.endsWith("opacity")) {
            theme.put(key, "" + (input.readInt() & 0xff));
            continue;
        }
        // if this is a padding or margin then we will have the 4 values as bytes
        if (key.endsWith("adding") || key.endsWith("argin")) {
            if (minorVersion > 7) {
                float p1 = input.readFloat();
                float p2 = input.readFloat();
                float p3 = input.readFloat();
                float p4 = input.readFloat();
                theme.put(key, "" + p1 + "," + p2 + "," + p3 + "," + p4);
            } else {
                int p1 = input.readByte() & 0xff;
                int p2 = input.readByte() & 0xff;
                int p3 = input.readByte() & 0xff;
                int p4 = input.readByte() & 0xff;
                theme.put(key, "" + p1 + "," + p2 + "," + p3 + "," + p4);
            }
            continue;
        }
        // padding and or margin type
        if (key.endsWith("Unit")) {
            byte p1 = input.readByte();
            byte p2 = input.readByte();
            byte p3 = input.readByte();
            byte p4 = input.readByte();
            theme.put(key, new byte[] { p1, p2, p3, p4 });
            continue;
        }
        // border
        if (key.endsWith("order")) {
            int borderType = input.readShort() & 0xffff;
            Object b = createBorder(input, borderType);
            theme.put(key, b);
            continue;
        }
        // if this is a font
        if (key.endsWith("ont")) {
            Font f;
            // is this a new font?
            if (input.readBoolean()) {
                String fontId = input.readUTF();
                f = (Font) resources.get(fontId);
                // if the font is not yet loaded
                if (f == null) {
                    theme.put(key, fontId);
                    continue;
                }
            } else {
                f = Font.createSystemFont(input.readByte(), input.readByte(), input.readByte());
                if (minorVersion > 4) {
                    boolean hasTTF = input.readBoolean();
                    if (hasTTF) {
                        String fileName = input.readUTF();
                        String fontName = input.readUTF();
                        int sizeSetting = input.readInt();
                        float fontSize = input.readFloat();
                        if (Font.isTrueTypeFileSupported()) {
                            f = createTrueTypeFont(f, fontName, fileName, fontSize, sizeSetting);
                        }
                    }
                }
            }
            theme.put(key, f);
            continue;
        }
        // the background property
        if (key.endsWith("ackground")) {
            int type = input.readByte() & 0xff;
            int pos = key.indexOf('.');
            if (pos > -1) {
                key = key.substring(0, pos);
            } else {
                key = "";
            }
            theme.put(key + Style.BACKGROUND_TYPE, new Byte((byte) type));
            switch(type) {
                // Scaled Image
                case 0xF1:
                // Tiled Both Image
                case MAGIC_INDEXED_IMAGE_LEGACY:
                    // the image name coupled with the type
                    theme.put(key + Style.BG_IMAGE, input.readUTF());
                    break;
                // Aligned Image
                case 0xf5:
                // Tiled Vertically Image
                case 0xF2:
                // Tiled Horizontally Image
                case 0xF3:
                    // the image name coupled with the type and with alignment information
                    String imageName = input.readUTF();
                    theme.put(key + Style.BG_IMAGE, imageName);
                    byte align = input.readByte();
                    theme.put(key + Style.BACKGROUND_ALIGNMENT, new Byte(align));
                    break;
                // Horizontal Linear Gradient
                case 0xF6:
                // Vertical Linear Gradient
                case 0xF7:
                    Float c = new Float(0.5f);
                    theme.put(key + Style.BACKGROUND_GRADIENT, new Object[] { new Integer(input.readInt()), new Integer(input.readInt()), c, c, new Float(1) });
                    break;
                // Radial Gradient
                case 0xF8:
                    int c1 = input.readInt();
                    int c2 = input.readInt();
                    float f1 = input.readFloat();
                    float f2 = input.readFloat();
                    float radialSize = 1;
                    if (minorVersion > 1) {
                        radialSize = input.readFloat();
                    }
                    theme.put(key + Style.BACKGROUND_GRADIENT, new Object[] { new Integer(c1), new Integer(c2), new Float(f1), new Float(f2), new Float(radialSize) });
                    break;
            }
            continue;
        }
        // if this is a background image bgImage
        if (key.endsWith("derive")) {
            theme.put(key, input.readUTF());
            continue;
        }
        // if this is a background image bgImage
        if (key.endsWith("bgImage")) {
            String imageId = input.readUTF();
            Image i = getImage(imageId);
            // if the font is not yet loaded
            if (i == null) {
                theme.put(key, imageId);
                continue;
            }
            theme.put(key, i);
            continue;
        }
        if (key.endsWith("scaledImage")) {
            if (input.readBoolean()) {
                theme.put(key, "true");
            } else {
                theme.put(key, "false");
            }
            continue;
        }
        if (key.endsWith(Style.BACKGROUND_TYPE) || key.endsWith(Style.BACKGROUND_ALIGNMENT)) {
            theme.put(key, new Byte(input.readByte()));
            continue;
        }
        if (key.endsWith(Style.BACKGROUND_GRADIENT)) {
            if (minorVersion < 2) {
                theme.put(key, new Object[] { new Integer(input.readInt()), new Integer(input.readInt()), new Float(input.readFloat()), new Float(input.readFloat()) });
            } else {
                theme.put(key, new Object[] { new Integer(input.readInt()), new Integer(input.readInt()), new Float(input.readFloat()), new Float(input.readFloat()), new Float(input.readFloat()) });
            }
            continue;
        }
        // thow an exception no idea what this is
        throw new IOException("Error while trying to read theme property: " + key);
    }
    return theme;
}
Also used : Hashtable(java.util.Hashtable) IOException(java.io.IOException) Image(com.codename1.ui.Image) EncodedImage(com.codename1.ui.EncodedImage) Font(com.codename1.ui.Font) AnimationObject(com.codename1.ui.animations.AnimationObject)

Example 30 with Resources

use of com.codename1.ui.util.Resources in project CodenameOne by codenameone.

the class LazyValueC method createComponent.

private Component createComponent(DataInputStream in, Container parent, Container root, Resources res, Hashtable componentListeners, EmbeddedContainer embedded) throws Exception {
    String name = in.readUTF();
    int property = in.readInt();
    // special case for the base form
    if (property == PROPERTY_BASE_FORM) {
        String baseFormName = name;
        initBaseForm(baseFormName);
        if (!ignorBaseForm) {
            Form base = (Form) createContainer(res, baseFormName);
            Container destination = (Container) findByName("destination", base);
            // try finding an appropriate empty container if no "fixed" destination is defined
            if (destination == null) {
                destination = findEmptyContainer(base.getContentPane());
                if (destination == null) {
                    System.out.println("Couldn't find appropriate 'destination' container in base form: " + baseFormName);
                    return null;
                }
            }
            root = base;
            Component cmp = createComponent(in, destination, root, res, componentListeners, embedded);
            if (destination.getLayout() instanceof BorderLayout) {
                destination.addComponent(BorderLayout.CENTER, cmp);
            } else {
                destination.addComponent(cmp);
            }
            return root;
        } else {
            name = in.readUTF();
            property = in.readInt();
        }
    }
    Component cmp = createComponentType(name);
    if (componentListeners != null) {
        Object listeners = componentListeners.get(name);
        if (listeners != null) {
            if (listeners instanceof Vector) {
                Vector v = (Vector) listeners;
                for (int iter = 0; iter < v.size(); iter++) {
                    bindListenerToComponent(cmp, v.elementAt(iter));
                }
            } else {
                bindListenerToComponent(cmp, listeners);
            }
        }
    }
    Component actualLead = cmp;
    if (actualLead instanceof Container) {
        Container cnt = (Container) actualLead;
        actualLead = cnt.getLeadComponent();
        if (actualLead == null) {
            actualLead = cmp;
        }
    }
    if (actualLead instanceof Button) {
        ActionListener l = getFormListenerInstance(root, embedded);
        if (l != null) {
            ((Button) actualLead).addActionListener(l);
        }
    } else {
        if (actualLead instanceof TextArea) {
            ActionListener l = getFormListenerInstance(root, embedded);
            if (l != null) {
                ((TextArea) actualLead).addActionListener(l);
            }
        } else {
            if (actualLead instanceof List) {
                ActionListener l = getFormListenerInstance(root, embedded);
                if (l != null) {
                    ((List) actualLead).addActionListener(l);
                }
            } else {
                if (actualLead instanceof ContainerList) {
                    ActionListener l = getFormListenerInstance(root, embedded);
                    if (l != null) {
                        ((ContainerList) actualLead).addActionListener(l);
                    }
                } else {
                    if (actualLead instanceof com.codename1.ui.Calendar) {
                        ActionListener l = getFormListenerInstance(root, embedded);
                        if (l != null) {
                            ((com.codename1.ui.Calendar) actualLead).addActionListener(l);
                        }
                    }
                }
            }
        }
    }
    cmp.putClientProperty(TYPE_KEY, name);
    if (root == null) {
        root = (Container) cmp;
    }
    while (property != -1) {
        modifyingProperty(cmp, property);
        switch(property) {
            case PROPERTY_CUSTOM:
                String customPropertyName = in.readUTF();
                modifyingCustomProperty(cmp, customPropertyName);
                boolean isNull = in.readBoolean();
                if (isNull) {
                    cmp.setPropertyValue(customPropertyName, null);
                    break;
                }
                boolean cl = cmp instanceof ContainerList;
                String[] propertyNames = cmp.getPropertyNames();
                for (int iter = 0; iter < propertyNames.length; iter++) {
                    if (propertyNames[iter].equals(customPropertyName)) {
                        Class type = cmp.getPropertyTypes()[iter];
                        String[] typeNames = cmp.getPropertyTypeNames();
                        String typeName = null;
                        if (typeNames != null && typeNames.length > iter) {
                            typeName = typeNames[iter];
                        }
                        Object value = readCustomPropertyValue(in, type, typeName, res, propertyNames[iter]);
                        if (cl && customPropertyName.equals("ListItems") && setListModel((ContainerList) cmp)) {
                            break;
                        }
                        cmp.setPropertyValue(customPropertyName, value);
                        break;
                    }
                }
                break;
            case PROPERTY_EMBED:
                root.putClientProperty(EMBEDDED_FORM_FLAG, "");
                ((EmbeddedContainer) cmp).setEmbed(in.readUTF());
                Container embed = createContainer(res, ((EmbeddedContainer) cmp).getEmbed(), (EmbeddedContainer) cmp);
                if (embed != null) {
                    if (embed instanceof Form) {
                        embed = formToContainer((Form) embed);
                    }
                    ((EmbeddedContainer) cmp).addComponent(BorderLayout.CENTER, embed);
                    // this isn't exactly the "right thing" but its the best we can do to make all
                    // use cases work
                    beforeShowContainer(embed);
                    postShowContainer(embed);
                }
                break;
            case PROPERTY_TOGGLE_BUTTON:
                ((Button) cmp).setToggle(in.readBoolean());
                break;
            case PROPERTY_RADIO_GROUP:
                ((RadioButton) cmp).setGroup(in.readUTF());
                break;
            case PROPERTY_SELECTED:
                boolean isSelected = in.readBoolean();
                if (cmp instanceof RadioButton) {
                    ((RadioButton) cmp).setSelected(isSelected);
                } else {
                    ((CheckBox) cmp).setSelected(isSelected);
                }
                break;
            case PROPERTY_SCROLLABLE_X:
                ((Container) cmp).setScrollableX(in.readBoolean());
                break;
            case PROPERTY_SCROLLABLE_Y:
                ((Container) cmp).setScrollableY(in.readBoolean());
                break;
            case PROPERTY_TENSILE_DRAG_ENABLED:
                cmp.setTensileDragEnabled(in.readBoolean());
                break;
            case PROPERTY_TACTILE_TOUCH:
                cmp.setTactileTouch(in.readBoolean());
                break;
            case PROPERTY_SNAP_TO_GRID:
                cmp.setSnapToGrid(in.readBoolean());
                break;
            case PROPERTY_FLATTEN:
                cmp.setFlatten(in.readBoolean());
                break;
            case PROPERTY_TEXT:
                if (cmp instanceof Label) {
                    ((Label) cmp).setText(in.readUTF());
                } else {
                    ((TextArea) cmp).setText(in.readUTF());
                }
                break;
            case PROPERTY_TEXT_MAX_LENGTH:
                ((TextArea) cmp).setMaxSize(in.readInt());
                break;
            case PROPERTY_TEXT_CONSTRAINT:
                ((TextArea) cmp).setConstraint(in.readInt());
                if (cmp instanceof TextField) {
                    int cons = ((TextArea) cmp).getConstraint();
                    if ((cons & TextArea.NUMERIC) == TextArea.NUMERIC) {
                        ((TextField) cmp).setInputModeOrder(new String[] { "123" });
                    }
                }
                break;
            case PROPERTY_ALIGNMENT:
                if (cmp instanceof Label) {
                    ((Label) cmp).setAlignment(in.readInt());
                } else {
                    ((TextArea) cmp).setAlignment(in.readInt());
                }
                break;
            case PROPERTY_TEXT_AREA_GROW:
                ((TextArea) cmp).setGrowByContent(in.readBoolean());
                break;
            case PROPERTY_LAYOUT:
                Layout layout = null;
                switch(in.readShort()) {
                    case LAYOUT_BORDER_LEGACY:
                        layout = new BorderLayout();
                        break;
                    case LAYOUT_BORDER_ANOTHER_LEGACY:
                        {
                            BorderLayout b = new BorderLayout();
                            if (in.readBoolean()) {
                                b.defineLandscapeSwap(BorderLayout.NORTH, in.readUTF());
                            }
                            if (in.readBoolean()) {
                                b.defineLandscapeSwap(BorderLayout.EAST, in.readUTF());
                            }
                            if (in.readBoolean()) {
                                b.defineLandscapeSwap(BorderLayout.WEST, in.readUTF());
                            }
                            if (in.readBoolean()) {
                                b.defineLandscapeSwap(BorderLayout.SOUTH, in.readUTF());
                            }
                            if (in.readBoolean()) {
                                b.defineLandscapeSwap(BorderLayout.CENTER, in.readUTF());
                            }
                            layout = b;
                            break;
                        }
                    case LAYOUT_BORDER:
                        {
                            BorderLayout b = new BorderLayout();
                            if (in.readBoolean()) {
                                b.defineLandscapeSwap(BorderLayout.NORTH, in.readUTF());
                            }
                            if (in.readBoolean()) {
                                b.defineLandscapeSwap(BorderLayout.EAST, in.readUTF());
                            }
                            if (in.readBoolean()) {
                                b.defineLandscapeSwap(BorderLayout.WEST, in.readUTF());
                            }
                            if (in.readBoolean()) {
                                b.defineLandscapeSwap(BorderLayout.SOUTH, in.readUTF());
                            }
                            if (in.readBoolean()) {
                                b.defineLandscapeSwap(BorderLayout.CENTER, in.readUTF());
                            }
                            b.setAbsoluteCenter(in.readBoolean());
                            layout = b;
                            break;
                        }
                    case LAYOUT_BOX_X:
                        layout = new BoxLayout(BoxLayout.X_AXIS);
                        break;
                    case LAYOUT_BOX_Y:
                        layout = new BoxLayout(BoxLayout.Y_AXIS);
                        break;
                    case LAYOUT_FLOW_LEGACY:
                        layout = new FlowLayout();
                        break;
                    case LAYOUT_FLOW:
                        FlowLayout f = new FlowLayout();
                        f.setFillRows(in.readBoolean());
                        f.setAlign(in.readInt());
                        f.setValign(in.readInt());
                        layout = f;
                        break;
                    case LAYOUT_LAYERED:
                        layout = new LayeredLayout();
                        break;
                    case LAYOUT_GRID:
                        layout = new GridLayout(in.readInt(), in.readInt());
                        break;
                    case LAYOUT_TABLE:
                        layout = new TableLayout(in.readInt(), in.readInt());
                        break;
                }
                ((Container) cmp).setLayout(layout);
                break;
            case PROPERTY_TAB_PLACEMENT:
                ((Tabs) cmp).setTabPlacement(in.readInt());
                break;
            case PROPERTY_TAB_TEXT_POSITION:
                ((Tabs) cmp).setTabTextPosition(in.readInt());
                break;
            case PROPERTY_PREFERRED_WIDTH:
                cmp.setPreferredW(in.readInt());
                break;
            case PROPERTY_PREFERRED_HEIGHT:
                cmp.setPreferredH(in.readInt());
                break;
            case PROPERTY_UIID:
                cmp.setUIID(in.readUTF());
                break;
            case PROPERTY_DIALOG_UIID:
                ((Dialog) cmp).setDialogUIID(in.readUTF());
                break;
            case PROPERTY_DISPOSE_WHEN_POINTER_OUT:
                ((Dialog) cmp).setDisposeWhenPointerOutOfBounds(in.readBoolean());
                break;
            case PROPERTY_CLOUD_BOUND_PROPERTY:
                cmp.setCloudBoundProperty(in.readUTF());
                break;
            case PROPERTY_CLOUD_DESTINATION_PROPERTY:
                cmp.setCloudDestinationProperty(in.readUTF());
                break;
            case PROPERTY_DIALOG_POSITION:
                String pos = in.readUTF();
                if (pos.length() > 0) {
                    ((Dialog) cmp).setDialogPosition(pos);
                }
                break;
            case PROPERTY_FOCUSABLE:
                cmp.setFocusable(in.readBoolean());
                break;
            case PROPERTY_ENABLED:
                cmp.setEnabled(in.readBoolean());
                break;
            case PROPERTY_SCROLL_VISIBLE:
                cmp.setScrollVisible(in.readBoolean());
                break;
            case PROPERTY_ICON:
                ((Label) cmp).setIcon(res.getImage(in.readUTF()));
                break;
            case PROPERTY_ROLLOVER_ICON:
                ((Button) cmp).setRolloverIcon(res.getImage(in.readUTF()));
                break;
            case PROPERTY_PRESSED_ICON:
                ((Button) cmp).setPressedIcon(res.getImage(in.readUTF()));
                break;
            case PROPERTY_DISABLED_ICON:
                ((Button) cmp).setDisabledIcon(res.getImage(in.readUTF()));
                break;
            case PROPERTY_GAP:
                ((Label) cmp).setGap(in.readInt());
                break;
            case PROPERTY_VERTICAL_ALIGNMENT:
                if (cmp instanceof TextArea) {
                    ((TextArea) cmp).setVerticalAlignment(in.readInt());
                } else {
                    ((Label) cmp).setVerticalAlignment(in.readInt());
                }
                break;
            case PROPERTY_TEXT_POSITION:
                ((Label) cmp).setTextPosition(in.readInt());
                break;
            case PROPERTY_CLIENT_PROPERTIES:
                int count = in.readInt();
                StringBuilder sb = new StringBuilder();
                for (int iter = 0; iter < count; iter++) {
                    String k = in.readUTF();
                    String v = in.readUTF();
                    cmp.putClientProperty(k, v);
                    sb.append(k);
                    if (iter < count - 1) {
                        sb.append(",");
                    }
                }
                cmp.putClientProperty("cn1$Properties", sb.toString());
                break;
            case PROPERTY_NAME:
                String componentName = in.readUTF();
                cmp.setName(componentName);
                root.putClientProperty("%" + componentName + "%", cmp);
                break;
            case PROPERTY_LAYOUT_CONSTRAINT:
                if (parent.getLayout() instanceof BorderLayout) {
                    cmp.putClientProperty("layoutConstraint", in.readUTF());
                } else {
                    TableLayout tl = (TableLayout) parent.getLayout();
                    TableLayout.Constraint con = tl.createConstraint(in.readInt(), in.readInt());
                    con.setHeightPercentage(in.readInt());
                    con.setWidthPercentage(in.readInt());
                    con.setHorizontalAlign(in.readInt());
                    con.setHorizontalSpan(in.readInt());
                    con.setVerticalAlign(in.readInt());
                    con.setVerticalSpan(in.readInt());
                    cmp.putClientProperty("layoutConstraint", con);
                }
                break;
            case PROPERTY_TITLE:
                ((Form) cmp).setTitle(in.readUTF());
                break;
            case PROPERTY_COMPONENTS:
                int componentCount = in.readInt();
                if (cmp instanceof Tabs) {
                    for (int iter = 0; iter < componentCount; iter++) {
                        String tab = in.readUTF();
                        Component child = createComponent(in, (Container) cmp, root, res, componentListeners, embedded);
                        ((Tabs) cmp).addTab(tab, child);
                    }
                } else {
                    for (int iter = 0; iter < componentCount; iter++) {
                        Component child = createComponent(in, (Container) cmp, root, res, componentListeners, embedded);
                        Object con = child.getClientProperty("layoutConstraint");
                        if (con != null) {
                            ((Container) cmp).addComponent(con, child);
                        } else {
                            ((Container) cmp).addComponent(child);
                        }
                    }
                }
                break;
            case PROPERTY_COLUMNS:
                ((TextArea) cmp).setColumns(in.readInt());
                break;
            case PROPERTY_ROWS:
                ((TextArea) cmp).setRows(in.readInt());
                break;
            case PROPERTY_HINT:
                if (cmp instanceof List) {
                    ((List) cmp).setHint(in.readUTF());
                } else {
                    ((TextArea) cmp).setHint(in.readUTF());
                }
                break;
            case PROPERTY_HINT_ICON:
                if (cmp instanceof List) {
                    ((List) cmp).setHintIcon(res.getImage(in.readUTF()));
                } else {
                    ((TextArea) cmp).setHintIcon(res.getImage(in.readUTF()));
                }
                break;
            case PROPERTY_ITEM_GAP:
                ((List) cmp).setItemGap(in.readInt());
                break;
            case PROPERTY_LIST_FIXED:
                ((List) cmp).setFixedSelection(in.readInt());
                break;
            case PROPERTY_LIST_ORIENTATION:
                ((List) cmp).setOrientation(in.readInt());
                break;
            case PROPERTY_LIST_ITEMS_LEGACY:
                String[] items = new String[in.readInt()];
                for (int iter = 0; iter < items.length; iter++) {
                    items[iter] = in.readUTF();
                }
                if (!setListModel(((List) cmp))) {
                    ((List) cmp).setModel(new DefaultListModel((Object[]) items));
                }
                break;
            case PROPERTY_LIST_ITEMS:
                Object[] elements = readObjectArrayForListModel(in, res);
                if (!setListModel(((List) cmp))) {
                    ((List) cmp).setModel(new DefaultListModel(elements));
                }
                break;
            case PROPERTY_LIST_RENDERER:
                if (cmp instanceof ContainerList) {
                    ((ContainerList) cmp).setRenderer(readRendererer(res, in));
                } else {
                    ((List) cmp).setRenderer(readRendererer(res, in));
                }
                break;
            case PROPERTY_NEXT_FORM:
                String nextForm = in.readUTF();
                setNextForm(cmp, nextForm, res, root);
                break;
            case PROPERTY_COMMANDS:
                readCommands(in, cmp, res, false);
                break;
            case PROPERTY_COMMANDS_LEGACY:
                readCommands(in, cmp, res, true);
                break;
            case PROPERTY_CYCLIC_FOCUS:
                ((Form) cmp).setCyclicFocus(in.readBoolean());
                break;
            case PROPERTY_RTL:
                cmp.setRTL(in.readBoolean());
                break;
            case PROPERTY_SLIDER_THUMB:
                ((Slider) cmp).setThumbImage(res.getImage(in.readUTF()));
                break;
            case PROPERTY_INFINITE:
                ((Slider) cmp).setInfinite(in.readBoolean());
                break;
            case PROPERTY_PROGRESS:
                ((Slider) cmp).setProgress(in.readInt());
                break;
            case PROPERTY_VERTICAL:
                ((Slider) cmp).setVertical(in.readBoolean());
                break;
            case PROPERTY_EDITABLE:
                if (cmp instanceof TextArea) {
                    ((TextArea) cmp).setEditable(in.readBoolean());
                } else {
                    ((Slider) cmp).setEditable(in.readBoolean());
                }
                break;
            case PROPERTY_INCREMENTS:
                ((Slider) cmp).setIncrements(in.readInt());
                break;
            case PROPERTY_RENDER_PERCENTAGE_ON_TOP:
                ((Slider) cmp).setRenderPercentageOnTop(in.readBoolean());
                break;
            case PROPERTY_MAX_VALUE:
                ((Slider) cmp).setMaxValue(in.readInt());
                break;
            case PROPERTY_MIN_VALUE:
                ((Slider) cmp).setMinValue(in.readInt());
                break;
        }
        property = in.readInt();
    }
    postCreateComponent(cmp);
    return cmp;
}
Also used : FlowLayout(com.codename1.ui.layouts.FlowLayout) Slider(com.codename1.ui.Slider) Form(com.codename1.ui.Form) TextArea(com.codename1.ui.TextArea) ContainerList(com.codename1.ui.list.ContainerList) BoxLayout(com.codename1.ui.layouts.BoxLayout) Label(com.codename1.ui.Label) DefaultListModel(com.codename1.ui.list.DefaultListModel) Container(com.codename1.ui.Container) GridLayout(com.codename1.ui.layouts.GridLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout) Button(com.codename1.ui.Button) RadioButton(com.codename1.ui.RadioButton) Dialog(com.codename1.ui.Dialog) TextField(com.codename1.ui.TextField) List(com.codename1.ui.List) ContainerList(com.codename1.ui.list.ContainerList) Component(com.codename1.ui.Component) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) Vector(java.util.Vector) TableLayout(com.codename1.ui.table.TableLayout) RadioButton(com.codename1.ui.RadioButton) ActionListener(com.codename1.ui.events.ActionListener) BoxLayout(com.codename1.ui.layouts.BoxLayout) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) GridLayout(com.codename1.ui.layouts.GridLayout) FlowLayout(com.codename1.ui.layouts.FlowLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout) Layout(com.codename1.ui.layouts.Layout) TableLayout(com.codename1.ui.table.TableLayout) CheckBox(com.codename1.ui.CheckBox) Tabs(com.codename1.ui.Tabs)

Aggregations

IOException (java.io.IOException)15 Resources (com.codename1.ui.util.Resources)14 FileInputStream (java.io.FileInputStream)6 Hashtable (java.util.Hashtable)6 Container (com.codename1.ui.Container)5 Form (com.codename1.ui.Form)5 UIBuilderOverride (com.codename1.ui.util.UIBuilderOverride)5 InputStream (java.io.InputStream)5 EditableResources (com.codename1.ui.util.EditableResources)4 BufferedInputStream (com.codename1.io.BufferedInputStream)3 Command (com.codename1.ui.Command)3 Component (com.codename1.ui.Component)3 EncodedImage (com.codename1.ui.EncodedImage)3 Image (com.codename1.ui.Image)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 File (java.io.File)3 Button (com.codename1.ui.Button)2 RadioButton (com.codename1.ui.RadioButton)2 AnimationObject (com.codename1.ui.animations.AnimationObject)2 DataInputStream (java.io.DataInputStream)2