Search in sources :

Example 1 with Grid

use of com.codename1.ui.layouts.mig.Grid in project CodenameOne by codenameone.

the class MigLayout method checkCache.

/**
 * Check if something has changed and if so recreate it to the cached
 * objects.
 *
 * @param parent The parent that is the target for this layout manager.
 */
private void checkCache(Container parent) {
    if (parent == null) {
        return;
    }
    if (dirty) {
        grid = null;
    }
    cleanConstraintMaps(parent);
    // Check if the grid is valid
    int mc = PlatformDefaults.getModCount();
    if (lastModCount != mc) {
        grid = null;
        lastModCount = mc;
    }
    // if (!parent.isValid()) {
    if (!lastWasInvalid) {
        lastWasInvalid = true;
        int hash = 0;
        // Added in 3.7.3 to resolve a timing regression introduced in 3.7.1
        boolean resetLastInvalidOnParent = false;
        for (ComponentWrapper wrapper : ccMap.keySet()) {
            Object component = wrapper.getComponent();
            if (component instanceof TextArea) {
                resetLastInvalidOnParent = true;
            }
            hash ^= wrapper.getLayoutHashCode();
            hash += 285134905;
        }
        if (resetLastInvalidOnParent) {
            resetLastInvalidOnParent(parent);
        }
        if (hash != lastHash) {
            grid = null;
            lastHash = hash;
        }
        Dimension ps = new Dimension(parent.getWidth(), parent.getHeight());
        if (lastInvalidSize == null || !lastInvalidSize.equals(ps)) {
            grid = null;
            lastInvalidSize = ps;
        }
    }
    /*} else {
         lastWasInvalid = false;
         }*/
    ContainerWrapper par = checkParent(parent);
    setDebug(par, getDebugMillis() > 0);
    if (grid == null) {
        grid = new Grid(par, lc, rowSpecs, colSpecs, ccMap, callbackList);
    }
    dirty = false;
}
Also used : TextArea(com.codename1.ui.TextArea) Grid(com.codename1.ui.layouts.mig.Grid) Dimension(com.codename1.ui.geom.Dimension) ContainerWrapper(com.codename1.ui.layouts.mig.ContainerWrapper) ComponentWrapper(com.codename1.ui.layouts.mig.ComponentWrapper)

Example 2 with Grid

use of com.codename1.ui.layouts.mig.Grid 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 3 with Grid

use of com.codename1.ui.layouts.mig.Grid 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)

Example 4 with Grid

use of com.codename1.ui.layouts.mig.Grid in project CodenameOne by codenameone.

the class DefaultCrashReporter method exception.

/**
 * {@inheritDoc}
 */
public void exception(Throwable t) {
    Preferences.set("$CN1_pendingCrash", true);
    if (promptUser) {
        Dialog error = new Dialog("Error");
        error.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        TextArea txt = new TextArea(errorText);
        txt.setEditable(false);
        txt.setUIID("DialogBody");
        error.addComponent(txt);
        CheckBox cb = new CheckBox(checkboxText);
        cb.setUIID("DialogBody");
        error.addComponent(cb);
        Container grid = new Container(new GridLayout(1, 2));
        error.addComponent(grid);
        Command ok = new Command(sendButtonText);
        Command dont = new Command(dontSendButtonText);
        Button send = new Button(ok);
        Button dontSend = new Button(dont);
        grid.addComponent(send);
        grid.addComponent(dontSend);
        Command result = error.showPacked(BorderLayout.CENTER, true);
        if (result == dont) {
            if (cb.isSelected()) {
                Preferences.set("$CN1_crashBlocked", true);
            }
            Preferences.set("$CN1_pendingCrash", false);
            return;
        } else {
            if (cb.isSelected()) {
                Preferences.set("$CN1_prompt", false);
            }
        }
    }
    Log.sendLog();
    Preferences.set("$CN1_pendingCrash", false);
}
Also used : Container(com.codename1.ui.Container) GridLayout(com.codename1.ui.layouts.GridLayout) TextArea(com.codename1.ui.TextArea) Command(com.codename1.ui.Command) Button(com.codename1.ui.Button) Dialog(com.codename1.ui.Dialog) CheckBox(com.codename1.ui.CheckBox) BoxLayout(com.codename1.ui.layouts.BoxLayout)

Example 5 with Grid

use of com.codename1.ui.layouts.mig.Grid in project CodenameOne by codenameone.

the class GridBagLayoutInfo method calculateComponentBounds.

private void calculateComponentBounds(ComponentSide horSide, ComponentSide vertSide, Rectangle r, Grid grid) {
    Rectangle dispArea = grid.componentDisplayArea(horSide, vertSide);
    r.setWidth(fillDisplaySide(dispArea.getWidth(), horSide));
    r.setHeight(fillDisplaySide(dispArea.getHeight(), vertSide));
    r.setX(anchorComponentSide(dispArea.getX(), dispArea.getWidth(), horSide, r.getWidth()));
    r.setY(anchorComponentSide(dispArea.getY(), dispArea.getHeight(), vertSide, r.getHeight()));
}
Also used : Rectangle(com.codename1.ui.geom.Rectangle)

Aggregations

Style (com.codename1.ui.plaf.Style)3 TextArea (com.codename1.ui.TextArea)2 Dimension (com.codename1.ui.geom.Dimension)2 Rectangle (com.codename1.ui.geom.Rectangle)2 Button (com.codename1.ui.Button)1 CheckBox (com.codename1.ui.CheckBox)1 Command (com.codename1.ui.Command)1 Container (com.codename1.ui.Container)1 Dialog (com.codename1.ui.Dialog)1 BoxLayout (com.codename1.ui.layouts.BoxLayout)1 GridLayout (com.codename1.ui.layouts.GridLayout)1 ComponentWrapper (com.codename1.ui.layouts.mig.ComponentWrapper)1 ContainerWrapper (com.codename1.ui.layouts.mig.ContainerWrapper)1 Grid (com.codename1.ui.layouts.mig.Grid)1