BoundaryTransformMediator implements TransformMediator { @Override public Transform adjust(final Transform transform, final Bounds visibleBounds) { updateBounds(); Transform newTransform = transform.copy(); final double scaleX = transform.getScaleX(); final double scaleY = transform.getScaleY(); final double translateX = newTransform.getTranslateX(); final double translateY = newTransform.getTranslateY(); final double scaledTranslateX = translateX / scaleX; final double scaledTranslateY = translateY / scaleY; final double visibleBoundsWidth = visibleBounds.getWidth(); final double visibleBoundsHeight = visibleBounds.getHeight(); if (-scaledTranslateX < minX) { newTransform = newTransform.translate(-scaledTranslateX - minX, 0); } if (-scaledTranslateY < minY) { newTransform = newTransform.translate(0, -scaledTranslateY - minY); } if (-scaledTranslateX + visibleBoundsWidth > maxX) { newTransform = newTransform.translate(-scaledTranslateX + visibleBoundsWidth - maxX, 0); } if (-scaledTranslateY + visibleBoundsHeight > maxY) { newTransform = newTransform.translate(0, -scaledTranslateY + visibleBoundsHeight - maxY); } return newTransform; } BoundaryTransformMediator(final GuidedDecisionTableModellerView view); @Override Transform adjust(final Transform transform,
                            final Bounds visibleBounds);  }
@Test public void testLeftEdge() { final Bounds visibleBounds = new BaseBounds( -500, -500, 1000, 1000 ); final Transform test = new Transform().translate( 1200.0, 0.0 ); final Transform result = restriction.adjust( test, visibleBounds ); assertNotNull( result ); assertEquals( 1000.0, result.getTranslateX(), 0.0 ); assertEquals( 0.0, result.getTranslateY(), 0.0 ); verify( view, times( 2 ) ).getBounds(); }
@Test public void testRightEdge() { final Bounds visibleBounds = new BaseBounds( -500, -500, 1000, 1000 ); final Transform test = new Transform().translate( -200.0, 0.0 ); final Transform result = restriction.adjust( test, visibleBounds ); assertNotNull( result ); assertEquals( 0.0, result.getTranslateX(), 0.0 ); assertEquals( 0.0, result.getTranslateY(), 0.0 ); verify( view, times( 2 ) ).getBounds(); }
@Test public void testTopEdge() { final Bounds visibleBounds = new BaseBounds( -500, -500, 1000, 1000 ); final Transform test = new Transform().translate( 0.0, 1200.0 ); final Transform result = restriction.adjust( test, visibleBounds ); assertNotNull( result ); assertEquals( 0.0, result.getTranslateX(), 0.0 ); assertEquals( 1000.0, result.getTranslateY(), 0.0 ); verify( view, times( 2 ) ).getBounds(); }
@Test public void testBottomEdge() { final Bounds visibleBounds = new BaseBounds( -500, -500, 1000, 1000 ); final Transform test = new Transform().translate( 0.0, -200.0 ); final Transform result = restriction.adjust( test, visibleBounds ); assertNotNull( result ); assertEquals( 0.0, result.getTranslateX(), 0.0 ); assertEquals( 0.0, result.getTranslateY(), 0.0 ); verify( view, times( 2 ) ).getBounds(); }