Example usage for org.jfree.chart.entity PieSectionEntity getSectionIndex

List of usage examples for org.jfree.chart.entity PieSectionEntity getSectionIndex

Introduction

In this page you can find the example usage for org.jfree.chart.entity PieSectionEntity getSectionIndex.

Prototype

public int getSectionIndex() 

Source Link

Document

Returns the section index.

Usage

From source file:lu.lippmann.cdb.common.gui.DragAndDroppablePieChartPanel.java

/**
 * {@inheritDoc}//from   w  ww.  ja v a2s.  c o m
 */
@Override
public void mouseReleased(MouseEvent e) {
    super.mouseReleased(e);
    final ChartEntity entity = getEntityForPoint(e.getX(), e.getY());
    if (entity instanceof PieSectionEntity) {
        final PieSectionEntity target = ((PieSectionEntity) entity);
        if (source != null) {
            if (target.getSectionIndex() != source.getSectionIndex()) {
                listener.onAction(new Integer[] { source.getSectionIndex(), target.getSectionIndex() });
            }
        }
    }
    released = true;
    repaint();
}

From source file:biz.ixnay.pivot.charts.skin.jfree.PieChartViewSkin.java

@Override
public ChartView.Element getElementAt(int x, int y) {
    ChartView.Element element = null;

    ChartEntity chartEntity = getChartEntityAt(x, y);
    if (chartEntity instanceof PieSectionEntity) {
        PieSectionEntity pieSectionEntity = (PieSectionEntity) chartEntity;
        int sectionIndex = pieSectionEntity.getSectionIndex();
        int seriesIndex = pieSectionEntity.getPieIndex();

        element = new ChartView.Element(seriesIndex, sectionIndex);
    }/*from   w  w w. j  a  v a2  s.c  o  m*/

    return element;
}

From source file:de.laures.cewolf.taglib.tags.ChartMapTag.java

private String generateToolTip(Dataset dataset, ChartEntity ce) throws JspException {
    String tooltip = null;/*from  w  w w  . j a v a  2 s . com*/
    if (useJFreeChartTooltipGenerator) {
        tooltip = ce.getToolTipText();
    } else if (toolTipGenerator instanceof CategoryToolTipGenerator
            || toolTipGenerator instanceof XYToolTipGenerator
            || toolTipGenerator instanceof PieToolTipGenerator) {
        if (toolTipGenerator instanceof CategoryToolTipGenerator) {
            if (ce instanceof CategoryItemEntity) {
                CategoryItemEntity catEnt = (CategoryItemEntity) ce;
                tooltip = ((CategoryToolTipGenerator) toolTipGenerator).generateToolTip(
                        (CategoryDataset) dataset, catEnt.getSeries(), catEnt.getCategoryIndex());
            }
        }

        if (toolTipGenerator instanceof XYToolTipGenerator) {
            if (ce instanceof XYItemEntity) {
                XYItemEntity xyEnt = (XYItemEntity) ce;
                tooltip = ((XYToolTipGenerator) toolTipGenerator).generateToolTip((XYDataset) dataset,
                        xyEnt.getSeriesIndex(), xyEnt.getItem());
            }
        }

        if (toolTipGenerator instanceof PieToolTipGenerator) {
            if (ce instanceof PieSectionEntity) {
                PieSectionEntity pieEnt = (PieSectionEntity) ce;
                PieDataset ds = (PieDataset) dataset;
                final int index = pieEnt.getSectionIndex();
                tooltip = ((PieToolTipGenerator) toolTipGenerator).generateToolTip(ds, ds.getKey(index), index);
            }
        }
    } else {
        // throw because category is unknown
        throw new JspException("TooltipgGenerator of class " + toolTipGenerator.getClass().getName()
                + " does not implement the appropriate TooltipGenerator interface for entity type "
                + ce.getClass().getName());
    }
    return tooltip;
}

From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java

