Search in sources :

Example 81 with Container

use of com.codename1.ui.Container in project CodenameOne by codenameone.

the class SideMenuBar method createSideNavigationPanel.

Container createSideNavigationPanel(Vector commands, String placement) {
    Container menu = constructSideNavigationComponent();
    if (getUIManager().isThemeConstant("paintsTitleBarBool", false)) {
        Container bar = new Container();
        bar.setUIID("StatusBarSideMenu");
        addComponentToSideMenu(menu, bar);
    }
    if (!getUIManager().isThemeConstant("sideMenuTensileDragBool", true)) {
        menu.setTensileDragEnabled(false);
    }
    for (int iter = commands.size() - 1; iter > -1; iter--) {
        Command c = (Command) commands.elementAt(iter);
        if (c.getClientProperty(COMMAND_PLACEMENT_KEY) != placement) {
            continue;
        }
        Component cmp = (Component) c.getClientProperty(COMMAND_SIDE_COMPONENT);
        if (cmp != null) {
            if (cmp.getParent() != null) {
                cmp.getParent().removeAll();
            }
            if (c.getClientProperty(COMMAND_ACTIONABLE) != null && c.getClientProperty(COMMAND_ACTIONABLE).equals(Boolean.TRUE)) {
                Container cnt = new Container(new BorderLayout());
                cnt.addComponent(BorderLayout.CENTER, cmp);
                Button btn = createTouchCommandButton(c);
                btn.setParent(cnt);
                cnt.setLeadComponent(btn);
                addComponentToSideMenu(menu, cnt);
            } else {
                addComponentToSideMenu(menu, cmp);
            }
            initTitleBarStatus();
        } else {
            // special case: hide back button that doesn't have text, icon or a side component entry
            if (parent.getBackCommand() == c && (c.getCommandName() == null || c.getCommandName().length() == 0) && c.getIcon() == null) {
                continue;
            }
            addComponentToSideMenu(menu, createTouchCommandButton(c));
        }
    }
    boolean isRTLValue = isRTL();
    if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
        isRTLValue = !isRTLValue;
    }
    UIManager uim = menu.getUIManager();
    boolean shadowEnabled = uim.isThemeConstant("sideMenuShadowBool", true);
    Image sh = (Image) uim.getThemeImageConstant("sideMenuShadowImage");
    if (sh == null && shadowEnabled) {
        sh = Resources.getSystemResource().getImage("sidemenu-shadow.png");
    }
    if (isRTLValue && sh != null) {
        sh = sh.flipHorizontally(true);
    }
    final Image shadow = sh;
    if (shadow == null) {
        return menu;
    } else {
        Container main = new Container(new LayeredLayout());
        Label shadowLabel = new Label();
        shadowLabel.getStyle().setBackgroundType(Style.BACKGROUND_IMAGE_TILE_VERTICAL_ALIGN_CENTER);
        shadowLabel.getStyle().setBgImage(shadow);
        shadowLabel.getStyle().setPadding(0, 0, 0, 0);
        shadowLabel.getStyle().setMargin(0, 0, 0, 0);
        shadowLabel.getStyle().setBgTransparency(0);
        Container c = new Container(new BorderLayout());
        if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
            shadowLabel.setPreferredW(shadow.getWidth());
            c.addComponent(BorderLayout.WEST, shadowLabel);
            shadowLabel.getStyle().setBgImage(shadow.rotate180Degrees(true));
        } else {
            if (placement == COMMAND_PLACEMENT_VALUE_TOP) {
            // shadowLabel.setPreferredH(shadow.getHeight());
            // c.addComponent(BorderLayout.SOUTH, shadowLabel);
            // shadowLabel.getStyle().setBgImage(shadow.rotate90Degrees(true));
            } else {
                shadowLabel.setPreferredW(shadow.getWidth());
                c.addComponent(BorderLayout.EAST, shadowLabel);
            }
        }
        main.addComponent(menu);
        main.addComponent(c);
        return main;
    }
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) UIManager(com.codename1.ui.plaf.UIManager) LayeredLayout(com.codename1.ui.layouts.LayeredLayout)

Example 82 with Container

use of com.codename1.ui.Container in project CodenameOne by codenameone.

the class SideMenuBar method installRightCommands.

