Search in sources :

Example 36 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class OnOffSwitch method animateTo.

private void animateTo(final boolean value, final int position) {
    int switchButtonPadInt = UIManager.getInstance().getThemeConstant("switchButtonPadInt", 16);
    if (Display.getInstance().getDisplayWidth() > 480) {
        // is retina
        switchButtonPadInt *= 2;
    }
    final Motion current = Motion.createEaseInOutMotion(Math.abs(position), switchMaskImage.getWidth() - 2 * switchButtonPadInt, 100);
    current.start();
    deltaX = position;
    getComponentForm().registerAnimated(new Animation() {

        public boolean animate() {
            deltaX = current.getValue();
            if (value) {
                deltaX *= -1;
            }
            dragged = true;
            if (current.isFinished()) {
                dragged = false;
                Form f = getComponentForm();
                if (f != null) {
                    f.deregisterAnimated(this);
                }
                OnOffSwitch.this.setValue(value);
            }
            repaint();
            return false;
        }

        public void paint(Graphics g) {
        }
    });
    dragged = true;
}
Also used : Graphics(com.codename1.ui.Graphics) Motion(com.codename1.ui.animations.Motion) Form(com.codename1.ui.Form) Animation(com.codename1.ui.animations.Animation)

Example 37 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class RSSReader method showRSSEntry.

/**
 * Shows a form containing the RSS entry
 *
 * @param h the parsed entry
 */
protected void showRSSEntry(Hashtable h) {
    Form newForm = null;
    if (targetContainer != null) {
        if (targetContainer instanceof Form) {
            newForm = (Form) targetContainer;
        } else {
            newForm = new Form((String) h.get("title"));
            newForm.setLayout(new BorderLayout());
            newForm.addComponent(BorderLayout.CENTER, targetContainer);
        }
        updateComponentValues(newForm, h);
    } else {
        newForm = new Form((String) h.get("title"));
        newForm.setScrollable(false);
        WebBrowser c = new WebBrowser();
        String s = (String) h.get("description");
        s = "<html><body>" + s + "</body></html>";
        c.setPage(s, null);
        newForm.setLayout(new BorderLayout());
        newForm.addComponent(BorderLayout.CENTER, c);
    }
    if (addBackToTaget) {
        final Form sourceForm = Display.getInstance().getCurrent();
        Command back = new BackCommand(sourceForm);
        newForm.addCommand(back);
        newForm.setBackCommand(back);
    }
    newForm.show();
}
Also used : BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) Command(com.codename1.ui.Command)

Example 38 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class ToastBar method getToastBarComponent.

private ToastBarComponent getToastBarComponent() {
    Form f = Display.getInstance().getCurrent();
    if (f != null && !(f instanceof Dialog)) {
        ToastBarComponent c = (ToastBarComponent) f.getClientProperty("ToastBarComponent");
        if (c == null || c.getParent() == null) {
            c = new ToastBarComponent();
            c.hidden = true;
            f.putClientProperty("ToastBarComponent", c);
            Container layered = f.getLayeredPane(this.getClass(), true);
            layered.setLayout(new BorderLayout());
            layered.addComponent(position == Component.TOP ? BorderLayout.NORTH : BorderLayout.SOUTH, c);
            updateStatus();
        }
        if (position == Component.BOTTOM && f.getInvisibleAreaUnderVKB() > 0) {
            Style s = c.getAllStyles();
            s.setMarginUnit(Style.UNIT_TYPE_PIXELS);
            s.setMarginBottom(f.getInvisibleAreaUnderVKB());
        }
        return c;
    }
    return null;
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) Style(com.codename1.ui.plaf.Style)

Example 39 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class ToastBar method setVisible.

/**
 * Shows or hides the {@code ToastBar}.
 * @param visible
 */
public void setVisible(boolean visible) {
    final ToastBarComponent c = getToastBarComponent();
    if (c == null || c.isVisible() == visible) {
        return;
    }
    if (visible) {
        c.hidden = true;
        c.setVisible(false);
        c.setHeight(0);
        c.setShouldCalcPreferredSize(true);
        c.getParent().revalidate();
        c.hidden = false;
        c.label.setPreferredH(UIManager.getInstance().getLookAndFeel().getTextAreaSize(c.label, true).getHeight());
        c.setShouldCalcPreferredSize(true);
        $(c).slideUpAndWait(2);
        $(c).slideDownAndWait(800);
        c.setVisible(true);
        updateStatus();
    } else {
        Form f = c.getComponentForm();
        if (Display.getInstance().getCurrent() == f && !f.getMenuBar().isMenuShowing()) {
            if (this.position == Component.BOTTOM) {
                c.setY(c.getY() + c.getHeight());
            }
            $(c).slideUpAndWait(500);
        } else {
            c.getParent().revalidate();
        }
        c.hidden = true;
        c.setVisible(false);
    }
}
Also used : Form(com.codename1.ui.Form)

Example 40 with Form

use of com.codename1.ui.Form in project CodenameOne by codenameone.

the class TestRecorder method generatePointerEventArguments.

private String generatePointerEventArguments(int x, int y) {
    com.codename1.ui.Component cmp = getCodenameOneComponentAt(x, y);
    if (cmp.getParent() instanceof Form) {
        cmp = cmp.getParent();
    }
    String componentName = cmp.getName();
    if (componentName == null) {
        componentName = getPathToComponent(cmp);
    } else {
        componentName = "\"" + componentName + "\"";
    }
    float actualX = ((float) x - cmp.getAbsoluteX()) / ((float) cmp.getWidth());
    float actualY = ((float) y - cmp.getAbsoluteY()) / ((float) cmp.getHeight());
    return "(" + actualX + "f, " + actualY + "f, " + componentName + ");\n";
}
Also used : Form(com.codename1.ui.Form) Component(com.codename1.ui.Component)

Aggregations

Form (com.codename1.ui.Form)90 ActionEvent (com.codename1.ui.events.ActionEvent)41 Component (com.codename1.ui.Component)38 BorderLayout (com.codename1.ui.layouts.BorderLayout)38 Container (com.codename1.ui.Container)26 ActionListener (com.codename1.ui.events.ActionListener)25 Dialog (com.codename1.ui.Dialog)21 Command (com.codename1.ui.Command)19 Hashtable (java.util.Hashtable)17 Label (com.codename1.ui.Label)14 Style (com.codename1.ui.plaf.Style)14 IOException (java.io.IOException)14 TextArea (com.codename1.ui.TextArea)13 Vector (java.util.Vector)12 Button (com.codename1.ui.Button)11 Graphics (com.codename1.ui.Graphics)9 RadioButton (com.codename1.ui.RadioButton)9 Animation (com.codename1.ui.animations.Animation)9 Image (com.codename1.ui.Image)8 UIManager (com.codename1.ui.plaf.UIManager)8