Search in sources :

Example 31 with Component

use of com.codename1.ui.Component 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 32 with Component

use of com.codename1.ui.Component 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 33 with Component

use of com.codename1.ui.Component in project CodenameOne by codenameone.

the class MigLayout method cleanConstraintMaps.

/**
 * Checks so all components in ccMap actually exist in the parent's
 * collection. Removes any references that don't.
 *
 * @param parent The parent to compare ccMap against. Never null.
 */
private void cleanConstraintMaps(Container parent) {
    HashSet<Component> parentCompSet = new HashSet<Component>();
    for (int iter = 0; iter < parent.getComponentCount(); iter++) {
        parentCompSet.add(parent.getComponentAt(iter));
    }
    Iterator<Map.Entry<ComponentWrapper, CC>> it = ccMap.entrySet().iterator();
    while (it.hasNext()) {
        Component c = (Component) it.next().getKey().getComponent();
        if (parentCompSet.contains(c) == false) {
            it.remove();
            scrConstrMap.remove(c);
        }
    }
}
Also used : Component(com.codename1.ui.Component) HashSet(java.util.HashSet)

Example 34 with Component

use of com.codename1.ui.Component in project CodenameOne by codenameone.

the class MigLayout method setConstraintMap.

/**
 * Sets the constraints map.
 *
 * @param map The map. Will be copied.
 */
public void setConstraintMap(Map<Component, Object> map) {
    scrConstrMap.clear();
    ccMap.clear();
    for (Component e : map.keySet()) {
        setComponentConstraintsImpl(e, map.get(e), true);
    }
}
Also used : Component(com.codename1.ui.Component)

Example 35 with Component

use of com.codename1.ui.Component in project CodenameOne by codenameone.

the class DefaultListCellRenderer method getCellRendererComponent.

/**
 * {@inheritDoc}
 */
public Component getCellRendererComponent(Component list, Object model, T value, int index, boolean isSelected) {
    if (!alwaysRenderSelection && !Display.getInstance().shouldRenderSelection(list)) {
        isSelected = false;
    }
    setFocus(isSelected);
    if (showNumbers) {
        String text = "" + value;
        Map<String, String> t = UIManager.getInstance().getBundle();
        if (t != null && value != null) {
            Object o = t.get(value.toString());
            if (o != null) {
                text = (String) o;
            }
        }
        if (isRTL()) {
            setText(text + " ." + (index + 1));
        } else {
            setText("" + (index + 1) + ". " + text);
        }
    } else {
        if (value != null) {
            String v = value.toString();
            setText(v);
            if (isRightAlignNumbers()) {
                char c = v.charAt(0);
                Style s = getStyle();
                if (c >= '0' && c <= '9') {
                    s.setAlignment(RIGHT);
                } else {
                    s.setAlignment(LEFT);
                }
            }
        } else {
            setText("null");
        }
    }
    if (value instanceof Command) {
        setIcon(((Command) value).getIcon());
        setEnabled(((Command) value).isEnabled());
    }
    return this;
}
Also used : Command(com.codename1.ui.Command) Style(com.codename1.ui.plaf.Style)

Aggregations

Component (com.codename1.ui.Component)152 Style (com.codename1.ui.plaf.Style)61 Container (com.codename1.ui.Container)55 Form (com.codename1.ui.Form)41 BorderLayout (com.codename1.ui.layouts.BorderLayout)40 TextArea (com.codename1.ui.TextArea)31 ActionEvent (com.codename1.ui.events.ActionEvent)28 Dimension (com.codename1.ui.geom.Dimension)28 Label (com.codename1.ui.Label)25 Point (com.codename1.ui.geom.Point)22 ArrayList (java.util.ArrayList)22 Rectangle (com.codename1.ui.geom.Rectangle)21 Vector (java.util.Vector)18 Button (com.codename1.ui.Button)16 Dialog (com.codename1.ui.Dialog)16 Hashtable (java.util.Hashtable)16 Image (com.codename1.ui.Image)15 TextField (com.codename1.ui.TextField)15 ActionListener (com.codename1.ui.events.ActionListener)13 BoxLayout (com.codename1.ui.layouts.BoxLayout)13