List of usage examples for java.awt Graphics2D setColor
public abstract void setColor(Color c);
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 w w . j a v a 2 s . com 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:org.tsho.dmc2.core.chart.CowebRenderer.java
private void animateCowebPlot(Graphics2D g2, Rectangle2D dataArea) { Graphics2D g2bisec = (Graphics2D) g2.create(); g2bisec.setColor(Color.blue); Stroke stroke = new BasicStroke(3f); Stroke origStroke = g2.getStroke(); Color color = Color.BLACK; g2blink = (Graphics2D) g2.create(); g2blink.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2blink.setXORMode(color);/* w w w. jav a 2 s . c o m*/ g2blink.setStroke(stroke); if (plot.isAlpha()) { g2bisec.setComposite(AlphaComposite.SrcOver); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, plot.getForegroundAlpha())); } /* transients */ stepper.setInitialValue(initialValue); stepper.initialize(); state = STATE_TRANSIENTS; for (int index = 0; index < transients; index++) { stepper.step(); if (stopped) { state = STATE_STOPPED; return; } } state = STATE_RUNNING; Range xDataRange = plot.getDataRange(domainAxis); int transX, transY, transX1, transY1; transX = (int) this.domainAxis.valueToJava2D(xDataRange.getLowerBound(), dataArea, RectangleEdge.BOTTOM); transY = (int) this.rangeAxis.valueToJava2D(xDataRange.getLowerBound(), dataArea, RectangleEdge.LEFT); transX1 = (int) this.domainAxis.valueToJava2D(xDataRange.getUpperBound(), dataArea, RectangleEdge.BOTTOM); transY1 = (int) this.rangeAxis.valueToJava2D(xDataRange.getUpperBound(), dataArea, RectangleEdge.LEFT); g2bisec.drawLine(transX, transY, transX1, transY1); //renderer.reset(); recurseCoweb(g2, dataArea); }
From source file:org.jrecruiter.service.impl.DataServiceImpl.java
/** {@inheritDoc} */ @Transactional(readOnly = true, propagation = Propagation.SUPPORTS) public Image getGoogleMapImage(final BigDecimal latitude, final BigDecimal longitude, final Integer zoomLevel) { if (longitude == null) { throw new IllegalArgumentException("Longitude cannot be null."); }/*from w w w.ja v a2 s . c om*/ if (latitude == null) { throw new IllegalArgumentException("Latitude cannot be null."); } if (zoomLevel == null) { throw new IllegalArgumentException("ZoomLevel cannot be null."); } final URI url = GoogleMapsUtils.buildGoogleMapsStaticUrl(latitude, longitude, zoomLevel); BufferedImage img; try { URLConnection conn = url.toURL().openConnection(); img = ImageIO.read(conn.getInputStream()); } catch (UnknownHostException e) { LOGGER.error("Google static MAPS web service is not reachable (UnknownHostException).", e); img = new BufferedImage(GoogleMapsUtils.defaultWidth, 100, BufferedImage.TYPE_INT_RGB); final Graphics2D graphics = img.createGraphics(); final Map<Object, Object> renderingHints = CollectionUtils.getHashMap(); renderingHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.addRenderingHints(renderingHints); graphics.setBackground(Color.WHITE); graphics.setColor(Color.GRAY); graphics.clearRect(0, 0, GoogleMapsUtils.defaultWidth, 100); graphics.drawString("Not Available", 30, 30); } catch (IOException e) { throw new IllegalStateException(e); } return img; }
From source file:de.dakror.villagedefense.game.entity.Entity.java
public void drawBump(Graphics2D g, boolean above) { if (bump == null || (!hovered && !clicked)) return;/*w w w. j a v a 2 s. c o m*/ Color oldColor = g.getColor(); g.setColor(clicked ? Color.black : Color.darkGray); if (above) { g.drawLine((int) x + bump.x, (int) y + bump.y, (int) x + bump.x, (int) y + bump.y + bump.height); // left g.drawLine((int) x + bump.x, (int) y + bump.y + bump.height, (int) x + bump.x + bump.width, (int) y + bump.y + bump.height); // bottom g.drawLine((int) x + bump.x + bump.width, (int) y + bump.y, (int) x + bump.x + bump.width, (int) y + bump.y + bump.height); // right } else { g.drawLine((int) x + bump.x, (int) y + bump.y, (int) x + bump.x + bump.width, (int) y + bump.y); // top } g.setColor(oldColor); }
From source file:com.celements.photo.image.GenerateThumbnail.java
private void drawBackground(String copyright, int width, int height, int bottomSpace, int rightSpace, int vSpacing, int hSpacing, int rounding, int stringHeight, FontMetrics metrics, Graphics2D g2d) { g2d.setColor(new Color(0, 0, 0)); AlphaComposite transprency = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f); g2d.setComposite(transprency);//w w w. ja v a2 s . c om g2d.fillRoundRect(width - metrics.stringWidth(copyright) - rightSpace - 2 * hSpacing, height - stringHeight - bottomSpace - 2 * vSpacing, metrics.stringWidth(copyright) + 2 * hSpacing, stringHeight + 2 * vSpacing, rounding, rounding); }
From source file:fr.ign.cogit.geoxygene.appli.layer.LayerViewAwtPanel.java
private void saveImage() { LayerViewAwtPanel.logger.debug("record"); //$NON-NLS-1$ Color bg = this.getBackground(); BufferedImage image = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = image.createGraphics(); graphics.setColor(bg); graphics.fillRect(0, 0, this.getWidth(), this.getHeight()); this.getRenderingManager().copyTo(graphics); this.recording = false; // this.paintOverlays(graphics); graphics.dispose();//from w w w . j av a 2 s . c om try { NumberFormat format = NumberFormat.getInstance(); format.setMinimumIntegerDigits(3); ImgUtil.saveImage(image, this.recordFileName + format.format(this.recordIndex) + ".png"); //$NON-NLS-1$ this.recordIndex++; } catch (IOException e1) { e1.printStackTrace(); } }
From source file:com.boundlessgeo.geoserver.api.controllers.ThumbnailController.java
/** * Creates a thumbnail for the layer as a Resource, and updates the layer with the new thumbnail * @param ws The workspace of the layer//from ww w .j a v a2s. c om * @param layer The layer or layerGroup to get the thumbnail for * @return The thumbnail image as a Resource * @throws Exception */ protected void createThumbnail(WorkspaceInfo ws, PublishedInfo layer, HttpServletRequest baseRequest) throws Exception { //Sync against this map/layer Semaphore s = semaphores.get(layer); s.acquire(); try { //(SUITE-1072) Initialize the thumbnail to a blank image in case the WMS request crashes geoserver BufferedImage blankImage = new BufferedImage(THUMBNAIL_SIZE * 2, THUMBNAIL_SIZE * 2, BufferedImage.TYPE_4BYTE_ABGR); Graphics2D g = blankImage.createGraphics(); g.setColor(new Color(0, 0, 0, 0)); g.fillRect(0, 0, blankImage.getWidth(), blankImage.getHeight()); writeThumbnail(layer, blankImage); //Set up getMap request String url = baseRequest.getScheme() + "://localhost:" + baseRequest.getLocalPort() + baseRequest.getContextPath() + "/" + ws.getName() + "/wms/reflect"; url += "?FORMAT=" + MIME_TYPE; ReferencedEnvelope bbox = null; if (layer instanceof LayerInfo) { url += "&LAYERS=" + layer.getName(); url += "&STYLES=" + ((LayerInfo) layer).getDefaultStyle().getName(); bbox = ((LayerInfo) layer).getResource().boundingBox(); } else if (layer instanceof LayerGroupInfo) { LayerGroupHelper helper = new LayerGroupHelper((LayerGroupInfo) layer); bbox = ((LayerGroupInfo) layer).getBounds(); url += "&CRS=" + CRS.toSRS(bbox.getCoordinateReferenceSystem()); List<LayerInfo> layerList = helper.allLayersForRendering(); if (layerList.size() > 0) { url += "&LAYERS="; for (int i = 0; i < layerList.size(); i++) { if (i > 0) { url += ","; } url += layerList.get(i) == null ? "" : layerList.get(i).getName(); } } List<StyleInfo> styleList = helper.allStylesForRendering(); if (styleList.size() > 0) { url += "&STYLES="; for (int i = 0; i < styleList.size(); i++) { if (i > 0) { url += ","; } if (styleList.get(i) == null) { url += layerList.get(i).getDefaultStyle() == null ? "" : layerList.get(i).getDefaultStyle().getName(); } else { url += styleList.get(i) == null ? "" : styleList.get(i).getName(); } } } } else { throw new RuntimeException("layer must be one of LayerInfo or LayerGroupInfo"); } //Set the size of the HR thumbnail //Take the smallest bbox dimension as the min dimension. We can then crop the other //dimension to give a square thumbnail url += "&BBOX=" + ((float) bbox.getMinX()) + "," + ((float) bbox.getMinY()) + "," + ((float) bbox.getMaxX()) + "," + ((float) bbox.getMaxY()); if (bbox.getWidth() < bbox.getHeight()) { url += "&WIDTH=" + (2 * THUMBNAIL_SIZE); url += "&HEIGHT=" + (2 * THUMBNAIL_SIZE * Math.round(bbox.getHeight() / bbox.getWidth())); } else { url += "&HEIGHT=" + (2 * THUMBNAIL_SIZE); url += "&WIDTH=" + (2 * THUMBNAIL_SIZE * Math.round(bbox.getWidth() / bbox.getHeight())); } //Run the getMap request through the WMS Reflector //WebMap response = wms.reflect(request); URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); BufferedImage image = ImageIO.read(con.getInputStream()); if (image == null) { throw new RuntimeException( "Failed to encode thumbnail for " + ws.getName() + ":" + layer.getName()); } writeThumbnail(layer, image); } finally { s.release(); } }
From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java
/** Creates new form TimeFrameVisualizer */ public TimeFrameVisualizer() { initComponents();/* w w w . j a v a 2 s . c o m*/ try { STROKED = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = STROKED.createGraphics(); g2d.setColor(Constants.DS_BACK_LIGHT); g2d.fillRect(0, 0, 3, 3); g2d.setColor(Constants.DS_BACK); g2d.drawLine(0, 2, 2, 0); g2d.dispose(); DAILY_START_FRAME_FILL = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); g2d = DAILY_START_FRAME_FILL.createGraphics(); g2d.setColor(Color.CYAN); g2d.fillRect(0, 0, 3, 3); g2d.setColor(Color.BLUE); g2d.drawLine(0, 2, 2, 0); g2d.dispose(); EXACT_START_FRAME_FILL = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); g2d = EXACT_START_FRAME_FILL.createGraphics(); g2d.setColor(Color.CYAN); g2d.fillRect(0, 0, 3, 3); g2d.dispose(); ONE_DAY_START_FRAME_FILL = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); g2d = ONE_DAY_START_FRAME_FILL.createGraphics(); g2d.setColor(Color.CYAN); g2d.fillRect(0, 0, 3, 3); g2d.setColor(Color.BLUE); g2d.drawLine(1, 0, 1, 2); g2d.dispose(); ARRIVE_FRAME_FILL = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB); g2d = ARRIVE_FRAME_FILL.createGraphics(); g2d.setColor(Color.RED); g2d.fillRect(0, 0, 3, 3); g2d.setColor(Color.BLACK); g2d.drawLine(0, 2, 2, 0); g2d.dispose(); } catch (Exception e) { } popupInfo = new HashMap<String, Object>(); addMouseMotionListener(new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { } @Override public void mouseMoved(MouseEvent e) { repaint(); } }); addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { fireClickEvent(e); } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } }); }
From source file:com.projity.pm.graphic.graph.GraphInteractor.java
protected Graphics2D initGraphics() { Graph graph = getGraph();/*from ww w . j a va2 s .c o m*/ Graphics2D g = (Graphics2D) graph.getGraphics(); g.setColor(graph.getForeground()); g.setXORMode(graph.getBackground().darker()); return g; }
From source file:CustomStrokes.java
/** Draw the example */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // Get a shape to work with. Here we'll use the letter B Font f = new Font("Serif", Font.BOLD, 200); GlyphVector gv = f.createGlyphVector(g.getFontRenderContext(), "B"); Shape shape = gv.getOutline(); // Set drawing attributes and starting position g.setColor(Color.black); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.translate(10, 175);// w ww . j av a 2s.c om // Draw the shape once with each stroke for (int i = 0; i < strokes.length; i++) { g.setStroke(strokes[i]); // set the stroke g.draw(shape); // draw the shape g.translate(140, 0); // move to the right } }