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());
}
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;
}
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);
}
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());
}
Aggregations