@Override
public void chartMouseMoved(ChartMouseEvent chartMouseEvent) {
    ChartEntity entity = chartMouseEvent.getEntity();

    //      System.out.println(entity.toString());
    if (entity != null) {
        if (entity instanceof PieSectionEntity) {
            PieSectionEntity pieSectionEntity = (PieSectionEntity) entity;
            int index = pieSectionEntity.getSectionIndex();

            PiePlot plot = (PiePlot) chart.getPlot();

            int sectionCount = plot.getDataset().getItemCount();

            for (int i = 0; i < sectionCount; ++i) {
                String key = (String) plot.getDataset().getKey(i);
                if (i == index) {
                    plot.setExplodePercent(key, 0.20);
                } else {
                    plot.setExplodePercent(key, 0.0);
                }/*  ww  w .ja  v a  2 s . c o m*/
            }
            lastSeries = index;
            lastCategory = -1;

            showQueryAction.setSeries(lastSeries);
            showQueryAction.setCategory(lastCategory);
            showQueriesMenuItem.setEnabled(true);
        }

        if (entity instanceof XYItemEntity) {
            XYItemEntity xyItemEntity = (XYItemEntity) entity;
            XYPlot plot = chart.getXYPlot();
            DBSeerXYLineAndShapeRenderer renderer = (DBSeerXYLineAndShapeRenderer) plot.getRenderer();
            if (isTransactionSampleChart && xyItemEntity.getSeriesIndex() < maxTransactionSeries) {
                renderer.setLastSeriesAndCategory(xyItemEntity.getSeriesIndex(), xyItemEntity.getItem());
                lastSeries = xyItemEntity.getSeriesIndex();
                lastCategory = xyItemEntity.getItem();
                showQueryAction.setSeries(lastSeries);
                showQueryAction.setCategory(lastCategory);
                showQueriesMenuItem.setEnabled(true);
                this.setRefreshBuffer(true);
                this.repaint();
            }
        }
    }
}

From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java

@Override
public void chartMouseClicked(ChartMouseEvent chartMouseEvent) {
    ChartEntity entity = chartMouseEvent.getEntity();
    MouseEvent mouseEvent = chartMouseEvent.getTrigger();

    if (SwingUtilities.isLeftMouseButton(mouseEvent) && entity != null && entity instanceof PieSectionEntity) {
        java.util.List<String> names = dataset.getTransactionTypeNames();
        PieSectionEntity pieSectionEntity = (PieSectionEntity) entity;
        int idx = pieSectionEntity.getSectionIndex();

        String name = (String) JOptionPane.showInputDialog(null, "Enter the name for this transaction type",
                "Transaction Type", JOptionPane.PLAIN_MESSAGE, null, null, "");

        if (name != null) {
            if (names.contains(name) && !names.get(idx).equals(name) && !name.isEmpty()) {
                JOptionPane.showMessageDialog(null,
                        "Please enter a different name for the transaction type.\nEach name has to be unique.",
                        "Warning", JOptionPane.WARNING_MESSAGE);
            } else {
                PieDataset oldDataset = pieSectionEntity.getDataset();
                DefaultPieDataset newDataset = new DefaultPieDataset();

                PiePlot plot = (PiePlot) chart.getPlot();
                String oldName = (String) oldDataset.getKey(idx);
                names.set(idx, name);/*from w  w  w  . ja va2 s. co m*/
                dataset.setTransactionTypeName(idx, name);

                for (int i = 0; i < oldDataset.getItemCount(); ++i) {
                    String key = (String) oldDataset.getKey(i);
                    Number number = oldDataset.getValue(i);

                    if (key.equals(oldName)) {
                        if (name.isEmpty())
                            newDataset.setValue("Transaction Type " + (i + 1), number);
                        else
                            newDataset.setValue(name, number);
                    } else {
                        newDataset.setValue(key, number);
                    }
                }

                Paint[] tempPaint = new Paint[oldDataset.getItemCount()];
                for (int i = 0; i < oldDataset.getItemCount(); ++i) {
                    String key = (String) oldDataset.getKey(i);
                    tempPaint[i] = plot.getSectionPaint(key);
                }

                ((DefaultPieDataset) oldDataset).clear();
                plot.setDataset(newDataset);

                for (int i = 0; i < newDataset.getItemCount(); ++i) {
                    String key = (String) newDataset.getKey(i);
                    plot.setSectionPaint(key, tempPaint[i]);
                }
            }
        }
    }
}