Search in sources :

Example 66 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class HTMLTable method createCell.

/**
 * This method is overriden to return the component that is contained in the HTMLTableModel
 * (Since our model contains the actual component and does not store data that can be rendered using toString we can't use the original createCell method)
 *
 * @param value the new value object
 * @param row row number, -1 for the header rows
 * @param column column number
 * @param editable true if the cell is editable
 * @return cell component instance
 */
protected Component createCell(Object value, int row, int column, boolean editable) {
    Component cmp = null;
    if (value instanceof Component) {
        cmp = (Component) value;
    // TODO - table cells styling - needs to propogate downwards since the cell is usually a container, on the other hand can't wipe out the style of the container's components - TBD
    // boolean isHeader=((HTMLTableModel)getModel()).isHeader(value);
    // if (isHeader) {
    // cmp.setUIID("TableHeader");
    // } else {
    // cmp.setUIID("TableCell");
    // }
    } else {
        cmp = super.createCell(value, row, column, editable);
    }
    cmp.setFocusable(false);
    return cmp;
}
Also used : Component(com.codename1.ui.Component)

Example 67 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class BorderLayout method layoutContainer.

/**
 * {@inheritDoc}
 */
public void layoutContainer(Container target) {
    Style s = target.getStyle();
    int top = s.getPaddingTop();
    int bottom = target.getLayoutHeight() - target.getBottomGap() - s.getPaddingBottom();
    int left = s.getPaddingLeft(target.isRTL());
    int right = target.getLayoutWidth() - target.getSideGap() - s.getPaddingRight(target.isRTL());
    int targetWidth = target.getWidth();
    int targetHeight = target.getHeight();
    boolean rtl = target.isRTL();
    if (rtl) {
        left += target.getSideGap();
    }
    Component east = getEast();
    Component west = getWest();
    Component south = getSouth();
    Component north = getNorth();
    Component center = getCenter();
    if (north != null) {
        Component c = north;
        positionTopBottom(target, c, right, left, targetHeight);
        c.setY(top + c.getStyle().getMarginTop());
        top += (c.getHeight() + c.getStyle().getMarginTop() + c.getStyle().getMarginBottom());
    }
    if (south != null) {
        Component c = south;
        positionTopBottom(target, c, right, left, targetHeight);
        c.setY(bottom - c.getHeight() - c.getStyle().getMarginBottom());
        bottom -= (c.getHeight() + c.getStyle().getMarginTop() + c.getStyle().getMarginBottom());
    }
    Component realEast = east;
    Component realWest = west;
    if (rtl) {
        realEast = west;
        realWest = east;
    }
    if (realEast != null) {
        Component c = realEast;
        positionLeftRight(realEast, targetWidth, bottom, top);
        c.setX(right - c.getWidth() - c.getStyle().getMarginRight(rtl));
        right -= (c.getWidth() + c.getStyle().getHorizontalMargins());
    }
    if (realWest != null) {
        Component c = realWest;
        positionLeftRight(realWest, targetWidth, bottom, top);
        c.setX(left + c.getStyle().getMarginLeft(rtl));
        left += (c.getWidth() + c.getStyle().getMarginLeftNoRTL() + c.getStyle().getMarginRightNoRTL());
    }
    if (center != null) {
        Component c = center;
        int w = right - left - c.getStyle().getMarginLeftNoRTL() - c.getStyle().getMarginRightNoRTL();
        int h = bottom - top - c.getStyle().getMarginTop() - c.getStyle().getMarginBottom();
        int x = left + c.getStyle().getMarginLeft(rtl);
        int y = top + c.getStyle().getMarginTop();
        switch(centerBehavior) {
            case CENTER_BEHAVIOR_CENTER_ABSOLUTE:
                {
                    Dimension d = c.getPreferredSize();
                    if (d.getWidth() < w) {
                        int newX = (s.getPaddingLeft(rtl) - s.getPaddingRight(rtl)) + targetWidth / 2 - d.getWidth() / 2;
                        if (newX > x) {
                            x = newX;
                        }
                        w = d.getWidth();
                    }
                    int append = 0;
                    int th = targetHeight;
                    if (north != null) {
                        append = north.getHeight();
                        th -= append;
                    }
                    if (south != null) {
                        th -= south.getHeight();
                        append += south.getHeight();
                    }
                    if (d.getHeight() < h) {
                        int newY = (s.getPaddingTop() + th) / 2 - d.getHeight() / 2 + append;
                        if (newY > y) {
                            y = newY;
                        }
                        h = d.getHeight();
                    }
                    break;
                }
            case CENTER_BEHAVIOR_CENTER:
                {
                    Dimension d = c.getPreferredSize();
                    if (d.getWidth() < w) {
                        x += w / 2 - d.getWidth() / 2;
                        w = d.getWidth();
                    }
                    if (d.getHeight() < h) {
                        y += h / 2 - d.getHeight() / 2;
                        h = d.getHeight();
                    }
                    break;
                }
            case CENTER_BEHAVIOR_TOTAL_BELOW:
                {
                    w = targetWidth;
                    h = targetHeight;
                    x = s.getPaddingLeft(rtl);
                    y = s.getPaddingTop();
                    ;
                }
        }
        c.setWidth(w);
        c.setHeight(h);
        c.setX(x);
        c.setY(y);
    }
    if (overlay != null) {
        Component c = overlay;
        c.setWidth(targetWidth);
        c.setHeight(targetHeight);
        c.setX(0);
        c.setY(0);
    }
}
Also used : Style(com.codename1.ui.plaf.Style) Component(com.codename1.ui.Component)

