java.awt.Rectangle#getCenterY ( )源码实例Demo

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

源代码1 项目: JavaGame   文件: Block.java
/**
 * �������ĵ�
 */
public void updateCenterPoint() {
	minX = maxX = (int) squareList.get(0).getCenterX();
	minY = maxY = (int) squareList.get(0).getCenterY();
	for (Rectangle rect : squareList) {
		if (rect.getCenterX() < minX) {
			minX = (int) rect.getCenterX();
		} else if (rect.getCenterX() > maxX) {
			maxX = (int) rect.getCenterX();
		}
		if (rect.getCenterY() < minY) {
			minY = (int) rect.getCenterY();
		} else if (rect.getCenterY() > maxY) {
			maxY = (int) rect.getCenterY();
		}
	}
	center.x = (minX + maxX) / 2;
	center.y = (minY + maxY) / 2;
	x = minX - Constant.BLOCK_WIDTH / 2;
	y = minY - Constant.BLOCK_HEIGHT / 2;
}
 
源代码2 项目: hottub   文件: MultiResolutionSplashTest.java
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
源代码3 项目: jdk8u-jdk   文件: MultiResolutionSplashTest.java
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
源代码4 项目: jdk8u60   文件: MultiResolutionSplashTest.java
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
源代码5 项目: GVGAI_GYM   文件: Utils.java
/**
 *  Returns the Polygon for a triangle in the middle of the provided
 *  rect, pointing in the orientation
 *  (given as angle from upwards, or orientation vector)
 * @param rect rectangle with the location
 * @param orientation orientation of the sprite.
 * @return a polygon (triangle) with the specified orientation.
 */
public static Polygon triPoints(Rectangle rect, Direction orientation)
{
    Vector2d p1 = new Vector2d(rect.getCenterX()+orientation.x()*rect.getWidth()/3.0,
                               rect.getCenterY()+orientation.y()*rect.getHeight()/3.0);
    Vector2d p2 = new Vector2d(rect.getCenterX()+orientation.x()*rect.getWidth()/4.0,
                               rect.getCenterY()+orientation.y()*rect.getHeight()/4.0);
    Vector2d orthdir = new Vector2d(orientation.y(), -orientation.x());

    Vector2d p2a = new Vector2d(p2.x-orthdir.x*rect.getWidth()/6.0,
                                p2.y-orthdir.y*rect.getHeight()/6.0);
    Vector2d p2b = new Vector2d(p2.x+orthdir.x*rect.getWidth()/6.0,
                                p2.y+orthdir.y*rect.getHeight()/6.0);

    return new Polygon(new int[]{(int)p1.x, (int)p2a.x, (int)p2b.x},
                       new int[]{(int)p1.y, (int)p2a.y, (int)p2b.y}, 3);
}
 
源代码6 项目: niftyeditor   文件: TrasferHandling.java
@Override
public Transferable createTransferable(JComponent c) {
    if (c instanceof NWidget) {
        NWidget comp = (NWidget) c;
        return comp.getData();
    }
    if (!coping) {
        Rectangle rec = gui.getSelection().getFirst().getBounds();
        int a = (int) rec.getCenterX() - gui.getSelection().getFirst().getNiftyElement().getX();
        int b = (int) rec.getCenterY() - gui.getSelection().getFirst().getNiftyElement().getY();
        return new WidgetData(gui.getSelection().getFirst(), a, b);
    }
    
    if (copyTemplate != null) {
        return new WidgetData(copyTemplate, 0, 0);
    } else {
        return null;
    }

}
 
源代码7 项目: PUMA   文件: AMCChecker.java
private double get_distance(Rectangle r1, Rectangle r2) {
	double x1 = r1.getCenterX();
	double y1 = r1.getCenterY();

	double x2 = r2.getCenterX();
	double y2 = r2.getCenterY();

	double delta_x = Math.abs(x1 - x2);
	double delta_y = Math.abs(y1 - y2);

	return Math.sqrt(delta_x * delta_x + delta_y * delta_y);
}
 
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    if(splashBounds.width != IMAGE_WIDTH){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong width");
    }
    if(splashBounds.height != IMAGE_HEIGHT){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong height");
    }

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
public void drawCollapsedMarker(int x, int y, int width, int height) {
  // rectangle
  int rectangleWidth = MARKER_WIDTH;
  int rectangleHeight = MARKER_WIDTH;
  Rectangle rect = new Rectangle(x + (width - rectangleWidth) / 2, y + height - rectangleHeight - 3, rectangleWidth, rectangleHeight);
  g.draw(rect);

  // plus inside rectangle
  Line2D.Double line = new Line2D.Double(rect.getCenterX(), rect.getY() + 2, rect.getCenterX(), rect.getMaxY() - 2);
  g.draw(line);
  line = new Line2D.Double(rect.getMinX() + 2, rect.getCenterY(), rect.getMaxX() - 2, rect.getCenterY());
  g.draw(line);
}
 
