List of usage examples for org.jfree.chart.entity CategoryItemEntity getColumnKey
public Comparable getColumnKey()
From source file:net.sf.maltcms.common.charts.api.selection.category.CategoryMouseSelectionHandler.java
/** * * @param cme//from w w w . ja v a 2 s . c o m */ @Override public void chartMouseMoved(ChartMouseEvent cme) { if (cme.getEntity() instanceof CategoryItemEntity) { CategoryItemEntity itemEntity = ((CategoryItemEntity) cme.getEntity()); int seriesIndex = dataset.getRowIndex(itemEntity.getRowKey()); int itemIndex = dataset.getColumnIndex(itemEntity.getColumnKey()); if (seriesIndex == -1 || itemIndex == -1) { throw new ArrayIndexOutOfBoundsException("Could not locate series and item index for entity!"); } selection = new CategorySelection(dataset, seriesIndex, itemIndex, XYSelection.Type.HOVER, dataset.getSource(seriesIndex), dataset.getTarget(seriesIndex, itemIndex), shapeFactory.createSelectionShape(itemEntity)); selection.setName(provider.getName(selection)); selection.setDisplayName(provider.getDisplayName(selection)); selection.setShortDescription(provider.getShortDescription(selection)); fireSelectionChange(); } else { clear(); } }
From source file:org.adempiere.webui.editor.WChartEditor.java
private void render(JFreeChart chart) { ChartRenderingInfo info = new ChartRenderingInfo(); int width = 400; int height = chartModel.getWinHeight(); BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info); try {/*from ww w.ja v a2s . co m*/ byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true); AImage image = new AImage("", bytes); Imagemap myImage = new Imagemap(); Panel panel = getComponent(); myImage.setContent(image); if (panel.getPanelchildren() != null) { panel.getPanelchildren().getChildren().clear(); panel.getPanelchildren().appendChild(myImage); } else { Panelchildren pc = new Panelchildren(); panel.appendChild(pc); pc.appendChild(myImage); } int count = 0; for (Iterator<?> it = info.getEntityCollection().getEntities().iterator(); it.hasNext();) { ChartEntity entity = (ChartEntity) it.next(); String key = null; String seriesName = null; if (entity instanceof CategoryItemEntity) { CategoryItemEntity item = ((CategoryItemEntity) entity); Comparable<?> colKey = item.getColumnKey(); Comparable<?> rowKey = item.getRowKey(); if (colKey != null && rowKey != null) { key = colKey.toString(); seriesName = rowKey.toString(); } } else if (entity instanceof PieSectionEntity) { Comparable<?> sectionKey = ((PieSectionEntity) entity).getSectionKey(); if (sectionKey != null) { key = sectionKey.toString(); } } if (entity instanceof XYItemEntity) { XYItemEntity item = ((XYItemEntity) entity); if (item.getDataset() instanceof TimeSeriesCollection) { TimeSeriesCollection data = (TimeSeriesCollection) item.getDataset(); TimeSeries series = data.getSeries(item.getSeriesIndex()); TimeSeriesDataItem dataitem = series.getDataItem(item.getItem()); seriesName = series.getKey().toString(); key = dataitem.getPeriod().toString(); } } if (key == null) continue; Area area = new Area(); myImage.appendChild(area); area.setCoords(entity.getShapeCoords()); area.setShape(entity.getShapeType()); area.setTooltiptext(entity.getToolTipText()); area.setId(count + "_WG__" + seriesName + "__" + key); count++; } myImage.addEventListener(Events.ON_CLICK, new EventListener() { public void onEvent(Event event) throws Exception { MouseEvent me = (MouseEvent) event; String areaId = me.getArea(); if (areaId != null) { String[] strs = areaId.split("__"); if (strs.length == 3) { chartMouseClicked(strs[2], strs[1]); } } } }); } catch (Exception e) { log.log(Level.SEVERE, "", e); } }
From source file:org.amanzi.awe.charts.ui.ChartsView.java
@Override public void chartMouseClicked(final ChartMouseEvent event) { if (event == null) { return;/* www . j a v a2s . c om*/ } Collection<String> groups = null; long startDate = Long.MIN_VALUE; long endDate = Long.MAX_VALUE; String cellName = StringUtils.EMPTY; if (event.getEntity() instanceof CategoryItemEntity) { CategoryItemEntity entity = (CategoryItemEntity) event.getEntity(); IColumn period = (IColumn) entity.getColumnKey(); ICategoryRow column = period.getItemByName((String) entity.getRowKey()); groups = column.getGroupsNames(); startDate = period.getStartDate(); endDate = period.getEndDate(); cellName = column.getName(); } else if (event.getEntity() instanceof XYItemEntity) { XYItemEntity entity = (XYItemEntity) event.getEntity(); TimeSeriesCollection dataset = (TimeSeriesCollection) entity.getDataset(); TimeSeries ts = dataset.getSeries(entity.getSeriesIndex()); ITimeRow row = (ITimeRow) ts.getKey(); RegularTimePeriod period = ts.getTimePeriod(entity.getItem()); startDate = period.getStart().getTime(); endDate = container.getPeriod().addPeriod(startDate); groups = row.getGroupsForTime(startDate); cellName = row.getName(); } else { return; } AWEEventManager.getManager().fireShowInViewEvent(model, new StatisticsFilter(container.getPeriod(), startDate, endDate, groups, cellName), this); }
From source file:com.igalia.java.zk.components.JFreeChartEngine.java
/** * decode CategoryItemEntity into key-value pair of Area's componentScope. *//*from w ww . j av a 2 s .co m*/ private void decodeCategoryInfo(Area area, CategoryItemEntity info) { if (info == null) { return; } CategoryDataset dataset = info.getDataset(); Comparable category = info.getColumnKey(); Comparable series = info.getRowKey(); area.setAttribute("series", series); area.setAttribute("category", category); if (dataset instanceof GanttCategoryDataset) { final GanttCategoryDataset gd = (GanttCategoryDataset) dataset; area.setAttribute("start", gd.getStartValue(series, category)); area.setAttribute("end", gd.getEndValue(series, category)); area.setAttribute("percent", gd.getPercentComplete(series, category)); } else { area.setAttribute("value", dataset.getValue(series, category)); } }
From source file:com.att.aro.ui.view.waterfalltab.WaterfallPanel.java
/** * //from w ww .j ava2 s .c o m * @return */ private ChartPanel getChartPanel() { if (chartPanel == null) { renderer = new StackedBarRenderer(); renderer.setMaximumBarWidth(0.05); renderer.setShadowVisible(false); renderer.setBaseToolTipGenerator(new CategoryToolTipGenerator() { @Override public String generateToolTip(CategoryDataset dataset, int row, int column) { WaterfallCategory wfCategory = (WaterfallCategory) dataset.getColumnKey(column); return wfCategory.getTooltip(); } }); renderer.setBaseItemLabelsVisible(true); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.INSIDE9, TextAnchor.CENTER_LEFT)); renderer.setPositiveItemLabelPositionFallback( new ItemLabelPosition(ItemLabelAnchor.INSIDE9, TextAnchor.CENTER_LEFT)); // Set up plot CategoryPlot plot = new CategoryPlot(new DefaultCategoryDataset(), getCategoryAxis(), getTimeAxis(), renderer); plot.setOrientation(PlotOrientation.HORIZONTAL); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePosition(CategoryAnchor.END); JFreeChart chart = new JFreeChart(plot); chartPanel = new ChartPanel(chart, 400, 200, 200, 200, 2000, 5000, true, false, false, false, false, true); chartPanel.setMouseZoomable(false); chartPanel.setRangeZoomable(false); chartPanel.setDomainZoomable(false); chartPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseMoved(ChartMouseEvent arg0) { // Do Nothing } @Override public void chartMouseClicked(ChartMouseEvent event) { //TODO Add listner info or separate the listener. if (event.getEntity() instanceof CategoryItemEntity) { CategoryItemEntity xyitem = (CategoryItemEntity) event.getEntity(); WaterfallCategory wfCategory = (WaterfallCategory) xyitem.getColumnKey(); if (wfCategory != null && wfCategory.getReqResp() != null) { int count = event.getTrigger().getClickCount(); if (count > 1) { waterfallTab.updateMainFrame(wfCategory.getSession()); } else { popup.refresh(wfCategory.getReqResp(), wfCategory.getIndex()); if (!popup.getPopupDialog().isVisible()) { popup.getPopupDialog().setVisible(true); } } } } } }); } return chartPanel; }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraphAction.java
/** * Add the action listener to the graph. *//*from w w w . j a va2 s . c om*/ private void setAction() { gui.pnlGraph.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(final ChartMouseEvent e) { if (e.getEntity() instanceof PlotEntity) { Point2D p = gui.pnlGraph.translateScreenToJava2D(e.getTrigger().getPoint()); CategoryPlot plot = (CategoryPlot) gui.pnlGraph.getChart().getPlot(); Rectangle2D plotArea = gui.pnlGraph.getScreenDataArea(); DateAxis rangeAxis = (DateAxis) plot.getRangeAxis(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); CategoryAxis catAxis = plot.getDomainAxis(); RectangleEdge domainAxisEdge = plot.getDomainAxisEdge(); double chartY = rangeAxis.java2DToValue(p.getX(), plotArea, rangeAxisEdge); CategoryDataset categories = (CategoryDataset) plot.getDataset(0); int categoryCount = categories.getColumnCount(); for (int i = 0; i < categoryCount; i++) { double catStart = catAxis.getCategoryStart(i, categoryCount, plotArea, domainAxisEdge); double catEnd = catAxis.getCategoryEnd(i, categoryCount, plotArea, domainAxisEdge); if (e.getTrigger().getY() >= catStart && e.getTrigger().getY() < catEnd) { new EditAvailabilityController(gui.function, gui.function.getWorkers().get(i), new Day(new Date((long) chartY)), parent); } } } else { CategoryItemEntity item = (CategoryItemEntity) e.getEntity(); CategoryPlot plot = (CategoryPlot) gui.pnlGraph.getChart().getPlot(); Rectangle2D plotArea = gui.pnlGraph.getScreenDataArea(); RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge(); DateAxis dateAxis = (DateAxis) plot.getRangeAxis(); double d = dateAxis.java2DToValue(e.getEntity().getArea().getBounds2D().getX(), plotArea, rangeAxisEdge); double d2 = dateAxis.java2DToValue(e.getEntity().getArea().getBounds2D().getX() + e.getEntity().getArea().getBounds2D().getWidth(), plotArea, rangeAxisEdge); Date startDate = new Date((long) d); Date endDate = new Date((long) d2); CategoryDataset categories = (CategoryDataset) plot.getDataset(0); int workerIndex = categories.getColumnIndex(item.getColumnKey()); Worker worker = gui.function.getWorkers().get(workerIndex); Set<Availability> found = CalendarService.getAllWorkerAvailability(worker.getId(), startDate, endDate); Availability foundAv = found.toArray(new Availability[1])[0]; if (foundAv != null) { new EditAvailabilityController(gui.function, foundAv, parent); } else { found = CalendarService.getProjectAvailability(startDate, endDate); foundAv = found.toArray(new Availability[1])[0]; if (foundAv != null) { new EditAvailabilityController(gui.function, foundAv, parent); } else { JOptionPane.showMessageDialog( new JFrame(LocalizedStrings.getGeneralStrings().warning()), LocalizedStrings.getErrorMessages().availabilityCanNotBeChanged()); } } } } @Override public void chartMouseMoved(final ChartMouseEvent arg0) { } }); /** * ActionListener */ gui.btnNext.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { gui.function.increment(); } }); /** * ActionListener */ gui.btnPrev.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { gui.function.decrement(); } }); for (int i = 0; i < gui.buttons.length; i++) { addButtonListener(i); } /** * ActionListener */ gui.btnManualAv.addItemListener(new ItemListener() { @Override public void itemStateChanged(final ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { gui.function.setManualAv(true); } else { gui.function.setManualAv(false); } } }); }
From source file:org.talend.dataprofiler.chart.TOPChartService.java
@Override public void addMouseListenerForChart(Object chartComposite, final Map<String, Object> menuMap, final boolean useRowFirst) { final ChartComposite chartComp = (ChartComposite) chartComposite; final ChartMouseListener listener = new ChartMouseListener() { @Override/* w w w . j a v a 2 s. c o m*/ public void chartMouseClicked(ChartMouseEvent event) { boolean flag = event.getTrigger().getButton() != MouseEvent.BUTTON3; chartComp.setDomainZoomable(flag); chartComp.setRangeZoomable(flag); if (flag) { return; } ChartEntity chartEntity = event.getEntity(); if (chartEntity != null && chartEntity instanceof CategoryItemEntity) { CategoryItemEntity cateEntity = (CategoryItemEntity) chartEntity; Menu menu = getCurrentMenu(cateEntity); if (menu != null) { chartComp.setMenu(menu); menu.setVisible(true); } } } private Menu getCurrentMenu(CategoryItemEntity cateEntity) { if (useRowFirst) { return findCurrentMenu(cateEntity.getRowKey(), cateEntity.getColumnKey()); } else { return findCurrentMenu(cateEntity.getColumnKey(), cateEntity.getRowKey()); } } /** * DOC yyin Comment method "findCurrentMenu". * * @param firstKey * @param secondKey * @return */ private Menu findCurrentMenu(final Object firstKey, Object secondKey) { Object menu = menuMap.get(firstKey); if (menu != null) { return (Menu) menu; } menu = menuMap.get(secondKey); if (menu != null) { return (Menu) menu; } 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(); } }); }
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// www . 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(); } }); }