List of usage examples for java.awt Graphics2D fill
public abstract void fill(Shape s);
From source file:org.eqaula.glue.faces.MethodPrinter.java
public Method printToDownload(Method method) { try {/*w w w.ja v a2s . c om*/ if (Method.Type.SEMAPHORE.equals(method.getMethodType())) { // So, browser is requesting the image. Get ID value from actual request param. BufferedImage bufferedImg = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = bufferedImg.createGraphics(); String color = "gray"; //Default color if (!method.getWrappers().isEmpty()) { color = method.getWrappers().get(0).getValue(); } Field field = Class.forName("java.awt.Color").getField(color); g2.setColor((Color) field.get(null)); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Ellipse2D.Float sign1 = new Ellipse2D.Float(0F, 0F, 32F, 32F); g2.fill(sign1); //g2.drawString(method.getTarget().getCurrentValue().toString(), 0, 10); ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(bufferedImg, "png", os); writeStreamedContentToFile(method, new ByteArrayInputStream(os.toByteArray())); } } catch (Exception e) { e.printStackTrace(); } return method; }
From source file:org.esa.s2tbx.dataio.s2.l1b.L1bSceneDescription.java
public BufferedImage createTilePicture(int width) { Color[] colors = new Color[] { Color.GREEN, Color.RED, Color.BLUE, Color.YELLOW }; double scale = width / sceneRectangle.getWidth(); int height = (int) Math.round(sceneRectangle.getHeight() * scale); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = image.createGraphics(); graphics.scale(scale, scale);/*from w ww .j av a2 s . co m*/ graphics.translate(-sceneRectangle.getX(), -sceneRectangle.getY()); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setPaint(Color.WHITE); graphics.fill(sceneRectangle); graphics.setStroke(new BasicStroke(100F)); graphics.setFont(new Font("Arial", Font.PLAIN, 800)); for (int i = 0; i < tileInfos.length; i++) { Rectangle rect = tileInfos[i].rectangle; graphics.setPaint(addAlpha(colors[i % colors.length].brighter(), 100)); graphics.fill(rect); } for (int i = 0; i < tileInfos.length; i++) { Rectangle rect = tileInfos[i].rectangle; graphics.setPaint(addAlpha(colors[i % colors.length].darker(), 100)); graphics.draw(rect); graphics.setPaint(colors[i % colors.length].darker().darker()); graphics.drawString("Tile " + (i + 1) + ": " + tileInfos[i].id, rect.x + 1200F, rect.y + 2200F); } return image; }
From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphNode.java
/** * Draw a GraphNode as a rectangle with a name * * @param g The Java2D Graphics//from w ww.j a va 2 s. c o m * @param col The color to draw */ public void drawNode(final Graphics2D g, final Color col) { final int x = displayPosition.x; final int y = displayPosition.y; g.setFont(g.getFont().deriveFont(Font.BOLD, 11)); final FontMetrics metrics = g.getFontMetrics(); final String name = node.getId(); final Rectangle2D rect = metrics.getStringBounds(name, g); final int stringWidth = (int) rect.getWidth(); setSize(Math.max(stringWidth, 50) + 10, 25); int step = 4; int alpha = 96; for (int i = 0; i < step; ++i) { g.setColor(new Color(0, 0, 0, alpha - (32 * i))); g.drawLine(x + i + 1, y + nodeHeight + i, x + nodeWidth + i - 1, y + nodeHeight + i); g.drawLine(x + nodeWidth + i, y + i, x + nodeWidth + i, y + nodeHeight + i); } Shape clipShape = new Rectangle(x, y, nodeWidth, nodeHeight); g.setComposite(AlphaComposite.SrcAtop); g.setPaint(new GradientPaint(x, y, col, x + nodeWidth, y + nodeHeight, col.darker())); g.fill(clipShape); g.setColor(Color.blue); g.draw3DRect(x, y, nodeWidth - 1, nodeHeight - 1, true); g.setColor(Color.BLACK); g.drawString(name, x + (nodeWidth - stringWidth) / 2, y + 15); }
From source file:org.evors.rs.kjunior.SimulatedKJunior.java
@Override public void render(Graphics2D g2) { g2.setStroke(bstroke);/*from w w w. ja v a2 s . c o m*/ g2.setColor(Color.RED); float[] input = getInput(); for (int i = 0; i < NUM_IRs; i++) { Line IR = Line.fromPolarVec(getIRBase(irAngles[i]), irAngles[i], input[i]); g2.draw(IR.toLine2D()); } g2.setColor(new Color(45, 45, 45)); g2.fill(getShape().toJava2DShape()); }
From source file:org.evors.rs.unibot.sim.SimulatedUnibot.java
@Override public void render(Graphics2D g2) { g2.setColor(new Color(45, 45, 45)); g2.fill(getShape().toJava2DShape()); g2.setStroke(bstroke);/*from w w w. ja va2s. co m*/ g2.setColor(Color.RED); g2.draw(getShortenedRangeFinderLine().toLine2D()); }
From source file:org.fao.geonet.services.region.GetMap.java
public Element exec(Element params, ServiceContext context) throws Exception { Util.toLowerCase(params);/* ww w . j a va2s . c om*/ String id = params.getChildText(Params.ID); String srs = Util.getParam(params, MAP_SRS_PARAM, "EPSG:4326"); String widthString = Util.getParamText(params, WIDTH_PARAM); String heightString = Util.getParamText(params, HEIGHT_PARAM); String background = Util.getParamText(params, BACKGROUND_PARAM); String geomParam = Util.getParamText(params, GEOM_PARAM); String geomType = Util.getParam(params, GEOM_TYPE_PARAM, GeomFormat.WKT.toString()); String geomSrs = Util.getParam(params, GEOM_SRS_PARAM, "EPSG:4326"); if (id == null && geomParam == null) { throw new BadParameterEx(Params.ID, "Either " + GEOM_PARAM + " or " + Params.ID + " is required"); } if (id != null && geomParam != null) { throw new BadParameterEx(Params.ID, "Only one of " + GEOM_PARAM + " or " + Params.ID + " is permitted"); } // see calculateImageSize for more parameter checks Geometry geom = null; if (id != null) { Collection<RegionsDAO> daos = context.getApplicationContext().getBeansOfType(RegionsDAO.class).values(); for (RegionsDAO regionsDAO : daos) { geom = regionsDAO.getGeom(context, id, false, srs); if (geom != null) { break; } } if (geom == null) { throw new RegionNotFoundEx(id); } } else { GeomFormat format = GeomFormat.find(geomType); geom = format.parse(geomParam); if (!geomSrs.equals(srs)) { CoordinateReferenceSystem mapCRS = Region.decodeCRS(srs); CoordinateReferenceSystem geomCRS = Region.decodeCRS(geomSrs); MathTransform transform = CRS.findMathTransform(geomCRS, mapCRS, true); geom = JTS.transform(geom, transform); } } BufferedImage image; Envelope bboxOfImage = new Envelope(geom.getEnvelopeInternal()); double expandFactor = 0.2; bboxOfImage.expandBy(bboxOfImage.getWidth() * expandFactor, bboxOfImage.getHeight() * expandFactor); Dimension imageDimenions = calculateImageSize(bboxOfImage, widthString, heightString); Exception error = null; if (background != null) { if (this.namedBackgrounds.containsKey(background)) { background = this.namedBackgrounds.get(background); } String minx = Double.toString(bboxOfImage.getMinX()); String maxx = Double.toString(bboxOfImage.getMaxX()); String miny = Double.toString(bboxOfImage.getMinY()); String maxy = Double.toString(bboxOfImage.getMaxY()); background = background.replace("{minx}", minx).replace("{maxx}", maxx).replace("{miny}", miny) .replace("{maxy}", maxy).replace("{srs}", srs) .replace("{width}", Integer.toString(imageDimenions.width)) .replace("{height}", Integer.toString(imageDimenions.height)).replace("{MINX}", minx) .replace("{MAXX}", maxx).replace("{MINY}", miny).replace("{MAXY}", maxy).replace("{SRS}", srs) .replace("{WIDTH}", Integer.toString(imageDimenions.width)) .replace("{HEIGHT}", Integer.toString(imageDimenions.height)); InputStream in = null; try { URL imageUrl = new URL(background); in = imageUrl.openStream(); image = ImageIO.read(in); } catch (IOException e) { image = new BufferedImage(imageDimenions.width, imageDimenions.height, BufferedImage.TYPE_INT_ARGB); error = e; } finally { if (in != null) { IOUtils.closeQuietly(in); } } } else { image = new BufferedImage(imageDimenions.width, imageDimenions.height, BufferedImage.TYPE_INT_ARGB); } Graphics2D graphics = image.createGraphics(); try { if (error != null) { graphics.drawString(error.getMessage(), 0, imageDimenions.height / 2); } ShapeWriter shapeWriter = new ShapeWriter(); AffineTransform worldToScreenTransform = worldToScreenTransform(bboxOfImage, imageDimenions); // MathTransform mathTransform = new AffineTransform2D(worldToScreenTransform); // Geometry screenGeom = JTS.transform(geom, mathTransform); Shape shape = worldToScreenTransform.createTransformedShape(shapeWriter.toShape(geom)); graphics.setColor(Color.yellow); graphics.draw(shape); graphics.setColor(new Color(255, 255, 0, 100)); graphics.fill(shape); } finally { graphics.dispose(); } File tmpFile = File.createTempFile("GetMap", "." + format); ImageIO.write(image, format, tmpFile); return BinaryFile.encode(200, tmpFile.getAbsolutePath(), true); }
From source file:org.geowebcache.georss.GeometryRasterMaskBuilder.java
/** * @param geom a geometry to mask the affected tiles for, in this matrix's gridSubSet coordinate * reference system/*from w ww.ja v a 2s . co m*/ */ public void setMasksForGeometry(final Geometry geom) { if (geom == null || geom.isEmpty()) { return; } final int startLevel = getStartLevel(); final int maxLevel = startLevel + getNumLevels() - 1; // loop over only up to the configured max masking level final int endLevel = Math.min(maxLevel, this.maxMaskLevel); if (logger.isDebugEnabled()) { logger.debug("Geom: " + geom); } if (aggregatedGeomBounds == null) { aggregatedGeomBounds = new Envelope(geom.getEnvelopeInternal()); } else { aggregatedGeomBounds.expandToInclude(geom.getEnvelopeInternal()); } for (int level = startLevel; level <= endLevel; level++) { final Geometry geometryInGridCrs = transformToGridCrs(geom, level); if (logger.isDebugEnabled()) { logger.debug("Geom in grid CRS: " + geometryInGridCrs); } final Geometry bufferedGeomInGridCrs = geometryInGridCrs.buffer(TILE_BUFFER_RATIO); if (logger.isDebugEnabled()) { logger.debug("Buffered Geom in grid CRS: " + bufferedGeomInGridCrs); } // do not generalize in LiteShape, it affects the expected masked pixels boolean generalize = false; // shape used identity transform, as the geometry is already projected Shape shape = new LiteShape(bufferedGeomInGridCrs, IDENTITY, generalize); Graphics2D graphics = getGraphics(level); /* * Disable antialiasing explicitly, otherwise the rendering will pick the platform's * default potentially producing missing pixels */ graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); graphics.setColor(Color.WHITE); graphics.fill(shape); } }
From source file:org.goko.viewer.jogl.service.JoglViewerServiceImpl.java
/** (inheritDoc) * @see org.goko.viewer.jogl.service.JoglSceneManager#drawOverlayData(java.awt.Graphics2D) */// w ww . j a v a 2 s . c om @Override protected void drawOverlayData(Graphics2D g2d) throws GkException { if (getCanvas().isKeyboardJogEnabled()) { // Draw a big red warning saying jog is enabled FontRenderContext frc = g2d.getFontRenderContext(); String warn = "Keyboard jog enabled"; GlyphVector gv = jogWarnFont.createGlyphVector(frc, warn); Rectangle bounds = gv.getPixelBounds(frc, 0, 0); int x = (getWidth() - bounds.width) / 2; int y = 5 + bounds.height; Rectangle2D bg = new Rectangle2D.Double(x - 5, 2, bounds.width + 15, bounds.height + 10); g2d.setFont(jogWarnFont); g2d.setColor(Color.RED);//new Color(0.9f,0,0,0.5f)); g2d.fill(bg); g2d.setColor(Color.WHITE); g2d.drawString(warn, x, y); } }
From source file:org.n52.v3d.terrainserver.povraywts.WebTerrainServlet.java
private void addAnnotations(BufferedImage pImage, int pHeight, int pWidth, double pPitch, double pYaw, boolean pDrawNorthArrow) { if (mCopyrightTextContent.length() > 0) { Graphics2D g = pImage.createGraphics(); g.drawImage(pImage, 0, 0, null); g.setColor(new java.awt.Color(mCopyrightTextColor.getRed(), mCopyrightTextColor.getGreen(), mCopyrightTextColor.getBlue())); // 1. Copyright-Vermerk // Etwas unschn: Durch JPEG-Komprimierung wird Text (insb. bei kleiner Font-Gre) wird unscharf... // TODO: Abhilfe evtl. durch Hintergrund? Font font = new Font(mCopyrightTextFont, Font.BOLD /* Style als int, siehe ggf. API-Dok.*/, mCopyrightTextSize);//w w w . j av a2 s . c o m g.setFont(font); // mehrzeilige Copyright-Texte erlauben: StringTokenizer str = new StringTokenizer(mCopyrightTextContent, "\n"); int spacePerRow = mCopyrightTextSize; int rows = str.countTokens(); int startPos = spacePerRow * rows; int currRow = 0; while (str.hasMoreTokens()) { int yPos = pHeight - (startPos - (currRow * spacePerRow)) + spacePerRow / 2; g.drawString(str.nextToken().trim(), 5, yPos); currRow++; } // 2. Nordpfeil if (pDrawNorthArrow) { // Zeichenparameter: double radius = 35.; double phi = 15.; // Symbolkonstruktion: int rx = (int) radius; int ry = (int) Math.round(radius * Math.sin(-pPitch * Math.PI / 180.)); int mx = pWidth - rx - 5; int my = pHeight - ry - 5; int dx = (int) (radius * Math.sin(pYaw * Math.PI / 180.)); int dy = (int) (radius * Math.sin(-pPitch * Math.PI / 180.) * Math.cos(pYaw * Math.PI / 180.)); int px = mx - dx, py = my - dy; // Pfeilspitze int qlx = mx + (int) (radius * Math.sin((pYaw + phi) * Math.PI / 180.)); int qly = my + (int) (radius * Math.sin(-pPitch * Math.PI / 180.) * Math.cos((pYaw + phi) * Math.PI / 180.)); int qrx = mx + (int) (radius * Math.sin((pYaw - phi) * Math.PI / 180.)); int qry = my + (int) (radius * Math.sin(-pPitch * Math.PI / 180.) * Math.cos((pYaw - phi) * Math.PI / 180.)); // Ellipse zeichnen: g.setStroke(new BasicStroke(2.f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); g.drawOval(mx - rx, my - ry, 2 * rx, 2 * ry); // Striche fr Pfeil zeichnen: g.setStroke(new BasicStroke(1.f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); boolean fillArrow = true; if (fillArrow) g.fill(new Polygon(new int[] { px, qlx, qrx }, new int[] { py, qly, qry }, 3)); else { g.drawLine(px, py, qlx, qly); g.drawLine(px, py, qrx, qry); g.drawLine(qlx, qly, qrx, qry); } } g.dispose(); } }
From source file:org.niord.web.aton.AtonTileRestService.java
/** * Generates an AtoN tile//from ww w . ja v a 2 s . co m * @param z the zoom level * @param bounds the tile bounds * @param mercator the mercator calculator * @param atonLonLats the aton positions * @return the resulting image */ private BufferedImage generateAtonTile(int z, double[] bounds, GlobalMercator mercator, java.util.List<double[]> atonLonLats) { BufferedImage image = new BufferedImage(TILE_SIZE, TILE_SIZE, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); GraphicsUtils.antialias(g2); int xy0[] = mercator.LatLonToPixels(-bounds[0], bounds[1], z); atonLonLats.stream().forEach(lonLat -> { int xy[] = mercator.LatLonToPixels(lonLat[1], lonLat[0], z); double px = xy[0] - xy0[0]; double py = -(xy[1] - xy0[1]); double radius = (z < 6) ? 0.5 : 1.0; Shape theCircle = new Ellipse2D.Double(px - radius, py - radius, 2.0 * radius, 2.0 * radius); g2.setColor(ATON_COLOR); g2.fill(theCircle); }); g2.dispose(); return image; }