源代码10 项目: TencentKona-8   文件: DiagramScene.java
private Point calcCenter(Rectangle r) {

        Point center = new Point((int) r.getCenterX(), (int) r.getCenterY());
        center.x -= getScrollPane().getViewport().getViewRect().width / 2;
        center.y -= getScrollPane().getViewport().getViewRect().height / 2;

        // Ensure to be within area
        center.x = Math.max(0, center.x);
        center.x = Math.min(getScrollPane().getViewport().getViewSize().width - getScrollPane().getViewport().getViewRect().width, center.x);
        center.y = Math.max(0, center.y);
        center.y = Math.min(getScrollPane().getViewport().getViewSize().height - getScrollPane().getViewport().getViewRect().height, center.y);

        return center;
    }
 
源代码11 项目: jdk8u_jdk   文件: MultiResolutionSplashTest.java
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    if(splashBounds.width != IMAGE_WIDTH){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong width");
    }
    if(splashBounds.height != IMAGE_HEIGHT){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong height");
    }

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
源代码12 项目: swingsane   文件: PreviewPanel.java
private Point getViewportMidpoint(JViewport viewport) {
  Point viewPosition = viewport.getViewPosition();
  Rectangle viewportRectangle = new Rectangle(viewPosition, viewport.getSize());
  Point viewportMidpoint = new Point((int) viewportRectangle.getCenterX(),
      (int) viewportRectangle.getCenterY());
  return viewportMidpoint;
}
 
源代码13 项目: niftyeditor   文件: ImageModeCanvas.java
@Override
 public void mouseMoved(MouseEvent e) {
     
     Rectangle selected = this.model.getRectangle();
     if(e.getX()>selected.getMaxX()-5 && e.getX()<selected.getMaxX()+5 
            && e.getY()>selected.getMaxY()-5
            && e.getY()<selected.getMaxY()+5
            ){
        
        e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
        curDir=DIR_SE;
    }else if(e.getX()==selected.getMinX() && (e.getY()<selected.getMaxY() && e.getY()>selected.getMinY() )){
        e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
        curDir=DIR_W;
    }else if(e.getX()==selected.getMaxX() && (e.getY()<selected.getMaxY() && e.getY()>selected.getMinY() )){
       e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
       curDir=DIR_E;
    }
    else if(e.getY()<selected.getMaxY()+5 && e.getY()>selected.getMaxY()-5 
            && (e.getX()<selected.getMaxX() && e.getX()>selected.getMinX() )){
         e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR)); 
         curDir=DIR_S;
    }
     else if(e.getY()==selected.getMinY() && (e.getX()<selected.getMaxX() && e.getX()>selected.getMinX() )){
         curDir=DIR_N;
         e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR)); 
}else if(e.getY()<selected.getCenterY()+10 &&
        e.getY()>selected.getCenterY()-10 && (e.getX()<(selected.getCenterX()+10) && e.getX()>selected.getCenterX()-10 )){
          e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 
          curDir = MOV;
     }
     else{
         e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 
         curDir=NOP;
     }
   }
 
源代码14 项目: openjdk-8   文件: DiagramScene.java
private Point calcCenter(Rectangle r) {

        Point center = new Point((int) r.getCenterX(), (int) r.getCenterY());
        center.x -= getScrollPane().getViewport().getViewRect().width / 2;
        center.y -= getScrollPane().getViewport().getViewRect().height / 2;

        // Ensure to be within area
        center.x = Math.max(0, center.x);
        center.x = Math.min(getScrollPane().getViewport().getViewSize().width - getScrollPane().getViewport().getViewRect().width, center.x);
        center.y = Math.max(0, center.y);
        center.y = Math.min(getScrollPane().getViewport().getViewSize().height - getScrollPane().getViewport().getViewRect().height, center.y);

        return center;
    }
 
