Search in sources :

Example 91 with Dimension

use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.

the class Component method setSize.

/**
 * Sets the Component size, this method is exposed for the purpose of
 * external layout managers and should not be invoked directly.<br>
 * If a user wishes to effect the component size setPreferredSize should
 * be used.
 *
 * @param d the component dimension
 * @see #setPreferredSize
 */
public void setSize(Dimension d) {
    Dimension d2 = bounds.getSize();
    d2.setWidth(d.getWidth());
    d2.setHeight(d.getHeight());
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 92 with Dimension

use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.

the class Component method getPreferredSizeWithMargin.

Dimension getPreferredSizeWithMargin() {
    Dimension d = preferredSize();
    Style s = getStyle();
    return new Dimension(d.getWidth() + s.getHorizontalMargins(), d.getHeight() + s.getVerticalMargins());
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Example 93 with Dimension

use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.

the class Component method repaint.

/**
 * Repaints a specific region within the component
 *
 * @param x boundary of the region to repaint in absolute screen coordinates not component coordinates
 * @param y boundary of the region to repaint in absolute screen coordinates not component coordinates
 * @param w boundary of the region to repaint
 * @param h boundary of the region to repaint
 */
public void repaint(int x, int y, int w, int h) {
    Rectangle rect;
    synchronized (dirtyRegionLock) {
        if (dirtyRegion == null) {
            if (repaintPending) {
                return;
            }
            rect = new Rectangle(x, y, w, h);
            setDirtyRegion(rect);
        } else if (dirtyRegion.getX() != x || dirtyRegion.getY() != y || dirtyRegion.getSize().getWidth() != w || dirtyRegion.getSize().getHeight() != h) {
            rect = new Rectangle(dirtyRegion);
            Dimension size = rect.getSize();
            int x1 = Math.min(rect.getX(), x);
            int y1 = Math.min(rect.getY(), y);
            int x2 = Math.max(x + w, rect.getX() + size.getWidth());
            int y2 = Math.max(y + h, rect.getY() + size.getHeight());
            rect.setX(x1);
            rect.setY(y1);
            size.setWidth(x2 - x1);
            size.setHeight(y2 - y1);
            setDirtyRegion(rect);
        }
    }
    repaint(this);
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle) Dimension(com.codename1.ui.geom.Dimension)

Example 94 with Dimension

use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.

the class BlackBerryImplementation method createNativePeer.

/**
 * @inheritDoc
 */
public PeerComponent createNativePeer(Object nativeComponent) {
    if (nativeComponent instanceof Field) {
        if (nullFld == null) {
            nullFld = new NullField();
            nullFld.setFocusListener(new FinishEditFocus());
            synchronized (UiApplication.getEventLock()) {
                canvas.add(nullFld);
            }
        }
        final Field fld = (Field) nativeComponent;
        final PeerComponent peer = new PeerComponent(fld) {

            public boolean isFocusable() {
                if (fld != null) {
                    return fld.isFocusable();
                }
                return super.isFocusable();
            }

            public void setFocus(boolean b) {
                if (hasFocus() == b) {
                    return;
                }
                if (b) {
                    canvas.eventTarget = fld;
                    fld.setFocusListener(new PeerFocus(fld, this));
                } else {
                    fld.setFocusListener(null);
                    if (canvas.eventTarget == fld) {
                        canvas.eventTarget = null;
                    }
                }
                if (isInitialized()) {
                    InvokeLaterWrapper i = new InvokeLaterWrapper(INVOKE_AND_WAIT_setFocus);
                    i.val = b;
                    i.fld = fld;
                    app.invokeAndWait(i);
                } else {
                    super.setFocus(b);
                }
            }

            public boolean animate() {
                if (fld.isDirty()) {
                    repaint();
                }
                return super.animate();
            }

            protected Dimension calcPreferredSize() {
                InvokeLaterWrapper i = new InvokeLaterWrapper(INVOKE_AND_WAIT_calcPreferredSize);
                i.dim = new Dimension();
                i.fld = fld;
                app.invokeAndWait(i);
                return i.dim;
            }

            protected void onPositionSizeChange() {
                InvokeLaterWrapper i = new InvokeLaterWrapper(INVOKE_LATER_dirty);
                i.fld = fld;
                app.invokeLater(i);
            }

            protected void initComponent() {
                fieldComponentMap.put(fld, this);
                InvokeLaterWrapper i = new InvokeLaterWrapper(INVOKE_LATER_initComponent);
                i.fld = fld;
                app.invokeLater(i);
                setFocus(super.hasFocus());
                if (hasFocus()) {
                    canvas.eventTarget = fld;
                }
                getComponentForm().registerAnimated(this);
            }

            protected void deinitialize() {
                getComponentForm().deregisterAnimated(this);
                canvas.eventTarget = null;
                InvokeLaterWrapper i = new InvokeLaterWrapper(INVOKE_LATER_deinitialize);
                i.fld = fld;
                app.invokeLater(i);
                fieldComponentMap.remove(fld);
            }
        };
        fieldComponentMap.put(fld, peer);
        return peer;
    }
    throw new IllegalArgumentException(nativeComponent.getClass().getName());
}
Also used : PasswordEditField(net.rim.device.api.ui.component.PasswordEditField) Field(net.rim.device.api.ui.Field) ActiveAutoTextEditField(net.rim.device.api.ui.component.ActiveAutoTextEditField) NullField(net.rim.device.api.ui.component.NullField) BasicEditField(net.rim.device.api.ui.component.BasicEditField) PeerComponent(com.codename1.ui.PeerComponent) NullField(net.rim.device.api.ui.component.NullField) Dimension(com.codename1.ui.geom.Dimension)

Aggregations

Dimension (com.codename1.ui.geom.Dimension)74 Style (com.codename1.ui.plaf.Style)27 Component (com.codename1.ui.Component)16 Image (com.codename1.ui.Image)16 Rectangle (com.codename1.ui.geom.Rectangle)9 EncodedImage (com.codename1.ui.EncodedImage)8 Label (com.codename1.ui.Label)7 Container (com.codename1.ui.Container)6 FileEncodedImage (com.codename1.components.FileEncodedImage)5 StorageImage (com.codename1.components.StorageImage)5 ActionEvent (com.codename1.ui.events.ActionEvent)5 Form (com.codename1.ui.Form)4 Dimension (java.awt.Dimension)4 Font (com.codename1.ui.Font)3 FontImage (com.codename1.ui.FontImage)3 TextArea (com.codename1.ui.TextArea)3 ActionListener (com.codename1.ui.events.ActionListener)3 Point (com.codename1.ui.geom.Point)3 BorderLayout (com.codename1.ui.layouts.BorderLayout)3 Border (com.codename1.ui.plaf.Border)3