Example usage for org.jfree.chart ChartPanel getHeight

List of usage examples for org.jfree.chart ChartPanel getHeight

Introduction

In this page you can find the example usage for org.jfree.chart ChartPanel getHeight.

Prototype

@BeanProperty(bound = false)
public int getHeight() 

Source Link

Document

Returns the current height of this component.

Usage

From source file:edu.jhuapl.graphs.jfreechart.utils.HighResChartUtil.java

/**
 * Returns a high resolution BufferedImage of the chart. Uses the default DPI_FILE_RESOLUTION.
 *
 * @param resolution The resolution, in dots per inch, of the image to generate.
 * @return the buffered image.//ww w.j a  va2 s.c  om
 */
public static BufferedImage getHighResChartImage(ChartPanel chartPanel, int resolution) {
    int screenResolution = Toolkit.getDefaultToolkit().getScreenResolution();
    double scaleRatio = resolution / screenResolution;
    int width = chartPanel.getWidth();
    int height = chartPanel.getHeight();
    int rasterWidth = (int) (width * scaleRatio);
    int rasterHeight = (int) (height * scaleRatio);

    BufferedImage image = new BufferedImage(rasterWidth, rasterHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();

    g2.transform(AffineTransform.getScaleInstance(scaleRatio, scaleRatio));
    chartPanel.getChart().draw(g2, new Rectangle2D.Double(0, 0, width, height), null);
    g2.dispose();

    return image;
}

From source file:ec.util.chart.swing.Charts.java

public static void copyChart(@Nonnull ChartPanel chartPanel) {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Insets insets = chartPanel.getInsets();
    int w = chartPanel.getWidth() - insets.left - insets.right;
    int h = chartPanel.getHeight() - insets.top - insets.bottom;
    Transferable selection = new ChartTransferable2(chartPanel.getChart(), w, h,
            chartPanel.getMinimumDrawWidth(), chartPanel.getMinimumDrawHeight(),
            chartPanel.getMaximumDrawWidth(), chartPanel.getMaximumDrawHeight(), true);
    clipboard.setContents(selection, null);
}

From source file:GUI.ResponseStatistics.java

/** * Creates a sample dataset */

private void InitPieChart(JFreeChart chart) {
    ChartPanel chartPanel = new ChartPanel(chart);
    // default size
    chartPanel.setSize(560, 800);/* w w  w  . j  a  v  a 2s.  c  om*/

    Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (int) ((dimension.getWidth() - chartPanel.getWidth()) / 2);
    int y = (int) ((dimension.getHeight() - chartPanel.getHeight()) / 2);

    chartPanel.setLocation(WIDTH, WIDTH);
    // add it to our application
    setContentPane(chartPanel);

    chartPanel.addChartMouseListener(new ChartMouseListener() {

        public void chartMouseClicked(ChartMouseEvent e) {

            wait = false;

        }

        public void chartMouseMoved(ChartMouseEvent e) {
        }

    });
}

From source file:net.bioclipse.model.ScatterPlotMouseHandler.java

@Override
public void mouseDragged(MouseEvent e) {
    super.mouseDragged(e);

    ChartPanel chartPanel = getChartPanel(e);
    JFreeChart selectedChart = chartPanel.getChart();
    ChartDescriptor cd = ChartUtils.getChartDescriptor(selectedChart);
    int[] indices = cd.getSourceIndices();

    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();

    //Create double buffer
    Image buffer = chartPanel.createImage(chartPanel.getWidth(), chartPanel.getHeight());
    Graphics bufferGraphics = buffer.getGraphics();
    chartPanel.paint(bufferGraphics);//from   w  w  w  .  j  ava2 s . c o m

    if (lastX == 0 && lastY == 0) {
        lastX = e.getX();
        lastY = e.getY();
    }

    drawRect = new Rectangle();
    int x1 = Math.min(Math.min(e.getX(), lastX), startX);
    int y1 = Math.min(Math.min(e.getY(), lastY), startY);
    int x2 = Math.max(Math.max(e.getX(), lastX), startX);
    int y2 = Math.max(Math.max(e.getY(), lastY), startY);

    drawRect.x = x1;
    drawRect.y = y1;
    drawRect.width = x2 - drawRect.x;
    drawRect.height = y2 - drawRect.y;

    //Create a clipping rectangle
    Rectangle clipRect = new Rectangle(drawRect.x - 100, drawRect.y - 100, drawRect.width + 200,
            drawRect.height + 200);

    //Check for selected points
    for (int j = 0; j < plot.getDataset().getItemCount(plot.getDataset().getSeriesCount() - 1); j++) {
        for (int i = 0; i < plot.getDataset().getSeriesCount(); i++) {
            Number xK = plot.getDataset().getX(i, j);
            Number yK = plot.getDataset().getY(i, j);
            Point2D datasetPoint2D = new Point2D.Double(domainValueTo2D(chartPanel, plot, xK.doubleValue()),
                    rangeValueTo2D(chartPanel, plot, yK.doubleValue()));

            if (drawRect.contains(datasetPoint2D)) {
                PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel());
                boolean pointAdded = mouseDragSelection.addPoint(cp);
                if (pointAdded) {
                    ((ScatterPlotRenderer) plot.getRenderer()).addMarkedPoint(j, i);
                    selectedChart.plotChanged(new PlotChangeEvent(plot));
                }
            } else if (!mouseDragSelection.isEmpty()) {
                PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel());
                boolean pointRemoved = mouseDragSelection.removePoint(cp);
                if (pointRemoved) {
                    ((ScatterPlotRenderer) plot.getRenderer()).removeMarkedPoint(new Point(j, i));
                    selectedChart.plotChanged(new PlotChangeEvent(plot));
                }
            }
        }
    }

    Iterator<PlotPointData> iterator = currentSelection.iterator();
    while (iterator.hasNext()) {
        PlotPointData next = iterator.next();
        Point dataPoint = next.getDataPoint();
        ((ScatterPlotRenderer) plot.getRenderer()).addMarkedPoint(dataPoint);
    }

    lastX = e.getX();
    lastY = e.getY();

    Graphics graphics = chartPanel.getGraphics();
    graphics.setClip(clipRect);

    //Draw selection rectangle
    bufferGraphics.drawRect(drawRect.x, drawRect.y, drawRect.width, drawRect.height);

    graphics.drawImage(buffer, 0, 0, chartPanel.getWidth(), chartPanel.getHeight(), null);
}

