当前位置: 首页>>代码示例>>Java>>正文


Java Rectangle.translate方法代码示例

本文整理汇总了Java中java.awt.Rectangle.translate方法的典型用法代码示例。如果您正苦于以下问题:Java Rectangle.translate方法的具体用法?Java Rectangle.translate怎么用?Java Rectangle.translate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Rectangle的用法示例。


在下文中一共展示了Rectangle.translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getClipBounds

import java.awt.Rectangle; //导入方法依赖的package包/类
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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:SunGraphics2D.java

示例2: transformShape

import java.awt.Rectangle; //导入方法依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:SunGraphics2D.java

示例3: setShellResizable

import java.awt.Rectangle; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:XWM.java

示例4: scrollAtEdge

import java.awt.Rectangle; //导入方法依赖的package包/类
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);
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:25,代码来源:SetupStack.java

示例5: computeBounds

import java.awt.Rectangle; //导入方法依赖的package包/类
/** 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:50,代码来源:PopupManager.java

示例6: repaintChildren

import java.awt.Rectangle; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:15,代码来源:LWContainerPeer.java

示例7: setShellResizable

import java.awt.Rectangle; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:XWM.java

示例8: boundingBox

import java.awt.Rectangle; //导入方法依赖的package包/类
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;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:9,代码来源:ColoredBorder.java

示例9: boundingBox

import java.awt.Rectangle; //导入方法依赖的package包/类
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;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:13,代码来源:Deck.java

示例10: getScreenBounds

import java.awt.Rectangle; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:16,代码来源:Info.java

示例11: dragGestureRecognized

import java.awt.Rectangle; //导入方法依赖的package包/类
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);
      }
    }
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:34,代码来源:SetupStack.java

示例12: boundingBox

import java.awt.Rectangle; //导入方法依赖的package包/类
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;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:14,代码来源:SelectionHighlighter.java

示例13: getTextBounds

import java.awt.Rectangle; //导入方法依赖的package包/类
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;
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:41,代码来源:GraphicsUtil.java

示例14: selectionBoundsOf

import java.awt.Rectangle; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:20,代码来源:Map.java

示例15: scroll

import java.awt.Rectangle; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:13,代码来源:Map.java


注:本文中的java.awt.Rectangle.translate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。