Example usage for org.jfree.chart ChartFrame setDefaultCloseOperation

List of usage examples for org.jfree.chart ChartFrame setDefaultCloseOperation

Introduction

In this page you can find the example usage for org.jfree.chart ChartFrame setDefaultCloseOperation.

Prototype

@BeanProperty(preferred = true, enumerationValues = { "WindowConstants.DO_NOTHING_ON_CLOSE",
        "WindowConstants.HIDE_ON_CLOSE", "WindowConstants.DISPOSE_ON_CLOSE",
        "WindowConstants.EXIT_ON_CLOSE" }, description = "The frame's default close operation.")
public void setDefaultCloseOperation(int operation) 

Source Link

Document

Sets the operation that will happen by default when the user initiates a "close" on this frame.

Usage

From source file:graph.jfreecharts.GraphFunction.java

/**
 * Plots an xyerror graph using jfreecharts
 * @param title the title of the graph//  w w w.j a v  a  2 s . c o  m
 * @param xlabel the x axis title
 * @param ylabel the y axis title
 * @param legend the legend
 * @param data the data values
 */
protected static void plotData(String title, String xlabel, String ylabel, String[] legend, double[][][] data) {

    DefaultIntervalXYDataset xydata = new DefaultIntervalXYDataset();

    for (int i = 0; i < legend.length; i++) {
        xydata.addSeries(legend[i], data[i]);
    }
    // create a chart...
    JFreeChart chart = GraphFunction.createXYIntervalChart(title, xlabel, ylabel, xydata,
            PlotOrientation.VERTICAL, true, true, false);
    // create and display a frame...
    ChartFrame frame = new ChartFrame("First", chart);
    frame.pack();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
}

From source file:org.audiveris.omr.util.ChartPlotter.java

/**
 * Wrap chart into a frame with specific title and display the frame at provided
 * location./*  w w w . jav a2 s .co  m*/
 *
 * @param title    frame title
 * @param location frame location
 */
public void display(String title, Point location) {
    ChartFrame frame = new ChartFrame(title, chart, true);
    frame.pack();
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.setLocation(location);
    frame.setVisible(true);
}

From source file:omr.glyph.ui.TextAreaBrowser.java

private void showHistogram(TextArea area, Oriented orientation) {
    int[] histo = area.getHistogram(orientation);
    boolean vertical = orientation.isVertical();
    Rectangle rect = area.getAbsoluteContour();

    // Projection data
    XYSeries dataSeries = new XYSeries("Foreground Pixels");
    int offset = vertical ? rect.x : rect.y;

    for (int i = 0; i < histo.length; i++) {
        if (vertical) {
            dataSeries.add(offset + i, histo[i]);
        } else {//from   ww w  .j  a  va 2  s. c  o m
            dataSeries.add(i - offset - histo.length + 1, histo[histo.length - 1 - i]);
        }
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(dataSeries);

    // Chart
    JFreeChart chart;

    if (vertical) {
        chart = ChartFactory.createXYAreaChart("Vertical Projections", // Title
                "Abscissa", "Cumulated Pixels", dataset, // Dataset
                PlotOrientation.VERTICAL, // orientation,
                false, // Show legend
                false, // Show tool tips
                false // urls
        );
    } else {
        // Thresholds
        addLine(dataset, area, "Base", area.getBaseline());
        addLine(dataset, area, "Median", area.getMedianLine());
        addLine(dataset, area, "Top", area.getTopline());

        chart = ChartFactory.createXYLineChart(
                "Horizontal Projections top:" + area.getTopline() + " median:" + area.getMedianLine() + " base:"
                        + area.getBaseline(), // Title
                "Ordinate", "Cumulated Pixels", dataset, // Dataset
                PlotOrientation.HORIZONTAL, // orientation,
                true, // Show legend
                true, // Show tool tips
                false // urls
        );
    }

    // Hosting frame
    ChartFrame frame = new ChartFrame("Histogram of " + rect, chart, true);
    frame.pack();
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setVisible(true);
}

From source file:omr.sheet.SkewBuilder.java

private void writePlot() {
    if (logger.isFineEnabled()) {
        logger.fine("Slope computation based on following sticks :");
    }// w  w w  .j  av a 2 s .c o m

    final int RESOLUTION = 10000;

    // Range -0.4 .. +0.4 Radians (-24 .. +24 Degrees)
    final int MAX_INDEX = 400;
    double[] histo = new double[MAX_INDEX];

    for (int i = MAX_INDEX - 1; i >= 0; i--) {
        histo[i] = 0;
    }

    for (Stick stick : sticks) {
        if (stick.getLength() >= lengthThreshold) {
            if (logger.isFineEnabled()) {
                stick.dump();
            }

            double slope = stick.getLine().getSlope();
            int length = stick.getLength();
            int index = (int) (slope * RESOLUTION) + (MAX_INDEX / 2);

            if ((index >= 0) && (index < MAX_INDEX)) {
                histo[index] += stick.getLength();
            }
        } else {
            break;
        }
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries slopeSeries = new XYSeries("Slope");

    for (int i = 0; i < MAX_INDEX; i++) {
        slopeSeries.add(i - (MAX_INDEX / 2), histo[i]);
    }

    dataset.addSeries(slopeSeries);

    // Chart
    JFreeChart chart = ChartFactory.createXYLineChart(sheet.getRadix() + " (Slope Histogram)", // Title
            "Slope [" + (float) (RESOLUTION * angle) + " Radians/" + RESOLUTION + "]", // X-Axis label
            "Counts", // Y-Axis label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // orientation,
            true, // Show legend
            false, // Show tool tips
            false // urls
    );

    // Hosting frame
    ChartFrame frame = new ChartFrame(sheet.getRadix() + " - Slope", chart, true);
    frame.pack();
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setVisible(true);
}

From source file:omr.sheet.LinesBuilder.java

private void writePlot(int[] histo, int maxHisto, double ratio) {
    XYSeriesCollection dataset = new XYSeriesCollection();

    // Threshold line
    XYSeries thresholdSeries = new XYSeries("Staff ratio used" + " [" + ratio + "]");
    thresholdSeries.add(0, ratio);/*from www. j  a  v a 2  s . c om*/
    thresholdSeries.add(-histo.length + 1, ratio);
    dataset.addSeries(thresholdSeries);

    // Projection data
    XYSeries dataSeries = new XYSeries("Projections");

    for (int i = 0; i < histo.length; i++) {
        dataSeries.add(-i, histo[i] / (double) maxHisto);
    }

    dataset.addSeries(dataSeries);

    // Chart
    JFreeChart chart = ChartFactory.createXYLineChart(sheet.getRadix() + " (Horizontal Projections)", // Title
            "Ordinate", "Ratios of horizontal counts", dataset, // Dataset
            PlotOrientation.HORIZONTAL, // orientation,
            true, // Show legend
            false, // Show tool tips
            false // urls
    );

    // Hosting frame
    ChartFrame frame = new ChartFrame(sheet.getRadix() + " - Staff Lines", chart, true);
    frame.pack();
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    RefineryUtilities.centerFrameOnScreen(frame);
    frame.setVisible(true);
}