Java源码示例:com.codename1.ui.events.ActionEvent

示例1
/**
 * Shows the search bar manually which is useful for use cases of popping 
 * up search from code
 * 
 * @param callback gets the search string callbacks
 */
public void showSearchBar(final ActionListener callback) {        
    SearchBar s = new SearchBar(Toolbar.this, searchIconSize) {

        @Override
        public void onSearch(String text) {
            callback.actionPerformed(new ActionEvent(text));
        }

    };
    Form f = (Form) Toolbar.this.getComponentForm();
    setHidden(true);
    f.removeComponentFromForm(Toolbar.this);
    f.setToolbar(s);
    s.initSearchBar();
    if(f == Display.INSTANCE.getCurrent()) {
        f.animateLayout(100);
    }
}
 
示例2
@Override
protected void onMain_CheckBoxRawJsonAction(Component c, ActionEvent event) {
    CheckBox rawPushCheckbox = (CheckBox)c;
    if (rawPushCheckbox.isSelected()) {
        try {
            final String existing = findTextAreaPush().getText();
            JSONObject data = new JSONObject();
            data.put("alert", existing);
            findTextAreaPush().setText(data.toString());
        } catch (JSONException ex) {
            // Ignore error and initialize to default
            findTextAreaPush().setText("{\n"
                    + "  \"alert\":\"message\""
                    + "\n}");
        }
    } else {
        findTextAreaPush().setText("");
    }
}
 
示例3
private void initUI() {
    setLayout(new BorderLayout());
    contentPane.setSafeArea(true);
    titleBar.setSafeArea(true);
    add(BorderLayout.NORTH, titleBar);
    if (parentSheet != null) {
        FontImage.setMaterialIcon(backButton, FontImage.MATERIAL_ARROW_BACK);
    }
    add(BorderLayout.CENTER, contentPane);
    backButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            back(DEFAULT_TRANSITION_DURATION);
        }
    });
    
}
 
示例4
public void start() {
    if(current != null){
        current.show();
        return;
    }
    s = new StateMachine("/theme");        
    
    Display.getInstance().addEdtErrorHandler(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            evt.consume();
            Log.p("Exception in AppName version " + Display.getInstance().getProperty("AppVersion", "Unknown"));
            Log.p("OS " + Display.getInstance().getPlatformName());
            Log.p("Error " + evt.getSource());
            Log.p("Current Form " + Display.getInstance().getCurrent().getName());
            Log.e((Throwable)evt.getSource());
            Log.sendLog();
        }
    });
}
 
示例5
Button createImageButton(final long imageId, final Container grid, final int offset) {
    final Button btn = new Button(URLImage.createToFileSystem(placeholder, FileSystemStorage.getInstance().getAppHomePath() + "/Thumb_" + imageId, THUMB_URL_PREFIX + imageId, URLImage.RESIZE_SCALE_TO_FILL));
    btn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            imageList.setSelectedIndex(offset);
            final Container viewerParent = new Container(new LayeredLayout());
            ImageViewer viewer = new ImageViewer(imageList.getItemAt(offset));
            viewerParent.addComponent(viewer);
            Container parent = new Container(new BorderLayout());
            viewerParent.addComponent(parent);
            parent.addComponent(BorderLayout.SOUTH, createToolbar(imageId));
            
            likeCount = new Label("");
            parent.addComponent(BorderLayout.NORTH, likeCount);
            
            
            viewer.setImageList(imageList);
            grid.getParent().replace(grid, viewerParent, CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 300));
            Display.getInstance().getCurrent().setBackCommand(createBackCommand(viewerParent, grid));
        }
    });
    return btn;
}
 
示例6
ActionListener createDetailsButtonActionListener(final long imageId) {
    return new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                InfiniteProgress ip = new InfiniteProgress();
                Dialog dlg = ip.showInifiniteBlocking();
                try {
                    String[] data = WebServiceProxy.getPhotoDetails(imageId);
                    String s = "";
                    for(String d : data) {
                        s += d;
                        s += "\n";
                    }
                    dlg.dispose();
                    Dialog.show("Data", s, "OK", null);
                } catch(IOException err) {
                    dlg.dispose();
                    Dialog.show("Error", "Error connecting to server", "OK", null);
                }
            }
        };
}
 