void installRightCommands() {
    if (rightCommands != null) {
        for (int i = 0; i < rightCommands.size(); i++) {
            Command rightCommand = (Command) rightCommands.get(rightCommands.size() - 1 - i);
            String uiid = (String) rightCommand.getClientProperty("uiid");
            if (uiid == null) {
                uiid = "TitleCommand";
            }
            int txtPosition = Component.RIGHT;
            Integer pos = (Integer) rightCommand.getClientProperty("textPosition");
            if (pos != null) {
                txtPosition = pos.intValue();
            }
            Layout l = getTitleAreaContainer().getLayout();
            if (l instanceof BorderLayout) {
                final Button b = new Button(rightCommand);
                b.setUIID(uiid);
                b.putClientProperty("TitleCommand", Boolean.TRUE);
                b.setTextPosition(txtPosition);
                BorderLayout bl = (BorderLayout) l;
                final Component east = bl.getEast();
                if (east == null) {
                    getTitleAreaContainer().addComponent(BorderLayout.EAST, b);
                } else {
                    if (east instanceof Container) {
                        Container cnt = (Container) east;
                        // check if this command is already added
                        boolean shouldAdd = true;
                        for (int j = 0; j < cnt.getComponentCount(); j++) {
                            Component c = cnt.getComponentAt(j);
                            if (c instanceof Button) {
                                Command cc = ((Button) c).getCommand();
                                if (cc != null && cc.equals(b.getCommand())) {
                                    shouldAdd = false;
                                    break;
                                }
                            }
                        }
                        if (shouldAdd) {
                            cnt.addComponent(b);
                        }
                    } else {
                        if (east instanceof Button) {
                            Command cc = ((Button) east).getCommand();
                            if (cc != null && cc.equals(b.getCommand())) {
                                continue;
                            }
                        }
                        east.getParent().removeComponent(east);
                        Container buttons = new Container(new BoxLayout(BoxLayout.X_AXIS));
                        buttons.addComponent(east);
                        buttons.addComponent(b);
                        getTitleAreaContainer().addComponent(BorderLayout.EAST, buttons);
                    }
                }
            }
        }
    }
    initTitleBarStatus();
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Layout(com.codename1.ui.layouts.Layout) BoxLayout(com.codename1.ui.layouts.BoxLayout) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout) BoxLayout(com.codename1.ui.layouts.BoxLayout)

Example 83 with Container

use of com.codename1.ui.Container in project CodenameOne by codenameone.

the class SideMenuBar method installLeftCommands.

