List of usage examples for java.awt Graphics2D create
public abstract Graphics create();
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java
public void clip(final StrictBounds bounds) { final Graphics2D g = getGraphics(); graphicsContexts.push(g);/* www . j a v a2s . c om*/ graphics = (Graphics2D) g.create(); graphics.clip(StrictGeomUtility.createAWTRectangle(bounds)); }
From source file:org.pentaho.reporting.engine.classic.extensions.modules.sbarcodes.BarcodeWrapper.java
public void draw(final Graphics2D g2, final Rectangle2D bounds) { final Graphics2D gr2 = (Graphics2D) g2.create(); try {/*from w w w . jav a 2s .c om*/ gr2.clip(bounds); if (scale) { final Dimension size = barcode.getPreferredSize(); final double horzScale = bounds.getWidth() / size.getWidth(); final double vertScale = bounds.getHeight() / size.getHeight(); if (keepAspectRatio) { final double scale = Math.min(horzScale, vertScale); gr2.scale(scale, scale); } else { gr2.scale(horzScale, vertScale); } } barcode.draw(gr2, (int) bounds.getX(), (int) bounds.getY()); } catch (OutputException e) { logger.error("Unable to draw barcode element", e); } finally { gr2.dispose(); } }
From source file:pt.lsts.neptus.console.plugins.ImageLayers.java
@Override public void paint(Graphics2D g, StateRenderer2D renderer) { g.setColor(Color.orange);/*from w w w .ja v a 2s . c om*/ g.drawString(note, 50, 20); for (ImageLayer il : layers) il.paint((Graphics2D) g.create(), renderer); }
From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java
@Override public void paintInteraction(Graphics2D g, StateRenderer2D source) { super.paintInteraction(g, source); g.setStroke(new BasicStroke(1f)); paint(g, source);/*from www .j ava 2 s . c om*/ AssetPosition pivot = intercepted; if (pivot != null) { Point2D pt = source.getScreenPosition(pivot.getLoc()); g.setColor(Color.white); g.draw(new Ellipse2D.Double(pt.getX() - 6, pt.getY() - 6, 12, 12)); if (assetProperties.containsKey(pivot.getAssetName())) pivot.putExtra("Description", assetProperties.get(pivot.getAssetName()).description); if (assetProperties.containsKey(pivot.getAssetName())) pivot.putExtra("Friendly name", assetProperties.get(pivot.getAssetName()).friendly); lbl.setOpaque(true); lbl.setBackground(new Color(255, 255, 255, 128)); lbl.setText(pivot.getHtml()); Dimension d = lbl.getPreferredSize(); lbl.setSize(d); Graphics copy = g.create(); copy.translate(10, 10); lbl.paint(copy); } for (AssetTrack t : assets.values()) { AssetPosition prev = t.getLatest(); AssetPosition pred = t.getPrediction(); if (prev != null && pred != null) { if (prev.getTimestamp() < oldestTimestampSelection || prev.getTimestamp() > newestTimestampSelection) continue; g.setColor(new Color(t.getColor().getRed(), t.getColor().getGreen(), t.getColor().getBlue(), 128)); Point2D pt1 = source.getScreenPosition(prev.getLoc()); Point2D pt2 = source.getScreenPosition(pred.getLoc()); if (pt1.distance(pt2) < 1000) g.draw(new Line2D.Double(pt1, pt2)); } } }
From source file:pt.lsts.neptus.plugins.wg.WgCtdLayer.java
private boolean paintHistory(Graphics2D g, StateRenderer2D renderer) { boolean paintedToRender = false; Long endMark = dataDateEnd.getTime(); Long timeMark = dataDateStart.getTime(); CtdData dataPoint;//from w ww. j a v a 2 s .c o m // double tempMaxTemp, tempMinTemp; // timeMark = ctdHistory.higherKey(timeMark); // if (timeMark != null) { // dataPoint = ctdHistory.get(timeMark); // tempMaxTemp = dataPoint.temperature; // tempMinTemp = dataPoint.temperature; // } // else { // tempMaxTemp = maxTemp; // tempMinTemp = minTemp; // } Color color; Graphics2D gt; Point2D pt; int width = (renderer.getZoom() > 1) ? (int) (5 * renderer.getZoom()) : 5; if (renderer.getZoom() < 0.002) { timeMark = ctdHistory.higherKey(timeMark); if (timeMark != null && timeMark <= endMark) { dataPoint = ctdHistory.get(timeMark); pt = renderer.getScreenPosition(dataPoint.location); if (isVisibleInRender(pt, renderer)) { gt = (Graphics2D) g.create(); color = genColor(dataPoint.temperature); gt.setColor(color); gt.fillOval((int) pt.getX(), (int) pt.getY(), 10, 10); gt.dispose(); paintedToRender = true; } } } else { try { timeMark = ctdHistory.higherKey(timeMark); // TODO avoid for in case of being too far from location shown on map for (timeMark = ctdHistory.higherKey(timeMark); timeMark != null && timeMark <= endMark; timeMark = ctdHistory.higherKey(timeMark + 1)) { dataPoint = ctdHistory.get(timeMark); pt = renderer.getScreenPosition(dataPoint.location); if (!isVisibleInRender(pt, renderer)) { continue; } // check if it is visible gt = (Graphics2D) g.create(); color = genColor(dataPoint.temperature); gt.setColor(color); gt.fillOval((int) pt.getX(), (int) pt.getY(), width, width); gt.dispose(); paintedToRender = true; } } catch (NullPointerException e) { System.out.println("timeMark"); } } return paintedToRender; }
From source file:pt.lsts.neptus.plugins.wg.WgCtdLayer.java
private void paintCaption(Graphics2D g) { cbar.setCmap(cmap);/*from w ww .j av a 2 s . c o m*/ cbar.setSize(new Dimension(20, 120)); Graphics copy = g.create(); copy.translate(10, 10); cbar.paint(copy); copy.setColor(Color.white); copy.drawString(String.format("%3.2f C", minTemp), 23, 120); copy.drawString(String.format("%3.2f C", maxTemp), 23, 10); }
From source file:uk.co.modularaudio.service.gui.impl.racktable.back.AbstractLinkImage.java
private void drawLinkWireIntoImage(final Point sourcePoint, final Point sinkPoint) { // log.debug("Drawing link from " + sourcePoint + " to " + sinkPoint); final int fromX = sourcePoint.x; final int fromY = sourcePoint.y; final int toX = sinkPoint.x; final int toY = sinkPoint.y; float f1, f2, f3, f4, f5, f6, f7, f8 = 0.0f; f1 = fromX;/*from w ww .j av a2 s. c o m*/ f2 = fromY; f3 = fromX; f4 = fromY + WIRE_DIP_PIXELS; f5 = toX; f6 = toY + WIRE_DIP_PIXELS; f7 = toX; f8 = toY; final CubicCurve2D cubicCurve = new CubicCurve2D.Float(f1, f2, f3, f4, f5, f6, f7, f8); final Rectangle cubicCurveBounds = cubicCurve.getBounds(); final int imageWidthToUse = cubicCurveBounds.width + LINK_IMAGE_PADDING_FOR_WIRE_RADIUS; // int imageHeightToUse = cubicCurveBounds.height + WIRE_DIP_PIXELS; int imageHeightToUse = cubicCurveBounds.height; // If the wire is close to vertical (little Y difference) we make the image a little bigger to account for the wire "dip" if (Math.abs(sinkPoint.y - sourcePoint.y) <= WIRE_DIP_PIXELS) { imageHeightToUse += (WIRE_DIP_PIXELS / 2); } // bufferedImage = new BufferedImage( imageWidthToUse, imageHeightToUse, BufferedImage.TYPE_INT_ARGB ); try { tiledBufferedImage = bufferImageAllocationService.allocateBufferedImage(allocationSource, allocationMatchToUse, AllocationLifetime.SHORT, AllocationBufferType.TYPE_INT_ARGB, imageWidthToUse, imageHeightToUse); bufferedImage = tiledBufferedImage.getUnderlyingBufferedImage(); final Graphics2D g2d = bufferedImage.createGraphics(); g2d.setComposite(AlphaComposite.Clear); g2d.fillRect(0, 0, imageWidthToUse, imageHeightToUse); g2d.setComposite(AlphaComposite.SrcOver); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); f1 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x; f2 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y; f3 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x; f4 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y; f5 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x; f6 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y; f7 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x; f8 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y; final CubicCurve2D offSetCubicCurve = new CubicCurve2D.Float(f1, f2, f3, f4, f5, f6, f7, f8); // Draw the highlight and shadow if (DRAW_HIGHTLIGHT_AND_SHADOW) { final Graphics2D sG2d = (Graphics2D) g2d.create(); sG2d.translate(WIRE_SHADOW_X_OFFSET, WIRE_SHADOW_Y_OFFSET); sG2d.setColor(Color.BLUE.darker()); sG2d.setStroke(new BasicStroke(WIRE_SHADOW_WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); sG2d.draw(offSetCubicCurve); final Graphics2D hG2d = (Graphics2D) g2d.create(); hG2d.translate(WIRE_HIGHLIGHT_X_OFFSET, WIRE_HIGHLIGHT_Y_OFFSET); hG2d.setColor(Color.WHITE); hG2d.setStroke( new BasicStroke(WIRE_HIGHLIGHT_WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); hG2d.draw(offSetCubicCurve); } g2d.setColor(Color.BLACK); g2d.setStroke(wireStroke); g2d.draw(offSetCubicCurve); g2d.setColor(Color.BLUE); g2d.setStroke(wireBodyStroke); g2d.draw(offSetCubicCurve); // For debugging, draw a green line around the outside of this image. if (DRAW_WIRE_BOUNDING_BOX) { g2d.setStroke(basicStrokeOfOne); g2d.setColor(Color.GREEN); g2d.drawRect(0, 0, imageWidthToUse - 1, imageHeightToUse - 1); } rectangle.x = cubicCurveBounds.x - LINK_IMAGE_DIST_TO_CENTER; rectangle.y = cubicCurveBounds.y - LINK_IMAGE_DIST_TO_CENTER; rectangle.width = imageWidthToUse; rectangle.height = imageHeightToUse; } catch (final Exception e) { final String msg = "Exception caught allocating buffered image: " + e.toString(); log.error(msg, e); } }