/** * Draws the title on a Java 2D graphics device (such as the screen or a * printer). * * @param g2 the graphics device. * @param area the available area for the title. */ @Override public void draw(Graphics2D g2, Rectangle2D area) { draw(g2, area, null); }
/** * Draws the title on a Java 2D graphics device (such as the screen or a * printer). * * @param g2 the graphics device. * @param area the available area for the title. */ public void draw(Graphics2D g2, Rectangle2D area) { draw(g2, area, null); }
/** * The resulting IVisualization shows a chart which consists a TimeSeries for each FeatureOfInterest * contained in the observationCollection. */ public IVisualization renderChart(OXFFeatureCollection observationCollection, ParameterContainer paramCon, int width, int height) { JFreeChart chart = renderChart(observationCollection, paramCon); // draw plot into image: Plot plot = chart.getPlot(); BufferedImage chartImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D chartGraphics = chartImage.createGraphics(); chartGraphics.setColor(Color.white); chartGraphics.fillRect(0, 0, width, height); plot.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height), null, null, null); // draw legend into image: LegendTitle legend = chart.getLegend(); BufferedImage legendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D legendGraphics = legendImage.createGraphics(); legendGraphics.setColor(Color.white); legendGraphics.fillRect(0, 0, (int) legend.getWidth(), (int) legend.getHeight()); legend.draw(legendGraphics, new Rectangle2D.Float(0, 0, width, height)); return new StaticVisualization(chartImage, legendImage); }
public static void saveAsPdf(LegendTitle legend, String FILENAME , int width, int height) { Document document = new Document(new Rectangle(width, height)); try { FileOutputStream file = new FileOutputStream(FILENAME); PdfWriter writer = PdfWriter.getInstance(document, file); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); Graphics2D g2d = tp.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height); legend.draw(g2d, r2d); g2d.dispose(); cb.addTemplate(tp, 0, 0); document.close(); g2d.dispose(); } catch(Exception e) { e.printStackTrace(); } }