org.jfree.data.category.CategoryDatasetSelectionState Java Examples

The following examples show how to use org.jfree.data.category.CategoryDatasetSelectionState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CategoryPlot.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Clears the selection.
 *
 * @since 1.2.0
 */
public void clearSelection() {
    // cycle through the datasets and clear the selection state
    int datasetCount = this.datasets.size();
    for (int d = 0; d < datasetCount; d++) {
        CategoryDataset dataset = (CategoryDataset) this.datasets.get(d);
        if (dataset instanceof SelectableCategoryDataset) {
            // FIXME:  actually, we need to get the selection state
            // taking into account the rendering source
            SelectableCategoryDataset scd
                    = (SelectableCategoryDataset) dataset;
            if (scd.getSelectionState() != null) {
                CategoryDatasetSelectionState selState
                        = scd.getSelectionState();
                selState.clearSelection();
            }
        }
    }
}
 
Example #2
Source File: CategoryPlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Perform a select for the item(s) at the specified (x, y) coordinates
 * in Java2D space.
 *
 * @param x  the x-coordinate.
 * @param y  the y-coordinate.
 * @param dataArea  the data area.
 * @param source  the rendering source.
 *
 * @since 1.2.0
 */
public void select(double x, double y, Rectangle2D dataArea,
        RenderingSource source) {

    int datasetCount = this.datasets.size();
    for (int d = 0; d < datasetCount; d++) {
        CategoryDataset dataset = (CategoryDataset) this.datasets.get(d);
        if (dataset == null) {
            continue;
        }
        CategoryDatasetSelectionState state = findSelectionStateForDataset(
                dataset, source);
        if (state == null) {
            continue;
        }
        Graphics2D g2 = source.createGraphics2D();
        CategoryItemRenderer renderer = getRendererForDataset(dataset);
        CategoryItemRendererState rs = renderer.initialise(g2, dataArea,
                this, dataset, null);
        int rowCount = dataset.getRowCount();
        int columnCount = dataset.getColumnCount();
        for (int r = 0; r < rowCount; r++) {
            for (int c = 0; c < columnCount; c++) {
                if (renderer.hitTest(x, y, null, dataArea, this,
                        getDomainAxisForDataset(d),
                        getRangeAxisForDataset(d), dataset, r, c, false,
                        rs)) {
                    state.setSelected(r, c, !state.isSelected(r, c));
                }
            }
        }
    }
}
 
Example #3
Source File: CategoryPlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the selection state for the specified dataset.  This could be
 * <code>null</code> if the dataset hasn't been set up to support
 * selections.
 *
 * @param dataset  the dataset.
 * @param source  the selection source.
 *
 * @return The selection state (possibly <code>null</code>).
 */
private CategoryDatasetSelectionState findSelectionStateForDataset(
        CategoryDataset dataset, Object source) {
    if (dataset instanceof SelectableCategoryDataset) {
        SelectableCategoryDataset sd = (SelectableCategoryDataset) dataset;
        CategoryDatasetSelectionState s = sd.getSelectionState();
        return s;
    }
    throw new RuntimeException();
    //return null;  // TODO: implement
}
 
Example #4
Source File: CategoryItemRendererState.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the selection state.
 *
 * @return The selection state (possibly <code>null</code>).
 *
 * @since 1.2.0
 */
public CategoryDatasetSelectionState getSelectionState() {
    return this.selectionState;
}
 
Example #5
Source File: CategoryItemRendererState.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets the selection state.
 *
 * @param state  the selection state (<code>null</code> permitted).
 *
 * @since 1.2.0
 */
public void setSelectionState(CategoryDatasetSelectionState state) {
    this.selectionState = state;
}