Search in sources :

Example 1 with Resources

use of com.codename1.ui.util.Resources in project codenameone-google-maps by codenameone.

the class GoogleMapsTestApp method init.

public void init(Object context) {
    try {
        Resources theme = Resources.openLayered("/theme");
        UIManager.getInstance().setThemeProps(theme.getTheme(theme.getThemeResourceNames()[0]));
        Display.getInstance().setCommandBehavior(Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION);
        UIManager.getInstance().getLookAndFeel().setMenuBarClass(SideMenuBar.class);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Resources(com.codename1.ui.util.Resources) IOException(java.io.IOException)

Example 2 with Resources

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

the class LazyValueC method readCommand.

private void readCommand(DataInputStream in, Component c, Container parent, Resources res, boolean legacy) throws IOException {
    String commandName = in.readUTF();
    String commandImageName = in.readUTF();
    String rollover = null;
    String pressed = null;
    String disabled = null;
    if (!legacy) {
        rollover = in.readUTF();
        pressed = in.readUTF();
        disabled = in.readUTF();
    }
    int commandId = in.readInt();
    String commandAction = in.readUTF();
    String commandArgument = "";
    if (commandAction.equals("$Execute")) {
        commandArgument = in.readUTF();
    }
    boolean isBack = in.readBoolean();
    Command cmd = createCommandImpl(commandName, res.getImage(commandImageName), commandId, commandAction, isBack, commandArgument);
    if (rollover != null && rollover.length() > 0) {
        cmd.setRolloverIcon(res.getImage(rollover));
    }
    if (pressed != null && pressed.length() > 0) {
        cmd.setPressedIcon(res.getImage(pressed));
    }
    if (disabled != null && disabled.length() > 0) {
        cmd.setPressedIcon(res.getImage(pressed));
    }
    if (isBack) {
        Form f = c.getComponentForm();
        if (f != null) {
            setBackCommand(f, cmd);
        } else {
            if (backCommands == null) {
                backCommands = new Vector();
            }
            backCommands.addElement(cmd);
        }
    }
    Button btn;
    if (c instanceof Container) {
        btn = (Button) ((Container) c).getLeadComponent();
    } else {
        btn = ((Button) c);
    }
    boolean e = btn.isEnabled();
    btn.setCommand(cmd);
    // special case since setting the command implicitly gets the enabled state from the command
    if (!e) {
        btn.setEnabled(false);
    }
    // no menu
    if (c.getComponentForm() != null) {
        btn.removeActionListener(getFormListenerInstance(parent, null));
    }
    cmd.putClientProperty(COMMAND_ARGUMENTS, commandArgument);
    cmd.putClientProperty(COMMAND_ACTION, commandAction);
    if (commandAction.length() > 0 && resourceFilePath == null || isKeepResourcesInRam()) {
        resourceFile = res;
    }
}
Also used : Container(com.codename1.ui.Container) Command(com.codename1.ui.Command) Form(com.codename1.ui.Form) Button(com.codename1.ui.Button) RadioButton(com.codename1.ui.RadioButton) Vector(java.util.Vector)

Example 3 with Resources

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

the class LazyValueC method readObjectArrayForListModel.

private Object[] readObjectArrayForListModel(DataInputStream in, Resources res) throws IOException {
    Object[] elements = new Object[in.readInt()];
    int elen = elements.length;
    for (int iter = 0; iter < elen; iter++) {
        switch(in.readByte()) {
            case // String
            1:
                elements[iter] = in.readUTF();
                break;
            case // hashtable of Strings
            2:
                int hashSize = in.readInt();
                Hashtable val = new Hashtable();
                elements[iter] = val;
                for (int i = 0; i < hashSize; i++) {
                    int type = in.readInt();
                    if (type == 1) {
                        // String
                        String key = in.readUTF();
                        Object value = in.readUTF();
                        if (key.equals("$navigation")) {
                            Command cmd = createCommandImpl((String) value, null, -1, (String) value, false, "");
                            cmd.putClientProperty(COMMAND_ACTION, (String) value);
                            value = cmd;
                        }
                        val.put(key, value);
                    } else {
                        val.put(in.readUTF(), res.getImage(in.readUTF()));
                    }
                }
                break;
        }
    }
    return elements;
}
Also used : Command(com.codename1.ui.Command) Hashtable(java.util.Hashtable)

Example 4 with Resources

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

the class LazyValueC method postCreateComponents.

/**
 * Invoked after the components were created to allow properties that require the entire
 * tree to exist to update the component. This is useful for properties that point
 * at other components.
 */
private void postCreateComponents(DataInputStream in, Container parent, Resources res) throws Exception {
    // finds the component whose properties need to update
    String name = in.readUTF();
    Component lastComponent = null;
    while (name.length() > 0) {
        if (lastComponent == null || !lastComponent.getName().equals(name)) {
            lastComponent = findByName(name, parent);
        }
        Component c = lastComponent;
        int property = in.readInt();
        modifyingProperty(c, property);
        switch(property) {
            case PROPERTY_COMMAND_LEGACY:
                {
                    readCommand(in, c, parent, res, true);
                    break;
                }
            case PROPERTY_COMMAND:
                {
                    readCommand(in, c, parent, res, false);
                    break;
                }
            case PROPERTY_LABEL_FOR:
                c.setLabelForComponent((Label) findByName(in.readUTF(), parent));
                break;
            case PROPERTY_LEAD_COMPONENT:
                ((Container) c).setLeadComponent(findByName(in.readUTF(), parent));
                break;
            case PROPERTY_NEXT_FOCUS_UP:
                c.setNextFocusUp(findByName(in.readUTF(), parent));
                break;
            case PROPERTY_NEXT_FOCUS_DOWN:
                c.setNextFocusDown(findByName(in.readUTF(), parent));
                break;
            case PROPERTY_NEXT_FOCUS_LEFT:
                c.setNextFocusLeft(findByName(in.readUTF(), parent));
                break;
            case PROPERTY_NEXT_FOCUS_RIGHT:
                c.setNextFocusRight(findByName(in.readUTF(), parent));
                break;
        }
        name = in.readUTF();
    }
}
Also used : Container(com.codename1.ui.Container) Component(com.codename1.ui.Component)

Example 5 with Resources

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

the class LazyValueC method createContainer.

Container createContainer(Resources res, String resourceName, EmbeddedContainer parentContainer) {
    onCreateRoot(resourceName);
    InputStream source = res.getUi(resourceName);
    if (source == null) {
        throw new RuntimeException("Resource doesn't exist within the current resource object: " + resourceName);
    }
    DataInputStream in = new DataInputStream(source);
    try {
        Hashtable h = null;
        if (localComponentListeners != null) {
            h = (Hashtable) localComponentListeners.get(resourceName);
        }
        Container c = (Container) createComponent(in, null, null, res, h, parentContainer);
        c.setName(resourceName);
        postCreateComponents(in, c, res);
        // try to be smart about initializing the home form
        if (homeForm == null) {
            if (c instanceof Form) {
                String nextForm = (String) c.getClientProperty("%next_form%");
                if (nextForm != null) {
                    homeForm = nextForm;
                } else {
                    homeForm = resourceName;
                }
            }
        }
        return c;
    } catch (Exception ex) {
        // If this happens its probably a serious bug
        ex.printStackTrace();
        return null;
    }
}
Also used : Container(com.codename1.ui.Container) Form(com.codename1.ui.Form) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) Hashtable(java.util.Hashtable) DataInputStream(java.io.DataInputStream) IOException(java.io.IOException)

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