2
Copyright 2008-2010 Gephi
3
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
4
Website : http://www.gephi.org
6
This file is part of Gephi.
8
Gephi is free software: you can redistribute it and/or modify
9
it under the terms of the GNU Affero General Public License as
10
published by the Free Software Foundation, either version 3 of the
11
License, or (at your option) any later version.
13
Gephi is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU Affero General Public License for more details.
18
You should have received a copy of the GNU Affero General Public License
19
along with Gephi. If not, see <http://www.gnu.org/licenses/>.
21
package org.gephi.filters;
23
import java.util.concurrent.atomic.AtomicBoolean;
24
import org.gephi.graph.api.GraphEvent;
25
import org.gephi.graph.api.GraphListener;
26
import org.gephi.graph.api.GraphModel;
27
import org.openide.util.Exceptions;
31
* @author Mathieu Bastian
33
public class FilterAutoRefreshor extends Thread implements GraphListener {
35
private static final int TIMER = 1000;
36
private final GraphModel graphModel;
37
private final FilterModelImpl filterModel;
38
private boolean running = true;
39
private AtomicBoolean refresh = new AtomicBoolean(false);
41
public FilterAutoRefreshor(FilterModelImpl filterModel, GraphModel graphModel) {
42
super("Filter Auto-Refresh");
44
this.graphModel = graphModel;
45
this.filterModel = filterModel;
52
if (refresh.compareAndSet(true, false)) {
56
} catch (InterruptedException ex) {
57
Exceptions.printStackTrace(ex);
62
public void setEnable(boolean enable) {
64
graphModel.addGraphListener(this);
66
graphModel.removeGraphListener(this);
74
public void graphChanged(GraphEvent event) {
75
if (event.getSource().isMainView() && event.is(GraphEvent.EventType.ADD_EDGES,
76
GraphEvent.EventType.ADD_NODES,
77
GraphEvent.EventType.MOVE_NODES,
78
GraphEvent.EventType.REMOVE_EDGES,
79
GraphEvent.EventType.REMOVE_NODES)) {
81
//System.out.println("set refresh true");
85
public void setRunning(boolean running) {
86
this.running = running;
88
graphModel.removeGraphListener(this);
93
public void manualRefresh() {
94
if (filterModel.getFilterThread() != null && filterModel.getCurrentQuery() != null) {
95
filterModel.getFilterThread().setRootQuery((AbstractQueryImpl) filterModel.getCurrentQuery());