List of usage examples for java.awt Rectangle Rectangle
public Rectangle(Point p, Dimension d)
From source file:com.esofthead.mycollab.ui.chart.JFreeChartWrapper.java
@Override public Resource getSource() { if (res == null) { StreamSource streamSource = new StreamResource.StreamSource() { private ByteArrayInputStream bytestream = null; ByteArrayInputStream getByteStream() { if (chart != null && bytestream == null) { int width = getGraphWidth(); int height = getGraphHeight(); if (mode == RenderingMode.SVG) { // Create an instance of the SVG Generator SVGGraphics2D svgGenerator = new SVGGraphics2D(width, height); // draw the chart in the SVG generator chart.draw(svgGenerator, new Rectangle(width, height)); // create an xml string in svg format from the drawing String drawingSVG = svgGenerator.getSVGElement(); return new ByteArrayInputStream(drawingSVG.getBytes(StandardCharsets.UTF_8)); } else { // Draw png to bytestream try { byte[] bytes = ChartUtilities.encodeAsPNG(chart.createBufferedImage(width, height)); bytestream = new ByteArrayInputStream(bytes); } catch (Exception e) { log.error("Error while generating PNG chart", e); }/*from w w w . j ava 2 s.co m*/ } } else { bytestream.reset(); } return bytestream; } @Override public InputStream getStream() { return getByteStream(); } }; res = new StreamResource(streamSource, String.format("graph%d", System.currentTimeMillis())) { @Override public int getBufferSize() { if (getStreamSource().getStream() != null) { try { return getStreamSource().getStream().available(); } catch (IOException e) { log.warn("Error while get stream info", e); return 0; } } else { return 0; } } @Override public long getCacheTime() { return 0; } @Override public String getFilename() { if (mode == RenderingMode.PNG) { return super.getFilename() + ".png"; } else { return super.getFilename() + (gzipEnabled ? ".svgz" : ".svg"); } } @Override public DownloadStream getStream() { DownloadStream downloadStream = new DownloadStream(getStreamSource().getStream(), getMIMEType(), getFilename()); if (gzipEnabled && mode == RenderingMode.SVG) { downloadStream.setParameter("Content-Encoding", "gzip"); } return downloadStream; } @Override public String getMIMEType() { if (mode == RenderingMode.PNG) { return "image/png"; } else { return "image/svg+xml"; } } }; } return res; }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.HierarchicalBarChart.java
private void buildFinalChart(String title, String subTitle, String xAxisLabel, String yAxisLabel, int height, int width, String filename, Chart.Scale scaleMode, Chart.LegendFormat legendFormatMode, int alpha) { @SuppressWarnings("unchecked") Vector<Counter>[] vec = new Vector[this.timers.length]; boolean exist; // create the dataset... for (int i = 0; i < this.timers.length; i++) { vec[i] = new Vector<Counter>(); @SuppressWarnings("unchecked") Iterator<Element> it = this.timers[i].getDescendants(); while (it.hasNext()) { try { Element elt = (Element) it.next(); String name = elt.getAttributeValue("name"); double value = Double.valueOf(elt.getAttributeValue("avg")); exist = false;//w w w.java2 s . co m for (int j = 0; j < vec[i].size(); j++) { if (((Counter) vec[i].get(j)).getName().equals(name)) { ((Counter) vec[i].get(j)).addValue(value); exist = true; break; } } if (!exist) { vec[i].add(new Counter(name, value)); } } catch (ClassCastException e) { continue; } } } CategoryDataset dataset = null; try { dataset = DatasetUtilities.createCategoryDataset(toSeries(vec[0]), this.categories, toDataset(vec)); } catch (IllegalArgumentException e) { e.printStackTrace(); throw new IllegalArgumentException( "Benchmark names must have different names. Be sure that your filter contains correct timers names"); } // create the chart... final CategoryAxis categoryAxis = new CategoryAxis(xAxisLabel); final ValueAxis valueAxis = new NumberAxis(yAxisLabel); final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, new HierarchicalBarRenderer()); plot.setOrientation(PlotOrientation.VERTICAL); final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.addSubtitle(new TextTitle(subTitle)); // set the background color for the chart... chart.setBackgroundPaint(Color.white); final HierarchicalBarRenderer renderer = (HierarchicalBarRenderer) plot.getRenderer(); renderer.setItemMargin(0.01); renderer.setDatasetTree(this.timers); renderer.setSeries(toSeries(vec[0])); renderer.setAlpha(alpha); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryMargin(HierarchicalBarChart.CATEGORY_MARGIN); domainAxis.setUpperMargin(0.05); domainAxis.setLowerMargin(0.05); try { if ((filename == null) || "".equals(filename)) { throw new RuntimeException( "The output filename for the HierarchicalBarChart cannot be null or empty !"); } ChartUtilities.saveChartAsPNG(XMLHelper.createFileWithDirs(filename + ".png"), chart, width, height); Utilities.saveChartAsSVG(chart, new Rectangle(width, height), XMLHelper.createFileWithDirs(filename + ".svg")); } catch (java.io.IOException e) { System.err.println("Error writing chart image to file"); e.printStackTrace(); } }
From source file:de.laures.cewolf.util.Renderer.java
/** * Renders a legend//from w w w . j a va2s .c o m * @param cd the chart iamge to be rendred * @return the rendered image * @throws CewolfException */ private static RenderedImage renderLegend(ChartImage cd, Object c) throws CewolfException { try { JFreeChart chart = (JFreeChart) c; final int width = cd.getWidth(); final int height = cd.getHeight(); LegendTitle legend = getLegend(chart); boolean haslegend = true; // with JFreeChart v0.9.20, the only way to get a valid legend, // is either to retrieve it from the chart or to assign a new // one to the chart. In the case where the chart has no legend, // a new one must be assigned, but just for rendering. After, we // have to reset the legend to null in the chart. if (null == legend) { haslegend = false; legend = new LegendTitle(chart.getPlot()); } legend.setPosition(RectangleEdge.BOTTOM); BufferedImage bimage = ImageHelper.createImage(width, height); Graphics2D g = bimage.createGraphics(); g.setColor(Color.white); g.fillRect(0, 0, width, height); legend.arrange(g, new RectangleConstraint(width, height)); legend.draw(g, new Rectangle(width, height)); ByteArrayOutputStream out = new ByteArrayOutputStream(); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bimage); param.setQuality(1.0f, true); encoder.encode(bimage, param); out.close(); // if the chart had no legend, reset it to null in order to give back the // chart in the state we received it. if (!haslegend) { removeLegend(chart); } return new RenderedImage(out.toByteArray(), "image/jpeg", new ChartRenderingInfo(new StandardEntityCollection())); } catch (IOException ioex) { log.error(ioex); throw new ChartRenderingException(ioex.getMessage(), ioex); } }
From source file:scheduler.benchmarker.manager.CreateCombinedCategoryPlot.java
private LegendItemCollection createCustomLegend() { LegendItemCollection legend = new LegendItemCollection(); Shape shape = new Rectangle(10, 10); Stroke stroke = new BasicStroke(1F); HashMap<String, Color> pColors = pluginColors.getPlugins(); Iterator it = pColors.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry) it.next(); legend.add(new LegendItem(String.valueOf(pairs.getKey()), null, null, null, shape, (Color) pairs.getValue(), stroke, Color.BLACK)); }// w ww . j a v a2 s . c o m return legend; }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.Line2dChart.java
/** * * @param title/*from w w w . jav a 2s .c om*/ * @param subTitle * @param fileName * @param domainAxis * @param rangeAxis * @param width * @param height */ private void buildFinalChart(String title, String subTitle, String fileName, String domainAxis, String rangeAxis, int width, int height) { CategoryDataset dataset = this.createDataset(); JFreeChart chart = ChartFactory.createLineChart(title, domainAxis, // domain // axis // label rangeAxis, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); chart.addSubtitle(new TextTitle(subTitle)); final LineAndShapeRenderer renderer = new LineAndShapeRenderer(); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); CategoryPlot c = chart.getCategoryPlot(); c.setRenderer(renderer); c.setRangeGridlinesVisible(true); try { ChartUtilities.saveChartAsPNG(XMLHelper.createFileWithDirs(fileName + ".png"), chart, width, height); Utilities.saveChartAsSVG(chart, new Rectangle(width, height), XMLHelper.createFileWithDirs(fileName + ".svg")); } catch (java.io.IOException e) { System.err.println("Error writing image to file"); e.printStackTrace(); } }
From source file:net.openbyte.gui.WelcomeFrame.java
private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents // Generated using JFormDesigner Evaluation license - Gary Lee scrollPane1 = new JScrollPane(); list1 = new JList(); button1 = new JButton(); label2 = new JLabel(); button2 = new JButton(); button3 = new JButton(); button4 = new JButton(); button5 = new JButton(); scrollPane2 = new JScrollPane(); xImagePanel1 = new JXImagePanel(); button6 = new JButton(); button7 = new JButton(); button8 = new JButton(); //======== this ======== setTitle("Welcome to OpenByte"); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setResizable(false);/*from w w w . ja v a 2 s. c o m*/ Container contentPane = getContentPane(); contentPane.setLayout(null); //======== scrollPane1 ======== { scrollPane1.setBorder(new TitledBorder(LineBorder.createGrayLineBorder(), "Recent Projects")); //---- list1 ---- list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list1.setBackground(new Color(240, 240, 240)); list1.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { list1ValueChanged(e); } }); scrollPane1.setViewportView(list1); } contentPane.add(scrollPane1); scrollPane1.setBounds(15, 10, 165, 340); //---- button1 ---- button1.setText("Open Project"); button1.setEnabled(false); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button1ActionPerformed(e); } }); contentPane.add(button1); button1.setBounds(105, 355, 110, button1.getPreferredSize().height); //---- label2 ---- label2.setText("Media"); contentPane.add(label2); label2.setBounds(new Rectangle(new Point(605, 210), label2.getPreferredSize())); //---- button2 ---- button2.setText("Minecraft Forums"); button2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button2ActionPerformed(e); } }); contentPane.add(button2); button2.setBounds(500, 230, 151, button2.getPreferredSize().height); //---- button3 ---- button3.setText("GitHub"); button3.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button3ActionPerformed(e); } }); contentPane.add(button3); button3.setBounds(500, 260, 150, button3.getPreferredSize().height); //---- button4 ---- button4.setText("+"); button4.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button4ActionPerformed(e); } }); contentPane.add(button4); button4.setBounds(15, 355, 45, button4.getPreferredSize().height); //---- button5 ---- button5.setText("-"); button5.setEnabled(false); button5.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button5ActionPerformed(e); } }); contentPane.add(button5); button5.setBounds(60, 355, 40, button5.getPreferredSize().height); //======== scrollPane2 ======== { scrollPane2.setBorder(null); scrollPane2.setViewportView(xImagePanel1); } contentPane.add(scrollPane2); scrollPane2.setBounds(210, 25, 445, 160); //---- button6 ---- button6.setText("Preferences"); button6.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button6ActionPerformed(e); } }); contentPane.add(button6); button6.setBounds(500, 290, 150, 30); //---- button7 ---- button7.setText("About"); button7.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button7ActionPerformed(e); } }); contentPane.add(button7); button7.setBounds(500, 320, 150, 30); //---- button8 ---- button8.setText("Plugins"); button8.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button8ActionPerformed(e); } }); contentPane.add(button8); button8.setBounds(500, 350, 150, 30); { // compute preferred size Dimension preferredSize = new Dimension(); for (int i = 0; i < contentPane.getComponentCount(); i++) { Rectangle bounds = contentPane.getComponent(i).getBounds(); preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); } Insets insets = contentPane.getInsets(); preferredSize.width += insets.right; preferredSize.height += insets.bottom; contentPane.setMinimumSize(preferredSize); contentPane.setPreferredSize(preferredSize); } setSize(675, 425); setLocationRelativeTo(getOwner()); // JFormDesigner - End of component initialization //GEN-END:initComponents }
From source file:canreg.client.analysis.Tools.java
static String writeJChartToFile(JFreeChart chart, File file, FileTypes fileType) throws IOException, DocumentException { String fileName = file.getPath(); switch (fileType) { case svg:/*ww w . jav a 2s. com*/ Tools.exportChartAsSVG(chart, new Rectangle(1000, 1000), file); break; case pdf: Tools.exportChartAsPDF(chart, new Rectangle(500, 400), file); break; case jchart: break; case csv: Tools.exportChartAsCSV(chart, file); break; default: ChartUtilities.saveChartAsPNG(file, chart, 1000, 1000); break; } return fileName; }
From source file:com.iontorrent.vaadin.utils.JFreeChartWrapper.java
public ChartRenderingInfo getInfo(int w, int h) { info = new ChartRenderingInfo(); BufferedImage img = chart.createBufferedImage(w, h, info); Graphics2D g = img.createGraphics(); chart.draw(g, new Rectangle(w, h), info); return info;/*from w w w . ja v a 2s . co m*/ }
From source file:PhysicDrawing.PhysicGraph.java
/** * Creates a chart./*from www . ja v a 2 s. co m*/ * * @param dataset the data for the chart. * * @return a chart. */ private JFreeChart createDisplacementChart(XYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart("Displacement", // chart title "X - Time (s)", // x axis label "Y - S (px)", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips true // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); // vertical line plot.setRangeGridlinePaint(Color.white); // horizontal line XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); // (index , value) renderer.setSeriesLinesVisible(1, true); // renderer.setSeriesShapesVisible(1, true); // renderer.setSeriesFillPaint(2, Color.black); renderer.setSeriesPaint(0, Color.RED, true); renderer.setSeriesPaint(1, Color.black, true); renderer.setSeriesPaint(2, Color.white, true); renderer.setSeriesShape(0, new Rectangle(1, 1)); renderer.setSeriesShape(1, new Rectangle(1, 1)); plot.setRenderer(renderer); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:scheduler.benchmarker.manager.CreateCombinedCategoryPlot.java
private LegendItemCollection createLegend() { LegendItemCollection legend = new LegendItemCollection(); Shape shape = new Rectangle(10, 10); Stroke stroke = new BasicStroke(1F); return legend; }