Example usage for org.jfree.chart.plot PiePlot DEFAULT_LABEL_FONT

List of usage examples for org.jfree.chart.plot PiePlot DEFAULT_LABEL_FONT

Introduction

In this page you can find the example usage for org.jfree.chart.plot PiePlot DEFAULT_LABEL_FONT.

Prototype

Font DEFAULT_LABEL_FONT

To view the source code for org.jfree.chart.plot PiePlot DEFAULT_LABEL_FONT.

Click Source Link

Document

The default section label font.

Usage

From source file:org.jajuk.ui.views.StatView.java

/**
 * Genre repartition pie./*from ww  w. j av a2s  . com*/
 * 
 * @return the chart
 */
private ChartPanel createGenreRepartition() {
    try {
        DefaultPieDataset pdata = null;
        JFreeChart jfchart = null;
        // data
        pdata = new DefaultPieDataset();
        int iTotal = TrackManager.getInstance().getElementCount();
        double dOthers = 0;
        // Prepare a map genre -> nb tracks
        Map<Genre, Integer> genreNbTracks = new HashMap<Genre, Integer>(
                GenreManager.getInstance().getElementCount());
        ReadOnlyIterator<Track> it = TrackManager.getInstance().getTracksIterator();
        while (it.hasNext()) {
            Track track = it.next();
            Genre genre = track.getGenre();
            Integer nbTracks = genreNbTracks.get(genre);
            if (nbTracks == null) {
                genreNbTracks.put(genre, 1);
            } else {
                genreNbTracks.put(genre, nbTracks + 1);
            }
        }
        // Cleanup genre with weight < 5 %
        for (Map.Entry<Genre, Integer> entry : genreNbTracks.entrySet()) {
            double d = entry.getValue();
            if (iTotal > 0 && d / iTotal < Conf.getFloat(CONF_STATS_MIN_VALUE_GENRE_DISPLAY) / 100) {
                // less than 5% -> go to others
                dOthers += d;
            } else {
                double dValue = Math.round(100 * (d / iTotal));
                pdata.setValue(entry.getKey().getName2(), dValue);
            }
        }
        if (iTotal > 0 && dOthers > 0) {
            double dValue = Math.round(100 * (dOthers / iTotal));
            pdata.setValue(Messages.getString("StatView.0"), dValue);
        }
        // chart
        jfchart = ChartFactory.createPieChart3D(Messages.getString("StatView.1"), pdata, true, true, true);
        // set the background color for the chart...
        PiePlot plot = (PiePlot) jfchart.getPlot();
        plot.setLabelFont(PiePlot.DEFAULT_LABEL_FONT);
        plot.setNoDataMessage(Messages.getString("StatView.2"));
        plot.setForegroundAlpha(0.5f);
        plot.setBackgroundAlpha(0.5f);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {2}"));
        plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {2}"));
        return new ChartPanel(jfchart);
    } catch (RuntimeException e) {
        Log.error(e);
        return null;
    }
}

From source file:org.jajuk.ui.views.StatView.java

/**
 * Device size pie.//from w  w w  . j  ava 2 s . c  o  m
 * 
 * @return the chart
 */
private ChartPanel createDeviceRepartition() {
    try {
        DefaultPieDataset pdata = null;
        JFreeChart jfchart = null;
        // data
        pdata = new DefaultPieDataset();
        // prepare devices
        long lTotalSize = 0;
        double dOthers = 0;
        List<Device> devices = DeviceManager.getInstance().getDevices();
        long[] lSizes = new long[DeviceManager.getInstance().getElementCount()];
        ReadOnlyIterator<File> it = FileManager.getInstance().getFilesIterator();
        while (it.hasNext()) {
            File file = it.next();
            lTotalSize += file.getSize();
            lSizes[devices.indexOf(file.getDirectory().getDevice())] += file.getSize();
        }
        for (Device device : devices) {
            long lSize = lSizes[devices.indexOf(device)];
            if (lTotalSize > 0 && (double) lSize / lTotalSize < 0.05) {
                // less than 5% -> go to others
                dOthers += lSize;
            } else {
                double dValue = Math.round((double) lSize / 1073741824);
                pdata.setValue(device.getName(), dValue);
            }
        }
        if (dOthers > 0) {
            double dValue = Math.round((dOthers / 1073741824));
            pdata.setValue(Messages.getString("StatView.3"), dValue);
        }
        // chart
        jfchart = ChartFactory.createPieChart3D(Messages.getString("StatView.4"), pdata, true, true, true);
        // set the background color for the chart...
        PiePlot plot = (PiePlot) jfchart.getPlot();
        plot.setLabelFont(PiePlot.DEFAULT_LABEL_FONT);
        plot.setNoDataMessage(Messages.getString("StatView.5"));
        plot.setForegroundAlpha(0.5f);
        plot.setBackgroundAlpha(0.5f);
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} GB ({2})"));
        plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0} = {1} GB ({2})"));
        return new ChartPanel(jfchart);
    } catch (RuntimeException e) {
        Log.error(e);
        return null;
    }
}