Search in sources :

Example 21 with UIManager

use of com.codename1.ui.plaf.UIManager in project CodenameOne by codenameone.

the class Toolbar method showOverflowMenu.

/*
     * A Overflow Menu is implemented as a dialog, this method allows you to 
     * override the dialog display in order to customize the dialog menu in 
     * various ways
     * 
     * @param menu a dialog containing Overflow Menu options that can be 
     * customized
     * @return the command selected by the user in the dialog
     */
protected Command showOverflowMenu(Dialog menu) {
    Form parent = sideMenu.getParentForm();
    int height;
    int marginLeft;
    int marginRight = 0;
    Container dialogContentPane = menu.getDialogComponent();
    marginLeft = parent.getWidth() - (dialogContentPane.getPreferredW() + menu.getStyle().getHorizontalPadding());
    marginLeft = Math.max(0, marginLeft);
    if (parent.getSoftButtonCount() > 1) {
        height = parent.getHeight() - parent.getSoftButton(0).getParent().getPreferredH() - dialogContentPane.getPreferredH();
    } else {
        height = parent.getHeight() - dialogContentPane.getPreferredH();
    }
    height = Math.max(0, height);
    int th = getHeight();
    Transition transitionIn;
    Transition transitionOut;
    UIManager manager = parent.getUIManager();
    LookAndFeel lf = manager.getLookAndFeel();
    if (lf.getDefaultMenuTransitionIn() != null || lf.getDefaultMenuTransitionOut() != null) {
        transitionIn = lf.getDefaultMenuTransitionIn();
        if (transitionIn instanceof BubbleTransition) {
            ((BubbleTransition) transitionIn).setComponentName("OverflowButton");
        }
        transitionOut = lf.getDefaultMenuTransitionOut();
    } else {
        transitionIn = CommonTransitions.createEmpty();
        transitionOut = CommonTransitions.createEmpty();
    }
    menu.setTransitionInAnimator(transitionIn);
    menu.setTransitionOutAnimator(transitionOut);
    if (isRTL()) {
        marginRight = marginLeft;
        marginLeft = 0;
    }
    int tint = parent.getTintColor();
    parent.setTintColor(0x00FFFFFF);
    parent.tint = false;
    boolean showBelowTitle = manager.isThemeConstant("showMenuBelowTitleBool", true);
    int topPadding = 0;
    Component statusBar = ((BorderLayout) getLayout()).getNorth();
    if (statusBar != null) {
        topPadding = statusBar.getAbsoluteY() + statusBar.getHeight();
    }
    if (showBelowTitle) {
        topPadding = th;
    }
    Command r = menu.show(topPadding, Math.max(topPadding, height - topPadding), marginLeft, marginRight, true);
    parent.setTintColor(tint);
    return r;
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Transition(com.codename1.ui.animations.Transition) BubbleTransition(com.codename1.ui.animations.BubbleTransition) UIManager(com.codename1.ui.plaf.UIManager) LookAndFeel(com.codename1.ui.plaf.LookAndFeel) BubbleTransition(com.codename1.ui.animations.BubbleTransition)

Example 22 with UIManager

use of com.codename1.ui.plaf.UIManager in project CodenameOne by codenameone.

the class Form method initLaf.

/**
 * {@inheritDoc}
 */
protected void initLaf(UIManager uim) {
    super.initLaf(uim);
    LookAndFeel laf = uim.getLookAndFeel();
    transitionOutAnimator = laf.getDefaultFormTransitionOut();
    transitionInAnimator = laf.getDefaultFormTransitionIn();
    focusScrolling = laf.isFocusScrolling();
    if (menuBar == null || !menuBar.getClass().equals(laf.getMenuBarClass())) {
        try {
            menuBar = (MenuBar) laf.getMenuBarClass().newInstance();
        } catch (Exception ex) {
            Log.e(ex);
            menuBar = new MenuBar();
        }
        menuBar.initMenuBar(this);
    }
    tintColor = laf.getDefaultFormTintColor();
    tactileTouchDuration = laf.getTactileTouchDuration();
}
Also used : LookAndFeel(com.codename1.ui.plaf.LookAndFeel)

Example 23 with UIManager

use of com.codename1.ui.plaf.UIManager in project CodenameOne by codenameone.

the class Label method initComponentImpl.

/**
 * {@inheritDoc}
 */
void initComponentImpl() {
    super.initComponentImpl();
    UIManager manager = getUIManager();
    LookAndFeel lf = manager.getLookAndFeel();
    if (hasFocus()) {
        if (lf instanceof DefaultLookAndFeel) {
            ((DefaultLookAndFeel) lf).focusGained(this);
        }
    }
    // into the container
    if (isTickerEnabled() && isTickerRunning() && !isCellRenderer()) {
        getComponentForm().registerAnimatedInternal(this);
    }
    checkAnimation();
    if (maskName != null && mask == null) {
        setMask(UIManager.getInstance().getThemeMaskConstant(maskName));
    }
    if (getIcon() != null) {
        getIcon().lock();
    }
}
Also used : DefaultLookAndFeel(com.codename1.ui.plaf.DefaultLookAndFeel) UIManager(com.codename1.ui.plaf.UIManager) LookAndFeel(com.codename1.ui.plaf.LookAndFeel) DefaultLookAndFeel(com.codename1.ui.plaf.DefaultLookAndFeel)

Example 24 with UIManager

use of com.codename1.ui.plaf.UIManager in project CodenameOne by codenameone.

the class SideMenuBar method installMenuBar.

/**
 * {@inheritDoc}
 */
protected void installMenuBar() {
    if (parent.getClientProperty("Menu") != null) {
        return;
    }
    super.installMenuBar();
    if (parent instanceof Dialog) {
        return;
    }
    openButton = createOpenButton();
    openButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            openMenu(null);
        }
    });
    addOpenButton(null, true);
    UIManager uim = parent.getUIManager();
    final boolean[] hasSideMenus = new boolean[2];
    if (uim.isThemeConstant("sideMenuFoldedSwipeBool", true) && parent.getClientProperty("sideMenuFoldedSwipeListeners") == null) {
        pointerDragged = new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                if (sideSwipePotential && hasSideMenus[0]) {
                    final int x = evt.getX();
                    final int y = evt.getY();
                    if (Math.abs(y - initialDragY) > x - initialDragX) {
                        sideSwipePotential = false;
                        return;
                    }
                    evt.consume();
                    if (x - initialDragX > Display.getInstance().getDisplayWidth() / getUIManager().getThemeConstant("sideSwipeActivationInt", 15)) {
                        draggedX = x;
                        dragActivated = true;
                        parent.pointerReleased(-1, -1);
                        openMenu(null, 0, draggedX, false);
                        initialDragX = 0;
                        initialDragY = 0;
                    }
                    return;
                }
                if (rightSideSwipePotential && (hasSideMenus[1] || (hasSideMenus[0] && isRTL()))) {
                    final int x = evt.getX();
                    final int y = evt.getY();
                    if (x < 0 || Math.abs(y - initialDragY) > initialDragX - x) {
                        rightSideSwipePotential = false;
                        return;
                    }
                    evt.consume();
                    if (initialDragX - x > Display.getInstance().getDisplayWidth() / getUIManager().getThemeConstant("sideSwipeActivationInt", 15)) {
                        draggedX = x;
                        dragActivated = true;
                        parent.pointerReleased(-1, -1);
                        if (isRTL()) {
                            openMenu(null, 0, draggedX, false);
                        } else {
                            openMenu(COMMAND_PLACEMENT_VALUE_RIGHT, 0, draggedX, false);
                        }
                        initialDragX = 0;
                        initialDragY = 0;
                    }
                }
                if (topSwipePotential) {
                    final int x = evt.getX();
                    final int y = evt.getY();
                    if (Math.abs(y - initialDragY) < x - initialDragX) {
                        topSwipePotential = false;
                        return;
                    }
                    evt.consume();
                    if (initialDragY - y > Display.getInstance().getDisplayHeight() / getUIManager().getThemeConstant("sideSwipeActivationInt", 15)) {
                        draggedX = y;
                        dragActivated = true;
                        parent.pointerReleased(-1, -1);
                        openMenu(COMMAND_PLACEMENT_VALUE_TOP, 0, draggedX, false);
                        initialDragX = 0;
                        initialDragY = 0;
                    }
                }
            }
        };
        parent.addPointerDraggedListener(pointerDragged);
        pointerPressed = new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                rightSideSwipePotential = false;
                topSwipePotential = false;
                sideSwipePotential = false;
                if (getCommandCount() == 0) {
                    return;
                }
                if (parent.getCommandCount() == 1) {
                    if (parent.getCommand(0) == parent.getBackCommand()) {
                        return;
                    }
                }
                for (int iter = 0; iter < getCommandCount(); iter++) {
                    Command c = getCommand(iter);
                    String p = (String) c.getClientProperty(COMMAND_PLACEMENT_KEY);
                    if (p == null) {
                        // has left menu
                        hasSideMenus[0] = true;
                    } else if (p.equals(COMMAND_PLACEMENT_VALUE_RIGHT)) {
                        // has right menu
                        hasSideMenus[1] = true;
                    }
                }
                int displayWidth = Display.getInstance().getDisplayWidth();
                if (rightSideButton != null || isRTL()) {
                    rightSideSwipePotential = !transitionRunning && evt.getX() > displayWidth - displayWidth / getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
                }
                if (getTitleComponent() instanceof Button) {
                    topSwipePotential = !transitionRunning && evt.getY() < Display.getInstance().getDisplayHeight() / getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
                }
                sideSwipePotential = !transitionRunning && evt.getX() < displayWidth / getUIManager().getThemeConstant("sideSwipeSensitiveInt", 10);
                initialDragX = evt.getX();
                initialDragY = evt.getY();
                if (sideSwipePotential || rightSideSwipePotential || topSwipePotential) {
                    Component c = Display.getInstance().getCurrent().getComponentAt(initialDragX, initialDragY);
                    if (c != null && c.shouldBlockSideSwipe()) {
                        sideSwipePotential = false;
                    }
                }
            }
        };
        parent.addPointerPressedListener(pointerPressed);
        parent.putClientProperty("sideMenuFoldedSwipeListeners", "true");
    }
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) UIManager(com.codename1.ui.plaf.UIManager)

