use of com.codename1.ui.Component in project CodenameOne by codenameone.
the class LazyValueC method restoreComponentState.
/**
* By default Codename One stores the states of components in the navigation graph
* as it moves between forms. However, some components aren't recognized by Codename One
* by default to enable smaller executable size. This method can be overriden to enable
* storing the state of custom components
*
* @param c the component whose state should be restored
* @param destination the hashtable containing the state
*/
protected void restoreComponentState(Component c, Hashtable destination) {
if (shouldAutoStoreState()) {
Enumeration e = destination.keys();
while (e.hasMoreElements()) {
String currentKey = (String) e.nextElement();
Component cmp = findByName(currentKey, c);
if (cmp != null) {
Object value = destination.get(currentKey);
if (value instanceof Integer) {
if (cmp instanceof List) {
((List) cmp).setSelectedIndex(((Integer) value).intValue());
continue;
}
if (cmp instanceof Tabs) {
int val = ((Integer) value).intValue();
Tabs t = (Tabs) cmp;
if (t.getTabCount() > val) {
t.setSelectedIndex(val);
}
continue;
}
}
cmp.setComponentState(value);
}
}
}
}
use of com.codename1.ui.Component in project CodenameOne by codenameone.
the class LazyValueC method setContainerStateImpl.
private void setContainerStateImpl(Container cnt, Hashtable state) {
if (state != null) {
restoreComponentState(cnt, state);
String cmpName = (String) state.get(FORM_STATE_KEY_FOCUS);
if (cmpName == null) {
return;
}
Component c = findByName(cmpName, cnt);
if (c != null) {
c.requestFocus();
if (c instanceof List) {
Integer i = (Integer) state.get(FORM_STATE_KEY_SELECTION);
if (i != null) {
((List) c).setSelectedIndex(i.intValue());
}
}
}
}
}
use of com.codename1.ui.Component 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;
}
use of com.codename1.ui.Component in project CodenameOne by codenameone.
the class LazyValueC method createComponentType.
Component createComponentType(String name) throws IllegalAccessException, InstantiationException, RuntimeException {
Class c = (Class) getComponentRegistry().get(name);
Component cmp = createComponentInstance(name, c);
if (cmp == null) {
if (c == null) {
throw new RuntimeException("Component not found use UIBuilder.registerCustomComponent(" + name + ", class);");
}
cmp = (Component) c.newInstance();
}
return cmp;
}
use of com.codename1.ui.Component 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);
}
}
}
Aggregations