Example usage for org.jfree.chart.plot PiePlot3D setDirection

List of usage examples for org.jfree.chart.plot PiePlot3D setDirection

Introduction

In this page you can find the example usage for org.jfree.chart.plot PiePlot3D setDirection.

Prototype

public void setDirection(Rotation direction) 

Source Link

Document

Sets the direction in which the pie sections are drawn and sends a PlotChangeEvent to all registered listeners.

Usage

From source file:com.smhdemo.common.report.generate.factory.ChartFactory.java

public byte[] export(Chart report, Map<String, String> pageParams) throws Exception {
    if (report == null) {
        return null;
    }//from   w w  w. j av  a2s .  co  m
    DefaultCategoryDataset dataset = buildDataset(report, pageParams);
    java.awt.Font titleFont = new java.awt.Font(report.getFontName(), report.getFontStyle(),
            report.getFontSize());
    String chartTitle = report.getChartTitle();
    chartTitle = replaceParam(pageParams, report.getParameters(), chartTitle, false);
    String horizAxisLabel = report.getHorizAxisLabel();
    horizAxisLabel = replaceParam(pageParams, report.getParameters(), horizAxisLabel, false);
    String vertAxisLabel = report.getVertAxisLabel();
    vertAxisLabel = replaceParam(pageParams, report.getParameters(), vertAxisLabel, false);
    Boolean showLegend = report.getShowLegend();
    Boolean showTooltips = report.getShowTooltips();
    Boolean drillThroughEnabled = false;
    Chart.Type chartType = report.getType();

    CategoryURLGenerator urlGenerator = null;

    JFreeChart chart = null;
    switch (chartType) {
    case VERTBAR:
        chart = ChartGenerationService.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case VERTBAR3D:
        chart = ChartGenerationService.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case HORIZBAR:
        chart = ChartGenerationService.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case HORIZBAR3D:
        chart = ChartGenerationService.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case STACKEDVERTBAR:
        chart = ChartGenerationService.createStackedBarChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case STACKEDVERTBAR3D:
        chart = ChartGenerationService.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case STACKEDHORIZBAR:
        chart = ChartGenerationService.createStackedBarChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips,
                drillThroughEnabled, urlGenerator);
        break;
    case STACKEDHORIZBAR3D:
        chart = ChartGenerationService.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips,
                drillThroughEnabled, urlGenerator);
        break;
    case VERTLINE:
        chart = ChartGenerationService.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case HORIZLINE:
        chart = ChartGenerationService.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case VERTAREA:
        chart = ChartGenerationService.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case HORIZAREA:
        chart = ChartGenerationService.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case VERTSTACKEDAREA:
        chart = ChartGenerationService.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case HORIZSTACKEDAREA:
        chart = ChartGenerationService.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips,
                drillThroughEnabled, urlGenerator);
        break;
    case PIEBYCOLUMN:
        chart = ChartGenerationService.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN,
                showLegend, showTooltips, drillThroughEnabled, null);
        break;
    case PIEBYROW:
        chart = ChartGenerationService.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW,
                showLegend, showTooltips, drillThroughEnabled, null);
        break;
    case PIEBYCOLUMN3D:
        chart = ChartGenerationService.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN,
                showLegend, showTooltips, drillThroughEnabled, null);

        break;
    case PIEBYROW3D:
        chart = ChartGenerationService.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW,
                showLegend, showTooltips, drillThroughEnabled, null);
        break;
    default:
        throw new BaseException("", "");
    }
    try {
        Integer bgColorR = report.getBgColorR();
        Integer bgColorG = report.getBgColorG();
        Integer bgColorB = report.getBgColorB();
        chart.setBackgroundPaint(new java.awt.Color(bgColorR, bgColorG, bgColorB));

        String axisFontName = report.getAxisFontName();
        Integer axisFontStyle = report.getAxisFontStyle();
        Integer axisFontSize = report.getAxisFontSize();
        java.awt.Font axisFont = new java.awt.Font(axisFontName, axisFontStyle, axisFontSize);

        String axisTickFontName = report.getAxisTickFontName();
        Integer axisTickFontStyle = report.getAxisTickFontStyle();
        Integer axisTickFontSize = report.getAxisTickFontSize();
        java.awt.Font axisTickFont = new java.awt.Font(axisTickFontName, axisTickFontStyle, axisTickFontSize);

        String legendFontName = report.getLegendFontName();
        Integer legendFontStyle = report.getLegendFontStyle();
        Integer legendFontSize = report.getLegendFontSize();
        java.awt.Font legendFont = new java.awt.Font(legendFontName, legendFontStyle, legendFontSize);
        Integer tickLabelRotate = report.getTickLabelRotate();

        String dataFontName = report.getDataFontName();
        Integer dataFontStyle = report.getDataFontStyle();
        Integer dataFontSize = report.getDataFontSize();
        java.awt.Font dataFont = new java.awt.Font(dataFontName, dataFontStyle, dataFontSize);

        Plot plot = chart.getPlot();
        if (!(plot instanceof MultiplePiePlot)) {
            CategoryPlot categoryPlot = chart.getCategoryPlot();
            CategoryItemRenderer renderer = categoryPlot.getRenderer();
            renderer.setBaseItemLabelGenerator(new LabelGenerator(0.0));
            renderer.setBaseItemLabelFont(dataFont);
            renderer.setBaseItemLabelsVisible(true);
            if (chartType == Chart.Type.VERTLINE || chartType == Chart.Type.HORIZLINE) {
                LineAndShapeRenderer lineRenderer = (LineAndShapeRenderer) categoryPlot.getRenderer();
                lineRenderer.setBaseShapesVisible(true);
                lineRenderer.setDrawOutlines(true);
                lineRenderer.setUseFillPaint(true);
            }
        }

        if (plot instanceof CategoryPlot) {
            CategoryPlot catPlot = (CategoryPlot) plot;
            catPlot.getDomainAxis().setLabelFont(axisFont);
            catPlot.getRangeAxis().setLabelFont(axisFont);
            catPlot.getDomainAxis().setTickLabelFont(axisTickFont);
            catPlot.getRangeAxis().setTickLabelFont(axisTickFont);
            catPlot.getDomainAxis().setMaximumCategoryLabelWidthRatio(100.0f);
            double angle = -2.0 * Math.PI / 360.0 * (double) tickLabelRotate;
            CategoryLabelPositions oldp = catPlot.getDomainAxis().getCategoryLabelPositions();
            CategoryLabelPositions newp = new CategoryLabelPositions(oldp.getLabelPosition(RectangleEdge.TOP),
                    new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT,
                            TextAnchor.TOP_RIGHT, angle, CategoryLabelWidthType.RANGE, 0.0f),
                    oldp.getLabelPosition(RectangleEdge.LEFT), oldp.getLabelPosition(RectangleEdge.RIGHT));
            catPlot.getDomainAxis().setCategoryLabelPositions(newp);
        } else if (plot instanceof PiePlot3D) {
            PiePlot3D piePlot = (PiePlot3D) plot;
            piePlot.setLabelFont(axisFont);
            piePlot.setDirection(org.jfree.util.Rotation.CLOCKWISE);
            piePlot.setForegroundAlpha(0.5f);
            piePlot.setNoDataMessage("?");
        } else if (plot instanceof PiePlot) {
            PiePlot piePlot = (PiePlot) plot;
            piePlot.setLabelFont(axisFont);
        }
        LegendTitle legend = (LegendTitle) chart.getLegend();
        if (legend != null) {
            legend.setItemFont(legendFont);
            RectangleEdge legendRectEdge = RectangleEdge.BOTTOM;
            Integer legendPosition = report.getLegendPosition();
            switch (legendPosition) {
            case 0:
                legendRectEdge = RectangleEdge.LEFT;
                break;
            case 1:
                legendRectEdge = RectangleEdge.TOP;
                break;
            case 2:
                legendRectEdge = RectangleEdge.RIGHT;
                break;
            case 3:
                legendRectEdge = RectangleEdge.BOTTOM;
                break;
            }
            legend.setPosition(legendRectEdge);
        }
    } catch (Exception e) {
        logger.error("Chart Export Exception", e);
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ChartUtilities.writeChartAsPNG(out, chart, report.getChartWidth(), report.getChartHeight());
    return out.toByteArray();
}