Example 25 with UIManager

use of com.codename1.ui.plaf.UIManager in project CodenameOne by codenameone.

the class SideMenuBar method setMenuGlassPane.

private void setMenuGlassPane(Form m, final String placement) {
    boolean isRTLValue = m.isRTL();
    if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
        isRTLValue = !isRTLValue;
    }
    final boolean isRTL = isRTLValue;
    final Image image = rightPanel.getStyle().getBgImage();
    UIManager uim = rightPanel.getUIManager();
    Image sh = (Image) uim.getThemeImageConstant("sideMenuShadowImage");
    if (sh == null) {
        sh = Resources.getSystemResource().getImage("sidemenu-shadow.png");
    }
    if (isRTL) {
        sh = sh.flipHorizontally(true);
    }
    final Image shadow = sh;
    if (m.getGlassPane() == null) {
        m.setGlassPane(new Painter() {

            Image img = image;

            public void paint(Graphics g, Rectangle rect) {
                if (img == null) {
                    // will happen for areMutableImagesFast returning false on iOS and Windows Phone
                    Component c = (Component) rightPanel.getClientProperty("$parent");
                    // not sure what is happening here
                    if (c == null) {
                        return;
                    }
                    boolean b = c.isVisible();
                    c.setVisible(true);
                    if (isRTL) {
                        int x = Math.max(draggedX, rightPanel.getWidth()) - c.getWidth();
                        g.translate(x, 0);
                        Container.sidemenuBarTranslation = x;
                        if (shadow != null) {
                            g.tileImage(shadow, x + c.getWidth() - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
                        }
                        c.paintComponent(g, true);
                        Container.sidemenuBarTranslation = 0;
                        g.translate(-x, 0);
                    } else {
                        int x = Math.min(draggedX, rightPanel.getX());
                        g.translate(x, 0);
                        Container.sidemenuBarTranslation = x;
                        if (shadow != null) {
                            g.tileImage(shadow, x - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
                        }
                        c.paintComponent(g, true);
                        Container.sidemenuBarTranslation = 0;
                        g.translate(-x, 0);
                    }
                    c.setVisible(b);
                } else {
                    if (Display.getInstance().areMutableImagesFast()) {
                        if (img.getHeight() != Display.getInstance().getDisplayHeight()) {
                            img = updateRightPanelBgImage(placement, parent);
                        }
                    }
                    if (isRTL) {
                        int x = Math.max(draggedX, rightPanel.getWidth()) - img.getWidth();
                        if (shadow != null) {
                            g.tileImage(shadow, x + img.getWidth() - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
                        }
                        g.drawImage(img, x, 0);
                    } else {
                        int x = Math.min(draggedX, rightPanel.getX());
                        if (shadow != null) {
                            g.tileImage(shadow, x - shadow.getWidth(), 0, shadow.getWidth(), rightPanel.getHeight());
                        }
                        g.drawImage(img, x, 0);
                    }
                }
            }
        });
    }
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) UIManager(com.codename1.ui.plaf.UIManager)

Aggregations

UIManager (com.codename1.ui.plaf.UIManager)21 LookAndFeel (com.codename1.ui.plaf.LookAndFeel)9 Style (com.codename1.ui.plaf.Style)5 Image (com.codename1.ui.Image)4 BorderLayout (com.codename1.ui.layouts.BorderLayout)4 FontImage (com.codename1.ui.FontImage)3 ActionEvent (com.codename1.ui.events.ActionEvent)2 ActionListener (com.codename1.ui.events.ActionListener)2 Dimension (com.codename1.ui.geom.Dimension)2 GridLayout (com.codename1.ui.layouts.GridLayout)2 Border (com.codename1.ui.plaf.Border)2 Component (com.codename1.ui.Component)1 Form (com.codename1.ui.Form)1 Label (com.codename1.ui.Label)1 BubbleTransition (com.codename1.ui.animations.BubbleTransition)1 Transition (com.codename1.ui.animations.Transition)1 Rectangle (com.codename1.ui.geom.Rectangle)1 FlowLayout (com.codename1.ui.layouts.FlowLayout)1 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)1 DefaultLookAndFeel (com.codename1.ui.plaf.DefaultLookAndFeel)1