Search in sources :

Example 11 with GraphController

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);
}
Also used : Table(org.gephi.graph.api.Table) Column(org.gephi.graph.api.Column) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) GraphController(org.gephi.graph.api.GraphController)

Example 12 with GraphController

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;
}
Also used : MouseClickEventListener(org.gephi.tools.spi.MouseClickEventListener) Node(org.gephi.graph.api.Node) DijkstraShortestPathAlgorithm(org.gephi.algorithms.shortestpath.DijkstraShortestPathAlgorithm) AbstractShortestPathAlgorithm(org.gephi.algorithms.shortestpath.AbstractShortestPathAlgorithm) BellmanFordShortestPathAlgorithm(org.gephi.algorithms.shortestpath.BellmanFordShortestPathAlgorithm) GraphModel(org.gephi.graph.api.GraphModel) NodeClickEventListener(org.gephi.tools.spi.NodeClickEventListener) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController)

Example 13 with GraphController

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;
}
Also used : MouseClickEventListener(org.gephi.tools.spi.MouseClickEventListener) Graph(org.gephi.graph.api.Graph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) GraphController(org.gephi.graph.api.GraphController)

Example 14 with GraphController

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);
    }
}
Also used : TimeFormat(org.gephi.graph.api.TimeFormat) Matcher(java.util.regex.Matcher) Element(org.gephi.graph.api.Element) DateTimeZone(org.joda.time.DateTimeZone) Column(org.gephi.graph.api.Column) GraphModel(org.gephi.graph.api.GraphModel) AttributeColumnsController(org.gephi.datalab.api.AttributeColumnsController) GraphController(org.gephi.graph.api.GraphController)

Example 15 with GraphController

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;
}
Also used : Graph(org.gephi.graph.api.Graph) IOException(java.io.IOException) GraphController(org.gephi.graph.api.GraphController)

Aggregations

GraphController (org.gephi.graph.api.GraphController)28 GraphModel (org.gephi.graph.api.GraphModel)19 Graph (org.gephi.graph.api.Graph)12 Node (org.gephi.graph.api.Node)9 Edge (org.gephi.graph.api.Edge)7 Column (org.gephi.graph.api.Column)5 TimeFormat (org.gephi.graph.api.TimeFormat)4 MouseClickEventListener (org.gephi.tools.spi.MouseClickEventListener)3 NodeClickEventListener (org.gephi.tools.spi.NodeClickEventListener)3 ArrayList (java.util.ArrayList)2 AbstractShortestPathAlgorithm (org.gephi.algorithms.shortestpath.AbstractShortestPathAlgorithm)2 BellmanFordShortestPathAlgorithm (org.gephi.algorithms.shortestpath.BellmanFordShortestPathAlgorithm)2 DijkstraShortestPathAlgorithm (org.gephi.algorithms.shortestpath.DijkstraShortestPathAlgorithm)2 AttributeColumnsController (org.gephi.datalab.api.AttributeColumnsController)2 GraphFactory (org.gephi.graph.api.GraphFactory)2 GraphView (org.gephi.graph.api.GraphView)2 DynamicStatistics (org.gephi.statistics.spi.DynamicStatistics)2 NotifyDescriptor (org.openide.NotifyDescriptor)2 Color (java.awt.Color)1 Font (java.awt.Font)1