Search in sources :

Example 1 with Range

use of org.gephi.filters.api.Range 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 }));
                }
            }
        }
    }
}
Also used : Query(org.gephi.filters.api.Query) DynamicRangeFilter(org.gephi.filters.plugin.dynamic.DynamicRangeBuilder.DynamicRangeFilter) FilterBuilder(org.gephi.filters.spi.FilterBuilder) Range(org.gephi.filters.api.Range) DynamicRangeBuilder(org.gephi.filters.plugin.dynamic.DynamicRangeBuilder)

Example 2 with Range

use of org.gephi.filters.api.Range in project gephi by gephi.

the class FilterProcessor method init.

public boolean init(Filter filter, Graph graph) {
    boolean res = true;
    // Init res
    if (filter instanceof NodeFilter) {
        res = ((NodeFilter) filter).init(graph);
    } else if (filter instanceof EdgeFilter) {
        res = ((EdgeFilter) filter).init(graph);
    }
    // Range
    if (filter instanceof RangeFilter) {
        RangeFilter rangeFilter = (RangeFilter) filter;
        Number[] values = rangeFilter.getValues(graph);
        NumberComparator comparator = new NumberComparator();
        Number min = null;
        Number max = null;
        if (values != null) {
            for (Number n : values) {
                min = min == null ? n : comparator.min(min, n);
                max = max == null ? n : comparator.max(max, n);
            }
        }
        Range previousRange = (Range) rangeFilter.getRangeProperty().getValue();
        Range newRange;
        if (min == null || max == null) {
            newRange = null;
            rangeFilter.getRangeProperty().setValue(newRange);
        } else if (previousRange == null) {
            newRange = new Range(min, max, min, max, values);
            rangeFilter.getRangeProperty().setValue(newRange);
        } else if (previousRange != null && (previousRange.getMinimum() == null || previousRange.getMaximum() == null)) {
            // Opening projects
            newRange = new Range(previousRange.getLowerBound(), previousRange.getUpperBound(), min, max, previousRange.isLeftInclusive(), previousRange.isRightInclusive(), values);
            rangeFilter.getRangeProperty().setValue(newRange);
        } else {
            // Collect some info
            boolean stickyLeft = previousRange.getMinimum().equals(previousRange.getLowerBound());
            boolean stickyRight = previousRange.getMaximum().equals(previousRange.getUpperBound());
            Number lowerBound = previousRange.getLowerBound();
            Number upperBound = previousRange.getUpperBound();
            // The inteval grows on the right
            if (stickyRight && comparator.superior(max, upperBound)) {
                upperBound = max;
            }
            // The interval grows on the left
            if (stickyLeft && comparator.inferior(min, lowerBound)) {
                lowerBound = min;
            }
            // The interval shrinks on the right
            if (comparator.superior(upperBound, max)) {
                upperBound = max;
            }
            // The interval shrinks on the left
            if (comparator.inferior(lowerBound, min)) {
                lowerBound = min;
            }
            newRange = new Range(lowerBound, upperBound, min, max, previousRange.isLeftInclusive(), previousRange.isRightInclusive(), values);
            if (!newRange.equals(previousRange)) {
                rangeFilter.getRangeProperty().setValue(newRange);
            }
        }
    }
    return res;
}
Also used : Range(org.gephi.filters.api.Range)

Example 3 with Range

use of org.gephi.filters.api.Range in project gephi by gephi.

the class RangePanel method setup.

public void setup(final RangeFilter rangeFilter) {
    this.filter = rangeFilter;
    final Range range = (Range) rangeFilter.getRangeProperty().getValue();
    if (range == null) {
    // Do nothing
    } else {
        new Thread(new Runnable() {

            @Override
            public void run() {
                final JRangeSliderPanel rangeSlider = (JRangeSliderPanel) rangeSliderPanel;
                values = range.getValues();
                rangeSlider.addPropertyChangeListener(new PropertyChangeListener() {

                    @Override
                    public void propertyChange(PropertyChangeEvent evt) {
                        try {
                            if (evt.getPropertyName().equals(JRangeSliderPanel.LOWER_BOUND)) {
                                Range oldRange = (Range) filter.getRangeProperty().getValue();
                                final Range newRange = new Range((Number) rangeSlider.getRange().getLowerBound(), (Number) rangeSlider.getRange().getUpperBound(), oldRange.getMinimum(), oldRange.getMaximum(), oldRange.getValues());
                                if (!oldRange.equals(newRange)) {
                                    filter.getRangeProperty().setValue(newRange);
                                    new Thread(new Runnable() {

                                        @Override
                                        public void run() {
                                            setupHistogram(filter, newRange);
                                        }
                                    }).start();
                                }
                            } else if (evt.getPropertyName().equals(JRangeSliderPanel.UPPER_BOUND)) {
                                final Range oldRange = (Range) filter.getRangeProperty().getValue();
                                final Range newRange = new Range((Number) rangeSlider.getRange().getLowerBound(), (Number) rangeSlider.getRange().getUpperBound(), oldRange.getMinimum(), oldRange.getMaximum(), oldRange.getValues());
                                if (!oldRange.equals(newRange)) {
                                    filter.getRangeProperty().setValue(newRange);
                                    new Thread(new Runnable() {

                                        @Override
                                        public void run() {
                                            setupHistogram(filter, newRange);
                                        }
                                    }).start();
                                }
                            }
                        } catch (Exception e) {
                            Logger.getLogger("").log(Level.SEVERE, "Error with range slider", e);
                        }
                    }
                });
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        rangeSlider.setRange(JRangeSliderPanel.Range.build(rangeSlider, range.getMinimum(), range.getMaximum(), range.getLowerBound(), range.getUpperBound()));
                    }
                });
                setupHistogram(rangeFilter, range);
            }
        }).start();
    }
// Tooltip
/*
         * histogram.getPanel().addMouseListener(new MouseAdapter() {
         *
         * RichTooltip richTooltip;
         *
         * @Override public void mouseEntered(MouseEvent e) { new Thread(new
         * Runnable() {
         *
         * public void run() { richTooltip = buildTooltip();
         *
         * SwingUtilities.invokeLater(new Runnable() {
         *
         * public void run() { if (richTooltip != null) {
         * richTooltip.showTooltip(histogram.getPanel()); } } }); } }).start();
         * }
         *
         * @Override public void mouseExited(MouseEvent e) { if (richTooltip !=
         * null) { richTooltip.hideTooltip(); richTooltip = null; } } });
         */
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) Range(org.gephi.filters.api.Range) JRangeSliderPanel(org.gephi.ui.components.JRangeSliderPanel)

Aggregations

Range (org.gephi.filters.api.Range)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 Query (org.gephi.filters.api.Query)1 DynamicRangeBuilder (org.gephi.filters.plugin.dynamic.DynamicRangeBuilder)1 DynamicRangeFilter (org.gephi.filters.plugin.dynamic.DynamicRangeBuilder.DynamicRangeFilter)1 FilterBuilder (org.gephi.filters.spi.FilterBuilder)1 JRangeSliderPanel (org.gephi.ui.components.JRangeSliderPanel)1