Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark Draw2D Cursors class as deprecated and for-removal #481

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2023 IBM Corporation and others.
* Copyright (c) 2005, 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
Expand All @@ -12,11 +12,10 @@
*******************************************************************************/
package org.eclipse.draw2d.examples.scrollpane;

import org.eclipse.swt.graphics.Cursor;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.CompoundBorder;
import org.eclipse.draw2d.Cursors;
import org.eclipse.draw2d.CursorProvider;
import org.eclipse.draw2d.CursorProviders;
import org.eclipse.draw2d.FigureUtilities;
import org.eclipse.draw2d.LabeledContainer;
import org.eclipse.draw2d.LineBorder;
Expand Down Expand Up @@ -123,42 +122,42 @@ public void mouseMoved(MouseEvent me) {
}
position = getClientArea().getCopy().shrink(4, 4).getPosition(mouseLocation);
move = false;
Cursor newCursor = null;
CursorProvider newCursor = null;

switch (position) {
case PositionConstants.NONE:
break;
case PositionConstants.SOUTH_EAST:
newCursor = Cursors.SIZESE;
newCursor = CursorProviders.SIZESE;
break;
case PositionConstants.SOUTH:
newCursor = Cursors.SIZES;
newCursor = CursorProviders.SIZES;
break;
case PositionConstants.EAST:
newCursor = Cursors.SIZEE;
newCursor = CursorProviders.SIZEE;
break;
case PositionConstants.NORTH_EAST:
newCursor = Cursors.SIZENE;
newCursor = CursorProviders.SIZENE;
break;
case PositionConstants.NORTH_WEST:
newCursor = Cursors.SIZENW;
newCursor = CursorProviders.SIZENW;
break;
case PositionConstants.SOUTH_WEST:
newCursor = Cursors.SIZESW;
newCursor = CursorProviders.SIZESW;
break;
case PositionConstants.NORTH:
if (mouseLocation.y > (getBounds().y + getInsets().left)) {
// Special case: MOVE and NOT RESIZE
move = true;
} else {
newCursor = Cursors.SIZEN;
newCursor = CursorProviders.SIZEN;
}
break;
case PositionConstants.WEST:
newCursor = Cursors.SIZEW;
newCursor = CursorProviders.SIZEW;
break;
}
setCursor(newCursor);
setCursorProvider(newCursor);
}

