Search in sources :

Example 16 with Style

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

the class TableLayout method layoutContainer.

/**
 * {@inheritDoc}
 */
public void layoutContainer(Container parent) {
    try {
        verticalSpanningExists = false;
        horizontalSpanningExists = false;
        // column and row size in pixels
        Style s = parent.getStyle();
        int top = s.getPaddingTop();
        int left = s.getPaddingLeft(parent.isRTL());
        int bottom = s.getPaddingBottom();
        int right = s.getPaddingRight(parent.isRTL());
        boolean rtl = parent.isRTL();
        columnSizes = new int[columns];
        if (modifableColumnSize == null || columns != modifableColumnSize.length) {
            modifableColumnSize = new boolean[columns];
        }
        columnPositions = new int[columns];
        int[] rowSizes = new int[rows];
        rowPositions = new int[rows];
        int pWidth = parent.getLayoutWidth() - parent.getSideGap() - left - right;
        int pHeight = parent.getLayoutHeight() - parent.getBottomGap() - top - bottom;
        int currentX = left;
        int availableReminder = pWidth;
        int cslen = columnSizes.length;
        for (int iter = 0; iter < cslen; iter++) {
            columnSizes[iter] = getColumnWidthPixels(iter, pWidth, availableReminder);
            availableReminder -= columnSizes[iter];
        }
        // so they are distributed sensibly if no room is available
        if (!parent.isScrollableX()) {
            int totalWidth = 0;
            int totalModifyablePixels = 0;
            // check how many columns we can modify (the user hasn't requested a specific size for those)
            for (int iter = 0; iter < modifableColumnSize.length; iter++) {
                if (modifableColumnSize[iter]) {
                    totalModifyablePixels += columnSizes[iter];
                }
                totalWidth += columnSizes[iter];
            }
            if (pWidth < totalWidth) {
                int totalPixelsToRemove = totalWidth - pWidth;
                int totalPixelsNecessary = totalModifyablePixels - totalPixelsToRemove;
                // Go over the modifyable columns and remove the right pixels according to the ratio
                for (int iter = 0; iter < modifableColumnSize.length; iter++) {
                    if (modifableColumnSize[iter]) {
                        columnSizes[iter] = (int) (((float) columnSizes[iter]) / ((float) totalModifyablePixels) * totalPixelsNecessary);
                    }
                }
            }
        }
        for (int iter = 0; iter < columnSizes.length; iter++) {
            if (rtl) {
                currentX += columnSizes[iter];
                columnPositions[iter] = pWidth - currentX;
            } else {
                columnPositions[iter] = currentX;
                currentX += columnSizes[iter];
            }
        }
        int currentY = top;
        int rlen = rowSizes.length;
        for (int iter = 0; iter < rlen; iter++) {
            if (parent.isScrollableY()) {
                rowSizes[iter] = getRowHeightPixels(iter, pHeight, -1);
            } else {
                rowSizes[iter] = getRowHeightPixels(iter, pHeight, pHeight - currentY + top);
            }
            rowPositions[iter] = currentY;
            currentY += rowSizes[iter];
        }
        int clen = columnSizes.length;
        for (int r = 0; r < rlen; r++) {
            for (int c = 0; c < clen; c++) {
                Constraint con = tablePositions[r * columns + c];
                int conX, conY, conW, conH;
                if (con != null && con != H_SPAN_CONSTRAINT && con != V_SPAN_CONSTRAINT && con != VH_SPAN_CONSTRAINT) {
                    Style componentStyle = con.parent.getStyle();
                    int leftMargin = componentStyle.getMarginLeft(parent.isRTL());
                    int topMargin = componentStyle.getMarginTop();
                    // conX = left + leftMargin + columnPositions[c]; // bugfix table with padding not drawn correctly
                    // conY = top + topMargin + rowPositions[r]; // bugfix table with padding not drawn correctly
                    conX = leftMargin + columnPositions[c];
                    conY = topMargin + rowPositions[r];
                    if (con.spanHorizontal > 1) {
                        horizontalSpanningExists = true;
                        int w = columnSizes[c];
                        for (int sh = 1; sh < con.spanHorizontal; sh++) {
                            w += columnSizes[Math.min(c + sh, columnSizes.length - 1)];
                        }
                        // for RTL we need to move the component to the side so spanning will work
                        if (rtl) {
                            conX = left + leftMargin + columnPositions[c + con.spanHorizontal - 1];
                        }
                        conW = w - leftMargin - componentStyle.getMarginLeft(parent.isRTL());
                    } else {
                        conW = columnSizes[c] - leftMargin - componentStyle.getMarginRight(parent.isRTL());
                    }
                    if (con.spanVertical > 1) {
                        verticalSpanningExists = true;
                        int h = rowSizes[r];
                        for (int sv = 1; sv < con.spanVertical; sv++) {
                            h += rowSizes[Math.min(r + sv, rowSizes.length - 1)];
                        }
                        conH = h - topMargin - componentStyle.getMarginBottom();
                    } else {
                        conH = rowSizes[r] - topMargin - componentStyle.getMarginBottom();
                    }
                    placeComponent(rtl, con, conX, conY, conW, conH);
                }
            }
        }
    } catch (ArrayIndexOutOfBoundsException err) {
        Log.e(err);
    }
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 17 with Style

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

the class TableLayout method getPreferredSize.

/**
 * {@inheritDoc}
 */
public Dimension getPreferredSize(Container parent) {
    Style s = parent.getStyle();
    int w = s.getPaddingLeftNoRTL() + s.getPaddingRightNoRTL();
    int h = s.getPaddingTop() + s.getPaddingBottom();
    int maxW = Display.getInstance().getDisplayWidth() * 2;
    int maxH = Display.getInstance().getDisplayHeight() * 2;
    for (int iter = 0; iter < columns; iter++) {
        w += getColumnWidthPixels(iter, maxW, -1);
    }
    for (int iter = 0; iter < rows; iter++) {
        h += getRowHeightPixels(iter, maxH, -1);
    }
    return new Dimension(w, h);
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

Example 18 with Style

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

the class UIManager method buildTheme.

private void buildTheme(Hashtable themeProps) {
    String con = (String) themeProps.get("@includeNativeBool");
    if (con != null && con.equalsIgnoreCase("true") && Display.getInstance().hasNativeTheme()) {
        boolean a = accessible;
        accessible = true;
        Display.getInstance().installNativeTheme();
        accessible = a;
    }
    Enumeration e = themeProps.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        // this is a constant not a theme entry
        if (key.startsWith("@")) {
            themeConstants.put(key.substring(1, key.length()), themeProps.get(key));
            continue;
        }
        this.themeProps.put(key, themeProps.get(key));
    }
    // necessary to clear up the style so we don't get resedue from the previous UI
    defaultStyle = new Style();
    // create's the default style
    defaultStyle = createStyle("", "", false);
    defaultSelectedStyle = new Style(defaultStyle);
    defaultSelectedStyle = createStyle("", "sel#", true);
    String overlayThemes = (String) themeProps.get("@OverlayThemes");
    if (overlayThemes != null) {
        java.util.List<String> overlayThemesArr = StringUtil.tokenize(overlayThemes, ',');
        for (String th : overlayThemesArr) {
            th = th.trim();
            if (th.length() == 0) {
                continue;
            }
            try {
                Resources res = Resources.openLayered("/" + th);
                boolean a = accessible;
                accessible = true;
                addThemeProps(res.getTheme(res.getThemeResourceNames()[0]));
                accessible = a;
            } catch (Exception ex) {
                System.err.println("Failed to load overlay theme file specified by @overlayThemes theme constant: " + th);
                Log.e(ex);
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) Resources(com.codename1.ui.util.Resources) IOException(java.io.IOException)

Example 19 with Style

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

the class MigLayout method layoutContainer.

public void layoutContainer(final Container parent) {
    checkCache(parent);
    Style i = parent.getStyle();
    int[] b = new int[] { i.getMarginLeftNoRTL(), i.getMarginTop(), parent.getWidth() - i.getHorizontalMargins(), parent.getHeight() - i.getVerticalMargins() };
    if (grid.layout(b, lc.getAlignX(), lc.getAlignY(), getDebug())) {
        grid = null;
        checkCache(parent);
        grid.layout(b, lc.getAlignX(), lc.getAlignY(), getDebug());
    }
    /*long newSize = grid.getHeight()[1] + (((long) grid.getWidth()[1]) << 32);
         if (lastSize != newSize) {
         lastSize = newSize;
         final ContainerWrapper containerWrapper = checkParent(parent);
         Window win = ((Window) SwingUtilities.getAncestorOfClass(Window.class, (Component)containerWrapper.getComponent()));
         if (win != null) {
         if (win.isVisible()) {
         SwingUtilities.invokeLater(new Runnable() {
         public void run() {
         adjustWindowSize(containerWrapper);
         }
         });
         } else {
         adjustWindowSize(containerWrapper);
         }
         }
         }*/
    lastInvalidSize = null;
}
Also used : Style(com.codename1.ui.plaf.Style)

Example 20 with Style

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

the class MigLayout method getSizeImpl.

// Implementation method that does the job.
private Dimension getSizeImpl(Container parent, int sizeType) {
    checkCache(parent);
    Style i = parent.getStyle();
    int w = LayoutUtil.getSizeSafe(grid != null ? grid.getWidth() : null, sizeType) + i.getHorizontalPadding();
    int h = LayoutUtil.getSizeSafe(grid != null ? grid.getHeight() : null, sizeType) + i.getVerticalPadding();
    return new Dimension(w, h);
}
Also used : Style(com.codename1.ui.plaf.Style) Dimension(com.codename1.ui.geom.Dimension)

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