public void mouseDragged(MouseEvent e) {
if ( startingBounds == null ) {
// (STEVE) Yucky work around for bug ID 4106552
return;
}
Point p = SwingUtilities.convertPoint((Component)e.getSource(),
e.getX(), e.getY(), null);
int deltaX = _x - p.x;
int deltaY = _y - p.y;
Dimension min = frame.getMinimumSize();
Dimension max = frame.getMaximumSize();
int newX, newY, newW, newH;
Insets i = frame.getInsets();
// Handle a MOVE
if (dragging) {
if (frame.isMaximum() || ((e.getModifiers() &
InputEvent.BUTTON1_MASK) !=
InputEvent.BUTTON1_MASK)) {
// don't allow moving of frames if maximixed or left mouse
// button was not used.
return;
}
int pWidth, pHeight;
Dimension s = frame.getParent().getSize();
pWidth = s.width;
pHeight = s.height;
newX = startingBounds.x - deltaX;
newY = startingBounds.y - deltaY;
// Make sure we stay in-bounds
if(newX + i.left < = -__x)
newX = -__x - i.left + 1;
if(newY + i.top < = -__y)
newY = -__y - i.top + 1;
if(newX + __x + i.right >= pWidth)
newX = pWidth - __x - i.right - 1;
if(newY + __y + i.bottom >= pHeight)
newY = pHeight - __y - i.bottom - 1;
getDesktopManager().dragFrame(frame, newX, newY);
return;
}
if(!frame.isResizable()) {
return;
}
newX = frame.getX();
newY = frame.getY();
newW = frame.getWidth();
newH = frame.getHeight();
parentBounds = frame.getParent().getBounds();
switch(resizeDir) {
case RESIZE_NONE:
return;
case NORTH:
if(startingBounds.height + deltaY < min.height)
deltaY = -(startingBounds.height - min.height);
else if(startingBounds.height + deltaY > max.height)
deltaY = max.height - startingBounds.height;
if (startingBounds.y - deltaY < 0) {deltaY = startingBounds.y;}
newX = startingBounds.x;
newY = startingBounds.y - deltaY;
newW = startingBounds.width;
newH = startingBounds.height + deltaY;
break;
case NORTH_EAST:
if(startingBounds.height + deltaY < min.height)
deltaY = -(startingBounds.height - min.height);
else if(startingBounds.height + deltaY > max.height)
deltaY = max.height - startingBounds.height;
if (startingBounds.y - deltaY < 0) {deltaY = startingBounds.y;}
if(startingBounds.width - deltaX < min.width)
deltaX = startingBounds.width - min.width;
else if(startingBounds.width - deltaX > max.width)
deltaX = -(max.width - startingBounds.width);
if (startingBounds.x + startingBounds.width - deltaX >
parentBounds.width) {
deltaX = startingBounds.x + startingBounds.width -
parentBounds.width;
}
newX = startingBounds.x;
newY = startingBounds.y - deltaY;
newW = startingBounds.width - deltaX;
newH = startingBounds.height + deltaY;
break;
case EAST:
if(startingBounds.width - deltaX < min.width)
deltaX = startingBounds.width - min.width;
else if(startingBounds.width - deltaX > max.width)
deltaX = -(max.width - startingBounds.width);
if (startingBounds.x + startingBounds.width - deltaX >
parentBounds.width) {
deltaX = startingBounds.x + startingBounds.width -
parentBounds.width;
}
newW = startingBounds.width - deltaX;
newH = startingBounds.height;
break;
case SOUTH_EAST:
if(startingBounds.width - deltaX < min.width)
deltaX = startingBounds.width - min.width;
else if(startingBounds.width - deltaX > max.width)
deltaX = -(max.width - startingBounds.width);
if (startingBounds.x + startingBounds.width - deltaX >
parentBounds.width) {
deltaX = startingBounds.x + startingBounds.width -
parentBounds.width;
}
if(startingBounds.height - deltaY < min.height)
deltaY = startingBounds.height - min.height;
else if(startingBounds.height - deltaY > max.height)
deltaY = -(max.height - startingBounds.height);
if (startingBounds.y + startingBounds.height - deltaY >
parentBounds.height) {
deltaY = startingBounds.y + startingBounds.height -
parentBounds.height ;
}
newW = startingBounds.width - deltaX;
newH = startingBounds.height - deltaY;
break;
case SOUTH:
if(startingBounds.height - deltaY < min.height)
deltaY = startingBounds.height - min.height;
else if(startingBounds.height - deltaY > max.height)
deltaY = -(max.height - startingBounds.height);
if (startingBounds.y + startingBounds.height - deltaY >
parentBounds.height) {
deltaY = startingBounds.y + startingBounds.height -
parentBounds.height ;
}
newW = startingBounds.width;
newH = startingBounds.height - deltaY;
break;
case SOUTH_WEST:
if(startingBounds.height - deltaY < min.height)
deltaY = startingBounds.height - min.height;
else if(startingBounds.height - deltaY > max.height)
deltaY = -(max.height - startingBounds.height);
if (startingBounds.y + startingBounds.height - deltaY >
parentBounds.height) {
deltaY = startingBounds.y + startingBounds.height -
parentBounds.height ;
}
if(startingBounds.width + deltaX < min.width)
deltaX = -(startingBounds.width - min.width);
else if(startingBounds.width + deltaX > max.width)
deltaX = max.width - startingBounds.width;
if (startingBounds.x - deltaX < 0) {
deltaX = startingBounds.x;
}
newX = startingBounds.x - deltaX;
newY = startingBounds.y;
newW = startingBounds.width + deltaX;
newH = startingBounds.height - deltaY;
break;
case WEST:
if(startingBounds.width + deltaX < min.width)
deltaX = -(startingBounds.width - min.width);
else if(startingBounds.width + deltaX > max.width)
deltaX = max.width - startingBounds.width;
if (startingBounds.x - deltaX < 0) {
deltaX = startingBounds.x;
}
newX = startingBounds.x - deltaX;
newY = startingBounds.y;
newW = startingBounds.width + deltaX;
newH = startingBounds.height;
break;
case NORTH_WEST:
if(startingBounds.width + deltaX < min.width)
deltaX = -(startingBounds.width - min.width);
else if(startingBounds.width + deltaX > max.width)
deltaX = max.width - startingBounds.width;
if (startingBounds.x - deltaX < 0) {
deltaX = startingBounds.x;
}
if(startingBounds.height + deltaY < min.height)
deltaY = -(startingBounds.height - min.height);
else if(startingBounds.height + deltaY > max.height)
deltaY = max.height - startingBounds.height;
if (startingBounds.y - deltaY < 0) {deltaY = startingBounds.y;}
newX = startingBounds.x - deltaX;
newY = startingBounds.y - deltaY;
newW = startingBounds.width + deltaX;
newH = startingBounds.height + deltaY;
break;
default:
return;
}
getDesktopManager().resizeFrame(frame, newX, newY, newW, newH);
}
|