Package org.gephi.io.importer.api

Examples of org.gephi.io.importer.api.NodeDraft


        int v_id = Integer.parseInt(index) - 1; // go from 1-based to 0-based index
        if (v_id >= num_vertices || v_id < 0) {
            report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat4", v_id, num_vertices), Issue.Level.SEVERE));
        }

        NodeDraft node = verticesArray[v_id];

        // only attach the label if there's one to attach
        if (label != null && label.length() > 0) {
            node.setLabel(label);
        }

        // parse the rest of the line
        if (firstParts != -1 && parts != null && parts.length >= firstParts + 2) {
            int i = firstParts;
            //Coordinates
            if (i < parts.length - 1) {
                try {
                    float x = Float.parseFloat(parts[i]);
                    float y = Float.parseFloat(parts[i + 1]);

                    node.setX(x);
                    node.setY(y);

                    i++;
                } catch (Exception e) {
                    report.logIssue(new Issue(NbBundle.getMessage(ImporterPajek.class, "importerNET_error_dataformat5", lineReader.getLineNumber()), Issue.Level.WARNING));
                }
            }

            // parse colors
            for (; i < parts.length - 1; i++) {
                // node's internal color
                if ("ic".equals(parts[i])) {
                    String colorName = parts[i + 1].replaceAll(" ", ""); // remove spaces from color's name so we can look it up
                    Color color = getPajekColorFromName(colorName);
                    node.setColor(color);
                }
            }
        }
    }