@Override
Expand All @@ -183,7 +182,7 @@ public void mouseReleased(MouseEvent me) {

@Override
public void mouseExited(MouseEvent me) {
setCursor(null);
setCursorProvider((CursorProvider) null);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2023 Google, Inc.
* Copyright (c) 2011, 2024 Google, Inc. 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
Expand Down Expand Up @@ -289,12 +289,12 @@ public void testCursor() {
actualLogger.assertEmpty();
//
// check invoke updateCursor() during setCursor()
testFigure.setCursor(null);
testFigure.setCursorProvider(null);
expectedLogger.log("updateCursor()");
actualLogger.assertEquals(expectedLogger);
//
// check not invoke updateCursor() during setCursor() if cursor not change
testFigure.setCursor(null);
testFigure.setCursorProvider(null);
actualLogger.assertEmpty();
}

Expand Down
31 changes: 31 additions & 0 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/CursorProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 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
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/

package org.eclipse.draw2d;

import java.util.function.Supplier;

import org.eclipse.swt.graphics.Cursor;

/**
* This interface is intended to be used by Draw2D to handle dynamic DPI
* changes, requiring a refresh of the underlying cursor resource. A call to
* {@link #get()} must always return a cursor object whose resolution matches
* the current display zoom.
*
* @since 3.17
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface CursorProvider extends Supplier<Cursor> {
}
203 changes: 203 additions & 0 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/CursorProviders.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
/*******************************************************************************
* Copyright (c) 2000, 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
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.draw2d;

import org.eclipse.swt.SWT;

import org.eclipse.draw2d.internal.SystemCursorProvider;

/**
* A collection of DPI-aware cursors.
*
* @since 3.17
*/
public class CursorProviders {

/**
* Returns the cursor corresponding to the given direction, defined in
* {@link PositionConstants}. Note that
* {@link #getDirectionalCursor(int, boolean)} should be used for applications
* which want to run properly when running in a mirrored environment. The
* behavior is the same as calling {@link #getDirectionalCursor(int, boolean)
* getDirectionalCursor(direction, false)}.
*
* @param direction the relative direction of the desired cursor
* @return The appropriate directional cursor
*/
public static CursorProvider getDirectionalCursor(int direction) {
return getDirectionalCursor(direction, false);
}

/**
* Returns the cursor corresponding to the given direction and mirroring. The
* direction must be one of:
* <UL>
* <LI>{@link PositionConstants#NORTH}
* <LI>{@link PositionConstants#SOUTH}
* <LI>{@link PositionConstants#EAST}
* <LI>{@link PositionConstants#WEST}
* <LI>{@link PositionConstants#NORTH_EAST}
* <LI>{@link PositionConstants#NORTH_WEST}
* <LI>{@link PositionConstants#SOUTH_EAST}
* <LI>{@link PositionConstants#SOUTH_WEST}
* </UL>
* <P>
* The behavior is undefined for other values. If <code>isMirrored</code> is set
* to <code>true</code>, EAST and WEST will be inverted.
*
* @param direction the relative direction of the desired cursor
* @param isMirrored <code>true</code> if EAST and WEST should be inverted
* @return The appropriate directional cursor
*/
public static CursorProvider getDirectionalCursor(int direction, boolean isMirrored) {
if (isMirrored && (direction & PositionConstants.EAST_WEST) != 0) {
direction = direction ^ PositionConstants.EAST_WEST;
}
switch (direction) {
case PositionConstants.NORTH:
return SIZEN;
case PositionConstants.SOUTH:
return SIZES;
case PositionConstants.EAST:
return SIZEE;
case PositionConstants.WEST:
return SIZEW;
case PositionConstants.SOUTH_EAST:
return SIZESE;
case PositionConstants.SOUTH_WEST:
return SIZESW;
case PositionConstants.NORTH_EAST:
return SIZENE;
case PositionConstants.NORTH_WEST:
return SIZENW;
default:
break;
}
return null;
}

/**
* @see SWT#CURSOR_ARROW
*/
public static final CursorProvider ARROW;
/**
* @see SWT#CURSOR_SIZEN
*/
public static final CursorProvider SIZEN;
/**
* @see SWT#CURSOR_SIZENE
*/
public static final CursorProvider SIZENE;
/**
* @see SWT#CURSOR_SIZEE
*/
public static final CursorProvider SIZEE;
/**
* @see SWT#CURSOR_SIZESE
*/
public static final CursorProvider SIZESE;
/**
* @see SWT#CURSOR_SIZES
*/
public static final CursorProvider SIZES;
/**
* @see SWT#CURSOR_SIZESW
*/
public static final CursorProvider SIZESW;
/**
* @see SWT#CURSOR_SIZEW
*/
public static final CursorProvider SIZEW;
/**
* @see SWT#CURSOR_SIZENW
*/
public static final CursorProvider SIZENW;
/**
* @see SWT#CURSOR_APPSTARTING
*/
public static final CursorProvider APPSTARTING;
/**
* @see SWT#CURSOR_CROSS
*/
public static final CursorProvider CROSS;
/**
* @see SWT#CURSOR_HAND
*/
public static final CursorProvider HAND;
/**
* @see SWT#CURSOR_HELP
*/
public static final CursorProvider HELP;
/**
* @see SWT#CURSOR_IBEAM
*/
public static final CursorProvider IBEAM;
/**
* @see SWT#CURSOR_NO
*/
public static final CursorProvider NO;
/**
* @see SWT#CURSOR_SIZEALL
*/
public static final CursorProvider SIZEALL;
/**
* @see SWT#CURSOR_SIZENESW
*/
public static final CursorProvider SIZENESW;
/**
* @see SWT#CURSOR_SIZENWSE
*/
public static final CursorProvider SIZENWSE;
/**
* @see SWT#CURSOR_SIZEWE
*/
public static final CursorProvider SIZEWE;
/**
* @see SWT#CURSOR_SIZENS
*/
public static final CursorProvider SIZENS;
/**
* @see SWT#CURSOR_UPARROW
*/
public static final CursorProvider UPARROW;
/**
* @see SWT#CURSOR_WAIT
*/
public static final CursorProvider WAIT;

static {
ARROW = new SystemCursorProvider(SWT.CURSOR_ARROW);
SIZEN = new SystemCursorProvider(SWT.CURSOR_SIZEN);
SIZENE = new SystemCursorProvider(SWT.CURSOR_SIZENE);
SIZEE = new SystemCursorProvider(SWT.CURSOR_SIZEE);
SIZESE = new SystemCursorProvider(SWT.CURSOR_SIZESE);
SIZES = new SystemCursorProvider(SWT.CURSOR_SIZES);
SIZESW = new SystemCursorProvider(SWT.CURSOR_SIZESW);
SIZEW = new SystemCursorProvider(SWT.CURSOR_SIZEW);
SIZENW = new SystemCursorProvider(SWT.CURSOR_SIZENW);
SIZENS = new SystemCursorProvider(SWT.CURSOR_SIZENS);
SIZEWE = new SystemCursorProvider(SWT.CURSOR_SIZEWE);
APPSTARTING = new SystemCursorProvider(SWT.CURSOR_APPSTARTING);
CROSS = new SystemCursorProvider(SWT.CURSOR_CROSS);
HAND = new SystemCursorProvider(SWT.CURSOR_HAND);
HELP = new SystemCursorProvider(SWT.CURSOR_HELP);
IBEAM = new SystemCursorProvider(SWT.CURSOR_IBEAM);
NO = new SystemCursorProvider(SWT.CURSOR_NO);
SIZEALL = new SystemCursorProvider(SWT.CURSOR_SIZEALL);
SIZENESW = new SystemCursorProvider(SWT.CURSOR_SIZENESW);
SIZENWSE = new SystemCursorProvider(SWT.CURSOR_SIZENWSE);
UPARROW = new SystemCursorProvider(SWT.CURSOR_UPARROW);
WAIT = new SystemCursorProvider(SWT.CURSOR_WAIT);
}

}
10 changes: 9 additions & 1 deletion org.eclipse.draw2d/src/org/eclipse/draw2d/Cursors.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 IBM Corporation and others.
* Copyright (c) 2000, 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
Expand All @@ -18,7 +18,15 @@

/**
* A collection of cursors.
*
* @deprecated Using static cursors is fundamentally flawed when considering
* dynamic DPI changes. The static cursors created by this class are
* created with respect to the current display zoom. Those objects
* are not updated, should this value change at a later time.
* Clients need to listen to the {@link SWT#ZoomChanged} event and
* update their cursors via {@link CursorProviders}.
*/
@Deprecated(since = "3.17", forRemoval = true)
public class Cursors {

/**
Expand Down
Loading
Loading