Search in sources :

Example 6 with Form

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

the class LazyValueC method showForm.

/**
 * This method is equivalent to the internal navigation behavior, it adds
 * functionality such as the back command into the given form resource and
 * shows it. If the source command is the back command the showBack() method
 * will run.
 *
 * @param resourceName the name of the resource for the form to show
 * @param sourceCommand the command of the resource (may be null)
 * @return the form thats being shown, notice that you can still manipulate
 * some states of the form before it actually appears
 */
public Form showForm(String resourceName, Command sourceCommand) {
    Form f = (Form) createContainer(fetchResourceFile(), resourceName);
    showForm(f, sourceCommand, null);
    return f;
}
Also used : Form(com.codename1.ui.Form)

Example 7 with Form

use of com.codename1.ui.Form 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 8 with Form

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

Example 9 with Form

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

the class LazyValueC method formToContainer.

Container formToContainer(Form f) {
    Container cnt = new Container(f.getContentPane().getLayout());
    if (f.getContentPane().getLayout() instanceof BorderLayout || f.getContentPane().getLayout() instanceof TableLayout) {
        while (f.getContentPane().getComponentCount() > 0) {
            Component src = f.getContentPane().getComponentAt(0);
            Object o = f.getContentPane().getLayout().getComponentConstraint(src);
            f.getContentPane().removeComponent(src);
            cnt.addComponent(o, src);
        }
    } else {
        while (f.getContentPane().getComponentCount() > 0) {
            Component src = f.getContentPane().getComponentAt(0);
            f.getContentPane().removeComponent(src);
            cnt.addComponent(src);
        }
    }
    return cnt;
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Component(com.codename1.ui.Component) TableLayout(com.codename1.ui.table.TableLayout)

Example 10 with Form

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

the class LazyValueC method back.

/**
 * This method effectively pops the form navigation stack and goes back
 * to the previous form if back navigation is enabled and there is
 * a previous form.
 *
 * @param sourceComponent the component that triggered the back command which effectively
 * allows us to find the EmbeddedContainer for a case of container navigation. Null
 * can be used if not applicable.
 */
public void back(Component sourceComponent) {
    Vector formNavigationStack = getFormNavigationStackForComponent(sourceComponent);
    if (formNavigationStack != null && formNavigationStack.size() > 0) {
        Hashtable h = (Hashtable) formNavigationStack.elementAt(formNavigationStack.size() - 1);
        if (h.containsKey(FORM_STATE_KEY_CONTAINER)) {
            Form currentForm = Display.getInstance().getCurrent();
            if (currentForm != null) {
                exitForm(currentForm);
            }
        }
        String formName = (String) h.get(FORM_STATE_KEY_NAME);
        if (!h.containsKey(FORM_STATE_KEY_CONTAINER)) {
            Form f = (Form) createContainer(fetchResourceFile(), formName);
            initBackForm(f);
            onBackNavigation();
            beforeShow(f);
            f.showBack();
            postShowImpl(f);
        } else {
            showContainerImpl(formName, null, sourceComponent, true);
        }
    }
}
Also used : Form(com.codename1.ui.Form) Hashtable(java.util.Hashtable) Vector(java.util.Vector)

Aggregations

Form (com.codename1.ui.Form)90 ActionEvent (com.codename1.ui.events.ActionEvent)41 Component (com.codename1.ui.Component)38 BorderLayout (com.codename1.ui.layouts.BorderLayout)38 Container (com.codename1.ui.Container)26 ActionListener (com.codename1.ui.events.ActionListener)25 Dialog (com.codename1.ui.Dialog)21 Command (com.codename1.ui.Command)19 Hashtable (java.util.Hashtable)17 Label (com.codename1.ui.Label)14 Style (com.codename1.ui.plaf.Style)14 IOException (java.io.IOException)14 TextArea (com.codename1.ui.TextArea)13 Vector (java.util.Vector)12 Button (com.codename1.ui.Button)11 Graphics (com.codename1.ui.Graphics)9 RadioButton (com.codename1.ui.RadioButton)9 Animation (com.codename1.ui.animations.Animation)9 Image (com.codename1.ui.Image)8 UIManager (com.codename1.ui.plaf.UIManager)8