List of usage examples for java.awt Graphics2D fill
public abstract void fill(Shape s);
From source file:org.nuclos.client.ui.resplan.header.JHeaderGrid.java
@Override protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; super.paintComponent(g2d); g2d.setPaint(gridColor);/*from ww w. j a v a 2 s. c o m*/ Rectangle clipBounds = g.getClipBounds(); int[] indices = stripRangeForRect(clipBounds); int startIndex = indices[0]; int endIndex = indices[1]; Point p1, p2; p1 = new Point(); p2 = new Point(getWidth(), getHeight()); for (int i = startIndex; i <= endIndex; i++) { int gridLine = getGridLine(i); orientation.updateCoord(p1, gridLine); orientation.updateCoord(p2, gridLine); g2d.drawLine(p1.x, p1.y, p2.x, p2.y); } p1.setLocation(0, 0); p2.setLocation(getWidth(), getHeight()); int groupGridLine = 0; for (CategoryView v : groupings) { groupGridLine += v.size; orientation.opposite().updateCoord(p1, groupGridLine); orientation.opposite().updateCoord(p2, groupGridLine); g2d.drawLine(p1.x, p1.y, p2.x, p2.y); groupGridLine += GRID_SIZE; } for (int level = 0, levelCount = groupings.length; level < levelCount; level++) { for (HeaderCell cell : groupings[level].cells) { if (cell.endIndex < startIndex || cell.startIndex >= endIndex) continue; Rectangle rect = getRect(level, cell.startIndex, cell.endIndex); if (clipBounds != null && !clipBounds.intersects(rect)) continue; paintHeaderCell(g2d, rect, cell.levelValue); } } if (cellResizingRange != null) { Rectangle rect = new Rectangle(getWidth(), getHeight()); orientation.updateRange(rect, cellResizingRange); rect.grow(orientation.select(GRID_SIZE, 0), orientation.select(0, GRID_SIZE)); g2d.setColor(new Color(0x9999ff, false)); g2d.draw(rect); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f)); g2d.fill(rect); } }
From source file:org.oscarehr.common.web.PregnancyAction.java
public ActionForward getFundalImage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { List<Point2D.Double> points = new ArrayList<Point2D.Double>(); int index = 1; while (true) { String ga = request.getParameter("ga" + index); String cm = request.getParameter("fh" + index); if (ga == null || cm == null) break; String weeks = null;/*from ww w. ja v a2s . com*/ String offset = null; try { weeks = ga.substring(0, ga.indexOf("w")); offset = "0"; if (ga.indexOf("+") != -1) offset = ga.substring(ga.indexOf("+") + 1); } catch (Exception e) { MiscUtils.getLogger().warn("Error", e); } if (weeks != null && offset != null) { try { double gaa = Integer.parseInt(weeks) + (Integer.parseInt(offset) / 7); double cma = Double.parseDouble(cm); Point2D.Double p = new Point2D.Double(gaa, cma); points.add(p); } catch (NumberFormatException e) { MiscUtils.getLogger().warn("Error", e); } } index++; } File file = new File(request.getSession().getServletContext().getRealPath("/") + "WEB-INF/classes/oscar/form/prop/fundal_graph.png"); BufferedImage bufferedImage = ImageIO.read(file); Graphics2D g = bufferedImage.createGraphics(); g.setColor(Color.black); g.setStroke(new BasicStroke(2)); int xStart = 23; //each week is 10.25pixels int yStart = 318; //each height is 10.6pixels int width = 7; int height = 7; int startingWeek = 20; int startingHeight = 15; Point2D.Double lastPoint = null; for (Point2D.Double p : points) { if (p.x < startingWeek || p.x > 42) continue; if (p.y < startingHeight || p.y > 45) continue; Rectangle r = new Rectangle((int) (xStart + (10.25 * (p.x - startingWeek)) - (width / 2)), (int) (yStart - (10.60 * (p.y - startingHeight)) - (height / 2)), width, height); g.fill(r); if (lastPoint != null) { g.drawLine((int) (xStart + (10.25 * (lastPoint.x - startingWeek))), (int) (yStart - (10.60 * (lastPoint.y - startingHeight))), (int) (xStart + (10.25 * (p.x - startingWeek))), (int) (yStart - (10.60 * (p.y - startingHeight)))); } lastPoint = p; } g.dispose(); response.setContentType("image/png"); OutputStream outputStream = response.getOutputStream(); ImageIO.write(bufferedImage, "png", outputStream); outputStream.close(); return null; }
From source file:org.pentaho.reporting.designer.core.editor.report.AbstractRenderComponent.java
protected void paintComponent(final Graphics g) { if (fpsCalculator.isActive()) { fpsCalculator.tick();//from w w w .j av a 2 s . c o m } final Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(new Color(224, 224, 224)); g2.fillRect(0, 0, getWidth(), getHeight()); final int leftBorder = (int) getLeftBorder(); final int topBorder = (int) getTopBorder(); final float scaleFactor = getRenderContext().getZoomModel().getZoomAsPercentage(); // draw the page area .. final PageDefinition pageDefinition = getRenderContext().getContextRoot().getPageDefinition(); final Rectangle2D.Double area = new Rectangle2D.Double(0, 0, pageDefinition.getWidth() * scaleFactor, getHeight()); g2.translate(leftBorder * scaleFactor, topBorder * scaleFactor); g2.clip(area); g2.setColor(Color.WHITE); g2.fill(area); // draw the grid (unscaled, but translated) final Point2D offset = getOffset(); if (offset.getX() != 0) { // The blackout area is for inline sub-reports and is the area where the subreport is not interested in // (so we can clip out). The blackout area is only visible in the sub-report. final Rectangle2D.Double blackoutArea = new Rectangle2D.Double(0, 0, offset.getX() * scaleFactor, getHeight()); g2.setColor(Color.LIGHT_GRAY); g2.fill(blackoutArea); } paintGrid(g2); paintElementAlignment(g2); g2.dispose(); final Graphics2D logicalPageAreaG2 = (Graphics2D) g.create(); // draw the renderable content ... logicalPageAreaG2.translate(leftBorder * scaleFactor, topBorder * scaleFactor); logicalPageAreaG2.clip(area); logicalPageAreaG2.scale(scaleFactor, scaleFactor); try { final ElementRenderer rendererRoot = getElementRenderer(); if (rendererRoot != null) { if (rendererRoot.draw(logicalPageAreaG2) == false) { rendererRoot.handleError(designerContext, renderContext); logicalPageAreaG2.scale(1f / scaleFactor, 1f / scaleFactor); logicalPageAreaG2.setPaint(Color.WHITE); logicalPageAreaG2.fill(area); } } } catch (Exception e) { // ignore for now.. UncaughtExceptionsModel.getInstance().addException(e); } logicalPageAreaG2.dispose(); final OverlayRenderer[] renderers = new OverlayRenderer[4]; renderers[0] = new OverlappingElementOverlayRenderer(getDefaultElement()); // displays the red border for warning renderers[1] = new SelectionOverlayRenderer(getDefaultElement()); renderers[2] = new GuidelineOverlayRenderer(horizontalLinealModel, verticalLinealModel); renderers[3] = new SelectionRectangleOverlayRenderer(); // blue box when you shift and drag the region to select multiple // elements for (int i = 0; i < renderers.length; i++) { final OverlayRenderer renderer = renderers[i]; final Graphics2D selectionG2 = (Graphics2D) g.create(); renderer.validate(getRenderContext(), scaleFactor, offset); renderer.draw(selectionG2, new Rectangle2D.Double(getLeftBorder(), getTopBorder(), getWidth(), getHeight()), this); selectionG2.dispose(); } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java
/** * Draws the object.// w w w . j a v a 2 s . co m * * @param graphics * the graphics device. * @param area * the area inside which the object should be drawn. */ public void draw(final Graphics2D graphics, final Rectangle2D area) { final Graphics2D g2 = (Graphics2D) graphics.create(); if (isDrawPageBackground()) { g2.setPaint(Color.white); g2.fill(area); } g2.translate(-area.getX(), -area.getY()); try { final StrictBounds pageBounds = StrictGeomUtility.createBounds(area.getX(), area.getY(), area.getWidth(), area.getHeight()); this.pageArea = pageBounds; this.drawArea = pageBounds; this.graphics = g2; if (startBlockBox(rootBox)) { processRootBand(pageBounds); } finishBlockBox(rootBox); } finally { this.graphics = null; this.drawArea = null; g2.dispose(); } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java
protected void renderBoxBorderAndBackground(final RenderBox box) { final Graphics2D g2 = getGraphics(); if (isOutlineMode()) { drawOutlineBox(g2, box);//from w ww . jav a2 s. c o m if (isIgnoreBorderWhenDrawingOutline()) { return; } } if (box.getBoxDefinition().getBorder().isEmpty() == false) { borderRenderer.paintBackgroundAndBorder(box, g2); } else { final Color backgroundColor = (Color) box.getStyleSheet() .getStyleProperty(ElementStyleKeys.BACKGROUND_COLOR); if (backgroundColor != null) { final double x = StrictGeomUtility.toExternalValue(box.getX()); final double y = StrictGeomUtility.toExternalValue(box.getY()); final double w = StrictGeomUtility.toExternalValue(box.getWidth()); final double h = StrictGeomUtility.toExternalValue(box.getHeight()); boxArea.setFrame(x, y, w, h); g2.setColor(backgroundColor); g2.fill(boxArea); } } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java
private void setPaint(final boolean invert, final double xoffset, final double yoffset, final boolean fill) { if (paint instanceof Color) { final Color color = (Color) paint; final int alpha = color.getAlpha(); if (fill) { if (alpha != currentFillGState) { currentFillGState = alpha; PdfGState gs = fillGState[alpha]; if (gs == null) { gs = new PdfGState(); gs.setFillOpacity(alpha / 255.00f); fillGState[alpha] = gs; }//ww w.ja v a 2s .c o m cb.setGState(gs); } cb.setColorFill(color); } else { if (alpha != currentStrokeGState) { currentStrokeGState = alpha; PdfGState gs = strokeGState[alpha]; if (gs == null) { gs = new PdfGState(); gs.setStrokeOpacity(alpha / 255.0f); strokeGState[alpha] = gs; } cb.setGState(gs); } cb.setColorStroke(color); } } else if (paint instanceof GradientPaint) { final GradientPaint gp = (GradientPaint) paint; final Point2D p1 = gp.getPoint1(); transform.transform(p1, p1); final Point2D p2 = gp.getPoint2(); transform.transform(p2, p2); final Color c1 = gp.getColor1(); final Color c2 = gp.getColor2(); final PdfShading shading = PdfShading.simpleAxial(cb.getPdfWriter(), (float) p1.getX(), normalizeY((float) p1.getY()), (float) p2.getX(), normalizeY((float) p2.getY()), c1, c2); final PdfShadingPattern pat = new PdfShadingPattern(shading); if (fill) { cb.setShadingFill(pat); } else { cb.setShadingStroke(pat); } } else if (paint instanceof TexturePaint) { try { final TexturePaint tp = (TexturePaint) paint; final BufferedImage img = tp.getImage(); final Rectangle2D rect = tp.getAnchorRect(); final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null); final PdfPatternPainter pattern = cb.createPattern(image.getWidth(), image.getHeight()); final AffineTransform inverse = this.normalizeMatrix(); inverse.translate(rect.getX(), rect.getY()); inverse.scale(rect.getWidth() / image.getWidth(), -rect.getHeight() / image.getHeight()); final double[] mx = new double[6]; inverse.getMatrix(mx); pattern.setPatternMatrix((float) mx[0], (float) mx[1], (float) mx[2], (float) mx[3], (float) mx[4], (float) mx[5]); image.setAbsolutePosition(0, 0); pattern.addImage(image); if (fill) { cb.setPatternFill(pattern); } else { cb.setPatternStroke(pattern); } } catch (Exception ex) { if (fill) { cb.setColorFill(Color.gray); } else { cb.setColorStroke(Color.gray); } } } else { try { int type = BufferedImage.TYPE_4BYTE_ABGR; if (paint.getTransparency() == Transparency.OPAQUE) { type = BufferedImage.TYPE_3BYTE_BGR; } final BufferedImage img = new BufferedImage((int) width, (int) height, type); final Graphics2D g = (Graphics2D) img.getGraphics(); g.transform(transform); final AffineTransform inv = transform.createInverse(); Shape fillRect = new Rectangle2D.Double(0, 0, img.getWidth(), img.getHeight()); fillRect = inv.createTransformedShape(fillRect); g.setPaint(paint); g.fill(fillRect); if (invert) { final AffineTransform tx = new AffineTransform(); tx.scale(1, -1); tx.translate(-xoffset, -yoffset); g.drawImage(img, tx, null); } g.dispose(); // g = null; final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null); final PdfPatternPainter pattern = cb.createPattern(width, height); image.setAbsolutePosition(0, 0); pattern.addImage(image); if (fill) { cb.setPatternFill(pattern); } else { cb.setPatternStroke(pattern); } } catch (Exception ex) { if (fill) { cb.setColorFill(Color.gray); } else { cb.setColorStroke(Color.gray); } } } }
From source file:org.pentaho.reporting.engine.classic.demo.ancient.demo.nogui.StraightToPNG.java
/** * Saves a report to PDF format./*from ww w.j a va 2 s. c om*/ * * @param report the report. * @param fileName target file name. * @return true or false. */ public boolean savePNG(final MasterReport report, final String fileName) { try { final PrintReportProcessor prc = new PrintReportProcessor(report); final int numberOfPages = prc.getNumberOfPages(); for (int i = 0; i < numberOfPages; i++) { final String fileNameFormated = MessageFormat.format(fileName, new Object[] { new Integer(i) }); final BufferedImage image = createImage(report.getPageDefinition()); final Rectangle rect = new Rectangle(0, 0, image.getWidth(), image.getHeight()); // prepare the image by filling it ... final Graphics2D g2 = image.createGraphics(); g2.setPaint(Color.white); g2.fill(rect); final PageDrawable pageDrawable = prc.getPageDrawable(i); pageDrawable.draw(g2, rect); g2.dispose(); // convert to PNG ... final PngEncoder encoder = new PngEncoder(image, true, 0, 9); final byte[] data = encoder.pngEncode(); final BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fileNameFormated)); out.write(data); out.close(); } return true; } catch (Exception e) { System.err.println("Writing PDF failed."); e.printStackTrace(); return false; } }
From source file:org.pentaho.reporting.libraries.pixie.wmf.WmfFile.java
public synchronized BufferedImage replay(final int imageX, final int imageY) { final BufferedImage image = new BufferedImage(imageX, imageY, BufferedImage.TYPE_INT_ARGB); final Graphics2D graphics = image.createGraphics(); // clear the image area ... graphics.setPaint(new Color(0, 0, 0, 0)); graphics.fill(new Rectangle(0, 0, imageX, imageY)); draw(graphics, new Rectangle2D.Float(0, 0, imageX, imageY)); graphics.dispose();/*from w w w .j ava 2 s . c om*/ return image; }
From source file:org.processmining.analysis.performance.sequence.Pattern.java
/** * Draws a rectangle of width 20, height length and starting point * (startX,startY) in the northwest corner of the rectangle. In case * logicSteps is true, the height is 10. * //from w ww . j a v a 2s . c o m * @param startX * double * @param startY * double * @param length * double * @param logicSteps * boolean * @param g * Graphics2D */ public void drawRectangle(double startX, double startY, double length, boolean logicSteps, Graphics2D g) { Rectangle2D r = new Rectangle2D.Double(startX, startY, 20, length); if (logicSteps) { r = new Rectangle2D.Double(startX, startY, 20, 10); } Color initialColor = g.getColor(); Paint initialPaint = g.getPaint(); GradientPaint towhite = new GradientPaint(((Double) startX).floatValue(), ((Double) startY).floatValue(), initialColor, ((Double) startX).floatValue() + 20, ((Double) (startY)).floatValue(), Color.WHITE); g.setPaint(towhite); g.fill(r); g.setPaint(initialPaint); g.setColor(Color.BLACK); g.draw(r); g.setColor(initialColor); }
From source file:org.squidy.designer.shape.ZoomShape.java
@Override protected void paintAfterChildren(PPaintContext paintContext) { super.paintAfterChildren(paintContext); Graphics2D g = paintContext.getGraphics(); if (multiSelection != null) { g.setColor(COLOR_MULTI_SELECTION); g.fill(globalToLocal((Rectangle2D) ((RectangularShape) multiSelection).clone())); g.setColor(Color.BLUE);/*from w w w . j a va2 s. c o m*/ // System.out.println(getGlobalScale()); g.setStroke(STROKE_MULTI_SELECTION); g.draw(globalToLocal((Rectangle2D) ((RectangularShape) multiSelection).clone())); } }