Java Code Examples for java.awt.Rectangle.getCenterX()

The following are Jave code examples for showing how to use getCenterX() of the java.awt.Rectangle class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: UnixMultiResolutionSplashTest.java   View Source Code Vote up 8 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 2
Project: openjdk-jdk10   File: MultiResolutionSplashTest.java   View Source Code Vote up 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();
    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 3
Project: incubator-netbeans   File: CenteredZoomAnimator.java   View Source Code Vote up 5 votes
@Override public void tick(double progress) {
    double nextZoom = progress >= 1.0 ? targetZoom :
        (sourceZoom + progress * (targetZoom - sourceZoom));

    Scene scene = getScene();
    JComponent view = scene.getView ();

    if (view != null) {
        Point viewLocation = view.getVisibleRect ().getLocation();
        Dimension viewSize = view.getVisibleRect ().getSize();
        Point oldCenter = scene.convertSceneToView (center);

        ((DependencyGraphScene)scene).setMyZoomFactor (nextZoom);
        scene.validate (); // HINT - forcing to change preferred size of the JComponent view

        Point newCenter = scene.convertSceneToView (center);
        Rectangle viewBounds = view.getVisibleRect();
        Point visibleCenter = new Point((int)viewBounds.getCenterX(), (int)viewBounds.getCenterY());
        newCenter.x += Math.round((newCenter.x - visibleCenter.x) * progress);
        newCenter.y += Math.round((newCenter.y - visibleCenter.y) * progress);

        view.scrollRectToVisible (new Rectangle (
                newCenter.x - oldCenter.x + viewLocation.x,
                newCenter.y - oldCenter.y + viewLocation.y,
                viewSize.width,
                viewSize.height
        ));
    } else {
        ((DependencyGraphScene)scene).setMyZoomFactor (nextZoom);
    }
}
 
Example 4
Project: incubator-netbeans   File: FruchtermanReingoldLayout.java   View Source Code Vote up 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 5
Project: Equella   File: SerialRenderer.java   View Source Code Vote up 5 votes
@Override
public void draw(Graphics g, Rectangle bounds)
{
	final int childWidth = bounds.width - (PADDING_SIZE * 2);

	// Start placing children from here...
	int nextY = bounds.y;

	final int childCount = getChildCount();
	for( int i = 0; i < childCount; i++ )
	{
		Renderer child = getChild(i);

		// Determine child boundries
		Rectangle childBound = new Rectangle();
		childBound.x = bounds.x + PADDING_SIZE;
		childBound.y = nextY;
		childBound.width = childWidth;
		childBound.height = child.getSize(g).height;

		// Draw child
		child.draw(g, childBound);

		// Next child Y coordinate.
		nextY += childBound.height;
	}

	int maxY = bounds.y + bounds.height;
	if( nextY < maxY )
	{
		int centreX = (int) bounds.getCenterX();
		g.setColor(ARROW_COLOUR);
		g.drawLine(centreX, nextY, centreX, maxY);
	}
}
 
Example 6
Project: What-Happened-to-Station-7   File: TileDamage.java   View Source Code Vote up 5 votes
@Override
public void drawOverEntities(Graphics2D g, int s)
{
	float time = Math.max(T(), getLength());
	Shape bound = pos.getBorder(s);
	Rectangle border = bound.getBounds();
	Point2D.Double f = new Point2D.Double(border.getCenterX(), border.getCenterY());
	Paint grad = new RadialGradientPaint(f, s / 3, new float[] {0, .7f, 1}, new Color[]{
			new Color(1, 0, 0, 0), 
			new Color(1, 0, 0, .2f * (1 - time / getLength())), 
			new Color(1, 0, 0, .8f * (1 - time / getLength()))});
	g.setPaint(grad);
	g.fill(bound);
}
 