From source file:ec.util.chart.swing.Charts.java

public static void saveChart(@Nonnull ChartPanel chartPanel) throws IOException {
    JFileChooser fileChooser = new JFileChooser();
    FileFilter defaultFilter = new FileNameExtensionFilter("PNG (.png)", "png");
    fileChooser.addChoosableFileFilter(defaultFilter);
    fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("JPG (.jpg) (.jpeg)", "jpg", "jpeg"));
    if (Charts.canWriteChartAsSVG()) {
        fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("SVG (.svg)", "svg"));
        fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Compressed SVG (.svgz)", "svgz"));
    }/*  w  w  w. j  a v  a 2  s  .c o  m*/
    fileChooser.setFileFilter(defaultFilter);
    File currentDir = chartPanel.getDefaultDirectoryForSaveAs();
    if (currentDir != null) {
        fileChooser.setCurrentDirectory(currentDir);
    }
    if (fileChooser.showSaveDialog(chartPanel) == JFileChooser.APPROVE_OPTION) {
        File file = fileChooser.getSelectedFile();
        try (OutputStream stream = Files.newOutputStream(file.toPath())) {
            writeChart(getMediaType(file), stream, chartPanel.getChart(), chartPanel.getWidth(),
                    chartPanel.getHeight());
        }
        chartPanel.setDefaultDirectoryForSaveAs(fileChooser.getCurrentDirectory());
    }
}

