I needed a way to make Axes and TextTitles "clickable" in a GUI, i.e. when the user clicks on the area occupied by an area or title, it should be possible to get a reference to the object and open a dialog for editing purposes.
The most obvious way was to create entities and have them added to the EntityCollection included in the ChartRenderingInfo of the ChartPanel.
While an entity is already created for TextTitles, it is an instance of ChartEntity, i.e. it is not possible to get a reference to the TextTitle that occupies the area of the entity. Entity support for Axes was completely missing.
The patch includes sthe following:
- two new classes AxisEntity and TitleEntity which simply extend ChartEntity and hold a reference to an Axis or a Title.
- Change to TextTitle.draw(Graphics2D,Rectangle2D, Object): creates a TitleEntity instead of a ChartEntity
- Changes to Axis: new method protected void createAndAddEntity(double cursor, AxisState state, Rectangle2D dataArea, RectangleEdge edge, PlotRenderingInfo plotState): gets an EntityCollection from the owner of the plotState and adds an AxisEntity with a rectangular hotspot.
- Changes to NumberAxis, DateAxis, LogAxis, CategoryAxis: call Axis.createAndAddEntity(...) in their draw-methods.
diff file against 1.0.12
Extended DIff
Extended vesion:
new classes: JFreeChartEntity, PlotEntity
one instance of each class will be added to the EntityCollection. The contain references to the chart/plot and use clones of the chart area and data area, respectively.
Change to LegendTitle: a TitleEntity is created that uses the original area. The TitleEntity is created before the LegendItemEntities. Thus, the LegendItemEntities will cover most of the space of the TitleEntity, but clicking at the edges of the LegendTitle should give the TitleEntity back.
File Added: AxisAndTitleEntities.diff
Nice work. I've committed your changes to Subversion for inclusion in the 1.0.13 release.
Best regards,
Dave Gilbert
JFreeChart Project Leader