Java Code Examples for java.awt.Rectangle.translate()

The following are Jave code examples for showing how to use translate() of the java.awt.Rectangle class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OpenJSharp   File: SunGraphics2D.java   View Source Code Vote up 7 votes
public Rectangle getClipBounds(Rectangle r) {
    if (clipState != CLIP_DEVICE) {
        if (transformState <= TRANSFORM_INT_TRANSLATE) {
            if (usrClip instanceof Rectangle) {
                r.setBounds((Rectangle) usrClip);
            } else {
                r.setFrame(usrClip.getBounds2D());
            }
            r.translate(-transX, -transY);
        } else {
            r.setFrame(getClip().getBounds2D());
        }
    } else if (r == null) {
        throw new NullPointerException("null rectangle parameter");
    }
    return r;
}
 
Example 2
Project: openjdk-jdk10   File: SunGraphics2D.java   View Source Code Vote up 6 votes
protected static Shape transformShape(int tx, int ty, Shape s) {
    if (s == null) {
        return null;
    }

    if (s instanceof Rectangle) {
        Rectangle r = s.getBounds();
        r.translate(tx, ty);
        return r;
    }
    if (s instanceof Rectangle2D) {
        Rectangle2D rect = (Rectangle2D) s;
        return new Rectangle2D.Double(rect.getX() + tx,
                                      rect.getY() + ty,
                                      rect.getWidth(),
                                      rect.getHeight());
    }

    if (tx == 0 && ty == 0) {
        return cloneShape(s);
    }

    AffineTransform mat = AffineTransform.getTranslateInstance(tx, ty);
    return mat.createTransformedShape(s);
}
 
Example 3
Project: OpenJSharp   File: XWM.java   View Source Code Vote up 6 votes
static void setShellResizable(XDecoratedPeer window) {
    if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
        insLog.fine("Setting shell resizable " + window);
    }
    XToolkit.awtLock();
    try {
        Rectangle shellBounds = window.getShellBounds();
        shellBounds.translate(-window.currentInsets.left, -window.currentInsets.top);
        window.updateSizeHints(window.getDimensions());
        requestWMExtents(window.getWindow());
        XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), window.getShell(),
                                      shellBounds.x, shellBounds.y, shellBounds.width, shellBounds.height);
        /* REMINDER: will need to revisit when setExtendedStateBounds is added */
        //Fix for 4320050: Minimum size for java.awt.Frame is not being enforced.
        //We need to update frame's minimum size, not to reset it
        removeSizeHints(window, XUtilConstants.PMaxSize);
        window.updateMinimumSize();

        /* Restore decorations */
        setShellDecor(window);
    } finally {
        XToolkit.awtUnlock();
    }
}
 
Example 4
Project: VASSAL-src   File: SetupStack.java   View Source Code Vote up 6 votes
public void scrollAtEdge(Point evtPt, int dist) {
  JScrollPane scroll = myStack.stackConfigurer.getScroll();

  Point p = new Point(evtPt.x - scroll.getViewport().getViewPosition().x,
      evtPt.y - scroll.getViewport().getViewPosition().y);
  int dx = 0, dy = 0;
  if (p.x < dist && p.x >= 0)
    dx = -1;
  if (p.x >= scroll.getViewport().getSize().width - dist
      && p.x < scroll.getViewport().getSize().width)
    dx = 1;
  if (p.y < dist && p.y >= 0)
    dy = -1;
  if (p.y >= scroll.getViewport().getSize().height - dist
      && p.y < scroll.getViewport().getSize().height)
    dy = 1;

  if (dx != 0 || dy != 0) {
    Rectangle r = new Rectangle(scroll.getViewport().getViewRect());
    r.translate(2 * dist * dx, 2 * dist * dy);
    r = r.intersection(new Rectangle(new Point(0, 0), getPreferredSize()));
    scrollRectToVisible(r);
  }
}
 
Example 5
Project: OpenJSharp   File: SunGraphics2D.java   View Source Code Vote up 6 votes
protected static Shape transformShape(int tx, int ty, Shape s) {
    if (s == null) {
        return null;
    }

    if (s instanceof Rectangle) {
        Rectangle r = s.getBounds();
        r.translate(tx, ty);
        return r;
    }
    if (s instanceof Rectangle2D) {
        Rectangle2D rect = (Rectangle2D) s;
        return new Rectangle2D.Double(rect.getX() + tx,
                                      rect.getY() + ty,
                                      rect.getWidth(),
                                      rect.getHeight());
    }

    if (tx == 0 && ty == 0) {
        return cloneShape(s);
    }

    AffineTransform mat = AffineTransform.getTranslateInstance(tx, ty);
    return mat.createTransformedShape(s);
}
 