源代码15 项目: openjdk-jdk8u   文件: MultiResolutionSplashTest.java
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    if(splashBounds.width != IMAGE_WIDTH){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong width");
    }
    if(splashBounds.height != IMAGE_HEIGHT){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong height");
    }

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
源代码16 项目: netbeans   文件: FruchtermanReingoldLayout.java
private void init() {
    int nds = scene.getNodes().size();
    bounds = new Rectangle(magicSizeConstant  + (magicSizeMultiplier * nds), 
                           magicSizeConstant  + (magicSizeMultiplier * nds)); //g.getMaximumBounds();
    temp = bounds.getWidth() / 10;
    forceConstant = 0.75 * Math.sqrt(bounds.getHeight() * bounds.getWidth() / nds);
    
    GraphNode<I> rn = scene.getRootGraphNode();
    NodeWidget rw = getWidget(rn);
    rw.locX = bounds.getCenterX();
    rw.locY = bounds.getCenterY();
    rw.setFixed(true);
    layoutCirculary(scene.getNodes(), rn);
}
 
源代码17 项目: hottub   文件: DiagramScene.java
private Point calcCenter(Rectangle r) {

        Point center = new Point((int) r.getCenterX(), (int) r.getCenterY());
        center.x -= getScrollPane().getViewport().getViewRect().width / 2;
        center.y -= getScrollPane().getViewport().getViewRect().height / 2;

        // Ensure to be within area
        center.x = Math.max(0, center.x);
        center.x = Math.min(getScrollPane().getViewport().getViewSize().width - getScrollPane().getViewport().getViewRect().width, center.x);
        center.y = Math.max(0, center.y);
        center.y = Math.min(getScrollPane().getViewport().getViewSize().height - getScrollPane().getViewport().getViewRect().height, center.y);

        return center;
    }
 
static void testSplash(ImageInfo test) throws Exception {
    SplashScreen splashScreen = SplashScreen.getSplashScreen();

    if (splashScreen == null) {
        throw new RuntimeException("Splash screen is not shown!");
    }

    Graphics2D g = splashScreen.createGraphics();
    Rectangle splashBounds = splashScreen.getBounds();
    int screenX = (int) splashBounds.getCenterX();
    int screenY = (int) splashBounds.getCenterY();

    if(splashBounds.width != IMAGE_WIDTH){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong width");
    }
    if(splashBounds.height != IMAGE_HEIGHT){
        throw new RuntimeException(
                "SplashScreen#getBounds has wrong height");
    }

    Robot robot = new Robot();
    Color splashScreenColor = robot.getPixelColor(screenX, screenY);

    float scaleFactor = getScaleFactor();
    Color testColor = (1 < scaleFactor) ? test.color2x : test.color1x;

    if (!compare(testColor, splashScreenColor)) {
        throw new RuntimeException(
                "Image with wrong resolution is used for splash screen!");
    }
}
 
public void drawCollapsedMarker(int x, int y, int width, int height) {
  // rectangle
  int rectangleWidth = MARKER_WIDTH;
  int rectangleHeight = MARKER_WIDTH;
  Rectangle rect = new Rectangle(x + (width - rectangleWidth) / 2, y + height - rectangleHeight - 3, rectangleWidth, rectangleHeight);
  g.draw(rect);

  // plus inside rectangle
  Line2D.Double line = new Line2D.Double(rect.getCenterX(), rect.getY() + 2, rect.getCenterX(), rect.getMaxY() - 2);
  g.draw(line);
  line = new Line2D.Double(rect.getMinX() + 2, rect.getCenterY(), rect.getMaxX() - 2, rect.getCenterY());
  g.draw(line);
}
 
源代码20 项目: rapidminer-studio   文件: ProcessPanel.java
/** Returns the center position of the current view. */
public Point getCurrentViewCenter() {
	Rectangle viewRect = getViewPort().getViewRect();
	Point center = new Point((int) viewRect.getCenterX(), (int) viewRect.getCenterY());
	return center;
}