com.codename1.ui.events.ActionEvent Java Examples

The following examples show how to use com.codename1.ui.events.ActionEvent. 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: AdsService.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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));
    }
}
 
Example #2
Source File: PushDemo.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
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();
        }
    });
}
 
Example #3
Source File: Sheet.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
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);
        }
    });
    
}
 
Example #4
Source File: FaceBookAccess.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
            }
        }
    });
}
 
Example #5
Source File: Log.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
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 #7
Source File: Toolbar.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #8
Source File: StateMachine.java    From parse4cn1 with Apache License 2.0 6 votes vote down vote up
@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("");
    }
}
 
Example #9
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 #10
Source File: HTMLImageMap.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
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);
        }
    }

}
 
Example #11
Source File: BlackBerryCanvas.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example #12
Source File: PhotoShare.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
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);
                }
            }
        };
}
 
Example #13
Source File: AutoCompleteTextField.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
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;
            }
        }
    }
}
 
Example #14
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 #15
Source File: LikeButton.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@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);
    }
}
 
Example #16
Source File: ClearableTextField.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;        
}
 
Example #17
Source File: TextComponentPassword.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
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();
                }
            }
        });
}
 
Example #18
Source File: FBDemo.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #19
Source File: PhotoShare.java    From codenameone-demos with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #20
Source File: FaceBookAccess.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
            }
        }
    });
}
 
Example #21
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 #22
Source File: FaceBookAccess.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the user notifications (this method uses the legacy rest api see http://developers.facebook.com/docs/reference/rest/)
 *
 * @param userId the user id
 * @param startTime Indicates the earliest time to return a notification.
 * This equates to the updated_time field in the notification FQL table. If not specified, this call returns all available notifications.
 * @param includeRead Indicates whether to include notifications that have already been read.
 * By default, notifications a user has read are not included.
 * @param notifications store notifications results into the given model,
 * each entry is an Hashtable Object contaning the Object data
 * @param callback the callback that should be updated when the data arrives
 */
public void getUserNotifications(String userId, String startTime, boolean includeRead,
        DefaultListModel notifications, final ActionListener callback) throws IOException {
    checkAuthentication();

    final FacebookRESTService con = new FacebookRESTService(token, "https://api.facebook.com/method/notifications.getList", false);
    con.addArgument("start_time", startTime);
    con.addArgument("include_read", new Boolean(includeRead).toString());
    con.addArgument("format", "json");

    con.setResponseDestination(notifications);
    con.addResponseListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            if (!con.isAlive()) {
                return;
            }
            if (callback != null) {
                callback.actionPerformed(evt);
            }
        }
    });

    if (slider != null) {
        SliderBridge.bindProgress(con, slider);
    }
    for (int i = 0; i < responseCodeListeners.size(); i++) {
        con.addResponseCodeListener((ActionListener) responseCodeListeners.elementAt(i));
    }
    current = con;
    NetworkManager.getInstance().addToQueue(con);
}
 
Example #23
Source File: ProxyHttpTile.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an Http Tile
 * 
 * @param tileSize the tile size
 * @param bbox the tile bounding box
 * @param url the url to bring the image from
 */
public ProxyHttpTile(Dimension tileSize, BoundingBox bbox, final String url) {
    super(tileSize, bbox, null);
    _url = url;
    String cacheId = url.substring(url.indexOf(":")+1);
    cacheId = StringUtil.replaceAll(cacheId, "\\", "_");
    cacheId = StringUtil.replaceAll(cacheId, "/", "_");
    cacheId = StringUtil.replaceAll(cacheId, ".", "_");
    cacheId = StringUtil.replaceAll(cacheId, "?", "_");
    cacheId = StringUtil.replaceAll(cacheId, "&", "_");
    
    ImageDownloadService.createImageToStorage(url, new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            NetworkEvent ne = (NetworkEvent) evt;

            Image i = (Image) ne.getMetaData();
            i.lock();
            _tile = new Tile(ProxyHttpTile.this.dimension(),
                    ProxyHttpTile.this.getBoundingBox(),
                    i);
            ProxyHttpTile.this.fireReady();
        }
    }, cacheId, true);


}
 
