fixing ScrollBarHandler for big data; use BigDecimal constants
diff --git a/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/impl/big/BigLayerExample.xtend b/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/impl/big/BigLayerExample.xtend
index e1acc42..24de2f8 100644
--- a/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/impl/big/BigLayerExample.xtend
+++ b/org.eclipse.nebula.widgets.nattable.core.example/src/org/eclipse/nebula/widgets/nattable/core/example/impl/big/BigLayerExample.xtend
@@ -20,6 +20,7 @@
override createLayer() {
val bodyLayer = new ViewportLayer(new DummyLayer(
+ // quadrillion, trillion, billion, million, thousand, hundred
new AxisImpl(10L * 1000 * 1000 * 1000 * 1000 * 1000, 200), // Horizontal axis
new AxisImpl(10L * 1000 * 1000 * 1000 * 1000 * 1000, 100) // Vertical axis
))
diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/core/layer/AxisTest.xtend b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/core/layer/AxisTest.xtend
index 7cf820f..44c13dd 100644
--- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/core/layer/AxisTest.xtend
+++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/core/layer/AxisTest.xtend
@@ -28,7 +28,7 @@
assertEquals('''«axisName» getStartPixelOfSegmentPosition(«segmentPosition»)''', expectedPixels.get(segmentPosition), axis.getStartPixelOfSegmentPosition(segmentPosition))
// Segment position of pixel location
- assertEquals('''«axisName» < range getSegmentPositionOfPixelLocation(«expectedPixels.get(0) - new BigDecimal(1)»)''', -1, axis.getSegmentPositionOfPixelLocation(expectedPixels.get(0) - new BigDecimal(1)))
+ assertEquals('''«axisName» < range getSegmentPositionOfPixelLocation(«expectedPixels.get(0) - BigDecimal::ONE»)''', -1, axis.getSegmentPositionOfPixelLocation(expectedPixels.get(0) - new BigDecimal(1)))
for (segmentPosition : 0 ..< expectedIds.size) {
val pixelLocation = expectedPixels.get(segmentPosition)
assertEquals('''«axisName» getSegmentPositionOfPixelLocation(«pixelLocation»)''', segmentPosition, axis.getSegmentPositionOfPixelLocation(pixelLocation))
diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/viewport/ViewportAxisTest.xtend b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/viewport/ViewportAxisTest.xtend
index 1d98d17..5bbd328 100644
--- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/viewport/ViewportAxisTest.xtend
+++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/viewport/ViewportAxisTest.xtend
@@ -47,11 +47,11 @@
@Test
def void beginningToBoundary() {
- // segment position: | 0 | 1 | 2 | 3 |
- // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
- // visible pixel range: |---------|
+ // segment position: | 0 | 1 | 2 | 3 |
+ // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
+ // visible pixel size: |---------|
viewportAxis.pixelOrigin = 0
- viewportAxis.visiblePixelRange = 5
+ viewportAxis.visiblePixelSize = 5
testAxis(
viewportAxis,
#[ 0L, 1L ],
@@ -61,12 +61,12 @@
@Test
def void boundaryToEnd() {
- // segment position: | 0 | 1 | 2 | 3 |
- // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
- // visible pixel range: |---------------------------------------------|
- // |0 1 2|3 4 5 6 7 8 9|0 1 2 3 4 5 6 7 8 9 0 1 2|
+ // segment position: | 0 | 1 | 2 | 3 |
+ // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
+ // visible pixel size: |---------------------------------------------|
+ // |0 1 2|3 4 5 6 7 8 9|0 1 2 3 4 5 6 7 8 9 0 1 2|
viewportAxis.pixelOrigin = 2
- viewportAxis.visiblePixelRange = 23
+ viewportAxis.visiblePixelSize = 23
testAxis(
viewportAxis,
#[ 1L, 2L, 3L ],
@@ -76,12 +76,12 @@
@Test
def void boundaryToBoundary() {
- // segment position: | 0 | 1 | 2 | 3 |
- // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
- // visible pixel range: |-------------------|
- // |0 1 2|3 4 5 6 7 8 9|
+ // segment position: | 0 | 1 | 2 | 3 |
+ // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
+ // visible pixel size: |-------------------|
+ // |0 1 2|3 4 5 6 7 8 9|
viewportAxis.pixelOrigin = 2
- viewportAxis.visiblePixelRange = 10
+ viewportAxis.visiblePixelSize = 10
testAxis(
viewportAxis,
#[ 1L, 2L ],
@@ -91,12 +91,12 @@
@Test
def void beginningToMidpoint() {
- // segment position: | 0 | 1 | 2 | 3 |
- // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
- // visible pixel range: |---------------|
- // |0 1|2 3 4|5 6 7 8 9 0 1|
+ // segment position: | 0 | 1 | 2 | 3 |
+ // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
+ // visible pixel size: |---------------|
+ // |0 1|2 3 4|5 6 7 8 9 0 1|
viewportAxis.pixelOrigin = 0
- viewportAxis.visiblePixelRange = 8
+ viewportAxis.visiblePixelSize = 8
testAxis(
viewportAxis,
#[ 0L, 1L, 2L ],
@@ -106,12 +106,12 @@
@Test
def void beforeMidpointToEnd() {
- // segment position: | 0 | 1 | 2 | 3 |
- // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
- // visible pixel range: |---------------------------------|
- // |3 2 1 0 1 2 3|4 5 6 7 8 9 0 1 2 3 4 5 6|
+ // segment position: | 0 | 1 | 2 | 3 |
+ // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
+ // visible pixel size: |---------------------------------|
+ // |3 2 1 0 1 2 3|4 5 6 7 8 9 0 1 2 3 4 5 6|
viewportAxis.pixelOrigin = 8
- viewportAxis.visiblePixelRange = 17
+ viewportAxis.visiblePixelSize = 17
testAxis(
viewportAxis,
#[ 2L, 3L ],
@@ -121,12 +121,12 @@
@Test
def void afterMidpointToEnd() {
- // segment position: | 0 | 1 | 2 | 3 |
- // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
- // visible pixel range: |-------------------|
- // |4 5 6 7 8 9 0 1 2 3 4 5 6|
+ // segment position: | 0 | 1 | 2 | 3 |
+ // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
+ // visible pixel size: |-------------------|
+ // |4 5 6 7 8 9 0 1 2 3 4 5 6|
viewportAxis.pixelOrigin = 17
- viewportAxis.visiblePixelRange = 10
+ viewportAxis.visiblePixelSize = 10
testAxis(
viewportAxis,
#[ 3L ],
@@ -136,12 +136,12 @@
@Test
def void midpointToMidpoint() {
- // segment position: | 0 | 1 | 2 | 3 |
- // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
- // visible pixel range: |-----------------------------|
- // |2 1 0|1 2 3 4 5 6 7|8 9 0 1 2 3 4 5 6 7 8 9 0|
+ // segment position: | 0 | 1 | 2 | 3 |
+ // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
+ // visible pixel size: |-----------------------------|
+ // |2 1 0|1 2 3 4 5 6 7|8 9 0 1 2 3 4 5 6 7 8 9 0|
viewportAxis.pixelOrigin = 4
- viewportAxis.visiblePixelRange = 15
+ viewportAxis.visiblePixelSize = 15
testAxis(
viewportAxis,
#[ 1L, 2L, 3L ],
@@ -151,12 +151,12 @@
@Test
def void expandRight() {
- // segment position: | 0 | 1 | 2 | 3 |
- // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
- // visible pixel range: |-------------|+++++|
- // |2 1 0|1 2 3 4 5 6 7|8 9 0 1 2 3 4 5 6 7 8 9 0|
+ // segment position: | 0 | 1 | 2 | 3 |
+ // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
+ // visible pixel size: |-------------|+++++|
+ // |2 1 0|1 2 3 4 5 6 7|8 9 0 1 2 3 4 5 6 7 8 9 0|
viewportAxis.pixelOrigin = 4
- viewportAxis.visiblePixelRange = 7
+ viewportAxis.visiblePixelSize = 7
testAxis(
"before expand",
viewportAxis,
@@ -164,11 +164,11 @@
#[ -2.0, 1.0, 8.0 ]
)
- // segment position: | 0 | 1 | 2 | 3 |
- // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
- // visible pixel range: |+++++++++++++++++++|
- // |2 1 0|1 2 3 4 5 6 7|8 9 0 1 2 3 4 5 6 7 8 9 0|
- viewportAxis.visiblePixelRange = 10
+ // segment position: | 0 | 1 | 2 | 3 |
+ // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
+ // visible pixel size: |+++++++++++++++++++|
+ // |2 1 0|1 2 3 4 5 6 7|8 9 0 1 2 3 4 5 6 7 8 9 0|
+ viewportAxis.visiblePixelSize = 10
viewportAxis.handleResize
testAxis(
"after expand",
@@ -180,12 +180,12 @@
@Test
def void expandBeyondEnd() {
- // segment position: | 0 | 1 | 2 | 3 |
- // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
- // visible pixel range: |-------------|+++++++++++++++++++++++++++++++++|
- // |2 1 0|1 2 3 4 5 6 7|8 9 0 1 2 3 4 5 6 7 8 9 0|1 2 3
+ // segment position: | 0 | 1 | 2 | 3 |
+ // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
+ // visible pixel size: |-------------|+++++++++++++++++++++++++++++++++|
+ // |2 1 0|1 2 3 4 5 6 7|8 9 0 1 2 3 4 5 6 7 8 9 0|1 2 3
viewportAxis.pixelOrigin = 4
- viewportAxis.visiblePixelRange = 7
+ viewportAxis.visiblePixelSize = 7
testAxis(
"before expand",
viewportAxis,
@@ -193,11 +193,11 @@
#[ -2.0, 1.0, 8.0 ]
)
- // segment position: | 0 | 1 | 2 | 3 |
- // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
- // visible pixel range: |+++++++++++++++++++++++++++++++++++++++++++++++|
- // |1 0|1 2 3|4 5 6 7 8 9 0|1 2 3 4 5 6 7 8 9 0 1 2 3|
- viewportAxis.visiblePixelRange = 24
+ // segment position: | 0 | 1 | 2 | 3 |
+ // pixel location: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
+ // visible pixel size: |+++++++++++++++++++++++++++++++++++++++++++++++|
+ // |1 0|1 2 3|4 5 6 7 8 9 0|1 2 3 4 5 6 7 8 9 0 1 2 3|
+ viewportAxis.visiblePixelSize = 24
viewportAxis.handleResize
testAxis(
"after expand",
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/geometry/PixelRectangleInvariants.xtend b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/geometry/PixelRectangleInvariants.xtend
index fc2df5b..93b481e 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/geometry/PixelRectangleInvariants.xtend
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/geometry/PixelRectangleInvariants.xtend
@@ -9,7 +9,7 @@
val startY = rect1.y.max(rect2.y)
val endX = rect1.x + rect1.width.min(rect2.x + rect2.width)
val endY = rect1.y + rect1.height.min(rect2.y + rect2.height)
- new PixelRectangle(startX, startY, new BigDecimal(0).max(endX - startX), new BigDecimal(0).max(endY - startY))
+ new PixelRectangle(startX, startY, BigDecimal::ZERO.max(endX - startX), BigDecimal::ZERO.max(endY - startY))
}
def static boolean isEmpty(PixelRectangle rect) {
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/AxisInvariants.xtend b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/AxisInvariants.xtend
index 3a15034..2ab40b5 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/AxisInvariants.xtend
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/AxisInvariants.xtend
@@ -18,7 +18,7 @@
}
def static boolean containsPixelLocation(Axis axis, BigDecimal pixelLocation) {
- pixelLocation >= new BigDecimal(0) && pixelLocation < axis.getStartPixelOfSegmentPosition(axis.segmentCount)
+ pixelLocation >= BigDecimal::ZERO && pixelLocation < axis.getStartPixelOfSegmentPosition(axis.segmentCount)
}
def static boolean containsSegmentPosition(Axis axis, long segmentPosition) {
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/AxisImpl.xtend b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/AxisImpl.xtend
index 0aacc6a..b2754e5 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/AxisImpl.xtend
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/axis/impl/AxisImpl.xtend
@@ -42,12 +42,12 @@
}
override getStartPixelOfSegmentPosition(long segmentPosition) {
- if (segmentPosition < 0) return new BigDecimal(-1)
- else if (segmentPosition == 0) return new BigDecimal(0)
+ if (segmentPosition < 0) return -BigDecimal::ONE
+ else if (segmentPosition == 0) return BigDecimal::ZERO
else if (segmentSizeMap.empty) return new BigDecimal(segmentPosition) * defaultSegmentSize
else {
var numResizedSegments = 0
- var resizeAggregate = new BigDecimal(0.0)
+ var resizeAggregate = BigDecimal::ZERO
for (resizedSegmentPosition : segmentSizeMap.subMap(0L, segmentPosition).keySet) {
numResizedSegments = numResizedSegments + 1
@@ -59,11 +59,11 @@
}
override getSegmentPositionOfPixelLocation(BigDecimal pixelLocation) {
- if (pixelLocation < new BigDecimal(0)) return -1
+ if (pixelLocation < BigDecimal::ZERO) return -1
else if (pixelLocation == 0) return 0
else if (pixelLocation >= pixelSize) return segmentCount
else if (segmentSizeMap.empty) return (pixelLocation / defaultSegmentSize).longValue
- else return findSegmentPositionOfPixelLocation(pixelLocation, new BigDecimal(0), pixelSize, 0, segmentCount)
+ else return findSegmentPositionOfPixelLocation(pixelLocation, BigDecimal::ZERO, pixelSize, 0, segmentCount)
}
def private long findSegmentPositionOfPixelLocation(BigDecimal pixelLocation, BigDecimal fromPixel, BigDecimal toPixel, long fromSegmentPosition, long toSegmentPosition) {
@@ -102,7 +102,7 @@
def void setPixelSizeOfSegmentPosition(BigDecimal size, long segmentPosition) {
if (!containsSegmentPosition(segmentPosition)) throw new IllegalArgumentException('''segment position «segmentPosition» is not contained in this axis''')
- if (size < new BigDecimal(0)) throw new IllegalArgumentException("size must be >= 0")
+ if (size < BigDecimal::ZERO) throw new IllegalArgumentException("size must be >= 0")
segmentSizeMap.put(segmentPosition, size)
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/CellLayerPainter.xtend b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/CellLayerPainter.xtend
index d67577c..80c7a38 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/CellLayerPainter.xtend
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/CellLayerPainter.xtend
@@ -22,15 +22,15 @@
// LayerPainter interface
override paintLayer(Layer layer, PixelArea layerPaintArea, GraphicsContext gc) {
- val layerPixelBounds = new PixelRectangle(new BigDecimal(0), new BigDecimal(0), layerPaintArea.width, layerPaintArea.height)
+ val layerPixelBounds = new PixelRectangle(BigDecimal::ZERO, BigDecimal::ZERO, layerPaintArea.width, layerPaintArea.height)
val clipBounds = gc.clipBounds
val fromColumnPosition = max(layer.getColumnPositionOfXPixel(clipBounds.x), 0)
- val toColumnPosition = min(layer.getColumnPositionOfXPixel(clipBounds.x + clipBounds.width - new BigDecimal(1)), layer.columnCount - 1)
+ val toColumnPosition = min(layer.getColumnPositionOfXPixel(clipBounds.x + clipBounds.width - BigDecimal::ONE), layer.columnCount - 1)
val columnRange = toColumnPosition - fromColumnPosition
val fromRowPosition = max(layer.getRowPositionOfYPixel(clipBounds.y), 0)
- val toRowPosition = min(layer.getRowPositionOfYPixel(clipBounds.y + clipBounds.height - new BigDecimal(1)), layer.rowCount - 1)
+ val toRowPosition = min(layer.getRowPositionOfYPixel(clipBounds.y + clipBounds.height - BigDecimal::ONE), layer.rowCount - 1)
val rowRange = toRowPosition - fromRowPosition
if (columnRange >= 0 && columnRange <= Integer::MAX_VALUE && rowRange >= 0 && rowRange <= Integer::MAX_VALUE) {
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/GridLineCellLayerPainter.xtend b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/GridLineCellLayerPainter.xtend
index 53e6724..ff923ff 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/GridLineCellLayerPainter.xtend
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/GridLineCellLayerPainter.xtend
@@ -32,8 +32,8 @@
new PixelRectangle(
pixelBounds.x,
pixelBounds.y,
- pixelBounds.width - new BigDecimal(1),
- pixelBounds.height - new BigDecimal(1)
+ pixelBounds.width - BigDecimal::ONE,
+ pixelBounds.height - BigDecimal::ONE
)
}
@@ -56,7 +56,7 @@
val rowRange = toRowPosition - fromRowPosition
if (rowRange >= 0 && rowRange <= Integer::MAX_VALUE)
for (rowOffset : 0 .. rowRange as int) {
- val y = (layer.getStartYPixelOfRowPosition(fromRowPosition + rowOffset) - new BigDecimal(1)).doubleValue
+ val y = (layer.getStartYPixelOfRowPosition(fromRowPosition + rowOffset) - BigDecimal::ONE).doubleValue
gc.drawLine(
0, y,
pixelWidth, y
@@ -69,7 +69,7 @@
val columnRange = toColumnPosition - fromColumnPosition
if (columnRange >= 0 && columnRange <= Integer::MAX_VALUE)
for (columnOffset : 0 .. columnRange as int) {
- val x = (layer.getStartXPixelOfColumnPosition(fromColumnPosition + columnOffset) - new BigDecimal(1)).doubleValue
+ val x = (layer.getStartXPixelOfColumnPosition(fromColumnPosition + columnOffset) - BigDecimal::ONE).doubleValue
gc.drawLine(
x, 0,
x, pixelHeight
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/composite/CompositeAxis.xtend b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/composite/CompositeAxis.xtend
index de38765..1381f0c 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/composite/CompositeAxis.xtend
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/composite/CompositeAxis.xtend
@@ -34,7 +34,7 @@
override getStartPixelOfSegmentPosition(long segmentPosition) {
var segmentOffset = 0L
- var pixelOffset = new BigDecimal(0.0)
+ var pixelOffset = BigDecimal::ZERO
for (subLayer : subLayers) {
val subAxis = subLayer.axis
@@ -51,11 +51,11 @@
}
override getSegmentPositionOfPixelLocation(BigDecimal pixelLocation) {
- if (pixelLocation < new BigDecimal(0)) return -1
+ if (pixelLocation < BigDecimal::ZERO) return -1
if (pixelLocation >= pixelSize) return segmentCount
var segmentOffset = 0L
- var pixelOffset = new BigDecimal(0.0)
+ var pixelOffset = BigDecimal::ZERO
for (subLayer : subLayers) {
val subAxis = subLayer.axis
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/composite/CompositeLayerPainter.xtend b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/composite/CompositeLayerPainter.xtend
index f643b93..7f3b989 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/composite/CompositeLayerPainter.xtend
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/composite/CompositeLayerPainter.xtend
@@ -15,12 +15,12 @@
@Inject extension PainterFactory
override paintLayer(CompositeLayer compositeLayer, PixelArea layerPaintArea, GraphicsContext gc) {
- var yOffset = new BigDecimal(0.0)
+ var yOffset = BigDecimal::ZERO
for (compositeRowPosition : 0 ..< compositeLayer.rows.size) {
val compositeRow = compositeLayer.rows.get(compositeRowPosition)
val isLastCompositeRow = compositeRowPosition == compositeLayer.rows.size - 1
- var xOffset = new BigDecimal(0.0)
+ var xOffset = BigDecimal::ZERO
for (compositeColumnPosition : 0 ..< compositeRow.childLayers.size) {
val childLayer = compositeRow.childLayers.get(compositeColumnPosition)
val isLastCompositeColumn = compositeColumnPosition == compositeRow.childLayers.size - 1
@@ -32,7 +32,7 @@
val pixelHeight = if (isLastCompositeRow) layerPaintArea.height - yOffset else childLayer.pixelHeight
val childLayerPaintArea = new PixelArea(pixelWidth, pixelHeight)
- gc.clipBounds = new PixelRectangle(new BigDecimal(0), new BigDecimal(0), pixelWidth, pixelHeight)
+ gc.clipBounds = new PixelRectangle(BigDecimal::ZERO, BigDecimal::ZERO, pixelWidth, pixelHeight)
childLayer.layerPainter.paintLayer(childLayer, childLayerPaintArea, gc)
gc.popState
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/viewport/ViewportAxis.xtend b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/viewport/ViewportAxis.xtend
index 1cd5ae9..96fe6ea 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/viewport/ViewportAxis.xtend
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/viewport/ViewportAxis.xtend
@@ -17,9 +17,9 @@
* Indicates the visible size of the axis. Note that the pixel locations returned by this ClientDimensionProvider
* must be in terms of underlying axis pixel coordinates.
*/
- BigDecimal visiblePixelRange = new BigDecimal(-1.0)
+ BigDecimal visiblePixelSize = -BigDecimal::ONE
- BigDecimal pixelOrigin = new BigDecimal(0)
+ BigDecimal pixelOrigin = BigDecimal::ZERO
new(Axis underlyingAxis, ViewportAxisListener viewportAxisListener) {
this.underlyingAxis = underlyingAxis
@@ -28,17 +28,17 @@
def getUnderlyingAxis() { underlyingAxis }
- def getVisiblePixelRange() {
- if (visiblePixelRange >= new BigDecimal(0)) visiblePixelRange
+ def getVisiblePixelSize() {
+ if (visiblePixelSize >= BigDecimal::ZERO) visiblePixelSize
else underlyingAxis.pixelSize
}
- def setVisiblePixelRange(double visiblePixelRange) {
- setVisiblePixelRange(new BigDecimal(visiblePixelRange))
+ def setVisiblePixelSize(double visiblePixelSize) {
+ setVisiblePixelSize(new BigDecimal(visiblePixelSize))
}
- def setVisiblePixelRange(BigDecimal visiblePixelRange) {
- this.visiblePixelRange = visiblePixelRange
+ def setVisiblePixelSize(BigDecimal visiblePixelSize) {
+ this.visiblePixelSize = visiblePixelSize
}
def getPixelOrigin() { pixelOrigin }
@@ -58,15 +58,15 @@
def void handleResize() {
// If the visible pixel size is greater than the content size, move origin to fill as much content as possible.
- val additionalSize = pixelOrigin + getVisiblePixelRange - underlyingAxis.pixelSize
- if (additionalSize > new BigDecimal(0))
- pixelOrigin = new BigDecimal(0).max(pixelOrigin - additionalSize)
+ val additionalSize = pixelOrigin + getVisiblePixelSize - underlyingAxis.pixelSize
+ if (additionalSize > BigDecimal::ZERO)
+ pixelOrigin = BigDecimal::ZERO.max(pixelOrigin - additionalSize)
}
// Layer interface
override getSegmentCount() {
- val endPixel = pixelOrigin + getVisiblePixelRange
+ val endPixel = pixelOrigin + getVisiblePixelSize
val endSegmentPosition = underlyingAxis.getSegmentPositionOfPixelLocation(endPixel)
val isEndPixelInsideEndSegment = endPixel > underlyingAxis.getStartPixelOfSegmentPosition(endSegmentPosition) && endPixel < underlyingAxis.getStartPixelOfSegmentPosition(underlyingAxis.segmentCount)
(endSegmentPosition + if (isEndPixelInsideEndSegment) 1 else 0) - originSegmentPosition
@@ -78,7 +78,7 @@
override getSegmentPositionOfPixelLocation(BigDecimal pixelLocation) {
val underlyingPixelLocation = pixelOrigin + pixelLocation
- if (underlyingPixelLocation < new BigDecimal(0)) return -1
+ if (underlyingPixelLocation < BigDecimal::ZERO) return -1
if (underlyingPixelLocation >= underlyingAxis.pixelSize) return segmentCount
underlyingAxis.getSegmentPositionOfPixelLocation(underlyingPixelLocation) - originSegmentPosition
}
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/viewport/ViewportLayer.xtend b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/viewport/ViewportLayer.xtend
index 575648f..1de8c01 100644
--- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/viewport/ViewportLayer.xtend
+++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/core/layer/impl/viewport/ViewportLayer.xtend
@@ -25,8 +25,8 @@
}
def void setVisiblePixelRectangle(PixelRectangle visiblePixelRectangle) {
- horizontalAxis.visiblePixelRange = visiblePixelRectangle.width
- verticalAxis.visiblePixelRange = visiblePixelRectangle.height
+ horizontalAxis.visiblePixelSize = visiblePixelRectangle.width
+ verticalAxis.visiblePixelSize = visiblePixelRectangle.height
}
def Layer getUnderlyingLayer() { underlyingLayer }
diff --git a/org.eclipse.nebula.widgets.nattable.renderer.swt.test/.classpath b/org.eclipse.nebula.widgets.nattable.renderer.swt.test/.classpath
deleted file mode 100644
index 9938e7c..0000000
--- a/org.eclipse.nebula.widgets.nattable.renderer.swt.test/.classpath
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="xtend-gen"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
diff --git a/org.eclipse.nebula.widgets.nattable.renderer.swt.test/.project b/org.eclipse.nebula.widgets.nattable.renderer.swt.test/.project
deleted file mode 100644
index 5d2c470..0000000
--- a/org.eclipse.nebula.widgets.nattable.renderer.swt.test/.project
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.nebula.widgets.nattable.renderer.swt.test</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
- </natures>
-</projectDescription>
diff --git a/org.eclipse.nebula.widgets.nattable.renderer.swt.test/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.nebula.widgets.nattable.renderer.swt.test/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index f42de36..0000000
--- a/org.eclipse.nebula.widgets.nattable.renderer.swt.test/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,7 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
-org.eclipse.jdt.core.compiler.compliance=1.7
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.7
diff --git a/org.eclipse.nebula.widgets.nattable.renderer.swt.test/META-INF/MANIFEST.MF b/org.eclipse.nebula.widgets.nattable.renderer.swt.test/META-INF/MANIFEST.MF
deleted file mode 100644
index 587b6f6..0000000
--- a/org.eclipse.nebula.widgets.nattable.renderer.swt.test/META-INF/MANIFEST.MF
+++ /dev/null
@@ -1,10 +0,0 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: NatTable SWT Renderer Test
-Bundle-SymbolicName: org.eclipse.nebula.widgets.nattable.renderer.swt.test
-Bundle-Version: 1.0.0.qualifier
-Fragment-Host: org.eclipse.nebula.widgets.nattable.renderer.swt;bundle-version="2.0.0"
-Bundle-RequiredExecutionEnvironment: JavaSE-1.7
-Require-Bundle: org.junit;bundle-version="4.10.0",
- org.mockito.mockito-core;bundle-version="1.9.5",
- com.springsource.org.objenesis;bundle-version="1.0.0"
diff --git a/org.eclipse.nebula.widgets.nattable.renderer.swt.test/build.properties b/org.eclipse.nebula.widgets.nattable.renderer.swt.test/build.properties
deleted file mode 100644
index d8e2f0e..0000000
--- a/org.eclipse.nebula.widgets.nattable.renderer.swt.test/build.properties
+++ /dev/null
@@ -1,5 +0,0 @@
-source.. = src/,\
- xtend-gen/
-output.. = bin/
-bin.includes = META-INF/,\
- .
diff --git a/org.eclipse.nebula.widgets.nattable.renderer.swt.test/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/ScrollBarHandlerTest.xtend b/org.eclipse.nebula.widgets.nattable.renderer.swt.test/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/ScrollBarHandlerTest.xtend
deleted file mode 100644
index e2417aa..0000000
--- a/org.eclipse.nebula.widgets.nattable.renderer.swt.test/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/ScrollBarHandlerTest.xtend
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.eclipse.nebula.widgets.nattable.renderer.swt.layer.viewport
-
-import java.math.BigDecimal
-import org.eclipse.nebula.widgets.nattable.core.layer.impl.viewport.ViewportAxis
-import org.eclipse.swt.widgets.ScrollBar
-import org.junit.Before
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.mockito.Mock
-import org.mockito.runners.MockitoJUnitRunner
-
-import static org.junit.Assert.*
-import static org.mockito.Mockito.*
-
-import static extension org.eclipse.nebula.widgets.nattable.renderer.swt.layer.viewport.ScrollBarHandler.*
-
-@RunWith(typeof(MockitoJUnitRunner))
-class ScrollBarHandlerTest {
-
- @Mock ScrollBar scrollBar
- @Mock ViewportAxis viewportAxis
- ScrollBarHandler scrollBarHandler
-
- @Before
- def void before() {
- scrollBarHandler = spy(new ScrollBarHandler(scrollBar, viewportAxis))
- }
-
- @Test
- def void scaleWithinIntRange() {
- assertEquals(1, new BigDecimal(1.0).scaleToInt(new BigDecimal(100.0)))
- assertEquals(new BigDecimal(1.0), 1.scaleToBigDecimal(new BigDecimal(100.0)))
- }
-
- @Test
- def void scaleOutsideIntRange() {
- val int maxIntDiv2 = Integer::MAX_VALUE / 2
- val BigDecimal maxIntTimes2 = new BigDecimal(Integer::MAX_VALUE) * new BigDecimal(2)
- val BigDecimal maxIntTimes4 = new BigDecimal(Integer::MAX_VALUE) * new BigDecimal(4)
-
- assertEquals(maxIntDiv2, maxIntTimes2.scaleToInt(maxIntTimes4))
- assertEquals(maxIntTimes2.doubleValue, maxIntDiv2.scaleToBigDecimal(maxIntTimes4).doubleValue, 2) // close enough!
- }
-
-}
\ No newline at end of file
diff --git a/org.eclipse.nebula.widgets.nattable.renderer.swt/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/SWTViewportLayerPainter.xtend b/org.eclipse.nebula.widgets.nattable.renderer.swt/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/SWTViewportLayerPainter.xtend
index ccb20ef..89e5164 100644
--- a/org.eclipse.nebula.widgets.nattable.renderer.swt/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/SWTViewportLayerPainter.xtend
+++ b/org.eclipse.nebula.widgets.nattable.renderer.swt/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/SWTViewportLayerPainter.xtend
@@ -50,16 +50,20 @@
viewportCanvas.addListener(SWT::Resize, [ event |
// Horizontal
viewportLayer.horizontalAxis.handleResize
- horizontalScrollBarHandler.recalculateScrollBarSize
// Vertical
viewportLayer.verticalAxis.handleResize
- verticalScrollBarHandler.recalculateScrollBarSize
])
- }
-
- // Resize viewport canvas
-
- val clipBounds = gc.clipBounds
+
+ resizeViewportCanvas(swtGC)
+
+ horizontalScrollBarHandler.recalculateScrollBarSize
+ verticalScrollBarHandler.recalculateScrollBarSize
+ } else
+ resizeViewportCanvas(swtGC)
+ }
+
+ def resizeViewportCanvas(SWTGraphicsContext swtGC) {
+ val clipBounds = swtGC.clipBounds
viewportCanvas.bounds = new Rectangle((swtGC.getXOffset + clipBounds.x) as int, (swtGC.getYOffset + clipBounds.y) as int, clipBounds.width.intValue, clipBounds.height.intValue)
}
diff --git a/org.eclipse.nebula.widgets.nattable.renderer.swt/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/ScrollBarHandler.xtend b/org.eclipse.nebula.widgets.nattable.renderer.swt/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/ScrollBarHandler.xtend
index b97c2cd..d34bc79 100644
--- a/org.eclipse.nebula.widgets.nattable.renderer.swt/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/ScrollBarHandler.xtend
+++ b/org.eclipse.nebula.widgets.nattable.renderer.swt/src/org/eclipse/nebula/widgets/nattable/renderer/swt/layer/viewport/ScrollBarHandler.xtend
@@ -1,6 +1,8 @@
package org.eclipse.nebula.widgets.nattable.renderer.swt.layer.viewport
import java.math.BigDecimal
+import java.math.MathContext
+import java.math.RoundingMode
import org.eclipse.nebula.widgets.nattable.core.layer.impl.viewport.ViewportAxis
import org.eclipse.swt.widgets.Event
import org.eclipse.swt.widgets.Listener
@@ -10,72 +12,65 @@
class ScrollBarHandler implements Listener {
- def static int scaleToInt(BigDecimal doubleValue, BigDecimal range) {
- val intScaleFactor = new BigDecimal(1.0).min(new BigDecimal(Integer::MAX_VALUE) / range)
- (doubleValue * intScaleFactor).intValue
- }
-
- def static BigDecimal scaleToBigDecimal(int intValue, BigDecimal range) {
- val doubleScaleFactor = new BigDecimal(1.0).max(range / new BigDecimal(Integer::MAX_VALUE))
- new BigDecimal(intValue) * doubleScaleFactor
- }
+ val static MAX_SCROLL_SIZE = new BigDecimal(Integer::MAX_VALUE)
//
val ScrollBar scrollBar
val ViewportAxis viewportAxis
+
+ val BigDecimal minThumb
+ val int minIncrement
+ val int minPageIncrement
+ val BigDecimal maxScrollSelection
new(ScrollBar scrollBar, ViewportAxis viewportAxis) {
this.scrollBar = scrollBar
this.viewportAxis = viewportAxis
+
+ scrollBar.thumb = 0
+ scrollBar.increment = 0
+ scrollBar.pageIncrement = 0
+
+ minThumb = new BigDecimal(scrollBar.thumb)
+ minIncrement = scrollBar.increment
+ minPageIncrement = scrollBar.pageIncrement
+ maxScrollSelection = MAX_SCROLL_SIZE - minThumb
}
override handleEvent(Event event) {
- viewportAxis.pixelOrigin = (/*viewportAxis.minimumOrigin +*/ scrollBar.selection).scaleToBigDecimal
- scrollBar.increment = scrollIncrement
- adjustScrollBar
+ val maxPixelOrigin = viewportAxis.underlyingAxis.pixelSize - viewportAxis.visiblePixelSize
+ val maxPixelSize = maxPixelOrigin * (MAX_SCROLL_SIZE / maxScrollSelection)
+ val intToPixel = BigDecimal::ONE.max(maxPixelSize.divide(MAX_SCROLL_SIZE, new MathContext(maxPixelSize.precision, RoundingMode::CEILING)))
+ viewportAxis.pixelOrigin = new BigDecimal(scrollBar.selection) * intToPixel
+ recalculateScrollBarSize
}
def void recalculateScrollBarSize() {
- val maxPixel = viewportAxis.underlyingAxis.pixelSize /*- viewportAxis.minimumOrigin*/
+ val visiblePixelSize = viewportAxis.visiblePixelSize
+ val maxPixelOrigin = viewportAxis.underlyingAxis.pixelSize - visiblePixelSize
- scrollBar.maximum = maxPixel.scaleToInt
+ val maxPixelSize = maxPixelOrigin * (MAX_SCROLL_SIZE / maxScrollSelection)
+ val pixelToInt = BigDecimal::ONE.min(MAX_SCROLL_SIZE.divide(maxPixelSize, new MathContext(maxPixelSize.precision, RoundingMode::CEILING)))
- val visiblePixelSize = viewportAxis.visiblePixelRange
+ scrollBar.maximum = (maxPixelSize * pixelToInt).intValue
+ scrollBar.selection = (viewportAxis.pixelOrigin * pixelToInt).intValue
- var thumbSize = 0
- if (visiblePixelSize < maxPixel && visiblePixelSize != 0) {
- thumbSize = visiblePixelSize.scaleToInt
- scrollBar.pageIncrement = thumbSize
- scrollBar.increment = scrollIncrement
+ if (visiblePixelSize < maxPixelSize && visiblePixelSize != 0) {
+ scrollBar.thumb = minThumb.max(visiblePixelSize * pixelToInt).intValue
+ // Increment by size of segment 0 or 1/4 of visible pixel size, whichever is smaller
+ val increment = viewportAxis.getPixelSizeOfSegmentPosition(0).min(viewportAxis.visiblePixelSize / new BigDecimal(4))
+ scrollBar.increment = Math::max(minIncrement, increment.intValue)
+ scrollBar.pageIncrement = Math::max(minPageIncrement, scrollBar.thumb)
scrollBar.enabled = true
scrollBar.visible = true
} else {
- thumbSize = maxPixel.scaleToInt
+ scrollBar.thumb = scrollBar.maximum
scrollBar.enabled = false
scrollBar.visible = false
}
- scrollBar.thumb = thumbSize
-
- adjustScrollBar
- }
-
- def private scaleToInt(BigDecimal pixel) {
- pixel.scaleToInt(viewportAxis.underlyingAxis.pixelSize)
- }
-
- def private scaleToBigDecimal(int intValue) {
- intValue.scaleToBigDecimal(viewportAxis.underlyingAxis.pixelSize)
- }
-
- def private void adjustScrollBar() {
- scrollBar.selection = (viewportAxis.pixelOrigin /*- viewportAxis.minimumOrigin*/).scaleToInt
- }
-
- def private int getScrollIncrement() {
- viewportAxis.getPixelSizeOfSegmentPosition(0).min(viewportAxis.visiblePixelRange / new BigDecimal(4)).scaleToInt
}
}
\ No newline at end of file