From source file:com.pureinfo.srm.reports.impl.PieChartBuilder.java

/**
 * @throws PureException// ww  w.j  a v a 2 s  . c  o m
 * @see com.pureinfo.srm.reports.IChartBuilder#draw(java.util.List, int)
 */
public JFreeChart buildChart() {
    Iterator result = m_datas.iterator();
    DefaultPieDataset ds = getDataset(result);

    JFreeChart jfreechart = ChartFactory.createPieChart3D(null, ds, false, false, false);
    jfreechart.setBackgroundPaint(Color.WHITE);

    PiePlot3D pieplot3d = (PiePlot3D) jfreechart.getPlot();
    pieplot3d.setOutlinePaint(Color.GRAY);
    pieplot3d.setOutlineStroke(new BasicStroke(1));
    pieplot3d.setStartAngle(30D);
    pieplot3d.setDepthFactor(0.04);
    pieplot3d.setDrawingSupplier(new DefaultDrawingSupplier(MyPaintMgr.getPaints(),
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));

    pieplot3d.setCircular(false);
    pieplot3d.setDirection(Rotation.CLOCKWISE);
    pieplot3d.setOutlinePaint(Color.WHITE);
    pieplot3d.setInteriorGap(.15);
    Color color = new Color(0xaa, 0xaa, 0xaa, 255);
    pieplot3d.setBaseSectionOutlinePaint(color);
    pieplot3d.setBaseSectionOutlineStroke(new BasicStroke(0));
    pieplot3d.setForegroundAlpha(0.6f);
    pieplot3d.setLabelLinkStroke(new BasicStroke(1));
    pieplot3d.setLabelOutlinePaint(new Color(0x777777));
    pieplot3d.setLabelBackgroundPaint(new Color(0xf1f1f7));
    pieplot3d.setLabelLinkPaint(new Color(0xaa, 0xaa, 0xaa, 60));
    pieplot3d.setNoDataMessage("No data to display");
    pieplot3d.setLabelShadowPaint(new Color(0xdddddd));
    pieplot3d.setLabelFont(new Font("", Font.PLAIN, 10));
    if (m_nType == TYPE_PERCENT) {

        pieplot3d.setLabelGenerator(new StandardPieItemLabelGenerator("{0} = {2}",
                NumberFormat.getNumberInstance(), PERCENT_NUMBER_FORMAT));
    }

    fillChartInfo(ds);
    return jfreechart;
}

From source file:com.ewcms.plugin.report.generate.factory.ChartFactory.java

