Search in sources :

Example 1 with Field

use of net.rim.device.api.ui.Field in project Samples-for-Java by blackberry.

the class LeftRightTwoCellManager method sublayout.

protected void sublayout(int width, int height) {
    Field field;
    // Field 0 goes to the left, Field 1 to the right 
    int y = _padding_top;
    if (getFieldCount() > 0) {
        field = getField(0);
        setPositionChild(field, _padding_left, y);
        layoutChild(field, field.getPreferredWidth(), field.getPreferredHeight());
    }
    if (getFieldCount() > 1) {
        field = getField(1);
        int field_width = field.getPreferredWidth();
        int x = Display.getWidth() - field_width - _padding_right;
        setPositionChild(field, x, y);
        layoutChild(field, field.getPreferredWidth(), field.getPreferredHeight());
    }
    // Set the manager's dimensions
    setExtent(width, getPreferredHeight());
}
Also used : Field(net.rim.device.api.ui.Field)

Example 2 with Field

use of net.rim.device.api.ui.Field in project CodenameOne by codenameone.

the class BlackBerryCanvas method paint.

public void paint(Graphics g) {
    int f = getFieldCount();
    if (f > 0) {
        g.drawBitmap(0, 0, getWidth(), getHeight(), screen, 0, 0);
        Form currentForm = Display.getInstance().getCurrent();
        for (int iter = 0; iter < f; iter++) {
            Field fld = getField(iter);
            int pops = 0;
            if (currentForm != null) {
                PeerComponent p = findPeer(currentForm.getContentPane(), fld);
                if (p != null) {
                    pops = clipOnLWUITBounds(p, g);
                } else {
                    Component cmp = currentForm.getFocused();
                    // we are now editing an edit field
                    if (cmp != null && cmp instanceof TextArea && cmp.hasFocus() && fld instanceof EditField) {
                        pops = clipOnLWUITBounds(cmp, g);
                        int x = fld.getLeft();
                        int y = fld.getTop();
                        g.clear(x, y, Math.max(cmp.getWidth(), fld.getWidth()), Math.max(cmp.getHeight(), fld.getHeight()));
                    }
                }
            }
            paintChild(g, fld);
            while (pops > 0) {
                g.popContext();
                pops--;
            }
        }
    } else {
        g.drawBitmap(0, 0, getWidth(), getHeight(), screen, 0, 0);
    }
    g.setColor(0);
    g.drawText(debug, 0, 0);
    painted = true;
}
Also used : EditField(net.rim.device.api.ui.component.EditField) Field(net.rim.device.api.ui.Field) PeerComponent(com.codename1.ui.PeerComponent) EditField(net.rim.device.api.ui.component.EditField) Form(com.codename1.ui.Form) TextArea(com.codename1.ui.TextArea) Component(com.codename1.ui.Component) PeerComponent(com.codename1.ui.PeerComponent)

Example 3 with Field

use of net.rim.device.api.ui.Field in project Samples-for-Java by blackberry.

the class Banner method sublayout.

/**
	 * Layout the banner
	 * 
	 * @param width
	 * @param height
	 */
