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

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

源代码1 项目: 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;
    }

}
 
源代码2 项目: ghidra   文件: FGViewUpdater.java
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);
	}
 
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);
}
 
源代码4 项目: fight-game   文件: RoleCreateFrame.java
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);
	}
 
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!");
    }
}
 
源代码6 项目: 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;
    }
 
源代码7 项目: 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;
}
 
源代码8 项目: rapidminer-studio   文件: ProcessPanel.java
/**
 * 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;
}
 
源代码9 项目: 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);
}
 
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);
}
 
源代码11 项目: audiveris   文件: HeadInter.java
/**
 * 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);
}
 
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);
}
 
源代码13 项目: openjdk-jdk8u   文件: 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;
    }
 
源代码14 项目: 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!");
    }
}
 
源代码15 项目: 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;
     }
   }
 
源代码16 项目: 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;
    }
 
源代码17 项目: openjdk-jdk8u-backup   文件: 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!");
    }
}
 
源代码19 项目: openjdk-jdk9   文件: 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!");
    }
}
 
@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();
}