use of com.codename1.ui.table.TableLayout in project CodenameOne by codenameone.
the class HTMLComponent method handleTableCell.
/**
* Handles a single table cell (a TD tag)
*
* @param tdTag The TD tag element
* @param align The current alignment
*/
private void handleTableCell(HTMLElement tdTag, int align) {
newLineIfNotEmpty(align);
tableCells.addElement(curContainer);
Container cell = new Container();
cell.getStyle().setBgTransparency(0);
cell.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
// int border=0;
HTMLElement trTag = (HTMLElement) tdTag.getParent();
while ((trTag != null) && (trTag.getTagId() != HTMLElement.TAG_TR)) {
// Though in strict XHTML TR can only contain TD/TH - in some HTMLs TR doesn't have to be the direct parent of the tdTag, i.e.: <tr><b><td>...</td>... </b></tr>
trTag = (HTMLElement) trTag.getParent();
}
// Commented since the table border should not affect cell border
/*if (trTag!=null) { // Null checks to prevent exceptions for a TD tag without table etc.
HTMLElement tableTag=(HTMLElement)trTag.getParent();
while ((tableTag!=null) && (tableTag.getTagId()!=HTMLElement.TAG_TABLE)) { // Though in strict XHTML TABLE can only contain TR - in some HTMLs it might be different
tableTag=(HTMLElement)tableTag.getParent();
}
if (tableTag!=null) {
border=getInt(tableTag.getAttributeById(HTMLElement.ATTR_BORDER));
}
}
cell.getUnselectedStyle().setPadding(border, border, border, border);
cell.getSelectedStyle().setPadding(border, border, border, border);*/
// Constraint constraint = new Constraint();
CellConstraint constraint = new CellConstraint();
int halign = align;
int valign = Component.CENTER;
if (trTag != null) {
HTMLElement tGroupTag = (HTMLElement) trTag.getParent();
int tagId = tGroupTag.getTagId();
if ((tagId == HTMLElement.TAG_TBODY) || (tagId == HTMLElement.TAG_THEAD) || (tagId == HTMLElement.TAG_TFOOT)) {
// Get the default TR alignment
halign = getHorizAlign(tGroupTag.getAttributeById(HTMLElement.ATTR_ALIGN), halign, false);
// Get the default TR valignment
valign = getVertAlign(tGroupTag.getAttributeById(HTMLElement.ATTR_VALIGN), valign);
}
// Get the default TR alignment
halign = getHorizAlign(trTag.getAttributeById(HTMLElement.ATTR_ALIGN), halign, false);
// Get the default TR valignment
valign = getVertAlign(trTag.getAttributeById(HTMLElement.ATTR_VALIGN), valign);
}
halign = getHorizAlign(tdTag.getAttributeById(HTMLElement.ATTR_ALIGN), halign, false);
valign = getVertAlign(tdTag.getAttributeById(HTMLElement.ATTR_VALIGN), valign);
int colspan = getInt(tdTag.getAttributeById(HTMLElement.ATTR_COLSPAN));
int rowspan = getInt(tdTag.getAttributeById(HTMLElement.ATTR_ROWSPAN));
String cWidth = tdTag.getAttributeById(HTMLElement.ATTR_WIDTH);
int pW = getPercentage(cWidth);
if ((pW > 0) && (pW < 100)) {
// constraint.setWidthPercentage(pW); //TODO - Setting a width constraint currently makes the field width 0 - needs to be fixed in TableLayout
} else {
pW = getInt(cWidth);
if (pW != 0) {
cell.setPreferredW(pW);
}
}
String cHeight = tdTag.getAttributeById(HTMLElement.ATTR_HEIGHT);
int pH = getPercentage(cHeight);
if ((pH > 0) && (pH < 100)) {
// constraint.setHeightPercentage(pH); //TODO - Setting a height constraint currently makes the field height 0 - needs to be fixed in TableLayout
} else {
pH = getInt(cHeight);
if (pH != 0) {
cell.setPreferredH(pH);
}
}
constraint.setHorizontalAlign(halign);
constraint.setVerticalAlign(valign);
if (colspan > 1) {
constraint.setHorizontalSpan(colspan);
}
if (rowspan > 1) {
constraint.setVerticalSpan(rowspan);
}
curContainer = cell;
if (curTable != null) {
curTable.addCell(cell, (tdTag.getTagId() == HTMLElement.TAG_TH), constraint);
}
if (loadCSS) {
tdTag.setAssociatedComponents(cell);
if (trTag != null) {
trTag.addAssociatedComponent(cell);
}
}
}
use of com.codename1.ui.table.TableLayout in project CodenameOne by codenameone.
the class LazyValueC method createComponent.
private Component createComponent(DataInputStream in, Container parent, Container root, Resources res, Hashtable componentListeners, EmbeddedContainer embedded) throws Exception {
String name = in.readUTF();
int property = in.readInt();
// special case for the base form
if (property == PROPERTY_BASE_FORM) {
String baseFormName = name;
initBaseForm(baseFormName);
if (!ignorBaseForm) {
Form base = (Form) createContainer(res, baseFormName);
Container destination = (Container) findByName("destination", base);
// try finding an appropriate empty container if no "fixed" destination is defined
if (destination == null) {
destination = findEmptyContainer(base.getContentPane());
if (destination == null) {
System.out.println("Couldn't find appropriate 'destination' container in base form: " + baseFormName);
return null;
}
}
root = base;
Component cmp = createComponent(in, destination, root, res, componentListeners, embedded);
if (destination.getLayout() instanceof BorderLayout) {
destination.addComponent(BorderLayout.CENTER, cmp);
} else {
destination.addComponent(cmp);
}
return root;
} else {
name = in.readUTF();
property = in.readInt();
}
}
Component cmp = createComponentType(name);
if (componentListeners != null) {
Object listeners = componentListeners.get(name);
if (listeners != null) {
if (listeners instanceof Vector) {
Vector v = (Vector) listeners;
for (int iter = 0; iter < v.size(); iter++) {
bindListenerToComponent(cmp, v.elementAt(iter));
}
} else {
bindListenerToComponent(cmp, listeners);
}
}
}
Component actualLead = cmp;
if (actualLead instanceof Container) {
Container cnt = (Container) actualLead;
actualLead = cnt.getLeadComponent();
if (actualLead == null) {
actualLead = cmp;
}
}
if (actualLead instanceof Button) {
ActionListener l = getFormListenerInstance(root, embedded);
if (l != null) {
((Button) actualLead).addActionListener(l);
}
} else {
if (actualLead instanceof TextArea) {
ActionListener l = getFormListenerInstance(root, embedded);
if (l != null) {
((TextArea) actualLead).addActionListener(l);
}
} else {
if (actualLead instanceof List) {
ActionListener l = getFormListenerInstance(root, embedded);
if (l != null) {
((List) actualLead).addActionListener(l);
}
} else {
if (actualLead instanceof ContainerList) {
ActionListener l = getFormListenerInstance(root, embedded);
if (l != null) {
((ContainerList) actualLead).addActionListener(l);
}
} else {
if (actualLead instanceof com.codename1.ui.Calendar) {
ActionListener l = getFormListenerInstance(root, embedded);
if (l != null) {
((com.codename1.ui.Calendar) actualLead).addActionListener(l);
}
}
}
}
}
}
cmp.putClientProperty(TYPE_KEY, name);
if (root == null) {
root = (Container) cmp;
}
while (property != -1) {
modifyingProperty(cmp, property);
switch(property) {
case PROPERTY_CUSTOM:
String customPropertyName = in.readUTF();
modifyingCustomProperty(cmp, customPropertyName);
boolean isNull = in.readBoolean();
if (isNull) {
cmp.setPropertyValue(customPropertyName, null);
break;
}
boolean cl = cmp instanceof ContainerList;
String[] propertyNames = cmp.getPropertyNames();
for (int iter = 0; iter < propertyNames.length; iter++) {
if (propertyNames[iter].equals(customPropertyName)) {
Class type = cmp.getPropertyTypes()[iter];
String[] typeNames = cmp.getPropertyTypeNames();
String typeName = null;
if (typeNames != null && typeNames.length > iter) {
typeName = typeNames[iter];
}
Object value = readCustomPropertyValue(in, type, typeName, res, propertyNames[iter]);
if (cl && customPropertyName.equals("ListItems") && setListModel((ContainerList) cmp)) {
break;
}
cmp.setPropertyValue(customPropertyName, value);
break;
}
}
break;
case PROPERTY_EMBED:
root.putClientProperty(EMBEDDED_FORM_FLAG, "");
((EmbeddedContainer) cmp).setEmbed(in.readUTF());
Container embed = createContainer(res, ((EmbeddedContainer) cmp).getEmbed(), (EmbeddedContainer) cmp);
if (embed != null) {
if (embed instanceof Form) {
embed = formToContainer((Form) embed);
}
((EmbeddedContainer) cmp).addComponent(BorderLayout.CENTER, embed);
// this isn't exactly the "right thing" but its the best we can do to make all
// use cases work
beforeShowContainer(embed);
postShowContainer(embed);
}
break;
case PROPERTY_TOGGLE_BUTTON:
((Button) cmp).setToggle(in.readBoolean());
break;
case PROPERTY_RADIO_GROUP:
((RadioButton) cmp).setGroup(in.readUTF());
break;
case PROPERTY_SELECTED:
boolean isSelected = in.readBoolean();
if (cmp instanceof RadioButton) {
((RadioButton) cmp).setSelected(isSelected);
} else {
((CheckBox) cmp).setSelected(isSelected);
}
break;
case PROPERTY_SCROLLABLE_X:
((Container) cmp).setScrollableX(in.readBoolean());
break;
case PROPERTY_SCROLLABLE_Y:
((Container) cmp).setScrollableY(in.readBoolean());
break;
case PROPERTY_TENSILE_DRAG_ENABLED:
cmp.setTensileDragEnabled(in.readBoolean());
break;
case PROPERTY_TACTILE_TOUCH:
cmp.setTactileTouch(in.readBoolean());
break;
case PROPERTY_SNAP_TO_GRID:
cmp.setSnapToGrid(in.readBoolean());
break;
case PROPERTY_FLATTEN:
cmp.setFlatten(in.readBoolean());
break;
case PROPERTY_TEXT:
if (cmp instanceof Label) {
((Label) cmp).setText(in.readUTF());
} else {
((TextArea) cmp).setText(in.readUTF());
}
break;
case PROPERTY_TEXT_MAX_LENGTH:
((TextArea) cmp).setMaxSize(in.readInt());
break;
case PROPERTY_TEXT_CONSTRAINT:
((TextArea) cmp).setConstraint(in.readInt());
if (cmp instanceof TextField) {
int cons = ((TextArea) cmp).getConstraint();
if ((cons & TextArea.NUMERIC) == TextArea.NUMERIC) {
((TextField) cmp).setInputModeOrder(new String[] { "123" });
}
}
break;
case PROPERTY_ALIGNMENT:
if (cmp instanceof Label) {
((Label) cmp).setAlignment(in.readInt());
} else {
((TextArea) cmp).setAlignment(in.readInt());
}
break;
case PROPERTY_TEXT_AREA_GROW:
((TextArea) cmp).setGrowByContent(in.readBoolean());
break;
case PROPERTY_LAYOUT:
Layout layout = null;
switch(in.readShort()) {
case LAYOUT_BORDER_LEGACY:
layout = new BorderLayout();
break;
case LAYOUT_BORDER_ANOTHER_LEGACY:
{
BorderLayout b = new BorderLayout();
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.NORTH, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.EAST, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.WEST, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.SOUTH, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.CENTER, in.readUTF());
}
layout = b;
break;
}
case LAYOUT_BORDER:
{
BorderLayout b = new BorderLayout();
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.NORTH, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.EAST, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.WEST, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.SOUTH, in.readUTF());
}
if (in.readBoolean()) {
b.defineLandscapeSwap(BorderLayout.CENTER, in.readUTF());
}
b.setAbsoluteCenter(in.readBoolean());
layout = b;
break;
}
case LAYOUT_BOX_X:
layout = new BoxLayout(BoxLayout.X_AXIS);
break;
case LAYOUT_BOX_Y:
layout = new BoxLayout(BoxLayout.Y_AXIS);
break;
case LAYOUT_FLOW_LEGACY:
layout = new FlowLayout();
break;
case LAYOUT_FLOW:
FlowLayout f = new FlowLayout();
f.setFillRows(in.readBoolean());
f.setAlign(in.readInt());
f.setValign(in.readInt());
layout = f;
break;
case LAYOUT_LAYERED:
layout = new LayeredLayout();
break;
case LAYOUT_GRID:
layout = new GridLayout(in.readInt(), in.readInt());
break;
case LAYOUT_TABLE:
layout = new TableLayout(in.readInt(), in.readInt());
break;
}
((Container) cmp).setLayout(layout);
break;
case PROPERTY_TAB_PLACEMENT:
((Tabs) cmp).setTabPlacement(in.readInt());
break;
case PROPERTY_TAB_TEXT_POSITION:
((Tabs) cmp).setTabTextPosition(in.readInt());
break;
case PROPERTY_PREFERRED_WIDTH:
cmp.setPreferredW(in.readInt());
break;
case PROPERTY_PREFERRED_HEIGHT:
cmp.setPreferredH(in.readInt());
break;
case PROPERTY_UIID:
cmp.setUIID(in.readUTF());
break;
case PROPERTY_DIALOG_UIID:
((Dialog) cmp).setDialogUIID(in.readUTF());
break;
case PROPERTY_DISPOSE_WHEN_POINTER_OUT:
((Dialog) cmp).setDisposeWhenPointerOutOfBounds(in.readBoolean());
break;
case PROPERTY_CLOUD_BOUND_PROPERTY:
cmp.setCloudBoundProperty(in.readUTF());
break;
case PROPERTY_CLOUD_DESTINATION_PROPERTY:
cmp.setCloudDestinationProperty(in.readUTF());
break;
case PROPERTY_DIALOG_POSITION:
String pos = in.readUTF();
if (pos.length() > 0) {
((Dialog) cmp).setDialogPosition(pos);
}
break;
case PROPERTY_FOCUSABLE:
cmp.setFocusable(in.readBoolean());
break;
case PROPERTY_ENABLED:
cmp.setEnabled(in.readBoolean());
break;
case PROPERTY_SCROLL_VISIBLE:
cmp.setScrollVisible(in.readBoolean());
break;
case PROPERTY_ICON:
((Label) cmp).setIcon(res.getImage(in.readUTF()));
break;
case PROPERTY_ROLLOVER_ICON:
((Button) cmp).setRolloverIcon(res.getImage(in.readUTF()));
break;
case PROPERTY_PRESSED_ICON:
((Button) cmp).setPressedIcon(res.getImage(in.readUTF()));
break;
case PROPERTY_DISABLED_ICON:
((Button) cmp).setDisabledIcon(res.getImage(in.readUTF()));
break;
case PROPERTY_GAP:
((Label) cmp).setGap(in.readInt());
break;
case PROPERTY_VERTICAL_ALIGNMENT:
if (cmp instanceof TextArea) {
((TextArea) cmp).setVerticalAlignment(in.readInt());
} else {
((Label) cmp).setVerticalAlignment(in.readInt());
}
break;
case PROPERTY_TEXT_POSITION:
((Label) cmp).setTextPosition(in.readInt());
break;
case PROPERTY_CLIENT_PROPERTIES:
int count = in.readInt();
StringBuilder sb = new StringBuilder();
for (int iter = 0; iter < count; iter++) {
String k = in.readUTF();
String v = in.readUTF();
cmp.putClientProperty(k, v);
sb.append(k);
if (iter < count - 1) {
sb.append(",");
}
}
cmp.putClientProperty("cn1$Properties", sb.toString());
break;
case PROPERTY_NAME:
String componentName = in.readUTF();
cmp.setName(componentName);
root.putClientProperty("%" + componentName + "%", cmp);
break;
case PROPERTY_LAYOUT_CONSTRAINT:
if (parent.getLayout() instanceof BorderLayout) {
cmp.putClientProperty("layoutConstraint", in.readUTF());
} else {
TableLayout tl = (TableLayout) parent.getLayout();
TableLayout.Constraint con = tl.createConstraint(in.readInt(), in.readInt());
con.setHeightPercentage(in.readInt());
con.setWidthPercentage(in.readInt());
con.setHorizontalAlign(in.readInt());
con.setHorizontalSpan(in.readInt());
con.setVerticalAlign(in.readInt());
con.setVerticalSpan(in.readInt());
cmp.putClientProperty("layoutConstraint", con);
}
break;
case PROPERTY_TITLE:
((Form) cmp).setTitle(in.readUTF());
break;
case PROPERTY_COMPONENTS:
int componentCount = in.readInt();
if (cmp instanceof Tabs) {
for (int iter = 0; iter < componentCount; iter++) {
String tab = in.readUTF();
Component child = createComponent(in, (Container) cmp, root, res, componentListeners, embedded);
((Tabs) cmp).addTab(tab, child);
}
} else {
for (int iter = 0; iter < componentCount; iter++) {
Component child = createComponent(in, (Container) cmp, root, res, componentListeners, embedded);
Object con = child.getClientProperty("layoutConstraint");
if (con != null) {
((Container) cmp).addComponent(con, child);
} else {
((Container) cmp).addComponent(child);
}
}
}
break;
case PROPERTY_COLUMNS:
((TextArea) cmp).setColumns(in.readInt());
break;
case PROPERTY_ROWS:
((TextArea) cmp).setRows(in.readInt());
break;
case PROPERTY_HINT:
if (cmp instanceof List) {
((List) cmp).setHint(in.readUTF());
} else {
((TextArea) cmp).setHint(in.readUTF());
}
break;
case PROPERTY_HINT_ICON:
if (cmp instanceof List) {
((List) cmp).setHintIcon(res.getImage(in.readUTF()));
} else {
((TextArea) cmp).setHintIcon(res.getImage(in.readUTF()));
}
break;
case PROPERTY_ITEM_GAP:
((List) cmp).setItemGap(in.readInt());
break;
case PROPERTY_LIST_FIXED:
((List) cmp).setFixedSelection(in.readInt());
break;
case PROPERTY_LIST_ORIENTATION:
((List) cmp).setOrientation(in.readInt());
break;
case PROPERTY_LIST_ITEMS_LEGACY:
String[] items = new String[in.readInt()];
for (int iter = 0; iter < items.length; iter++) {
items[iter] = in.readUTF();
}
if (!setListModel(((List) cmp))) {
((List) cmp).setModel(new DefaultListModel((Object[]) items));
}
break;
case PROPERTY_LIST_ITEMS:
Object[] elements = readObjectArrayForListModel(in, res);
if (!setListModel(((List) cmp))) {
((List) cmp).setModel(new DefaultListModel(elements));
}
break;
case PROPERTY_LIST_RENDERER:
if (cmp instanceof ContainerList) {
((ContainerList) cmp).setRenderer(readRendererer(res, in));
} else {
((List) cmp).setRenderer(readRendererer(res, in));
}
break;
case PROPERTY_NEXT_FORM:
String nextForm = in.readUTF();
setNextForm(cmp, nextForm, res, root);
break;
case PROPERTY_COMMANDS:
readCommands(in, cmp, res, false);
break;
case PROPERTY_COMMANDS_LEGACY:
readCommands(in, cmp, res, true);
break;
case PROPERTY_CYCLIC_FOCUS:
((Form) cmp).setCyclicFocus(in.readBoolean());
break;
case PROPERTY_RTL:
cmp.setRTL(in.readBoolean());
break;
case PROPERTY_SLIDER_THUMB:
((Slider) cmp).setThumbImage(res.getImage(in.readUTF()));
break;
case PROPERTY_INFINITE:
((Slider) cmp).setInfinite(in.readBoolean());
break;
case PROPERTY_PROGRESS:
((Slider) cmp).setProgress(in.readInt());
break;
case PROPERTY_VERTICAL:
((Slider) cmp).setVertical(in.readBoolean());
break;
case PROPERTY_EDITABLE:
if (cmp instanceof TextArea) {
((TextArea) cmp).setEditable(in.readBoolean());
} else {
((Slider) cmp).setEditable(in.readBoolean());
}
break;
case PROPERTY_INCREMENTS:
((Slider) cmp).setIncrements(in.readInt());
break;
case PROPERTY_RENDER_PERCENTAGE_ON_TOP:
((Slider) cmp).setRenderPercentageOnTop(in.readBoolean());
break;
case PROPERTY_MAX_VALUE:
((Slider) cmp).setMaxValue(in.readInt());
break;
case PROPERTY_MIN_VALUE:
((Slider) cmp).setMinValue(in.readInt());
break;
}
property = in.readInt();
}
postCreateComponent(cmp);
return cmp;
}
use of com.codename1.ui.table.TableLayout in project CodenameOne by codenameone.
the class Table method paintGlass.
/**
* {@inheritDoc}
*/
protected void paintGlass(Graphics g) {
if ((drawBorder) && (innerBorder != INNER_BORDERS_NONE)) {
int xPos = getAbsoluteX();
int yPos = getAbsoluteY();
g.translate(xPos, yPos);
int rows = model.getRowCount();
int cols = model.getColumnCount();
if (includeHeader) {
rows++;
}
g.setColor(getStyle().getFgColor());
TableLayout t = (TableLayout) getLayout();
int actualWidth = Math.max(getWidth(), getScrollDimension().getWidth());
int actualHeight = Math.max(getHeight(), getScrollDimension().getHeight());
if (// inner borders cols/rows are supported only in collapsed mode
(collapseBorder) || (innerBorder != INNER_BORDERS_ALL) || (t.hasHorizontalSpanning()) || (t.hasVerticalSpanning())) {
// TODO - We currently don't support separate borders for tables with spanned cells
if ((innerBorder == INNER_BORDERS_ALL) || (innerBorder == INNER_BORDERS_ROWS)) {
if (t.hasVerticalSpanning()) {
// the components other than the ones that are at the last column.
for (int cellRow = 0; cellRow < rows - 1; cellRow++) {
for (int cellColumn = 0; cellColumn < cols; cellColumn++) {
// if this isn't the last row
if (cellRow + t.getCellVerticalSpan(cellRow, cellColumn) - 1 != rows - 1) {
// if this is a spanned through cell we don't want to draw a line here
if (t.isCellSpannedThroughHorizontally(cellRow, cellColumn)) {
continue;
}
int x = t.getColumnPosition(cellColumn);
int y = t.getRowPosition(cellRow);
int rowHeight = t.getRowPosition(cellRow + t.getCellVerticalSpan(cellRow, cellColumn)) - y;
int columnWidth;
if (cellColumn < getModel().getColumnCount() - 1) {
columnWidth = t.getColumnPosition(cellColumn + 1) - x;
} else {
columnWidth = getWidth() - y;
}
if ((innerBorder != INNER_BORDERS_ROWS) || (shouldDrawInnerBorderAfterRow(cellRow))) {
g.drawLine(x, y + rowHeight, x + columnWidth, y + rowHeight);
}
}
}
}
} else {
// this is much faster since we don't need to check spanning
for (int row = 1; row < rows; row++) {
int y = t.getRowPosition(row);
if ((innerBorder != INNER_BORDERS_ROWS) || (shouldDrawInnerBorderAfterRow(row - 1))) {
g.drawLine(0, y, actualWidth, y);
}
// g.drawLine(0+2, y+2, actualWidth-2, y+2);
}
}
}
if ((innerBorder == INNER_BORDERS_ALL) || (innerBorder == INNER_BORDERS_COLS)) {
if (t.hasHorizontalSpanning()) {
// the components other than the ones that are at the last column.
for (int cellRow = 0; cellRow < rows; cellRow++) {
for (int cellColumn = 0; cellColumn < cols - 1; cellColumn++) {
// if this isn't the last column
if (cellColumn + t.getCellHorizontalSpan(cellRow, cellColumn) - 1 != cols - 1) {
// if this is a spanned through cell we don't want to draw a line here
if (t.isCellSpannedThroughVertically(cellRow, cellColumn)) {
continue;
}
int x = t.getColumnPosition(cellColumn);
int y = t.getRowPosition(cellRow);
int rowHeight;
int columnWidth = t.getColumnPosition(cellColumn + t.getCellHorizontalSpan(cellRow, cellColumn)) - x;
if (cellRow < getModel().getRowCount() - 1) {
rowHeight = t.getRowPosition(cellRow + 1) - y;
} else {
rowHeight = getHeight() - y;
}
g.drawLine(x + columnWidth, y, x + columnWidth, y + rowHeight);
}
if (t.getCellHorizontalSpan(cellRow, cellColumn) > 1) {
cellColumn += t.getCellHorizontalSpan(cellRow, cellColumn) - 1;
}
}
}
} else {
for (int col = 1; col < cols; col++) {
int x = t.getColumnPosition(col);
g.drawLine(x, 0, x, actualHeight);
// g.drawLine(x+2, 0+2, x+2, actualHeight-2);
}
}
}
} else {
// if ((!t.hasHorizontalSpanning()) && (!t.hasVerticalSpanning())) {
for (int row = 0; row < rows; row++) {
int y = t.getRowPosition(row);
int h;
if (row + 1 < rows) {
h = t.getRowPosition(row + 1) - y;
} else {
h = getY() + actualHeight - y - 2;
}
for (int col = 0; col < cols; col++) {
int x = t.getColumnPosition(col);
int w;
if (col + 1 < cols) {
w = t.getColumnPosition(col + 1) - x;
} else {
w = getX() + actualWidth - x - 2;
}
Component comp = t.getComponentAt(row, col);
if ((comp.isVisible()) && ((drawEmptyCellsBorder) || ((comp.getWidth() - comp.getStyle().getPaddingRightNoRTL() - comp.getStyle().getPaddingLeftNoRTL() > 0) && (comp.getHeight() - comp.getStyle().getPaddingTop() - comp.getStyle().getPaddingBottom() > 0)))) {
int rightMargin = comp.getStyle().getMarginRightNoRTL();
int bottomMargin = comp.getStyle().getMarginBottom();
if (col == 0) {
// Since the first cell includes margins from both sides (left/right) so the next cell location is farther away - but we don't want to paint the border up to it
rightMargin *= 2;
}
if (row == 0) {
bottomMargin *= 2;
}
g.drawRect(x + comp.getStyle().getMarginLeftNoRTL(), y + comp.getStyle().getMarginTop(), w - 2 - rightMargin, h - 2 - bottomMargin);
}
}
}
}
g.translate(-xPos, -yPos);
}
}
use of com.codename1.ui.table.TableLayout in project CodenameOne by codenameone.
the class Table method updateModel.
private void updateModel() {
int selectionRow = -1, selectionColumn = -1;
Form f = getComponentForm();
if (f != null) {
Component c = f.getFocused();
if (c != null) {
selectionRow = getCellRow(c);
selectionColumn = getCellColumn(c);
}
}
removeAll();
int columnCount = model.getColumnCount();
// another row for the table header
if (includeHeader) {
setLayout(new TableLayout(model.getRowCount() + 1, columnCount));
for (int iter = 0; iter < columnCount; iter++) {
String name = model.getColumnName(iter);
Component header = createCellImpl(name, -1, iter, false);
TableLayout.Constraint con = createCellConstraint(name, -1, iter);
addComponent(con, header);
}
} else {
setLayout(new TableLayout(model.getRowCount(), columnCount));
}
for (int r = 0; r < model.getRowCount(); r++) {
for (int c = 0; c < columnCount; c++) {
Object value = model.getValueAt(r, c);
// null should be returned for spanned over values
if (value != null || includeNullValues()) {
boolean e = model.isCellEditable(r, c);
Component cell = createCellImpl(value, r, c, e);
if (cell != null) {
TableLayout.Constraint con = createCellConstraint(value, r, c);
// returns the current row we iterate about
int currentRow = ((TableLayout) getLayout()).getNextRow();
if (r > model.getRowCount()) {
return;
}
addComponent(con, cell);
if (r == selectionRow && c == selectionColumn) {
cell.requestFocus();
}
}
}
}
}
}
use of com.codename1.ui.table.TableLayout in project CodenameOne by codenameone.
the class Table method updateMargins.
private void updateMargins() {
TableLayout t = (TableLayout) getLayout();
int hSpace = horizontalBorderSpacing;
int vSpace = verticalBorderSpacing;
if (collapseBorder) {
// not relevant for collapse border
hSpace = 0;
vSpace = 0;
}
if ((!t.hasHorizontalSpanning()) && (!t.hasVerticalSpanning())) {
for (int row = 0; row < t.getRows(); row++) {
for (int col = 0; col < t.getColumns(); col++) {
Component cmp = null;
try {
cmp = t.getComponentAt(row, col);
} catch (Exception e) {
// parent of cmp can be null as well - TODO - check why
}
if (cmp != null) {
int leftMargin = (col == 0) ? hSpace : 0;
int topMargin = (row == 0) ? vSpace : 0;
cmp.getUnselectedStyle().setMargin(topMargin, vSpace, leftMargin, hSpace);
cmp.getSelectedStyle().setMargin(topMargin, vSpace, leftMargin, hSpace);
}
}
}
}
repaint();
}
Aggregations