-
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
5 changed files
with
596 additions
and
14 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
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
100 changes: 100 additions & 0 deletions
100
...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,100 @@ | ||
/******************************************************************************* | ||
* 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.IFigure; | ||
import org.eclipse.draw2d.geometry.PrecisionRectangle; | ||
import org.eclipse.draw2d.geometry.Translatable; | ||
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.sirius.diagram.ui.tools.internal.ui.SnapToAllDragEditPartsTracker; | ||
|
||
/** | ||
* Overridden to support the new mode moving node with arrow keys. | ||
* | ||
* @author Laurent Redor | ||
*/ | ||
@SuppressWarnings("restriction") | ||
public class SiriusSnapToGridEx extends SnapToGridEx { | ||
|
||
boolean isMoveWithArrowSiriusMode; | ||
|
||
/** | ||
* Default constructor. | ||
* | ||
* @param container | ||
* the editpart which the grid is on | ||
*/ | ||
public SiriusSnapToGridEx(GraphicalEditPart container) { | ||
super(container); | ||
} | ||
|
||
protected void setMoveWithArrowSiriusMode(boolean moveWithArrowSiriusMode) { | ||
this.isMoveWithArrowSiriusMode = moveWithArrowSiriusMode; | ||
} | ||
|
||
protected boolean isMoveWithArrowSiriusMode() { | ||
return isMoveWithArrowSiriusMode; | ||
} | ||
|
||
/** | ||
* Method overridden to handle the new move mode with arrow keys (then used in makeRelative and makeAbsolute). | ||
* Indeed, in this case, the absolute coordinate of <code>rect</code> consider the scrollbars. It is not the case | ||
* otherwise. | ||
* | ||
* @see SnapToHelper#snapRectangle(Request, int, PrecisionRectangle, PrecisionRectangle) | ||
*/ | ||
@Override | ||
public int snapRectangle(Request request, int snapLocations, PrecisionRectangle rect, PrecisionRectangle result) { | ||
setMoveWithArrowSiriusMode(((Boolean) (Optional.ofNullable(request.getExtendedData().get(SnapToAllDragEditPartsTracker.MOVE_WITH_ARROW_SIRIUS_MODE)).orElse(Boolean.FALSE))).booleanValue()); | ||
return super.snapRectangle(request, snapLocations, rect, result); | ||
} | ||
|
||
/** | ||
* Translates from absolute to coordinates relative to the given figure. | ||
* | ||
* @param figure | ||
* the reference figure | ||
* @param t | ||
* the object to translate | ||
*/ | ||
@Override | ||
protected void makeRelative(IFigure figure, Translatable t) { | ||
// In the case of move with arrow key, there is nothing to do. Compute is already done in absolute coordinates | ||
// (considering zoom and scrollbars). | ||
if (!isMoveWithArrowSiriusMode()) { | ||
super.makeRelative(figure, t); | ||
} | ||
} | ||
|
||
/** | ||
* Translates from a given figure to absolute coordinates. | ||
* | ||
* @param figure | ||
* the reference figure | ||
* @param t | ||
* the object to translate | ||
*/ | ||
@Override | ||
protected void makeAbsolute(IFigure figure, Translatable t) { | ||
// In the case of move with arrow key, there is nothing to do. Compute is already done in absolute coordinates | ||
// (considering zoom and scrollbars). | ||
if (!isMoveWithArrowSiriusMode()) { | ||
super.makeAbsolute(figure, t); | ||
} | ||
} | ||
} |
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.