-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[359] New implementation of move with arrow keys
Bug: #359
- Loading branch information
Showing
4 changed files
with
561 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
...am.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/ruler/SiriusSnapToGridEx.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 THALES GLOBAL SERVICES. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.diagram.ui.tools.internal.ruler; | ||
|
||
import java.util.Optional; | ||
|
||
import org.eclipse.draw2d.PositionConstants; | ||
import org.eclipse.draw2d.geometry.PrecisionRectangle; | ||
import org.eclipse.gef.GraphicalEditPart; | ||
import org.eclipse.gef.Request; | ||
import org.eclipse.gef.SnapToHelper; | ||
import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.SnapToGridEx; | ||
import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.SnapToHelperUtil; | ||
import org.eclipse.sirius.diagram.ui.tools.internal.ui.SnapToAllDragEditPartsTracker; | ||
import org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper; | ||
|
||
/** | ||
* Overridden to support the new mode moving node with arrow keys. | ||
* | ||
* @author Laurent Redor | ||
*/ | ||
@SuppressWarnings("restriction") | ||
public class SiriusSnapToGridEx extends SnapToGridEx { | ||
|
||
/** | ||
* Default constructor. | ||
* | ||
* @param container | ||
* the editpart which the grid is on | ||
*/ | ||
public SiriusSnapToGridEx(GraphicalEditPart container) { | ||
super(container); | ||
} | ||
|
||
/** | ||
* Method overridden to handle the new move mode with arrow keys. Indeed, in this case, the absolute coordinate of | ||
* <code>rect</code> consider the scrollbars. It is not the case otherwise.<BR/> | ||
* Only the calls to {@link #makeRelative(org.eclipse.draw2d.IFigure, org.eclipse.draw2d.geometry.Translatable)} and | ||
* {@link #makeAbsolute(org.eclipse.draw2d.IFigure, org.eclipse.draw2d.geometry.Translatable)} are replaced in this | ||
* method. | ||
* | ||
* @see SnapToHelper#snapRectangle(Request, int, PrecisionRectangle, PrecisionRectangle) | ||
*/ | ||
@Override | ||
public int snapRectangle(Request request, int snapLocations, PrecisionRectangle rect, PrecisionRectangle result) { | ||
boolean isMoveWithArrowSiriusMode = ((Boolean) (Optional.ofNullable(request.getExtendedData().get(SnapToAllDragEditPartsTracker.MOVE_WITH_ARROW_SIRIUS_MODE)).orElse(Boolean.FALSE))) | ||
.booleanValue(); | ||
double zoom = GraphicalHelper.getZoom(container); | ||
|
||
Integer restrictedDirections = (Integer) request.getExtendedData().get(SnapToHelperUtil.RESTRICTED_DIRECTIONS); | ||
if (restrictedDirections == null || restrictedDirections == PositionConstants.NONE) { | ||
return super.snapRectangle(request, snapLocations, rect, result); | ||
} | ||
int snapLocationsCopy = SnapToHelperUtil.updateSnapLocations(snapLocations, restrictedDirections); | ||
|
||
PrecisionRectangle rectCopy = rect.getPreciseCopy(); | ||
if (isMoveWithArrowSiriusMode) { | ||
// In the case, only the zoom must be applied | ||
rectCopy.performScale(1.0d / zoom); | ||
} else { | ||
makeRelative(container.getContentPane(), rectCopy); | ||
} | ||
PrecisionRectangle correction = new PrecisionRectangle(); | ||
if (isMoveWithArrowSiriusMode) { | ||
// In the case, only the zoom must be applied | ||
correction.performScale(1.0d / zoom); | ||
} else { | ||
makeRelative(container.getContentPane(), correction); | ||
} | ||
|
||
if (gridX > 0 && (snapLocationsCopy & EAST) != 0) { | ||
correction.setPreciseWidth(correction.preciseWidth() - Math.IEEEremainder(rectCopy.preciseRight() - origin.x - 1, gridX)); | ||
snapLocationsCopy &= ~EAST; | ||
} | ||
|
||
if ((snapLocationsCopy & (WEST | HORIZONTAL)) != 0 && gridX > 0) { | ||
double leftCorrection = Math.IEEEremainder(rectCopy.preciseX() - origin.x, gridX); | ||
|
||
// /////////////////// ADDED THIS CODE | ||
// CHECKSTYLE:OFF | ||
if ((restrictedDirections & EAST) != 0 && (restrictedDirections & WEST) == 0 && leftCorrection > 0) { | ||
// restricted to moving EAST | ||
correction.setPreciseX(correction.preciseX() + (gridX - leftCorrection)); | ||
} else if ((restrictedDirections & WEST) != 0 && (restrictedDirections & EAST) == 0 && leftCorrection < 0) { | ||
// restricted to moving WEST | ||
correction.setPreciseX(correction.preciseX() - (gridX + leftCorrection)); | ||
} else { | ||
// no horizontal restrictions | ||
correction.setPreciseX(correction.preciseX() - leftCorrection); | ||
} | ||
// /////////////////// | ||
// CHECKSTYLE:ON | ||
|
||
if ((snapLocationsCopy & HORIZONTAL) == 0) | ||
correction.setPreciseWidth(correction.preciseWidth() + leftCorrection); | ||
snapLocationsCopy &= ~(WEST | HORIZONTAL); | ||
} | ||
|
||
if ((snapLocationsCopy & SOUTH) != 0 && gridY > 0) { | ||
correction.setPreciseHeight(correction.preciseHeight() - Math.IEEEremainder(rectCopy.preciseBottom() - origin.y - 1, gridY)); | ||
snapLocationsCopy &= ~SOUTH; | ||
} | ||
|
||
if ((snapLocationsCopy & (NORTH | VERTICAL)) != 0 && gridY > 0) { | ||
double topCorrection = Math.IEEEremainder(rectCopy.preciseY() - origin.y, gridY); | ||
|
||
// /////////////////// ADDED THIS CODE | ||
// CHECKSTYLE:OFF | ||
if ((restrictedDirections & SOUTH) != 0 && (restrictedDirections & NORTH) == 0 && topCorrection > 0) { | ||
// restricted to moving SOUTH | ||
correction.setPreciseY(correction.preciseY() + (gridY - topCorrection)); | ||
} else if ((restrictedDirections & NORTH) != 0 && (restrictedDirections & SOUTH) == 0 && topCorrection < 0) { | ||
// restricted to moving NORTH | ||
correction.setPreciseY(correction.preciseY() - (gridY + topCorrection)); | ||
} else { | ||
// no vertical restrictions | ||
correction.setPreciseY(correction.preciseY() - topCorrection); | ||
} | ||
// /////////////////// | ||
// CHECKSTYLE:ON | ||
|
||
if ((snapLocationsCopy & VERTICAL) == 0) | ||
correction.setPreciseHeight(correction.preciseHeight() + topCorrection); | ||
snapLocationsCopy &= ~(NORTH | VERTICAL); | ||
} | ||
|
||
|
||
if (isMoveWithArrowSiriusMode) { | ||
// In the case, only the zoom must be applied | ||
correction.performScale(zoom); | ||
} else { | ||
makeAbsolute(container.getContentPane(), correction); | ||
} | ||
result.setPreciseX(result.preciseX() + correction.preciseX()); | ||
result.setPreciseY(result.preciseY() + correction.preciseY()); | ||
result.setPreciseWidth(result.preciseWidth() + correction.preciseWidth()); | ||
result.setPreciseHeight(result.preciseHeight() + correction.preciseHeight()); | ||
|
||
return snapLocationsCopy; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.