Mouse cursor must keep the resize shape while resizing. In the previous
version it was spontaneously reverting to the default cursor and the
areas of the XY resizes (at corners) were smaller than visible resize
controls.
2006-05-16 Audrius Meskauskas <[EMAIL PROTECTED]>
* javax/swing/plaf/basic/BasicInternalFrameUI.java
(BorderListener): Rewritten. (InternalFrameBorder):
Made package private.
(InternalFrameBorder.offset):
Renamed to cornerSize, made package private.
(bSize): Made package private.
Index: BasicInternalFrameUI.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/plaf/basic/BasicInternalFrameUI.java,v
retrieving revision 1.33
diff -u -r1.33 BasicInternalFrameUI.java
--- BasicInternalFrameUI.java 10 May 2006 21:18:42 -0000 1.33
+++ BasicInternalFrameUI.java 16 May 2006 08:16:16 -0000
@@ -168,10 +168,9 @@
implements SwingConstants
{
/**
- * If true, the cursor is being already shown in the alternative "resize"
- * shape.
+ * The current shape of the cursor.
*/
- transient boolean showingResizeCursor;
+ transient int showingCursor;
/** FIXME: Use for something. */
protected final int RESIZE_NONE = 0;
@@ -187,7 +186,7 @@
/** Cache rectangle that can be reused. */
private transient Rectangle cacheRect = new Rectangle();
-
+
/**
* This method is called when the mouse is clicked.
*
@@ -223,34 +222,34 @@
{
switch (direction)
{
- case NORTH:
+ case Cursor.N_RESIZE_CURSOR:
cacheRect.setBounds(b.x, Math.min(b.y + y, b.y + b.height
- min.height),
b.width, b.height - y);
break;
- case NORTH_EAST:
+ case Cursor.NE_RESIZE_CURSOR:
cacheRect.setBounds(b.x, Math.min(b.y + y, b.y + b.height
- - min.height), x,
+ - min.height), x + 1,
b.height - y);
break;
- case EAST:
- cacheRect.setBounds(b.x, b.y, x, b.height);
+ case Cursor.E_RESIZE_CURSOR:
+ cacheRect.setBounds(b.x, b.y, x + 1, b.height);
break;
- case SOUTH_EAST:
- cacheRect.setBounds(b.x, b.y, x, y);
+ case Cursor.SE_RESIZE_CURSOR:
+ cacheRect.setBounds(b.x, b.y, x + 1, y + 1);
break;
- case SOUTH:
- cacheRect.setBounds(b.x, b.y, b.width, y);
+ case Cursor.S_RESIZE_CURSOR:
+ cacheRect.setBounds(b.x, b.y, b.width, y + 1);
break;
- case SOUTH_WEST:
+ case Cursor.SW_RESIZE_CURSOR:
cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
- b.y, b.width - x, y);
+ b.y, b.width - x, y + 1);
break;
- case WEST:
+ case Cursor.W_RESIZE_CURSOR:
cacheRect.setBounds(Math.min(b.x + x, b.x + b.width - min.width),
b.y, b.width - x, b.height);
break;
- case NORTH_WEST:
+ case Cursor.NW_RESIZE_CURSOR:
cacheRect.setBounds(
Math.min(b.x + x, b.x + b.width - min.width),
Math.min(b.y + y, b.y + b.height - min.height),
@@ -268,6 +267,7 @@
dm.dragFrame(frame, e.getX() - xOffset + b.x, e.getY() - yOffset
+ b.y);
}
+ setCursor(e);
}
/**
@@ -277,11 +277,10 @@
*/
public void mouseExited(MouseEvent e)
{
- // Reset the cursor shape.
- if (showingResizeCursor)
+ if (showingCursor != Cursor.DEFAULT_CURSOR)
{
frame.setCursor(Cursor.getDefaultCursor());
- showingResizeCursor = false;
+ showingCursor = Cursor.DEFAULT_CURSOR;
}
}
@@ -293,53 +292,36 @@
public void mouseMoved(MouseEvent e)
{
// Turn off the resize cursor if we are in the frame header.
- if (showingResizeCursor && e.getSource() != frame)
+ if (showingCursor != Cursor.DEFAULT_CURSOR && e.getSource() != frame)
{
frame.setCursor(Cursor.getDefaultCursor());
- showingResizeCursor = false;
+ showingCursor = Cursor.DEFAULT_CURSOR;
}
else if (e.getSource()==frame && frame.isResizable())
{
- int cursor;
- switch (sectionOfClick(e.getX(), e.getY()))
- {
- case NORTH:
- cursor = Cursor.N_RESIZE_CURSOR;
- break;
- case NORTH_EAST:
- cursor = Cursor.NE_RESIZE_CURSOR;
- break;
- case EAST:
- cursor = Cursor.E_RESIZE_CURSOR;
- break;
- case SOUTH_EAST:
- cursor = Cursor.SE_RESIZE_CURSOR;
- break;
- case SOUTH:
- cursor = Cursor.S_RESIZE_CURSOR;
- break;
- case SOUTH_WEST:
- cursor = Cursor.SW_RESIZE_CURSOR;
- break;
- case WEST:
- cursor = Cursor.W_RESIZE_CURSOR;
- break;
- case NORTH_WEST:
- cursor = Cursor.NW_RESIZE_CURSOR;
- break;
- default:
- cursor = Cursor.DEFAULT_CURSOR;
- }
-
+ setCursor(e);
+ }
+ }
+
+ /**
+ * Set the mouse cursor, how applicable.
+ *
+ * @param e the current mouse event.
+ */
+ void setCursor(MouseEvent e)
+ {
+ int cursor = sectionOfClick(e.getX(), e.getY());
+ if (cursor != showingCursor)
+ {
Cursor resize = Cursor.getPredefinedCursor(cursor);
frame.setCursor(resize);
- showingResizeCursor = true;
+ showingCursor = cursor;
}
}
/**
* This method is called when the mouse is pressed.
- *
+ *
* @param e The MouseEvent.
*/
public void mousePressed(MouseEvent e)
@@ -383,6 +365,8 @@
dm.endDraggingFrame(frame);
frame.putClientProperty("bufferedDragging", null);
}
+
+ setCursor(e);
}
/**
@@ -392,30 +376,31 @@
* @param x The x coordinate of the MouseEvent.
* @param y The y coordinate of the MouseEvent.
*
- * @return The direction of the resize (a SwingConstant direction).
+ * @return The cursor constant, determining the resizing direction.
*/
private int sectionOfClick(int x, int y)
{
- Insets insets = frame.getInsets();
Rectangle b = frame.getBounds();
- if (x < insets.left && y < insets.top)
- return NORTH_WEST;
- else if (x > b.width - insets.right && y < insets.top)
- return NORTH_EAST;
- else if (x > b.width - insets.right && y > b.height - insets.bottom)
- return SOUTH_EAST;
- else if (x < insets.left && y > b.height - insets.bottom)
- return SOUTH_WEST;
- else if (y < insets.top)
- return NORTH;
- else if (x < insets.left)
- return WEST;
- else if (y > b.height - insets.bottom)
- return SOUTH;
- else if (x > b.width - insets.right)
- return EAST;
+ int corner = InternalFrameBorder.cornerSize;
+
+ if (x < corner && y < corner)
+ return Cursor.NW_RESIZE_CURSOR;
+ else if (x > b.width - corner && y < corner)
+ return Cursor.NE_RESIZE_CURSOR;
+ else if (x > b.width - corner && y > b.height - corner)
+ return Cursor.SE_RESIZE_CURSOR;
+ else if (x < corner && y > b.height - corner)
+ return Cursor.SW_RESIZE_CURSOR;
+ else if (y < corner)
+ return Cursor.N_RESIZE_CURSOR;
+ else if (x < corner)
+ return Cursor.W_RESIZE_CURSOR;
+ else if (y > b.height - corner)
+ return Cursor.S_RESIZE_CURSOR;
+ else if (x > b.width - corner)
+ return Cursor.E_RESIZE_CURSOR;
- return -1;
+ return Cursor.DEFAULT_CURSOR;
}
}
@@ -992,14 +977,18 @@
/**
* This helper class is the border for the JInternalFrame.
*/
- private class InternalFrameBorder extends AbstractBorder implements
+ class InternalFrameBorder extends AbstractBorder implements
UIResource
{
- /** The width of the border. */
- private static final int bSize = 5;
+ /**
+ * The width of the border.
+ */
+ static final int bSize = 5;
- /** The size of the corners. */
- private static final int offset = 10;
+ /**
+ * The size of the corners (also used by the mouse listener).
+ */
+ static final int cornerSize = 10;
/**
* This method returns whether the border is opaque.
@@ -1069,10 +1058,12 @@
g.fillRect(0, y3, b.width, bSize);
g.fillRect(x3, 0, bSize, b.height);
- g.fill3DRect(0, offset, bSize, b.height - 2 * offset, false);
- g.fill3DRect(offset, 0, b.width - 2 * offset, bSize, false);
- g.fill3DRect(offset, b.height - bSize, b.width - 2 * offset, bSize, false);
- g.fill3DRect(b.width - bSize, offset, bSize, b.height - 2 * offset, false);
+ g.fill3DRect(0, cornerSize, bSize, b.height - 2 * cornerSize, false);
+ g.fill3DRect(cornerSize, 0, b.width - 2 * cornerSize, bSize, false);
+ g.fill3DRect(cornerSize, b.height - bSize, b.width - 2 * cornerSize,
+ bSize, false);
+ g.fill3DRect(b.width - bSize, cornerSize, bSize,
+ b.height - 2 * cornerSize, false);
g.translate(-x, -y);
g.setColor(saved);