public byte[] export(ChartReport report, Map<String, String> pageParams) throws Exception {
    if (report == null) {
        return null;
    }//  w w  w.  ja va  2s .c  om
    DefaultCategoryDataset dataset = buildDataset(report, pageParams);
    java.awt.Font titleFont = new java.awt.Font(report.getFontName(), report.getFontStyle(),
            report.getFontSize());
    String chartTitle = report.getChartTitle();
    chartTitle = replaceParam(pageParams, report.getParameters(), chartTitle, false);
    String horizAxisLabel = report.getHorizAxisLabel();
    horizAxisLabel = replaceParam(pageParams, report.getParameters(), horizAxisLabel, false);
    String vertAxisLabel = report.getVertAxisLabel();
    vertAxisLabel = replaceParam(pageParams, report.getParameters(), vertAxisLabel, false);
    Boolean showLegend = report.getShowLegend();
    Boolean showTooltips = report.getShowTooltips();
    Boolean drillThroughEnabled = false;
    ChartReport.Type chartType = report.getType();

    CategoryURLGenerator urlGenerator = null;

    JFreeChart chart = null;
    switch (chartType) {
    case VERTBAR:
        chart = ChartGenerationService.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case VERTBAR3D:
        chart = ChartGenerationService.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case HORIZBAR:
        chart = ChartGenerationService.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case HORIZBAR3D:
        chart = ChartGenerationService.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case STACKEDVERTBAR:
        chart = ChartGenerationService.createStackedBarChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case STACKEDVERTBAR3D:
        chart = ChartGenerationService.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case STACKEDHORIZBAR:
        chart = ChartGenerationService.createStackedBarChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips,
                drillThroughEnabled, urlGenerator);
        break;
    case STACKEDHORIZBAR3D:
        chart = ChartGenerationService.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips,
                drillThroughEnabled, urlGenerator);
        break;
    case VERTLINE:
        chart = ChartGenerationService.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case HORIZLINE:
        chart = ChartGenerationService.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case VERTAREA:
        chart = ChartGenerationService.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
        break;
    case HORIZAREA:
        chart = ChartGenerationService.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case VERTSTACKEDAREA:
        chart = ChartGenerationService.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                urlGenerator);
        break;
    case HORIZSTACKEDAREA:
        chart = ChartGenerationService.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel,
                vertAxisLabel, dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips,
                drillThroughEnabled, urlGenerator);
        break;
    case PIEBYCOLUMN:
        chart = ChartGenerationService.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN,
                showLegend, showTooltips, drillThroughEnabled, null);
        break;
    case PIEBYROW:
        chart = ChartGenerationService.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW,
                showLegend, showTooltips, drillThroughEnabled, null);
        break;
    case PIEBYCOLUMN3D:
        chart = ChartGenerationService.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN,
                showLegend, showTooltips, drillThroughEnabled, null);

        break;
    case PIEBYROW3D:
        chart = ChartGenerationService.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW,
                showLegend, showTooltips, drillThroughEnabled, null);
        break;
    default:
        throw new BaseException("", "");
    }
    try {
        Integer bgColorR = report.getBgColorR();
        Integer bgColorG = report.getBgColorG();
        Integer bgColorB = report.getBgColorB();
        chart.setBackgroundPaint(new java.awt.Color(bgColorR, bgColorG, bgColorB));

        String axisFontName = report.getAxisFontName();
        Integer axisFontStyle = report.getAxisFontStyle();
        Integer axisFontSize = report.getAxisFontSize();
        java.awt.Font axisFont = new java.awt.Font(axisFontName, axisFontStyle, axisFontSize);

        String axisTickFontName = report.getAxisTickFontName();
        Integer axisTickFontStyle = report.getAxisTickFontStyle();
        Integer axisTickFontSize = report.getAxisTickFontSize();
        java.awt.Font axisTickFont = new java.awt.Font(axisTickFontName, axisTickFontStyle, axisTickFontSize);

        String legendFontName = report.getLegendFontName();
        Integer legendFontStyle = report.getLegendFontStyle();
        Integer legendFontSize = report.getLegendFontSize();
        java.awt.Font legendFont = new java.awt.Font(legendFontName, legendFontStyle, legendFontSize);
        Integer tickLabelRotate = report.getTickLabelRotate();

        String dataFontName = report.getDataFontName();
        Integer dataFontStyle = report.getDataFontStyle();
        Integer dataFontSize = report.getDataFontSize();
        java.awt.Font dataFont = new java.awt.Font(dataFontName, dataFontStyle, dataFontSize);

        Plot plot = chart.getPlot();
        if (!(plot instanceof MultiplePiePlot)) {
            CategoryPlot categoryPlot = chart.getCategoryPlot();
            CategoryItemRenderer renderer = categoryPlot.getRenderer();
            renderer.setBaseItemLabelGenerator(new LabelGenerator(0.0));
            renderer.setBaseItemLabelFont(dataFont);
            renderer.setBaseItemLabelsVisible(true);
            if (chartType == ChartReport.Type.VERTLINE || chartType == ChartReport.Type.HORIZLINE) {
                LineAndShapeRenderer lineRenderer = (LineAndShapeRenderer) categoryPlot.getRenderer();
                lineRenderer.setBaseShapesVisible(true);
                lineRenderer.setDrawOutlines(true);
                lineRenderer.setUseFillPaint(true);
            }
        }

        if (plot instanceof CategoryPlot) {
            CategoryPlot catPlot = (CategoryPlot) plot;
            catPlot.getDomainAxis().setLabelFont(axisFont);
            catPlot.getRangeAxis().setLabelFont(axisFont);
            catPlot.getDomainAxis().setTickLabelFont(axisTickFont);
            catPlot.getRangeAxis().setTickLabelFont(axisTickFont);
            catPlot.getDomainAxis().setMaximumCategoryLabelWidthRatio(100.0f);
            double angle = -2.0 * Math.PI / 360.0 * (double) tickLabelRotate;
            CategoryLabelPositions oldp = catPlot.getDomainAxis().getCategoryLabelPositions();
            CategoryLabelPositions newp = new CategoryLabelPositions(oldp.getLabelPosition(RectangleEdge.TOP),
                    new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT,
                            TextAnchor.TOP_RIGHT, angle, CategoryLabelWidthType.RANGE, 0.0f),
                    oldp.getLabelPosition(RectangleEdge.LEFT), oldp.getLabelPosition(RectangleEdge.RIGHT));
            catPlot.getDomainAxis().setCategoryLabelPositions(newp);
        } else if (plot instanceof PiePlot3D) {
            PiePlot3D piePlot = (PiePlot3D) plot;
            piePlot.setLabelFont(axisFont);
            piePlot.setDirection(org.jfree.util.Rotation.CLOCKWISE);
            piePlot.setForegroundAlpha(0.5f);
            piePlot.setNoDataMessage("?");
        } else if (plot instanceof PiePlot) {
            PiePlot piePlot = (PiePlot) plot;
            piePlot.setLabelFont(axisFont);
        }
        LegendTitle legend = (LegendTitle) chart.getLegend();
        if (legend != null) {
            legend.setItemFont(legendFont);
            RectangleEdge legendRectEdge = RectangleEdge.BOTTOM;
            Integer legendPosition = report.getLegendPosition();
            switch (legendPosition) {
            case 0:
                legendRectEdge = RectangleEdge.LEFT;
                break;
            case 1:
                legendRectEdge = RectangleEdge.TOP;
                break;
            case 2:
                legendRectEdge = RectangleEdge.RIGHT;
                break;
            case 3:
                legendRectEdge = RectangleEdge.BOTTOM;
                break;
            }
            legend.setPosition(legendRectEdge);
        }
    } catch (Exception e) {
        logger.error("Chart Export Exception", e);
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ChartUtilities.writeChartAsPNG(out, chart, report.getChartWidth(), report.getChartHeight());
    return out.toByteArray();
}