示例7
/**
 * 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);
    }
}
 
示例8
public TextComponentPassword() {
    super();
    field.setConstraint(TextArea.PASSWORD);
    action(FontImage.MATERIAL_VISIBILITY_OFF).
        actionClick(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (field.getConstraint() == TextArea.PASSWORD) {
                    field.setConstraint(TextField.NON_PREDICTIVE);
                    action(FontImage.MATERIAL_VISIBILITY_OFF);
                } else {
                    field.setConstraint(TextField.PASSWORD);
                    action(FontImage.MATERIAL_VISIBILITY);
                }
                if (field.isEditing()) {
                    field.stopEditing();
                    field.startEditingAsync();
                } else {
                    field.getParent().revalidate();
                }
            }
        });
}
 
示例9
private Component showMyFriends() {
    final Container c = new Container(new BorderLayout());
    c.setScrollable(false);
    BorderLayout bl = new BorderLayout();
    bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
    Container p = new Container(bl);
    p.addComponent(BorderLayout.CENTER, new InfiniteProgress());

    c.addComponent(BorderLayout.CENTER, p);
    final List myFriends = new List();
    myFriends.setRenderer(new FriendsRenderer());
    try {
        FaceBookAccess.getInstance().getUserFriends("me", (DefaultListModel) myFriends.getModel(), new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                c.removeAll();
                c.addComponent(BorderLayout.CENTER, myFriends);
                c.revalidate();
            }
        });
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return c;
}
 
示例10
public void actionPerformed(ActionEvent evt) {
    pressInBounds = false;
    final Form f = getComponentForm();
    Container layered = f.getLayeredPane(AutoCompleteTextField.this.getClass(), true);

    boolean canOpenPopup = true;

    for (int i = 0; i < layered.getComponentCount(); i++) {
        Container wrap = (Container) layered.getComponentAt(i);
        Component pop = wrap.getComponentAt(0);
        if(pop.isVisible()){
            if(!pop.contains(evt.getX(), evt.getY())){

            }else{
                pressInBounds = true;
            }
        }
    }
}
 
示例11
protected boolean keyControl(char c, int status, int time) {
    if(c == Characters.CONTROL_VOLUME_UP || c == Characters.CONTROL_VOLUME_DOWN) {
        int i = MMAPIPlayer.getGlobalVolume();
        if(i == -1) {
            i = 70;
        }
        if(c == Characters.CONTROL_VOLUME_UP) {
            MMAPIPlayer.setGlobalVolume(Math.min(100, i + 4));
        } else {
            MMAPIPlayer.setGlobalVolume(Math.max(0, i - 4));
        }
        if(BlackBerryImplementation.getVolumeListener() != null) {
            BlackBerryImplementation.getVolumeListener().fireActionEvent(new ActionEvent(this, c));
            return true;
        }
    }
    return super.keyControl(c, status, time);
}
 
示例12
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);
        }
    }

}
 
示例13
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;
}
 
示例14
/**
 * Binds pro based crash protection logic that will send out an email in case of an exception thrown on the EDT
 * 
 * @param consumeError true will hide the error from the user, false will leave the builtin logic that defaults to
 * showing an error dialog to the user
 */
public static void bindCrashProtection(final boolean consumeError) {
    if(Display.getInstance().isSimulator()) {
        return;
    }
    Display.getInstance().addEdtErrorHandler(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if(consumeError) {
                evt.consume();
            }
            p("Exception in " + Display.getInstance().getProperty("AppName", "app") + " version " + Display.getInstance().getProperty("AppVersion", "Unknown"));
            p("OS " + Display.getInstance().getPlatformName());
            p("Error " + evt.getSource());
            if(Display.getInstance().getCurrent() != null) {
                p("Current Form " + Display.getInstance().getCurrent().getName());
            } else {
                p("Before the first form!");
            }
            e((Throwable)evt.getSource());
            if(getUniqueDeviceKey() != null) {
                sendLog();
            }
        }
    });
    crashBound = true;
}
 
示例15
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);
        }
    }
}
 
示例16
/**
 * Gest a post from a post Id
 *
 * @param postId the postId
 * @param post an Object to fill with the data
 * @param callback the callback that should be updated when the data arrives
 */
public void getPost(String postId, final Post post, final ActionListener callback) throws IOException {
    getFaceBookObject(postId, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            Vector v = (Vector) ((NetworkEvent) evt).getMetaData();
            Hashtable t = (Hashtable) v.elementAt(0);
            if (post != null) {
                post.copy(t);
            }
            if (callback != null) {
                callback.actionPerformed(evt);
            }
        }
    });
}
 
示例17
/**
 * Gest an album from an albumId
 *
 * @param albumId the albumId
 * @param album an Object to fill with the data
 * @param callback the callback that should be updated when the data arrives
 */
public void getAlbum(String albumId, final Album album, final ActionListener callback) throws IOException {
    getFaceBookObject(albumId, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            Vector v = (Vector) ((NetworkEvent) evt).getMetaData();
            Hashtable t = (Hashtable) v.elementAt(0);
            if (album != null) {
                album.copy(t);
            }
            if (callback != null) {
                callback.actionPerformed(evt);
            }
        }
    });
}
 
