Skip to content

Commit

Permalink
[63] Use precise coordinates in DragEditPartsTrackerEx.snapPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lredor committed Apr 25, 2024
1 parent b22c586 commit a71d84d
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (c) 2002, 2008 IBM Corporation and others.
* Copyright (c) 2002, 2024 IBM Corporation and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand Down Expand Up @@ -56,7 +56,8 @@ public DragEditPartsTrackerEx(EditPart sourceEditPart) {
/**
* @see org.eclipse.gef.tools.AbstractTool#getCommand()
*/
protected Command getCommand() {
@Override
protected Command getCommand() {
if (!isMove()) {
CompoundCommand command = new CompoundCommand();
addSourceCommands(false, command);
Expand Down Expand Up @@ -116,7 +117,8 @@ protected void addSourceCommands(boolean isMove, CompoundCommand command) {
/**
* @see org.eclipse.gef.tools.AbstractTool#getCommandName()
*/
protected String getCommandName() {
@Override
protected String getCommandName() {
if (!isMove())
return RequestConstants.REQ_DROP;
return super.getCommandName();
Expand All @@ -126,7 +128,8 @@ protected String getCommandName() {
* If the source is not in the operation set, it is not a move
* @see org.eclipse.gef.tool s.DragEditPartsTracker#isMove()
*/
protected boolean isMove() {
@Override
protected boolean isMove() {
for (int i = 0 ; i < getOperationSet().size(); i++){
if (getOperationSet().get(i).equals(getSourceEditPart())){
return super.isMove();
Expand All @@ -148,7 +151,8 @@ protected boolean isMove() {
/* (non-Javadoc)
* @see org.eclipse.gef.tools.AbstractTool#executeCurrentCommand()
*/
protected void executeCurrentCommand() {
@Override
protected void executeCurrentCommand() {
super.executeCurrentCommand();
if (isActive()) {
if (getOperationSet().size() > 0) {
Expand All @@ -174,6 +178,7 @@ protected void reveal(EditPart editpart){
editpart.getViewer().reveal(editpart);
}

@Override
protected boolean handleDragInProgress() {
boolean returnValue = super.handleDragInProgress();
if (isInState(STATE_DRAG_IN_PROGRESS)
Expand All @@ -186,6 +191,7 @@ protected boolean handleDragInProgress() {
return returnValue;
}

@Override
protected Cursor calculateCursor() {
if (isInState(STATE_DRAG_IN_PROGRESS)
|| isInState(STATE_ACCESSIBLE_DRAG_IN_PROGRESS)) {
Expand Down Expand Up @@ -215,6 +221,7 @@ protected Cursor calculateCursor() {
return super.calculateCursor();
}

@Override
protected boolean handleButtonDown(int button) {

// If the group is selected, and the user clicks on a shape, defer the
Expand All @@ -232,6 +239,7 @@ && getSourceEditPart().getParent().getSelected() != EditPart.SELECTED_NONE) {
return super.handleButtonDown(button);
}

@Override
protected boolean handleDoubleClick(int button) {
// If the user double-clicks a shape in a group and the shape is not
// selected, select the shape.
Expand All @@ -244,6 +252,7 @@ && getSourceEditPart().getSelected() == EditPart.SELECTED_NONE) {
}
}

@Override
protected void performSelection() {
super.performSelection();

Expand All @@ -258,23 +267,24 @@ && getSourceEditPart().getParent().getSelected() != EditPart.SELECTED_NONE) {
* Overridden to add extended data to the request to restrict snapping to
* specific directions based on the move delta.
*/
@Override
protected void snapPoint(ChangeBoundsRequest request) {
Point moveDelta = request.getMoveDelta();
if (getState() == STATE_ACCESSIBLE_DRAG_IN_PROGRESS) {
int restrictedDirection = 0;

if (moveDelta.x > 0) {
if (moveDelta.preciseX() > 0) {
restrictedDirection = restrictedDirection
| PositionConstants.EAST;
} else if (moveDelta.x < 0) {
} else if (moveDelta.preciseX() < 0) {
restrictedDirection = restrictedDirection
| PositionConstants.WEST;
}

if (moveDelta.y > 0) {
if (moveDelta.preciseY() > 0) {
restrictedDirection = restrictedDirection
| PositionConstants.SOUTH;
} else if (moveDelta.y < 0) {
} else if (moveDelta.preciseY() < 0) {
restrictedDirection = restrictedDirection
| PositionConstants.NORTH;
}
Expand All @@ -286,6 +296,7 @@ protected void snapPoint(ChangeBoundsRequest request) {
super.snapPoint(request);
}

@Override
protected boolean handleKeyDown(KeyEvent e) {
if (acceptArrowKey(e)) {
if (isInState(STATE_INITIAL)) {
Expand Down

0 comments on commit a71d84d

Please sign in to comment.