Search in sources :

Example 11 with Component

use of com.codename1.ui.Component in project CodenameOne by codenameone.

the class LazyValueC method getFormNavigationStackForComponent.

private Vector getFormNavigationStackForComponent(Component c) {
    if (baseFormNavigationStack == null) {
        return null;
    }
    if (c == null) {
        return baseFormNavigationStack;
    }
    Component root = getRootAncestor(c);
    if (root.getParent() instanceof EmbeddedContainer) {
        Vector nav = (Vector) root.getParent().getClientProperty("$baseNav");
        if (nav == null) {
            nav = new Vector();
            root.getParent().putClientProperty("$baseNav", nav);
        }
        return nav;
    }
    return baseFormNavigationStack;
}
Also used : Component(com.codename1.ui.Component) Vector(java.util.Vector)

Example 12 with Component

use of com.codename1.ui.Component in project CodenameOne by codenameone.

the class LazyValueC method showContainerImpl.

private Container showContainerImpl(String resourceName, Command sourceCommand, Component sourceComponent, boolean forceBack) {
    if (sourceComponent != null) {
        Form currentForm = sourceComponent.getComponentForm();
        // avoid the overhead of searching if no embedding is used
        if (currentForm.getClientProperty(EMBEDDED_FORM_FLAG) != null) {
            Container destContainer = sourceComponent.getParent();
            while (!(destContainer instanceof EmbeddedContainer || destContainer instanceof Form)) {
                // race condition, container was already removed by someone else
                if (destContainer == null) {
                    return null;
                }
                destContainer = destContainer.getParent();
            }
            if (destContainer instanceof EmbeddedContainer) {
                Container cnt = createContainer(fetchResourceFile(), resourceName, (EmbeddedContainer) destContainer);
                if (cnt instanceof Form) {
                    // Form f = (Form)cnt;
                    // cnt = formToContainer(f);
                    showForm((Form) cnt, sourceCommand, sourceComponent);
                    return cnt;
                }
                Component fromCmp = destContainer.getComponentAt(0);
                // This seems to be no longer necessary now that we have the replaceAndWait version that drops events
                // block the user from the ability to press the button twice by mistake
                // fromCmp.setEnabled(false);
                boolean isBack = forceBack;
                Transition t = fromCmp.getUIManager().getLookAndFeel().getDefaultFormTransitionOut();
                if (forceBack) {
                    initBackContainer(cnt, destContainer.getComponentForm(), getFormNavigationStackForComponent(sourceComponent));
                    t = t.copy(true);
                } else {
                    if (sourceCommand != null) {
                        if (t != null && backCommands != null && backCommands.contains(sourceCommand) || Display.getInstance().getCurrent().getBackCommand() == sourceCommand) {
                            isBack = true;
                            t = t.copy(true);
                        }
                    }
                }
                // create a back command if supported
                String commandAction = cnt.getName();
                Vector formNavigationStack = getFormNavigationStackForComponent(fromCmp);
                if (formNavigationStack != null && !isBack && allowBackTo(commandAction) && !isSameBackDestination((Container) fromCmp, cnt)) {
                    // trigger listener creation if this is the only command in the form
                    getFormListenerInstance(destContainer.getComponentForm(), null);
                    formNavigationStack.addElement(getContainerState((com.codename1.ui.Container) fromCmp));
                }
                beforeShowContainer(cnt);
                destContainer.replaceAndWait(fromCmp, cnt, t, true);
                postShowContainer(cnt);
                return cnt;
            } else {
                Container cnt = createContainer(fetchResourceFile(), resourceName);
                showForm((Form) cnt, sourceCommand, sourceComponent);
                return cnt;
            }
        }
    }
    Container cnt = createContainer(fetchResourceFile(), resourceName);
    if (cnt instanceof Form) {
        showForm((Form) cnt, sourceCommand, sourceComponent);
    } else {
        Form f = new Form();
        f.setLayout(new BorderLayout());
        f.addComponent(BorderLayout.CENTER, cnt);
        f.setName("Form" + cnt.getName());
        showForm(f, sourceCommand, sourceComponent);
    }
    return cnt;
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) Transition(com.codename1.ui.animations.Transition) Component(com.codename1.ui.Component) Vector(java.util.Vector)

Example 13 with Component

use of com.codename1.ui.Component in project CodenameOne by codenameone.

the class LazyValueC method storeComponentStateImpl.

private void storeComponentStateImpl(Component c, Hashtable destination) {
    if (c.getName() == null || destination.containsKey(c.getName()) || c.getClientProperty("CN1IgnoreStore") != null) {
        return;
    }
    if (c instanceof Tabs) {
        destination.put(c.getName(), new Integer(((Tabs) c).getSelectedIndex()));
    }
    if (c instanceof Container) {
        Container cnt = (Container) c;
        int count = cnt.getComponentCount();
        for (int iter = 0; iter < count; iter++) {
            storeComponentStateImpl(cnt.getComponentAt(iter), destination);
        }
        return;
    }
    if (c instanceof List) {
        destination.put(c.getName(), new Integer(((List) c).getSelectedIndex()));
        return;
    }
    Object o = c.getComponentState();
    if (o != null) {
        destination.put(c.getName(), o);
    }
}
Also used : Container(com.codename1.ui.Container) Tabs(com.codename1.ui.Tabs) List(com.codename1.ui.List) ContainerList(com.codename1.ui.list.ContainerList)

Example 14 with Component

use of com.codename1.ui.Component 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 15 with Component

use of com.codename1.ui.Component 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)

Aggregations

Component (com.codename1.ui.Component)152 Style (com.codename1.ui.plaf.Style)61 Container (com.codename1.ui.Container)55 Form (com.codename1.ui.Form)41 BorderLayout (com.codename1.ui.layouts.BorderLayout)40 TextArea (com.codename1.ui.TextArea)31 ActionEvent (com.codename1.ui.events.ActionEvent)28 Dimension (com.codename1.ui.geom.Dimension)28 Label (com.codename1.ui.Label)25 Point (com.codename1.ui.geom.Point)22 ArrayList (java.util.ArrayList)22 Rectangle (com.codename1.ui.geom.Rectangle)21 Vector (java.util.Vector)18 Button (com.codename1.ui.Button)16 Dialog (com.codename1.ui.Dialog)16 Hashtable (java.util.Hashtable)16 Image (com.codename1.ui.Image)15 TextField (com.codename1.ui.TextField)15 ActionListener (com.codename1.ui.events.ActionListener)13 BoxLayout (com.codename1.ui.layouts.BoxLayout)13