void installLeftCommands() {
    if (leftCommands != null) {
        for (int i = 0; i < leftCommands.size(); i++) {
            Command leftCommand = (Command) leftCommands.get(leftCommands.size() - 1 - i);
            String uiid = (String) leftCommand.getClientProperty("uiid");
            if (uiid == null) {
                uiid = "TitleCommand";
            }
            int txtPosition = Component.RIGHT;
            Integer pos = (Integer) leftCommand.getClientProperty("textPosition");
            if (pos != null) {
                txtPosition = pos.intValue();
            }
            Layout l = getTitleAreaContainer().getLayout();
            if (l instanceof BorderLayout) {
                Button b = new Button(leftCommand);
                b.setUIID(uiid);
                b.putClientProperty("TitleCommand", Boolean.TRUE);
                b.setTextPosition(txtPosition);
                BorderLayout bl = (BorderLayout) l;
                Component west = bl.getWest();
                if (west == null) {
                    getTitleAreaContainer().addComponent(BorderLayout.WEST, b);
                } else {
                    if (west instanceof Container) {
                        Container cnt = (Container) west;
                        // check if this command is already added
                        boolean shouldAdd = true;
                        for (int j = 0; j < cnt.getComponentCount(); j++) {
                            Component c = cnt.getComponentAt(j);
                            if (c instanceof Button) {
                                Command cc = ((Button) c).getCommand();
                                if (cc != null && cc.equals(b.getCommand())) {
                                    shouldAdd = false;
                                    break;
                                }
                            }
                        }
                        if (shouldAdd) {
                            cnt.addComponent(b);
                        }
                    } else {
                        if (west instanceof Button) {
                            Command cc = ((Button) west).getCommand();
                            if (cc != null && cc.equals(b.getCommand())) {
                                continue;
                            }
                        }
                        west.getParent().removeComponent(west);
                        Container buttons = new Container(new BoxLayout(BoxLayout.X_AXIS));
                        buttons.addComponent(west);
                        buttons.addComponent(b);
                        getTitleAreaContainer().addComponent(BorderLayout.WEST, buttons);
                    }
                }
            }
        }
    }
    initTitleBarStatus();
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Layout(com.codename1.ui.layouts.Layout) BoxLayout(com.codename1.ui.layouts.BoxLayout) LayeredLayout(com.codename1.ui.layouts.LayeredLayout) BorderLayout(com.codename1.ui.layouts.BorderLayout) BoxLayout(com.codename1.ui.layouts.BoxLayout)

Example 84 with Container

use of com.codename1.ui.Container in project CodenameOne by codenameone.

the class SideMenuBar method createMenu.

private Form createMenu(final String placement) {
    final Form m = new Form() {

        private boolean pressedInRightPanel;

        private boolean manualMotionLock;

        protected boolean shouldSendPointerReleaseToOtherForm() {
            return true;
        }

        void actionCommandImpl(Command cmd, ActionEvent ev) {
            if (cmd instanceof SideMenuBar.CommandWrapper) {
                cmd = ((SideMenuBar.CommandWrapper) cmd).cmd;
                ev = new ActionEvent(cmd, ActionEvent.Type.Command);
            }
            final Command c = cmd;
            final ActionEvent e = ev;
            Display.getInstance().scheduleBackgroundTask(new Runnable() {

                public void run() {
                    Display.getInstance().invokeAndBlock(new Runnable() {

                        public void run() {
                            while (Display.getInstance().getCurrent() != parent) {
                                try {
                                    Thread.sleep(40);
                                } catch (Exception ex) {
                                }
                            }
                        }
                    });
                    Display.getInstance().callSerially(new Runnable() {

                        public void run() {
                            parent.actionCommandImpl(c, e);
                        }
                    });
                }
            });
        }

        protected void sizeChanged(int w, int h) {
            Style formStyle = getStyle();
            int width = w - (formStyle.getHorizontalMargins());
            parent.sizeChangedInternal(w, h);
            // close the menu
            if (getWidth() != width) {
                closeMenu();
            }
            super.sizeChanged(w, h);
        }

        public void pointerPressed(int x, int y) {
            if (manualMotionLock) {
                return;
            }
            super.pointerPressed(x, y);
            if (rightPanel.contains(x, y)) {
                pressedInRightPanel = true;
            }
        }

        public void pointerDragged(int[] x, int[] y) {
            if (manualMotionLock) {
                return;
            }
            if (!transitionRunning && pressedInRightPanel) {
                dragActivated = true;
                pressedInRightPanel = false;
            }
            if (dragActivated) {
                setMenuGlassPane(menu, placement);
                draggedX = x[0];
                repaint();
                return;
            }
            super.pointerDragged(x, y);
        }

        public void pointerReleased(int x, int y) {
            if (manualMotionLock) {
                return;
            }
            super.pointerReleased(x, y);
            boolean isRTLValue = isRTL();
            if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
                isRTLValue = !isRTLValue;
            }
            int displayWidth = Display.getInstance().getDisplayWidth();
            if (isRTLValue) {
                if (!transitionRunning && dragActivated && x < (displayWidth - rightPanel.getWidth()) / 2) {
                    final Motion motion = Motion.createEaseInOutMotion(draggedX, rightPanel.getWidth(), 200);
                    motion.start();
                    registerAnimated(new Animation() {

                        public boolean animate() {
                            draggedX = motion.getValue();
                            if (motion.isFinished()) {
                                dragActivated = false;
                                Display.getInstance().getCurrent().setGlassPane(null);
                                deregisterAnimated(this);
                            }
                            return true;
                        }

                        public void paint(Graphics g) {
                            repaint();
                        }
                    });
                    return;
                }
            } else {
                if (!transitionRunning && dragActivated && x > (displayWidth - rightPanel.getWidth()) / 2) {
                    final Motion motion = Motion.createEaseInOutMotion(draggedX, Display.getInstance().getDisplayWidth() - rightPanel.getWidth(), 200);
                    motion.start();
                    registerAnimated(new Animation() {

                        public boolean animate() {
                            draggedX = motion.getValue();
                            if (motion.isFinished()) {
                                dragActivated = false;
                                Display.getInstance().getCurrent().setGlassPane(null);
                                deregisterAnimated(this);
                            }
                            return true;
                        }

                        public void paint(Graphics g) {
                            repaint();
                        }
                    });
                    return;
                }
            }
            if (dragActivated || rightPanel.contains(x, y)) {
                setMenuGlassPane(menu, placement);
                draggedX = x;
                int start = x;
                int end = 0;
                if (isRTLValue) {
                    end = getWidth();
                }
                final Motion motion = Motion.createEaseInOutMotion(start, end, getUIManager().getThemeConstant("sideMenuAnimSpeedInt", 300));
                motion.start();
                manualMotionLock = true;
                sideSwipePotential = false;
                rightSideSwipePotential = false;
                topSwipePotential = false;
                registerAnimated(new Animation() {

                    public boolean animate() {
                        draggedX = motion.getValue();
                        if (motion.isFinished()) {
                            dragActivated = false;
                        }
                        return true;
                    }

                    public void paint(Graphics g) {
                        repaint();
                        if (draggedX == motion.getDestinationValue() && motion.isFinished()) {
                            parent.setTransitionInAnimator(CommonTransitions.createEmpty());
                            parent.show();
                            deregisterAnimated(this);
                            Display.getInstance().callSerially(new Runnable() {

                                public void run() {
                                    clean();
                                }
                            });
                        }
                    }
                });
            }
        }

        public void keyReleased(int keyCode) {
            if (keyCode == leftSK) {
                if (transitionRunning) {
                    return;
                }
                closeMenu();
                return;
            }
            super.keyReleased(keyCode);
        }
    };
    m.setScrollable(false);
    m.removeComponentFromForm(m.getTitleArea());
    m.putClientProperty("Menu", "true");
    m.setTransitionInAnimator(CommonTransitions.createEmpty());
    m.setTransitionOutAnimator(CommonTransitions.createEmpty());
    m.setBackCommand(new Command("") {

        public void actionPerformed(ActionEvent evt) {
            if (transitionRunning) {
                return;
            }
            closeMenu();
        }
    });
    m.setLayout(new BorderLayout());
    if (Display.getInstance().areMutableImagesFast()) {
        rightPanel = new Container(new BorderLayout());
    } else {
        rightPanel = new Container(new BorderLayout()) {

            public void paintBackground(Graphics g) {
            }

            public void paintBackgrounds(Graphics g) {
            }

            public void paint(Graphics g) {
                Component c = (Component) rightPanel.getClientProperty("$parent");
                // not sure why its happening: https://code.google.com/p/codenameone/issues/detail?id=1072
                if (c != null) {
                    boolean b = c.isVisible();
                    c.setVisible(true);
                    int x = getAbsoluteX();
                    g.translate(x, 0);
                    Container.sidemenuBarTranslation = x;
                    c.paintComponent(g, true);
                    Container.sidemenuBarTranslation = 0;
                    g.translate(-x, 0);
                    c.setVisible(b);
                }
            }
        };
    }
    if (placement == COMMAND_PLACEMENT_VALUE_TOP) {
        int v = 0;
        if (Display.getInstance().isPortrait()) {
            if (Display.getInstance().isTablet()) {
                v = getUIManager().getThemeConstant("topMenuSizeTabPortraitInt", -1);
                if (v < 0) {
                    v = m.getHeight() * 2 / 3;
                } else {
                    v = m.getHeight() / 100 * v;
                }
            } else {
                v = getUIManager().getThemeConstant("topMenuSizePortraitInt", -1);
                if (v < 0) {
                    v = openButton.getHeight();
                } else {
                    v = m.getHeight() / 100 * v;
                }
            }
        } else {
            if (Display.getInstance().isTablet()) {
                v = getUIManager().getThemeConstant("topMenuSizeTabLandscapeInt", -1);
                if (v < 0) {
                    v = m.getHeight() * 3 / 4;
                } else {
                    v = m.getWidth() / 100 * v;
                }
            } else {
                v = getUIManager().getThemeConstant("topMenuSizeLandscapeInt", -1);
                if (v < 0) {
                    v = m.getHeight() * 4 / 10;
                } else {
                    v = m.getHeight() / 100 * v;
                }
            }
        }
        rightPanel.setPreferredH(v);
    } else {
        if (Display.getInstance().isPortrait()) {
            int v = 0;
            if (Display.getInstance().isTablet()) {
                v = getUIManager().getThemeConstant("sideMenuSizeTabPortraitInt", -1);
                if (v < 0) {
                    v = m.getWidth() * 2 / 3;
                } else {
                    v = m.getWidth() / 100 * v;
                }
            } else {
                v = getUIManager().getThemeConstant("sideMenuSizePortraitInt", -1);
                if (v < 0) {
                    if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
                        if (isRTL()) {
                            v = openButton.getWidth();
                        } else {
                            v = rightSideButton.getWidth();
                        }
                    } else {
                        v = openButton.getWidth();
                    }
                } else {
                    v = m.getWidth() / 100 * v;
                }
            }
            rightPanel.setPreferredW(v);
        } else {
            int v = 0;
            if (Display.getInstance().isTablet()) {
                v = getUIManager().getThemeConstant("sideMenuSizeTabLandscapeInt", -1);
                if (v < 0) {
                    v = m.getWidth() * 3 / 4;
                } else {
                    v = m.getWidth() / 100 * v;
                }
            } else {
                v = getUIManager().getThemeConstant("sideMenuSizeLandscapeInt", -1);
                if (v < 0) {
                    v = m.getWidth() * 4 / 10;
                } else {
                    v = m.getWidth() / 100 * v;
                }
            }
            rightPanel.setPreferredW(v);
        }
    }
    if (sidePanel != null) {
        sidePanel.removeAll();
        sidePanel = null;
    }
    sidePanel = createSideNavigationComponent(getCommands(), placement);
    if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
        m.addComponent(BorderLayout.WEST, rightPanel);
        m.addComponent(BorderLayout.CENTER, sidePanel);
    } else {
        if (placement == COMMAND_PLACEMENT_VALUE_TOP) {
            m.addComponent(BorderLayout.NORTH, rightPanel);
            m.addComponent(BorderLayout.CENTER, sidePanel);
            Button button = new Button(" ");
            button.setUIID("Container");
            button.setPreferredH(Display.getInstance().getDisplayHeight() / 10);
            m.addComponent(BorderLayout.SOUTH, button);
            button.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent evt) {
                    closeMenu();
                }
            });
        } else {
            m.addComponent(BorderLayout.EAST, rightPanel);
            m.addComponent(BorderLayout.CENTER, sidePanel);
        }
    }
    m.putClientProperty("cn1$sideMenuParent", this);
    return m;
}
Also used : Motion(com.codename1.ui.animations.Motion) ActionEvent(com.codename1.ui.events.ActionEvent) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) Style(com.codename1.ui.plaf.Style) Animation(com.codename1.ui.animations.Animation)