Example 68 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class LayeredLayout method getPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getPreferredSize(Container parent) {
    int maxWidth = 0;
    int maxHeight = 0;
    int numOfcomponents = parent.getComponentCount();
    tmpLaidOut.clear();
    for (int i = 0; i < numOfcomponents; i++) {
        Component cmp = parent.getComponentAt(i);
        calcPreferredValues(cmp);
        LayeredLayoutConstraint constraint = (LayeredLayoutConstraint) getComponentConstraint(cmp);
        int vInsets = 0;
        int hInsets = 0;
        if (constraint != null) {
            vInsets += constraint.insets[Component.TOP].preferredValue + constraint.insets[Component.BOTTOM].preferredValue;
            hInsets += constraint.insets[Component.LEFT].preferredValue + constraint.insets[Component.RIGHT].preferredValue;
        }
        maxHeight = Math.max(maxHeight, cmp.getPreferredH() + cmp.getStyle().getMarginTop() + cmp.getStyle().getMarginBottom() + vInsets);
        maxWidth = Math.max(maxWidth, cmp.getPreferredW() + cmp.getStyle().getMarginLeftNoRTL() + cmp.getStyle().getMarginRightNoRTL() + hInsets);
    }
    Style s = parent.getStyle();
    Dimension d = new Dimension(maxWidth + s.getPaddingLeftNoRTL() + s.getPaddingRightNoRTL(), maxHeight + s.getPaddingTop() + s.getPaddingBottom());
    if (preferredWidthMM > 0) {
        int minW = Display.getInstance().convertToPixels(preferredWidthMM);
        if (d.getWidth() < minW) {
            d.setWidth(minW);
        }
    }
    if (preferredHeightMM > 0) {
        int minH = Display.getInstance().convertToPixels(preferredHeightMM);
        if (d.getHeight() < Display.getInstance().convertToPixels(preferredHeightMM)) {
            d.setHeight(minH);
        }
    }
    return d;
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension) Component(com.codename1.ui.Component)

Example 69 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class LayeredLayout method layoutComponent.

/**
 * Lays out the specific component within the container.  This will first lay out any components that it depends on.
 * @param parent The parent container being laid out.
 * @param cmp The component being laid out.
 * @param top
 * @param left
 * @param bottom
 * @param right
 */
private void layoutComponent(Container parent, Component cmp, int top, int left, int bottom, int right) {
    if (tmpLaidOut.contains(cmp)) {
        return;
    }
    tmpLaidOut.add(cmp);
    LayeredLayoutConstraint constraint = (LayeredLayoutConstraint) getComponentConstraint(cmp);
    if (constraint != null) {
        constraint.fixDependencies(parent);
        for (LayeredLayoutConstraint.Inset inset : constraint.insets) {
            if (inset.referenceComponent != null && inset.referenceComponent.getParent() == parent) {
                layoutComponent(parent, inset.referenceComponent, top, left, bottom, right);
            }
        }
    }
    Style s = cmp.getStyle();
    if (constraint != null) {
        // int innerTop = top;
        // int innerBottom = bottom;
        // left = 0;
        // right = parent.getLayoutWidth();
        int leftInset = constraint.insets[Component.LEFT].calculate(cmp, top, left, bottom, right);
        int rightInset = constraint.insets[Component.RIGHT].calculate(cmp, top, left, bottom, right);
        int topInset = constraint.insets[Component.TOP].calculate(cmp, top, left, bottom, right);
        int bottomInset = constraint.insets[Component.BOTTOM].calculate(cmp, top, left, bottom, right);
        cmp.setX(left + leftInset + s.getMarginLeft(parent.isRTL()));
        cmp.setY(top + topInset + s.getMarginTop());
        cmp.setWidth(Math.max(0, right - cmp.getX() - s.getMarginRight(parent.isRTL()) - rightInset));
        // cmp.setWidth(Math.max(0, right - left - s.getHorizontalMargins() - rightInset - leftInset));
        // cmp.setHeight(Math.max(0, bottom - top - s.getVerticalMargins() - bottomInset - topInset));
        cmp.setHeight(Math.max(0, bottom - cmp.getY() - s.getMarginBottom() - bottomInset));
    } else {
        int x = left + s.getMarginLeft(parent.isRTL());
        int y = top + s.getMarginTop();
        int w = right - left - s.getHorizontalMargins();
        int h = bottom - top - s.getVerticalMargins();
        cmp.setX(x);
        cmp.setY(y);
        cmp.setWidth(Math.max(0, w));
        cmp.setHeight(Math.max(0, h));
    // System.out.println("Component laid out "+cmp);
    }
}
Also used : Inset(com.codename1.ui.layouts.LayeredLayout.LayeredLayoutConstraint.Inset) Style(com.codename1.ui.plaf.Style)

