Example usage for org.jfree.chart.entity CategoryItemEntity getCategoryIndex

List of usage examples for org.jfree.chart.entity CategoryItemEntity getCategoryIndex

Introduction

In this page you can find the example usage for org.jfree.chart.entity CategoryItemEntity getCategoryIndex.

Prototype

public int getCategoryIndex() 

Source Link

Document

Returns the category index.

Usage

From source file:org.openfaces.component.chart.impl.helpers.ChartInfoUtil.java

private static GridPointInfo getGridPointInfo(CategoryItemEntity en, Chart chart) {
    ChartModel model = chart.getModel();
    if (model == null)
        return null;

    GridPointInfo info = new GridPointInfoImpl();
    info.setSeries(new SeriesInfoImpl());
    info.getSeries().setIndex(en.getSeries());

    ModelInfo modelInfo = new ModelInfo(model);

    if (!modelInfo.isDataEmpty()) {
        CategoryDataset ds = ModelConverter.toCategoryDataset(modelInfo);
        Comparable seriesKey = ds.getRowKey(en.getSeries());
        Comparable tupleKey = ds.getColumnKey(en.getCategoryIndex());
        Object tupleValue = ds.getValue(seriesKey, tupleKey);
        info.setIndex(en.getCategoryIndex());
        info.setKey(tupleKey);//from   w  ww.  j a v  a  2 s  .c o  m
        info.setValue(tupleValue);
        info.getSeries().setKey(seriesKey);
    }

    return info;
}

From source file:com.choicemaker.cm.modelmaker.gui.utils.HistoChartPanel.java

public HistoChartPanel(final JFreeChart chart, boolean properties, boolean save, boolean print, boolean zoom,
        boolean tooltips, final ModelMaker modelMaker) {
    super(chart, properties, save, print, zoom, tooltips);
    this.modelMaker = modelMaker;
    // horizontal zoom doesn't work, by setting false we don't get bogus menu item
    //      setHorizontalZoom(false);
    //      setVerticalZoom(true);
    final JCheckBoxMenuItem logYScale = new JCheckBoxMenuItem(
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.test.logscale.y"));
    logYScale.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            CategoryPlot p = (CategoryPlot) chart.getPlot();
            Axis oldAxis = p.getRangeAxis();
            if (logYScale.isSelected()) {
                LogarithmicAxis yAxis = new LogarithmicAxis(ChoiceMakerCoreMessages.m
                        .formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs"));
                yAxis.setStrictValuesFlag(false);
                p.setRangeAxis(yAxis);//ww w  .  j ava2  s  .c om
            } else {
                p.setRangeAxis(new NumberAxis(ChoiceMakerCoreMessages.m
                        .formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs")));
            }
            oldAxis.setPlot(null);
            chartChanged(new ChartChangeEvent(this));
        }
    });
    JPopupMenu popup = getPopupMenu();
    popup.addSeparator();
    popup.add(logYScale);
    popup.addSeparator();
    select = new JMenu("Select");
    final JMenuItem all = new JMenuItem("All");
    select.add(all);
    final JMenuItem cmDiffer = new JMenuItem("Human marked differ");
    select.add(cmDiffer);
    final JMenuItem cmHold = new JMenuItem("Human marked hold");
    select.add(cmHold);
    final JMenuItem cmMatch = new JMenuItem("Human marked match");
    select.add(cmMatch);
    ActionListener l = new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            ListeningMarkedRecordPairFilter filter = modelMaker.getFilter();
            filter.reset();
            filter.setFromPercentage(rangeFrom);
            filter.setToPercentage(rangeTo);
            Object src = ev.getSource();
            if (src != all) {
                boolean[] b = new boolean[Decision.NUM_DECISIONS];
                if (src == cmDiffer) {
                    b[Decision.DIFFER.toInt()] = true;
                } else if (src == cmHold) {
                    b[Decision.HOLD.toInt()] = true;
                } else if (src == cmMatch) {
                    b[Decision.MATCH.toInt()] = true;
                }
                filter.setHumanDecision(b);
            }
            modelMaker.filterMarkedRecordPairList();
        }
    };
    all.addActionListener(l);
    cmDiffer.addActionListener(l);
    cmHold.addActionListener(l);
    cmMatch.addActionListener(l);
    popup.add(select);
    addChartMouseListener(new ChartMouseListener() {
        public void chartMouseClicked(ChartMouseEvent evt) {
            ChartEntity e = evt.getEntity();
            if (e instanceof CategoryItemEntity) {
                CategoryItemEntity c = (CategoryItemEntity) e;
                int cat = c.getCategoryIndex();
                HistoCategoryDataset data = (HistoCategoryDataset) ((CategoryPlot) getChart().getPlot())
                        .getDataset();
                int len = data.getColumnCount();
                float step = 1f / len;
                rangeFrom = cat * step;
                rangeTo = rangeFrom + step;
                ListeningMarkedRecordPairFilter filter = modelMaker.getFilter();
                filter.reset();
                filter.setFromPercentage(rangeFrom);
                filter.setToPercentage(rangeTo);
                boolean[] b = new boolean[Decision.NUM_DECISIONS];
                int series = c.getSeries();
                if (data.isIncludeHolds() && series != 0) {
                    if (series == 1) {
                        series = 2;
                    } else {
                        series = 1;
                    }
                }
                b[series] = true;
                filter.setHumanDecision(b);
                modelMaker.filterMarkedRecordPairList();

            }
        }

        public void chartMouseMoved(ChartMouseEvent arg0) {
        }
    });
}

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  va  2s  .  c o m*/
    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:org.talend.dataprofiler.chart.TOPChartService.java

