use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.
the class DefaultLookAndFeel method getPullToRefreshHeight.
/**
* {@inheritDoc}
*/
public int getPullToRefreshHeight() {
if (pull == null) {
BorderLayout bl = new BorderLayout();
bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
pull = new Container(bl);
}
if (pullDown == null) {
pullDown = new Label(getUIManager().localize("pull.down", "Pull down do refresh..."));
pullDown.setUIID("PullToRefresh");
Image i = UIManager.getInstance().getThemeImageConstant("pullToRefreshImage");
if (i == null) {
i = getDefaultRefreshIcon();
}
i = i.rotate(180);
((Label) pullDown).setIcon(i);
}
if (releaseToRefresh == null) {
releaseToRefresh = new Label(getUIManager().localize("pull.release", "Release to refresh..."));
releaseToRefresh.setUIID("PullToRefresh");
Image i = UIManager.getInstance().getThemeImageConstant("pullToRefreshImage");
if (i == null) {
i = getDefaultRefreshIcon();
}
((Label) releaseToRefresh).setIcon(i);
}
if (updating == null) {
updating = new Container(new BoxLayout(BoxLayout.X_AXIS));
((Container) updating).addComponent(new InfiniteProgress());
Label l = new Label(getUIManager().localize("pull.refresh", "Updating..."));
l.setUIID("PullToRefresh");
((Container) updating).addComponent(l);
pull.getUnselectedStyle().setPadding(0, 0, 0, 0);
pull.getUnselectedStyle().setMargin(0, 0, 0, 0);
pull.addComponent(BorderLayout.CENTER, updating);
pull.layoutContainer();
pull.setHeight(Math.max(pullDown.getPreferredH(), pull.getPreferredH()));
}
String s = UIManager.getInstance().getThemeConstant("pullToRefreshHeight", null);
if (s != null) {
float f = Util.toFloatValue(s);
if (f > 0) {
return Display.getInstance().convertToPixels(f);
}
}
return pull.getHeight();
}
use of com.codename1.ui.layouts.BorderLayout 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.layouts.BorderLayout 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.layouts.BorderLayout in project CodenameOne by codenameone.
the class Tree method buildBranch.
/**
* Adds the child components of a tree branch to the given container.
*/
private void buildBranch(Object parent, int depth, Container destination) {
Vector children = model.getChildren(parent);
int size = children.size();
Integer depthVal = new Integer(depth + 1);
for (int iter = 0; iter < size; iter++) {
final Object current = children.elementAt(iter);
Component nodeComponent = createNode(current, depth);
if (model.isLeaf(current)) {
destination.addComponent(nodeComponent);
bindNodeListener(new Handler(current), nodeComponent);
} else {
Container componentArea = new Container(new BorderLayout());
componentArea.addComponent(BorderLayout.NORTH, nodeComponent);
destination.addComponent(componentArea);
bindNodeListener(expansionListener, nodeComponent);
}
nodeComponent.putClientProperty(KEY_OBJECT, current);
nodeComponent.putClientProperty(KEY_PARENT, parent);
nodeComponent.putClientProperty(KEY_DEPTH, depthVal);
}
}
use of com.codename1.ui.layouts.BorderLayout in project CodenameOne by codenameone.
the class Tree method collapsePathNode.
private void collapsePathNode(Container parent, Object node) {
int cc = parent.getComponentCount();
for (int iter = 0; iter < cc; iter++) {
Component current = parent.getComponentAt(iter);
if (isExpanded(current)) {
BorderLayout bl = (BorderLayout) ((Container) current).getLayout();
// the tree component is always at north expanded or otherwise
current = bl.getNorth();
Object o = current.getClientProperty(KEY_OBJECT);
if (o != null && o.equals(node)) {
if (isExpanded(current)) {
collapseNode(current, null);
}
return;
}
}
}
}
Aggregations