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;
}
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);
}
}
}
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);
}
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;
}
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;
}
Aggregations