Example 85 with Container

use of com.codename1.ui.Container in project CodenameOne by codenameone.

the class TextComponent method constructUI.

void constructUI() {
    if (getComponentCount() == 0) {
        if (isOnTopMode() && isFocusAnimation()) {
            getLabel().setUIID("FloatingHint");
            setLayout(new LayeredLayout());
            Container tfContainer = BorderLayout.center(field).add(BorderLayout.NORTH, getLabel()).add(BorderLayout.SOUTH, getErrorMessage());
            add(tfContainer);
            Label errorMessageFiller = new Label();
            Component.setSameSize(errorMessageFiller, getErrorMessage());
            animationLayer = BorderLayout.south(errorMessageFiller);
            add(animationLayer);
            if (field.getText() == null || field.getText().length() == 0) {
                field.setHint(getLabel().getText());
                getLabel().setVisible(false);
            }
        } else {
            super.constructUI();
        }
    }
}
Also used : LayeredLayout(com.codename1.ui.layouts.LayeredLayout)

Aggregations

Container (com.codename1.ui.Container)85 Component (com.codename1.ui.Component)65 BorderLayout (com.codename1.ui.layouts.BorderLayout)46 Style (com.codename1.ui.plaf.Style)38 ActionEvent (com.codename1.ui.events.ActionEvent)29 Form (com.codename1.ui.Form)26 Label (com.codename1.ui.Label)21 BoxLayout (com.codename1.ui.layouts.BoxLayout)21 Dimension (com.codename1.ui.geom.Dimension)20 ActionListener (com.codename1.ui.events.ActionListener)19 Button (com.codename1.ui.Button)15 FlowLayout (com.codename1.ui.layouts.FlowLayout)15 ArrayList (java.util.ArrayList)14 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)12 TextArea (com.codename1.ui.TextArea)11 Point (com.codename1.ui.geom.Point)11 Rectangle (com.codename1.ui.geom.Rectangle)11 Dialog (com.codename1.ui.Dialog)10 RadioButton (com.codename1.ui.RadioButton)10 Vector (java.util.Vector)9