Search in sources :

Example 21 with Container

use of com.codename1.ui.Container 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 22 with Container

use of com.codename1.ui.Container 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 23 with Container

use of com.codename1.ui.Container 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 24 with Container

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

the class InstantUI method createEditUI.

/**
 * Creates editing UI for the given business object
 * @param bo the business object
 * @param autoCommit true if the bindings used should be auto-committed
 * @return a UI container that can be used to edit the business object
 */
public Container createEditUI(PropertyBusinessObject bo, boolean autoCommit) {
    Container cnt;
    if (Display.getInstance().isTablet()) {
        TableLayout tl = new TableLayout(1, 2);
        tl.setGrowHorizontally(true);
        cnt = new Container(tl);
    } else {
        cnt = new Container(BoxLayout.y());
    }
    UiBinding uib = new UiBinding();
    ArrayList<UiBinding.Binding> allBindings = new ArrayList<UiBinding.Binding>();
    for (PropertyBase b : bo.getPropertyIndex()) {
        if (isExcludedProperty(b)) {
            continue;
        }
        Class cls = (Class) b.getClientProperty("cn1$cmpCls");
        if (cls != null) {
            try {
                Component cmp = (Component) cls.newInstance();
                cmp.setName(b.getName());
                cnt.add(b.getLabel()).add(cmp);
                allBindings.add(uib.bind(b, cmp));
            } catch (Exception err) {
                Log.e(err);
                throw new RuntimeException("Custom property instant UI failed for " + b.getName() + " " + err);
            }
            continue;
        }
        String[] multiLabels = (String[]) b.getClientProperty("cn1$multiChceLbl");
        if (multiLabels != null) {
            // multi choice component
            final Object[] multiValues = (Object[]) b.getClientProperty("cn1$multiChceVal");
            if (multiLabels.length < 5) {
                // toggle buttons
                ButtonGroup bg = new ButtonGroup();
                RadioButton[] rbs = new RadioButton[multiLabels.length];
                cnt.add(b.getLabel());
                Container radioBox = new Container(new GridLayout(multiLabels.length));
                for (int iter = 0; iter < multiLabels.length; iter++) {
                    rbs[iter] = RadioButton.createToggle(multiLabels[iter], bg);
                    radioBox.add(rbs[iter]);
                }
                cnt.add(radioBox);
                allBindings.add(uib.bindGroup(b, multiValues, rbs));
            } else {
                Picker stringPicker = new Picker();
                stringPicker.setStrings(multiLabels);
                Map<Object, Object> m1 = new HashMap<Object, Object>();
                Map<Object, Object> m2 = new HashMap<Object, Object>();
                for (int iter = 0; iter < multiLabels.length; iter++) {
                    m1.put(multiLabels[iter], multiValues[iter]);
                    m2.put(multiValues[iter], multiLabels[iter]);
                }
                cnt.add(b.getLabel()).add(stringPicker);
                allBindings.add(uib.bind(b, stringPicker, new UiBinding.PickerAdapter<Object>(new UiBinding.MappingConverter(m1), new UiBinding.MappingConverter(m2))));
            }
            continue;
        }
        Class t = b.getGenericType();
        if (t != null) {
            if (t == Boolean.class) {
                CheckBox cb = new CheckBox();
                uib.bind(b, cb);
                cnt.add(b.getLabel()).add(cb);
                continue;
            }
            if (t == Date.class) {
                Picker dp = new Picker();
                dp.setType(Display.PICKER_TYPE_DATE);
                uib.bind(b, dp);
                cnt.add(b.getLabel()).add(dp);
                continue;
            }
        }
        TextField tf = new TextField();
        tf.setConstraint(getTextFieldConstraint(b));
        uib.bind(b, tf);
        cnt.add(b.getLabel()).add(tf);
    }
    cnt.putClientProperty("cn1$iui-binding", uib.createGroupBinding(allBindings));
    return cnt;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Container(com.codename1.ui.Container) GridLayout(com.codename1.ui.layouts.GridLayout) Picker(com.codename1.ui.spinner.Picker) TextField(com.codename1.ui.TextField) Component(com.codename1.ui.Component) TableLayout(com.codename1.ui.table.TableLayout) RadioButton(com.codename1.ui.RadioButton) ButtonGroup(com.codename1.ui.ButtonGroup) CheckBox(com.codename1.ui.CheckBox)

Example 25 with Container

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

the class UIBuilderOverride method createInstance.

/**
 * Create a component instance from XML
 */
public Container createInstance(ComponentEntry root, EditableResources res) {
    ArrayList<Runnable> postCreateTasks = new ArrayList<Runnable>();
    Container c = (Container) createInstance(root, res, null, null, postCreateTasks);
    // execute tasks that must have the entire hierarchy constructed in order to work
    for (Runnable r : postCreateTasks) {
        r.run();
    }
    return c;
}
Also used : Container(com.codename1.ui.Container) ArrayList(java.util.ArrayList)

Aggregations

Container (com.codename1.ui.Container)85 Component (com.codename1.ui.Component)65 BorderLayout (com.codename1.ui.layouts.BorderLayout)46 Style (com.codename1.ui.plaf.Style)38 ActionEvent (com.codename1.ui.events.ActionEvent)29 Form (com.codename1.ui.Form)26 Label (com.codename1.ui.Label)21 BoxLayout (com.codename1.ui.layouts.BoxLayout)21 Dimension (com.codename1.ui.geom.Dimension)20 ActionListener (com.codename1.ui.events.ActionListener)19 Button (com.codename1.ui.Button)15 FlowLayout (com.codename1.ui.layouts.FlowLayout)15 ArrayList (java.util.ArrayList)14 LayeredLayout (com.codename1.ui.layouts.LayeredLayout)12 TextArea (com.codename1.ui.TextArea)11 Point (com.codename1.ui.geom.Point)11 Rectangle (com.codename1.ui.geom.Rectangle)11 Dialog (com.codename1.ui.Dialog)10 RadioButton (com.codename1.ui.RadioButton)10 Vector (java.util.Vector)9