/** * Adds an entity with the specified hotspot. * * @param entities the entity collection. * @param dataset the dataset. * @param row the row index. * @param column the column index. * @param hotspot the hotspot. */ protected void addItemEntity(EntityCollection entities, CategoryDataset dataset, int row, int column, Shape hotspot) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; CategoryURLGenerator urlster = getItemURLGenerator(row, column); if (urlster != null) { url = urlster.generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(hotspot, tip, url, dataset, row, dataset.getColumnKey(column), column); entities.add(entity); }
/** * Adds an entity with the specified hotspot. * * @param entities the entity collection. * @param dataset the dataset. * @param row the row index. * @param column the column index. * @param hotspot the hotspot (<code>null</code> not permitted). */ protected void addItemEntity(EntityCollection entities, CategoryDataset dataset, int row, int column, Shape hotspot) { ParamChecks.nullNotPermitted(hotspot, "hotspot"); if (!getItemCreateEntity(row, column)) { return; } String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; CategoryURLGenerator urlster = getItemURLGenerator(row, column); if (urlster != null) { url = urlster.generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(hotspot, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); }
/** * Adds an entity with the specified hotspot. * * @param entities the entity collection. * @param dataset the dataset. * @param row the row index. * @param column the column index. * @param hotspot the hotspot ({@code null} not permitted). */ protected void addItemEntity(EntityCollection entities, CategoryDataset dataset, int row, int column, Shape hotspot) { Args.nullNotPermitted(hotspot, "hotspot"); if (!getItemCreateEntity(row, column)) { return; } String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; CategoryURLGenerator urlster = getItemURLGenerator(row, column); if (urlster != null) { url = urlster.generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(hotspot, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); }
@Override public JRPrintHyperlink getEntityHyperlink(ChartEntity entity) { JRPrintHyperlink printHyperlink = null; if (hasHyperlinks() && entity instanceof CategoryItemEntity) { CategoryItemEntity itemEntity = (CategoryItemEntity) entity; Comparable<?> serie = itemEntity.getRowKey(); Map<Comparable<?>,JRPrintHyperlink> serieHyperlinks = itemHyperlinks.get(serie); if (serieHyperlinks != null) { Comparable<?> category = itemEntity.getColumnKey(); printHyperlink = serieHyperlinks.get(category); } } return printHyperlink; }
/** * Adds an entity with the specified hotspot. * * @param entities the entity collection. * @param dataset the dataset. * @param row the row index. * @param column the column index. * @param hotspot the hotspot. */ protected void addItemEntity(EntityCollection entities, CategoryDataset dataset, int row, int column, Shape hotspot) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; CategoryURLGenerator urlster = getItemURLGenerator(row, column); if (urlster != null) { url = urlster.generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(hotspot, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); }
/** * Adds an entity with the specified hotspot. * * @param entities the entity collection. * @param dataset the dataset. * @param row the row index. * @param column the column index. * @param hotspot the hotspot (<code>null</code> not permitted). */ protected void addItemEntity(EntityCollection entities, CategoryDataset dataset, int row, int column, Shape hotspot) { if (hotspot == null) { throw new IllegalArgumentException("Null 'hotspot' argument."); } if (!getItemCreateEntity(row, column)) { return; } String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; CategoryURLGenerator urlster = getItemURLGenerator(row, column); if (urlster != null) { url = urlster.generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(hotspot, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); }
@Override public void getModelCoordinatesInfo(final int xOnScreen, final int yOnScreen, final IDisplaySurface g, final Point positionInPixels, final StringBuilder sb) { final int x = xOnScreen - positionInPixels.x; final int y = yOnScreen - positionInPixels.y; final ChartEntity entity = info.getEntityCollection().getEntity(x, y); // getChart().handleClick(x, y, info); final Comparable<?> columnKey = ((CategoryItemEntity) entity).getColumnKey(); final String title = columnKey.toString(); final CategoryDataset data = ((CategoryItemEntity) entity).getDataset(); final Comparable<?> rowKey = ((CategoryItemEntity) entity).getRowKey(); final double xx = data.getValue(rowKey, columnKey).doubleValue(); final boolean xInt = xx % 1 == 0; sb.append(title).append(" ").append(xInt ? (int) xx : String.format("%.2f", xx)); }
/** * Adds an entity with the specified hotspot, but only if an entity * collection is accessible via the renderer state. * * @param entities the entity collection. * @param dataset the dataset. * @param row the row index. * @param column the column index. * @param hotspot the hotspot. */ protected void addItemEntity(EntityCollection entities, CategoryDataset dataset, int row, int column, Shape hotspot) { String tip = null; CategoryToolTipGenerator tipster = getToolTipGenerator(row, column); if (tipster != null) { tip = tipster.generateToolTip(dataset, row, column); } String url = null; CategoryURLGenerator urlster = getItemURLGenerator(row, column); if (urlster != null) { url = urlster.generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(hotspot, tip, url, dataset, row, dataset.getColumnKey(column), column); entities.add(entity); }
/** * Override the method so we can set custom tooltips */ @Override protected void addItemEntity(EntityCollection entities, CategoryDataset dataset, int row, int column, Shape hotspot) { ParamChecks.nullNotPermitted(hotspot, "hotspot"); if (!getItemCreateEntity(row, column)) { return; } String tip = null; if((index-1) < tooltips.size()){ tip = tooltips.get(index-1); } String url = null; CategoryURLGenerator urlster = getItemURLGenerator(row, column); if (urlster != null) { url = urlster.generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(hotspot, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); }
@Override public void chartMouseClicked(ChartMouseEvent event) { if (event.getEntity().getClass() == CategoryItemEntity.class) { if ((getChart() != null) && (getChart().getClass() == HighlightableBarChart.class)) { HighlightableBarChart chart = (HighlightableBarChart) getChart(); CategoryItemEntity entity = (CategoryItemEntity) event.getEntity(); // toggle highlight if already selected if (chart.isHighlighted(entity)) { chart.clearHighlights(); firePropertyChange("highlightedBar", getRowAndColumn(entity), null); } else { chart.clearHighlights(); chart.highlightEntity(entity); firePropertyChange("highlightedBar", null, getRowAndColumn(entity)); } // assume whatever fired the event will repaint the chart } } }
/** * Adds an entity to the collection. * * @param entities the entity collection being populated. * @param hotspot the entity area (if <code>null</code> a default will be * used). * @param dataset the dataset. * @param row the series. * @param column the item. * @param entityX the entity's center x-coordinate in user space (only * used if <code>area</code> is <code>null</code>). * @param entityY the entity's center y-coordinate in user space (only * used if <code>area</code> is <code>null</code>). * * @since 1.0.13 */ protected void addEntity(EntityCollection entities, Shape hotspot, CategoryDataset dataset, int row, int column, double entityX, double entityY) { if (!getItemCreateEntity(row, column)) { return; } Shape s = hotspot; if (hotspot == null) { double r = getDefaultEntityRadius(); double w = r * 2; if (getPlot().getOrientation() == PlotOrientation.VERTICAL) { s = new Ellipse2D.Double(entityX - r, entityY - r, w, w); } else { s = new Ellipse2D.Double(entityY - r, entityX - r, w, w); } } String tip = null; CategoryToolTipGenerator generator = getToolTipGenerator(row, column); if (generator != null) { tip = generator.generateToolTip(dataset, row, column); } String url = null; CategoryURLGenerator urlster = getItemURLGenerator(row, column); if (urlster != null) { url = urlster.generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(s, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); }
/** * Adds an entity to the collection. * * @param entities the entity collection being populated. * @param hotspot the entity area (if {@code null} a default will be * used). * @param dataset the dataset. * @param row the series. * @param column the item. * @param entityX the entity's center x-coordinate in user space (only * used if {@code area} is {@code null}). * @param entityY the entity's center y-coordinate in user space (only * used if {@code area} is {@code null}). * * @since 1.0.13 */ protected void addEntity(EntityCollection entities, Shape hotspot, CategoryDataset dataset, int row, int column, double entityX, double entityY) { if (!getItemCreateEntity(row, column)) { return; } Shape s = hotspot; if (hotspot == null) { double r = getDefaultEntityRadius(); double w = r * 2; if (getPlot().getOrientation() == PlotOrientation.VERTICAL) { s = new Ellipse2D.Double(entityX - r, entityY - r, w, w); } else { s = new Ellipse2D.Double(entityY - r, entityX - r, w, w); } } String tip = null; CategoryToolTipGenerator generator = getToolTipGenerator(row, column); if (generator != null) { tip = generator.generateToolTip(dataset, row, column); } String url = null; CategoryURLGenerator urlster = getItemURLGenerator(row, column); if (urlster != null) { url = urlster.generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(s, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); }
protected Dataset getEntityDataset(ChartEntity entity) { Dataset dataset = null; if (entity instanceof CategoryItemEntity) { dataset = ((CategoryItemEntity) entity).getDataset(); } else if (entity instanceof XYItemEntity) { dataset = ((XYItemEntity) entity).getDataset(); } return dataset; }
/** * The gesture entity type * * @param entity * @return */ public static Entity getGestureEntity(ChartEntity entity) { if (entity == null) return NONE; if (entity instanceof PlotEntity) return PLOT; if (entity instanceof AxisEntity) { AxisEntity e = (AxisEntity) entity; if (e.getAxis().getPlot() instanceof XYPlot) { XYPlot plot = ((XYPlot) e.getAxis().getPlot()); for (int i = 0; i < plot.getDomainAxisCount(); i++) if (plot.getDomainAxis(i).equals(e.getAxis())) return DOMAIN_AXIS; for (int i = 0; i < plot.getRangeAxisCount(); i++) if (plot.getRangeAxis(i).equals(e.getAxis())) return RANGE_AXIS; } // else return basic axis return AXIS; } if (entity instanceof LegendItemEntity) return LEGEND_ITEM; if (entity instanceof XYItemEntity) return XY_ITEM; if (entity instanceof XYAnnotationEntity) return XY_ANNOTATION; if (entity instanceof TitleEntity) { if (((TitleEntity) entity).getTitle() instanceof TextTitle) return TEXT_TITLE; else return NON_TEXT_TITLE; } if (entity instanceof JFreeChartEntity) return JFREECHART; if (entity instanceof CategoryItemEntity) return CATEGORY_ITEM; return GENERAL; }
/** * Get BarGraphColumn for ChartEntity * @param event * @return BarGraphColumn or null if not found */ private GraphColumn getGraphColumn(ChartMouseEvent event) { ChartEntity entity = event.getEntity(); String key = null; if (entity instanceof CategoryItemEntity) { Comparable<?> colKey = ((CategoryItemEntity)entity).getColumnKey(); if (colKey != null) { key = colKey.toString(); } } else if (entity instanceof PieSectionEntity) { Comparable<?> sectionKey = ((PieSectionEntity)entity).getSectionKey(); if (sectionKey != null) { key = sectionKey.toString(); } } if (key == null) { return null; } for (int i = 0; i < list.size(); i++) { final String label = list.get(i).getLabel(); if (key.equals(label)) { return list.get(i); } } // return null; }
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { DefaultCategoryDataset d = new DefaultCategoryDataset(); d.addValue(1.0, "R1", "C1"); d.addValue(2.0, "R1", "C2"); d.addValue(3.0, "R2", "C1"); d.addValue(4.0, "R2", "C2"); CategoryItemEntity e1 = new CategoryItemEntity(new Rectangle2D.Double( 1.0, 2.0, 3.0, 4.0), "ToolTip", "URL", d, "R2", "C2"); CategoryItemEntity e2 = new CategoryItemEntity(new Rectangle2D.Double( 1.0, 2.0, 3.0, 4.0), "ToolTip", "URL", d, "R2", "C2"); assertTrue(e1.equals(e2)); e1.setArea(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0)); assertFalse(e1.equals(e2)); e2.setArea(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0)); assertTrue(e1.equals(e2)); e1.setToolTipText("New ToolTip"); assertFalse(e1.equals(e2)); e2.setToolTipText("New ToolTip"); assertTrue(e1.equals(e2)); e1.setURLText("New URL"); assertFalse(e1.equals(e2)); e2.setURLText("New URL"); assertTrue(e1.equals(e2)); e1.setColumnKey("C1"); assertFalse(e1.equals(e2)); e2.setColumnKey("C1"); assertTrue(e1.equals(e2)); e1.setRowKey("R1"); assertFalse(e1.equals(e2)); e2.setRowKey("R1"); assertTrue(e1.equals(e2)); }
/** * Adds an entity to the collection. * * @param entities the entity collection being populated. * @param hotspot the entity area (if <code>null</code> a default will be * used). * @param dataset the dataset. * @param row the series. * @param column the item. * @param selected is the item selected? * @param entityX the entity's center x-coordinate in user space (only * used if <code>area</code> is <code>null</code>). * @param entityY the entity's center y-coordinate in user space (only * used if <code>area</code> is <code>null</code>). * * @since 1.2.0 */ protected void addEntity(EntityCollection entities, Shape hotspot, CategoryDataset dataset, int row, int column, boolean selected, double entityX, double entityY) { if (!getItemCreateEntity(row, column, selected)) { return; } Shape s = hotspot; if (hotspot == null) { double r = getDefaultEntityRadius(); double w = r * 2; if (getPlot().getOrientation() == PlotOrientation.VERTICAL) { s = new Ellipse2D.Double(entityX - r, entityY - r, w, w); } else { s = new Ellipse2D.Double(entityY - r, entityX - r, w, w); } } String tip = null; CategoryToolTipGenerator generator = getToolTipGenerator(row, column, selected); if (generator != null) { tip = generator.generateToolTip(dataset, row, column); } String url = null; CategoryURLGenerator urlster = getURLGenerator(row, column, selected); if (urlster != null) { url = urlster.generateURL(dataset, row, column); } CategoryItemEntity entity = new CategoryItemEntity(s, tip, url, dataset, dataset.getRowKey(row), dataset.getColumnKey(column)); entities.add(entity); }
@Override public void highlightElement(int row, int column) { if ((getChart() != null) && (getChart().getClass() == HighlightableBarChart.class)) { boolean highlightWholeBar = ((DataTupleCategoryDataset) getChart().getCategoryPlot().getDataset()) .categoriesHaveDifferentStats(); // find the CategoryItemEntity that matches the given row and column // assume there are not that many entities in the chart and this will be relatively fast @SuppressWarnings("rawtypes") java.util.Iterator i = getChartRenderingInfo().getEntityCollection().iterator(); while (i.hasNext()) { ChartEntity entity = (ChartEntity) i.next(); if (entity.getClass() == CategoryItemEntity.class) { CategoryItemEntity categoryEntity = (CategoryItemEntity) entity; int currentRow = categoryEntity.getDataset().getRowIndex(categoryEntity.getRowKey()); int currentColumn = categoryEntity.getDataset().getColumnIndex(categoryEntity.getColumnKey()); if (highlightWholeBar) { // match all categories if (currentColumn == column) { ((HighlightableBarChart) getChart()).highlightEntity(categoryEntity); } } else { // match only a single category if ((currentRow == row) && (currentColumn == column)) { ((HighlightableBarChart) getChart()).highlightEntity(categoryEntity); break; } } } } } }
private int[] getRowAndColumn(CategoryItemEntity entity) { int[] toReturn = new int[2]; toReturn[0] = entity.getDataset().getRowIndex(entity.getRowKey()); toReturn[1] = entity.getDataset().getColumnIndex(entity.getColumnKey()); return toReturn; }
@Override public void draw(Graphics2D g2, Rectangle2D chartArea, Point2D anchor, ChartRenderingInfo info) { super.draw(g2, chartArea, anchor, info); if (info != null) { // for each CategoryItem, highlight the bar // this has to be done during painting so it carries over on repaints for (CategoryItemEntity entity : selectedEntities) { Rectangle2D area = ((Rectangle2D) entity.getArea()) .createIntersection(info.getPlotInfo().getDataArea()); CategoryItemRenderer renderer = ((CategoryPlot) getPlot()).getRenderer(); int row = entity.getDataset().getRowIndex(entity.getRowKey()); int column = entity.getDataset().getColumnIndex(entity.getColumnKey()); java.awt.Color baseColor = (java.awt.Color) renderer.getItemPaint(row, column); // redraw the bar with the base color // assuming bar was drawn with SimpleGradientBarPainter, this will be a flat color g2.setPaint(baseColor); g2.fill(area); // draw a brighter outline around the bar g2.setStroke(renderer.getBaseOutlineStroke()); g2.setPaint(baseColor.darker()); g2.draw(area); } } }