示例18
/**
 * {@inheritDoc}
 */
public void actionPerformed(ActionEvent evt) {
    if(!FaceBookAccess.getInstance().isAuthenticated()) {
        FaceBookAccess.setClientId(appId);
        FaceBookAccess.setRedirectURI(redirectURI);
        FaceBookAccess.setClientSecret(clientSecret);
        if(permissions != null) {
            FaceBookAccess.setPermissions(permissions);            
        }
        FaceBookAccess.getInstance().showAuthentication(this);
        return;
    }
    if(evt.getSource() instanceof Exception) {
        return;
    }
    try {
        FaceBookAccess.getInstance().postLike(getPostId());
    } catch (IOException ex) {
        Log.e(ex);
    }
}
 
示例19
/**
 * Wraps the given text field with a UI that will allow us to clear it
 * @param tf the text field
 * @param iconSize size in millimeters for the clear icon, -1 for default size
 * @return a Container that should be added to the UI instead of the actual text field
 */
public static ClearableTextField wrap(final TextArea tf, float iconSize) {
    ClearableTextField cf = new ClearableTextField();
    Button b = new Button("", tf.getUIID());
    if(iconSize > 0) {
        FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR, iconSize);
    } else {
        FontImage.setMaterialIcon(b, FontImage.MATERIAL_CLEAR);
    }
    removeCmpBackground(tf);
    removeCmpBackground(b);
    cf.setUIID(tf.getUIID());
    cf.add(BorderLayout.CENTER, tf);
    cf.add(BorderLayout.EAST, b);
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            tf.stopEditing();
            tf.setText("");
            tf.startEditingAsync();
        }
    });
    return cf;        
}
 
示例20
/**
 * {@inheritDoc}
 */
protected void readResponse(InputStream input) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] buffer = new byte[256];
    int len;
    while ((len = input.read(buffer)) > 0) {
        out.write(buffer, 0, len);
    }

    int size = out.toByteArray().length;
    if (size > 0) {
        String s = new String(out.toByteArray(), 0, size, "UTF-8");
        currentAd = s;
        fireResponseListener(new ActionEvent(currentAd,ActionEvent.Type.Response));
    }
}
 
示例21
/**
 * Executes the back command for the current form, similarly to pressing the back button
 */
public static void goBack() {
    if(verbose) {
        log("goBack()");
    }
    Form f = Display.getInstance().getCurrent();
    Command c = f.getBackCommand();
    assertBool(c != null, "The current form doesn't have a back command at this moment! for form name " + f.getName());
    f.dispatchCommand(c, new ActionEvent(c,ActionEvent.Type.Command));
    waitFor(20);
}
 
示例22
@Override
protected void onMain_ButtonAction(Component c, ActionEvent event) {
    try {
        Logger.getInstance().showLog();
    } catch (ParseException ex) {
        Dialog.show("Error", 
                "Showing log failed:\n\n" + ex.getMessage(), 
                Dialog.TYPE_ERROR, null, "OK", null);
    }
}
 
示例23
@Override
protected void onMain_ButtonClearBadgeAction(Component c, ActionEvent event) {
    if (Parse.getPlatform() != Parse.EPlatform.IOS) {
        Dialog.show("Info", "Badging the app icon is only supported on iOS", "OK", null);
    } else {
        try {
            ParseInstallation.getCurrentInstallation().setBadge(0);
        } catch (ParseException ex) {
            Dialog.show("Error", 
                "Clearing badge failed:\n\n" + ex.getMessage(), 
                Dialog.TYPE_ERROR, null, "OK", null);
        }
    }
}
 
示例24
/**
 * Shows the favorites screen 
 */
void showFavs() {
    final Form favsForm = new Form("Favourites");
    addBackToHome(favsForm);
    favsForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    if(favoritesList.size() == 0) {
        favsForm.addComponent(new SpanLabel("You have not added any properties to your favourites"));
    } else {
        // this is really trivial we just take the favorites and show them as a set of buttons
        for(Map<String, Object> c : favoritesList) {
            MultiButton mb = new MultiButton();
            final Map<String, Object> currentListing = c;
            String thumb_url = (String)currentListing.get("thumb_url");
            String guid = (String)currentListing.get("guid");
            String price_formatted = (String)currentListing.get("price_formatted");
            String summary = (String)currentListing.get("summary");
            mb.setIcon(URLImage.createToStorage(placeholder, guid, thumb_url, URLImage.RESIZE_SCALE_TO_FILL));
            mb.setTextLine1(price_formatted);
            mb.setTextLine2(summary);
            mb.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    showPropertyDetails(favsForm, currentListing);
                }
            });
            favsForm.addComponent(mb);
        }
    }
    favsForm.show();
}
 
