### Eclipse Workspace Patch 1.0 #P org.eclipse.gef Index: src/org/eclipse/gef/SnapToGuides.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.gef/src/org/eclipse/gef/SnapToGuides.java,v retrieving revision 1.32 diff -u -r1.32 SnapToGuides.java --- src/org/eclipse/gef/SnapToGuides.java 24 Jun 2005 21:53:38 -0000 1.32 +++ src/org/eclipse/gef/SnapToGuides.java 19 Dec 2007 17:05:12 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. + * Copyright (c) 2003, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -87,6 +87,8 @@ */ protected static final double THRESHOLD = 5.001; +private double threshold = THRESHOLD; + /** * The graphical editpart to which guides are relative. This should also the parent of * the parts being snapped to guides. @@ -114,8 +116,31 @@ } /** + * Get the sensitivity of the snapping. Corrections greater than this value will not occur. + * + * @return the snapping threshold + * @since 3.4 + */ +protected double getThreshold() +{ + return this.threshold; +} + +/** + * Set the sensitivity of the snapping. + * + * @see #getThreshold() + * @param newThreshold the new snapping threshold + * @since 3.4 + */ +protected void setThreshold(double newThreshold) +{ + this.threshold = newThreshold; +} + +/** * Returns the correction for the given near and far sides of a rectangle or {@link - * #THRESHOLD} if no correction was found. The near side represents the top or left side + * #getThreshold()} if no correction was found. The near side represents the top or left side * of a rectangle being snapped. Similar for far. If snapping occurs, the extendedData * will have the guide and attachment point set. * @@ -125,7 +150,7 @@ * @param extendedData the map for storing snap details * @param isVertical true if for vertical guides, false * for horizontal. - * @return the correction amount or THRESHOLD if no correction was made + * @return the correction amount or getThreshold() if no correction was made */ protected double getCorrectionFor(int[] guides, double near, double far, Map extendedData, boolean isVertical) { @@ -135,31 +160,31 @@ if ((int)(near - far) % 2 == 0) total -= 1.0; double result = getCorrectionFor(guides, total / 2, extendedData, isVertical, 0); - if (result == THRESHOLD) + if (result == getThreshold()) result = getCorrectionFor(guides, near, extendedData, isVertical, -1); - if (result == THRESHOLD) + if (result == getThreshold()) result = getCorrectionFor(guides, far, extendedData, isVertical, 1); return result; } /** - * Returns the correction for the given location or {@link #THRESHOLD} if no correction + * Returns the correction for the given location or {@link #getThreshold()} if no correction * was found. If correction occurs, the extendedData will have the guide and attachment * point set. The attachment point is identified by the side parameter. *

