use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class CoordinateLayout method getPreferredSize.
/**
* {@inheritDoc}
*/
public Dimension getPreferredSize(Container parent) {
Dimension retVal = new Dimension();
int numOfcomponents = parent.getComponentCount();
for (int i = 0; i < numOfcomponents; i++) {
Component cmp = parent.getComponentAt(i);
retVal.setWidth(Math.max(retVal.getWidth(), cmp.getX() + cmp.getPreferredW()));
retVal.setHeight(Math.max(retVal.getHeight(), cmp.getY() + cmp.getPreferredH()));
}
return retVal;
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class GridLayout method getPreferredSize.
/**
* {@inheritDoc}
*/
public Dimension getPreferredSize(Container parent) {
int width = 0;
int height = 0;
int numOfcomponents = parent.getComponentCount();
for (int i = 0; i < numOfcomponents; i++) {
Component cmp = parent.getComponentAt(i);
width = Math.max(width, cmp.getPreferredW() + cmp.getStyle().getMarginLeftNoRTL() + cmp.getStyle().getMarginRightNoRTL());
height = Math.max(height, cmp.getPreferredH() + cmp.getStyle().getMarginTop() + cmp.getStyle().getMarginBottom());
}
boolean landscapeMode = isLandscapeMode();
autoSizeCols(parent, parent.getWidth(), landscapeMode);
int rows, columns;
if (landscapeMode) {
rows = landscapeRows;
columns = landscapeColumns;
} else {
rows = portraitRows;
columns = portraitColumns;
}
if (columns > 1) {
width = width * columns;
}
if (rows > 1) {
if (numOfcomponents > rows * columns) {
// if there are more components than planned
height = height * (numOfcomponents / columns + (numOfcomponents % columns == 0 ? 0 : 1));
} else {
height = height * rows;
}
}
Style s = parent.getStyle();
return new Dimension(width + s.getHorizontalPadding(), height + s.getVerticalPadding());
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class GridBagLayoutInfo method initCompsArray.
private Dimension initCompsArray(Container parent, Component[] components) {
int maxW = 0;
int maxH = 0;
int i = 0;
for (Component comp : comptable.keySet()) {
GridBagConstraints cons = comptable.get(comp);
if ((comp.getParent() == parent) && comp.isVisible()) {
components[i++] = comp;
}
if ((cons.gridx != GridBagConstraints.RELATIVE) && (cons.gridy != GridBagConstraints.RELATIVE)) {
maxW = Math.max(maxW, cons.gridx + cons.gridwidth);
maxH = Math.max(maxH, cons.gridy + cons.gridheight);
}
}
return new Dimension(maxW, maxH);
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class GridBagLayoutInfo method validate.
private void validate(Container parent, ParentInfo info) {
if (info.valid) {
return;
}
info.valid = true;
resetCache(parent, info);
info.orientation = parent.isRTL();
Dimension maxSize = initCompsArray(parent, info.components);
new RelativeTranslator(maxSize.getWidth(), maxSize.getHeight()).translate(info);
initCompSides(info);
info.grid.validate(info);
if (layoutInfo == null) {
layoutInfo = new GridBagLayoutInfo(info.grid.lookupWidths(), info.grid.lookupHeights());
} else {
layoutInfo.update(info.grid.lookupWidths(), info.grid.lookupHeights());
}
}
use of com.codename1.ui.geom.Dimension in project CodenameOne by codenameone.
the class GroupLayout method layoutContainer.
/**
* Returns the minimum size for the specified container.
*
* @param parent the container to return size for
* @throws IllegalArgumentException if <code>parent</code> is not
* the same <code>Container</code> that this was created with
* @throws IllegalStateException if any of the components added to
* this layout are not in both a horizontal and vertical group
* @see java.awt.Container#getMinimumSize
*/
/*public Dimension minimumLayoutSize(Container parent) {
checkParent(parent);
prepare(MIN_SIZE);
return adjustSize(horizontalGroup.getMinimumSize(HORIZONTAL),
verticalGroup.getMinimumSize(VERTICAL));
}*/
/**
* Lays out the specified container.
*
* @param parent the container to be laid out
* @throws IllegalStateException if any of the components added to
* this layout are not in both a horizontal and vertical group
*/
public void layoutContainer(Container parent) {
// Step 1: Prepare for layout.
prepare(SPECIFIC_SIZE);
int insetLeft = parent.getStyle().getMarginLeftNoRTL();
int insetTop = parent.getStyle().getMarginTop();
int insetRight = parent.getStyle().getMarginRightNoRTL();
int insetBottom = parent.getStyle().getMarginBottom();
int width = parent.getWidth() - insetLeft - insetRight;
int height = parent.getHeight() - insetTop - insetBottom;
boolean ltr = isLeftToRight();
if (getAutocreateGaps() || getAutocreateContainerGaps() || hasPreferredPaddingSprings) {
// Step 2: Calculate autopadding springs
calculateAutopadding(horizontalGroup, HORIZONTAL, SPECIFIC_SIZE, 0, width);
calculateAutopadding(verticalGroup, VERTICAL, SPECIFIC_SIZE, 0, height);
}
// Step 3: set the size of the groups.
horizontalGroup.setSize(HORIZONTAL, 0, width);
verticalGroup.setSize(VERTICAL, 0, height);
// Step 4: apply the size to the components.
Iterator componentInfo = componentInfos.values().iterator();
while (componentInfo.hasNext()) {
ComponentInfo info = (ComponentInfo) componentInfo.next();
Component c = info.getComponent();
info.setBounds(insetLeft, insetTop, width, ltr);
}
}
Aggregations