From source file:com.tocea.scertify.eclipse.scertifycode.ui.stats.views.GraphStatsView.java

/**
 * Cre le graphe JFreeChart./*from  w ww. j  a  va2s .  c om*/
 * 
 * @param piedataset
 *            : la source de donnes  afficher
 * @return le diagramme
 */
private JFreeChart createChart(final GraphPieDataset piedataset) {

    final JFreeChart jfreechart = ChartFactory.createPieChart3D(null, piedataset, false, true, false);
    jfreechart.setAntiAlias(true);
    jfreechart.setTextAntiAlias(true);

    final PiePlot3D pieplot3d = (PiePlot3D) jfreechart.getPlot();
    // pieplot3d.setInsets(new RectangleInsets(0, 0, 0, 0));

    final double angle = 290D;
    pieplot3d.setStartAngle(angle);
    pieplot3d.setDirection(Rotation.CLOCKWISE);
    final float foreground = 0.5F;
    pieplot3d.setForegroundAlpha(foreground);
    pieplot3d.setBackgroundAlpha(0.0F);
    pieplot3d.setNoDataMessage(Messages.GraphStatsView_noDataToDisplay);

    pieplot3d.setOutlinePaint(null);
    pieplot3d.setLabelFont(new Font("SansSerif", Font.PLAIN, 10));
    pieplot3d.setLabelGap(0.02);
    pieplot3d.setLabelOutlinePaint(null);
    pieplot3d.setLabelShadowPaint(null);
    pieplot3d.setLabelBackgroundPaint(Color.WHITE);
    pieplot3d.setBackgroundPaint(Color.WHITE);

    pieplot3d.setInteriorGap(0.02);
    pieplot3d.setMaximumLabelWidth(0.20);

    return jfreechart;
}

From source file:org.sonar.plugins.abacus.chart.PieChart3D.java

@Override
protected Plot getPlot(ChartParameters params) {
    PiePlot3D plot = new PiePlot3D();

    String[] colorsHex = params.getValues(PARAM_COLORS, ",", true);
    String[] serie = params.getValues(PARAM_VALUES, ";", true);

    DefaultPieDataset set = new DefaultPieDataset();

    Color[] colors = COLORS;//from   w  w w. j  a va 2s .  com
    if (colorsHex != null && colorsHex.length > 0) {
        colors = new Color[colorsHex.length];
        for (int i = 0; i < colorsHex.length; i++) {
            colors[i] = Color.decode("#" + colorsHex[i]);
        }
    }

    String[] keyValue = null;
    for (int i = 0; i < serie.length; i++) {
        if (!StringUtils.isEmpty(serie[i])) {
            keyValue = StringUtils.split(serie[i], "=");
            set.setValue(keyValue[0], Double.parseDouble(keyValue[1]));
            plot.setSectionPaint(keyValue[0], colors[i]);
        }
    }
    plot.setDataset(set);

    plot.setStartAngle(360);
    plot.setCircular(true);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setNoDataMessage(DEFAULT_MESSAGE_NODATA);
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setForegroundAlpha(1.0f);
    plot.setBackgroundAlpha(0.0f);
    plot.setIgnoreNullValues(true);
    plot.setIgnoreZeroValues(true);
    plot.setOutlinePaint(Color.WHITE);
    plot.setShadowPaint(Color.WHITE);
    plot.setDarkerSides(false);
    plot.setLabelFont(DEFAULT_FONT);
    plot.setLabelPaint(Color.BLACK);
    plot.setLabelBackgroundPaint(Color.WHITE);
    plot.setLabelOutlinePaint(Color.WHITE);
    plot.setLabelShadowPaint(Color.WHITE);
    plot.setLabelPadding(new RectangleInsets(1, 1, 1, 1));
    plot.setInteriorGap(0.02);
    plot.setMaximumLabelWidth(0.15);

    return plot;
}

From source file:org.sonar.plugins.scmstats.charts.PieChart3D.java

@Override
protected Plot getPlot(ChartParameters params) {
    PiePlot3D plot = new PiePlot3D();

    String[] colorsHex = params.getValues(PARAM_COLORS, ",", true);
    String[] serie = params.getValues(PARAM_VALUES, ";", true);

    DefaultPieDataset set = new DefaultPieDataset();

    Color[] colors = COLORS;//from  w  ww  .ja v  a 2  s .  c  om
    if (colorsHex != null && colorsHex.length > 0) {
        colors = new Color[colorsHex.length];
        for (int i = 0; i < colorsHex.length; i++) {
            colors[i] = Color.decode("#" + colorsHex[i]);
        }
    }

    String[] keyValue = null;
    for (int i = 0; i < serie.length; i++) {
        if (!StringUtils.isEmpty(serie[i])) {
            keyValue = StringUtils.split(serie[i], "=");
            set.setValue(keyValue[0], Double.parseDouble(keyValue[1]));
            plot.setSectionPaint(keyValue[0], colors[i]);
        }
    }
    plot.setDataset(set);

    plot.setStartAngle(180);
    plot.setCircular(true);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setNoDataMessage(DEFAULT_MESSAGE_NODATA);
    plot.setInsets(RectangleInsets.ZERO_INSETS);
    plot.setForegroundAlpha(1.0f);
    plot.setBackgroundAlpha(0.0f);
    plot.setIgnoreNullValues(true);
    plot.setIgnoreZeroValues(true);
    plot.setOutlinePaint(Color.WHITE);
    plot.setShadowPaint(Color.GREEN);
    plot.setDarkerSides(true);
    plot.setLabelFont(DEFAULT_FONT);
    plot.setLabelPaint(Color.BLACK);
    plot.setLabelBackgroundPaint(Color.WHITE);
    plot.setLabelOutlinePaint(Color.WHITE);
    plot.setLabelShadowPaint(Color.GRAY);
    plot.setLabelPadding(new RectangleInsets(1, 1, 1, 1));
    plot.setInteriorGap(0.01);
    plot.setMaximumLabelWidth(0.25);

    return plot;
}