Example 70 with Style

use of com.codename1.ui.plaf.Style in project CodenameOne by codenameone.

the class OnOffSwitch method paint.

/**
 * {@inheritDoc}
 */
public void paint(Graphics g) {
    if (iosMode) {
        int switchButtonPadInt = UIManager.getInstance().getThemeConstant("switchButtonPadInt", 16);
        if (Display.getInstance().getDisplayWidth() > 480) {
            // is retina
            switchButtonPadInt *= 2;
        }
        Style s = getStyle();
        int x = getX() + s.getPaddingLeftNoRTL();
        int y = getY() + s.getPaddingTop();
        if (!value) {
            if (deltaX > 0) {
                dragged = false;
            } else {
                if (deltaX < -switchOnImage.getWidth()) {
                    deltaX = -switchOnImage.getWidth();
                }
            }
        } else {
            if (deltaX < 0) {
                dragged = false;
            } else {
                if (deltaX > switchOnImage.getWidth()) {
                    deltaX = switchOnImage.getWidth();
                }
            }
        }
        if (dragged) {
            int onX;
            int offX;
            if (value) {
                onX = x - deltaX;
                offX = x - deltaX + switchOnImage.getWidth() - 2 * switchButtonPadInt;
            } else {
                onX = x - deltaX - switchOnImage.getWidth() + 2 * switchButtonPadInt;
                offX = x - deltaX;
            }
            switchButtonPadInt /= 2;
            int oldClipX = g.getClipX();
            int oldClipY = g.getClipY();
            int oldClipW = g.getClipWidth();
            int oldClipH = g.getClipHeight();
            g.clipRect(getX(), getY(), switchMaskImage.getWidth(), switchMaskImage.getHeight());
            g.drawImage(switchOnImage, onX, y);
            g.drawImage(switchOffImage, offX, y);
            int strWidth = s.getFont().stringWidth(on);
            int sX = onX + switchMaskImage.getWidth() / 2 - strWidth / 2 - switchButtonPadInt;
            int sY = y + switchMaskImage.getHeight() / 2 - s.getFont().getHeight() / 2;
            g.setFont(s.getFont());
            g.setColor(0xffffff);
            if (!noTextMode) {
                g.drawString(on, sX, sY, Style.TEXT_DECORATION_3D);
            }
            strWidth = s.getFont().stringWidth(off);
            g.setColor(0x333333);
            sX = offX + switchMaskImage.getWidth() / 2 - strWidth / 2 + switchButtonPadInt;
            if (!noTextMode) {
                g.drawString(off, sX, sY);
            }
            g.setClip(oldClipX, oldClipY, oldClipW, oldClipH);
        } else {
            String str;
            switchButtonPadInt /= 2;
            if (value) {
                g.drawImage(switchOnImage, x, y);
                str = on;
                g.setColor(0xffffff);
                switchButtonPadInt *= -1;
            } else {
                g.drawImage(switchOffImage, x, y);
                str = off;
                g.setColor(0x333333);
            }
            int strWidth = s.getFont().stringWidth(str);
            int sX = x + switchMaskImage.getWidth() / 2 - strWidth / 2 + switchButtonPadInt;
            int sY = y + switchMaskImage.getHeight() / 2 - s.getFont().getHeight() / 2;
            g.setFont(s.getFont());
            if (!noTextMode) {
                g.drawString(str, sX, sY);
            }
        }
        g.drawImage(switchMaskImage, x, y);
    } else {
        super.paint(g);
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Aggregations

Style (com.codename1.ui.plaf.Style)103 Dimension (com.codename1.ui.geom.Dimension)28 Component (com.codename1.ui.Component)25 Image (com.codename1.ui.Image)20 Rectangle (com.codename1.ui.geom.Rectangle)13 Container (com.codename1.ui.Container)11 Font (com.codename1.ui.Font)11 FontImage (com.codename1.ui.FontImage)11 Border (com.codename1.ui.plaf.Border)8 Form (com.codename1.ui.Form)6 Label (com.codename1.ui.Label)6 ActionEvent (com.codename1.ui.events.ActionEvent)6 IOException (java.io.IOException)6 UIManager (com.codename1.ui.plaf.UIManager)5 Vector (java.util.Vector)5 Dialog (com.codename1.ui.Dialog)4 EncodedImage (com.codename1.ui.EncodedImage)4 Graphics (com.codename1.ui.Graphics)4 TextArea (com.codename1.ui.TextArea)4 SpanButton (com.codename1.components.SpanButton)3