Example 6
Project: openjdk-jdk10   File: SunGraphics2D.java   View Source Code Vote up 6 votes
public Rectangle getClipBounds(Rectangle r) {
    if (clipState != CLIP_DEVICE) {
        if (transformState <= TRANSFORM_INT_TRANSLATE) {
            if (usrClip instanceof Rectangle) {
                r.setBounds((Rectangle) usrClip);
            } else {
                r.setFrame(usrClip.getBounds2D());
            }
            r.translate(-transX, -transY);
        } else {
            r.setFrame(getClip().getBounds2D());
        }
    } else if (r == null) {
        throw new NullPointerException("null rectangle parameter");
    }
    return r;
}
 
Example 7
Project: jdk8u-jdk   File: XWM.java   View Source Code Vote up 6 votes
static void setShellResizable(XDecoratedPeer window) {
    if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
        insLog.fine("Setting shell resizable " + window);
    }
    XToolkit.awtLock();
    try {
        Rectangle shellBounds = window.getShellBounds();
        shellBounds.translate(-window.currentInsets.left, -window.currentInsets.top);
        window.updateSizeHints(window.getDimensions());
        requestWMExtents(window.getWindow());
        XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), window.getShell(),
                                      shellBounds.x, shellBounds.y, shellBounds.width, shellBounds.height);
        /* REMINDER: will need to revisit when setExtendedStateBounds is added */
        //Fix for 4320050: Minimum size for java.awt.Frame is not being enforced.
        //We need to update frame's minimum size, not to reset it
        removeSizeHints(window, XUtilConstants.PMaxSize);
        window.updateMinimumSize();

        /* Restore decorations */
        setShellDecor(window);
    } finally {
        XToolkit.awtUnlock();
    }
}
 
Example 8
Project: incubator-netbeans   File: PopupManager.java   View Source Code Vote up 5 votes
/** Variation of the method for computing the bounds
 * for the concrete view component. As the component can possibly
 * be placed in a scroll pane it's first necessary
 * to translate the cursor bounds and also translate
 * back the resulting popup bounds.
 * @param popup  popup panel to be displayed
 * @param view component over which the popup is displayed.
 * @param cursorBounds the bounds of the caret or mouse cursor
 *    relative to the upper-left corner of the visible view.
 * @param placement where to place the popup panel according to
 *    the cursor position.
 * @return bounds of popup panel relative to the upper-left corner
 *    of the underlying view component.
 *    <CODE>null</CODE> if there is no place to display popup.
 */
protected static Rectangle computeBounds(JComponent popup,
JComponent view, Rectangle cursorBounds, Placement placement, HorizontalBounds horizontalBounds) {
    
    if (horizontalBounds == null) horizontalBounds = ViewPortBounds;
    
    Rectangle ret;
    Component viewParent = view.getParent();
    
    if (viewParent instanceof JLayeredPane) {
        viewParent = viewParent.getParent();
    }
    
    if (viewParent instanceof JViewport) {
        Rectangle viewBounds = ((JViewport)viewParent).getViewRect();

        Rectangle translatedCursorBounds = (Rectangle)cursorBounds.clone();
        if (placement != FixedPoint) {
            translatedCursorBounds.translate(-viewBounds.x, -viewBounds.y);
        }

        ret = computeBounds(popup, viewBounds.width, viewBounds.height,
            translatedCursorBounds, placement, horizontalBounds);
        
        if (ret != null) { // valid bounds
            ret.translate(viewBounds.x, viewBounds.y);
        }
        
    } else { // not in scroll pane
        ret = computeBounds(popup, view.getWidth(), view.getHeight(),
            cursorBounds, placement);
    }
    
    return ret;
}
 
Example 9
Project: jdk8u-jdk   File: LWContainerPeer.java   View Source Code Vote up 5 votes
/**
 * Paints all the child peers in the straight z-order, so the
 * bottom-most ones are painted first.
 */
