Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Fauth2016-11-24 22:46:03 +0000
committerDirk Fauth2016-11-24 22:46:03 +0000
commitb05cb2eeff9bce170e344c1194131eda666e74d5 (patch)
treec8fcad06858c474948ad328ec5aba284b257d468
parent534b99c17968a54085e5a5af7a67c4cafa5b3130 (diff)
downloadorg.eclipse.nebula.widgets.nattable-b05cb2eeff9bce170e344c1194131eda666e74d5.tar.gz
org.eclipse.nebula.widgets.nattable-b05cb2eeff9bce170e344c1194131eda666e74d5.tar.xz
org.eclipse.nebula.widgets.nattable-b05cb2eeff9bce170e344c1194131eda666e74d5.zip
Bug 508152 - [Scaling] Inconsistent behavior for programmatically
setting cell dimensions Change-Id: Iddd209a4a83e6525bc63c5a5586a0ab303d85fd7 Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
-rw-r--r--org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfigScalingTest.java44
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/DataLayer.java4
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfig.java12
-rw-r--r--org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/mode/ColumnResizeDragMode.java16
-rwxr-xr-xorg.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/mode/RowResizeDragMode.java34
5 files changed, 57 insertions, 53 deletions
diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfigScalingTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfigScalingTest.java
index 0e38e1ae..b1c50e6b 100644
--- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfigScalingTest.java
+++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfigScalingTest.java
@@ -45,8 +45,8 @@ public class SizeConfigScalingTest {
@Test
public void sizeOverride() throws Exception {
this.sizeConfig.setSize(5, 120);
-
- assertEquals(120, this.sizeConfig.getSize(5));
+ // width of 120 pixels is upscaled to 180
+ assertEquals(180, this.sizeConfig.getSize(5));
}
@Test
@@ -55,9 +55,11 @@ public class SizeConfigScalingTest {
this.sizeConfig.setSize(0, 10);
// rounding issue with downscaling and upscaling
- assertEquals(11, this.sizeConfig.getAggregateSize(1));
- assertEquals(611, this.sizeConfig.getAggregateSize(5));
- assertEquals(1331, this.sizeConfig.getAggregateSize(10));
+ assertEquals(15, this.sizeConfig.getAggregateSize(1));
+ // 10 + 400 + 120
+ assertEquals(795, this.sizeConfig.getAggregateSize(6));
+ // 10 + 800 + 120
+ assertEquals(1395, this.sizeConfig.getAggregateSize(10));
}
@Test
@@ -66,7 +68,7 @@ public class SizeConfigScalingTest {
this.sizeConfig.setPositionResizable(2, true);
this.sizeConfig.setSize(2, 120);
- assertEquals(420, this.sizeConfig.getAggregateSize(3));
+ assertEquals(480, this.sizeConfig.getAggregateSize(3));
}
@Test
@@ -102,7 +104,7 @@ public class SizeConfigScalingTest {
sc.setSize(1, 30);
// use global default for 3rd and 4th position
- assertEquals(210, sc.getAggregateSize(4));
+ assertEquals(240, sc.getAggregateSize(4));
}
@Test
@@ -120,13 +122,16 @@ public class SizeConfigScalingTest {
sc.setSize(0, 30);
sc.setSize(1, 30);
- sc.setDefaultSize(0, 10); // must not be considered as there is a size
+ // must not be considered as there is a size
// set on 1st position
- sc.setDefaultSize(2, 10); // must be considered as there is no size
+ sc.setDefaultSize(0, 10);
+ // must be considered as there is no size
// setting on 3rd position
+ sc.setDefaultSize(2, 10);
// use global default for 4th position
- assertEquals(150, sc.getAggregateSize(4));
+ // 30 + 30 + 10 + 50
+ assertEquals(180, sc.getAggregateSize(4));
}
@Test
@@ -142,16 +147,17 @@ public class SizeConfigScalingTest {
});
+ assertEquals(750, sc.getAggregateSize(5));
sc.setSize(0, 75);
- assertEquals(675, sc.getAggregateSize(5));
+ assertEquals(713, sc.getAggregateSize(5));
sc.setSize(1, 75);
- assertEquals(600, sc.getAggregateSize(5));
+ assertEquals(676, sc.getAggregateSize(5));
sc.setSize(2, 75);
- assertEquals(525, sc.getAggregateSize(5));
+ assertEquals(639, sc.getAggregateSize(5));
sc.setDefaultSize(75);
- assertEquals(451, sc.getAggregateSize(5));
+ assertEquals(565, sc.getAggregateSize(5));
sc.setSize(2, 100);
- assertEquals(477, sc.getAggregateSize(5));
+ assertEquals(602, sc.getAggregateSize(5));
}
@Test
@@ -191,9 +197,9 @@ public class SizeConfigScalingTest {
});
- sc.setSize(0, 127);
- sc.setSize(1, 127);
- sc.setSize(2, 127);
+ sc.setSize(0, 102);
+ sc.setSize(1, 102);
+ sc.setSize(2, 102);
assertEquals(128, sc.getSize(0));
assertEquals(128, sc.getSize(1));
@@ -216,7 +222,7 @@ public class SizeConfigScalingTest {
});
// results because of scaling in 223
- sc.setSize(1, 222);
+ sc.setSize(1, 178);
assertEquals(128, sc.getSize(0));
assertEquals(223, sc.getSize(1));
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/DataLayer.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/DataLayer.java
index c3981124..e58fe648 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/DataLayer.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/DataLayer.java
@@ -482,13 +482,13 @@ public class DataLayer extends AbstractLayer implements IUniqueIndexLayer {
boolean refresh = false;
if (isColumnPercentageSizing()) {
this.columnWidthConfig.calculatePercentages(
- clientAreaResizeCommand.getCalcArea().width,
+ this.columnWidthConfig.downScale(clientAreaResizeCommand.getCalcArea().width),
getColumnCount());
refresh = true;
}
if (isRowPercentageSizing()) {
this.rowHeightConfig.calculatePercentages(
- clientAreaResizeCommand.getCalcArea().height,
+ this.rowHeightConfig.downScale(clientAreaResizeCommand.getCalcArea().height),
getRowCount());
refresh = true;
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfig.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfig.java
index 5a03fcde..8185ed32 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfig.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/layer/SizeConfig.java
@@ -259,11 +259,11 @@ public class SizeConfig implements IPersistable {
size = this.realSizeMap.get(position);
} else {
if (this.sizeMap.containsKey(position)) {
- size = upScale(this.sizeMap.get(position));
+ size = this.sizeMap.get(position);
}
}
if (size != null) {
- return size.intValue();
+ return upScale(size.intValue());
} else {
return upScale(getDefaultSize(position));
}
@@ -295,7 +295,7 @@ public class SizeConfig implements IPersistable {
// check whether the given value should be remembered as is or if it
// needs to be calculated
if (!isPercentageSizing(position)) {
- this.sizeMap.put(position, downScale(size));
+ this.sizeMap.put(position, size);
} else {
if (this.availableSpace > 0) {
Double percentage = ((double) size * 100) / this.availableSpace;
@@ -725,7 +725,7 @@ public class SizeConfig implements IPersistable {
if (resizedPosition.intValue() < position) {
resizedColumns++;
int size = mapToUse.get(resizedPosition);
- resizeAggregate += isPercentageSizing() ? size : upScale(size);
+ resizeAggregate += upScale(size);
} else {
break;
}
@@ -737,14 +737,14 @@ public class SizeConfig implements IPersistable {
if (!mapToUse.containsKey(defaultPosition)) {
resizedColumns++;
int size = this.defaultSizeMap.get(defaultPosition);
- resizeAggregate += isPercentageSizing() ? size : upScale(size);
+ resizeAggregate += upScale(size);
}
} else {
break;
}
}
- int result = (position - resizedColumns) * (isPercentageSizing() ? this.defaultSize : upScale(this.defaultSize));
+ int result = (position - resizedColumns) * upScale(this.defaultSize);
result += resizeAggregate;
return result;
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/mode/ColumnResizeDragMode.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/mode/ColumnResizeDragMode.java
index 9083275e..2595ee99 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/mode/ColumnResizeDragMode.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/mode/ColumnResizeDragMode.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2014, 2015 Original authors and others.
+ * Copyright (c) 2012, 2016 Original authors and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -51,10 +51,8 @@ public class ColumnResizeDragMode implements IDragMode {
this.columnPositionToResize =
CellEdgeDetectUtil.getColumnPositionToResize(natTable, new Point(event.x, event.y));
if (this.columnPositionToResize >= 0) {
- this.gridColumnStartX =
- natTable.getStartXOfColumnPosition(this.columnPositionToResize);
- this.originalColumnWidth =
- natTable.getColumnWidthByPosition(this.columnPositionToResize);
+ this.gridColumnStartX = natTable.getStartXOfColumnPosition(this.columnPositionToResize);
+ this.originalColumnWidth = natTable.getColumnWidthByPosition(this.columnPositionToResize);
this.startX = event.x;
natTable.addOverlayPainter(this.overlayPainter);
}
@@ -70,8 +68,7 @@ public class ColumnResizeDragMode implements IDragMode {
if (this.checkMinimumWidth
&& this.currentX < this.gridColumnStartX + getColumnWidthMinimum()) {
this.currentX = this.gridColumnStartX + getColumnWidthMinimum();
- }
- else {
+ } else {
int overlayExtent = ColumnResizeOverlayPainter.COLUMN_RESIZE_OVERLAY_WIDTH / 2;
Set<Integer> columnsToRepaint = new HashSet<Integer>();
@@ -107,7 +104,10 @@ public class ColumnResizeDragMode implements IDragMode {
newColumnWidth = getColumnWidthMinimum();
}
natLayer.doCommand(
- new ColumnResizeCommand(natLayer, this.columnPositionToResize, newColumnWidth));
+ new ColumnResizeCommand(
+ natLayer,
+ this.columnPositionToResize,
+ GUIHelper.convertVerticalDpiToPixel(newColumnWidth)));
}
// XXX: This method must ask the layer what it's minimum width is!
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/mode/RowResizeDragMode.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/mode/RowResizeDragMode.java
index f804886b..29d4b83e 100755
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/mode/RowResizeDragMode.java
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/resize/mode/RowResizeDragMode.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2014 Original authors and others.
+ * Copyright (c) 2012, 2016 Original authors and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -47,13 +47,11 @@ public class RowResizeDragMode implements IDragMode {
@Override
public void mouseDown(NatTable natTable, MouseEvent event) {
natTable.forceFocus();
- this.gridRowPositionToResize = CellEdgeDetectUtil.getRowPositionToResize(
- natTable, new Point(event.x, event.y));
+ this.gridRowPositionToResize =
+ CellEdgeDetectUtil.getRowPositionToResize(natTable, new Point(event.x, event.y));
if (this.gridRowPositionToResize > 0) {
- this.gridRowStartY = natTable
- .getStartYOfRowPosition(this.gridRowPositionToResize);
- this.originalRowHeight = natTable
- .getRowHeightByPosition(this.gridRowPositionToResize);
+ this.gridRowStartY = natTable.getStartYOfRowPosition(this.gridRowPositionToResize);
+ this.originalRowHeight = natTable.getRowHeightByPosition(this.gridRowPositionToResize);
this.startY = event.y;
natTable.addOverlayPainter(this.overlayPainter);
}
@@ -74,16 +72,12 @@ public class RowResizeDragMode implements IDragMode {
Set<Integer> rowsToRepaint = new HashSet<Integer>();
- rowsToRepaint.add(Integer.valueOf(natTable
- .getRowPositionByY(this.currentY - overlayExtent)));
- rowsToRepaint.add(Integer.valueOf(natTable
- .getRowPositionByY(this.currentY + overlayExtent)));
+ rowsToRepaint.add(natTable.getRowPositionByY(this.currentY - overlayExtent));
+ rowsToRepaint.add(natTable.getRowPositionByY(this.currentY + overlayExtent));
if (this.lastY >= 0) {
- rowsToRepaint.add(Integer.valueOf(natTable
- .getRowPositionByY(this.lastY - overlayExtent)));
- rowsToRepaint.add(Integer.valueOf(natTable
- .getRowPositionByY(this.lastY + overlayExtent)));
+ rowsToRepaint.add(natTable.getRowPositionByY(this.lastY - overlayExtent));
+ rowsToRepaint.add(natTable.getRowPositionByY(this.lastY + overlayExtent));
}
for (Integer rowToRepaint : rowsToRepaint) {
@@ -103,10 +97,14 @@ public class RowResizeDragMode implements IDragMode {
private void updateRowHeight(ILayer natLayer, MouseEvent e) {
int dragHeight = e.y - this.startY;
int newRowHeight = this.originalRowHeight + dragHeight;
- if (newRowHeight < getRowHeightMinimum())
+ if (newRowHeight < getRowHeightMinimum()) {
newRowHeight = getRowHeightMinimum();
- natLayer.doCommand(new RowResizeCommand(natLayer,
- this.gridRowPositionToResize, newRowHeight));
+ }
+ natLayer.doCommand(
+ new RowResizeCommand(
+ natLayer,
+ this.gridRowPositionToResize,
+ GUIHelper.convertHorizontalDpiToPixel(newRowHeight)));
}
// XXX: should ask the layer for its minimum row height

Back to the top