Example 7
Project: jdk8u-jdk   File: MultiResolutionSplashTest.java   View Source Code Vote up 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 8
Project: jmt   File: Mediator.java   View Source Code Vote up 4 votes
private int searchNext(JmtCell prev) {
	Rectangle boundspadre = GraphConstants.getBounds((prev).getAttributes()).getBounds();
	Object[] listEdges = null;
	GraphModel graphmodel = graph.getModel();
	List<Object> next = new ArrayList<Object>();

	if (flag1 == false && prev.seen == false) {
		if (!flag2) {
			boundspadre.setLocation(x, y + ((e + 1) * (42 + heightMax)) - (int) (boundspadre.getHeight() / 2) + 30);
		} else {
			boundspadre.setLocation(x - (int) (boundspadre.getWidth() / 2), y + ((e + 1) * (42 + heightMax))
					- (int) (boundspadre.getHeight() / 2) + 30);
		}

		GraphConstants.setBounds(prev.getAttributes(), boundspadre);
		x = (int) boundspadre.getCenterX() + widthMax + 50;
		prev.seen = true;
		flag2 = true;
	}

	listEdges = DefaultGraphModel.getOutgoingEdges(graphmodel, prev);
	Vector<Object> listEdgestmp = new Vector<Object>();
	for (Object listEdge : listEdges) {
		JmtCell qq = (JmtCell) (graphmodel.getParent(graphmodel.getTarget(listEdge)));
		if (!(qq).seen) {
			listEdgestmp.add(listEdge);
		}
	}
	listEdges = listEdgestmp.toArray();

	int numTarget = listEdges.length;
	if (numTarget == 0) {
		return 1;
	}

	for (int k = 0; k < numTarget; k++) {
		next.add((graphmodel.getParent(graphmodel.getTarget(listEdges[k]))));
	}

	int j = 1;
	if (inRepositionSons == false && ((JmtCell) next.get(0)).seen == false) {
		j = searchNext((JmtCell) next.get(0));
	} else if (inRepositionSons == true && ((JmtCell) next.get(0)).seen == false) {
		Rectangle bounds = GraphConstants.getBounds(((JmtCell) next.get(0)).getAttributes()).getBounds();
		bounds.setLocation((int) (boundspadre.getCenterX()) + widthMax + 50 - (int) (bounds.getWidth() / 2),
				(int) boundspadre.getCenterY() - (int) (bounds.getHeight() / 2));
		GraphConstants.setBounds(((JmtCell) next.get(0)).getAttributes(), bounds);

		((JmtCell) next.get(0)).seen = true;
		j = searchNext((JmtCell) next.get(0));
	}

	if (numTarget > 0) {
		if (!flag) {
			repositionSons(prev, next, j - 1, 1);
		} else {
			repositionSons(prev, next, -1, 0);
		}
		flag = false;
	}

	(prev).sons = 0;
	for (int w = 0; w < numTarget; w++) {
		prev.sons += ((JmtCell) next.get(w)).sons;
	}

	return prev.sons;
}
 
Example 9
Project: QN-ACTR-Release   File: Mediator.java   View Source Code Vote up 4 votes
private int searchNext(JmtCell prev) {
	Rectangle boundspadre = GraphConstants.getBounds((prev).getAttributes()).getBounds();
	Object[] listEdges = null;
	GraphModel graphmodel = graph.getModel();
	List<Object> next = new ArrayList<Object>();

	if (flag1 == false && prev.seen == false) {

		// Rectangle bounds =
		// GraphConstants.getBounds(((JmtCell)prev).getAttributes()).getBounds();
		if (!flag2) {
			boundspadre.setLocation(x, y + ((e + 1) * (42 + heightMax)) - (int) (boundspadre.getHeight() / 2) + 30);
		} else {
			boundspadre.setLocation(x - (int) (boundspadre.getWidth() / 2), y + ((e + 1) * (42 + heightMax))
					- (int) (boundspadre.getHeight() / 2) + 30);
		}

		GraphConstants.setBounds(prev.getAttributes(), boundspadre);
		x = (int) boundspadre.getCenterX() + widthMax + 50;
		prev.seen = true;
		flag2 = true;
	}

	// inserisco tutti gli archi uscenti e entranti di min.get(j) in
	// listEdges
	listEdges = DefaultGraphModel.getOutgoingEdges(graphmodel, prev);
	Vector<Object> listEdgestmp = new Vector<Object>();
	for (Object listEdge : listEdges) {
		JmtCell qq = (JmtCell) (graphmodel.getParent(graphmodel.getTarget(listEdge)));
		if (!(qq).seen) {
			listEdgestmp.add(listEdge);
		}
	}
	listEdges = listEdgestmp.toArray();

	int numTarget = listEdges.length;
	if (numTarget == 0) {
		return 1;
	}

	for (int k = 0; k < numTarget; k++) {
		next.add((graphmodel.getParent(graphmodel.getTarget(listEdges[k]))));
	}

	int j = 1;
	if (inRepositionSons == false && ((JmtCell) next.get(0)).seen == false) {
		j = searchNext((JmtCell) next.get(0));
	} else if (inRepositionSons == true && ((JmtCell) next.get(0)).seen == false) {

		Rectangle bounds = GraphConstants.getBounds(((JmtCell) next.get(0)).getAttributes()).getBounds();
		bounds.setLocation((int) (boundspadre.getCenterX()) + widthMax + 50 - (int) (bounds.getWidth() / 2), (int) boundspadre.getCenterY()
				- (int) (bounds.getHeight() / 2));
		GraphConstants.setBounds(((JmtCell) next.get(0)).getAttributes(), bounds);

		((JmtCell) next.get(0)).seen = true;
		j = searchNext((JmtCell) next.get(0));
	}

	if (numTarget > 0) {
		if (!flag) {
			repositionSons(prev, next, j - 1, 1);
		} else {
			repositionSons(prev, next, -1, 0);
		}
		flag = false;
	}

	(prev).sons = 0;
	for (int w = 0; w < numTarget; w++) {
		prev.sons += ((JmtCell) next.get(w)).sons;
	}

	return prev.sons;
}
 
