Java Code Examples for java.awt.Rectangle#getCenterY()
The following examples show how to use
java.awt.Rectangle#getCenterY() .
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: Block.java From JavaGame with MIT License | 6 votes |
/** * �������ĵ� */ 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; }
Example 2
Source File: MultiResolutionSplashTest.java From hottub with GNU General Public License v2.0 | 6 votes |
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!"); } }
Example 3
Source File: TrasferHandling.java From niftyeditor with Apache License 2.0 | 6 votes |
@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; } }
Example 4
Source File: MultiResolutionSplashTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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!"); } }
Example 5
Source File: MultiResolutionSplashTest.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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!"); } }
Example 6
Source File: Utils.java From GVGAI_GYM with Apache License 2.0 | 6 votes |
/** * 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); }
Example 7
Source File: PreviewPanel.java From swingsane with Apache License 2.0 | 5 votes |
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; }
Example 8
Source File: ProcessDiagramCanvas.java From maven-framework-project with MIT License | 5 votes |
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); }
Example 9
Source File: MultiResolutionSplashTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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!"); } }
Example 10
Source File: DiagramScene.java From hottub with GNU General Public License v2.0 | 5 votes |
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; }
Example 11
Source File: FruchtermanReingoldLayout.java From netbeans with Apache License 2.0 | 5 votes |
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); }
Example 12
Source File: MultiResolutionSplashTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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!"); } }
Example 13
Source File: DiagramScene.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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; }
Example 14
Source File: ImageModeCanvas.java From niftyeditor with Apache License 2.0 | 5 votes |
@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; } }
Example 15
Source File: MultiResolutionSplashTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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!"); } }
Example 16
Source File: DiagramScene.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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; }
Example 17
Source File: ProcessDiagramCanvas.java From maven-framework-project with MIT License | 5 votes |
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); }
Example 18
Source File: MultiResolutionSplashTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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!"); } }
Example 19
Source File: AMCChecker.java From PUMA with Apache License 2.0 | 5 votes |
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); }
Example 20
Source File: ProcessPanel.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
/** 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; }