Search in sources :

Example 86 with Dimension

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;
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Example 87 with Dimension

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;
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 88 with Dimension

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);
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Example 89 with Dimension

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);
}
Also used : Dimension(com.codename1.ui.geom.Dimension)

Example 90 with Dimension

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();
}
Also used : Motion(com.codename1.ui.animations.Motion) 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