From source file:com.tonbeller.jpivot.chart.ChartComponent.java

/**
 * Entry point for producing charts, called by wcf render tag.
 * Produces a jfreechart dataset from olap model, then creates a chart and
 * writes it to the servlet container temp directory.
 * Returns a DOM document for Renderer to transform into html.
 * Requires that jfreechart servlet is installed in this application context.
 *///from  w  w w. j a v  a 2 s .c o m
public Document render(RequestContext context) throws Exception {
    // check if we need to produce a new chart
    if (dirty) {
        // clear old listeners
        dispatcher.clear();
        this.result = olapModel.getResult();
        this.cellIterator = result.getCells().iterator();
        this.dimCount = result.getAxes().length;
        DefaultCategoryDataset dataset = null;
        switch (dimCount) {
        case 1:
            logger.info("1-dim data");
            dataset = build1dimDataset();
            break;
        case 2:
            logger.info("2-dim data");
            dataset = build2dimDataset();
            break;
        default:
            logger.error("less than 1 or more than 2 dimensions");
            throw new IllegalArgumentException("ChartRenderer requires a 1 or 2 dimensional result");
        }
        // re-set dirty flag
        dirty = false;

        // create font
        titleFont = new java.awt.Font(fontName, fontStyle, fontSize);

        CategoryURLGenerator urlGenerator = new jpivotCategoryURLGenerator(webControllerURL);

        // Create the chart object
        JFreeChart chart = null;
        switch (chartType) {
        case 1:
            chart = ChartFactory.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
            break;
        case 2:
            chart = ChartFactory.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
            break;
        case 3:
            chart = ChartFactory.createBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset,
                    PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
            break;
        case 4:
            chart = ChartFactory.createBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset,
                    PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
            break;
        case 5:
            chart = ChartFactory.createStackedBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                    dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                    urlGenerator);
            break;
        case 6:
            chart = ChartFactory.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                    dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                    urlGenerator);
            break;
        case 7:
            chart = ChartFactory.createStackedBarChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                    dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                    urlGenerator);
            break;
        case 8:
            chart = ChartFactory.createStackedBarChart3D(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                    dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                    urlGenerator);
            break;
        case 9:
            chart = ChartFactory.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
            break;
        case 10:
            chart = ChartFactory.createLineChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset,
                    PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
            break;
        case 11:
            chart = ChartFactory.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset,
                    PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
            break;
        case 12:
            chart = ChartFactory.createAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel, dataset,
                    PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled, urlGenerator);
            break;

        case 13:
            chart = ChartFactory.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                    dataset, PlotOrientation.VERTICAL, showLegend, showTooltips, drillThroughEnabled,
                    urlGenerator);
            break;
        case 14:
            chart = ChartFactory.createStackedAreaChart(chartTitle, titleFont, horizAxisLabel, vertAxisLabel,
                    dataset, PlotOrientation.HORIZONTAL, showLegend, showTooltips, drillThroughEnabled,
                    urlGenerator);
            break;

        case 15:
            chart = ChartFactory.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN,
                    showLegend, showTooltips, drillThroughEnabled,
                    new jpivotPieURLGenerator(TableOrder.BY_COLUMN, dataset, webControllerURL));
            break;
        case 16:
            chart = ChartFactory.createPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW, showLegend,
                    showTooltips, drillThroughEnabled,
                    new jpivotPieURLGenerator(TableOrder.BY_ROW, dataset, webControllerURL));
            break;
        case 17:
            chart = ChartFactory.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_COLUMN,
                    showLegend, showTooltips, drillThroughEnabled,
                    new jpivotPieURLGenerator(TableOrder.BY_COLUMN, dataset, webControllerURL));

            break;
        case 18:
            chart = ChartFactory.create3DPieChart(chartTitle, titleFont, dataset, TableOrder.BY_ROW, showLegend,
                    showTooltips, drillThroughEnabled,
                    new jpivotPieURLGenerator(TableOrder.BY_ROW, dataset, webControllerURL));

            break;

        default:
            throw new Exception("An unknown Chart Type was requested");
        }
        try {
            chart.setBackgroundPaint(new java.awt.Color(bgColorR, bgColorG, bgColorB));

            java.awt.Font slicerFont = new java.awt.Font(slicerFontName, slicerFontStyle, slicerFontSize);
            java.awt.Font axisFont = new java.awt.Font(axisFontName, axisFontStyle, axisFontSize);
            java.awt.Font axisTickFont = new java.awt.Font(axisTickFontName, axisTickFontStyle,
                    axisTickFontSize);
            java.awt.Font legendFont = new java.awt.Font(legendFontName, legendFontStyle, legendFontSize);
            Plot plot = chart.getPlot();

            if (plot instanceof CategoryPlot) {
                CategoryPlot catPlot = (CategoryPlot) plot;
                catPlot.getDomainAxis().setLabelFont(axisFont);
                catPlot.getRangeAxis().setLabelFont(axisFont);
                catPlot.getDomainAxis().setTickLabelFont(axisTickFont);
                catPlot.getRangeAxis().setTickLabelFont(axisTickFont);
                catPlot.getDomainAxis().setMaximumCategoryLabelWidthRatio(100.0f);
                double angle = -2.0 * Math.PI / 360.0 * (double) tickLabelRotate;
                CategoryLabelPositions oldp = catPlot.getDomainAxis().getCategoryLabelPositions();
                CategoryLabelPositions newp = new CategoryLabelPositions(
                        oldp.getLabelPosition(RectangleEdge.TOP),
                        new CategoryLabelPosition(RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT,
                                TextAnchor.TOP_RIGHT, angle, CategoryLabelWidthType.RANGE, 0.0f),
                        oldp.getLabelPosition(RectangleEdge.LEFT), oldp.getLabelPosition(RectangleEdge.RIGHT));
                catPlot.getDomainAxis().setCategoryLabelPositions(newp);
            } else if (plot instanceof PiePlot3D) {
                PiePlot3D piePlot = (PiePlot3D) plot;
                //piePlot.setSectionLabelFont(axisFont);
                piePlot.setLabelFont(axisFont);
                //piePlot.setSeriesLabelFont(axisTickFont);
                //piePlot.setSectionLabelType(piePlot.NO_LABELS);
                piePlot.setDirection(org.jfree.util.Rotation.CLOCKWISE);
                piePlot.setForegroundAlpha(0.5f);
                piePlot.setNoDataMessage("No data to display");
            } else if (plot instanceof PiePlot) {
                PiePlot piePlot = (PiePlot) plot;
                //piePlot.setSectionLabelFont(axisFont);
                //piePlot.setSeriesLabelFont(axisTickFont);
                piePlot.setLabelFont(axisFont);
                //piePlot.setSectionLabelType(piePlot.NO_LABELS);

            }
            LegendTitle legend = (LegendTitle) chart.getLegend();
            if (legend != null) {
                legend.setItemFont(legendFont);
                /*
                     RectangleAnchor legendRectAnchor=RectangleAnchor.BOTTOM;
                        
                switch (legendPosition){
                     case 0:
                        legendRectAnchor = RectangleAnchor.LEFT;
                        break;
                    case 1:
                       legendRectAnchor = RectangleAnchor.TOP;
                        break;
                    case 2:
                       legendRectAnchor = RectangleAnchor.RIGHT;
                        break;
                    case 3:
                       legendRectAnchor = RectangleAnchor.BOTTOM;
                        break;
                }
                legend.setLegendItemGraphicAnchor(legendRectAnchor);
                */
                RectangleEdge legendRectEdge = RectangleEdge.BOTTOM;
                switch (legendPosition) {
                case 0:
                    legendRectEdge = RectangleEdge.LEFT;
                    break;
                case 1:
                    legendRectEdge = RectangleEdge.TOP;
                    break;
                case 2:
                    legendRectEdge = RectangleEdge.RIGHT;
                    break;
                case 3:
                    legendRectEdge = RectangleEdge.BOTTOM;
                    break;
                }
                legend.setPosition(legendRectEdge);
            }
            if (showSlicer) {
                RectangleEdge slicerRectPos = RectangleEdge.BOTTOM;
                HorizontalAlignment slicerHorizAlignment = HorizontalAlignment.LEFT;

                switch (slicerPosition) {
                case 0:
                    slicerRectPos = RectangleEdge.TOP;
                    break;
                case 1:
                    slicerRectPos = RectangleEdge.BOTTOM;
                    break;
                case 2:
                    slicerRectPos = RectangleEdge.RIGHT;
                    break;
                case 3:
                    slicerRectPos = RectangleEdge.LEFT;
                    break;
                }

                switch (slicerAlignment) {
                case 4:
                    slicerHorizAlignment = HorizontalAlignment.CENTER;
                    break;
                case 3:
                    slicerHorizAlignment = HorizontalAlignment.LEFT;
                    break;
                case 2:
                    slicerHorizAlignment = HorizontalAlignment.RIGHT;
                    break;
                }
                TextTitle slicer = new TextTitle(buildSlicer(), slicerFont, Color.BLACK, slicerRectPos,
                        slicerHorizAlignment, VerticalAlignment.CENTER, new RectangleInsets(0, 0, 0, 0));

                slicer.setPosition(slicerRectPos);
                chart.addSubtitle(slicer);
            }
            info = new ChartRenderingInfo(new StandardEntityCollection());
            //  Write the chart image to the temporary directory
            HttpSession session = context.getSession();
            filename = ServletUtilities.saveChartAsPNG(chart, chartWidth, chartHeight, info, session);

        } catch (Exception e) {
            filename = "public_error_500x300.png";
            dirty = true;
        }
    }
    // new DOM document
    DocumentBuilder parser = XmlUtils.getParser();
    // get an image map for the chart, wrap it in xchart tags
    String xchart = "<xchart>" + writeImageMap(filename, info, false) + "</xchart>";
    /*
          if (logger.isDebugEnabled()) {
             logger.debug("Chart XML");
             logger.debug(xchart);
          }
    */
    // create an InputStream from the DOM document
    InputStream stream = new ByteArrayInputStream(xchart.getBytes("UTF-8"));

    document = parser.parse(stream);
    Element root = document.getDocumentElement();
    // create url for img tag
    String graphURL = getGraphURL(context);

    Element img = document.createElement("img");
    img.setAttribute("src", graphURL);
    img.setAttribute("width", new Integer(chartWidth).toString());
    img.setAttribute("height", new Integer(chartHeight).toString());
    img.setAttribute("style", "border:0;");
    img.setAttribute("usemap", "#" + filename);
    root.appendChild(img);

    return document;
}

