List of usage examples for java.awt Rectangle setSize
public void setSize(int width, int height)
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Rectangle r = new Rectangle(new Point(10, 10)); r.setSize(30, 30); g2.fill(r);//from w w w .j av a2s . com System.out.println(r.isEmpty()); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Rectangle r = new Rectangle(); r.setLocation(10, 10);/* w w w . j av a 2s . c o m*/ r.setSize(10, 10); g2.fill(r); System.out.println(r.height); }
From source file:com.igormaznitsa.sciareto.ui.editors.MMDEditor.java
@Override public void onEnsureVisibilityOfTopic(@Nonnull final MindMapPanel source, @Nullable final Topic topic) { SwingUtilities.invokeLater(new Runnable() { @Override// www . jav a 2s . c o m public void run() { if (topic == null) { return; } final AbstractElement element = (AbstractElement) topic.getPayload(); if (element == null) { return; } final Rectangle2D orig = element.getBounds(); final int GAP = 30; final Rectangle bounds = orig.getBounds(); bounds.setLocation(Math.max(0, bounds.x - GAP), Math.max(0, bounds.y - GAP)); bounds.setSize(bounds.width + GAP * 2, bounds.height + GAP * 2); final JViewport viewport = getViewport(); final Rectangle visible = viewport.getViewRect(); if (visible.contains(bounds)) { return; } bounds.setLocation(bounds.x - visible.x, bounds.y - visible.y); viewport.scrollRectToVisible(bounds); } }); }
From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java
private void solveConflict() { if (this.investPoint == null || this.ROIPoint == null) { /* No conflict to be solved. */ return;//from w w w . jav a 2 s.c om } /* Take border into consideration. */ final Rectangle ROIRectWithBorder = new Rectangle((Rectangle) this.ROIRect); final Rectangle investRectWithBorder = new Rectangle((Rectangle) this.investRect); ROIRectWithBorder.setLocation((int) ROIRectWithBorder.getX() - 1, (int) ROIRectWithBorder.getY() - 1); ROIRectWithBorder.setSize((int) ROIRectWithBorder.getWidth() + 2, (int) ROIRectWithBorder.getHeight() + 2); investRectWithBorder.setLocation((int) investRectWithBorder.getX() - 1, (int) investRectWithBorder.getY() - 1); investRectWithBorder.setSize((int) investRectWithBorder.getWidth() + 2, (int) investRectWithBorder.getHeight() + 2); if (false == ROIRectWithBorder.intersects(investRectWithBorder)) { return; } final Rectangle oldROIRect = new Rectangle((Rectangle) this.ROIRect); final Rectangle oldInvestRect = new Rectangle((Rectangle) this.investRect); // Move to Down. if (this.ROIRect.getY() > this.investRect.getY()) { ((Rectangle) this.ROIRect).translate(0, (int) (this.investRect.getY() + this.investRect.getHeight() - this.ROIRect.getY() + 4)); } else { ((Rectangle) this.investRect).translate(0, (int) (this.ROIRect.getY() + this.ROIRect.getHeight() - this.investRect.getY() + 4)); } if ((this.drawArea.getY() + this.drawArea.getHeight()) > (this.ROIRect.getY() + this.ROIRect.getHeight()) && (this.drawArea.getY() + this.drawArea.getHeight()) > (this.investRect.getY() + this.investRect.getHeight())) { return; } this.ROIRect.setRect(oldROIRect); this.investRect.setRect(oldInvestRect); // Move to Up. if (this.ROIRect.getY() > this.investRect.getY()) { ((Rectangle) this.investRect).translate(0, -(int) (this.investRect.getY() + this.investRect.getHeight() - this.ROIRect.getY() + 4)); } else { ((Rectangle) this.ROIRect).translate(0, -(int) (this.ROIRect.getY() + this.ROIRect.getHeight() - this.investRect.getY() + 4)); } if ((this.drawArea.getY() < this.ROIRect.getY()) && (this.drawArea.getY() < this.investRect.getY())) { return; } this.ROIRect.setRect(oldROIRect); this.investRect.setRect(oldInvestRect); }
From source file:knop.psfj.BeadImage.java
/** * Gets the enlarged frame./*from w w w.java2s.c om*/ * * @param r the r * @param f the f * @return the enlarged frame */ public static Rectangle getEnlargedFrame(Rectangle r, int f) { Rectangle rn = new Rectangle(); rn.setLocation(round(r.getCenterX() - f / 2), round(r.getCenterY() - f / 2)); rn.setSize(f, f); return rn; }
From source file:knop.psfj.BeadImage.java
/** * Gets the enlarged frame./* w w w . j a v a2 s .c o m*/ * * @param r the r * @return the enlarged frame */ public Rectangle getEnlargedFrame(Rectangle r) { Rectangle rn = new Rectangle(); int f = frameSize; if (frameSize * frameSize >= imageWidth * imageHeight * 0.8) { rn.setLocation(0, 0); rn.setSize(imageWidth, imageHeight); return rn; } int x = MathUtils.round(r.getX() + r.getWidth() / 2 - f / 2); int y = MathUtils.round(r.getY() + r.getHeight() / 2 - f / 2); x -= 1; y -= 1; int w = f; int h = f; rn.setLocation(x, y); rn.setSize(w, h); return rn; }
From source file:org.apache.fop.render.pcl.PCLPainter.java
private Rectangle getTextBoundingBox(int x, int y, int letterSpacing, int wordSpacing, int[] dx, String text, Font font, FontMetricsMapper metrics) { int maxAscent = metrics.getMaxAscent(font.getFontSize()) / 1000; int descent = metrics.getDescender(font.getFontSize()) / 1000; //is negative int safetyMargin = (int) (SAFETY_MARGIN_FACTOR * font.getFontSize()); Rectangle boundingRect = new Rectangle(x, y - maxAscent - safetyMargin, 0, maxAscent - descent + 2 * safetyMargin); int l = text.length(); int dxl = (dx != null ? dx.length : 0); if (dx != null && dxl > 0 && dx[0] != 0) { boundingRect.setLocation(boundingRect.x - (int) Math.ceil(dx[0] / 10f), boundingRect.y); }//w w w. j av a 2 s . co m float width = 0.0f; for (int i = 0; i < l; i++) { char orgChar = text.charAt(i); float glyphAdjust = 0; int cw = font.getCharWidth(orgChar); if ((wordSpacing != 0) && CharUtilities.isAdjustableSpace(orgChar)) { glyphAdjust += wordSpacing; } glyphAdjust += letterSpacing; if (dx != null && i < dxl - 1) { glyphAdjust += dx[i + 1]; } width += cw + glyphAdjust; } int extraWidth = font.getFontSize() / 3; boundingRect.setSize((int) Math.ceil(width) + extraWidth, boundingRect.height); return boundingRect; }
From source file:pcgen.gui2.tools.Utility.java
/** * Adjust the crop rectangle to fit within the image it is cropping. Also * ensure the area is square.// w w w. j a va 2 s. c o m * * @param image The image being cropped * @param cropRect The rectangle defining the cropping area. This may be updated. */ public static void adjustRectToFitImage(RenderedImage image, Rectangle cropRect) { // Make sure the rectangle is not too big if (cropRect.width > image.getWidth()) { cropRect.width = image.getWidth(); } if (cropRect.height > image.getHeight()) { cropRect.height = image.getHeight(); } // Make it square int dimension = Math.min(cropRect.width, cropRect.height); cropRect.setSize(dimension, dimension); // Now adjust the origin point so the box is within the image if ((cropRect.x + cropRect.width) > image.getWidth()) { cropRect.x = image.getWidth() - cropRect.width; } if ((cropRect.y + cropRect.height) > image.getHeight()) { cropRect.y = image.getHeight() - cropRect.height; } }
From source file:VASSAL.Info.java
/** * Get size of screen accounting for the screen insets (i.e. Windows taskbar) * * @return//w ww. j a va 2s.c o m */ public static Rectangle getScreenBounds(Component c) { final Rectangle bounds = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); final GraphicsConfiguration config = c.getGraphicsConfiguration(); final Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(config); bounds.translate(insets.left, insets.top); bounds.setSize(bounds.width - insets.left - insets.right, bounds.height - insets.top - insets.bottom); return bounds; }