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