From source file:edu.ucla.stat.SOCR.chart.ChartGenerator_JTable.java

private JFreeChart createPieChart(String titleLabel, PieDataset dataset) {
    // System.out.println("rotation="+rotation);
    if (dimension.equalsIgnoreCase("3D")) {
        JFreeChart chart = ChartFactory.createPieChart3D(titleLabel, // chart title
                dataset, // data
                true, // include legend
                true, false);//from w w w  .ja  va2s  .c  om

        PiePlot3D plot = (PiePlot3D) chart.getPlot();
        if (rotation.equalsIgnoreCase("clockwise")) {
            plot.setStartAngle(290);
            plot.setDirection(Rotation.CLOCKWISE);
            Rotator rotator = new Rotator(plot);
            rotator.start();
        } else if (rotation.equalsIgnoreCase("counter_clockwise")) {
            plot.setStartAngle(290);
            plot.setDirection(Rotation.ANTICLOCKWISE);
            Rotator rotator = new Rotator(plot);
            rotator.start();
        }
        plot.setForegroundAlpha(0.5f);
        plot.setNoDataMessage("No data to display");
        return chart;
    } //end of 3D

    //2D ring
    if (rotation.equalsIgnoreCase("ring")) {
        JFreeChart chart = ChartFactory.createRingChart(titleLabel, // chart title
                dataset, // data
                false, // include legend
                true, false);

        RingPlot plot = (RingPlot) chart.getPlot();
        plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
        plot.setNoDataMessage("No data available");
        plot.setCircular(false);
        plot.setLabelGap(0.02);
        return chart;
    }

    //2D
    JFreeChart chart = ChartFactory.createPieChart(titleLabel, // chart title
            dataset, // data
            true, // include legend
            true, false);
    TextTitle title = chart.getTitle();
    title.setToolTipText("A title tooltip!");

    PiePlot plot = (PiePlot) chart.getPlot();
    if (rotation.equalsIgnoreCase("clockwise")) {
        plot.setStartAngle(290);
        plot.setDirection(Rotation.CLOCKWISE);
        Rotator rotator = new Rotator(plot);
        rotator.start();
    } else if (rotation.equalsIgnoreCase("counter_clockwise")) {
        plot.setStartAngle(290);
        plot.setDirection(Rotation.ANTICLOCKWISE);
        Rotator rotator = new Rotator(plot);
        rotator.start();
    }

    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);

    return chart;
}

