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);
}
}
}
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);
}
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;
}
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);
}
}
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));
}
Aggregations