List of usage examples for java.awt Graphics2D fillRect
public abstract void fillRect(int x, int y, int width, int height);
From source file:it.smartcommunitylab.parking.management.web.manager.MarkerIconStorage.java
private void generateMarkerWithFlag(String basePath, String company, String entity, String color) throws IOException { BufferedImage templateIcon = ImageIO.read(new File(getIconFolder(basePath, ICON_FOLDER) + TEMPLATE_FILE)); BufferedImage icon = new BufferedImage(templateIcon.getWidth(), templateIcon.getHeight() + ICON_INCR_HEIGHT, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = icon.createGraphics(); graphics.setColor(new Color(Integer.parseInt(color, 16))); graphics.drawRect(0, 0, icon.getWidth(), COLOR_RECT_HEIGHT); graphics.fillRect(0, 0, icon.getWidth(), COLOR_RECT_HEIGHT); graphics.drawImage(templateIcon, 0, ICON_INCR_HEIGHT, null); graphics.dispose();/*from w w w .jav a 2 s . com*/ ImageIO.write(icon, ICON_TYPE, new File(getIconFolder(basePath, ICON_FOLDER_CACHE) + company + "-" + entity + "-" + color + ICON_EXTENSION)); }
From source file:Composite.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; Dimension d = getSize();/* www . ja va 2 s. c o m*/ int w = d.width; int h = d.height; BufferedImage buffImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D gbi = buffImg.createGraphics(); g2.setColor(Color.white); g2.fillRect(0, 0, d.width, d.height); int rectx = w / 4; int recty = h / 4; gbi.setColor(new Color(0.0f, 0.0f, 1.0f, 1.0f)); gbi.fill(new Rectangle2D.Double(rectx, recty, 150, 100)); gbi.setColor(new Color(1.0f, 0.0f, 0.0f, 1.0f)); gbi.setComposite(ac); gbi.fill(new Ellipse2D.Double(rectx + rectx / 2, recty + recty / 2, 150, 100)); g2.drawImage(buffImg, null, 0, 0); }
From source file:TexturedPanel.java
/** * Creates a new TexturePaint using the provided colors and texture map. *///from w w w . j a v a 2 s .c om private void setupTexturePainter(Color foreground, Color background, boolean[][] texture, int scale) { if (texture == null || texture.length < 1 || texture[0].length < 1) { setupDefaultPainter(foreground, background); return; } else if (foreground == null || background == null) { ourPainter = null; return; } scale = Math.max(1, scale); int w = texture[0].length; int h = texture.length; BufferedImage buff = new BufferedImage(w * scale, h * scale, BufferedImage.TYPE_INT_ARGB_PRE); Graphics2D g2 = buff.createGraphics(); g2.setColor(background); g2.fillRect(0, 0, w * scale, h * scale); g2.setColor(foreground); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { try { if (texture[i][j]) g2.fillRect(j * scale, i * scale, scale, scale); } // g2.drawLine(j, i, j, i); } catch (ArrayIndexOutOfBoundsException aob) { } } } ourPainter = new TexturePaint(buff, new Rectangle(0, 0, w * scale, h * scale)); g2.dispose(); }
From source file:org.n52.io.type.quantity.handler.img.ChartIoHandler.java
private BufferedImage createImage() { IoParameters parameters = getParameters(); int width = parameters.getWidth(); int height = parameters.getHeight(); BufferedImage chartImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D chartGraphics = chartImage.createGraphics(); chartGraphics.fillRect(0, 0, width, height); chartGraphics.setColor(Color.WHITE); jFreeChart.setTextAntiAlias(true);/*from w ww . ja va 2 s . c o m*/ jFreeChart.setAntiAlias(true); if (jFreeChart.getLegend() != null) { jFreeChart.getLegend().setFrame(BlockBorder.NONE); } jFreeChart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height)); return chartImage; }
From source file:DrawShapes_2008.java
@Override protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; // Paint a gradient for the sky GradientPaint background = new GradientPaint(0f, 0f, Color.GRAY.darker(), 0f, (float) getHeight(), Color.GRAY.brighter()); g2d.setPaint(background);/*from w w w .java 2 s .co m*/ g2d.fillRect(0, 0, getWidth(), 4 * getHeight() / 5); // Paint a gradient for the ground background = new GradientPaint(0f, (float) 4 * getHeight() / 5, Color.BLACK, 0f, (float) getHeight(), Color.GRAY.darker()); g2d.setPaint(background); g2d.fillRect(0, 4 * getHeight() / 5, getWidth(), getHeight() / 5); // Enable anti-aliasing to get smooth outlines g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Iterate through all of the current shapes for (Shape shape : shapes) { // Get the bounds to compute the RadialGradient properties Rectangle rect = shape.getBounds(); Point2D center = new Point2D.Float(rect.x + (float) rect.width / 2.0f, rect.y + (float) rect.height / 2.0f); float radius = (float) rect.width / 2.0f; float[] dist = { 0.1f, 0.9f }; Color[] colors = { Color.WHITE, Color.BLACK }; // Create and set a RadialGradient centered on the object, // going from white at the center to black at the edges RadialGradientPaint paint = new RadialGradientPaint(center, radius, dist, colors); g2d.setPaint(paint); // Finally, render our shape g2d.fill(shape); } }
From source file:embedding.ExampleJava2D2PDF.java
/** * Creates a PDF file. The contents are painted using a Graphics2D implementation that * generates an PDF file.//w ww. j a va2 s . c o m * @param outputFile the target file * @throws IOException In case of an I/O error * @throws ConfigurationException if an error occurs configuring the PDF output */ public void generatePDF(File outputFile) throws IOException, ConfigurationException { OutputStream out = new java.io.FileOutputStream(outputFile); out = new java.io.BufferedOutputStream(out); try { //Instantiate the PDFDocumentGraphics2D instance PDFDocumentGraphics2D g2d = new PDFDocumentGraphics2D(false); g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext()); //Configure the G2D with the necessary fonts configure(g2d, createAutoFontsConfiguration()); //Set up the document size Dimension pageSize = new Dimension((int) Math.ceil(UnitConv.mm2pt(210)), (int) Math.ceil(UnitConv.mm2pt(297))); //page size A4 (in pt) g2d.setupDocument(out, pageSize.width, pageSize.height); g2d.translate(144, 72); //Establish some page borders //A few rectangles rotated and with different color Graphics2D copy = (Graphics2D) g2d.create(); int c = 12; for (int i = 0; i < c; i++) { float f = ((i + 1) / (float) c); Color col = new Color(0.0f, 1 - f, 0.0f); copy.setColor(col); copy.fillRect(70, 90, 50, 50); copy.rotate(-2 * Math.PI / c, 70, 90); } copy.dispose(); //Some text g2d.rotate(-0.25); g2d.setColor(Color.RED); g2d.setFont(new Font("sans-serif", Font.PLAIN, 36)); g2d.drawString("Hello world!", 140, 140); g2d.setColor(Color.RED.darker()); g2d.setFont(new Font("serif", Font.PLAIN, 36)); g2d.drawString("Hello world!", 140, 180); pageSize = new Dimension(pageSize.height, pageSize.width); g2d.nextPage(pageSize.width, pageSize.height); //Demonstrate painting rich text String someHTML = "<html><body style=\"font-family:Verdana\">" + "<p>Welcome to <b>page 2!</b></p>" + "<h2>PDFDocumentGraphics2D Demonstration</h2>" + "<p>We can <i>easily</i> paint some HTML here!</p>" + "<p style=\"color:green;\">" + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin accumsan" + " condimentum ullamcorper. Sed varius quam id arcu fermentum luctus. Praesent" + " nisi ligula, cursus sed vestibulum vel, sodales sed lectus.</p>" + "</body></html>"; JEditorPane htmlComp = new JEditorPane(); htmlComp.setContentType("text/html"); htmlComp.read(new StringReader(someHTML), null); htmlComp.setSize(new Dimension(pageSize.width - 72, pageSize.height - 72)); //htmlComp.setBackground(Color.ORANGE); htmlComp.validate(); htmlComp.printAll(g2d); //Cleanup g2d.finish(); } finally { IOUtils.closeQuietly(out); } }
From source file:TapTapTap.java
@Override public void paint(Graphics g, JComponent c) { int w = c.getWidth(); int h = c.getHeight(); // Paint the view. super.paint(g, c); if (!mIsRunning) { return;//from w ww . j a v a2 s . c o m } Graphics2D g2 = (Graphics2D) g.create(); float fade = (float) mFadeCount / (float) mFadeLimit; // Gray it out. Composite urComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f * fade)); g2.fillRect(0, 0, w, h); g2.setComposite(urComposite); // Paint the wait indicator. int s = Math.min(w, h) / 5; int cx = w / 2; int cy = h / 2; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setStroke(new BasicStroke(s / 4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); g2.setPaint(Color.white); g2.rotate(Math.PI * mAngle / 180, cx, cy); for (int i = 0; i < 12; i++) { float scale = (11.0f - (float) i) / 11.0f; g2.drawLine(cx + s, cy, cx + s * 2, cy); g2.rotate(-Math.PI / 6, cx, cy); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, scale * fade)); } g2.dispose(); }
From source file:org.n52.oxf.render.sos.TimeSeriesMapChartRenderer.java
/** * @param observationCollection/*from w ww . j ava 2 s . com*/ * @param screenW * @param screenH * @param bbox * @param selectedFeatures * the Features of Interest for which a chart shall be renderered. */ public StaticVisualization renderLayer(OXFFeatureCollection observationCollection, ParameterContainer paramCon, int screenW, int screenH, IBoundingBox bbox, Set<OXFFeature> selectedFeatures) { if (selectedFeaturesCache == null) { selectedFeaturesCache = selectedFeatures; } // before starting to render --> run garbageCollection Runtime.getRuntime().gc(); LOGGER.info("Garbage Collection done."); // -- String[] observedProperties; // which observedProperty has been used?: ParameterShell observedPropertyPS = paramCon.getParameterShellWithServiceSidedName("observedProperty"); if (observedPropertyPS.hasMultipleSpecifiedValues()) { observedProperties = observedPropertyPS.getSpecifiedTypedValueArray(String[].class); } else if (observedPropertyPS.hasSingleSpecifiedValue()) { observedProperties = new String[] { (String) observedPropertyPS.getSpecifiedValue() }; } else { throw new IllegalArgumentException("no observedProperties found."); } // find tuples: if (obsValues4FOI == null) { obsValues4FOI = new ObservationSeriesCollection(observationCollection, selectedFeaturesCache, observedProperties, true); } ContextBoundingBox contextBBox = new ContextBoundingBox(bbox); BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); // draw white background: g.setColor(Color.WHITE); g.fillRect(0, 0, screenW, screenH); g.setColor(Color.BLACK); for (OXFFeature chartFeature : selectedFeaturesCache) { // // CACHING: create Plot for each "chart feature" and add it to the cache: // if (!chartCache.containsKey(chartFeature)) { Map<ITimePosition, ObservedValueTuple> timeMap = obsValues4FOI.getAllTuples(chartFeature); // draw a chart if there are tuples for the chartFeature available: if (timeMap != null) { XYPlot chart = drawChart4FOI(chartFeature.getID(), timeMap); chartCache.put(chartFeature, chart); } } // // draw the plots (which are in the cache): // Point pRealWorld = (Point) chartFeature.getGeometry(); java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW, screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y)); XYPlot cachedPlot = (XYPlot) chartCache.get(chartFeature); // if there is a plot in the cache for the chartFeature -> draw it: if (cachedPlot != null) { cachedPlot.getRangeAxis().setRange((Double) obsValues4FOI.getMinimum(0), (Double) obsValues4FOI.getMaximum(0)); cachedPlot.draw(g, new Rectangle2D.Float(pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT, CHART_WIDTH, CHART_HEIGHT), null, null, null); } else { g.drawString("No data available", pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT); } // draw point of feature: g.fillOval(pScreen.x - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), pScreen.y - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), FeatureGeometryRenderer.DOT_SIZE_POINT, FeatureGeometryRenderer.DOT_SIZE_POINT); } return new StaticVisualization(image); }
From source file:org.apache.fop.render.pdf.pdfbox.PSPDFGraphics2D.java
private BufferedImage getImage(int width, int height, Image img, ImageObserver observer) { Dimension size = new Dimension(width, height); BufferedImage buf = buildBufferedImage(size); Graphics2D g = buf.createGraphics(); g.setComposite(AlphaComposite.SrcOver); g.setBackground(new Color(1, 1, 1, 0)); g.fillRect(0, 0, width, height); g.clip(new Rectangle(0, 0, buf.getWidth(), buf.getHeight())); if (!g.drawImage(img, 0, 0, observer)) { return null; }//from ww w. j a v a 2 s. com g.dispose(); return buf; }
From source file:savant.view.tracks.VariantTrackRenderer.java
@Override public void drawLegend(Graphics2D g2, DrawingMode ignored) { int x = 6, y = 17; drawBaseLegend(g2, x, y, ColourKey.A, ColourKey.C, ColourKey.G, ColourKey.T); y += LEGEND_LINE_HEIGHT;/* w ww.java2 s . com*/ g2.setColor(Color.BLACK); g2.fillRect(x, y - SWATCH_SIZE.height + 2, SWATCH_SIZE.width, SWATCH_SIZE.height); g2.setColor(Color.BLACK); g2.drawString("Deletion", x + SWATCH_SIZE.width + 3, y); x += 66; g2.setColor(Color.MAGENTA); g2.fillRect(x, y - SWATCH_SIZE.height + 2, SWATCH_SIZE.width, SWATCH_SIZE.height); g2.setColor(Color.BLACK); g2.drawString("Insertion", x + 12, y); y += LEGEND_LINE_HEIGHT; g2.drawString("Translucent = Heterozygous", 6, y); }