Search in sources :

Example 71 with Command

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

the class LazyValueC method initBackForm.

private void initBackForm(Form f) {
    Vector formNavigationStack = baseFormNavigationStack;
    if (formNavigationStack != null && formNavigationStack.size() > 0) {
        setFormState(f, (Hashtable) formNavigationStack.elementAt(formNavigationStack.size() - 1));
        formNavigationStack.removeElementAt(formNavigationStack.size() - 1);
        if (formNavigationStack.size() > 0) {
            Hashtable previous = (Hashtable) formNavigationStack.elementAt(formNavigationStack.size() - 1);
            String commandAction = (String) previous.get(FORM_STATE_KEY_NAME);
            Command backCommand = createCommandImpl(getBackCommandText((String) previous.get(FORM_STATE_KEY_TITLE)), null, BACK_COMMAND_ID, commandAction, true, "");
            setBackCommand(f, backCommand);
            // trigger listener creation if this is the only command in the form
            getFormListenerInstance(f, null);
            backCommand.putClientProperty(COMMAND_ARGUMENTS, "");
            backCommand.putClientProperty(COMMAND_ACTION, commandAction);
        }
    }
}
Also used : Command(com.codename1.ui.Command) Hashtable(java.util.Hashtable) Vector(java.util.Vector)

Example 72 with Command

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

the class LazyValueC method reloadForm.

/**
 * Useful tool to refresh the current state of a form shown using show form
 * without pushing another instance to the back stack
 */
public void reloadForm() {
    Form currentForm = Display.getInstance().getCurrent();
    Command backCommand = currentForm.getBackCommand();
    Form newForm = (Form) createContainer(fetchResourceFile(), currentForm.getName());
    if (backCommand != null) {
        setBackCommand(newForm, backCommand);
        // trigger listener creation if this is the only command in the form
        getFormListenerInstance(newForm, null);
        for (int iter = 0; iter < currentForm.getCommandCount(); iter++) {
            if (backCommand == currentForm.getCommand(iter)) {
                newForm.addCommand(backCommand, newForm.getCommandCount());
                break;
            }
        }
    }
    beforeShow(newForm);
    Transition tin = newForm.getTransitionInAnimator();
    Transition tout = newForm.getTransitionOutAnimator();
    currentForm.setTransitionInAnimator(CommonTransitions.createEmpty());
    currentForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
    newForm.setTransitionInAnimator(CommonTransitions.createEmpty());
    newForm.setTransitionOutAnimator(CommonTransitions.createEmpty());
    newForm.layoutContainer();
    newForm.show();
    postShowImpl(newForm);
    newForm.setTransitionInAnimator(tin);
    newForm.setTransitionOutAnimator(tout);
}
Also used : Form(com.codename1.ui.Form) Command(com.codename1.ui.Command) Transition(com.codename1.ui.animations.Transition)

Example 73 with Command

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

the class LazyValueC method getFormState.

/**
 * Returns the state of the current form which we are about to leave as part
 * of the navigation logic. When a back command will return to this form the
 * state would be restored using setFormState.
 * The default implementation of this method restores focus and list selection.
 * You can add arbitrary keys to the form state, keys starting with a $ sign
 * are reserved for the UIBuilder base class use.
 *
 * @param f the form whose state should be preserved
 * @return arbitrary state object
 */
protected Hashtable getFormState(Form f) {
    Component c = f.getFocused();
    Hashtable h = new Hashtable();
    // can happen if we navigate away from a form that was shown without the GUI builder
    if (f.getName() != null) {
        h.put(FORM_STATE_KEY_NAME, f.getName());
    }
    if (c != null) {
        if (c instanceof List) {
            h.put(FORM_STATE_KEY_SELECTION, new Integer(((List) c).getSelectedIndex()));
        }
        if (c.getName() != null) {
            h.put(FORM_STATE_KEY_FOCUS, c.getName());
        }
        if (f.getTitle() != null) {
            h.put(FORM_STATE_KEY_TITLE, f.getTitle());
        }
    }
    storeComponentState(f, h);
    return h;
}
Also used : Hashtable(java.util.Hashtable) List(com.codename1.ui.List) ContainerList(com.codename1.ui.list.ContainerList) Component(com.codename1.ui.Component)

Example 74 with Command

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

the class LazyValueC method initBackContainer.

private void initBackContainer(Container cnt, Form destForm, Vector formNavigationStack) {
    setContainerState(cnt, (Hashtable) formNavigationStack.elementAt(formNavigationStack.size() - 1));
    formNavigationStack.removeElementAt(formNavigationStack.size() - 1);
    if (formNavigationStack.size() > 0) {
        Hashtable previous = (Hashtable) formNavigationStack.elementAt(formNavigationStack.size() - 1);
        String commandAction = (String) previous.get(FORM_STATE_KEY_NAME);
        Command backCommand = createCommandImpl(getBackCommandText((String) previous.get(FORM_STATE_KEY_TITLE)), null, BACK_COMMAND_ID, commandAction, true, "");
        setBackCommand(destForm, backCommand);
        backCommand.putClientProperty(COMMAND_ARGUMENTS, "");
        backCommand.putClientProperty(COMMAND_ACTION, commandAction);
    }
}
Also used : Command(com.codename1.ui.Command) Hashtable(java.util.Hashtable)

Example 75 with Command

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

the class GameCanvasImplementation method editString.

/**
 * @inheritDoc
 */
public void editString(Component cmp, int maxSize, int constraint, String text, int keyCode) {
    UIManager m = UIManager.getInstance();
    CONFIRM_COMMAND = new Command(m.localize("ok", "OK"), Command.OK, 1);
    CANCEL_COMMAND = new Command(m.localize("cancel", "Cancel"), Command.CANCEL, 2);
    if (mid.getAppProperty("forceBackCommand") != null) {
        canvas.addCommand(MIDP_BACK_COMMAND);
    }
    currentTextBox = new TextBox("", "", maxSize, TextArea.ANY);
    currentTextBox.setCommandListener((CommandListener) canvas);
    currentTextBox.addCommand(CONFIRM_COMMAND);
    currentTextBox.addCommand(CANCEL_COMMAND);
    currentTextComponent = cmp;
    currentTextBox.setMaxSize(maxSize);
    currentTextBox.setString(text);
    currentTextBox.setConstraints(constraint);
    display.setCurrent(currentTextBox);
    ((C) canvas).setDone(false);
    Display.getInstance().invokeAndBlock(((C) canvas));
}
Also used : Command(javax.microedition.lcdui.Command) UIManager(com.codename1.ui.plaf.UIManager) TextBox(javax.microedition.lcdui.TextBox)

Aggregations

BorderLayout (com.codename1.ui.layouts.BorderLayout)25 Command (com.codename1.ui.Command)24 ActionEvent (com.codename1.ui.events.ActionEvent)22 Form (com.codename1.ui.Form)20 Hashtable (java.util.Hashtable)13 UIManager (com.codename1.ui.plaf.UIManager)11 Container (com.codename1.ui.Container)10 ActionListener (com.codename1.ui.events.ActionListener)10 GridLayout (com.codename1.ui.layouts.GridLayout)9 Button (com.codename1.ui.Button)8 Style (com.codename1.ui.plaf.Style)8 IOException (java.io.IOException)7 Vector (java.util.Vector)7 Component (com.codename1.ui.Component)6 Dialog (com.codename1.ui.Dialog)6 BoxLayout (com.codename1.ui.layouts.BoxLayout)6 ArrayList (java.util.ArrayList)6 RadioButton (com.codename1.ui.RadioButton)5 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)5 CheckBox (com.codename1.ui.CheckBox)4