private void repaintChildren(final Rectangle r) {
    final Rectangle content = getContentSize();
    for (final LWComponentPeer<?, ?> child : getChildren()) {
        final Rectangle childBounds = child.getBounds();
        Rectangle toPaint = r.intersection(childBounds);
        toPaint = toPaint.intersection(content);
        toPaint.translate(-childBounds.x, -childBounds.y);
        child.repaintPeer(toPaint);
    }
}
 
Example 10
Project: openjdk-jdk10   File: XWM.java   View Source Code Vote up 5 votes
static void setShellResizable(XDecoratedPeer window) {
    if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
        insLog.fine("Setting shell resizable " + window);
    }
    XToolkit.awtLock();
    try {
        Rectangle shellBounds;
        if (getWMID() != UNITY_COMPIZ_WM) {
            shellBounds = window.getShellBounds();
            shellBounds.translate(-window.currentInsets.left,
                                  -window.currentInsets.top);
        } else {
            shellBounds = window.getDimensions().getScreenBounds();
        }
        window.updateSizeHints(window.getDimensions());
        requestWMExtents(window.getWindow());
        XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(),
                                      window.getShell(),
                                      window.scaleUp(shellBounds.x),
                                      window.scaleUp(shellBounds.y),
                                      window.scaleUp(shellBounds.width),
                                      window.scaleUp(shellBounds.height));
        /* REMINDER: will need to revisit when setExtendedStateBounds is added */
        //Fix for 4320050: Minimum size for java.awt.Frame is not being enforced.
        //We need to update frame's minimum size, not to reset it
        removeSizeHints(window, XUtilConstants.PMaxSize);
        window.updateMinimumSize();

        /* Restore decorations */
        setShellDecor(window);
    } finally {
        XToolkit.awtUnlock();
    }
}
 
Example 11
Project: VASSAL-src   File: ColoredBorder.java   View Source Code Vote up 5 votes
public Rectangle boundingBox(GamePiece p) {
  final Rectangle r = p.getShape().getBounds();
  r.translate(-thickness, -thickness);
  r.setSize(r.width + 2 * thickness, r.height + 2 * thickness);

  for (Highlighter h : highlighters) r.add(h.boundingBox(p));
  return r;
}
 
Example 12
Project: VASSAL-src   File: Deck.java   View Source Code Vote up 5 votes
public Rectangle boundingBox() {
  GamePiece top = topPiece();
  Dimension d = top == null ? size : top.getShape().getBounds().getSize();
  Rectangle r = new Rectangle(new Point(), d);
  r.translate(-r.width / 2, -r.height / 2);
  for (int i=0,n=getMaximumVisiblePieceCount();i<n;++i) {
    r.y -= 2;
    r.height += 2;
    r.width += 2;
  }
  return r;
}
 
Example 13
Project: VASSAL-src   File: Info.java   View Source Code Vote up 5 votes
/**
 * Get size of screen accounting for the screen insets (i.e. Windows taskbar)
 *
 * @return
 */
public static Rectangle getScreenBounds(Component c) {
  final Rectangle bounds =
    new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
  final GraphicsConfiguration config = c.getGraphicsConfiguration();
  final Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(config);
  bounds.translate(insets.left, insets.top);
  bounds.setSize(bounds.width - insets.left - insets.right,
                 bounds.height - insets.top - insets.bottom);
  return bounds;
}
 
Example 14
Project: VASSAL-src   File: SetupStack.java   View Source Code Vote up 5 votes
public void dragGestureRecognized(DragGestureEvent dge) {

      Point mousePosition = dge.getDragOrigin();
      Point piecePosition = new Point(myStack.pos);

      // Check drag starts inside piece
      Rectangle r = myStack.stackConfigurer.getPieceBoundingBox();
      r.translate(piecePosition.x, piecePosition.y);
      if (!r.contains(mousePosition)) {
        return;
      }

      originalPieceOffsetX = piecePosition.x - mousePosition.x;
      originalPieceOffsetY = piecePosition.y - mousePosition.y;

      drawWin = null;

      makeDragCursor();
      setDragCursor();

      SwingUtilities.convertPointToScreen(mousePosition, drawWin);
      moveDragCursor(mousePosition.x, mousePosition.y);

      // begin dragging
      try {
        dge.startDrag(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR),
                      new StringSelection(""), this); // DEBUG
        dge.getDragSource().addDragSourceMotionListener(this);
      }
      catch (InvalidDnDOperationException e) {
        ErrorDialog.bug(e);
      }
    }
 