Example 10
Project: Equella   File: RootRenderer.java   View Source Code Vote up 4 votes
@Override
public void draw(Graphics g, Rectangle bounds)
{
	g.setFont(Renderer.DEFAULT_FONT);

	final int centreX = (int) bounds.getCenterX();
	int topY = bounds.y;

	// Draw our start point
	drawCircledText(g, START_TEXT, centreX, topY);
	topY += OVAL_HEIGHT;

	drawLeadingOutArrow(g, centreX, topY, HALF_ARROW_HEIGHT);
	topY += HALF_ARROW_HEIGHT;

	// Get ready to draw our child
	Renderer child = getChild(0);
	Dimension childSize = child.getSize(g);
	Rectangle childBound = new Rectangle();
	childBound.x = centreX - (childSize.width / 2);
	childBound.y = topY;
	childBound.width = childSize.width;
	childBound.height = childSize.height;

	child.draw(g, childBound);
	topY += childSize.height;

	// Draw our end point
	drawLeadingInArrow(g, centreX, topY, HALF_ARROW_HEIGHT);
	topY += HALF_ARROW_HEIGHT;

	drawCircledText(g, END_TEXT, centreX, topY);
	topY += OVAL_HEIGHT;

	// Draw any legend elements
	topY += LEGEND_PADDING;
	g.setFont(Renderer.DEFAULT_FONT);
	int legendX = bounds.x + PADDING_SIZE;
	for( Map.Entry<Color, String> entry : legendText.entrySet() )
	{
		int textHeight = (int) getTextSize(g, entry.getValue()).getHeight();

		g.setColor(entry.getKey());
		g.fillRect(legendX, topY, textHeight, textHeight);
		g.setColor(Color.BLACK);
		g.drawRect(legendX, topY, textHeight, textHeight);

		g.drawString(entry.getValue(), legendX + textHeight + PADDING_SIZE, topY + textHeight);

		topY += textHeight + LEGEND_PADDING;
	}
}
 
Example 11
Project: Equella   File: TaskRenderer.java   View Source Code Vote up 4 votes
@Override
public void draw(Graphics g, Rectangle bounds)
{
	// Make a few coordinate calculations
	Dimension totalTextSize = getTextArea(g);

	int maxTextStartX = (int) (bounds.getCenterX() - (totalTextSize.getWidth() / 2));
	int maxTextStartY = (int) (bounds.getCenterY() + (totalTextSize.getHeight() / 2));

	int boxStartY = maxTextStartY - (int) totalTextSize.getHeight() - PADDING_SIZE;
	int boxStartX = maxTextStartX - PADDING_SIZE;
	int boxWidth = (int) totalTextSize.getWidth() + (PADDING_SIZE * 2);
	int boxHeight = (int) totalTextSize.getHeight() + (PADDING_SIZE * 2);

	// Draw the box
	if( getHilight() != null )
	{
		g.setColor(getHilight());
		g.fillRect(boxStartX, boxStartY, boxWidth, boxHeight);
	}
	g.setColor(Color.BLACK);
	g.drawRect(boxStartX, boxStartY, boxWidth, boxHeight);

	// Draw the text
	Dimension textSize = getTextArea(g, displayName);
	int textX = (int) (bounds.getCenterX() - (textSize.getWidth() / 2));
	int textY = boxStartY + PADDING_SIZE + (int) textSize.getHeight();

	g.setFont(DEFAULT_FONT);
	g.drawString(displayName, textX, textY - 2);

	if( getMessage() != null )
	{
		textSize = getTextArea(g, getMessage());
		textX = (int) (bounds.getCenterX() - (textSize.getWidth() / 2));
		textY += NOTE_PADDING + (int) textSize.getHeight();

		g.setFont(NOTE_FONT);
		g.drawString(getMessage(), textX, textY - 2);
	}

	// Draw leading arrow
	drawLeadingInArrow(g, (int) bounds.getCenterX(), bounds.y, boxStartY - bounds.y);

	// Draw trailing arrow
	int arrowX = (int) bounds.getCenterX();
	int arrowY = boxStartY + boxHeight;
	int arrowLength = (bounds.y + bounds.height) - (boxStartY + boxHeight);
	drawLeadingOutArrow(g, arrowX, arrowY, arrowLength);
}
 
