Search in sources :

Example 96 with ActionEvent

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

the class Component method pointerReleased.

/**
 * If this Component is focused, the pointer released event
 * will call this method
 *
 * @param x the pointer x coordinate
 * @param y the pointer y coordinate
 */
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;
        }
    }
    pointerReleaseImpl(x, y);
    scrollOpacity = 0xff;
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

Example 97 with ActionEvent

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

the class Component method pointerPressed.

/**
 * If this Component is focused, the pointer pressed event
 * will call this method
 *
 * @param x the pointer x coordinate
 * @param y the pointer y coordinate
 */
public void pointerPressed(int x, int y) {
    dragActivated = false;
    if (pointerPressedListeners != null && pointerPressedListeners.hasListeners()) {
        pointerPressedListeners.fireActionEvent(new ActionEvent(this, ActionEvent.Type.PointerPressed, x, y));
    }
    clearDrag();
    if (isDragAndDropOperation(x, y)) {
        int restore = Display.getInstance().getDragStartPercentage();
        if (restore > 1) {
            restoreDragPercentage = restore;
        }
        Display.getInstance().setDragStartPercentage(1);
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) Point(com.codename1.ui.geom.Point)

Example 98 with ActionEvent

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

the class Component method dragFinishedImpl.

void dragFinishedImpl(int x, int y) {
    if (dragAndDropInitialized && dragActivated) {
        Form p = getComponentForm();
        if (p == null) {
            // The component was removed from the form during the drag
            dragActivated = false;
            dragAndDropInitialized = false;
            setVisible(true);
            dragImage = null;
            dropTargetComponent = null;
            return;
        }
        p.setDraggedComponent(null);
        Component dropTo = findDropTarget(this, x, y);
        if (dropTargetComponent != dropTo) {
            if (dropTargetComponent != null) {
                dropTargetComponent.dragExit(this);
            }
            dropTargetComponent = dropTo;
            if (dropTargetComponent != null) {
                dropTargetComponent.dragEnter(this);
            }
        }
        if (dropTargetComponent != null) {
            p.repaint(x, y, getWidth(), getHeight());
            getParent().scrollRectToVisible(getX(), getY(), getWidth(), getHeight(), getParent());
            if (dropListener != null) {
                ActionEvent ev = new ActionEvent(this, ActionEvent.Type.PointerDrag, dropTargetComponent, x, y);
                dropListener.fireActionEvent(ev);
                if (!ev.isConsumed()) {
                    dropTargetComponent.drop(this, x, y);
                }
            } else {
                dropTargetComponent.drop(this, x, y);
            }
        } else {
            if (dragOverListener != null) {
                ActionEvent ev = new ActionEvent(this, ActionEvent.Type.PointerDrag, null, x, y);
                dragOverListener.fireActionEvent(ev);
            }
            p.repaint();
        }
        setVisible(true);
        dragImage = null;
        dropTargetComponent = null;
    }
    if (getUIManager().getLookAndFeel().isFadeScrollBar() && isScrollable()) {
        Form frm = getComponentForm();
        if (frm != null) {
            frm.registerAnimatedInternal(this);
        }
    }
    dragActivated = false;
    dragAndDropInitialized = false;
    if (dragFinishedListeners != null && dragFinishedListeners.hasListeners()) {
        ActionEvent ev = new ActionEvent(this, ActionEvent.Type.DragFinished, x, y);
        dragFinishedListeners.fireActionEvent(ev);
        if (ev.isConsumed()) {
            return;
        }
    }
    dragFinished(x, y);
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

Example 99 with ActionEvent

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

the class AutoCompleteTextField method addPopup.

private void addPopup() {
    final Form f = getComponentForm();
    popup.removeAll();
    popup.setVisible(false);
    popup.setEnabled(false);
    filter(getText());
    final com.codename1.ui.List l = new com.codename1.ui.List(getSuggestionModel());
    if (getMinimumElementsShownInPopup() > 0) {
        l.setMinElementHeight(getMinimumElementsShownInPopup());
    }
    l.setScrollToSelected(false);
    l.setItemGap(0);
    for (ActionListener al : listeners) {
        l.addActionListener(al);
    }
    if (completionRenderer == null) {
        ((DefaultListCellRenderer<String>) l.getRenderer()).setShowNumbers(false);
    } else {
        l.setRenderer(completionRenderer);
    }
    l.setUIID("AutoCompleteList");
    l.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            pickedText = (String) l.getSelectedItem();
            setParentText(pickedText);
            fireActionEvent();
            // relaunch text editing if we are still editing
            if (Display.getInstance().isTextEditing(AutoCompleteTextField.this)) {
                Display.getInstance().editString(AutoCompleteTextField.this, getMaxSize(), getConstraint(), (String) l.getSelectedItem());
            }
            popup.setVisible(false);
            popup.setEnabled(false);
            f.repaint();
        }
    });
    byte[] units = popup.getStyle().getMarginUnit();
    if (units != null) {
        units[Component.LEFT] = Style.UNIT_TYPE_PIXELS;
        units[Component.TOP] = Style.UNIT_TYPE_PIXELS;
        popup.getAllStyles().setMarginUnit(units);
    }
    popup.getAllStyles().setMargin(LEFT, Math.max(0, getAbsoluteX()));
    int popupHeight = calcPopuupHeight(l);
    popup.setPreferredW(getWidth());
    popup.setHeight(popupHeight);
    popup.setWidth(getWidth());
    popup.addComponent(l);
    popup.layoutContainer();
    // block the reflow of this popup, which can cause painting problems
    dontCalcSize = true;
    if (f != null) {
        if (popup.getParent() == null) {
            Container lay = f.getLayeredPane(AutoCompleteTextField.this.getClass(), true);
            lay.setLayout(new LayeredLayout());
            Container wrapper = new Container();
            wrapper.add(popup);
            lay.addComponent(wrapper);
        }
        f.revalidate();
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) ActionListener(com.codename1.ui.events.ActionListener) ArrayList(java.util.ArrayList) LayeredLayout(com.codename1.ui.layouts.LayeredLayout)

Example 100 with ActionEvent

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

the class Button method pointerReleased.

/**
 * {@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) {
        if (f.buttonsAwatingRelease != null) {
            f.buttonsAwatingRelease.remove(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);
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

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