use of org.gephi.graph.api.GraphController in project gephi by gephi.
the class SearchReplaceControllerImpl method canReplace.
@Override
public boolean canReplace(SearchResult result) {
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
Table table;
Column column;
if (result.getFoundNode() != null) {
table = gc.getGraphModel().getNodeTable();
column = table.getColumn(result.getFoundColumnIndex());
} else {
table = gc.getGraphModel().getEdgeTable();
column = table.getColumn(result.getFoundColumnIndex());
}
return Lookup.getDefault().lookup(AttributeColumnsController.class).canChangeColumnData(column);
}
use of org.gephi.graph.api.GraphController in project gephi by gephi.
the class ShortestPath method getListeners.
@Override
public ToolEventListener[] getListeners() {
listeners = new ToolEventListener[2];
listeners[0] = new NodeClickEventListener() {
@Override
public void clickNodes(Node[] nodes) {
Node n = nodes[0];
if (sourceNode == null) {
sourceNode = n;
shortestPathPanel.setResult("");
shortestPathPanel.setStatus(NbBundle.getMessage(ShortestPath.class, "ShortestPath.status2"));
} else if (n != sourceNode) {
color = shortestPathPanel.getColor();
Node targetNode = n;
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
GraphModel gm = gc.getGraphModel();
AbstractShortestPathAlgorithm algorithm;
if (gm.isDirected()) {
algorithm = new BellmanFordShortestPathAlgorithm(gm.getDirectedGraphVisible(), sourceNode);
} else {
algorithm = new DijkstraShortestPathAlgorithm(gm.getGraphVisible(), sourceNode);
}
algorithm.compute();
double distance;
if ((distance = algorithm.getDistances().get(targetNode)) != Double.POSITIVE_INFINITY) {
targetNode.setColor(color);
VizController.getInstance().selectNode(targetNode);
Edge predecessorEdge = algorithm.getPredecessorIncoming(targetNode);
Node predecessor = algorithm.getPredecessor(targetNode);
while (predecessorEdge != null && predecessor != sourceNode) {
predecessorEdge.setColor(color);
VizController.getInstance().selectEdge(predecessorEdge);
predecessor.setColor(color);
VizController.getInstance().selectNode(predecessor);
predecessorEdge = algorithm.getPredecessorIncoming(predecessor);
predecessor = algorithm.getPredecessor(predecessor);
}
predecessorEdge.setColor(color);
VizController.getInstance().selectEdge(predecessorEdge);
sourceNode.setColor(color);
VizController.getInstance().selectNode(sourceNode);
shortestPathPanel.setResult(NbBundle.getMessage(ShortestPath.class, "ShortestPath.result", distance));
} else {
//No path
shortestPathPanel.setResult(NbBundle.getMessage(ShortestPath.class, "ShortestPath.noresult"));
}
sourceNode = null;
shortestPathPanel.setStatus(NbBundle.getMessage(ShortestPath.class, "ShortestPath.status1"));
}
}
};
listeners[1] = new MouseClickEventListener() {
@Override
public void mouseClick(int[] positionViewport, float[] position3d) {
if (sourceNode != null) {
//Cancel
shortestPathPanel.setStatus(NbBundle.getMessage(ShortestPath.class, "ShortestPath.status1"));
sourceNode = null;
} else {
VizController.getInstance().resetSelection();
}
}
};
return listeners;
}
use of org.gephi.graph.api.GraphController in project gephi by gephi.
the class NodePencil method getListeners.
@Override
public ToolEventListener[] getListeners() {
listeners = new ToolEventListener[1];
listeners[0] = new MouseClickEventListener() {
@Override
public void mouseClick(int[] positionViewport, float[] position3d) {
color = nodePencilPanel.getColor();
size = nodePencilPanel.getNodeSize();
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
GraphModel gm = gc.getGraphModel();
Graph graph = gm.getGraph();
Node node = gm.factory().newNode();
node.setX(position3d[0]);
node.setY(position3d[1]);
node.setSize(size);
node.setColor(color);
graph.addNode(node);
}
};
return listeners;
}
use of org.gephi.graph.api.GraphController in project gephi by gephi.
the class SearchReplaceControllerImpl method replace.
@Override
public SearchResult replace(SearchResult result, String replacement) {
if (result == null) {
throw new IllegalArgumentException();
}
if (!canReplace(result)) {
//Go to next search result
return findNext(result);
}
GraphController gc = Lookup.getDefault().lookup(GraphController.class);
Object value;
String str;
Element attributes;
Column column;
if (!result.getSearchOptions().isUseRegexReplaceMode()) {
//Avoid using groups and other regex aspects in the replacement
replacement = Matcher.quoteReplacement(replacement);
}
try {
//Get value to re-match and replace:
if (result.getFoundNode() != null) {
attributes = result.getFoundNode();
column = gc.getGraphModel().getNodeTable().getColumn(result.getFoundColumnIndex());
} else {
attributes = result.getFoundEdge();
column = gc.getGraphModel().getEdgeTable().getColumn(result.getFoundColumnIndex());
}
GraphModel graphModel = column.getTable().getGraph().getModel();
TimeFormat timeFormat = graphModel.getTimeFormat();
DateTimeZone timeZone = graphModel.getTimeZone();
value = attributes.getAttribute(column);
str = value != null ? AttributeUtils.print(value, timeFormat, timeZone) : "";
StringBuffer sb = new StringBuffer();
//Match and replace the result:
Matcher matcher = result.getSearchOptions().getRegexPattern().matcher(str.substring(result.getStart()));
if (matcher.find()) {
matcher.appendReplacement(sb, replacement);
int replaceLong = sb.length();
matcher.appendTail(sb);
str = str.substring(0, result.getStart()) + sb.toString();
result.getSearchOptions().setRegionStart(result.getStart() + replaceLong);
Lookup.getDefault().lookup(AttributeColumnsController.class).setAttributeValue(str, attributes, column);
//Go to next search result
return findNext(result);
} else {
//Go to next search result
return findNext(result);
}
} catch (Exception ex) {
if (ex instanceof IndexOutOfBoundsException) {
//Rethrow the exception when it is caused by a bad regex replacement
throw new IndexOutOfBoundsException();
}
//Go to next search result
return findNext(result);
}
}
use of org.gephi.graph.api.GraphController in project gephi by gephi.
the class ExporterGML method execute.
@Override
public boolean execute() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
graphModel = graphController.getGraphModel(workspace);
Graph graph = exportVisible ? graphModel.getGraphVisible() : graphModel.getGraph();
Progress.start(progressTicket, graph.getNodeCount() + graph.getEdgeCount());
graph.readLock();
try {
if (normalize) {
computeNormalizeValues(graph);
}
exportData(graph);
} catch (IOException e) {
Logger.getLogger(ExporterGML.class.getName()).log(Level.SEVERE, null, e);
} finally {
graph.readUnlock();
Progress.finish(progressTicket);
}
return !cancel;
}
Aggregations