Search in sources :

Example 71 with ActionEvent

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

the class NetworkManager method handleException.

private boolean handleException(ConnectionRequest r, Exception o) {
    if (errorListeners != null) {
        ActionEvent ev = new NetworkEvent(r, o);
        errorListeners.fireActionEvent(ev);
        return ev.isConsumed();
    }
    return false;
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

Example 72 with ActionEvent

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

the class Oauth2 method handleURL.

private void handleURL(String url, WebBrowser web, final ActionListener al, final Form frm, final Form backToForm, final Dialog progress) {
    if ((url.startsWith(redirectURI))) {
        if (Display.getInstance().getCurrent() == progress) {
            progress.dispose();
        }
        web.stop();
        // remove the browser component.
        if (login != null) {
            login.removeAll();
            login.revalidate();
        }
        if (url.indexOf("code=") > -1) {
            Hashtable params = getParamsFromURL(url);
            ConnectionRequest req = new ConnectionRequest() {

                protected void readResponse(InputStream input) throws IOException {
                    byte[] tok = Util.readInputStream(input);
                    String t = new String(tok);
                    if (t.startsWith("{")) {
                        JSONParser p = new JSONParser();
                        Map map = p.parseJSON(new StringReader(t));
                        token = (String) map.get("access_token");
                        Object ex = map.get("expires_in");
                        if (ex == null) {
                            ex = map.get("expires");
                        }
                        if (ex != null) {
                            expires = ex.toString();
                        }
                    } else {
                        token = t.substring(t.indexOf("=") + 1, t.indexOf("&"));
                        int off = t.indexOf("expires=");
                        int start = 8;
                        if (off == -1) {
                            off = t.indexOf("expires_in=");
                            start = 11;
                        }
                        if (off > -1) {
                            int end = t.indexOf('&', off);
                            if (end < 0 || end < off) {
                                end = t.length();
                            }
                            expires = t.substring(off + start, end);
                        }
                    }
                    if (login != null) {
                        login.dispose();
                    }
                }

                protected void handleException(Exception err) {
                    if (backToForm != null) {
                        backToForm.showBack();
                    }
                    if (al != null) {
                        al.actionPerformed(new ActionEvent(err, ActionEvent.Type.Exception));
                    }
                }

                protected void postResponse() {
                    if (backToParent && backToForm != null) {
                        backToForm.showBack();
                    }
                    if (al != null) {
                        al.actionPerformed(new ActionEvent(new AccessToken(token, expires), ActionEvent.Type.Response));
                    }
                }
            };
            req.setUrl(tokenRequestURL);
            req.setPost(true);
            req.addRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            req.addArgument("client_id", clientId);
            req.addArgument("redirect_uri", redirectURI);
            req.addArgument("client_secret", clientSecret);
            req.addArgument("code", (String) params.get("code"));
            req.addArgument("grant_type", "authorization_code");
            NetworkManager.getInstance().addToQueue(req);
        } else if (url.indexOf("error_reason=") > -1) {
            Hashtable table = getParamsFromURL(url);
            String error = (String) table.get("error_reason");
            if (login != null) {
                login.dispose();
            }
            if (backToForm != null) {
                backToForm.showBack();
            }
            if (al != null) {
                al.actionPerformed(new ActionEvent(new IOException(error), ActionEvent.Type.Exception));
            }
        } else {
            boolean success = url.indexOf("#") > -1;
            if (success) {
                String accessToken = url.substring(url.indexOf("#") + 1);
                if (accessToken.indexOf("&") > 0) {
                    token = accessToken.substring(accessToken.indexOf("=") + 1, accessToken.indexOf("&"));
                } else {
                    token = accessToken.substring(accessToken.indexOf("=") + 1);
                }
                if (login != null) {
                    login.dispose();
                }
                if (backToParent && backToForm != null) {
                    backToForm.showBack();
                }
                if (al != null) {
                    al.actionPerformed(new ActionEvent(new AccessToken(token, expires), ActionEvent.Type.Response));
                }
            }
        }
    } else {
        if (frm != null && Display.getInstance().getCurrent() != frm) {
            progress.dispose();
            frm.show();
        }
    }
}
Also used : Hashtable(java.util.Hashtable) InputStream(java.io.InputStream) ActionEvent(com.codename1.ui.events.ActionEvent) IOException(java.io.IOException) IOException(java.io.IOException) StringReader(com.codename1.util.regex.StringReader) Map(java.util.Map)

Example 73 with ActionEvent

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

the class LayerWithZoomLevels method getTiles.

private void getTiles() throws RuntimeException {
    _tiles = new Vector();
    Dimension tileSize = _map.tileSize();
    int posY = 0;
    _delta = null;
    while (posY - tileSize.getHeight() < getHeight()) {
        int posX = 0;
        while (posX - tileSize.getWidth() < getWidth()) {
            Tile tile;
            Coord cur = _map.translate(_center, _zoom, posX - getWidth() / 2, getHeight() / 2 - posY);
            if (_map.projection().extent().contains(cur)) {
                tile = _map.tileFor(_map.bboxFor(cur, _zoom));
                if (_delta == null) {
                    _delta = tile.pointPosition(cur);
                }
                tile.setsTileReadyListener(new ActionListener() {

                    public void actionPerformed(ActionEvent evt) {
                        refreshLayers = true;
                        repaint();
                    }
                });
                _tiles.addElement(new PositionedTile(new Point(posX, posY), tile));
            }
            posX += tileSize.getWidth();
        }
        posY += tileSize.getHeight();
    }
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) Dimension(com.codename1.ui.geom.Dimension) Point(com.codename1.ui.geom.Point) Vector(java.util.Vector) Point(com.codename1.ui.geom.Point)

Example 74 with ActionEvent

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

the class Dialog method onShowCompletedImpl.

void onShowCompletedImpl() {
    pressedOutOfBounds = false;
    disposedDueToRotation = false;
    onShowCompleted();
    if (isDisposed()) {
        disposeImpl();
    }
    if (showListener != null) {
        showListener.fireActionEvent(new ActionEvent(this, ActionEvent.Type.Show));
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent)

Example 75 with ActionEvent

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

the class List method pointerReleasedImpl.

private void pointerReleasedImpl(int x, int y, boolean isHover, boolean longPress) {
    if (!isEnabled()) {
        return;
    }
    if (isDragActivated()) {
        if (fixedSelection < FIXED_NONE_BOUNDRY) {
            super.pointerReleased(x, y);
        } else {
            boolean vertical = getOrientation() == VERTICAL;
            float speed = getDragSpeed(vertical);
            if (vertical) {
                fixedDraggedMotion = Motion.createFrictionMotion(-fixedDraggedAnimationPosition, Integer.MAX_VALUE, speed, 0.0007f);
            } else {
                fixedDraggedMotion = Motion.createFrictionMotion(-fixedDraggedAnimationPosition, Integer.MAX_VALUE, speed, 0.0007f);
            }
            fixedDraggedPosition = fixedDraggedAnimationPosition;
            Form p = getComponentForm();
            if (p != null) {
                p.registerAnimatedInternal(this);
            }
            fixedDraggedMotion.start();
        }
        return;
    }
    if (!isHover && pointerSelect(x, y) > -1) {
        if (fixedSelection > FIXED_NONE_BOUNDRY) {
            int index = pointerSelect(x, y);
            updateAnimationPosition(index - getSelectedIndex());
            setSelectedIndex(index);
            fireActionEvent(new ActionEvent(eventSource, ActionEvent.Type.Other));
            return;
        }
        if ((fireOnClick && fixedSelection < FIXED_NONE_BOUNDRY) || fireOnRelease) {
            // fire the action event into the selected component
            Component selectionCmp = renderer.getListCellRendererComponent(this, getSelectedItem(), getSelectedIndex(), true);
            Style style = getStyle();
            int width = getWidth() - style.getHorizontalPadding() - getSideGap();
            Rectangle pos = new Rectangle();
            Dimension rendererSize = getElementSize(false, true);
            calculateComponentPosition(getSelectedIndex(), width, pos, rendererSize, getElementSize(true, true), true);
            int absX = getAbsoluteX();
            int posX = pos.getX();
            int absY = getAbsoluteY();
            int posY = pos.getY();
            int newX = x - absX - posX;
            int newY = y - absY - posY;
            selectionCmp.setX(0);
            selectionCmp.setY(0);
            if (selectionCmp instanceof Container) {
                Component tmp = ((Container) selectionCmp).getComponentAt(newX, newY);
                if (tmp != null) {
                    selectionCmp = tmp;
                }
            }
            if (longPress) {
                selectionCmp.longPointerPress(newX, newY);
                fireActionEvent(new ActionEvent(eventSource, newX, newY, true));
            } else {
                selectionCmp.pointerPressed(newX, newY);
                selectionCmp.pointerReleased(newX, newY);
                fireActionEvent(new ActionEvent(eventSource, newX, newY, false));
            }
        }
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) Rectangle(com.codename1.ui.geom.Rectangle) Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

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