Search in sources :

Example 76 with ActionListener

use of com.codename1.ui.events.ActionListener 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 77 with ActionListener

use of com.codename1.ui.events.ActionListener 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 78 with ActionListener

use of com.codename1.ui.events.ActionListener 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 79 with ActionListener

use of com.codename1.ui.events.ActionListener in project CodenameOne by codenameone.

the class SideMenuBar method closeCurrentMenu.

/**
 * Folds the current side menu if it is open, when the menu is closed it
 * will invoke the runnable callback method
 *
 * @param callback will be invoked when the menu is actually closed
 */
public static void closeCurrentMenu(final Runnable callback) {
    if (Toolbar.isOnTopSideMenu() && (Toolbar.isGlobalToolbar() || Display.getInstance().getCommandBehavior() != Display.COMMAND_BEHAVIOR_SIDE_NAVIGATION)) {
        Display.getInstance().getCurrent().getToolbar().closeSideMenu();
        callback.run();
        return;
    }
    Form f = Display.getInstance().getCurrent();
    final SideMenuBar b = (SideMenuBar) f.getClientProperty("cn1$sideMenuParent");
    if (b != null && !b.transitionRunning) {
        b.parent.addShowListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                b.parent.removeShowListener(this);
                callback.run();
            }
        });
        b.closeMenu();
    } else {
        callback.run();
    }
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 80 with ActionListener

use of com.codename1.ui.events.ActionListener 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

ActionEvent (com.codename1.ui.events.ActionEvent)61 ActionListener (com.codename1.ui.events.ActionListener)61 IOException (java.io.IOException)25 BorderLayout (com.codename1.ui.layouts.BorderLayout)20 EventDispatcher (com.codename1.ui.util.EventDispatcher)16 Hashtable (java.util.Hashtable)14 NetworkEvent (com.codename1.io.NetworkEvent)13 Form (com.codename1.ui.Form)13 Vector (java.util.Vector)11 Container (com.codename1.ui.Container)10 Button (com.codename1.ui.Button)8 ActionEvent (java.awt.event.ActionEvent)8 ActionListener (java.awt.event.ActionListener)8 Dialog (com.codename1.ui.Dialog)7 EncodedImage (com.codename1.ui.EncodedImage)6 Image (com.codename1.ui.Image)6 Label (com.codename1.ui.Label)6 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)6 MediaException (javax.microedition.media.MediaException)6 RecordStoreException (javax.microedition.rms.RecordStoreException)6