summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Alhroos <john.ahlroos@itmill.com>2011-08-02 14:28:31 +0000
committerJohn Alhroos <john.ahlroos@itmill.com>2011-08-02 14:28:31 +0000
commit2a65fd134dbb3e55452d3770343244e1afc2bbe9 (patch)
tree68e39fcbe21f89723fe1b17c28925da90677f643
parent5935d10d2c16db3f55b6ac3e237b884aab00ef15 (diff)
downloadvaadin-framework-2a65fd134dbb3e55452d3770343244e1afc2bbe9.tar.gz
vaadin-framework-2a65fd134dbb3e55452d3770343244e1afc2bbe9.zip
Improved the column calculation #6677
svn changeset:20085/svn branch:6.6
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java115
1 files changed, 87 insertions, 28 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
index 5961b5a344..cdf088c746 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
@@ -1615,40 +1615,78 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler,
final int totalWidthR = total - totalExplicitColumnsWidths;
needsReLayout = true;
- if (expandRatioDivider > 0) {
- // visible columns have some active expand ratios, excess
- // space is divided according to them
+ if (extraSpace == 1) {
+ // We cannot divide one single pixel so we give it the first
+ // undefined column
headCells = tHead.iterator();
i = 0;
while (headCells.hasNext()) {
- HeaderCell hCell = (HeaderCell) headCells.next();
- if (hCell.getExpandRatio() > 0) {
- int w = widths[i];
- final int newSpace = (int) (extraSpace * (hCell
- .getExpandRatio() / expandRatioDivider));
- w += newSpace;
- widths[i] = w;
+ HeaderCell hc = (HeaderCell) headCells.next();
+ if (!hc.isDefinedWidth()) {
+ widths[i]++;
+ break;
}
i++;
}
- } else if (totalWidthR > 0) {
- // no expand ratios defined, we will share extra space
- // relatively to "natural widths" among those without
- // explicit width
- headCells = tHead.iterator();
- i = 0;
- while (headCells.hasNext()) {
- HeaderCell hCell = (HeaderCell) headCells.next();
- if (!hCell.isDefinedWidth()) {
- int w = widths[i];
- final int newSpace = extraSpace * w / totalWidthR;
- w += newSpace;
- widths[i] = w;
+
+ } else if (expandRatioDivider > 0 || totalWidthR > 0) {
+ int checksum = 0;
+ if(expandRatioDivider > 0){
+ // visible columns have some active expand ratios, excess
+ // space is divided according to them
+ headCells = tHead.iterator();
+ i = 0;
+ checksum = 0;
+ while (headCells.hasNext()) {
+ HeaderCell hCell = (HeaderCell) headCells.next();
+ if (hCell.getExpandRatio() > 0) {
+ int w = widths[i];
+ final int newSpace = (int) (extraSpace * (hCell
+ .getExpandRatio() / expandRatioDivider));
+ w += newSpace;
+ widths[i] = w;
+ checksum += w;
+ }
+ i++;
+ }
+ } else {
+ // no expand ratios defined, we will share extra space
+ // relatively to "natural widths" among those without
+ // explicit width
+ headCells = tHead.iterator();
+ i = 0;
+ checksum = 0;
+ while (headCells.hasNext()) {
+ HeaderCell hCell = (HeaderCell) headCells.next();
+ if (!hCell.isDefinedWidth()) {
+ int w = widths[i];
+ final int newSpace = Math.round((float) extraSpace
+ * (float) w / totalWidthR);
+ w += newSpace;
+ widths[i] = w;
+ checksum += w;
+ }
+ i++;
+ }
+ }
+
+ if (checksum != availW) {
+ /*
+ * There might be in some cases a rounding error of 1px
+ * so if there is one then we give the first undefined column 1 more pixel
+ */
+ headCells = tHead.iterator();
+ i = 0;
+ while (headCells.hasNext()) {
+ HeaderCell hc = (HeaderCell) headCells.next();
+ if (!hc.isDefinedWidth()) {
+ widths[i] += availW - checksum;
+ break;
+ }
+ i++;
}
- i++;
}
}
-
} else {
// bodys size will be more than available and scrollbar will appear
}
@@ -4976,6 +5014,7 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler,
HeaderCell hCell;
colIndex = 0;
headCells = tHead.iterator();
+ int checksum = 0;
while (headCells.hasNext()) {
hCell = (HeaderCell) headCells.next();
if (!hCell.isDefinedWidth()) {
@@ -4983,21 +5022,41 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler,
int newSpace;
if (expandRatioDivider > 0) {
// divide excess space by expand ratios
- newSpace = (int) (w + extraSpace
+ newSpace = Math.round(w + extraSpace
* hCell.getExpandRatio() / expandRatioDivider);
} else {
if (totalUndefinedNaturaWidths != 0) {
// divide relatively to natural column widths
- newSpace = w + extraSpace * w
- / totalUndefinedNaturaWidths;
+ newSpace = Math.round(w + (float) extraSpace
+ * (float) w / totalUndefinedNaturaWidths);
} else {
newSpace = w;
}
}
+ checksum += newSpace;
setColWidth(colIndex, newSpace, false);
}
colIndex++;
}
+
+ if (checksum != availW) {
+ /*
+ * There might be in some cases a rounding error of 1px
+ * so if there is one then we give the first undefined column 1 more pixel
+ */
+ headCells = tHead.iterator();
+ colIndex = 0;
+ while (headCells.hasNext()) {
+ HeaderCell hc = (HeaderCell) headCells.next();
+ if (!hc.isDefinedWidth()) {
+ setColWidth(colIndex,
+ hc.getWidth() + availW - checksum, false);
+ break;
+ }
+ colIndex++;
+ }
+ }
+
if ((height == null || "".equals(height))
&& totalRows == pageLength) {
// fix body height (may vary if lazy loading is offhorizontal