use of org.gephi.filters.plugin.dynamic.DynamicRangeBuilder in project gephi by gephi.
the class TimelineControllerImpl method setInterval.
@Override
public void setInterval(double from, double to) {
if (model != null) {
if (model.getIntervalStart() != from || model.getIntervalEnd() != to) {
if (from >= to) {
throw new IllegalArgumentException("from should be less than to");
}
if (!(Double.isInfinite(from) && Double.isInfinite(to))) {
if (from < model.getCustomMin() || to > model.getCustomMax()) {
throw new IllegalArgumentException("From and to should be in the bounds");
}
}
model.setInterval(from, to);
// Filter magic
Query dynamicQuery = null;
boolean selecting = false;
// Get or create Dynamic Query
if (filterModel.getCurrentQuery() != null) {
// Look if current query is dynamic - filtering must be active
Query query = filterModel.getCurrentQuery();
Query[] dynamicQueries = query.getQueries(DynamicRangeFilter.class);
if (dynamicQueries.length > 0) {
dynamicQuery = query;
selecting = filterModel.isSelecting();
}
} else if (filterModel.getQueries().length == 1) {
// Look if a dynamic query alone exists
Query query = filterModel.getQueries()[0];
Query[] dynamicQueries = query.getQueries(DynamicRangeFilter.class);
if (dynamicQueries.length > 0) {
dynamicQuery = query;
}
}
if (Double.isInfinite(from) && Double.isInfinite(to)) {
if (dynamicQuery != null) {
filterController.remove(dynamicQuery);
}
} else {
if (dynamicQuery == null) {
// Create dynamic filter
DynamicRangeBuilder rangeBuilder = filterModel.getLibrary().getLookup().lookup(DynamicRangeBuilder.class);
FilterBuilder[] fb = rangeBuilder.getBuilders(filterModel.getWorkspace());
if (fb.length > 0) {
dynamicQuery = filterController.createQuery(fb[0]);
filterController.add(dynamicQuery);
}
}
if (dynamicQuery != null) {
dynamicQuery.getFilter().getProperties()[0].setValue(new Range(from, to));
if (selecting) {
filterController.selectVisible(dynamicQuery);
} else {
filterController.filterVisible(dynamicQuery);
}
fireTimelineModelEvent(new TimelineModelEvent(TimelineModelEvent.EventType.INTERVAL, model, new double[] { from, to }));
}
}
}
}
}
Aggregations