Java Code Examples for com.codename1.ui.events.ActionEvent#isConsumed()

The following examples show how to use com.codename1.ui.events.ActionEvent#isConsumed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Form.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Invoked to allow subclasses of form to handle a command from one point
 * rather than implementing many command instances
 */
void actionCommandImplNoRecurseComponent(Command cmd, ActionEvent ev) {
    if (cmd == null) {
        return;
    }

    if (comboLock) {
        if (cmd == menuBar.getCancelMenuItem()) {
            actionCommand(cmd);
            return;
        }
        return;
    }
    if (cmd != menuBar.getSelectCommand()) {
        if (commandListener != null) {
            commandListener.fireActionEvent(ev);
            if (ev.isConsumed()) {
                return;
            }
        }
        actionCommand(cmd);
    } 
}
 
Example 2
Source File: Form.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void longPointerPress(int x, int y) {
    if (longPressListeners != null && longPressListeners.hasListeners()) {
        ActionEvent ev = new ActionEvent(this, ActionEvent.Type.LongPointerPress, x, y);
        longPressListeners.fireActionEvent(ev);
        if(ev.isConsumed()) {
            return;
        }
    }
    if (focused != null && focused.contains(x, y)) {
        if (focused.getComponentForm() == this) {
            LeadUtil.longPointerPress(focused, x, y);
            
        }
    }
}
 