From source file:gui.images.ImageHubExplorer.java

/**
 * This method sets the image of the specified history index as the
 * currently selected image and updates all the views.
 *
 * @param index Integer that is the history index of the image to select as
 * the current image./*from w w w  .j  a  va2s . c om*/
 */
private synchronized void setSelectedImageForHistoryIndex(int historyIndex) {
    // Update the selected image panels.
    BufferedImage photo = getPhoto(selectedImageHistory.get(historyIndex));
    selectedImagePanelClassNeighborMain.setImage(photo);
    selectedImagePanelClassNeighbor.setImage(photo);
    selectedImagePanelClass.setImage(photo);
    selectedImagePanelSearch.setImage(photo);
    int index = selectedImageHistory.get(historyIndex);
    // Update the labels with the new name.
    String shortPath = imgPaths.get(index).substring(workspace.getPath().length(),
            imgPaths.get(index).length());
    selectedImagePathLabelClassNeighborMain.setText(shortPath);
    selectedImagePathLabelClassNeighbor.setText(shortPath);
    selectedImagePathLabelClass.setText(shortPath);
    selectedImagePathLabelSearch.setText(shortPath);
    // Update the class colors.
    selectedImageLabelClassNeighborMain.setBackground(classColors[quantizedRepresentation.getLabelOf(index)]);
    selectedImageLabelClassNeighbor.setBackground(classColors[quantizedRepresentation.getLabelOf(index)]);
    selectedImageLabelClass.setBackground(classColors[quantizedRepresentation.getLabelOf(index)]);
    selectedImageLabelSearch.setBackground(classColors[quantizedRepresentation.getLabelOf(index)]);
    // Refresh the display.
    selectedImageLabelClassNeighborMain.setOpaque(true);
    selectedImageLabelClassNeighbor.setOpaque(true);
    selectedImageLabelClass.setOpaque(true);
    selectedImageLabelSearch.setOpaque(true);
    selectedImageLabelClassNeighborMain.repaint();
    selectedImageLabelClassNeighbor.repaint();
    selectedImageLabelClass.repaint();
    selectedImageLabelSearch.repaint();
    // Update the nearest neighbors and the reverse nearest neighbors.
    NeighborSetFinder nsf = getNSF();
    nnPanel.removeAll();
    rnnPanel.removeAll();
    nnPanel.revalidate();
    nnPanel.repaint();
    rnnPanel.revalidate();
    rnnPanel.repaint();
    int[][] kneighbors = nsf.getKNeighbors();
    for (int neighborIndex = 0; neighborIndex < neighborhoodSize; neighborIndex++) {
        BufferedImage thumb = thumbnails.get(kneighbors[index][neighborIndex]);
        try {
            Thread t = new Thread(new SetImageNeighborsHelper(nnPanel, thumb,
                    quantizedRepresentation.getLabelOf(kneighbors[index][neighborIndex]),
                    kneighbors[index][neighborIndex]));
            t.start();
            t.join(500);
            if (t.isAlive()) {
                t.interrupt();
            }
        } catch (Throwable thr) {
            System.err.println(thr.getMessage());
        }
    }
    ArrayList<Integer>[] rrns = rnnSetsAllK[neighborhoodSize - 1];
    if (rrns[index] != null && rrns[index].size() > 0) {
        for (int i = 0; i < rrns[index].size(); i++) {
            BufferedImage thumb = thumbnails.get(rrns[index].get(i));
            try {
                Thread t = new Thread(new SetImageNeighborsHelper(rnnPanel, thumb,
                        quantizedRepresentation.getLabelOf(rrns[index].get(i)), rrns[index].get(i)));
                t.start();
                t.join(500);
                if (t.isAlive()) {
                    t.interrupt();
                }
            } catch (Throwable thr) {
                System.err.println(thr.getMessage());
            }
        }
    }
    // Refresh the neighbor and reverse neighbor panels.
    nnPanel.revalidate();
    nnPanel.repaint();
    rnnPanel.revalidate();
    rnnPanel.repaint();
    // Visualize the neighbor occurrence profile of the selected image.
    DefaultPieDataset pieData = new DefaultPieDataset();
    for (int c = 0; c < numClasses; c++) {
        pieData.setValue(classNames[c], occurrenceProfilesAllK[neighborhoodSize - 1][index][c]);
    }
    JFreeChart chart = ChartFactory.createPieChart3D("occurrence profile", pieData, true, true, false);
    PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(290);
    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    PieRenderer prend = new PieRenderer(classColors);
    prend.setColor(plot, pieData);
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(240, 200));
    occProfileChartHolder.removeAll();
    occProfileChartHolder.add(chartPanel);
    occProfileChartHolder.revalidate();
    occProfileChartHolder.repaint();
}

