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