Search in sources :

Example 1 with BorderLayout

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();
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) InfiniteProgress(com.codename1.components.InfiniteProgress) BoxLayout(com.codename1.ui.layouts.BoxLayout) Label(com.codename1.ui.Label) Image(com.codename1.ui.Image) FontImage(com.codename1.ui.FontImage)

Example 2 with BorderLayout

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;
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) Transition(com.codename1.ui.animations.Transition) Component(com.codename1.ui.Component) Vector(java.util.Vector)

Example 3 with BorderLayout

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;
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Component(com.codename1.ui.Component) TableLayout(com.codename1.ui.table.TableLayout)

Example 4 with BorderLayout

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);
    }
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Component(com.codename1.ui.Component) Vector(java.util.Vector)

Example 5 with BorderLayout

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;
            }
        }
    }
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Component(com.codename1.ui.Component)

Aggregations

BorderLayout (com.codename1.ui.layouts.BorderLayout)64 ActionEvent (com.codename1.ui.events.ActionEvent)27 Container (com.codename1.ui.Container)21 Form (com.codename1.ui.Form)18 ActionListener (com.codename1.ui.events.ActionListener)18 Component (com.codename1.ui.Component)15 BoxLayout (com.codename1.ui.layouts.BoxLayout)14 Label (com.codename1.ui.Label)12 Button (com.codename1.ui.Button)10 IOException (java.io.IOException)9 Dialog (com.codename1.ui.Dialog)8 Hashtable (java.util.Hashtable)8 Command (com.codename1.ui.Command)6 TextArea (com.codename1.ui.TextArea)6 FlowLayout (com.codename1.ui.layouts.FlowLayout)6 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)6 Vector (java.util.Vector)6 RadioButton (com.codename1.ui.RadioButton)5 Animation (com.codename1.ui.animations.Animation)4 Style (com.codename1.ui.plaf.Style)4