Java Code Examples for java.awt.Rectangle#getCenterX()
The following examples show how to use
java.awt.Rectangle#getCenterX() .
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: 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 2
Source File: FGViewUpdater.java From ghidra with Apache License 2.0 | 6 votes |
public void regroupVertices(FGController controller, FGVertex vertex) { FGData functionGraphData = controller.getFunctionGraphData(); FunctionGraph functionGraph = functionGraphData.getFunctionGraph(); GroupHistoryInfo groupHistory = functionGraph.getGroupHistory(vertex); if (groupHistory == null) { throw new AssertException("Cannot find group history for regroup operation!"); } Set<FGVertex> vertices = new HashSet<>(groupHistory.getVertices()); Point2D location = groupHistory.getGroupLocation(); if (location == null) { FGView view = controller.getView(); VisualizationServer<FGVertex, FGEdge> viewer = view.getPrimaryGraphViewer(); Rectangle containingBounds = GraphViewerUtils.getBoundsForVerticesInLayoutSpace(viewer, vertices); location = new Point2D.Double(containingBounds.getCenterX(), containingBounds.getCenterY()); } fixupVerticesForUncollapsedGroupMembers(functionGraph, vertices); String text = groupHistory.getGroupDescription(); groupVertices(controller, text, vertices, location, true); }
Example 3
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 4
Source File: MultiResolutionSplashTest.java From openjdk-jdk9 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 5
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 6
Source File: DiagramScene.java From openjdk-jdk8u-backup 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 7
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 8
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 9
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 10
Source File: DiagramScene.java From openjdk-jdk8u 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: DefaultProcessDiagramCanvas.java From activiti6-boot2 with Apache License 2.0 | 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 12
Source File: HeadInter.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
/** * Shrink a bit a bounding bounds when checking for note overlap. * * @param box the bounding bounds * @return the shrunk bounds */ public static Rectangle2D shrink (Rectangle box) { double newWidth = constants.shrinkHoriRatio.getValue() * box.width; double newHeight = constants.shrinkVertRatio.getValue() * box.height; return new Rectangle2D.Double( box.getCenterX() - (newWidth / 2.0), box.getCenterY() - (newHeight / 2.0), newWidth, newHeight); }
Example 13
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 14
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 15
Source File: ProcessPanel.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * Scrolls the view to the specified {@link Operator}, making it the center of the view if * necessary, indicated by the flag. * * @param operator * the operator to focus on * @param toCenter * flag to indicate whether to force centering * @return whether the scrolling was successful * @since 7.5 * @see #scrollToViewPosition(Point) */ public boolean scrollToOperator(Operator operator, boolean toCenter) { Rectangle2D opRect = renderer.getModel().getOperatorRect(operator); if (opRect == null) { return false; } int pIndex = renderer.getProcessIndexOfOperator(operator); if (pIndex == -1) { return false; } Rectangle opViewRect = getOpViewRect(opRect, pIndex); Rectangle viewRect = getViewPort().getViewRect(); if (!toCenter) { if (viewRect.contains(opViewRect)) { // if operator visible, do nothing return false; } if (viewRect.intersects(opViewRect)) { // if partially visible, just scroll it into view opViewRect.translate(-viewRect.x, -viewRect.y); getViewPort().scrollRectToVisible(opViewRect); // return false nonetheless, see PortInfoBubble return false; } } Point opCenter = new Point((int) opViewRect.getCenterX(), (int) opViewRect.getCenterY()); scrollToViewPosition(opCenter); return true; }
Example 16
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 17
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 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: RoleCreateFrame.java From fight-game with MIT License | 5 votes |
public void showInCenter(JFrame parent) { Rectangle parentBounds = parent.getBounds(); double x = parentBounds.getCenterX() - 450 / 2.0; double y = parentBounds.getCenterY() - 300 / 2.0; // setLocation((int)x, (int)y); setBounds((int)x, (int)y, 450, 300); setVisible(true); }
Example 20
Source File: EnsureAreaVisibleAnimatorFunctionGraphJob.java From ghidra with Apache License 2.0 | 4 votes |
@Override protected Animator createAnimator() { Rectangle viewSpaceRectangle = GraphViewerUtils.translateRectangleFromVertexRelativeSpaceToViewSpace(viewer, vertex, visibleArea); // // Get the point to which we will move if any of the cursor is obscured // Point newPoint = new Point((int) viewSpaceRectangle.getCenterX(), (int) viewSpaceRectangle.getCenterY()); // get the point of the cursor, centered in the vertex (this prevents jumping from // side-to-side as we move the vertex) Rectangle vertexBounds = GraphViewerUtils.getVertexBoundsInViewSpace(viewer, vertex); int vertexCenterX = vertexBounds.x + (vertexBounds.width >> 1); newPoint.x = vertexCenterX; // see if the cursor bounds are not completely in screen Rectangle viewerBounds = viewer.getBounds(); if (!viewerBounds.contains(viewSpaceRectangle)) { preCreatedDestinaton = newPoint; return super.createAnimator(); } if (!satelliteViewer.isDocked()) { return null; // cannot obscure if not docked } if (!satelliteViewer.isShowing()) { return null; // nothing to do } // see if the satellite is hiding the area Rectangle satelliteBounds = satelliteViewer.getBounds(); if (!satelliteBounds.contains(viewSpaceRectangle)) { return null; // nothing to do } preCreatedDestinaton = newPoint; return super.createAnimator(); }