use of org.gephi.graph.api.GraphView in project gephi by gephi.
the class DynamicSettingsPanel method setup.
public void setup(DynamicStatistics dynamicStatistics) {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = graphController.getGraphModel();
TimeFormat timeFormat = graphModel.getTimeFormat();
// Bounds
GraphView currentView = graphModel.getVisibleView();
if (currentView.isMainView()) {
bounds = graphModel.getTimeBounds();
} else {
bounds = currentView.getTimeInterval();
}
String boundsStr = timeFormat.print(bounds.getLow()) + " - " + timeFormat.print(bounds.getHigh());
currentIntervalLabel.setText(boundsStr);
// TimeUnit
if (timeFormat.equals(TimeFormat.DOUBLE)) {
windowTimeUnitCombo.setVisible(false);
tickTimeUnitCombo.setVisible(false);
}
// Set latest selected item
if (!timeFormat.equals(TimeFormat.DOUBLE)) {
loadDefaultTimeUnits();
}
// Window and tick
double initValue = 0.;
if (bounds.getHigh() - bounds.getLow() > 1) {
initValue = 1.;
}
if (timeFormat.equals(TimeFormat.DOUBLE)) {
windowTextField.setText(initValue + "");
tickTextField.setText(initValue + "");
} else {
windowTextField.setText("" + windowTimeUnit.convert((long) initValue, TimeUnit.MILLISECONDS));
tickTextField.setText("" + tickTimeUnit.convert((long) initValue, TimeUnit.MILLISECONDS));
}
// Add listeners
windowTimeUnitCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getItem() != windowTimeUnitCombo.getSelectedItem()) {
refreshWindowTimeUnit();
}
}
});
tickTimeUnitCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getItem() != tickTimeUnitCombo.getSelectedItem()) {
refreshTickTimeUnit();
}
}
});
}
use of org.gephi.graph.api.GraphView in project gephi by gephi.
the class FilterControllerImpl method exportToLabelVisible.
@Override
public void exportToLabelVisible(Query query) {
Graph result;
if (model.getCurrentQuery() == query) {
GraphView view = model.getCurrentResult();
if (view == null) {
return;
}
result = model.getGraphModel().getGraph(view);
} else {
FilterProcessor processor = new FilterProcessor();
result = (Graph) processor.process((AbstractQueryImpl) query, model.getGraphModel());
}
Graph fullGraph = model.getGraphModel().getGraph();
fullGraph.writeLock();
try {
for (Node n : fullGraph.getNodes()) {
boolean inView = result.contains(n);
n.getTextProperties().setVisible(inView);
}
for (Edge e : fullGraph.getEdges()) {
boolean inView = result.contains(e);
e.getTextProperties().setVisible(inView);
}
} finally {
fullGraph.writeUnlock();
fullGraph.readUnlockAll();
}
}
use of org.gephi.graph.api.GraphView in project gephi by gephi.
the class FilterThread method select.
private void select(AbstractQueryImpl query) {
FilterProcessor processor = new FilterProcessor();
GraphModel graphModel = model.getGraphModel();
Graph result = processor.process((AbstractQueryImpl) query, graphModel);
if (running) {
VisualizationController visController = Lookup.getDefault().lookup(VisualizationController.class);
if (visController != null) {
visController.resetSelection();
visController.selectNodes(result.getNodes().toArray());
visController.selectEdges(result.getEdges().toArray());
}
GraphView view = result.getView();
model.setCurrentResult(view);
} else {
// destroy view
graphModel.destroyView(result.getView());
}
}
use of org.gephi.graph.api.GraphView in project gephi by gephi.
the class StatisticsControllerImpl method executeDynamic.
private void executeDynamic(DynamicStatistics statistics, DynamicLongTask dynamicLongTask) {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = graphController.getGraphModel();
double window = statistics.getWindow();
double tick = statistics.getTick();
GraphView currentView = graphModel.getVisibleView();
Interval bounds = statistics.getBounds();
if (bounds == null) {
if (currentView.isMainView()) {
bounds = graphModel.getTimeBounds();
} else {
bounds = currentView.getTimeInterval();
}
statistics.setBounds(bounds);
}
if (dynamicLongTask != null) {
// Count
int c = (int) ((bounds.getHigh() - window - bounds.getLow()) / tick);
dynamicLongTask.start(c);
}
// Init
statistics.execute(graphModel);
// Loop
for (double low = bounds.getLow(); low <= bounds.getHigh() - window; low += tick) {
double high = low + window;
Graph graph = graphModel.getGraphVisible();
graph.writeLock();
try {
GraphView view = graphModel.createView();
Subgraph g = graphModel.getGraph(view);
TimeIndex<Node> nodeIndex = graphModel.getNodeTimeIndex(currentView);
if (Double.isInfinite(nodeIndex.getMinTimestamp()) && Double.isInfinite(nodeIndex.getMaxTimestamp())) {
for (Node node : graph.getNodes()) {
g.addNode(node);
}
} else {
for (Node node : nodeIndex.get(new Interval(low, high))) {
g.addNode(node);
}
}
TimeIndex<Edge> edgeIndex = graphModel.getEdgeTimeIndex(currentView);
if (Double.isInfinite(edgeIndex.getMinTimestamp()) && Double.isInfinite(edgeIndex.getMaxTimestamp())) {
for (Edge edge : graph.getEdges()) {
if (g.contains(edge.getSource()) && g.contains(edge.getTarget())) {
g.addEdge(edge);
}
}
} else {
for (Edge edge : edgeIndex.get(new Interval(low, high))) {
if (g.contains(edge.getSource()) && g.contains(edge.getTarget())) {
g.addEdge(edge);
}
}
}
statistics.loop(g.getView(), new Interval(low, high));
} finally {
graph.writeUnlock();
graph.readUnlockAll();
}
// Cancelled?
if (dynamicLongTask != null && dynamicLongTask.isCancelled()) {
return;
} else if (dynamicLongTask != null) {
dynamicLongTask.progress();
}
}
statistics.end();
model.addReport(statistics);
}
use of org.gephi.graph.api.GraphView in project gephi by gephi.
the class FilterControllerImpl method exportToNewWorkspace.
@Override
public void exportToNewWorkspace(Query query) {
Graph result;
if (model.getCurrentQuery() == query) {
GraphView view = model.getCurrentResult();
if (view == null) {
return;
}
result = model.getGraphModel().getGraph(view);
} else {
FilterProcessor processor = new FilterProcessor();
GraphModel graphModel = model.getGraphModel();
result = (Graph) processor.process((AbstractQueryImpl) query, graphModel);
}
final Graph graphView = result;
new Thread(new Runnable() {
@Override
public void run() {
ProgressTicketProvider progressProvider = Lookup.getDefault().lookup(ProgressTicketProvider.class);
ProgressTicket ticket = null;
if (progressProvider != null) {
String msg = NbBundle.getMessage(FilterControllerImpl.class, "FilterController.exportToNewWorkspace.task");
ticket = progressProvider.createTicket(msg, null);
}
Progress.start(ticket);
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
Workspace newWorkspace = pc.newWorkspace(pc.getCurrentProject());
GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getGraphModel(newWorkspace);
graphModel.bridge().copyNodes(graphView.getNodes().toArray());
Graph graph = graphModel.getGraph();
List<Edge> edgesToRemove = new ArrayList<>();
for (Edge edge : graph.getEdges()) {
if (!graphView.hasEdge(edge.getId())) {
edgesToRemove.add(edge);
}
}
if (!edgesToRemove.isEmpty()) {
graph.removeAllEdges(edgesToRemove);
}
Progress.finish(ticket);
String workspaceName = newWorkspace.getLookup().lookup(WorkspaceInformation.class).getName();
// StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(FilterControllerImpl.class, "FilterController.exportToNewWorkspace.status", workspaceName));
}
}, "Export filter to workspace").start();
}
Aggregations