Search in sources :

Example 86 with ActionEvent

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

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

Example 88 with ActionEvent

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

the class SwipeableContainer method animate.

@Override
public boolean animate() {
    if (openCloseMotion != null) {
        int val = openCloseMotion.getValue();
        if (openedToRight) {
            topWrapper.setX(val);
        } else {
            topWrapper.setX(-val);
        }
        repaint();
        boolean finished = openCloseMotion.isFinished();
        if (finished) {
            // getComponentForm().deregisterAnimated(this);
            openCloseMotion = null;
            if (!open) {
                bottomRightWrapper.setVisible(false);
                bottomLeftWrapper.setVisible(false);
                openedToLeft = false;
                openedToRight = false;
            } else {
                dispatcher.fireActionEvent(new ActionEvent(this, ActionEvent.Type.Swipe));
            }
        }
        return !finished;
    }
    return false;
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

Example 89 with ActionEvent

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

the class TextArea method fireActionEvent.

/**
 * Notifies listeners of a change to the text area
 */
void fireActionEvent() {
    if (actionListeners != null) {
        ActionEvent evt = new ActionEvent(this, ActionEvent.Type.Edit);
        actionListeners.fireActionEvent(evt);
    }
    if (bindListeners != null) {
        String t = getText();
        bindListeners.fireBindTargetChange(this, "text", lastTextValue, t);
        lastTextValue = t;
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

Example 90 with ActionEvent

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

the class HTMLImageMap method actionPerformed.

public void actionPerformed(ActionEvent evt) {
    if (mapData != null) {
        int x = evt.getX();
        int y = evt.getY();
        if ((mapData.areas != null) && (x != -1)) {
            for (Enumeration e = mapData.areas.keys(); e.hasMoreElements(); ) {
                Rectangle rect = (Rectangle) e.nextElement();
                if (rect.contains(x - getAbsoluteX(), y - getAbsoluteY())) {
                    String link = (String) mapData.areas.get(rect);
                    if (link != null) {
                        HTMLLink.processLink(htmlC, link);
                    }
                    return;
                }
            }
        }
        if (mapData.defaultLink != null) {
            HTMLLink.processLink(htmlC, mapData.defaultLink);
        }
    }
}
Also used : Enumeration(java.util.Enumeration) Rectangle(com.codename1.ui.geom.Rectangle)

Aggregations

ActionEvent (com.codename1.ui.events.ActionEvent)98 ActionListener (com.codename1.ui.events.ActionListener)55 IOException (java.io.IOException)30 BorderLayout (com.codename1.ui.layouts.BorderLayout)28 Form (com.codename1.ui.Form)18 Hashtable (java.util.Hashtable)14 Vector (java.util.Vector)11 NetworkEvent (com.codename1.io.NetworkEvent)10 Container (com.codename1.ui.Container)9 ActionEvent (java.awt.event.ActionEvent)9 Command (com.codename1.ui.Command)8 ActionListener (java.awt.event.ActionListener)8 Button (com.codename1.ui.Button)7 Style (com.codename1.ui.plaf.Style)7 Rectangle (com.codename1.ui.geom.Rectangle)6 File (java.io.File)6 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)6 MediaException (javax.microedition.media.MediaException)6 RecordStoreException (javax.microedition.rms.RecordStoreException)6 BufferedOutputStream (com.codename1.io.BufferedOutputStream)5