Example 3
Source File: Form.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
private boolean fireReleaseListeners(int x, int y) {
    if (pointerReleasedListeners != null && pointerReleasedListeners.hasListeners()) {
        ActionEvent ev = new ActionEvent(this, ActionEvent.Type.PointerReleased, x, y);
        pointerReleasedListeners.fireActionEvent(ev);
        if(ev.isConsumed()) {
            if (dragged != null) {
                if (dragged.isDragAndDropInitialized()) {
                    LeadUtil.dragFinished(dragged, x, y);

                }
                dragged = null;
            }
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: Button.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Allows subclasses to override action event behavior 
 * {@inheritDoc}
 * 
 * @param x the x position of the click if applicable (can be 0 or -1 otherwise)
 * @param y the y position of the click if applicable (can be 0 or -1 otherwise)
 */
protected void fireActionEvent(int x, int y){
    super.fireActionEvent();
    if(cmd != null) {
        ActionEvent ev = new ActionEvent(cmd, this, x, y);
        dispatcher.fireActionEvent(ev);
        if(!ev.isConsumed()) {
            Form f = getComponentForm();
            if(f != null) {
                f.actionCommandImplNoRecurseComponent(cmd, ev);
            }
        }
    } else {
        dispatcher.fireActionEvent(new ActionEvent(this, ActionEvent.Type.PointerPressed,x, y));
    }
    Display d = Display.getInstance();
    if(d.isBuiltinSoundsEnabled()) {
        d.playBuiltinSound(Display.SOUND_TYPE_BUTTON_PRESS);
    }
}
 
Example 5
Source File: Button.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void pointerReleased(int x, int y) {
    if (pointerReleasedListeners != null && pointerReleasedListeners.hasListeners()) {
        ActionEvent ev = new ActionEvent(this, ActionEvent.Type.PointerReleased, x, y);
        pointerReleasedListeners.fireActionEvent(ev);
        if(ev.isConsumed()) {
            return;
        }
    }
    Form f = getComponentForm();
    // might happen when programmatically triggering press
    if(f != null) {
        f.removeComponentAwaitingRelease(this);
    }

    // button shouldn't fire an event when a pointer is dragged into it
    if(state == STATE_PRESSED) {
        released(x, y);
     }
    if(restoreDragPercentage > -1) {
        Display.getInstance().setDragStartPercentage(restoreDragPercentage);
    }
}
 
Example 6
Source File: List.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Triggers the event to the listeners
 * @param evt the event to fire
 */ 
protected void fireActionEvent(ActionEvent a) {
    if(isEnabled() && !Display.getInstance().hasDragOccured()){
        if(disposeDialogOnSelection) {
            ((Dialog)getComponentForm()).dispose();
        }
        super.fireActionEvent();
        dispatcher.fireActionEvent(a);
        if(isCommandList() && !a.isConsumed()) {
            T i = getSelectedItem();
            if(i != null && i instanceof Command && ((Command)i).isEnabled()) {
                ((Command)i).actionPerformed(a);
                if(!a.isConsumed()) {
                    Form f = getComponentForm();
                    if(f != null) {
                        f.actionCommandImpl((Command)i);
                    }
                }
            }
        }
        Display d = Display.getInstance();
        if(d.isBuiltinSoundsEnabled()) {
            d.playBuiltinSound(Display.SOUND_TYPE_BUTTON_PRESS);
        }
    }
}
 
Example 7
Source File: UIBuilder.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
private void processCommandImpl(ActionEvent ev, Command cmd) {
    processCommand(ev, cmd);
    if(ev.isConsumed()) {
        return;
    }
    if(globalCommandListeners != null) {
        globalCommandListeners.fireActionEvent(ev);
        if(ev.isConsumed()) {
            return;
        }
    }

    if(localCommandListeners != null) {
        Form f = Display.getInstance().getCurrent();
        EventDispatcher e = (EventDispatcher)localCommandListeners.get(f.getName());
        if(e != null) {
            e.fireActionEvent(ev);
        }
    }
}
 
Example 8
Source File: Form.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Dispatches a command via the standard form mechanism of firing a command event
 * 
 * @param cmd The command to dispatch
 * @param ev the event to dispatch 
 */
public void dispatchCommand(Command cmd, ActionEvent ev) {
    cmd.actionPerformed(ev);
    if (!ev.isConsumed()) {
        actionCommandImpl(cmd, ev);
    }
}
 
Example 9
Source File: Form.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void fireKeyEvent(HashMap<Integer, ArrayList<ActionListener>> keyListeners, int keyCode) {
    if (keyListeners != null) {
        ArrayList<ActionListener> listeners = keyListeners.get(new Integer(keyCode));
        if (listeners != null) {
            ActionEvent evt = new ActionEvent(this, keyCode);
            for (int iter = 0; iter < listeners.size(); iter++) {
                listeners.get(iter).actionPerformed(evt);
                if (evt.isConsumed()) {
                    return;
                }
            }
        }
    }
}
 
Example 10
Source File: NetworkManager.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
boolean handleErrorCode(ConnectionRequest r, int code, String message) {
    if(errorListeners != null) {
        ActionEvent ev = new NetworkEvent(r, code, message);
        errorListeners.fireActionEvent(ev);
        return ev.isConsumed();
    }
    return false;
}
 
Example 11
Source File: NetworkManager.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private boolean handleException(ConnectionRequest r, Exception o) {
    if(errorListeners != null) {
        ActionEvent ev = new NetworkEvent(r, o);
        errorListeners.fireActionEvent(ev);
        return ev.isConsumed();
    }
    return false;
}
 
Example 12
Source File: MenuBar.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void keyReleased(int keyCode) {
    int commandBehavior = getCommandBehavior();
    if (commandBehavior >= Display.COMMAND_BEHAVIOR_BUTTON_BAR && keyCode != backSK && keyCode != clearSK && keyCode != backspaceSK) {
        return;
    }
    if (getCommandCount() > 0) {
        int softkeyCount = Display.getInstance().getImplementation().getSoftkeyCount();
        if (softkeyCount < 2 && isLSK(keyCode)) {
            if (commandList != null) {
                Container parent = commandList.getParent();
                while (parent != null) {
                    if (parent instanceof Dialog && ((Dialog) parent).isMenu()) {
                        return;
                    }
                    parent = parent.getParent();
                }
            }
            showMenu();
            return;
        } else {
            if (isLSK(keyCode)) {
                if (left != null) {
                    left.released();
                }
                return;
            } else {
                // it might be a back command...
                if (isRSK(keyCode)) {
                    if (right != null) {
                        right.released();
                    }
                    return;
                } else {
                    if (Display.getInstance().getGameAction(keyCode) == Display.GAME_FIRE) {
                        main.released();
                        return;
                    }
                }
            }
        }
    }

    // allows a back/clear command to occur regardless of whether the
    // command was added to the form
    Command c = null;
    if (keyCode == backSK) {
        // the back command should be invoked
        c = parent.getBackCommand();
        if(c == null && minimizeOnBack) {
            Display.getInstance().minimizeApplication();
            return;
        }
    } else {
        if (keyCode == clearSK || keyCode == backspaceSK) {
            c = getClearCommand();
        }
    }
    if (c != null) {
        ActionEvent ev = new ActionEvent(c, keyCode);
        c.actionPerformed(ev);
        if (!ev.isConsumed()) {
            parent.actionCommandImpl(c);
        }
    }
}