Search in sources :

Example 16 with GraphController

use of org.gephi.graph.api.GraphController in project gephi by gephi.

the class FilterModelPersistenceProvider method readQuery.

private Query readQuery(XMLStreamReader reader, FilterModelImpl model) throws XMLStreamException {
    String builderClassName = reader.getAttributeValue(null, "builder");
    String filterClassName = reader.getAttributeValue(null, "filter");
    FilterBuilder builder = null;
    for (FilterBuilder fb : model.getLibrary().getLookup().lookupAll(FilterBuilder.class)) {
        if (fb.getClass().getName().equals(builderClassName)) {
            if (filterClassName != null) {
                if (fb.getFilter(model.getWorkspace()).getClass().getName().equals(filterClassName)) {
                    builder = fb;
                    break;
                }
            } else {
                builder = fb;
                break;
            }
        }
    }
    if (builder == null) {
        for (CategoryBuilder catBuilder : Lookup.getDefault().lookupAll(CategoryBuilder.class)) {
            for (FilterBuilder fb : catBuilder.getBuilders(model.getWorkspace())) {
                if (fb.getClass().getName().equals(builderClassName)) {
                    if (filterClassName != null) {
                        if (fb.getFilter(model.getWorkspace()).getClass().getName().equals(filterClassName)) {
                            builder = fb;
                            break;
                        }
                    } else {
                        builder = fb;
                        break;
                    }
                }
            }
        }
    }
    if (builder != null) {
        //Create filter
        Filter filter = builder.getFilter(model.getWorkspace());
        Query query;
        if (filter instanceof Operator) {
            query = new OperatorQueryImpl((Operator) filter);
        } else {
            query = new FilterQueryImpl(builder, filter);
        }
        FilterProperty property = null;
        boolean end = false;
        while (reader.hasNext() && !end) {
            Integer eventType = reader.next();
            if (eventType.equals(XMLEvent.START_ELEMENT)) {
                String name = reader.getLocalName();
                if ("parameter".equalsIgnoreCase(name)) {
                    int index = Integer.parseInt(reader.getAttributeValue(null, "index"));
                    property = query.getFilter().getProperties()[index];
                }
            } else if (eventType.equals(XMLStreamReader.CHARACTERS) && property != null) {
                try {
                    PropertyEditor editor = property.getPropertyEditor();
                    if (editor == null) {
                        editor = PropertyEditorManager.findEditor(property.getValueType());
                    }
                    if (editor != null) {
                        String textValue = reader.getText();
                        if (editor instanceof AttributeColumnPropertyEditor) {
                            GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                            GraphModel graphModel = gc.getGraphModel(model.getWorkspace());
                            ((AttributeColumnPropertyEditor) editor).setGraphModel(graphModel);
                        }
                        editor.setAsText(textValue);
                        property.setValue(editor.getValue());
                        model.updateParameters(query);
                        if (editor instanceof AttributeColumnPropertyEditor) {
                            ((AttributeColumnPropertyEditor) editor).setGraphModel(null);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else if (eventType.equals(XMLStreamReader.END_ELEMENT)) {
                property = null;
                if ("query".equalsIgnoreCase(reader.getLocalName())) {
                    end = true;
                }
            }
        }
        return query;
    }
    return null;
}
Also used : Query(org.gephi.filters.api.Query) XMLStreamException(javax.xml.stream.XMLStreamException) GraphModel(org.gephi.graph.api.GraphModel) PropertyEditor(java.beans.PropertyEditor) GraphController(org.gephi.graph.api.GraphController)

Example 17 with GraphController

use of org.gephi.graph.api.GraphController in project gephi by gephi.

the class EdgePencil method updatePanel.

private void updatePanel() {
    if (edgePencilPanel != null) {
        GraphController gc = Lookup.getDefault().lookup(GraphController.class);
        if (gc.getGraphModel() != null) {
            edgePencilPanel.setType(gc.getGraphModel().isDirected() || gc.getGraphModel().isMixed());
        }
        sourceNode = null;
        edgePencilPanel.setStatus(NbBundle.getMessage(EdgePencil.class, "EdgePencil.status1"));
    }
}
Also used : GraphController(org.gephi.graph.api.GraphController)

Example 18 with GraphController

use of org.gephi.graph.api.GraphController in project gephi by gephi.

the class HeatMap method getListeners.

@Override
public ToolEventListener[] getListeners() {
    listeners = new ToolEventListener[1];
    listeners[0] = new NodeClickEventListener() {

        @Override
        public void clickNodes(Node[] nodes) {
            try {
                Node n = nodes[0];
                Color[] colors;
                float[] positions;
                if (heatMapPanel.isUsePalette()) {
                    colors = heatMapPanel.getSelectedPalette().getColors();
                    positions = heatMapPanel.getSelectedPalette().getPositions();
                    dontPaintUnreachable = true;
                } else {
                    gradientColors = colors = heatMapPanel.getGradientColors();
                    gradientPositions = positions = heatMapPanel.getGradientPositions();
                    dontPaintUnreachable = heatMapPanel.isDontPaintUnreachable();
                }
                GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                AbstractShortestPathAlgorithm algorithm;
                if (gc.getGraphModel().isDirected()) {
                    DirectedGraph graph = gc.getGraphModel().getDirectedGraphVisible();
                    algorithm = new BellmanFordShortestPathAlgorithm(graph, n);
                    algorithm.compute();
                } else {
                    Graph graph = gc.getGraphModel().getGraphVisible();
                    algorithm = new DijkstraShortestPathAlgorithm(graph, n);
                    algorithm.compute();
                }
                //Color
                LinearGradient linearGradient = new LinearGradient(colors, positions);
                //Algorithm
                double maxDistance = algorithm.getMaxDistance();
                if (!dontPaintUnreachable) {
                    //+1 to have the maxdistance nodes a ratio<1
                    maxDistance++;
                }
                if (maxDistance > 0) {
                    for (Entry<Node, Double> entry : algorithm.getDistances().entrySet()) {
                        Node node = entry.getKey();
                        if (!Double.isInfinite(entry.getValue())) {
                            float ratio = (float) (entry.getValue() / maxDistance);
                            Color c = linearGradient.getValue(ratio);
                            node.setColor(c);
                        } else if (!dontPaintUnreachable) {
                            Color c = colors[colors.length - 1];
                            node.setColor(c);
                        }
                    }
                }
                Color c = colors[0];
                n.setColor(c);
                heatMapPanel.setStatus(NbBundle.getMessage(HeatMap.class, "HeatMap.status.maxdistance") + new DecimalFormat("#.##").format(algorithm.getMaxDistance()));
            } catch (Exception e) {
                Logger.getLogger("").log(Level.SEVERE, "", e);
            }
        }
    };
    return listeners;
}
Also used : Node(org.gephi.graph.api.Node) Color(java.awt.Color) DecimalFormat(java.text.DecimalFormat) DijkstraShortestPathAlgorithm(org.gephi.algorithms.shortestpath.DijkstraShortestPathAlgorithm) AbstractShortestPathAlgorithm(org.gephi.algorithms.shortestpath.AbstractShortestPathAlgorithm) BellmanFordShortestPathAlgorithm(org.gephi.algorithms.shortestpath.BellmanFordShortestPathAlgorithm) LinearGradient(org.gephi.ui.utils.GradientUtils.LinearGradient) Entry(java.util.Map.Entry) DirectedGraph(org.gephi.graph.api.DirectedGraph) Graph(org.gephi.graph.api.Graph) DirectedGraph(org.gephi.graph.api.DirectedGraph) NodeClickEventListener(org.gephi.tools.spi.NodeClickEventListener) GraphController(org.gephi.graph.api.GraphController)

Example 19 with GraphController

use of org.gephi.graph.api.GraphController in project gephi by gephi.

the class DefaultProcessor method process.

protected void process(ContainerUnloader container, Workspace workspace) {
    //Architecture
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    graphModel = graphController.getGraphModel(workspace);
    //Get graph
    Graph graph = graphModel.getGraph();
    GraphFactory factory = graphModel.factory();
    //Time Format & Time zone
    graphModel.setTimeFormat(container.getTimeFormat());
    graphModel.setTimeZone(container.getTimeZone());
    //Progress
    Progress.start(progressTicket, container.getNodeCount() + container.getEdgeCount());
    //Attributes - Creates columns for properties
    flushColumns(container);
    //Counters
    int addedNodes = 0, addedEdges = 0;
    //Create all nodes
    ElementIdType elementIdType = container.getElementIdType();
    for (NodeDraft draftNode : container.getNodes()) {
        String idString = draftNode.getId();
        Object id = toElementId(elementIdType, idString);
        Node node = graph.getNode(id);
        boolean newNode = false;
        if (node == null) {
            node = factory.newNode(id);
            addedNodes++;
            newNode = true;
        }
        flushToNode(draftNode, node);
        if (newNode) {
            graph.addNode(node);
        }
        Progress.progress(progressTicket);
    }
    //Create all edges and push to data structure
    for (EdgeDraft draftEdge : container.getEdges()) {
        String idString = draftEdge.getId();
        Object id = toElementId(elementIdType, idString);
        String sourceId = draftEdge.getSource().getId();
        String targetId = draftEdge.getTarget().getId();
        Node source = graph.getNode(toElementId(elementIdType, sourceId));
        Node target = graph.getNode(toElementId(elementIdType, targetId));
        Object type = draftEdge.getType();
        int edgeType = graphModel.addEdgeType(type);
        Edge edge = graph.getEdge(source, target, edgeType);
        boolean newEdge = false;
        if (edge == null) {
            switch(container.getEdgeDefault()) {
                case DIRECTED:
                    edge = factory.newEdge(id, source, target, edgeType, draftEdge.getWeight(), true);
                    break;
                case UNDIRECTED:
                    edge = factory.newEdge(id, source, target, edgeType, draftEdge.getWeight(), false);
                    break;
                case MIXED:
                    boolean directed = draftEdge.getDirection() == null || !draftEdge.getDirection().equals(EdgeDirection.UNDIRECTED);
                    edge = factory.newEdge(id, source, target, edgeType, draftEdge.getWeight(), directed);
                    break;
            }
            addedEdges++;
            newEdge = true;
        }
        flushToEdge(draftEdge, edge);
        if (newEdge) {
            graph.addEdge(edge);
        }
        Progress.progress(progressTicket);
    }
    //Report
    int touchedNodes = container.getNodeCount();
    int touchedEdges = container.getEdgeCount();
    if (touchedNodes != addedNodes || touchedEdges != addedEdges) {
        Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Nodes loaded: {0} ({1} added)", new Object[] { touchedNodes, addedNodes });
        Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Edges loaded: {0} ({1} added)", new Object[] { touchedEdges, addedEdges });
    } else {
        Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Nodes loaded: {0}", new Object[] { touchedNodes });
        Logger.getLogger(getClass().getSimpleName()).log(Level.INFO, "# Edges loaded: {0}", new Object[] { touchedEdges });
    }
    Progress.finish(progressTicket);
}
Also used : ElementIdType(org.gephi.io.importer.api.ElementIdType) GraphFactory(org.gephi.graph.api.GraphFactory) EdgeDraft(org.gephi.io.importer.api.EdgeDraft) Graph(org.gephi.graph.api.Graph) NodeDraft(org.gephi.io.importer.api.NodeDraft) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge) GraphController(org.gephi.graph.api.GraphController)

Example 20 with GraphController

use of org.gephi.graph.api.GraphController in project gephi by gephi.

the class DefaultProcessor method processConfiguration.

protected void processConfiguration(ContainerUnloader container, Workspace workspace) {
    //Configuration
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    Configuration configuration = new Configuration();
    configuration.setTimeRepresentation(container.getTimeRepresentation());
    if (container.getEdgeTypeLabelClass() != null) {
        configuration.setEdgeLabelType(container.getEdgeTypeLabelClass());
    }
    configuration.setNodeIdType(container.getElementIdType().getTypeClass());
    configuration.setEdgeIdType(container.getElementIdType().getTypeClass());
    ColumnDraft weightColumn = container.getEdgeColumn("weight");
    if (weightColumn != null && weightColumn.isDynamic()) {
        if (container.getTimeRepresentation().equals(TimeRepresentation.INTERVAL)) {
            configuration.setEdgeWeightType(IntervalDoubleMap.class);
        } else {
            configuration.setEdgeWeightType(TimestampDoubleMap.class);
        }
    }
    graphController.getGraphModel(workspace).setConfiguration(configuration);
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Configuration(org.gephi.graph.api.Configuration) 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