ComponentHandle
objects contain relevant information about the selected component.
For example, a DataComponentHandle
identifies the group and series of the selected
graph component, or the row and column of a selected cell in a table or crosstab.
You can get more detailed information by calling the getComponentInfo
method of
the ComponentHandle
. The ComponentHandle
returns a
ComponentInfo
object that is specific to the ComponentHandle
. For
example, a DataComponentHandle
returns a DataComponentInfo
.
The ComponentInfo
object specifically provides access to information
about the data that the component represents. Depending on what the DataAccess
that provides data to the view supports, you can call methods of the ComponentInfo
to get information about selected component.
The following code shows how you might use information about the ComponentHandle
as you program a graph.
class GraphMouseListener extends ViewMouseListenerAdapter { DataAccess graphData; // for getting slice labels public GraphMouseListener(Graph graph){ graphData = graph.getGraphModel().getDataAccess(); if (graphData == null){ System.out.println("No data access"); } } // constructor public void mouseClicked(ViewMouseEvent e){ ComponentHandle handle = e.getComponentHandle(); if (handle instanceof NonDataComponentHandle){ System.out.println("No data associated with the selected component."); } else{ int seriesSlice = -1; int groupSlice = -1; if (handle instanceof DataComponentHandle){ seriesSlice = ((DataComponentHandle)handle).getSeries(); System.out.println("Series: " + seriesSlice); groupSlice = ((DataComponentHandle)handle).getGroup(); System.out.println("Group: " + groupSlice); } if (handle instanceof SeriesComponentHandle){ seriesSlice = ((SeriesComponentHandle)handle).getSeries(); System.out.println("Series: " + seriesSlice); } if (handle instanceof GroupComponentHandle){ groupSlice = ((GroupComponentHandle)handle).getGroup(); System.out.println("Group: " + groupSlice); } // get the labels Object label; // assumes graph.isDataRowShownAsASeries returns true // if it returns false, then pass // DataDirector.COLUMN_EDGE for series labels // and DataDirector.ROW_EDGE for group labels try{ // if the DataAccess supports it, you can // pass MetadataMap.METADATA_VALUE to get the actual value if (seriesSlice >= 0){ label = graphData.getSliceLabel(DataDirector.ROW_EDGE, seriesSlice, MetadataMap.METADATA_SHORTLABEL); System.out.println(label); } if (groupSlice >= 0){ label = graphData.getSliceLabel(DataDirector.COLUMN_EDGE, groupSlice, MetadataMap.METADATA_SHORTLABEL); System.out.println(label); } } catch (SliceOutOfRangeException ex){ System.out.println("wrong series"); } catch (EdgeOutOfRangeException exedge){ System.out.println("wrong edge"); } } // end else } // end mouseClicked } // end class GraphMouseListener
Component Handles for Graphs
Component Handles for Tables and Crosstabs