示例25
/**
 * A blocking method that creates the card deal animation and binds the drop logic when cards are dropped on the deck
 */
private void dealCard(Component deck, final Container destination, Image cardImage, Card currentCard) {
    final Button card = new Button();
    card.setUIID("Label");
    card.setIcon(cardImage);
    
    // Components are normally placed by layout managers so setX/Y/Width/Height shouldn't be invoked. However,
    // in this case we want the layout animation to deal from a specific location. Notice that we use absoluteX/Y
    // since the default X/Y are relative to their parent container.
    card.setX(deck.getAbsoluteX());
    int deckAbsY = deck.getAbsoluteY();
    if(destination.getY() > deckAbsY) {
        card.setY(deckAbsY - destination.getAbsoluteY());
    } else {
        card.setY(deckAbsY);
    }
    card.setWidth(deck.getWidth());
    card.setHeight(deck.getHeight());
    destination.addComponent(card);
    
    // we save the model data directly into the component so we don't need to keep track of it. Later when we
    // need to check the card type a user touched we can just use getClientProperty
    card.putClientProperty("card", currentCard);
    destination.getParent().animateHierarchyAndWait(400);
    card.setDraggable(true);
    
    // when the user drops a card on a drop target (currently only the deck) we remove it and animate it out
    card.addDropListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            evt.consume();
            card.getParent().removeComponent(card);
            destination.animateLayout(300);
        }
    });
}
 
示例26
private void showLoginForm() {
    Form login = new Form("Login");
    BorderLayout bl = new BorderLayout();
    bl.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
    ComponentGroup loginDetails = new ComponentGroup();
    
    TextField displayName = new TextField();
    displayName.setHint("Display Name");
    loginDetails.addComponent(displayName);

    final TextField email = new TextField();
    email.setHint("E-Mail");
    loginDetails.addComponent(email);

    Button send = new Button("Send Verification");
    loginDetails.addComponent(send);
    
    send.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            onSendAction(email);
        }
    });
    
    login.setLayout(bl);
    login.addComponent(BorderLayout.CENTER, loginDetails);
    login.show();
}
 
示例27
private Command createPictureCommand(final Container grid) {
    return new Command("Take Picture") {
        public void actionPerformed(ActionEvent ev) {
            String picture = Capture.capturePhoto(1024, -1);
            if(picture == null) {
                return;
            }
            MultipartRequest mp = new MultipartRequest() {
                private long key;
                @Override
                protected void readResponse(InputStream input) throws IOException {
                    DataInputStream di = new DataInputStream(input);
                    key = di.readLong();
                }

                @Override
                protected void postResponse() {
                    final Button btn = createImageButton(key, grid, imageList.getSize());
                    imageList.addImageId(key);
                    grid.addComponent(0, btn);
                    if(!animating) {
                        animating = true;
                        grid.animateLayoutAndWait(400);
                        animating = false;
                    }
                }
            };
            mp.setUrl(UPLOAD_URL);
            try {
                mp.addData("i", picture, "image/jpeg");
                mp.addArgument("p", "Data;More data");
                NetworkManager.getInstance().addToQueue(mp);
            } catch(IOException err) {
                err.printStackTrace();
            }
        }
    };
}
 
示例28
ActionListener createLikeAction(final long imageId) {
    return new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    WebServiceProxy.likePhoto(imageId, Preferences.get("key", ""));
                } catch(IOException err) {
                    err.printStackTrace();
                }
            }
        };
}
 
示例29
void showChat() {
    Form f= new Form("Chat");
    f.setLayout(new BorderLayout());
    
    Container south = new Container();
    final TextField tf = new TextField();
    Button send = new Button(new Command("Send") {

        @Override
        public void actionPerformed(ActionEvent evt) {
            if (sock.getReadyState() == WebSocketState.OPEN) {
                sock.send(tf.getText());
                tf.setText("");
            } else {
                Dialog.show("", "The socket is not open", "OK", null);
                showLogin();
            }
            
        }
         
    });
    
    chatContainer = new Container();
    chatContainer.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    
    south.addComponent(tf);
    south.addComponent(send);
    f.addComponent(BorderLayout.SOUTH, south);
    f.addComponent(BorderLayout.CENTER, chatContainer);
    f.setFormBottomPaddingEditingMode(true);
    f.show();
    
}
 
示例30
public void actionPerformed(ActionEvent evt) {
    super.actionPerformed(evt);
    if (isSubmit) {
        htmlForm.submit(key,value);
    } else {
        htmlForm.reset();
    }
}