Example #24
Source File: GoogleLoginSample.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void showContactsForm(UserData data) {
    Form f = new Form("Contact Info");
    f.setToolbar(new Toolbar());
    f.getToolbar().setTitle("Contact Info");
    Form prev = CN.getCurrentForm();
    if (prev != null) {
        f.getToolbar().setBackCommand(new Command("Back") {
            public void actionPerformed(ActionEvent evt) {
                prev.show();
            }
            
        });
    }
    f.add(new Label("You are logged in as "+fullName));
    
    Button logout = new Button("Log out");
    logout.addActionListener(e->{
        GoogleConnect.getInstance().doLogout();
        Preferences.set(tokenPrefix + "tokenExpires", -1);
        Preferences.set(tokenPrefix + "token", (String)null);
        showLoginForm();
    });
    f.add(logout);
    f.show();
    
    
}
 
Example #25
Source File: Switch.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent evt) {

            dragged = true;
            deltaX = pressX - evt.getX();
            deltaY = pressY - evt.getY();
            if (Math.abs(deltaY) >= Math.abs(deltaX*0.5)) {
                dragged = false;
                deltaX = 0;
                deltaY = 0;
            } else {
                evt.consume();
            }
        }
 
Example #26
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 #27
Source File: ComponentTreeInspector.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(java.awt.event.ActionEvent evt) {
    if (evt.getSource() == unselected) {
        ComponentTreeInspector.this.unselectedActionPerformed(evt);
    }
    else if (evt.getSource() == refreshTree) {
        ComponentTreeInspector.this.refreshTreeActionPerformed(evt);
    }
    else if (evt.getSource() == validate) {
        ComponentTreeInspector.this.validateActionPerformed(evt);
    }
}
 
Example #28
Source File: ContainerList.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void keyReleased(int keyCode) {
    super.keyReleased(keyCode);
    if(Display.getInstance().getGameAction(keyCode) == Display.GAME_FIRE) {
        fireActionEvent(new ActionEvent(ContainerList.this, keyCode));
    }
}
 
Example #29
Source File: OnOffSwitch.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private void initialize() {
    iosMode = UIManager.getInstance().isThemeConstant("onOffIOSModeBool", false);
    removeAll();
    setFocusable(true);
    if(iosMode) {
        button = null;
        switchMaskImage = UIManager.getInstance().getThemeImageConstant("switchMaskImage");
        switchOnImage = UIManager.getInstance().getThemeImageConstant("switchOnImage");
        switchOffImage = UIManager.getInstance().getThemeImageConstant("switchOffImage");
        noTextMode = UIManager.getInstance().isThemeConstant("noTextModeBool", false);
    } else {
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        button = new CheckBox(on);
        button.setToggle(true);
        button.setUIID("Button");
        button.setEndsWith3Points(false);
        button.getUnselectedStyle().setFont(getUnselectedStyle().getFont());
        button.getSelectedStyle().setFont(getSelectedStyle().getFont());
        button.getPressedStyle().setFont(getSelectedStyle().getFont());
        
        Dimension d = button.getPreferredSize();
        button.setText(off);
        int pw = button.getPreferredW();
        d.setWidth(Math.max(pw, d.getWidth()));
        
        // prevents the button from growing/shrinking as its states flip
        button.setPreferredSize(d);
        
        buttonWidth = button.getPreferredW();
        button.setFocusable(false);
        updateButton();
        addComponent(button);
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                flip();
            }
        });
    }
}
 
Example #30
Source File: FacebookShare.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void actionPerformed(ActionEvent evt) {
    if (!FaceBookAccess.getInstance().isAuthenticated()) {
        FaceBookAccess.getInstance().showAuthentication(this);
        return;
    }
    if (evt.getSource() instanceof Exception) {
        return;
    }
    if (evt.getSource() instanceof String) {
        token = (String) evt.getSource();
    }

    super.actionPerformed(evt);
}