/** * Handles mouse clicks in the chart panel. * * @param event the chart mouse event */ private void mouseClickedInChart(ChartMouseEvent event) { ArrayList<ChartEntity> entities = getEntitiesForPoint(event.getTrigger().getPoint().x, event.getTrigger().getPoint().y); if (entities.isEmpty()) { return; } boolean dataPointFound = false; String dataPointTooltip = ""; for (ChartEntity tempEntity : entities) { if (tempEntity instanceof XYAnnotationEntity) { if (((XYAnnotationEntity) tempEntity).getToolTipText() != null) { dataPointFound = true; dataPointTooltip = ((XYAnnotationEntity) tempEntity).getToolTipText(); } } } if (dataPointFound) { String dataset = tooltipToDatasetMap.get(dataPointTooltip); JOptionPane.showMessageDialog(this, dataPointTooltip + ":\n" + vennDiagramResults.get(dataset), "Selected Values", JOptionPane.INFORMATION_MESSAGE); } }
/** * Handles mouse movements in the chart panel. * * @param event the chart mouse event */ private void mouseMovedInChart(ChartMouseEvent event) { ArrayList<ChartEntity> entities = getEntitiesForPoint(event.getTrigger().getPoint().x, event.getTrigger().getPoint().y); boolean dataPointFound = false; for (ChartEntity tempEntity : entities) { if (tempEntity instanceof XYAnnotationEntity) { if (((XYAnnotationEntity) tempEntity).getToolTipText() != null) { dataPointFound = true; } } } if (dataPointFound) { chartPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); } else { chartPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); } }
/** * A utility method for adding an {@link XYAnnotationEntity} to * a {@link PlotRenderingInfo} instance. * * @param info the plot rendering info (<code>null</code> permitted). * @param hotspot the hotspot area. * @param rendererIndex the renderer index. * @param toolTipText the tool tip text. * @param urlText the URL text. */ protected void addEntity(PlotRenderingInfo info, Shape hotspot, int rendererIndex, String toolTipText, String urlText) { if (info == null) { return; } EntityCollection entities = info.getOwner().getEntityCollection(); if (entities == null) { return; } XYAnnotationEntity entity = new XYAnnotationEntity(hotspot, rendererIndex, toolTipText, urlText); entities.add(entity); }
/** * A utility method for adding an {@link XYAnnotationEntity} to * a {@link PlotRenderingInfo} instance. * * @param info the plot rendering info ({@code null} permitted). * @param hotspot the hotspot area. * @param rendererIndex the renderer index. * @param toolTipText the tool tip text. * @param urlText the URL text. */ protected void addEntity(PlotRenderingInfo info, Shape hotspot, int rendererIndex, String toolTipText, String urlText) { if (info == null) { return; } EntityCollection entities = info.getOwner().getEntityCollection(); if (entities == null) { return; } XYAnnotationEntity entity = new XYAnnotationEntity(hotspot, rendererIndex, toolTipText, urlText); entities.add(entity); }
/** * 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; }