protected void sublayout(int width, int height) {
    int fullWidth = width;
    width -= (hPadding << 1);
    int availableWidth = width;
    // each field reduces our available width
    // Calculate max height as we go
    int maxHeight = 0;
    int fieldCount = getFieldCount();
    Field child;
    for (int i = 0; i < fieldCount; i++) {
        child = getField(i);
        if (hasField(title) && child == title) {
            continue;
        // Layout title last, separately
        }
        layoutChild(child, availableWidth, height);
        XYRect childExtent = child.getExtent();
        availableWidth -= childExtent.width;
        if (hasField(icon) && child == icon) {
        // skip the interior padding loss.
        } else {
            availableWidth -= interiorPadding;
        }
        maxHeight = Math.max(maxHeight, childExtent.height);
    }
    // Layout Title with remaining space
    if (hasField(title)) {
        child = title;
        layoutChild(child, availableWidth, height);
        XYRect childExtent = child.getExtent();
        availableWidth -= childExtent.width + interiorPadding;
        maxHeight = Math.max(maxHeight, childExtent.height);
    }
    // Set Positions
    if (hasField(icon)) {
        int childY = determineTop(vPadding, icon.getExtent().height, maxHeight, DrawStyle.VCENTER);
        setPositionChild(icon, hPadding, childY);
    }
    if (hasField(title)) {
        int childX = determineLeft(title, width, icon, DrawStyle.LEFT);
        int childY = determineTop(vPadding, title.getExtent().height, maxHeight, DrawStyle.VCENTER);
        setPositionChild(title, childX, childY);
    }
    if (hasField(timeDisplay)) {
        int childX = determineLeft(timeDisplay, width, new Field[] { icon, title }, DrawStyle.LEFT);
        int childY = determineTop(vPadding, timeDisplay.getExtent().height, maxHeight, DrawStyle.VCENTER);
        setPositionChild(timeDisplay, childX, childY);
    }
    if (hasField(wirelessStatus)) {
        int childX = determineLeft(wirelessStatus, width, new Field[0], DrawStyle.RIGHT);
        int drawStyle = DrawStyle.BOTTOM;
        if (isDimension) {
            drawStyle = DrawStyle.VCENTER;
        }
        int childY = determineTop(vPadding, wirelessStatus.getExtent().height, maxHeight, drawStyle);
        setPositionChild(wirelessStatus, childX, childY);
    }
    if (hasField(wirelessStatus) && hasField(roam)) {
        int childY = determineTop(vPadding, roam.getExtent().height, maxHeight, DrawStyle.VCENTER);
        int childX = determineLeft(roam, width, wirelessStatus, DrawStyle.RIGHT);
        setPositionChild(roam, childX, childY);
    }
    if (hasField(wifi)) {
        int childY = determineTop(vPadding, wifi.getExtent().height, maxHeight, DrawStyle.VCENTER);
        int childX = determineLeft(wifi, width, new Field[] { wirelessStatus, roam }, DrawStyle.RIGHT);
        setPositionChild(wifi, childX, childY);
    }
    if (hasField(phone)) {
        int childY = determineTop(vPadding, phone.getExtent().height, maxHeight, DrawStyle.VCENTER);
        int childX = determineLeft(phone, width, new Field[] { wirelessStatus, wifi, roam }, DrawStyle.RIGHT);
        setPositionChild(phone, childX, childY);
    }
    if (hasField(battery)) {
        int childY = determineTop(vPadding, battery.getExtent().height, maxHeight, DrawStyle.VCENTER);
        int childX = determineLeft(battery, width, new Field[] { wirelessStatus, wifi, phone, roam }, DrawStyle.RIGHT);
        setPositionChild(battery, childX, childY);
    }
    if (hasField(notifications)) {
        int childX = determineLeft(notifications, width, new Field[] { wirelessStatus, wifi, battery, phone, roam }, DrawStyle.RIGHT);
        setPositionChild(notifications, childX, vPadding);
    }
    int totalHeight = maxHeight + (vPadding >> 1);
    setVirtualExtent(fullWidth, totalHeight);
    setExtent(fullWidth, totalHeight);
}
Also used : LabelField(net.rim.device.api.ui.component.LabelField) BitmapField(net.rim.device.api.ui.component.BitmapField) Field(net.rim.device.api.ui.Field) XYRect(net.rim.device.api.ui.XYRect)

Example 4 with Field

use of net.rim.device.api.ui.Field 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

Field (net.rim.device.api.ui.Field)4 PeerComponent (com.codename1.ui.PeerComponent)2 Component (com.codename1.ui.Component)1 Form (com.codename1.ui.Form)1 TextArea (com.codename1.ui.TextArea)1 Dimension (com.codename1.ui.geom.Dimension)1 XYRect (net.rim.device.api.ui.XYRect)1 ActiveAutoTextEditField (net.rim.device.api.ui.component.ActiveAutoTextEditField)1 BasicEditField (net.rim.device.api.ui.component.BasicEditField)1 BitmapField (net.rim.device.api.ui.component.BitmapField)1 EditField (net.rim.device.api.ui.component.EditField)1 LabelField (net.rim.device.api.ui.component.LabelField)1 NullField (net.rim.device.api.ui.component.NullField)1 PasswordEditField (net.rim.device.api.ui.component.PasswordEditField)1