- * The correction's magnitude will be less than THRESHOLD. + * The correction's magnitude will be less than getThreshold(). * * @param guides the location of the guides * @param value the location being tested * @param extendedData the map for storing snap details * @param vert true if for vertical guides, false * @param side the integer indicating which side is being snapped - * @return a correction amount or THRESHOLD if no correction was made + * @return a correction amount or getThreshold() if no correction was made */ protected double getCorrectionFor(int[] guides, double value, Map extendedData, boolean vert, int side) { - double resultMag = THRESHOLD; - double result = THRESHOLD; + double resultMag = getThreshold(); + double result = getThreshold(); for (int i = 0; i < guides.length; i++) { int offset = guides[i]; @@ -227,7 +252,7 @@ if ((snapOrientation & HORIZONTAL) != 0) { double xcorrect = getCorrectionFor(getVerticalGuides(), baseRect.preciseX, baseRect.preciseRight(), request.getExtendedData(), true); - if (xcorrect != THRESHOLD) { + if (xcorrect != getThreshold()) { snapOrientation &= ~HORIZONTAL; correction.preciseX += xcorrect; } @@ -236,7 +261,7 @@ if ((snapOrientation & VERTICAL) != 0) { double ycorrect = getCorrectionFor(getHorizontalGuides(), baseRect.preciseY, baseRect.preciseBottom(), request.getExtendedData(), false); - if (ycorrect != THRESHOLD) { + if (ycorrect != getThreshold()) { snapOrientation &= ~VERTICAL; correction.preciseY += ycorrect; } @@ -246,7 +271,7 @@ if (!snapped && (snapOrientation & WEST) != 0) { double leftCorrection = getCorrectionFor(getVerticalGuides(), baseRect.preciseX, request.getExtendedData(), true, -1); - if (leftCorrection != THRESHOLD) { + if (leftCorrection != getThreshold()) { snapOrientation &= ~WEST; correction.preciseWidth -= leftCorrection; correction.preciseX += leftCorrection; @@ -256,7 +281,7 @@ if (!snapped && (snapOrientation & EAST) != 0) { double rightCorrection = getCorrectionFor(getVerticalGuides(), baseRect.preciseRight() - 1, request.getExtendedData(), true, 1); - if (rightCorrection != THRESHOLD) { + if (rightCorrection != getThreshold()) { snapped = true; snapOrientation &= ~EAST; correction.preciseWidth += rightCorrection; @@ -267,7 +292,7 @@ if (!snapped && (snapOrientation & NORTH) != 0) { double topCorrection = getCorrectionFor(getHorizontalGuides(), baseRect.preciseY, request.getExtendedData(), false, -1); - if (topCorrection != THRESHOLD) { + if (topCorrection != getThreshold()) { snapOrientation &= ~NORTH; correction.preciseHeight -= topCorrection; correction.preciseY += topCorrection; @@ -277,7 +302,7 @@ if (!snapped && (snapOrientation & SOUTH) != 0) { double bottom = getCorrectionFor(getHorizontalGuides(), baseRect.preciseBottom() - 1, request.getExtendedData(), false, 1); - if (bottom != THRESHOLD) { + if (bottom != getThreshold()) { snapped = true; snapOrientation &= ~SOUTH; correction.preciseHeight += bottom; Index: src/org/eclipse/gef/CompoundSnapToHelper.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.gef/src/org/eclipse/gef/CompoundSnapToHelper.java,v retrieving revision 1.9 diff -u -r1.9 CompoundSnapToHelper.java --- src/org/eclipse/gef/CompoundSnapToHelper.java 17 Oct 2007 17:56:51 -0000 1.9 +++ src/org/eclipse/gef/CompoundSnapToHelper.java 19 Dec 2007 17:05:12 -0000 @@ -37,13 +37,24 @@ this.delegates = delegates; } + +/** + * Gets the array of helpers. + * + * @return the array of helpers. + * @since 3.4 + */ +protected SnapToHelper[] getDelegates() { + return delegates; +} + /** * @see SnapToHelper#snapRectangle(Request, int, PrecisionRectangle, PrecisionRectangle) */ public int snapRectangle(Request request, int snapOrientation, PrecisionRectangle baseRect, PrecisionRectangle result) { - for (int i = 0; i < delegates.length && snapOrientation != NONE; i++) - snapOrientation = delegates[i].snapRectangle(request, snapOrientation, + for (int i = 0; i < getDelegates().length && snapOrientation != NONE; i++) + snapOrientation = getDelegates()[i].snapRectangle(request, snapOrientation, baseRect, result); return snapOrientation; } Index: src/org/eclipse/gef/tools/TargetingTool.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.gef/src/org/eclipse/gef/tools/TargetingTool.java,v retrieving revision 1.21 diff -u -r1.21 TargetingTool.java --- src/org/eclipse/gef/tools/TargetingTool.java 9 Jan 2007 19:33:47 -0000 1.21 +++ src/org/eclipse/gef/tools/TargetingTool.java 19 Dec 2007 17:05:13 -0000 @@ -281,7 +281,11 @@ super.resetFlags(); } -void resetHover() { +/** + * Resets hovering to inactive. + * @since 3.4 + */ +protected void resetHover() { if (isHoverActive()) handleHoverStop(); setHoverActive(false); Index: src/org/eclipse/gef/tools/DragEditPartsTracker.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.gef/src/org/eclipse/gef/tools/DragEditPartsTracker.java,v retrieving revision 1.53 diff -u -r1.53 DragEditPartsTracker.java --- src/org/eclipse/gef/tools/DragEditPartsTracker.java 29 Oct 2007 17:56:18 -0000 1.53 +++ src/org/eclipse/gef/tools/DragEditPartsTracker.java 19 Dec 2007 17:05:13 -0000 @@ -608,21 +608,36 @@ request.getExtendedData().clear(); request.setMoveDelta(moveDelta); - if (snapToHelper != null && !getCurrentInput().isModKeyDown(MODIFIER_NO_SNAPPING)) { - PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy(); - PrecisionRectangle jointRect = compoundSrcRect.getPreciseCopy(); - baseRect.translate(moveDelta); - jointRect.translate(moveDelta); - - PrecisionPoint preciseDelta = new PrecisionPoint(moveDelta); - snapToHelper.snapPoint(request, - PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, - new PrecisionRectangle[] {baseRect, jointRect}, preciseDelta); - request.setMoveDelta(preciseDelta); - } + snapPoint(request); request.setLocation(getLocation()); request.setType(getCommandName()); } +/** + * This method can be overridden by clients to customize the snapping + * behavior. + * + * @param request + * the ChangeBoundsRequest from which the move + * delta can be extracted and updated + * @since 3.4 + */ +protected void snapPoint(ChangeBoundsRequest request) { + Point moveDelta = request.getMoveDelta(); + if (snapToHelper != null + && !getCurrentInput().isModKeyDown(MODIFIER_NO_SNAPPING)) { + PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy(); + PrecisionRectangle jointRect = compoundSrcRect.getPreciseCopy(); + baseRect.translate(moveDelta); + jointRect.translate(moveDelta); + + PrecisionPoint preciseDelta = new PrecisionPoint(moveDelta); + snapToHelper.snapPoint(request, PositionConstants.HORIZONTAL + | PositionConstants.VERTICAL, new PrecisionRectangle[] { + baseRect, jointRect}, preciseDelta); + request.setMoveDelta(preciseDelta); + } +} + } Index: src/org/eclipse/gef/tools/AbstractTool.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.gef/src/org/eclipse/gef/tools/AbstractTool.java,v retrieving revision 1.54 diff -u -r1.54 AbstractTool.java --- src/org/eclipse/gef/tools/AbstractTool.java 5 Nov 2007 16:23:55 -0000 1.54 +++ src/org/eclipse/gef/tools/AbstractTool.java 19 Dec 2007 17:05:13 -0000 @@ -200,7 +200,17 @@ return e.character == SWT.ESC; } -boolean acceptArrowKey(KeyEvent e) { +/** + * Returns true if the event corresponds to an arrow key with the + * appropriate modifiers and if the system is in a state where the arrow key + * should be accepted. + * + * @param e + * the key event + * @return true if the arrow key should be accepted by this tool + * @since 3.4 + */ +protected boolean acceptArrowKey(KeyEvent e) { int key = e.keyCode; if (!(isInState(STATE_INITIAL | STATE_ACCESSIBLE_DRAG @@ -1120,7 +1130,16 @@ handler.handleMouseWheel(event, viewer); } -void placeMouseInViewer(Point p) { +/** + * Places the mouse in the viewer based on the point given. If the point + * given is outside the viewer, then the mouse is placed in the location + * nearest the given point but within the viewer. + * + * @param p + * the point + * @since 3.4 + */ +protected void placeMouseInViewer(Point p) { if (getCurrentViewer() == null) return; Control c = getCurrentViewer().getControl(); @@ -1511,7 +1530,13 @@ setFlag(1 << which, state); } - void setMouseLocation(int x, int y) { + /** + * Sets the current location of the mouse + * @param x x location + * @param y y location + * @since 3.4 + */ + public void setMouseLocation(int x, int y) { mouse.setLocation(x, y); } } Index: src/org/eclipse/gef/ui/parts/GraphicalViewerKeyHandler.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.gef/src/org/eclipse/gef/ui/parts/GraphicalViewerKeyHandler.java,v retrieving revision 1.26 diff -u -r1.26 GraphicalViewerKeyHandler.java --- src/org/eclipse/gef/ui/parts/GraphicalViewerKeyHandler.java 9 Jan 2007 19:56:29 -0000 1.26 +++ src/org/eclipse/gef/ui/parts/GraphicalViewerKeyHandler.java 19 Dec 2007 17:05:13 -0000 @@ -224,8 +224,9 @@ * This implementation returns a list that contains the EditPart that has focus. *

* @return a list of navigation editparts + * @since 3.4 */ -List getNavigationSiblings() { +protected List getNavigationSiblings() { EditPart focusPart = getFocusEditPart(); if (focusPart.getParent() != null) return focusPart.getParent().getChildren(); @@ -244,9 +245,9 @@ /** * @return true if the viewer is mirrored - * @since 3.1 + * @since 3.4 */ -boolean isViewerMirrored() { +protected boolean isViewerMirrored() { return (viewer.getControl().getStyle() & SWT.MIRRORED) != 0; }