use of com.codename1.db.Row in project CodenameOne by codenameone.
the class FlowLayout method fillRow.
/**
* This method tries to fill up the available space in a row.
* This method is called if isFillRows() returns true.
*
* @param target the parent container
* @param width the width of the row to fill
* @param start the index of the first component in this row
* @param end the index of the last component in this row
*/
protected void fillRow(Container target, int width, int start, int end) {
int available = width;
for (int iter = start; iter < end; iter++) {
Component c = target.getComponentAt(iter);
available -= (c.getWidth() + c.getStyle().getMarginRightNoRTL() + c.getStyle().getMarginLeftNoRTL());
}
if (available > 0 && end - start > 0) {
int perComponent = available / (end - start);
int lastComponent = perComponent + available % (end - start);
if (perComponent > 0) {
int addOffset = 0;
boolean rtl = target.isRTL();
for (int iter = start; iter < end - 1; iter++) {
Component c = target.getComponentAt(iter);
c.setWidth(c.getWidth() + perComponent);
if (rtl) {
addOffset += perComponent;
c.setX(c.getX() - addOffset);
} else {
c.setX(c.getX() + addOffset);
addOffset += perComponent;
}
}
Component c = target.getComponentAt(end - 1);
if (rtl) {
addOffset += lastComponent;
c.setX(c.getX() - addOffset);
} else {
c.setX(c.getX() + addOffset);
}
c.setWidth(c.getWidth() + lastComponent);
} else {
Component c = target.getComponentAt(end - 1);
c.setWidth(c.getWidth() + lastComponent);
}
}
}
use of com.codename1.db.Row in project CodenameOne by codenameone.
the class HTMLTable method createCell.
/**
* This method is overriden to return the component that is contained in the HTMLTableModel
* (Since our model contains the actual component and does not store data that can be rendered using toString we can't use the original createCell method)
*
* @param value the new value object
* @param row row number, -1 for the header rows
* @param column column number
* @param editable true if the cell is editable
* @return cell component instance
*/
protected Component createCell(Object value, int row, int column, boolean editable) {
Component cmp = null;
if (value instanceof Component) {
cmp = (Component) value;
// TODO - table cells styling - needs to propogate downwards since the cell is usually a container, on the other hand can't wipe out the style of the container's components - TBD
// boolean isHeader=((HTMLTableModel)getModel()).isHeader(value);
// if (isHeader) {
// cmp.setUIID("TableHeader");
// } else {
// cmp.setUIID("TableCell");
// }
} else {
cmp = super.createCell(value, row, column, editable);
}
cmp.setFocusable(false);
return cmp;
}
use of com.codename1.db.Row in project CodenameOne by codenameone.
the class HTMLTable method createCellConstraint.
/**
* This method is overriden to fetch the constraints from the associated HTMLTableModel and converts it to TableLayout.Constraint
*
* @param value the value of the cell
* @param row the table row
* @param column the table column
* @return the table constraint
*/
protected Constraint createCellConstraint(Object value, int row, int column) {
CellConstraint cConstraint = ((HTMLTableModel) getModel()).getConstraint(value);
if (cConstraint == null) {
// Can be null for cells that were "spanned over"
return super.createCellConstraint(value, row, column);
}
Constraint constraint = new Constraint();
constraint.setHorizontalAlign(cConstraint.align);
constraint.setVerticalAlign(cConstraint.valign);
constraint.setHorizontalSpan(cConstraint.spanHorizontal);
constraint.setVerticalSpan(cConstraint.spanVertical);
constraint.setWidthPercentage(cConstraint.width);
constraint.setHeightPercentage(cConstraint.height);
return constraint;
}
use of com.codename1.db.Row in project CodenameOne by codenameone.
the class MultiButton method setInvertFirstTwoEntries.
/**
* Inverts the order of the first two entries so the second line appears first.
* This only works in horizontal mode!
*
* @param b true to place the second row entry as the first entry
*/
public void setInvertFirstTwoEntries(boolean b) {
if (b != invert) {
invert = b;
if (isHorizontalLayout()) {
Container c = firstRow.getParent();
c.removeComponent(secondRow);
if (invert) {
c.addComponent(BorderLayout.WEST, secondRow);
} else {
c.addComponent(BorderLayout.EAST, secondRow);
}
}
}
}
use of com.codename1.db.Row in project CodenameOne by codenameone.
the class GridLayout method layoutContainer.
/**
* {@inheritDoc}
*/
public void layoutContainer(Container parent) {
Style s = parent.getStyle();
int width = parent.getLayoutWidth() - parent.getSideGap() - s.getHorizontalPadding();
int height = parent.getLayoutHeight() - parent.getBottomGap() - s.getVerticalPadding();
int numOfcomponents = parent.getComponentCount();
boolean landscapeMode = isLandscapeMode();
autoSizeCols(parent, width, landscapeMode);
int rows, columns;
if (landscapeMode) {
rows = landscapeRows;
columns = landscapeColumns;
} else {
rows = portraitRows;
columns = portraitColumns;
}
int x = s.getPaddingLeft(parent.isRTL());
int y = s.getPaddingTop();
boolean rtl = parent.isRTL();
if (rtl) {
x += parent.getSideGap();
}
int localColumns = columns;
int cmpWidth = width / columns;
int cmpHeight;
if (numOfcomponents > rows * columns) {
// actual rows number
cmpHeight = height / (numOfcomponents / columns + (numOfcomponents % columns == 0 ? 0 : 1));
} else {
cmpHeight = height / rows;
}
int row = 0;
int offset = 0;
for (int iter = 0; iter < numOfcomponents; iter++) {
Component cmp = parent.getComponentAt(iter);
Style cmpStyle = cmp.getStyle();
int marginLeft = cmpStyle.getMarginLeft(parent.isRTL());
int marginTop = cmpStyle.getMarginTop();
if (hideZeroSized) {
if (cmp.isHidden()) {
continue;
}
}
cmp.setWidth(cmpWidth - marginLeft - cmpStyle.getMarginRight(parent.isRTL()));
cmp.setHeight(cmpHeight - marginTop - cmpStyle.getMarginBottom());
if (rtl) {
cmp.setX(x + (localColumns - 1 - (offset % localColumns)) * cmpWidth + marginLeft);
} else {
cmp.setX(x + (offset % localColumns) * cmpWidth + marginLeft);
}
cmp.setY(y + row * cmpHeight + marginTop);
if ((offset + 1) % columns == 0) {
row++;
// check if we need to recalculate component widths
if (fillLastRow && row == rows - 1) {
localColumns = numOfcomponents % columns;
if (localColumns == 0) {
localColumns = columns;
}
cmpWidth = width / localColumns;
}
}
offset++;
}
}
Aggregations