Example 12
Project: Equella   File: DecisionRenderer.java   View Source Code Vote up 4 votes
@Override
public void draw(Graphics g, Rectangle bounds)
{
	final int centreX = (int) bounds.getCenterX();

	// Draw the leading arrow
	drawLeadingInArrow(g, centreX, bounds.y, HALF_ARROW_HEIGHT);

	// Draw the trailing arrow
	drawLeadingOutArrow(g, centreX, bounds.y + bounds.height - HALF_ARROW_HEIGHT, HALF_ARROW_HEIGHT);

	// Get ready to draw our child
	Dimension childSize = super.getSizeWithNoPadding(g);
	Rectangle childBound = new Rectangle();
	childBound.x = centreX - (childSize.width / 2);
	childBound.y = bounds.y + (HALF_ARROW_HEIGHT * 2) + DIAMOND_SIZE;
	childBound.width = childSize.width;
	childBound.height = childSize.height;

	// Draw child
	super.draw(g, childBound);

	// Do some general calculations
	Rectangle2D textSize = g.getFontMetrics().getStringBounds(nodeName, g);

	int diamondTop = bounds.y + HALF_ARROW_HEIGHT;
	int halfDiamondY = DIAMOND_SIZE / 2;
	int halfDiamondX = (int) (textSize.getWidth() / 2) + (PADDING_SIZE * 2);

	int textStartX = centreX - (int) (textSize.getWidth() / 2);
	int textStartY = diamondTop + halfDiamondY + (int) (textSize.getHeight() / 2);

	// Draw the diamond
	int[] pointsX = {centreX, centreX - halfDiamondX, centreX, centreX + halfDiamondX};
	int[] pointsY = {diamondTop, diamondTop + halfDiamondY, diamondTop + DIAMOND_SIZE, diamondTop + halfDiamondY};

	if( getHilight() != null )
	{
		g.setColor(getHilight());
		g.fillPolygon(pointsX, pointsY, pointsX.length);
	}

	g.setColor(Color.BLACK);
	g.drawPolygon(pointsX, pointsY, pointsX.length);

	// Draw the text
	g.setColor(Color.BLACK);
	g.drawString(nodeName, textStartX, textStartY - 3);

	// Draw the arrow leading out from the diamond
	drawLeadingOutArrow(g, centreX, diamondTop + DIAMOND_SIZE, HALF_ARROW_HEIGHT);

	// Draw connecting lines
	int lineX1 = centreX - (childSize.width / 2) - PADDING_SIZE;
	int lineX2 = centreX - halfDiamondX;
	int lineY1 = diamondTop + halfDiamondY;
	int lineY2 = lineY1 + HALF_ARROW_HEIGHT + halfDiamondY + childSize.height;

	lineX1 = Math.min(lineX1, lineX2);

	g.setColor(ARROW_COLOUR);
	g.drawLine(lineX1, lineY1, lineX2, lineY1);
	g.drawLine(lineX1, lineY2, centreX, lineY2);
	g.drawLine(lineX1, lineY1, lineX1, lineY2);

	// Draw sideways pointer on arrow
	g.drawLine(centreX - ARROW_HEAD_HEIGHT, lineY2 - ARROW_HEAD_WIDTH, centreX, lineY2);
	g.drawLine(centreX - ARROW_HEAD_HEIGHT, lineY2 + ARROW_HEAD_WIDTH, centreX, lineY2);
}