Search in sources :

Example 81 with ActionEvent

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

the class Form method keyReleased.

/**
 * {@inheritDoc}
 */
public void keyReleased(int keyCode) {
    int game = Display.getInstance().getGameAction(keyCode);
    if (menuBar.handlesKeycode(keyCode)) {
        menuBar.keyReleased(keyCode);
        return;
    }
    // Component focused = focusManager.getFocused();
    if (focused != null) {
        if (focused.getComponentForm() == this) {
            if (focused.isEnabled()) {
                focused.keyReleased(keyCode);
            }
        }
    }
    // prevent the default action from stealing the behavior from the popup/combo box...
    if (game == Display.GAME_FIRE) {
        Command defaultCmd = getDefaultCommand();
        if (defaultCmd != null) {
            defaultCmd.actionPerformed(new ActionEvent(defaultCmd, keyCode));
            actionCommandImpl(defaultCmd);
        }
    }
    fireKeyEvent(keyListeners, keyCode);
    fireKeyEvent(gameKeyListeners, game);
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

Example 82 with ActionEvent

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

the class Form method sizeChangedInternal.

/**
 * This method is only invoked when the underlying canvas for the form gets
 * a size changed event.
 * This method will trigger a relayout of the Form.
 * This method will get the callback only if this Form is the Current Form
 * @param w the new width of the Form
 * @param h the new height of the Form
 */
void sizeChangedInternal(int w, int h) {
    int oldWidth = getWidth();
    int oldHeight = getHeight();
    sizeChanged(w, h);
    Style formStyle = getStyle();
    w = w - (formStyle.getHorizontalMargins());
    h = h - (formStyle.getVerticalMargins());
    setSize(new Dimension(w, h));
    setShouldCalcPreferredSize(true);
    doLayout();
    focused = getFocused();
    if (focused != null) {
        Component.setDisableSmoothScrolling(true);
        scrollComponentToVisible(focused);
        Component.setDisableSmoothScrolling(false);
    }
    if (oldWidth != w && oldHeight != h) {
        if (orientationListener != null) {
            orientationListener.fireActionEvent(new ActionEvent(this, ActionEvent.Type.OrientationChange));
        }
    }
    if (sizeChangedListener != null) {
        sizeChangedListener.fireActionEvent(new ActionEvent(this, ActionEvent.Type.SizeChange, w, h));
    }
    repaint();
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Example 83 with ActionEvent

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

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

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

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