Java Code Examples for java.awt.Rectangle#OUT_BOTTOM

The following examples show how to use java.awt.Rectangle#OUT_BOTTOM . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JFrame_Main.java    From MobyDroid with Apache License 2.0 4 votes vote down vote up
@Override
public void mouseDragged(MouseEvent me) {
    // dragging
    if (dragging) {
        int x = me.getXOnScreen();
        int y = me.getYOnScreen();
        // Move frame by the mouse delta
        setLocation(getLocationOnScreen().x + x - prevX, getLocationOnScreen().y + y - prevY);
        prevX = x;
        prevY = y;
    }
    // resizing
    if (resizing) {
        Component component = me.getComponent();
        Rectangle rect = prevR;
        int xInc = me.getXOnScreen() - prevX;
        int yInc = me.getYOnScreen() - prevY;

        //  Resizing the West or North border affects the size and location
        switch (outcode) {
            case Rectangle.OUT_TOP:
                rect.y += yInc;
                rect.height -= yInc;
                break;
            case Rectangle.OUT_TOP + Rectangle.OUT_LEFT:
                rect.y += yInc;
                rect.height -= yInc;
                rect.x += xInc;
                rect.width -= xInc;
                break;
            case Rectangle.OUT_LEFT:
                rect.x += xInc;
                rect.width -= xInc;
                break;
            case Rectangle.OUT_LEFT + Rectangle.OUT_BOTTOM:
                rect.height += yInc;
                rect.x += xInc;
                rect.width -= xInc;
                break;
            case Rectangle.OUT_BOTTOM:
                rect.height += yInc;
                break;
            case Rectangle.OUT_BOTTOM + Rectangle.OUT_RIGHT:
                rect.height += yInc;
                rect.width += xInc;
                break;
            case Rectangle.OUT_RIGHT:
                rect.width += xInc;
                break;
            case Rectangle.OUT_RIGHT + Rectangle.OUT_TOP:
                rect.y += yInc;
                rect.height -= yInc;
                rect.width += xInc;
                break;
            default:
                break;
        }

        prevX = me.getXOnScreen();
        prevY = me.getYOnScreen();

        component.setBounds(rect);
        component.validate();
        component.repaint();
    }
}
 
Example 2
Source File: JFrame_Main.java    From MobyDroid with Apache License 2.0 4 votes vote down vote up
@Override
public void mouseMoved(MouseEvent me) {
    Component component = me.getComponent();
    Point point = me.getPoint();

    // Locate cursor relative to center of rect.
    Rectangle rect = new Rectangle(component.getSize());
    switch (getOutcode(point, new Rectangle(component.getSize()))) {
        case Rectangle.OUT_TOP:
            if (Math.abs(point.y - rect.y) < PROX_DIST) {
                component.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
            }
            break;
        case Rectangle.OUT_TOP + Rectangle.OUT_LEFT:
            if (Math.abs(point.y - rect.y) < PROX_DIST && Math.abs(point.x - rect.x) < PROX_DIST) {
                component.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
            }
            break;
        case Rectangle.OUT_LEFT:
            if (Math.abs(point.x - rect.x) < PROX_DIST) {
                component.setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
            }
            break;
        case Rectangle.OUT_LEFT + Rectangle.OUT_BOTTOM:
            if (Math.abs(point.x - rect.x) < PROX_DIST && Math.abs(point.y - (rect.y + rect.height)) < PROX_DIST) {
                component.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
            }
            break;
        case Rectangle.OUT_BOTTOM:
            if (Math.abs(point.y - (rect.y + rect.height)) < PROX_DIST) {
                component.setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
            }
            break;
        case Rectangle.OUT_BOTTOM + Rectangle.OUT_RIGHT:
            if (Math.abs(point.x - (rect.x + rect.width)) < PROX_DIST && Math.abs(point.y - (rect.y + rect.height)) < PROX_DIST) {
                component.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
            }
            break;
        case Rectangle.OUT_RIGHT:
            if (Math.abs(point.x - (rect.x + rect.width)) < PROX_DIST) {
                component.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
            }
            break;
        case Rectangle.OUT_RIGHT + Rectangle.OUT_TOP:
            if (Math.abs(point.x - (rect.x + rect.width)) < PROX_DIST && Math.abs(point.y - rect.y) < PROX_DIST) {
                component.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
            }
            break;
        default:    // center
            component.setCursor(Cursor.getDefaultCursor());
    }
}
 
Example 3
Source File: OverlayRenderer.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public MouseEvent mouseMoved(MouseEvent mouseEvent)
{
	if (!inOverlayManagingMode)
	{
		return mouseEvent;
	}

	final Point mousePoint = mouseEvent.getPoint();
	mousePosition.setLocation(mousePoint);

	if (!inOverlayResizingMode && !inOverlayDraggingMode)
	{
		currentManagedOverlay = null;

		synchronized (overlayManager)
		{
			for (Overlay overlay : overlayManager.getOverlays())
			{
				final Rectangle bounds = overlay.getBounds();
				if (bounds.contains(mousePoint))
				{
					currentManagedOverlay = overlay;
					break;
				}
			}
		}
	}

	if (currentManagedOverlay == null || !currentManagedOverlay.isResizable())
	{
		clientUI.setCursor(clientUI.getDefaultCursor());
		return mouseEvent;
	}

	final Rectangle toleranceRect = new Rectangle(currentManagedOverlay.getBounds());
	toleranceRect.grow(-OVERLAY_RESIZE_TOLERANCE, -OVERLAY_RESIZE_TOLERANCE);
	final int outcode = toleranceRect.outcode(mouseEvent.getPoint());

	switch (outcode)
	{
		case Rectangle.OUT_TOP:
			clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
			break;
		case Rectangle.OUT_TOP | Rectangle.OUT_LEFT:
			clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
			break;
		case Rectangle.OUT_LEFT:
			clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
			break;
		case Rectangle.OUT_LEFT | Rectangle.OUT_BOTTOM:
			clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
			break;
		case Rectangle.OUT_BOTTOM:
			clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
			break;
		case Rectangle.OUT_BOTTOM | Rectangle.OUT_RIGHT:
			clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
			break;
		case Rectangle.OUT_RIGHT:
			clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
			break;
		case Rectangle.OUT_RIGHT | Rectangle.OUT_TOP:
			clientUI.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
			break;
		default:
			// center
			clientUI.setCursor(clientUI.getDefaultCursor());
	}

	return mouseEvent;
}