use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class Form method changeFocusState.
/**
* This method changes the cmp state to be focused/unfocused and fires the
* focus gained/lost events.
* @param cmp the Component to change the focus state
* @param gained if true this Component needs to gain focus if false
* it needs to lose focus
* @return this method returns true if the state change needs to trigger a
* revalidate
*/
private boolean changeFocusState(Component cmp, boolean gained) {
boolean trigger = false;
Style selected = cmp.getSelectedStyle();
Style unselected = cmp.getUnselectedStyle();
// chance we need to trigger a revalidate
if (!selected.getFont().equals(unselected.getFont()) || selected.getPaddingTop() != unselected.getPaddingTop() || selected.getPaddingBottom() != unselected.getPaddingBottom() || selected.getPaddingRight(isRTL()) != unselected.getPaddingRight(isRTL()) || selected.getPaddingLeft(isRTL()) != unselected.getPaddingLeft(isRTL()) || selected.getMarginTop() != unselected.getMarginTop() || selected.getMarginBottom() != unselected.getMarginBottom() || selected.getMarginRight(isRTL()) != unselected.getMarginRight(isRTL()) || selected.getMarginLeft(isRTL()) != unselected.getMarginLeft(isRTL())) {
trigger = true;
}
int prefW = 0;
int prefH = 0;
if (trigger) {
Dimension d = cmp.getPreferredSize();
prefW = d.getWidth();
prefH = d.getHeight();
}
if (gained) {
cmp.setFocus(true);
cmp.fireFocusGained();
fireFocusGained(cmp);
} else {
cmp.setFocus(false);
cmp.fireFocusLost();
fireFocusLost(cmp);
}
// a revalidate
if (trigger) {
cmp.setShouldCalcPreferredSize(true);
Dimension d = cmp.getPreferredSize();
if (prefW != d.getWidth() || prefH != d.getHeight()) {
cmp.setShouldCalcPreferredSize(false);
trigger = false;
}
}
return trigger;
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class IndexedImage method scaled.
/**
* {@inheritDoc}
*/
public Image scaled(int width, int height) {
int srcWidth = getWidth();
int srcHeight = getHeight();
// no need to scale
if (srcWidth == width && srcHeight == height) {
return this;
}
Dimension d = new Dimension(width, height);
Image i = getCachedImage(d);
// currently we only support byte data...
i = new IndexedImage(width, height, palette, scaleArray(imageDataByte, width, height));
cacheImage(d, i);
return i;
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class Slider method calcPreferredSize.
/**
* Return the size we would generally like for the component
*/
protected Dimension calcPreferredSize() {
Style style = getStyle();
int prefW = 0, prefH = 0;
if (style.getBorder() != null) {
prefW = Math.max(style.getBorder().getMinimumWidth(), prefW);
prefH = Math.max(style.getBorder().getMinimumHeight(), prefH);
}
if (thumbImage != null) {
prefW = Math.max(thumbImage.getWidth(), prefW);
prefH = Math.max(thumbImage.getHeight(), prefH);
}
// a generally good indication for size expectations
if (Display.getInstance().isTouchScreenDevice() && isEditable()) {
if (vertical) {
prefW = Math.max(prefW, Font.getDefaultFont().charWidth('X') * 2);
prefH = Math.max(prefH, Display.getInstance().getDisplayHeight() / 2);
} else {
prefW = Math.max(prefW, Display.getInstance().getDisplayWidth() / 2);
prefH = Math.max(prefH, Font.getDefaultFont().getHeight() * 2);
}
} else {
if (vertical) {
prefW = Math.max(prefW, Font.getDefaultFont().charWidth('X'));
prefH = Math.max(prefH, Display.getInstance().getDisplayHeight() / 2);
} else {
prefW = Math.max(prefW, Display.getInstance().getDisplayWidth() / 2);
prefH = Math.max(prefH, Font.getDefaultFont().getHeight());
}
}
if (prefH != 0) {
prefH += style.getVerticalPadding();
}
if (prefW != 0) {
prefW += style.getHorizontalPadding();
}
return new Dimension(prefW, prefH);
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class TextArea method calcPreferredSize.
/**
* {@inheritDoc}
*/
protected Dimension calcPreferredSize() {
if (shouldShowHint()) {
Label l = getHintLabelImpl();
if (l != null) {
Dimension d1 = getUIManager().getLookAndFeel().getTextAreaSize(this, true);
Dimension d2 = l.getPreferredSize();
return new Dimension(Math.max(d1.getWidth(), d2.getWidth()), Math.max(d1.getHeight(), d2.getHeight()));
}
}
return getUIManager().getLookAndFeel().getTextAreaSize(this, true);
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class Component method growShrink.
/**
* Grows or shrinks this component to its new preferred size, this method
* essentially takes a component whose preferred size has changed and creates a "growing"
* effect that lasts for the duration. Notice that some components (such as text areas)
* don't report proper preferred size untill they are laid out once. Hence the first time
* around a text area (or container containing a text area) will not produce the expected
* effect. This can be solved by invoking revalidate before the call to this method only the
* first time around!
*
* @param duration the duration in milliseconds for the grow/shrink animation
*/
public void growShrink(int duration) {
Motion wMotion = Motion.createSplineMotion(getWidth(), getPreferredW(), duration);
Motion hMotion = Motion.createSplineMotion(getHeight(), getPreferredH(), duration);
wMotion.start();
hMotion.start();
setPreferredSize(new Dimension(getWidth(), getHeight()));
// we are using bgpainter just to save the cost of creating another class
getComponentForm().registerAnimated(new BGPainter(wMotion, hMotion));
getComponentForm().revalidate();
}
Aggregations