Example 15
Project: VASSAL-src   File: SelectionHighlighter.java   View Source Code Vote up 5 votes
public Rectangle boundingBox(GamePiece p) {
  final Rectangle r = p.getShape().getBounds();
  if (accept(p)) {
    if (useImage) {
      r.add(ImageUtils.getBounds(imagePainter.getImageSize()));
    }
    else {
      r.translate(-thickness, -thickness);
      r.setSize(r.width + 2 * thickness, r.height + 2 * thickness);
    }
  }
  return r;
}
 
Example 16
Project: Logisim   File: GraphicsUtil.java   View Source Code Vote up 5 votes
static public Rectangle getTextBounds(Graphics g, String text, int x, int y, int halign, int valign) {
	if (g == null)
		return new Rectangle(x, y, 0, 0);
	FontMetrics mets = g.getFontMetrics();
	int width = mets.stringWidth(text);
	int ascent = mets.getAscent();
	int descent = mets.getDescent();
	int height = ascent + descent;

	Rectangle ret = new Rectangle(x, y, width, height);
	switch (halign) {
	case H_CENTER:
		ret.translate(-(width / 2), 0);
		break;
	case H_RIGHT:
		ret.translate(-width, 0);
		break;
	default:
		;
	}
	switch (valign) {
	case V_TOP:
		break;
	case V_CENTER:
		ret.translate(0, -(ascent / 2));
		break;
	case V_CENTER_OVERALL:
		ret.translate(0, -(height / 2));
		break;
	case V_BASELINE:
		ret.translate(0, -ascent);
		break;
	case V_BOTTOM:
		ret.translate(0, -height);
		break;
	default:
		;
	}
	return ret;
}
 
Example 17
Project: VASSAL-src   File: Map.java   View Source Code Vote up 5 votes
/**
 * Returns the selection bounding box of a GamePiece accounting for the offset of a piece within a stack
 *
 * @see GamePiece#getShape
 */
public Rectangle selectionBoundsOf(GamePiece p) {
  if (p.getMap() != this) {
    throw new IllegalArgumentException(
      Resources.getString("Map.piece_not_on_map")); //$NON-NLS-1$
  }

  final Rectangle r = p.getShape().getBounds();
  r.translate(p.getPosition().x, p.getPosition().y);
  if (p.getParent() != null) {
    Point pt = getStackMetrics().relativePosition(p.getParent(), p);
    r.translate(pt.x, pt.y);
  }
  return r;
}
 
Example 18
Project: VASSAL-src   File: Map.java   View Source Code Vote up 5 votes
/**
 * Scrolls the map in the containing JScrollPane.
 *
 * @param dx number of pixels to scroll horizontally
 * @param dy number of pixels to scroll vertically
 */
public void scroll(int dx, int dy) {
  Rectangle r = scroll.getViewport().getViewRect();
  r.translate(dx, dy);
  r = r.intersection(new Rectangle(getPreferredSize()));
  theMap.scrollRectToVisible(r);
}
 
Example 19
Project: OpenJSharp   File: CustomComponent.java   View Source Code Vote up 5 votes
public static Region getRegionOfInterest(SurfaceData src, SurfaceData dst,
                                         Region clip,
                                         int srcx, int srcy,
                                         int dstx, int dsty,
                                         int w, int h)
{
    /*
     * Intersect all of:
     *   - operation area (dstx, dsty, w, h)
     *   - destination bounds
     *   - (translated) src bounds
     *   - supplied clip (may be non-rectangular)
     * Intersect the rectangular regions first since those are
     * simpler operations.
     */
    Region ret = Region.getInstanceXYWH(dstx, dsty, w, h);
    ret = ret.getIntersection(dst.getBounds());
    Rectangle r = src.getBounds();
    // srcxy in src space maps to dstxy in dst space
    r.translate(dstx - srcx, dsty - srcy);
    ret = ret.getIntersection(r);
    if (clip != null) {
        // Intersect with clip last since it may be non-rectangular
        ret = ret.getIntersection(clip);
    }
    return ret;
}
 
Example 20
Project: openjdk-jdk10   File: CompositionArea.java   View Source Code Vote up 4 votes
Rectangle getTextLocation(TextHitInfo offset) {
    Rectangle rectangle = getCaretRectangle(offset);
    Point location = getLocationOnScreen();
    rectangle.translate(location.x, location.y);
    return rectangle;
}