java.awt.Rectangle#OUT_BOTTOM源码实例Demo

下面列出了java.awt.Rectangle#OUT_BOTTOM 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MobyDroid   文件: JFrame_Main.java
@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();
    }
}
 
源代码2 项目: MobyDroid   文件: JFrame_Main.java
@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());
    }
}
 
源代码3 项目: runelite   文件: OverlayRenderer.java
@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;
}