@Override
public void addSpecifiedListenersForCorrelationChart(Object chartcomp, final Object chart, final boolean isAvg,
        final boolean isDate, final Map<Integer, Object> keyWithAdapter) {
    final ChartComposite chartComp = (ChartComposite) chartcomp;
    chartComp.addChartMouseListener(new ChartMouseListener() {

        @Override/*from w w  w .  ja v a  2 s .  co  m*/
        public void chartMouseClicked(ChartMouseEvent event) {

            chartComp.setRangeZoomable(event.getTrigger().getButton() == 1);
            chartComp.setDomainZoomable(event.getTrigger().getButton() == 1);

            if (event.getTrigger().getButton() != 3) {
                return;
            }
            final Menu menu = new Menu(chartComp.getShell(), SWT.POP_UP);
            MenuItem itemShowInFullScreen = new MenuItem(menu, SWT.PUSH);
            itemShowInFullScreen.setText(Messages.getString("HideSeriesChartComposite.ShowInFullScreen")); //$NON-NLS-1$
            itemShowInFullScreen.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            showChartInFillScreen(chart, isAvg, isDate);
                        }
                    });
                }
            });

            chartComp.setMenu(menu);
            ChartEntity chartEntity = event.getEntity();
            if (chartEntity != null) {
                if (isAvg) {
                    addMenuOnBubbleChart(menu, chartEntity);
                } else if (isDate) {
                    addMenuOnGantChart(menu, chartEntity);
                }
            }
            menu.setVisible(true);
        }

        private void addMenuOnBubbleChart(Menu menu, ChartEntity chartEntity) {
            if (chartEntity instanceof XYItemEntity) {
                XYItemEntity xyItemEntity = (XYItemEntity) chartEntity;
                createMenuItem(menu, xyItemEntity.getItem());
            }
        }

        private void addMenuOnGantChart(Menu menu, ChartEntity chartEntity) {

            if (chartEntity instanceof CategoryItemEntity) {
                CategoryItemEntity itemEntity = (CategoryItemEntity) chartEntity;
                createMenuItem(menu, itemEntity.getCategoryIndex());
            }
        }

        private void createMenuItem(Menu menu, final int seriesK) {
            final SelectionAdapter selectionAdapter = (SelectionAdapter) keyWithAdapter.get(seriesK);
            MenuItem item;
            item = new MenuItem(menu, SWT.PUSH);
            item.setText(Messages.getString("HideSeriesChartComposite.ViewRow")); //$NON-NLS-1$
            item.addSelectionListener(selectionAdapter);
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            // no need to implement
        }

    });
}

From source file:org.talend.dataprofiler.chart.TOPChartService.java

@Override
public void addMouseListenerForConceptChart(Object chartComposite, final Map<String, Object> actionMap) {
    final ChartComposite chartComp = (ChartComposite) chartComposite;
    final ChartMouseListener listener = new ChartMouseListener() {

        @Override/*from w  w w.  j a v  a  2 s.c o m*/
        public void chartMouseClicked(ChartMouseEvent event) {
            boolean flag = event.getTrigger().getButton() == MouseEvent.BUTTON1;
            chartComp.setDomainZoomable(flag);
            chartComp.setRangeZoomable(flag);
            if (!flag) {
                return;
            }

            ChartEntity chartEntity = event.getEntity();
            if (chartEntity != null && chartEntity instanceof CategoryItemEntity) {
                CategoryItemEntity cateEntity = (CategoryItemEntity) chartEntity;
                // highlight current selected bar
                Plot plot = event.getChart().getPlot();
                if (plot != null) {
                    // ((CategoryPlot) plot).getRenderer().setSeriesPaint(cateEntity.getSeries(), Green);
                    CustomConceptRenderer render = new CustomConceptRenderer(cateEntity.getCategoryIndex());
                    render.setShadowVisible(false);
                    render.setDrawBarOutline(false);
                    ((CategoryPlot) plot).setRenderer(render);
                    // ChartDecorator.decorateConceptChart(event.getChart(), PlotOrientation.HORIZONTAL);

                }
                Object action = getCurrentAction(cateEntity);
                Class<? extends Object> actionClass = action.getClass();
                try {
                    Method actionRunMethod = actionClass.getDeclaredMethod("run"); //$NON-NLS-1$
                    actionRunMethod.invoke(action);

                } catch (NoSuchMethodException e) {
                    log.error(e, e);
                } catch (SecurityException e) {
                    log.error(e, e);
                } catch (IllegalAccessException e) {
                    log.error(e, e);
                } catch (IllegalArgumentException e) {
                    log.error(e, e);
                } catch (InvocationTargetException e) {
                    log.error(e, e);
                }

            }
        }

        private Object getCurrentAction(CategoryItemEntity cateEntity) {
            return findCurrentAction(cateEntity.getColumnKey(), cateEntity.getRowKey());
        }

        /**
         * Find current action
         * 
         * @param firstKey
         * @param secondKey
         * @return
         */
        private Object findCurrentAction(final Object firstKey, Object secondKey) {
            Object action = actionMap.get(firstKey);
            if (action != null) {
                return action;
            }
            action = actionMap.get(secondKey);
            if (action != null) {
                return action;
            }
            return null;
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            // no action here

        }

    };
    chartComp.addChartMouseListener(listener);
    chartComp.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            chartComp.removeChartMouseListener(listener);
            chartComp.dispose();
        }

    });
}