Search in sources :

Example 66 with Button

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

the class Form method createStatusBar.

/**
 * Subclasses can override this method to control the creation of the status bar component.
 * Notice that this method will only be invoked if the paintsTitleBarBool theme constant is true
 * which it is on iOS by default
 * @return a Component that represents the status bar if the OS requires status bar spacing
 */
protected Component createStatusBar() {
    if (getUIManager().isThemeConstant("statusBarScrollsUpBool", true)) {
        Button bar = new Button();
        bar.setShowEvenIfBlank(true);
        bar.setUIID("StatusBar");
        bar.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                Component c = findScrollableChild(getContentPane());
                if (c != null) {
                    c.scrollRectToVisible(new Rectangle(0, 0, 10, 10), c);
                }
            }
        });
        return bar;
    } else {
        Container bar = new Container();
        bar.setUIID("StatusBar");
        return bar;
    }
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) Rectangle(com.codename1.ui.geom.Rectangle)

Example 67 with Button

use of com.codename1.ui.Button 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 68 with Button

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

the class SideMenuBar method validateCommandPlacement.

private void validateCommandPlacement(String placement) {
    if (placement == COMMAND_PLACEMENT_VALUE_TOP) {
        ((BorderLayout) getTitleAreaContainer().getLayout()).setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_SCALE);
        if (!(getTitleComponent() instanceof Button)) {
            Button b = new Button(parent.getTitle());
            b.setUIID("Title");
            parent.setTitleComponent(b);
            b.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent evt) {
                    openMenu(COMMAND_PLACEMENT_VALUE_TOP);
                }
            });
        }
        return;
    }
    if (placement == COMMAND_PLACEMENT_VALUE_RIGHT) {
        if (rightSideButton != null && rightSideButton.getParent() != null) {
            return;
        }
        rightSideButton = new Button();
        rightSideButton.setUIID("MenuButtonRight");
        UIManager uim = parent.getUIManager();
        Image i = (Image) uim.getThemeImageConstant("rightSideMenuImage");
        if (i != null) {
            rightSideButton.setIcon(i);
        } else {
            FontImage.setMaterialIcon(rightSideButton, FontImage.MATERIAL_MENU);
        }
        Image p = (Image) uim.getThemeImageConstant("rightSideMenuPressImage");
        if (p != null) {
            rightSideButton.setPressedIcon(p);
        }
        rightSideButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                openMenu(COMMAND_PLACEMENT_VALUE_RIGHT);
            }
        });
        Container ta = getTitleAreaContainer();
        ta.addComponent(BorderLayout.EAST, rightSideButton);
        ta.revalidate();
        return;
    }
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) UIManager(com.codename1.ui.plaf.UIManager)

Example 69 with Button

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

the class SideMenuBar method createOpenButton.

/**
 * Creates the Side Menu open button.
 * @return a Button instance to place on the TitleArea
 */
protected Button createOpenButton() {
    Button ob = new Button();
    ob.setUIID("MenuButton");
    UIManager uim = parent.getUIManager();
    Image i = (Image) uim.getThemeImageConstant("sideMenuImage");
    if (i != null) {
        ob.setIcon(i);
    } else {
        float size = 4.5f;
        try {
            size = Float.parseFloat(uim.getThemeConstant("menuImageSize", "4.5"));
        } catch (Throwable t) {
            Log.e(t);
        }
        FontImage.setMaterialIcon(ob, FontImage.MATERIAL_MENU, size);
    }
    Image p = (Image) uim.getThemeImageConstant("sideMenuPressImage");
    if (p != null) {
        ob.setPressedIcon(p);
    }
    return ob;
}
Also used : UIManager(com.codename1.ui.plaf.UIManager)

Example 70 with Button

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

the class Tabs method insertTab.

/**
 * Inserts a <code>component</code>, at <code>index</code>,
 * represented by a <code>button</code>
 * Uses java.util.Vector internally, see <code>insertElementAt</code>
 * for details of insertion conventions.
 * The Button styling will be associated with "Tab" UIID.
 *
 * @param tab represents the tab on top
 * @param component The component to be displayed when this tab is clicked.
 * @param index the position to insert this new tab
 *
 * @see #addTab
 * @see #removeTabAt
 * @deprecated should use radio button as an argument
 */
public void insertTab(Component tab, Component component, int index) {
    checkIndex(index);
    if (component == null) {
        return;
    }
    final Component b = tab;
    if (tabUIID != null) {
        b.setUIID(tabUIID);
    }
    b.addFocusListener(focusListener);
    bindTabActionListener(b, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (selectedTab != null) {
                if (tabUIID != null) {
                    selectedTab.setUIID(tabUIID);
                }
                if (!animateTabSelection) {
                    selectedTab.setShouldCalcPreferredSize(true);
                    selectedTab.repaint();
                }
                int previousSelectedIndex = tabsContainer.getComponentIndex(selectedTab);
                // this might happen if a tab was removed
                if (previousSelectedIndex != -1) {
                    Component previousContent = contentPane.getComponentAt(previousSelectedIndex);
                    if (previousContent instanceof Container) {
                        ((Container) previousContent).setBlockFocus(true);
                    }
                }
            }
            active = tabsContainer.getComponentIndex(b);
            Component content = contentPane.getComponentAt(active);
            if (content instanceof Container) {
                ((Container) content).setBlockFocus(false);
            }
            setSelectedIndex(active, animateTabSelection);
            initTabsFocus();
            selectedTab = b;
            if (!animateTabSelection) {
                selectedTab.setShouldCalcPreferredSize(true);
                tabsContainer.revalidate();
            }
            tabsContainer.scrollComponentToVisible(selectedTab);
        }
    });
    if (component instanceof Container) {
        ((Container) component).setBlockFocus(true);
    }
    tabsContainer.addComponent(index, b);
    contentPane.addComponent(index, component);
    setTabsLayout(tabPlacement);
    if (tabsContainer.getComponentCount() == 1) {
        selectedTab = tabsContainer.getComponentAt(0);
        if (component instanceof Container) {
            ((Container) component).setBlockFocus(false);
        }
        initTabsFocus();
    }
    checkTabsCanBeSeen();
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent)

Aggregations

Button (com.codename1.ui.Button)31 BorderLayout (com.codename1.ui.layouts.BorderLayout)25 ActionEvent (com.codename1.ui.events.ActionEvent)21 Container (com.codename1.ui.Container)18 ActionListener (com.codename1.ui.events.ActionListener)17 Component (com.codename1.ui.Component)14 RadioButton (com.codename1.ui.RadioButton)14 Form (com.codename1.ui.Form)12 Label (com.codename1.ui.Label)11 BoxLayout (com.codename1.ui.layouts.BoxLayout)11 TextArea (com.codename1.ui.TextArea)10 Hashtable (java.util.Hashtable)9 Command (com.codename1.ui.Command)8 Image (com.codename1.ui.Image)8 TextField (com.codename1.ui.TextField)8 FlowLayout (com.codename1.ui.layouts.FlowLayout)8 GridLayout (com.codename1.ui.layouts.GridLayout)8 UIManager (com.codename1.ui.plaf.UIManager)8 CheckBox (com.codename1.ui.CheckBox)7 Style (com.codename1.ui.plaf.Style)7