From source file:gui.images.ImageHubExplorer.java

/**
 * This method sets the image of the specified index as the currently
 * selected image and updates all the views.
 *
 * @param index Integer that is the index of the image to select as the
 * current image.//www.  ja  v  a 2  s.c  o m
 */
private synchronized void setSelectedImageForIndex(int index) {
    try {
        // Update the selected image panels.
        BufferedImage photo = getPhoto(index);
        selectedImagePanelClassNeighborMain.setImage(photo);
        selectedImagePanelClassNeighbor.setImage(photo);
        selectedImagePanelClass.setImage(photo);
        selectedImagePanelSearch.setImage(photo);
        String shortPath = imgPaths.get(index).substring(workspace.getPath().length(),
                imgPaths.get(index).length());
        // Update the labels with the new name.
        selectedImagePathLabelClassNeighborMain.setText(shortPath);
        selectedImagePathLabelClassNeighbor.setText(shortPath);
        selectedImagePathLabelClass.setText(shortPath);
        selectedImagePathLabelSearch.setText(shortPath);
        // Update the class colors.
        selectedImageLabelClassNeighborMain
                .setBackground(classColors[quantizedRepresentation.getLabelOf(index)]);
        selectedImageLabelClassNeighbor.setBackground(classColors[quantizedRepresentation.getLabelOf(index)]);
        selectedImageLabelClass.setBackground(classColors[quantizedRepresentation.getLabelOf(index)]);
        selectedImageLabelSearch.setBackground(classColors[quantizedRepresentation.getLabelOf(index)]);
        // Refresh the display.
        selectedImageLabelClassNeighborMain.setOpaque(true);
        selectedImageLabelClassNeighbor.setOpaque(true);
        selectedImageLabelClass.setOpaque(true);
        selectedImageLabelSearch.setOpaque(true);
        selectedImageLabelClassNeighborMain.repaint();
        selectedImageLabelClassNeighbor.repaint();
        selectedImageLabelClass.repaint();
        selectedImageLabelSearch.repaint();
        // Update the history.
        if (selectedImageHistory == null) {
            selectedImageHistory = new ArrayList<>(200);
            selectedImageIndexInHistory = -1;
        }
        // Discard the future history.
        if (selectedImageIndexInHistory < selectedImageHistory.size() - 1) {
            for (int i = selectedImageHistory.size() - 1; i > selectedImageIndexInHistory; i--) {
                selectedImageHistory.remove(i);
            }
        }
        selectedImageHistory.add(index);
        selectedImageIndexInHistory = selectedImageHistory.size() - 1;
        // Update the nearest neighbors and the reverse nearest neighbors.
        NeighborSetFinder nsf = getNSF();
        nnPanel.removeAll();
        rnnPanel.removeAll();
        nnPanel.revalidate();
        nnPanel.repaint();
        rnnPanel.revalidate();
        rnnPanel.repaint();
        int[][] kneighbors = nsf.getKNeighbors();
        for (int neighborIndex = 0; neighborIndex < neighborhoodSize; neighborIndex++) {
            // Insert all the nearest neighbors to their panel.
            BufferedImage thumb = thumbnails.get(kneighbors[index][neighborIndex]);
            try {
                Thread t = new Thread(new SetImageNeighborsHelper(nnPanel, thumb,
                        quantizedRepresentation.getLabelOf(kneighbors[index][neighborIndex]),
                        kneighbors[index][neighborIndex]));
                t.start();
                t.join(500);
                if (t.isAlive()) {
                    t.interrupt();
                }
            } catch (Throwable thr) {
                System.err.println(thr.getMessage());
            }
        }
        // Insert all the reverse nearest neighbors to their panel.
        ArrayList<Integer>[] rrns = null;
        if (rnnSetsAllK != null) {
            rrns = rnnSetsAllK[neighborhoodSize - 1];
        }
        if (rrns != null && rrns[index] != null && rrns[index].size() > 0) {
            for (int i = 0; i < rrns[index].size(); i++) {
                BufferedImage thumb = thumbnails.get(rrns[index].get(i));
                try {
                    Thread t = new Thread(new SetImageNeighborsHelper(rnnPanel, thumb,
                            quantizedRepresentation.getLabelOf(rrns[index].get(i)), rrns[index].get(i)));
                    t.start();
                    t.join(500);
                    if (t.isAlive()) {
                        t.interrupt();
                    }
                } catch (Throwable thr) {
                    System.err.println(thr.getMessage());
                }
            }
        }
        // Refresh the neighbor and reverse neighbor panels.
        nnPanel.revalidate();
        nnPanel.repaint();
        rnnPanel.revalidate();
        rnnPanel.repaint();
        // Visualize the neighbor occurrence profile of the selected image.
        DefaultPieDataset pieData = new DefaultPieDataset();
        for (int c = 0; c < numClasses; c++) {
            pieData.setValue(classNames[c], occurrenceProfilesAllK[neighborhoodSize - 1][index][c]);
        }
        JFreeChart chart = ChartFactory.createPieChart3D("occurrence " + "profile", pieData, true, true, false);
        PiePlot3D plot = (PiePlot3D) chart.getPlot();
        plot.setStartAngle(290);
        plot.setDirection(Rotation.CLOCKWISE);
        plot.setForegroundAlpha(0.5f);
        PieRenderer prend = new PieRenderer(classColors);
        prend.setColor(plot, pieData);
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new Dimension(240, 200));
        occProfileChartHolder.removeAll();
        occProfileChartHolder.add(chartPanel);
        occProfileChartHolder.revalidate();
        occProfileChartHolder.repaint();
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}