List of usage examples for java.awt Rectangle Rectangle
public Rectangle(int x, int y, int width, int height)
From source file:ala.soils2sat.DrawingUtils.java
/** * * @param srcWidth//from w w w. j a va2s . co m * @param srcHeight * @param targetWidth * @param targetHeight * @return */ public static Rectangle resizeImage(int srcWidth, int srcHeight, int targetWidth, int targetHeight) { while (srcHeight > targetHeight || srcWidth > targetWidth) { if (srcHeight > targetHeight) { double ratio = (double) (targetHeight) / (double) srcHeight; srcHeight = targetHeight; srcWidth = (int) ((double) srcWidth * ratio); } if (srcWidth > targetWidth) { double ratio = (double) (targetWidth) / (double) srcWidth; srcWidth = targetWidth; srcHeight = (int) ((double) srcHeight * ratio); } } return new Rectangle(0, 0, srcWidth, srcHeight); }
From source file:gdsc.smlm.ij.plugins.DensityImage.java
/** * Remove any results which fall in the radius border added around the ROI. Results are modified in place and a new * density array is returned.//from ww w . j ava 2 s . co m * * @param results * @param density * @return */ private int[] cropBorder(MemoryPeakResults results, int[] density) { if (roiBounds == null) return density; final float minX = (int) (scaledRoiMinX); final float maxX = (int) Math.ceil(scaledRoiMaxX); final float minY = (int) (scaledRoiMinY); final float maxY = (int) Math.ceil(scaledRoiMaxY); // Clone the results then add back those that are within the bounds List<PeakResult> peakResults = new ArrayList<PeakResult>(results.getResults()); results.begin(); int count = 0; for (int i = 0; i < peakResults.size(); i++) { PeakResult peakResult = peakResults.get(i); float x = peakResult.params[Gaussian2DFunction.X_POSITION]; float y = peakResult.params[Gaussian2DFunction.Y_POSITION]; if (x < minX || x > maxX || y < minY || y > maxY) continue; results.add(peakResult); density[count++] = density[i]; } results.end(); results.setBounds(new Rectangle((int) minX, (int) minY, (int) (maxX - minX), (int) (maxY - minY))); return Arrays.copyOf(density, count); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
protected void paintAnnotations(Graphics2D g2d) { DecimalFormat mz_df = new DecimalFormat("0.0"); // set font/* ww w . ja v a 2 s.c o m*/ Font old_font = g2d.getFont(); Font new_font = new Font(theOptions.ANNOTATION_MZ_FONT, Font.PLAIN, theOptions.ANNOTATION_MZ_SIZE); // compute bboxes PositionManager pman = new PositionManager(); BBoxManager bbman = new BBoxManager(); computeRectangles(pman, bbman); // compute connections computeConnections(); // paint connections for (AnnotationObject a : theDocument.getAnnotations()) { boolean selected = !is_printing && selections.contains(a); // paint arrow Polygon connection = connections.get(a); if (connection != null) { g2d.setColor(theOptions.CONNECTION_LINES_COLOR); g2d.setStroke((selected) ? new BasicStroke((float) (1. + theOptions.ANNOTATION_LINE_WIDTH)) : new BasicStroke((float) theOptions.ANNOTATION_LINE_WIDTH)); g2d.draw(connection); g2d.setStroke(new BasicStroke(1)); } // paint control point if (selected) { g2d.setColor(Color.black); Point2D cp = connections_cp.get(a); if (cp != null) { int s = (int) (2 + theOptions.ANNOTATION_LINE_WIDTH); g2d.fill(new Rectangle((int) cp.getX() - s, (int) cp.getY() - s, 2 * s, 2 * s)); } } } // paint glycans for (AnnotationObject a : theDocument.getAnnotations()) { boolean highlighted = a.isHighlighted(); boolean selected = !is_printing && selections.contains(a); // set scale theGlycanRenderer.getGraphicOptions().setScale(theOptions.SCALE_GLYCANS * theDocument.getScale(a)); // paint highlighted region if (highlighted) { Rectangle c_bbox = rectangles_complete.get(a); g2d.setColor(theOptions.HIGHLIGHTED_COLOR); g2d.setXORMode(Color.white); g2d.fill(c_bbox); g2d.setPaintMode(); g2d.setColor(Color.black); g2d.draw(c_bbox); } // paint glycan for (Glycan s : a.getStructures()) theGlycanRenderer.paint(g2d, s, null, null, false, false, pman, bbman); // paint MZ text g2d.setFont(new_font); g2d.setColor(theOptions.MASS_TEXT_COLOR); String mz_text = mz_df.format(a.getPeakPoint().getX()); Rectangle mz_bbox = rectangles_text.get(a); g2d.drawString(mz_text, mz_bbox.x, mz_bbox.y + mz_bbox.height); // paint selection if (selected) { // paint rectangle Rectangle c_bbox = rectangles_complete.get(a); g2d.setStroke(new BasicStroke(highlighted ? 2 : 1)); g2d.setColor(Color.black); g2d.draw(c_bbox); g2d.setStroke(new BasicStroke(1)); // paint resize points Polygon p1 = new Polygon(); int cx1 = right(c_bbox); int cy1 = top(c_bbox); p1.addPoint(cx1, cy1); p1.addPoint(cx1 - 2 * theOptions.ANNOTATION_MARGIN / 3, cy1); p1.addPoint(cx1, cy1 + 2 * theOptions.ANNOTATION_MARGIN / 3); g2d.fill(p1); Polygon p2 = new Polygon(); int cx2 = left(c_bbox); int cy2 = top(c_bbox); p2.addPoint(cx2, cy2); p2.addPoint(cx2 + 2 * theOptions.ANNOTATION_MARGIN / 3, cy2); p2.addPoint(cx2, cy2 + 2 * theOptions.ANNOTATION_MARGIN / 3); g2d.fill(p2); } } g2d.setFont(old_font); }
From source file:fr.amap.commons.javafx.chart.ChartViewer.java
/** * A handler for the export to PNG option in the context menu. */// w w w . j av a 2 s .c o m private void handleExportToPNG() { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Export to PNG"); fileChooser.setSelectedExtensionFilter( new FileChooser.ExtensionFilter("Portable Network Graphics (PNG)", "png")); File file = fileChooser.showSaveDialog(stage); if (file != null) { try { CanvasPositionsAndSize canvasPositionAndSize = getCanvasPositionAndSize(); BufferedImage image = new BufferedImage((int) canvasPositionAndSize.totalWidth, (int) canvasPositionAndSize.totalHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); int index = 0; for (ChartCanvas canvas : chartCanvasList) { Rectangle2D rectangle2D = canvasPositionAndSize.positionsAndSizes.get(index); ((Drawable) canvas.chart).draw(g2, new Rectangle((int) rectangle2D.getX(), (int) rectangle2D.getY(), (int) rectangle2D.getWidth(), (int) rectangle2D.getHeight())); index++; } try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) { ImageIO.write(image, "png", out); } } catch (IOException ex) { // FIXME: show a dialog with the error } } }
From source file:com.seleniumtests.driver.CustomEventFiringWebDriver.java
/** * Returns the rectangle of all screens on the system * @return// w w w . j a va2 s . c om */ private static Rectangle getScreensRectangle() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Rectangle screenRect = new Rectangle(0, 0, 0, 0); for (GraphicsDevice gd : ge.getScreenDevices()) { screenRect = screenRect.union(gd.getDefaultConfiguration().getBounds()); } return screenRect; }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java
@Override public void paintComponent(Graphics g) { super.paintComponent(g); if (getChart() == null) { return;/*from w w w. j a v a2 s. c o m*/ } Graphics2D g2 = (Graphics2D) g.create(); // first determine the size of the chart rendering area... Dimension size = getSize(); Insets insets = getInsets(); Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); // work out if scaling is required... boolean scale = false; double drawWidth = available.getWidth(); double drawHeight = available.getHeight(); setChartFieldValue(getChartFieldByName("scaleX"), 1.0); // this.scaleX = 1.0; setChartFieldValue(getChartFieldByName("scaleY"), 1.0); // this.scaleY = 1.0; if (drawWidth < getMinimumDrawWidth()) { setChartFieldValue(getChartFieldByName("scaleX"), drawWidth / getMinimumDrawWidth()); // this.scaleX = drawWidth / getMinimumDrawWidth(); drawWidth = getMinimumDrawWidth(); scale = true; } else if (drawWidth > getMaximumDrawWidth()) { setChartFieldValue(getChartFieldByName("scaleX"), drawWidth / getMaximumDrawWidth()); // this.scaleX = drawWidth / getMaximumDrawWidth(); drawWidth = getMaximumDrawWidth(); scale = true; } if (drawHeight < getMinimumDrawHeight()) { setChartFieldValue(getChartFieldByName("scaleY"), drawHeight / getMinimumDrawHeight()); // this.scaleY = drawHeight / getMinimumDrawHeight(); drawHeight = getMinimumDrawHeight(); scale = true; } else if (drawHeight > getMaximumDrawHeight()) { setChartFieldValue(getChartFieldByName("scaleY"), drawHeight / getMaximumDrawHeight()); // this.scaleY = drawHeight / getMaximumDrawHeight(); drawHeight = getMaximumDrawHeight(); scale = true; } Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight); // are we using the chart buffer? if ((Boolean) getChartFieldValueByName("useBuffer")) { // do we need to resize the buffer? if ((getChartFieldValueByName("chartBuffer") == null) || ((Integer) getChartFieldValueByName("chartBufferWidth") != available.getWidth()) || ((Integer) getChartFieldValueByName("chartBufferHeight") != available.getHeight())) { setChartFieldValue(getChartFieldByName("chartBufferWidth"), (int) available.getWidth()); // this.chartBufferWidth = (int) available.getWidth(); setChartFieldValue(getChartFieldByName("chartBufferHeight"), (int) available.getHeight()); // this.chartBufferHeight = (int) available.getHeight(); GraphicsConfiguration gc = g2.getDeviceConfiguration(); setChartFieldValue(getChartFieldByName("chartBuffer"), gc.createCompatibleImage((Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight"), Transparency.TRANSLUCENT)); // this.chartBuffer = gc.createCompatibleImage(this.chartBufferWidth, // this.chartBufferHeight, Transparency.TRANSLUCENT); setRefreshBuffer(true); } // do we need to redraw the buffer? if (getRefreshBuffer()) { setRefreshBuffer(false); // clear the flag Rectangle2D bufferArea = new Rectangle2D.Double(0, 0, (Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight")); Graphics2D bufferG2 = (Graphics2D) ((Image) getChartFieldValueByName("chartBuffer")).getGraphics(); Rectangle r = new Rectangle(0, 0, (Integer) getChartFieldValueByName("chartBufferWidth"), (Integer) getChartFieldValueByName("chartBufferHeight")); bufferG2.setPaint(getBackground()); bufferG2.fill(r); if (scale) { AffineTransform saved = bufferG2.getTransform(); AffineTransform st = AffineTransform.getScaleInstance( (Double) getChartFieldValueByName("scaleX"), (Double) getChartFieldValueByName("scaleY")); bufferG2.transform(st); getChart().draw(bufferG2, chartArea, getAnchor(), getChartRenderingInfo()); bufferG2.setTransform(saved); } else { getChart().draw(bufferG2, bufferArea, getAnchor(), getChartRenderingInfo()); } } // zap the buffer onto the panel... g2.drawImage((Image) getChartFieldValueByName("chartBuffer"), insets.left, insets.top, this); } // or redrawing the chart every time... else { AffineTransform saved = g2.getTransform(); g2.translate(insets.left, insets.top); if (scale) { AffineTransform st = AffineTransform.getScaleInstance((Double) getChartFieldValueByName("scaleX"), (Double) getChartFieldValueByName("scaleY")); g2.transform(st); } getChart().draw(g2, chartArea, getAnchor(), getChartRenderingInfo()); g2.setTransform(saved); } Iterator iterator = ((List) getChartFieldValueByName("overlays")).iterator(); while (iterator.hasNext()) { Overlay overlay = (Overlay) iterator.next(); overlay.paintOverlay(g2, this); } // redraw the zoom rectangle (if present) - if useBuffer is false, // we use XOR so we can XOR the rectangle away again without redrawing // the chart drawZoomRectangle(g2, !(Boolean) getChartFieldValueByName("useBuffer")); g2.dispose(); setAnchor(null); setVerticalTraceLine(null); setHorizontalTraceLine(null); }
From source file:SWTGraphics2D.java
/** * Returns the clip bounds.// w w w. j a va 2 s. com * * @return The clip bounds. */ public Rectangle getClipBounds() { org.eclipse.swt.graphics.Rectangle clip = this.gc.getClipping(); return new Rectangle(clip.x, clip.y, clip.width, clip.height); }
From source file:com.juanhg.cicloc.cicloCApplet.java
private void initSimulation() { Point2D[] nullArray = new Point2D[0]; //Crear modelo model = new cicloCModel(T1, T2, Vmin, Vmax, N, isHot); calculateLimits();/*from w ww .j av a 2 s.c o m*/ // Inicializar charts chartPV = new Grafica(nullArray, "", "", "V", "P", false, Color.BLUE, 1f, false); chartPV.agregarGrafica(nullArray, "", Color.RED, 1f, false); chartPV.setRangeAxis(VLimits, PLimits); chartUV = new Grafica(nullArray, "", "", "V", "U", false, Color.BLUE, 1f, false); chartUV.agregarGrafica(nullArray, "", Color.RED, 1f, false); chartUV.setRangeAxis(VLimits, ULimits); chartTV = new Grafica(nullArray, "", "", "V", "T", false, Color.BLUE, 1f, false); chartTV.agregarGrafica(nullArray, "", Color.RED, 1f, false); chartTV.setRangeAxis(VLimits, TLimits); chartPT = new Grafica(nullArray, "", "", "T", "P", false, Color.BLUE, 1f, false); chartPT.agregarGrafica(nullArray, "", Color.RED, 1f, false); chartPT.setRangeAxis(TLimits, PLimits); chartST = new Grafica(nullArray, "", "", "T", "S", false, Color.BLUE, 1f, false); chartST.agregarGrafica(nullArray, "", Color.RED, 1f, false); chartST.setRangeAxis(TLimits, SLimits); chartUT = new Grafica(nullArray, "", "", "T", "U", false, Color.BLUE, 1f, false); chartUT.agregarGrafica(nullArray, "", Color.RED, 1f, false); chartUT.setRangeAxis(TLimits, ULimits); chartPiston = new Grafica(nullArray, "", "", "", "", false, Color.BLUE, 1f, false); chartPiston.setRangeAxis(getPistonX0() - 0.5, (getPistonX1() + 0.5), 0, 10); chartPiston.fijaFondo(Color.WHITE); chartPiston.setAxisVisible(false); chartTermo = new Grafica(nullArray, "", "", "", "", false, Color.BLUE, 1f, false); chartTermo.setRangeAxis(0, 10, 0, 10); chartTermo.fijaFondo(Color.WHITE); chartTermo.setAxisVisible(false); tBulb = new Time(); tLED = new Time(); //Load Images waterTextureImage = loadImage(waterTexture); texture = new TexturePaint(waterTextureImage, new Rectangle(0, 0, 300, 200)); termoImage = loadImage(termo); //Set Images chartTermo.setImageAtPoint(termoImage, 5, 5); tAnnotation = new XYTextAnnotation("-", 5, 5); tAnnotation.setPaint(Color.RED); tAnnotation.setFont(new Font(null, 10, 40)); chartTermo.setAnnotation(tAnnotation); this.drawPiston(); //Actualize panels updatePanels(); repaint(); }
From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java
/**Render default view if there is no timeframe yet*/ private void renderNoInfoView(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setPaint(new TexturePaint(STROKED, new Rectangle(0, 0, 3, 3))); g2d.fillRect(0, 0, getWidth(), getHeight()); Font f = g2d.getFont().deriveFont(Font.BOLD, 14.0f); g2d.setFont(f);//from www . ja v a 2s . co m Rectangle2D bounds = g2d.getFontMetrics().getStringBounds("Kein Zeitfenster aktiv", g); int dx = 10; if (getWidth() > bounds.getWidth()) { dx = (int) Math.rint((getWidth() - bounds.getWidth()) / 2); } int dy = 10; if (getHeight() > bounds.getHeight()) { dy = (int) Math.rint((getHeight() - bounds.getHeight()) / 2); } g2d.setColor(Color.black); g2d.drawString("Kein Zeitfenster aktiv", dx, dy); }
From source file:gdsc.utils.Cell_Outliner.java
private PolygonRoi[] findCells(ImageProcessor inputProcessor) { // Limit processing to where it is needed bounds = createBounds(inputProcessor); ImageProcessor ip = inputProcessor.duplicate(); ip.setRoi(bounds);//w ww . j av a2 s.com ip = ip.crop(); if (kernels == null) { kernels = createKernels(); convolved = null; } if (convolved == null) { convolved = convolveImage(ip, kernels); //showConvolvedImages(convolved); } if (Thread.currentThread().isInterrupted()) return null; FloatProcessor combinedIp = null; Blitter b = null; ImagePlus combinedImp = null; if (debug) { combinedIp = new FloatProcessor(ip.getWidth(), ip.getHeight()); b = new FloatBlitter(combinedIp); combinedImp = displayImage(combinedIp, "Combined edge projection"); } PolygonRoi[] cells = new PolygonRoi[xpoints.length]; if (!this.buildMaskOutput) IJ.showStatus("Finding cells ..."); // Process each point for (int n = 0; n < xpoints.length; n++) { if (!this.buildMaskOutput) IJ.showProgress(n, xpoints.length); int cx = xpoints[n] - bounds.x; int cy = ypoints[n] - bounds.y; // Restrict bounds using the cell radius and tolerance int extra = (int) Math.ceil(cellRadius + cellRadius * tolerance + kernelWidth / 2); int minx = Math.max(0, cx - extra); int miny = Math.max(0, cy - extra); int maxx = Math.min(ip.getWidth() - 1, cx + extra); int maxy = Math.min(ip.getHeight() - 1, cy + extra); Rectangle pointBounds = new Rectangle(minx, miny, maxx - minx + 1, maxy - miny + 1); // Calculate the angle FloatProcessor angle = createAngleProcessor(ip, cx, cy, pointBounds); //if (debug) displayImage(angle, "Angle"); if (Thread.currentThread().isInterrupted()) return null; FloatProcessor edgeProjection = computeEdgeProjection(convolved, cx, cy, pointBounds, angle); // Initialise the edge as a circle. PolygonRoi cell = null; double[] params = { cx - minx, cy - miny, cellRadius, cellRadius, cellRadius, 0 }; double range = cellRadius * 0.9; // Iterate to find the best cell outline boolean returnEllipticalFit = ellipticalFit; for (int iter = 0; iter < iterations; iter++) { // Use the current elliptical edge to define the weights for the edge projection FloatProcessor weights = createWeightMap(pointBounds, params, range); if (Thread.currentThread().isInterrupted()) return null; if (debug) displayImage(weights, "Weight map"); FloatProcessor weightedEdgeProjection = applyWeights(edgeProjection, weights); if (debug) { b.copyBits(weightedEdgeProjection, pointBounds.x, pointBounds.y, Blitter.ADD); combinedIp.resetMinAndMax(); combinedImp.updateAndDraw(); displayImage(weightedEdgeProjection, "Weighted edge projection"); } cell = findPolygonalCell((int) Math.round(params[0]), (int) Math.round(params[1]), weightedEdgeProjection, angle); FloatProcessor weightMap = weightedEdgeProjection; // weights double[] newParams = fitPolygonalCell(cell, params, weightMap, angle); if (newParams == null) { returnEllipticalFit = false; break; } // Set the parameters for the weight map params = newParams; // Update the range to become smaller for a tighter fit //range = Math.max(3, range * 0.9); } // Return either the fitted elliptical cell or the last polygon outline if (returnEllipticalFit) { EllipticalCell e = new EllipticalCell(); FloatPolygon ellipse = e.drawEllipse(params); cell = new PolygonRoi(ellipse.xpoints, ellipse.ypoints, ellipse.npoints, PolygonRoi.POLYGON); } PolygonRoi finalCell = cell; if (dilate > 0) { // Dilate the cell and then trace the new outline ByteProcessor bp = new ByteProcessor(pointBounds.width, pointBounds.height); bp.setColor(CELL & 0xff); bp.draw(cell); for (int i = 0; i < dilate; i++) dilate(bp); cell = traceOutline(bp, params[0], params[1]); if (cell != null) finalCell = cell; } Rectangle pos = finalCell.getBounds(); // Does not work in IJ 1.46+ //finalCell.setLocation(pos.x + bounds.x + pointBounds.x, pos.y + bounds.y + pointBounds.y); // Create a new Polygon with the correct coordinates. This is required since IJ 1.46 // since setting the location is not passed through when drawing an overlay int[] xCoords = finalCell.getXCoordinates(); int[] yCoords = finalCell.getYCoordinates(); int nPoints = finalCell.getNCoordinates(); for (int i = 0; i < nPoints; i++) { xCoords[i] += pos.x + bounds.x + pointBounds.x; yCoords[i] += pos.y + bounds.y + pointBounds.y; } finalCell = new PolygonRoi(xCoords, yCoords, nPoints, Roi.POLYGON); cells[n] = finalCell; } return cells; }