From 6dacdff00b480032744dd1c61aa203e9bb7731ca Mon Sep 17 00:00:00 2001 From: Vincent Aravantinos <aravantinos@fortiss.org> Date: Mon, 17 Jul 2017 15:46:21 +0000 Subject: [PATCH] also fixes corners refs 2346 --- .../base/ui/editor/DiagramKeyHandler.java | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/DiagramKeyHandler.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/DiagramKeyHandler.java index 6fdd186f3..565d5b3b2 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/DiagramKeyHandler.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/DiagramKeyHandler.java @@ -60,7 +60,7 @@ import org.fortiss.tooling.kernel.service.IPersistencyService; * @author aravantinos * @author $Author$ * @version $Rev$ - * @ConQAT.Rating YELLOW Hash: 60245690315B7D65B464ADC89AC541B9 + * @ConQAT.Rating YELLOW Hash: 70C42CF9316623FE28B2B7ABEAC08CB8 */ public class DiagramKeyHandler extends KeyHandler { @@ -167,18 +167,13 @@ public class DiagramKeyHandler extends KeyHandler { if((oo.getOrientation() == EOrientation.EAST || oo.getOrientation() == EOrientation.WEST) && (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_UP)) { int newY = oo.getOffset() + scrollCoeff.y; - if(newY >= 0 && newY < containerDim.getHeight() - DEFAULT_GRID_SIZE) { - setStickyConnectorLayoutData(ep.getModel(), - oo.getOrientation(), newY); - } + moveVertical(newY, containerDim, ep.getModel(), oo.getOrientation()); } else if((oo.getOrientation() == EOrientation.NORTH || oo .getOrientation() == EOrientation.SOUTH) && (event.keyCode == SWT.ARROW_LEFT || event.keyCode == SWT.ARROW_RIGHT)) { int newX = oo.getOffset() + scrollCoeff.x; - if(newX >= 0 && newX < containerDim.getWidth() - DEFAULT_GRID_SIZE) { - setStickyConnectorLayoutData(ep.getModel(), - oo.getOrientation(), newX); - } + moveHorizontal(newX, containerDim, ep.getModel(), + oo.getOrientation()); } } else { Angle angle = getConnectorAngle(ep.getModel()); @@ -195,6 +190,36 @@ public class DiagramKeyHandler extends KeyHandler { return true; } + /** Moves the given layouted element vertically by the distance provided by offset. */ + private void moveVertical(int offset, Dimension containerDim, ILayoutedModelElement layouted, + EOrientation orientation) { + int newOffset = + orientation == EOrientation.WEST ? 0 : containerDim.getWidth() - 2 * + DEFAULT_GRID_SIZE; + if(offset <= 0) { + setStickyConnectorLayoutData(layouted, EOrientation.NORTH, newOffset); + } else if(offset >= containerDim.getHeight() - 2 * DEFAULT_GRID_SIZE) { + setStickyConnectorLayoutData(layouted, EOrientation.SOUTH, newOffset); + } else { + setStickyConnectorLayoutData(layouted, orientation, offset); + } + } + + /** Moves the given layouted element horizontally by the distance provided by offset. */ + private void moveHorizontal(int offset, Dimension containerDim, ILayoutedModelElement layouted, + EOrientation orientation) { + int newOffset = + orientation == EOrientation.NORTH ? 0 : containerDim.getHeight() - 2 * + DEFAULT_GRID_SIZE; + if(offset <= 0) { + setStickyConnectorLayoutData(layouted, EOrientation.WEST, newOffset); + } else if(offset >= containerDim.getWidth() - 2 * DEFAULT_GRID_SIZE) { + setStickyConnectorLayoutData(layouted, EOrientation.EAST, newOffset); + } else { + setStickyConnectorLayoutData(layouted, orientation, offset); + } + } + /** Returns a coefficient of 1 if the SHIFT key is not pressed, 50 otherwise. */ private Point computeScrollCoeff(KeyEvent event) { int coeff = (event.stateMask & SWT.SHIFT) == 0 ? 1 : 10; -- GitLab