Search in sources :

Example 41 with ActionListener

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

the class MultiButton method setCheckBox.

/**
 * Turns the multi-button into a checkbox multi-button
 *
 * @param b true for a checkbox multi-button
 */
public void setCheckBox(boolean b) {
    if (b != isCheckBox()) {
        Container par = emblem.getParent();
        Button old = emblem;
        if (b) {
            emblem = new CheckBox();
        } else {
            emblem = new Button();
        }
        emblem.setUIID(old.getUIID());
        emblem.setName(old.getName());
        java.util.List actionListeners = (java.util.List) old.getListeners();
        if (actionListeners != null) {
            for (int iter = 0; iter < actionListeners.size(); iter++) {
                emblem.addActionListener((ActionListener) actionListeners.get(iter));
            }
        }
        if (old.getCommand() != null) {
            Image img = old.getIcon();
            emblem.setCommand(old.getCommand());
            emblem.setText("");
            emblem.setIcon(img);
        } else {
            emblem.setText(old.getText());
            if (old.getIcon() != null) {
                emblem.setIcon(old.getIcon());
            }
        }
        par.replace(old, emblem, null);
        setLeadComponent(emblem);
    }
}
Also used : Container(com.codename1.ui.Container) RadioButton(com.codename1.ui.RadioButton) Button(com.codename1.ui.Button) CheckBox(com.codename1.ui.CheckBox) Image(com.codename1.ui.Image)

Example 42 with ActionListener

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

the class MultiButton method setRadioButton.

/**
 * Turns the multi-button into a radio multi-button
 *
 * @param b true for a radio multi-button
 */
public void setRadioButton(boolean b) {
    if (b != isRadioButton()) {
        Container par = emblem.getParent();
        Button old = emblem;
        if (b) {
            emblem = new RadioButton();
            if (group != null) {
                ((RadioButton) emblem).setGroup(group);
            }
        } else {
            emblem = new Button();
        }
        emblem.setName(old.getName());
        emblem.setUIID(old.getUIID());
        java.util.List actionListeners = (java.util.List) old.getListeners();
        if (actionListeners != null) {
            for (int iter = 0; iter < actionListeners.size(); iter++) {
                emblem.addActionListener((ActionListener) actionListeners.get(iter));
            }
        }
        if (old.getCommand() != null) {
            Image img = old.getIcon();
            emblem.setCommand(old.getCommand());
            emblem.setText("");
            emblem.setIcon(img);
        }
        par.replace(old, emblem, null);
        setLeadComponent(emblem);
        emblem.setShowEvenIfBlank(true);
    }
}
Also used : Container(com.codename1.ui.Container) RadioButton(com.codename1.ui.RadioButton) Button(com.codename1.ui.Button) RadioButton(com.codename1.ui.RadioButton) Image(com.codename1.ui.Image)

Example 43 with ActionListener

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

the class OnOffSwitch method initialize.

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();
            }
        });
    }
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) CheckBox(com.codename1.ui.CheckBox) ActionEvent(com.codename1.ui.events.ActionEvent) BoxLayout(com.codename1.ui.layouts.BoxLayout) Dimension(com.codename1.ui.geom.Dimension)

Example 44 with ActionListener

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

the class Ads method setAd.

/**
 * HTML ad received from the server
 * @param ad the ad to set
 */
public void setAd(String ad) {
    HTMLComponent html = new HTMLComponent(new AsyncDocumentRequestHandlerImpl() {

        protected ConnectionRequest createConnectionRequest(DocumentInfo docInfo, IOCallback callback, Object[] response) {
            ConnectionRequest req = super.createConnectionRequest(docInfo, callback, response);
            req.setFailSilently(true);
            req.addResponseCodeListener(new ActionListener() {

                public void actionPerformed(ActionEvent evt) {
                // do nothing, just make sure the html won't throw an error
                }
            });
            return req;
        }
    });
    html.setSupressExceptions(true);
    html.setHTMLCallback(this);
    html.setBodyText("<html><body><div align='center'>" + ad + "</div></body></html>");
    replace(getComponentAt(0), html, null);
    revalidate();
    html.setPageUIID("Container");
    html.getStyle().setBgTransparency(0);
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest) ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) AsyncDocumentRequestHandlerImpl(com.codename1.ui.html.AsyncDocumentRequestHandlerImpl) IOCallback(com.codename1.ui.html.IOCallback) HTMLComponent(com.codename1.ui.html.HTMLComponent) DocumentInfo(com.codename1.ui.html.DocumentInfo)

Example 45 with ActionListener

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

the class FloatingActionButton method released.

@Override
public void released(int x, int y) {
    super.released(x, y);
    if (current != null) {
        current.dispose();
        current = null;
    }
    // if this fab has sub fab's display them
    if (subMenu != null) {
        final Container con = createPopupContent(subMenu);
        Dialog d = new Dialog();
        d.setDialogUIID("Container");
        d.getContentPane().setUIID("Container");
        d.setLayout(new BorderLayout());
        d.add(BorderLayout.CENTER, con);
        for (FloatingActionButton next : subMenu) {
            next.current = d;
        }
        d.setTransitionInAnimator(CommonTransitions.createEmpty());
        d.setTransitionOutAnimator(CommonTransitions.createEmpty());
        for (Component c : con) {
            c.setVisible(false);
        }
        Form f = getComponentForm();
        int oldTint = f.getTintColor();
        f.setTintColor(0);
        d.setBlurBackgroundRadius(-1);
        d.addShowListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                for (Component c : con) {
                    c.setY(con.getHeight());
                    c.setVisible(true);
                }
                con.animateLayout(200);
            }
        });
        showPopupDialog(d);
        f.setTintColor(oldTint);
        for (FloatingActionButton next : subMenu) {
            next.remove();
        }
        con.removeAll();
    }
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) ActionEvent(com.codename1.ui.events.ActionEvent) Component(com.codename1.ui.Component)

Aggregations

ActionEvent (com.codename1.ui.events.ActionEvent)61 ActionListener (com.codename1.ui.events.ActionListener)61 IOException (java.io.IOException)25 BorderLayout (com.codename1.ui.layouts.BorderLayout)20 EventDispatcher (com.codename1.ui.util.EventDispatcher)16 Hashtable (java.util.Hashtable)14 NetworkEvent (com.codename1.io.NetworkEvent)13 Form (com.codename1.ui.Form)13 Vector (java.util.Vector)11 Container (com.codename1.ui.Container)10 Button (com.codename1.ui.Button)8 ActionEvent (java.awt.event.ActionEvent)8 ActionListener (java.awt.event.ActionListener)8 Dialog (com.codename1.ui.Dialog)7 EncodedImage (com.codename1.ui.EncodedImage)6 Image (com.codename1.ui.Image)6 Label (com.codename1.ui.Label)6 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)6 MediaException (javax.microedition.media.MediaException)6 RecordStoreException (javax.microedition.rms.RecordStoreException)6