List of usage examples for java.awt Rectangle Rectangle
public Rectangle()
From source file:com.adobe.acs.commons.images.transformers.impl.CropImageTransformerImpl.java
private Rectangle constrainByHeight(final int x, final int y, final int width, final int height, final int layerHeight, final int y2) { final Rectangle rectangle = new Rectangle(); // Compute amount of overflow for y (that requires clipping) final int deltaY = y2 - layerHeight; // Compute amount to clip width (X) constrained by the % of total width that was removed for deltaY // (Amount clipped from Y should be proportionately equals to amount clipped from Y) int deltaX = Math.round(((float) deltaY / height) * width); // Set the bounds to be the new clipped width/height rectangle.setBounds(x, y, width - deltaX, height - deltaY); return rectangle; }
From source file:geva.Operator.Operations.UserSelect.java
private void terminateDialog() { if (rectangle == null) rectangle = new Rectangle(); dialog.getBounds(rectangle);//from ww w. j a v a 2 s .co m dialog.dispose(); dialog = null; }
From source file:com.adobe.acs.commons.images.transformers.impl.CropImageTransformerImpl.java
private Rectangle constrainByWidth(final int x, final int y, final int width, final int height, final int layerWidth, final int x2) { final Rectangle rectangle = new Rectangle(); // Compute amount of overflow for x (that requires clipping) int deltaX = x2 - layerWidth; // Compute amount to clip height (Y) constrained by the % of total width that was removed for deltaX // (Amount clipped from Y should be proportionately equals to amount clipped from X) int deltaY = Math.round(((float) deltaX / width) * height); // Set the bounds to be the new clipped width/height rectangle.setBounds(x, y, width - deltaX, height - deltaY); return rectangle; }
From source file:com.comcast.cats.image.OCRRegionInfo.java
/** * Returns a Rectangle object comprising of the x,y,width and height values from this region info. * If there invalid x, y, widht, or height values, null is returned. * /* ww w.j ava 2 s . c om*/ * @return The Rectangle object representing this region info or null if there are invalid values. */ public Rectangle getJavaRect() { Rectangle rectangle = new Rectangle(); if (x >= 0 && y >= 0 && width > 0 && height > 0) { rectangle.setBounds(x, y, width, height); } else { rectangle = null; } return rectangle; }
From source file:edu.umd.cfar.lamp.viper.geometry.BoundingBox.java
/** * This creates a new box that represents the area shared by two boxes. * /*www . j a v a 2 s . co m*/ * @param A * a box to intersect * @param B * a box to intersect * @return a new bbox consisting solely of the shared region. */ public static BoundingBox intersection(BoundingBox A, BoundingBox B) { BoundingBox solution = new BoundingBox(); //If we know this is going nowhere, bail if (!A.rect.intersects(B.rect)) return solution; solution.rect = null; // The hard case -- two composed Bounding Boxes if (A.composed && B.composed) { solution.pieces = new LinkedList(); solution.composed = true; Iterator iterA = A.pieces.iterator(); while (iterA.hasNext()) { BoundingBox aBox = (BoundingBox) iterA.next(); Iterator iterB = B.pieces.iterator(); while (iterB.hasNext()) { BoundingBox bBox = (BoundingBox) iterB.next(); assert !aBox.composed && !bBox.composed : "BoundingBox wasn't flattened."; if (aBox.intersects(bBox)) { BoundingBox newBox = new BoundingBox((Rectangle) aBox.rect.createIntersection(bBox.rect)); if (solution.rect == null) { solution.rect = (Rectangle) newBox.rect.clone(); } else { Rectangle2D.union(solution.rect, newBox.rect, solution.rect); } solution.pieces.add(newBox); } } } solution.simplify(); } else if (A.composed || B.composed) { // Now handle the case where one is composed. BoundingBox uncomposedBox = (A.composed ? B : A); BoundingBox composedBox = (A.composed ? A : B); solution.pieces = new LinkedList(); solution.composed = true; Iterator iter = composedBox.pieces.iterator(); while (iter.hasNext()) { BoundingBox child = (BoundingBox) iter.next(); assert !child.composed : "BoundingBox wasn't flattened."; if (child.rect.intersects(uncomposedBox.rect.x, uncomposedBox.rect.y, uncomposedBox.rect.width, uncomposedBox.rect.height)) { BoundingBox newBox = new BoundingBox( (Rectangle) child.rect.createIntersection(uncomposedBox.rect)); if (solution.rect == null) { solution.rect = (Rectangle) newBox.rect.clone(); } else { Rectangle2D.union(solution.rect, newBox.rect, solution.rect); } solution.pieces.add(newBox); } } solution.simplify(); } else { // The easy case. if (A.rect.intersects(B.rect.x, B.rect.y, B.rect.width, B.rect.height)) { solution.rect = (Rectangle) A.rect.createIntersection(B.rect); solution.initPoly(); } else { solution.rect = new Rectangle(); } } return solution; }
From source file:ExtendedTableCellRenderer.java
public void paint(Graphics g) { super.paint(g); if (underlined) { Insets i = getInsets();/*from w w w.ja v a 2s . c o m*/ FontMetrics fm = g.getFontMetrics(); Rectangle textRect = new Rectangle(); Rectangle viewRect = new Rectangle(i.left, i.top, getWidth() - (i.right + i.left), getHeight() - (i.bottom + i.top)); SwingUtilities.layoutCompoundLabel(this, fm, getText(), getIcon(), getVerticalAlignment(), getHorizontalAlignment(), getVerticalTextPosition(), getHorizontalTextPosition(), viewRect, new Rectangle(), textRect, getText() == null ? 0 : ((Integer) UIManager.get("Button.textIconGap")).intValue()); int offset = 2; if (UIManager.getLookAndFeel().isNativeLookAndFeel() && System.getProperty("os.name").startsWith("Windows")) { offset = 1; } g.fillRect(textRect.x + ((Integer) UIManager.get("Button.textShiftOffset")).intValue(), textRect.y + fm.getAscent() + ((Integer) UIManager.get("Button.textShiftOffset")).intValue() + offset, textRect.width, 1); } }
From source file:com.att.aro.ui.view.diagnostictab.CreateBarPlot.java
public XYPlot drawYIntervalPlot() { // Create the plot renderer YIntervalRenderer renderer = new YIntervalRenderer() { private static final long serialVersionUID = 1L; public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); }//from www . j ava 2s . co m IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; double x = intervalDataset.getXValue(series, item); double yLow = intervalDataset.getStartYValue(series, item); double yHigh = intervalDataset.getEndYValue(series, item); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation); double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation); Paint p = getItemPaint(series, item); Stroke s = getItemStroke(series, item); Line2D line = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(yyLow, xx, yyHigh, xx); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(xx, yyLow, xx, yyHigh); } g2.setPaint(p); g2.setStroke(s); g2.draw(line); // add an entity for the item... if (entities != null && line != null) { if (entityArea == null) { entityArea = line.getBounds(); } String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, null); entities.add(entity); } } }; renderer.setAdditionalItemLabelGenerator(null); renderer.setBaseShape(new Rectangle()); renderer.setAutoPopulateSeriesShape(false); renderer.setAutoPopulateSeriesPaint(false); renderer.setBasePaint(Color.GRAY); // Create the plot XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer); plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); plot.getRangeAxis().setVisible(false); return plot; }
From source file:com.sshtools.common.ui.PreferencesStore.java
/** * * * @param name//www . j a v a 2 s . co m * @param def * * @return */ public static Rectangle getRectangle(String name, Rectangle def) { String s = get(name); if ((s == null) || s.equals("")) { return def; } else { StringTokenizer st = new StringTokenizer(s, ","); Rectangle r = new Rectangle(); try { r.x = Integer.parseInt(st.nextToken()); r.y = Integer.parseInt(st.nextToken()); r.width = Integer.parseInt(st.nextToken()); r.height = Integer.parseInt(st.nextToken()); } catch (NumberFormatException nfe) { log.warn("Preference is " + name + " is badly formatted", nfe); } return r; } }
From source file:com.jaeksoft.searchlib.web.controller.ViewerController.java
private void loadPdf() throws PDFException, PDFSecurityException, IOException { Document pdf = null;//from www .j a v a 2 s. c om try { int pdfPage = page - 1; pdf = new Document(); pdf.setFile(tempFile.getAbsolutePath()); List<Rectangle> boxList = new ArrayList<Rectangle>(0); PDimension pd = pdf.getPageDimension(pdfPage, 0.0f); float zoomFactor = zoom / 100; float pageWidth = pd.getWidth(); float pageHeight = pd.getHeight(); if (keywords != null) { PageText pageText = pdf.getPageViewText(pdfPage); for (LineText lineText : pageText.getPageLines()) { for (WordText wordText : lineText.getWords()) { for (String keyword : keywords) if (keyword.equalsIgnoreCase(wordText.getText())) { Rectangle2D.Float rectf = wordText.getBounds(); Rectangle rect = new Rectangle(); rect.x = (int) (rectf.x * zoomFactor); rect.y = (int) ((pageHeight - rectf.y - rectf.height) * zoomFactor); rect.width = (int) (rectf.width * zoomFactor); rect.height = (int) (rectf.height * zoomFactor); boxList.add(rect); break; } } } if (hocrPdf != null) { HocrPage page = hocrPdf.getPage(pdfPage); float xFactor = (pageWidth / page.getPageWidth()) * zoomFactor; float yFactor = (pageHeight / page.getPageHeight()) * zoomFactor; if (page != null) for (String keyword : keywords) page.addBoxes(keyword, boxList, xFactor, yFactor); } } currentImage = pdf.getPageImage(pdfPage, GraphicsRenderingHints.SCREEN, Page.BOUNDARY_CROPBOX, 0.0f, zoom / 100); ImageUtils.yellowHighlight(currentImage, boxList); numberOfPages = pdf.getNumberOfPages(); } finally { if (pdf != null) pdf.dispose(); } }
From source file:gdsc.core.utils.ConvexHull.java
public Rectangle getBounds() { int npoints = size(); float[] xpoints = this.x; float[] ypoints = this.y; if (npoints == 0) return new Rectangle(); if (bounds == null) calculateBounds(xpoints, ypoints, npoints); return bounds.getBounds(); }