View Full Code Here


            }

            StringTokenizer st = new StringTokenizer(nextLine.trim());

            int vid1 = Integer.parseInt(st.nextToken()) - 1;
            NodeDraft nodeFrom = verticesArray[vid1];

            if (is_list) // one source, multiple destinations
            {
                do {
                    int vid2 = Integer.parseInt(st.nextToken()) - 1;
                    NodeDraft nodeTo = verticesArray[vid2];
                    EdgeDraft edge = container.factory().newEdgeDraft();
                    edge.setSource(nodeFrom);
                    edge.setTarget(nodeTo);
                    container.addEdge(edge);
                } while (st.hasMoreTokens());
            } else // one source, one destination, at most one weight
            {
                int vid2 = Integer.parseInt(st.nextToken()) - 1;
                NodeDraft nodeTo = verticesArray[vid2];
                EdgeDraft edge = container.factory().newEdgeDraft();
                edge.setSource(nodeFrom);
                edge.setTarget(nodeTo);

                // get the edge weight if we care
View Full Code Here

        }
        return ret;
    }

    private boolean parseNode(ArrayList list) {
        NodeDraft node = container.factory().newNodeDraft();
        String id = null;
        for (int i = 0; i < list.size(); i += 2) {
            String key = (String) list.get(i);
            Object value = list.get(i + 1);
            if ("id".equals(key)) {
                id = value.toString();
                node.setId(id);
            } else if ("label".equals(key)) {
                String label = value.toString();
                node.setLabel(label);
            }
        }
        if (id == null) {
            report.logIssue(new Issue(NbBundle.getMessage(ImporterGML.class, "importerGML_error_nodeidmissing"), Issue.Level.WARNING));
        }
View Full Code Here

        EdgeDraft edgeDraft = container.factory().newEdgeDraft();
        for (int i = 0; i < list.size(); i += 2) {
            String key = (String) list.get(i);
            Object value = list.get(i + 1);
            if ("source".equals(key)) {
                NodeDraft source = container.getNode(value.toString());
                edgeDraft.setSource(source);
            } else if ("target".equals(key)) {
                NodeDraft target = container.getNode(value.toString());
                edgeDraft.setTarget(target);
            } else if ("value".equals(key) || "weight".equals(key)) {
                if (value instanceof Double) {
                    edgeDraft.setWeight(((Double) value).floatValue());
                }
View Full Code Here

        AttributeTable nodeClass = container.getAttributeModel().getNodeTable();
        ResultSetMetaData metaData = rs.getMetaData();
        int columnsCount = metaData.getColumnCount();
        int count = 0;
        while (rs.next()) {
            NodeDraft node = factory.newNodeDraft();
            for (int i = 0; i < columnsCount; i++) {
                String columnName = metaData.getColumnLabel(i + 1);
                NodeProperties p = properties.getNodeProperty(columnName);
                if (p != null) {
                    injectNodeProperty(p, rs, i + 1, node);
View Full Code Here

                }
                break;
            case SOURCE:
                String source = rs.getString(column);
                if (source != null) {
                    NodeDraft sourceNode = container.getNode(source);
                    edgeDraft.setSource(sourceNode);
                }
                break;
            case TARGET:
                String target = rs.getString(column);
                if (target != null) {
                    NodeDraft targetNode = container.getNode(target);
                    edgeDraft.setTarget(targetNode);
                }
                break;
            case WEIGHT:
                float weight = rs.getFloat(column);
View Full Code Here

        }
        return tokens.toArray(new String[]{});
    }

    private void addNode(String[] nodeData) {
        NodeDraft node;
        String id = nodeData[0];
        if (!container.nodeExists(id)) {
            node = container.factory().newNodeDraft();
            node.setId(id);
            container.addNode(node);
        } else {
            node = container.getNode(id);
        }
        for (int i = 1; i < nodeDataColumns.length; i++) {
            node.addAttributeValue(nodeDataColumns[i], nodeData[i]);
        }
    }
View Full Code Here

            node.addAttributeValue(nodeDataColumns[i], nodeData[i]);
        }
    }

    private void addNodeProperties(String[] nodeProperties) {
        NodeDraft node;
        String id = nodeProperties[0];
        if (!container.nodeExists(id)) {
            node = container.factory().newNodeDraft();
            node.setId(id);
            container.addNode(node);
        } else {
            node = container.getNode(id);
        }
        int i = 0;
        try {
            for (i = 1; i < nodeProperties.length; i++) {
                switch (nodeDataAttributes[i]) {
                    case NODE_X:
                        node.setX(Float.parseFloat(nodeProperties[i]));
                        break;
                    case NODE_Y:
                        node.setY(Float.parseFloat(nodeProperties[i]));
                        break;
                    case NODE_COLOR:
                        // Add just shades of red as NetDraw VNA is not specific
                        // about color.
                        node.setColor(Integer.parseInt(nodeProperties[i]), 0, 0);
                        break;
                    case NODE_SIZE:
                        node.setSize(Float.parseFloat(nodeProperties[i]));
                        break;
                    case NODE_SHORT_LABEL:
                        node.setLabel(nodeProperties[i]);
                        break;
                }
            }
        } catch (NumberFormatException e) {
            report.logIssue(new Issue("Error parsing numerical value at '" + nodeProperties[i] + "'.", Issue.Level.WARNING));
View Full Code Here

            report.logIssue(new Issue("Error parsing numerical value at '" + nodeProperties[i] + "'.", Issue.Level.WARNING));
        }
    }

    private void addEdge(String[] edgeData) {
        NodeDraft sourceNode;
        if (!container.nodeExists(edgeData[0])) {
            sourceNode = container.factory().newNodeDraft();
            sourceNode.setId(edgeData[0]);
            container.addNode(sourceNode);
        } else {
            sourceNode = container.getNode(edgeData[0]);
        }
        NodeDraft targetNode;
        if (!container.nodeExists(edgeData[1])) {
            targetNode = container.factory().newNodeDraft();
            targetNode.setId(edgeData[1]);
            container.addNode(targetNode);
        } else {
            targetNode = container.getNode(edgeData[1]);
        }
        EdgeDraft edge = container.getEdge(sourceNode, targetNode);
View Full Code Here

            if (cancel) {
                return;
            }

            //Create Node
            NodeDraft node = container.factory().newNodeDraft();

            Matcher m = pattern.matcher(nodeLine);
            int count = 0;
            String id = "";
            while (m.find()) {
                int start = m.start();
                int end = m.end();
                if (start != end) {
                    String data = nodeLine.substring(start, end);
                    data = data.trim();
                    if (!data.isEmpty() && !data.toLowerCase().equals("null")) {
                        if (count == 0) {
                            //Id
                            id = data;
                            node.setId(data);
                        } else if (count - 1 < nodeColumns.length) {
                            if (nodeColumns[count - 1] != null) {
                                setNodeData(node, nodeColumns[count - 1], data);
                            }
                        } else {
                            report.logIssue(new Issue(NbBundle.getMessage(ImporterGDF.class, "importerGDF_error_dataformat7", id), Issue.Level.SEVERE));
                        }
                    }
                }
                count++;
            }

            container.addNode(node);

            Progress.progress(progressTicket);      //Progress
        }

        //Edges
        for (String edgeLine : edgeLines) {
            if (cancel) {
                return;
            }
            //Create Edge
            EdgeDraft edge = container.factory().newEdgeDraft();

            Matcher m = pattern.matcher(edgeLine);
            int count = 0;
            String id = "";
            while (m.find()) {
                int start = m.start();
                int end = m.end();
                if (start != end) {
                    String data = edgeLine.substring(start, end);
                    data = data.trim();
                    if (!data.isEmpty() && !data.toLowerCase().equals("null")) {
                        if (count == 0) {
                            NodeDraft nodeSource = container.getNode(data);
                            edge.setSource(nodeSource);
                            id = data;
                        } else if (count == 1) {
                            NodeDraft nodeTarget = container.getNode(data);
                            edge.setTarget(nodeTarget);
                            id += "," + data;
                        } else if (count - 2 < edgeColumns.length) {
                            if (edgeColumns[count - 2] != null) {
                                setEdgeData(edge, edgeColumns[count - 2], data);
View Full Code Here

TOP

Related Classes of org.gephi.io.importer.api.NodeDraft

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.