From source file:cish.CISH.java

@Override
public String getHTMLReport(String HTMLFolderName) {
    String output = "<html>";
    String lb = "\n";

    if (!tss.isEmpty()) {

        // Save the parameters
        output += "<table><tr>" + lb + "  <td colspan=2><i><u>CISH Parameters</u></i></td>" + lb + " </tr>" + lb
                + " <tr>" + lb + "  <td><b>Point Radius:</b></td>" + lb + "  <td>"
                + getParam_PointSignalRadius() + "</td>" + lb + " </tr>" + lb + " <tr>" + lb
                + "  <td><b>Number of Random Points for Local Ratio:</b></td>" + lb + "  <td>" + getParam_nPts()
                + "</td>" + lb + " </tr>" + lb + " <tr>" + lb + "  <td><b>Polarity:</b></td>" + lb + "  <td>"
                + (getParam_darkpoints() ? "Detect Dark Points" : "Detect Light Points") + "</td>" + lb
                + " </tr>" + lb;
        output += "</table><br>" + lb;

        // Save the CISH Table
        output += "<table>" + lb + "  <tr>" + lb;
        for (int i = 0; i < jXTable1.getColumnCount(); i++) {
            output += "    <th>" + jXTable1.getColumnName(i) + "</th>" + lb;
        }//from   w ww .  j ava 2 s  .c  o  m
        output += "  </tr>" + lb;
        for (int i = 0; i < jXTable1.getRowCount(); i++) {
            output += "  <tr>" + lb;
            for (int j = 0; j < jXTable1.getColumnCount(); j++) {
                output += "    <td>" + jXTable1.getStringAt(i, j) + "</td>" + lb;
            }
            output += "  </tr>" + lb;
        }
        output += "</table>" + lb;

        // Save the CISH plot image
        ChartPanel chartpanel = (ChartPanel) jPanel1.getComponent(0);
        if (chartpanel != null) {
            File file_tmp = new File(HTMLFolderName + "CISHPlot.png");
            try {
                ChartUtilities.saveChartAsPNG(file_tmp, chartpanel.getChart(), chartpanel.getWidth(),
                        chartpanel.getHeight());
            } catch (IOException ex) {
                Logger.getLogger(CISH.class.getName()).log(Level.SEVERE, null, ex);
            }
            output += "<br><br>" + lb;
            output += "<img src=\"" + HTMLFolderName
                    + "CISHPlot.png\" alt=\"Global vs. Local Ratio Plot\"><br><br>" + lb;
        }

        // Save the TMA spot images with CISH marks
        for (TMAspot ts : tss) {
            try {
                File file_tmp = new File(HTMLFolderName + ts.getName() + "_CISH.jpg");
                BufferedImage bi = ts.getBufferedImage();
                drawInformationPreNuclei(ts, bi.createGraphics(), 1, 0, 0, bi.getWidth(), bi.getHeight());
                ImageIO.write(bi, "jpg", file_tmp);
                output += "<a href=\"" + HTMLFolderName + ts.getName() + "_CISH.jpg\">" + "<img src=\""
                        + HTMLFolderName + ts.getName() + "_CISH.jpg\" alt=\"" + ts.getName()
                        + " CISH Points\" width=\"100\">" + "</a>&nbsp;&nbsp;&nbsp;" + lb;
            } catch (IOException ex) {
                Logger.getLogger(CISH.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        output += "<br>" + "<font color=\"" + Misc.Color2HTML(COLORS[0]) + "\"><b>centromer</b></font> "
                + "<font color=\"" + Misc.Color2HTML(COLORS[1]) + "\"><b>gene</b></font> " + "<font color=\""
                + Misc.Color2HTML(COLORS[4]) + "\"><b>both</b></font> " + "<br><br>" + lb;
    }

    output += "</html>";

    return output;
}

From source file:org.jfree.chart.demo.SuperDemo.java

private void exportToPDF() {
    java.awt.Component component = chartContainer.getComponent(0);
    if (component instanceof ChartPanel) {
        JFileChooser jfilechooser = new JFileChooser();
        jfilechooser.setName("untitled.pdf");
        jfilechooser.setFileFilter(new FileFilter() {

            public boolean accept(File file) {
                return file.isDirectory() || file.getName().endsWith(".pdf");
            }// ww w.  j  a  v  a2 s  .c  o  m

            public String getDescription() {
                return "Portable Document Format (PDF)";
            }

        });
        int i = jfilechooser.showSaveDialog(this);
        if (i == 0) {
            ChartPanel chartpanel = (ChartPanel) component;
            try {
                JFreeChart jfreechart = (JFreeChart) chartpanel.getChart().clone();
                PDFExportTask pdfexporttask = new PDFExportTask(jfreechart, chartpanel.getWidth(),
                        chartpanel.getHeight(), jfilechooser.getSelectedFile());
                Thread thread = new Thread(pdfexporttask);
                thread.start();
            } catch (CloneNotSupportedException clonenotsupportedexception) {
                clonenotsupportedexception.printStackTrace();
            }
        }
    } else {
        String s = "Unable to export the selected item.  There is ";
        s = s + "either no chart selected,\nor else the chart is not ";
        s = s + "at the expected location in the component hierarchy\n";
        s = s + "(future versions of the demo may include code to ";
        s = s + "handle these special cases).";
        JOptionPane.showMessageDialog(this, s, "PDF Export", 1);
    }
}

From source file:jamel.gui.JamelWindow.java

/**
 * Exports a rapport.//ww  w . ja v a2  s. co m
 */
public void exportRapport() {
    final int max = tabbedPane.getTabCount();
    final ProgressMonitor progressMonitor = new ProgressMonitor(this, "Exporting", "", 0, max);
    progressMonitor.setMillisToDecideToPopup(0);
    final String rc = System.getProperty("line.separator");
    final File outputDirectory = new File("exports/" + this.getTitle() + "-" + (new Date()).getTime());
    outputDirectory.mkdir();
    try {
        final FileWriter writer = new FileWriter(new File(outputDirectory, "Rapport.html"));
        writer.write("<HTML>" + rc);
        writer.write("<HEAD>");
        writer.write("<TITLE>" + this.getTitle() + "</TITLE>" + rc);
        writer.write("</HEAD>" + rc);
        writer.write("<BODY>" + rc);
        writer.write("<H1>" + this.getTitle() + "</H1>" + rc);
        writer.write("<HR>" + rc);
        final Date start = viewManager.getStart().getDate();
        final Date end = viewManager.getEnd().getDate();
        for (int tabIndex = 0; tabIndex < max; tabIndex++) {
            try {
                final JPanel currentTab = (JPanel) tabbedPane.getComponentAt(tabIndex);
                final String tabTitle = tabbedPane.getTitleAt(tabIndex);
                writer.write("<H2>" + tabTitle + "</H2>" + rc);
                writer.write("<TABLE>" + rc);
                final int chartPanelCount = currentTab.getComponentCount();
                for (int chartIndex = 0; chartIndex < chartPanelCount; chartIndex++) {
                    if ((chartIndex == 3) | (chartIndex == 6))
                        writer.write("<TR>" + rc);
                    final ChartPanel aChartPanel = (ChartPanel) currentTab.getComponent(chartIndex);
                    final JamelChart chart = (JamelChart) aChartPanel.getChart();
                    if (chart != null) {
                        final String chartTitle = chart.getTitle().getText();
                        if (!chartTitle.equals("Empty")) {
                            try {
                                chart.setTitle("");
                                chart.setTimeRange(start, end);
                                String imageName = (tabTitle + "-" + chartIndex + "-" + chartTitle + ".png")
                                        .replace(" ", "_").replace("&", "and");
                                ChartUtilities.saveChartAsPNG(new File(outputDirectory, imageName), chart,
                                        aChartPanel.getWidth(), aChartPanel.getHeight());
                                writer.write("<TD><IMG src=\"" + imageName + "\" title=\"" + chartTitle + "\">"
                                        + rc);
                                chart.setTitle(chartTitle);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
                writer.write("</TABLE>" + rc);
                writer.write("<HR>" + rc);
            } catch (ClassCastException e) {
            }
            progressMonitor.setProgress(tabIndex);
        }
        writer.write("<H2>Scenario</H2>" + rc);
        writer.write(this.consoleText.toString());
        writer.write("</BODY>" + rc);
        writer.write("</HTML>" + rc);
        writer.close();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    progressMonitor.close();
}

From source file:edu.uara.gui.tableeditor.ChartGenerationFrame.java

public ChartGenerationFrame()//dummy constructor for testing
{

    initComponents();// w  ww.j av  a 2s .c o  m
    this.addRadioButtonGroup();
    // create a baseDataset...
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(20.3, "Product 1 (US)", "Jan 04");
    dataset.addValue(27.2, "Product 1 (US)", "Feb 04");
    dataset.addValue(19.7, "Product 1 (US)", "Mar 04");
    dataset.addValue(19.4, "Product 1 (Europe)", "Jan 04");
    dataset.addValue(10.9, "Product 1 (Europe)", "Feb 04");
    dataset.addValue(18.4, "Product 1 (Europe)", "Mar 04");
    dataset.addValue(16.5, "Product 1 (Asia)", "Jan 04");
    dataset.addValue(15.9, "Product 1 (Asia)", "Feb 04");
    dataset.addValue(16.1, "Product 1 (Asia)", "Mar 04");
    dataset.addValue(13.2, "Product 1 (Middle East)", "Jan 04");
    dataset.addValue(14.4, "Product 1 (Middle East)", "Feb 04");
    dataset.addValue(13.7, "Product 1 (Middle East)", "Mar 04");

    dataset.addValue(23.3, "Product 2 (US)", "Jan 04");
    dataset.addValue(16.2, "Product 2 (US)", "Feb 04");
    dataset.addValue(28.7, "Product 2 (US)", "Mar 04");
    dataset.addValue(12.7, "Product 2 (Europe)", "Jan 04");
    dataset.addValue(17.9, "Product 2 (Europe)", "Feb 04");
    dataset.addValue(12.6, "Product 2 (Europe)", "Mar 04");
    dataset.addValue(15.4, "Product 2 (Asia)", "Jan 04");
    dataset.addValue(21.0, "Product 2 (Asia)", "Feb 04");
    dataset.addValue(11.1, "Product 2 (Asia)", "Mar 04");
    dataset.addValue(23.8, "Product 2 (Middle East)", "Jan 04");
    dataset.addValue(23.4, "Product 2 (Middle East)", "Feb 04");
    dataset.addValue(19.3, "Product 2 (Middle East)", "Mar 04");

    dataset.addValue(11.9, "Product 3 (US)", "Jan 04");
    dataset.addValue(31.0, "Product 3 (US)", "Feb 04");
    dataset.addValue(22.7, "Product 3 (US)", "Mar 04");
    dataset.addValue(15.3, "Product 3 (Europe)", "Jan 04");
    dataset.addValue(14.4, "Product 3 (Europe)", "Feb 04");
    dataset.addValue(25.3, "Product 3 (Europe)", "Mar 04");
    dataset.addValue(23.9, "Product 3 (Asia)", "Jan 04");
    dataset.addValue(19.0, "Product 3 (Asia)", "Feb 04");
    dataset.addValue(10.1, "Product 3 (Asia)", "Mar 04");
    dataset.addValue(13.2, "Product 3 (Middle East)", "Jan 04");
    dataset.addValue(15.5, "Product 3 (Middle East)", "Feb 04");
    dataset.addValue(10.1, "Product 3 (Middle East)", "Mar 04");
    // create a chart...
    IBarChart c = new CustomBarChart("Test barchart", "Domain", "Range", PlotOrientation.VERTICAL, true);
    c.generate3DStackedBarChart(dataset);
    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("Product 1 (US)", "G1");
    map.mapKeyToGroup("Product 1 (Europe)", "G1");
    map.mapKeyToGroup("Product 1 (Asia)", "G1");
    map.mapKeyToGroup("Product 1 (Middle East)", "G1");
    map.mapKeyToGroup("Product 2 (US)", "G2");
    map.mapKeyToGroup("Product 2 (Europe)", "G2");
    map.mapKeyToGroup("Product 2 (Asia)", "G2");
    map.mapKeyToGroup("Product 2 (Middle East)", "G2");
    map.mapKeyToGroup("Product 3 (US)", "G3");
    map.mapKeyToGroup("Product 3 (Europe)", "G3");
    map.mapKeyToGroup("Product 3 (Asia)", "G3");
    map.mapKeyToGroup("Product 3 (Middle East)", "G3");
    renderer.setSeriesToGroupMap(map);

    renderer.setItemMargin(0.0);
    Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f,
            new Color(0x88, 0x88, 0xFF));
    renderer.setSeriesPaint(0, p1);
    renderer.setSeriesPaint(4, p1);
    renderer.setSeriesPaint(8, p1);

    Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0x88, 0xFF, 0x88));
    renderer.setSeriesPaint(1, p2);
    renderer.setSeriesPaint(5, p2);
    renderer.setSeriesPaint(9, p2);

    Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0x88, 0x88));
    renderer.setSeriesPaint(2, p3);
    renderer.setSeriesPaint(6, p3);
    renderer.setSeriesPaint(10, p3);

    Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0xFF, 0x88));
    renderer.setSeriesPaint(3, p4);
    renderer.setSeriesPaint(7, p4);
    renderer.setSeriesPaint(11, p4);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    SubCategoryAxis domainAxis = new SubCategoryAxis("Product / Month");
    domainAxis.setCategoryMargin(0.05);
    domainAxis.addSubCategory("Product 1");
    domainAxis.addSubCategory("Product 2");
    domainAxis.addSubCategory("Product 3");

    CategoryPlot plot = (CategoryPlot) ((CustomJFreeChart) c).getPlot();
    plot.setDomainAxis(domainAxis);
    //plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
    plot.setRenderer(renderer);
    //plot.setFixedLegendItems(createLegendItems());

    ChartPanel panel = c.drawChart("Chart Editor").getChartPanel();

    ChartPanel.add(panel);
    //ChartPanel.setSize(panel.getWidth(), panel.getHeight());
    splitPane.setDividerLocation(panel.getHeight());
    //test table
    //H4_2 t = new H4_2();
    //CustomJTable temp = (CustomJTable) t.generateTable();
    //temp.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    //JScrollPane tableScrollPane = new JScrollPane(temp);
    //tableScrollPane.add(temp);
    //splitPane.setBottomComponent(tableScrollPane);
    //temp.setCellSelectionEnabled(true);
    //this.getContentPane().add(TablePanel)
}

From source file:com.appnativa.rare.ui.chart.jfreechart.ChartHandler.java

@Override
public UIImage getChartImage(iPlatformComponent chartPanel, ChartDefinition cd) {
    if (chartPanel == null) {
        return null;
    }//from w  ww .  j a  v  a  2 s . c o  m

    ChartPanel cp = (ChartPanel) chartPanel.getView();

    return new UIImage(cp.getChart().createBufferedImage(cp.getWidth(), cp.getHeight()));
}