diff --git a/modules/ExportPlugin/pom.xml b/modules/ExportPlugin/pom.xml
index 7d4821cc84d47974dcb1dff929c5b2f466060002..66ca736b8eb34772933adac306ef185f1ba0f97d 100644
--- a/modules/ExportPlugin/pom.xml
+++ b/modules/ExportPlugin/pom.xml
@@ -16,10 +16,6 @@
ExportPlugin
-
- ${project.groupId}
- data-attributes-api
-
${project.groupId}
dynamic-api
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderCSV.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderCSV.java
index e9b6539118bbe4c08ee97a5f8f1da4fa9d8c831e..9eeaa83d1e0bfb6faa243107440c8a048ca21ad8 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderCSV.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderCSV.java
@@ -54,15 +54,18 @@ import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = GraphFileExporterBuilder.class)
public class ExporterBuilderCSV implements GraphFileExporterBuilder {
+ @Override
public GraphExporter buildExporter() {
return new ExporterCSV();
}
+ @Override
public FileType[] getFileTypes() {
FileType ft = new FileType(".csv", NbBundle.getMessage(ExporterBuilderCSV.class, "fileType_CSV_Name"));
return new FileType[]{ft};
}
+ @Override
public String getName() {
return "CSV";
}
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGDF.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGDF.java
index 7a89fff1e8c78f6ccc908cf053494e666007c32c..2872fcd2c4d9ddef20d8fa6de9d300cf13f2f63c 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGDF.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGDF.java
@@ -54,15 +54,18 @@ import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = GraphFileExporterBuilder.class)
public class ExporterBuilderGDF implements GraphFileExporterBuilder {
+ @Override
public GraphExporter buildExporter() {
return new ExporterGDF();
}
+ @Override
public FileType[] getFileTypes() {
FileType ft = new FileType(".gdf", NbBundle.getMessage(ExporterBuilderGDF.class, "fileType_GDF_Name"));
return new FileType[]{ft};
}
+ @Override
public String getName() {
return "GDF";
}
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGEXF.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGEXF.java
index 894c07a961e5bd53ea21beae4e40af3d47ef5e13..fbdd7a92a17a1e9ac55fd406ba551bea81b44ab3 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGEXF.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGEXF.java
@@ -54,15 +54,18 @@ import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = GraphFileExporterBuilder.class)
public class ExporterBuilderGEXF implements GraphFileExporterBuilder {
+ @Override
public GraphExporter buildExporter() {
return new ExporterGEXF();
}
+ @Override
public FileType[] getFileTypes() {
FileType ft = new FileType(".gexf", NbBundle.getMessage(ExporterBuilderGEXF.class, "fileType_GEXF_Name"));
return new FileType[]{ft};
}
+ @Override
public String getName() {
return "GEXF";
}
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGML.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGML.java
index f4207ed4730d112cecaf16e14cad0acc72e32b59..255d5e8bbe6126a3c24bf4bfd632e0a1bf859378 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGML.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGML.java
@@ -53,14 +53,17 @@ import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = GraphFileExporterBuilder.class)
public class ExporterBuilderGML implements GraphFileExporterBuilder {
+ @Override
public GraphExporter buildExporter() {
return new ExporterGML();
}
+ @Override
public FileType[] getFileTypes() {
return new FileType[]{new FileType(".gml", "GML files")};
}
+ @Override
public String getName() {
return "GML exporter";
}
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGraphML.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGraphML.java
index d248b0e848a953b4e45c3e88f9a531df91cc6978..6ba15669405a2a7b38a8a29425a75439c3ff1d70 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGraphML.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderGraphML.java
@@ -54,15 +54,18 @@ import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = GraphFileExporterBuilder.class)
public class ExporterBuilderGraphML implements GraphFileExporterBuilder {
+ @Override
public GraphExporter buildExporter() {
return new ExporterGraphML();
}
+ @Override
public FileType[] getFileTypes() {
FileType ft = new FileType(".graphml", NbBundle.getMessage(ExporterBuilderGraphML.class, "fileType_GraphML_Name"));
return new FileType[]{ft};
}
+ @Override
public String getName() {
return "GraphML";
}
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderPajek.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderPajek.java
index 670a624ac05167da44f129329279f4854b787be6..e951777f7120c0932f33296a8a5c3e09cf040b92 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderPajek.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderPajek.java
@@ -54,15 +54,18 @@ import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = GraphFileExporterBuilder.class)
public class ExporterBuilderPajek implements GraphFileExporterBuilder {
+ @Override
public GraphExporter buildExporter() {
return new ExporterPajek();
}
+ @Override
public FileType[] getFileTypes() {
FileType ft = new FileType(".net", NbBundle.getMessage(ExporterBuilderCSV.class, "fileType_Pajek_Name"));
return new FileType[]{ft};
}
+ @Override
public String getName() {
return "Pajek";
}
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderVNA.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderVNA.java
index 29235f764ca39e65f484bfebd6f886b09a5a8ecd..65c3ee63bcc2e0c0df18a377b833e2af6809ee6d 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderVNA.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterBuilderVNA.java
@@ -53,14 +53,17 @@ import org.openide.util.lookup.ServiceProvider;
*/
@ServiceProvider(service = GraphFileExporterBuilder.class)
public class ExporterBuilderVNA implements GraphFileExporterBuilder{
+ @Override
public GraphExporter buildExporter() {
return new ExporterVNA();
}
+ @Override
public FileType[] getFileTypes() {
return new FileType[]{new FileType(".vna", NbBundle.getMessage(ExporterBuilderVNA.class, "fileType_VNA_Name"))};
}
+ @Override
public String getName() {
return "vna";
}
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterCSV.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterCSV.java
index 9bfdaa026554714ea27222dba035f946dc053fee..35df9030d05b82a1ecbbceb431614fae64142fdb 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterCSV.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterCSV.java
@@ -1,43 +1,43 @@
/*
-Copyright 2008-2010 Gephi
-Authors : Mathieu Bastian
-Website : http://www.gephi.org
-
-This file is part of Gephi.
-
-DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
-
-Copyright 2011 Gephi Consortium. All rights reserved.
-
-The contents of this file are subject to the terms of either the GNU
-General Public License Version 3 only ("GPL") or the Common
-Development and Distribution License("CDDL") (collectively, the
-"License"). You may not use this file except in compliance with the
-License. You can obtain a copy of the License at
-http://gephi.org/about/legal/license-notice/
-or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
-specific language governing permissions and limitations under the
-License. When distributing the software, include this License Header
-Notice in each file and include the License files at
-/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
-License Header, with the fields enclosed by brackets [] replaced by
-your own identifying information:
-"Portions Copyrighted [year] [name of copyright owner]"
-
-If you wish your version of this file to be governed by only the CDDL
-or only the GPL Version 3, indicate your decision by adding
-"[Contributor] elects to include this software in this distribution
-under the [CDDL or GPL Version 3] license." If you do not indicate a
-single choice of license, a recipient has the option to distribute
-your version of this file under either the CDDL, the GPL Version 3 or
-to extend the choice of license to its licensees as provided above.
-However, if you add GPL Version 3 code and therefore, elected the GPL
-Version 3 license, then the option applies only if the new code is
-made subject to such option by the copyright holder.
-
-Contributor(s):
-
-Portions Copyrighted 2011 Gephi Consortium.
+ Copyright 2008-2010 Gephi
+ Authors : Mathieu Bastian
+ Website : http://www.gephi.org
+
+ This file is part of Gephi.
+
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+
+ Copyright 2011 Gephi Consortium. All rights reserved.
+
+ The contents of this file are subject to the terms of either the GNU
+ General Public License Version 3 only ("GPL") or the Common
+ Development and Distribution License("CDDL") (collectively, the
+ "License"). You may not use this file except in compliance with the
+ License. You can obtain a copy of the License at
+ http://gephi.org/about/legal/license-notice/
+ or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
+ specific language governing permissions and limitations under the
+ License. When distributing the software, include this License Header
+ Notice in each file and include the License files at
+ /cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
+ License Header, with the fields enclosed by brackets [] replaced by
+ your own identifying information:
+ "Portions Copyrighted [year] [name of copyright owner]"
+
+ If you wish your version of this file to be governed by only the CDDL
+ or only the GPL Version 3, indicate your decision by adding
+ "[Contributor] elects to include this software in this distribution
+ under the [CDDL or GPL Version 3] license." If you do not indicate a
+ single choice of license, a recipient has the option to distribute
+ your version of this file under either the CDDL, the GPL Version 3 or
+ to extend the choice of license to its licensees as provided above.
+ However, if you add GPL Version 3 code and therefore, elected the GPL
+ Version 3 license, then the option applies only if the new code is
+ made subject to such option by the copyright holder.
+
+ Contributor(s):
+
+ Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.io.exporter.plugin;
@@ -45,19 +45,12 @@ import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
-import org.gephi.graph.api.DirectedGraph;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphModel;
-import org.gephi.graph.api.HierarchicalDirectedGraph;
-import org.gephi.graph.api.HierarchicalGraph;
-import org.gephi.graph.api.HierarchicalMixedGraph;
-import org.gephi.graph.api.HierarchicalUndirectedGraph;
-import org.gephi.graph.api.MixedGraph;
import org.gephi.graph.api.Node;
-import org.gephi.graph.api.UndirectedGraph;
-import org.gephi.io.exporter.spi.GraphExporter;
import org.gephi.io.exporter.spi.CharacterExporter;
+import org.gephi.io.exporter.spi.GraphExporter;
import org.gephi.project.api.Workspace;
import org.gephi.utils.longtask.spi.LongTask;
import org.gephi.utils.progress.Progress;
@@ -83,6 +76,7 @@ public class ExporterCSV implements GraphExporter, CharacterExporter, LongTask {
private boolean cancel = false;
private ProgressTicket progressTicket;
+ @Override
public boolean execute() {
GraphModel graphModel = workspace.getLookup().lookup(GraphModel.class);
Graph graph = null;
@@ -128,7 +122,7 @@ public class ExporterCSV implements GraphExporter, CharacterExporter, LongTask {
}
}
- for (Edge e : ((HierarchicalGraph) graph).getMetaEdges(n)) {
+ for (Edge e : graph.getEdges(n)) {
if (!e.isDirected() || (e.isDirected() && n == e.getSource())) {
Node m = graph.getOpposite(n, e);
neighbours.add(m);
@@ -143,57 +137,19 @@ public class ExporterCSV implements GraphExporter, CharacterExporter, LongTask {
writer.append(EOL);
}
} else {
- if (graph instanceof DirectedGraph) {
- DirectedGraph directedGraph = (DirectedGraph) graph;
- Node[] nodes = graph.getNodes().toArray();
- for (Node n : nodes) {
- if (cancel) {
- break;
- }
- writeMatrixNode(n, true);
- for (int j = 0; j < nodes.length; j++) {
- Node m = nodes[j];
- Edge e = directedGraph.getEdge(n, m);
- e = e == null ? ((HierarchicalDirectedGraph) directedGraph).getMetaEdge(n, m) : e;
- writeEdge(e, j < nodes.length - 1);
- }
- Progress.progress(progressTicket);
- writer.append(EOL);
- }
- } else if (graph instanceof UndirectedGraph) {
- UndirectedGraph undirectedGraph = (UndirectedGraph) graph;
- Node[] nodes = graph.getNodes().toArray();
- for (Node n : nodes) {
- if (cancel) {
- break;
- }
- writeMatrixNode(n, true);
- for (int j = 0; j < nodes.length; j++) {
- Node m = nodes[j];
- Edge e = undirectedGraph.getEdge(n, m);
- e = e == null ? ((HierarchicalUndirectedGraph) undirectedGraph).getMetaEdge(n, m) : e;
- writeEdge(e, j < nodes.length - 1);
- }
- Progress.progress(progressTicket);
- writer.append(EOL);
+ Node[] nodes = graph.getNodes().toArray();
+ for (Node n : nodes) {
+ if (cancel) {
+ break;
}
- } else {
- MixedGraph mixedGraph = (MixedGraph) graph;
- Node[] nodes = graph.getNodes().toArray();
- for (Node n : graph.getNodes()) {
- if (cancel) {
- break;
- }
- writeMatrixNode(n, true);
- for (int j = 0; j < nodes.length; j++) {
- Node m = nodes[j];
- Edge e = mixedGraph.getEdge(n, m);
- e = e == null ? ((HierarchicalMixedGraph) mixedGraph).getMetaEdge(n, m) : e;
- writeEdge(e, j < nodes.length - 1);
- }
- Progress.progress(progressTicket);
- writer.append(EOL);
+ writeMatrixNode(n, true);
+ for (int j = 0; j < nodes.length; j++) {
+ Node m = nodes[j];
+ Edge e = graph.getEdge(n, m);
+ writeEdge(e, j < nodes.length - 1);
}
+ Progress.progress(progressTicket);
+ writer.append(EOL);
}
}
@@ -205,9 +161,9 @@ public class ExporterCSV implements GraphExporter, CharacterExporter, LongTask {
private void writeEdge(Edge edge, boolean writeSeparator) throws IOException {
if (edge != null) {
if (edgeWeight) {
- writer.append(Float.toString(edge.getWeight()));
+ writer.append(Double.toString(edge.getWeight()));
} else {
- writer.append(Float.toString(1f));
+ writer.append(Double.toString(1.0));
}
if (writeSeparator) {
writer.append(SEPARATOR);
@@ -225,11 +181,8 @@ public class ExporterCSV implements GraphExporter, CharacterExporter, LongTask {
private void writeMatrixNode(Node node, boolean writeSeparator) throws IOException {
if (header) {
- String label = node.getNodeData().getLabel();
- if (label == null) {
- label = node.getNodeData().getId();
- }
- writer.append(label);
+ Object label = node.getId();
+ writer.append(label.toString());
if (writeSeparator) {
writer.append(SEPARATOR);
}
@@ -237,21 +190,20 @@ public class ExporterCSV implements GraphExporter, CharacterExporter, LongTask {
}
private void writeListNode(Node node, boolean writeSeparator) throws IOException {
- String label = node.getNodeData().getLabel();
- if (label == null) {
- label = node.getNodeData().getId();
- }
- writer.append(label);
+ Object label = node.getId();
+ writer.append(label.toString());
if (writeSeparator) {
writer.append(SEPARATOR);
}
}
+ @Override
public boolean cancel() {
cancel = true;
return true;
}
+ @Override
public void setProgressTicket(ProgressTicket progressTicket) {
this.progressTicket = progressTicket;
}
@@ -288,22 +240,27 @@ public class ExporterCSV implements GraphExporter, CharacterExporter, LongTask {
this.list = list;
}
+ @Override
public boolean isExportVisible() {
return exportVisible;
}
+ @Override
public void setExportVisible(boolean exportVisible) {
this.exportVisible = exportVisible;
}
+ @Override
public void setWriter(Writer writer) {
this.writer = writer;
}
+ @Override
public Workspace getWorkspace() {
return workspace;
}
+ @Override
public void setWorkspace(Workspace workspace) {
this.workspace = workspace;
}
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterDL.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterDL.java
index cdee5478ca00a8b03c14484067ea2c483f9fa6af..f6464dcd52e2cfa5dae3338e1c40e615743f4853 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterDL.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterDL.java
@@ -47,15 +47,14 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
-import org.gephi.data.attributes.api.AttributeModel;
-import org.gephi.data.attributes.type.TimeInterval;
-import org.gephi.dynamic.api.DynamicModel;
+import org.gephi.attribute.api.AttributeModel;
import org.gephi.graph.api.*;
import org.gephi.io.exporter.spi.CharacterExporter;
import org.gephi.io.exporter.spi.GraphExporter;
import org.gephi.project.api.Workspace;
import org.gephi.utils.longtask.spi.LongTask;
import org.gephi.utils.progress.ProgressTicket;
+import org.openide.util.Lookup;
public class ExporterDL implements GraphExporter, CharacterExporter, LongTask {
@@ -68,9 +67,8 @@ public class ExporterDL implements GraphExporter, CharacterExporter, LongTask {
ProgressTicket progressTicket;
private boolean useMatrixFormat = false;
private boolean useListFormat = true;
+ private boolean exportDynamicWeight = true;
private boolean makeSymmetricMatrix = false;
- private double getLow;//time interval, used for getting edge weight in dynamic graphs
- private double getHigh;
public boolean isMakeSymmetricMatrix() {
return makeSymmetricMatrix;
@@ -109,8 +107,9 @@ public class ExporterDL implements GraphExporter, CharacterExporter, LongTask {
@Override
public boolean execute() {
progressTicket.start();
- attributeModel = workspace.getLookup().lookup(AttributeModel.class);
- graphModel = workspace.getLookup().lookup(GraphModel.class);
+ GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
+ attributeModel = graphController.getAttributeModel(workspace);
+ graphModel = graphController.getGraphModel(workspace);
Graph graph = null;
if (exportVisible) {
graph = graphModel.getGraphVisible();
@@ -127,20 +126,10 @@ public class ExporterDL implements GraphExporter, CharacterExporter, LongTask {
if (cancel) {
break;
}
- useLabels &= (nodeIterable.iterator().next().getNodeData().getLabel() != null);
+ useLabels &= (nodeIterable.iterator().next().getLabel() != null);
}
System.err.println("use labels " + useLabels);
- //find borders of the interval for edge.getWeight(low, high). If it's a static graph, then (-inf, inf)
- DynamicModel dynamicModel = workspace.getLookup().lookup(DynamicModel.class);
- TimeInterval visibleInterval = dynamicModel != null && exportVisible ? dynamicModel.getVisibleInterval() : new TimeInterval();
- getLow = Double.NEGATIVE_INFINITY;
- getHigh = Double.POSITIVE_INFINITY;
- if (visibleInterval != null) {
- getLow = visibleInterval.getLow();
- getHigh = visibleInterval.getHigh();
- }
-
if (!cancel) {
try {
if (useListFormat) {
@@ -174,22 +163,22 @@ public class ExporterDL implements GraphExporter, CharacterExporter, LongTask {
private void saveAsEdgeList1(boolean useLabels, Graph graph) throws IOException {
- HashMap idToLabel = new HashMap();//systemId to changed label
+ HashMap idToLabel = new HashMap();//systemId to changed label
HashSet labelUsed = new HashSet();
//edgelist format forbids equal nodes
if (useLabels) {
for (Node node : graph.getNodes()) {
- if (labelUsed.contains(node.getNodeData().getLabel())) {
+ if (labelUsed.contains(node.getLabel())) {
for (int i = 0;; i++) {
- if (!labelUsed.contains(node.getNodeData().getLabel() + "_" + i)) {
- idToLabel.put(node.getId(), node.getNodeData().getLabel() + "_" + i);
- labelUsed.add(node.getNodeData().getLabel() + "_" + i);
+ if (!labelUsed.contains(node.getLabel() + "_" + i)) {
+ idToLabel.put(node.getId(), node.getLabel() + "_" + i);
+ labelUsed.add(node.getLabel() + "_" + i);
break;
}
}
} else {
- idToLabel.put(node.getId(), node.getNodeData().getLabel());
- labelUsed.add(node.getNodeData().getLabel());
+ idToLabel.put(node.getId(), node.getLabel());
+ labelUsed.add(node.getLabel());
}
}
}
@@ -205,21 +194,29 @@ public class ExporterDL implements GraphExporter, CharacterExporter, LongTask {
break;
}
Edge edge = edgeIterator.iterator().next();
+ double weight;
+ if (exportDynamicWeight) {
+ weight = edge.getWeight(graph.getView());
+ } else {
+ weight = edge.getWeight();
+ }
+
if (useLabels) {
writer.write(formatLabel(idToLabel.get(edge.getSource().getId()), false) + " "
- + formatLabel(idToLabel.get(edge.getTarget().getId()), false) + " " + edge.getWeight(getLow, getHigh) + "\n");
+ + formatLabel(idToLabel.get(edge.getTarget().getId()), false) + " " + weight + "\n");
} else {
- writer.write(formatLabel(edge.getSource().getNodeData().getId(), false) + " "
- + formatLabel(edge.getTarget().getNodeData().getId(), false) + " " + edge.getWeight(getLow, getHigh) + "\n");
+ writer.write(formatLabel(edge.getSource().getId().toString(), false) + " "
+ + formatLabel(edge.getTarget().getId().toString(), false) + " " + weight + "\n");
}
if (!edge.isDirected()) {
+
if (useLabels) {
writer.write(formatLabel(idToLabel.get(edge.getTarget().getId()), false) + " "
- + formatLabel(idToLabel.get(edge.getSource().getId()), false) + " " + edge.getWeight(getLow, getHigh) + "\n");
+ + formatLabel(idToLabel.get(edge.getSource().getId()), false) + " " + weight + "\n");
} else {
- writer.write(formatLabel(edge.getTarget().getNodeData().getId(), false) + " "
- + formatLabel(edge.getSource().getNodeData().getId(), false) + " " + edge.getWeight(getLow, getHigh) + "\n");
+ writer.write(formatLabel(edge.getTarget().getId().toString(), false) + " "
+ + formatLabel(edge.getSource().getId().toString(), false) + " " + weight + "\n");
}
}
}
@@ -250,7 +247,13 @@ public class ExporterDL implements GraphExporter, CharacterExporter, LongTask {
int maxLengthOfEdgeWeight = 0;
if (makeSymmetricMatrix) {
for (Edge edge : graph.getEdges()) {
- maxLengthOfEdgeWeight = Math.max(maxLengthOfEdgeWeight, Double.toString(edge.getWeight(getLow, getHigh)).length());
+ double weight;
+ if (exportDynamicWeight) {
+ weight = edge.getWeight(graph.getView());
+ } else {
+ weight = edge.getWeight();
+ }
+ maxLengthOfEdgeWeight = Math.max(maxLengthOfEdgeWeight, Double.toString(weight).length());
}
}
@@ -261,9 +264,9 @@ public class ExporterDL implements GraphExporter, CharacterExporter, LongTask {
}
if (useLabels) {
- writer.write(formatLabel(idToNode.get(i).getNodeData().getLabel(), true));
+ writer.write(formatLabel(idToNode.get(i).getLabel(), true));
} else {
- writer.write(formatLabel(idToNode.get(i).getNodeData().getId(), true));
+ writer.write(formatLabel(idToNode.get(i).getId().toString(), true));
}
}
writer.write("\n");
@@ -280,10 +283,13 @@ public class ExporterDL implements GraphExporter, CharacterExporter, LongTask {
}
Node target = idToNode.get(j);
double weight = 0;
- if (graph.getEdge(source, target) != null) {
- weight = graph.getEdge(source, target).getWeight(getLow, getHigh);
- } else if (graph.getEdge(target, source) != null && !graph.getEdge(target, source).isDirected()) {
- weight = graph.getEdge(target, source).getWeight(getLow, getHigh);
+ Edge edge = graph.getEdge(source, target);
+ if (edge != null) {
+ if (exportDynamicWeight) {
+ weight = edge.getWeight(graph.getView());
+ } else {
+ weight = edge.getWeight();
+ }
}
writer.write(Double.toString(weight) + " ");
if (makeSymmetricMatrix) {
@@ -306,4 +312,4 @@ public class ExporterDL implements GraphExporter, CharacterExporter, LongTask {
public void setProgressTicket(ProgressTicket progressTicket) {
this.progressTicket = progressTicket;
}
-}
\ No newline at end of file
+}
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGDF.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGDF.java
index d6cb48ac64e5a2e4831f1a3a03b43b9876d7838f..98acf00cbcfbd1b92333791d000065ac52874750 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGDF.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGDF.java
@@ -44,27 +44,23 @@ package org.gephi.io.exporter.plugin;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
-import org.gephi.data.attributes.api.AttributeColumn;
-import org.gephi.data.attributes.api.AttributeModel;
-import org.gephi.data.attributes.api.AttributeOrigin;
-import org.gephi.data.attributes.api.AttributeType;
-import org.gephi.data.attributes.type.TimeInterval;
-import org.gephi.dynamic.DynamicUtilities;
-import org.gephi.dynamic.api.DynamicModel;
+import org.gephi.attribute.api.AttributeModel;
+import org.gephi.attribute.api.AttributeUtils;
+import org.gephi.attribute.api.Column;
+import org.gephi.attribute.time.TimestampValueSet;
import org.gephi.graph.api.Edge;
-import org.gephi.graph.api.EdgeIterable;
import org.gephi.graph.api.Graph;
+import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
-import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.graph.api.Node;
-import org.gephi.graph.api.NodeData;
import org.gephi.io.exporter.api.FileType;
-import org.gephi.io.exporter.spi.GraphExporter;
import org.gephi.io.exporter.spi.CharacterExporter;
+import org.gephi.io.exporter.spi.GraphExporter;
import org.gephi.project.api.Workspace;
import org.gephi.utils.longtask.spi.LongTask;
import org.gephi.utils.progress.Progress;
import org.gephi.utils.progress.ProgressTicket;
+import org.openide.util.Lookup;
import org.openide.util.NbBundle;
/**
@@ -84,6 +80,7 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
private boolean exportColors = true;
private boolean exportPosition = true;
private boolean exportAttributes = true;
+ private boolean exportDynamicWeight = true;
private boolean exportVisibility = false;
//Settings Helper
private float minSize;
@@ -97,24 +94,22 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
//Columns
private NodeColumnsGDF[] defaultNodeColumnsGDFs;
private EdgeColumnsGDF[] defaultEdgeColumnsGDFs;
- private AttributeColumn[] nodeColumns;
- private AttributeColumn[] edgeColumns;
+ private Column[] nodeColumns;
+ private Column[] edgeColumns;
//Buffer
private Writer writer;
- //Dynamic
- private TimeInterval visibleInterval;
+ @Override
public boolean execute() {
- AttributeModel attributeModel = workspace.getLookup().lookup(AttributeModel.class);
- GraphModel graphModel = workspace.getLookup().lookup(GraphModel.class);
+ GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
+ AttributeModel attributeModel = graphController.getAttributeModel(workspace);
+ GraphModel graphModel = graphController.getGraphModel(workspace);
Graph graph = null;
if (exportVisible) {
graph = graphModel.getGraphVisible();
} else {
graph = graphModel.getGraph();
}
- DynamicModel dynamicModel = workspace.getLookup().lookup(DynamicModel.class);
- visibleInterval = dynamicModel != null && exportVisible ? dynamicModel.getVisibleInterval() : new TimeInterval();
try {
exportData(graph, attributeModel);
} catch (Exception e) {
@@ -153,11 +148,11 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
}
//Attributes Node columns
- for (AttributeColumn c : nodeColumns) {
- if (!c.getOrigin().equals(AttributeOrigin.PROPERTY)) {
+ for (Column c : nodeColumns) {
+ if (!c.isProperty()) {
stringBuilder.append(c.getTitle());
stringBuilder.append(" ");
- DataTypeGDF dataTypeGDF = getDataTypeGDF(c.getType());
+ DataTypeGDF dataTypeGDF = getDataTypeGDF(c.getTypeClass());
stringBuilder.append(dataTypeGDF.toString().toUpperCase());
if (c.getDefaultValue() != null) {
stringBuilder.append(" default ");
@@ -188,10 +183,9 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
if (cancel) {
break;
}
- NodeData nodeData = node.getNodeData();
//Id
- stringBuilder.append(nodeData.getId());
+ stringBuilder.append(node.getId());
stringBuilder.append(",");
//Default columns
@@ -203,12 +197,11 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
}
//Attributes columns
- for (AttributeColumn c : nodeColumns) {
- if (!c.getOrigin().equals(AttributeOrigin.PROPERTY)) {
- Object val = node.getNodeData().getAttributes().getValue(c.getIndex());
- val = DynamicUtilities.getDynamicValue(val, visibleInterval.getLow(), visibleInterval.getHigh());
+ for (Column c : nodeColumns) {
+ if (!c.isProperty()) {
+ Object val = node.getAttribute(c, graph.getView());
if (val != null) {
- if (c.getType().equals(AttributeType.STRING) || c.getType().equals(AttributeType.LIST_STRING)) {
+ if (c.getTypeClass().equals(String.class) || c.getTypeClass().equals(String[].class)) {
String quote = !useQuotes ? "" : simpleQuotes ? "'" : "\"";
stringBuilder.append(quote);
stringBuilder.append(val.toString());
@@ -232,10 +225,9 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
stringBuilder.append("edgedef> node1,node2,");
//Edge settings helper
- HierarchicalGraph hg = (HierarchicalGraph) graph;
- for (Edge e : hg.getEdgesAndMetaEdges()) {
- edgeColors = edgeColors || e.getEdgeData().r() != -1;
- edgeLabels = edgeLabels || (e.getEdgeData().getLabel() != null && !e.getEdgeData().getLabel().isEmpty());
+ for (Edge e : graph.getEdges()) {
+ edgeColors = edgeColors || e.alpha() != 0;
+ edgeLabels = edgeLabels || (e.getLabel() != null && !e.getLabel().isEmpty());
}
//Edge columns title
@@ -253,11 +245,11 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
}
//Attributes Edge columns
- for (AttributeColumn c : edgeColumns) {
- if (!c.getOrigin().equals(AttributeOrigin.PROPERTY)) {
+ for (Column c : edgeColumns) {
+ if (!c.isProperty()) {
stringBuilder.append(c.getTitle());
stringBuilder.append(" ");
- DataTypeGDF dataTypeGDF = getDataTypeGDF(c.getType());
+ DataTypeGDF dataTypeGDF = getDataTypeGDF(c.getTypeClass());
stringBuilder.append(dataTypeGDF.toString().toUpperCase());
if (c.getDefaultValue() != null) {
stringBuilder.append(" default ");
@@ -271,24 +263,15 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
stringBuilder.setLength(stringBuilder.length() - 1);
stringBuilder.append("\n");
- //MetaEdges
- EdgeIterable edgeIterable;
- if (graph.getGraphModel().isHierarchical()) {
- HierarchicalGraph hierarchicalGraph = (HierarchicalGraph) graph;
- edgeIterable = hierarchicalGraph.getEdgesAndMetaEdges();
- } else {
- edgeIterable = graph.getEdges();
- }
-
//Edge lines
- for (Edge edge : edgeIterable) {
+ for (Edge edge : graph.getEdges()) {
if (cancel) {
break;
}
//Source & Target
- stringBuilder.append(edge.getSource().getNodeData().getId());
+ stringBuilder.append(edge.getSource().getId());
stringBuilder.append(",");
- stringBuilder.append(edge.getTarget().getNodeData().getId());
+ stringBuilder.append(edge.getTarget().getId());
stringBuilder.append(",");
//Default columns
@@ -300,12 +283,11 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
}
//Attributes columns
- for (AttributeColumn c : edgeColumns) {
- if (!c.getOrigin().equals(AttributeOrigin.PROPERTY)) {
- Object val = edge.getEdgeData().getAttributes().getValue(c.getIndex());
- val = DynamicUtilities.getDynamicValue(val, visibleInterval.getLow(), visibleInterval.getHigh());
+ for (Column c : edgeColumns) {
+ if (!c.isProperty()) {
+ Object val = edge.getAttribute(c, graph.getView());
if (val != null) {
- if (c.getType().equals(AttributeType.STRING) || c.getType().equals(AttributeType.LIST_STRING)) {
+ if (c.getTypeClass().equals(String.class) || c.getTypeClass().equals(String[].class)) {
String quote = !useQuotes ? "" : simpleQuotes ? "'" : "\"";
stringBuilder.append(quote);
stringBuilder.append(val.toString());
@@ -336,27 +318,27 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
}
private void attributesNodeColumns(AttributeModel attributeModel) {
- List cols = new ArrayList();
+ List cols = new ArrayList();
if (exportAttributes && attributeModel != null) {
- for (AttributeColumn column : attributeModel.getNodeTable().getColumns()) {
+ for (Column column : attributeModel.getNodeTable()) {
if (!isNodeDefaultColumn(column.getId())) {
cols.add(column);
}
}
}
- nodeColumns = cols.toArray(new AttributeColumn[0]);
+ nodeColumns = cols.toArray(new Column[0]);
}
private void attributesEdgeColumns(AttributeModel attributeModel) {
- List cols = new ArrayList();
+ List cols = new ArrayList();
if (exportAttributes && attributeModel != null) {
- for (AttributeColumn column : attributeModel.getEdgeTable().getColumns()) {
+ for (Column column : attributeModel.getEdgeTable()) {
if (!isEdgeDefaultColumn(column.getId())) {
cols.add(column);
}
}
}
- edgeColumns = cols.toArray(new AttributeColumn[0]);
+ edgeColumns = cols.toArray(new Column[0]);
}
private boolean isNodeDefaultColumn(String id) {
@@ -379,7 +361,6 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
private void defaultNodeColumns(Graph graph) {
NodeColumnsGDF labelColumn = new NodeColumnsGDF("label") {
-
@Override
public boolean isEnable() {
return true;
@@ -387,7 +368,7 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
@Override
public void writeData(StringBuilder builder, Node node) {
- String label = node.getNodeData().getLabel();
+ String label = node.getLabel();
if (label != null) {
String quote = !useQuotes ? "" : simpleQuotes ? "'" : "\"";
builder.append(quote);
@@ -398,7 +379,6 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
};
NodeColumnsGDF visibleColumn = new NodeColumnsGDF("visible", DataTypeGDF.BOOLEAN) {
-
@Override
public boolean isEnable() {
return exportVisibility;
@@ -411,7 +391,6 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
};
NodeColumnsGDF labelVisibleColumn = new NodeColumnsGDF("labelvisible", DataTypeGDF.BOOLEAN) {
-
@Override
public boolean isEnable() {
return exportVisibility;
@@ -419,12 +398,11 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
@Override
public void writeData(StringBuilder builder, Node node) {
- builder.append(node.getNodeData().getTextData().isVisible());
+ builder.append(node.getTextProperties().isVisible());
}
};
NodeColumnsGDF widthColumn = new NodeColumnsGDF("width", DataTypeGDF.DOUBLE) {
-
@Override
public boolean isEnable() {
return exportPosition;
@@ -432,7 +410,7 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
@Override
public void writeData(StringBuilder builder, Node node) {
- float size = node.getNodeData().getSize();
+ float size = node.size();
if (normalize) {
size = (size - minSize) / (maxSize - minSize);
}
@@ -441,7 +419,6 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
};
NodeColumnsGDF heightColumn = new NodeColumnsGDF("height", DataTypeGDF.DOUBLE) {
-
@Override
public boolean isEnable() {
return exportPosition;
@@ -449,7 +426,7 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
@Override
public void writeData(StringBuilder builder, Node node) {
- float size = node.getNodeData().getSize();
+ float size = node.size();
if (normalize) {
size = (size - minSize) / (maxSize - minSize);
}
@@ -458,7 +435,6 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
};
NodeColumnsGDF xColumn = new NodeColumnsGDF("x", DataTypeGDF.DOUBLE) {
-
@Override
public boolean isEnable() {
return exportPosition;
@@ -466,7 +442,7 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
@Override
public void writeData(StringBuilder builder, Node node) {
- float x = node.getNodeData().x();
+ float x = node.x();
if (normalize && x != 0.0) {
x = (x - minX) / (maxX - minX);
}
@@ -475,7 +451,6 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
};
NodeColumnsGDF yColumn = new NodeColumnsGDF("y", DataTypeGDF.DOUBLE) {
-
@Override
public boolean isEnable() {
return exportPosition;
@@ -483,7 +458,7 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
@Override
public void writeData(StringBuilder builder, Node node) {
- float y = node.getNodeData().y();
+ float y = node.y();
if (normalize && y != 0.0) {
y = (y - minY) / (maxY - minY);
}
@@ -492,7 +467,6 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
};
NodeColumnsGDF colorColumn = new NodeColumnsGDF("color") {
-
@Override
public boolean isEnable() {
return exportColors;
@@ -502,17 +476,16 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
public void writeData(StringBuilder builder, Node node) {
String quote = "'";
builder.append(quote);
- builder.append((int) (node.getNodeData().r() * 255f));
+ builder.append((int) (node.r() * 255f));
builder.append(",");
- builder.append((int) (node.getNodeData().g() * 255f));
+ builder.append((int) (node.g() * 255f));
builder.append(",");
- builder.append((int) (node.getNodeData().b() * 255f));
+ builder.append((int) (node.b() * 255f));
builder.append(quote);
}
};
NodeColumnsGDF fixedColumn = new NodeColumnsGDF("fixed", DataTypeGDF.BOOLEAN) {
-
@Override
public boolean isEnable() {
return exportVisibility;
@@ -520,12 +493,11 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
@Override
public void writeData(StringBuilder builder, Node node) {
- builder.append(node.getNodeData().isFixed());
+ builder.append(node.isFixed());
}
};
NodeColumnsGDF styleColumn = new NodeColumnsGDF("style", DataTypeGDF.INT) {
-
@Override
public boolean isEnable() {
return false;
@@ -551,7 +523,6 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
private void defaultEdgeColumns(final Graph graph) {
EdgeColumnsGDF labelColumn = new EdgeColumnsGDF("label") {
-
@Override
public boolean isEnable() {
return edgeLabels;
@@ -559,7 +530,7 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
@Override
public void writeData(StringBuilder builder, Edge edge) {
- String label = edge.getEdgeData().getLabel();
+ String label = edge.getLabel();
if (label != null) {
String quote = !useQuotes ? "" : simpleQuotes ? "'" : "\"";
builder.append(quote);
@@ -570,7 +541,6 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
};
EdgeColumnsGDF weightColumn = new EdgeColumnsGDF("weight", DataTypeGDF.DOUBLE) {
-
@Override
public boolean isEnable() {
return true;
@@ -578,12 +548,17 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
@Override
public void writeData(StringBuilder builder, Edge edge) {
- builder.append(edge.getWeight(visibleInterval.getLow(), visibleInterval.getHigh()));
+ double weight;
+ if (exportDynamicWeight) {
+ weight = edge.getWeight(graph.getView());
+ } else {
+ weight = edge.getWeight();
+ }
+ builder.append(weight);
}
};
EdgeColumnsGDF directedColumn = new EdgeColumnsGDF("directed", DataTypeGDF.BOOLEAN) {
-
@Override
public boolean isEnable() {
return true;
@@ -596,7 +571,6 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
};
EdgeColumnsGDF colorColumn = new EdgeColumnsGDF("color") {
-
@Override
public boolean isEnable() {
return exportColors && edgeColors;
@@ -604,21 +578,20 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
@Override
public void writeData(StringBuilder builder, Edge edge) {
- if (edge.getEdgeData().r() != -1) {
+ if (edge.alpha() != 0) {
String quote = "'";
builder.append(quote);
- builder.append((int) (edge.getEdgeData().r() * 255f));
+ builder.append((int) (edge.r() * 255f));
builder.append(",");
- builder.append((int) (edge.getEdgeData().g() * 255f));
+ builder.append((int) (edge.g() * 255f));
builder.append(",");
- builder.append((int) (edge.getEdgeData().b() * 255f));
+ builder.append((int) (edge.b() * 255f));
builder.append(quote);
}
}
};
EdgeColumnsGDF visibleColumn = new EdgeColumnsGDF("visible", DataTypeGDF.BOOLEAN) {
-
@Override
public boolean isEnable() {
return exportVisibility;
@@ -631,7 +604,6 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
};
EdgeColumnsGDF labelVisibleColumn = new EdgeColumnsGDF("labelvisible", DataTypeGDF.BOOLEAN) {
-
@Override
public boolean isEnable() {
return exportVisibility;
@@ -639,12 +611,11 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
@Override
public void writeData(StringBuilder builder, Edge edge) {
- builder.append(edge.getEdgeData().getTextData().isVisible());
+ builder.append(edge.getTextProperties().isVisible());
}
};
EdgeColumnsGDF edgeIdColumn = new EdgeColumnsGDF("id", DataTypeGDF.VARCHAR) {
-
@Override
public boolean isEnable() {
return false;
@@ -674,21 +645,22 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
maxSize = Float.NEGATIVE_INFINITY;
for (Node node : graph.getNodes()) {
- NodeData nodeData = node.getNodeData();
- minX = Math.min(minX, nodeData.x());
- maxX = Math.max(maxX, nodeData.x());
- minY = Math.min(minY, nodeData.y());
- maxY = Math.max(maxY, nodeData.y());
- minSize = Math.min(minSize, nodeData.getSize());
- maxSize = Math.max(maxSize, nodeData.getSize());
+ minX = Math.min(minX, node.x());
+ maxX = Math.max(maxX, node.x());
+ minY = Math.min(minY, node.y());
+ maxY = Math.max(maxY, node.y());
+ minSize = Math.min(minSize, node.size());
+ maxSize = Math.max(maxSize, node.size());
}
}
+ @Override
public boolean cancel() {
cancel = true;
return true;
}
+ @Override
public void setProgressTicket(ProgressTicket progressTicket) {
this.progressTicket = progressTicket;
}
@@ -758,34 +730,28 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
this.useQuotes = useQuotes;
}
- private DataTypeGDF getDataTypeGDF(AttributeType type) {
- switch (type) {
- case BOOLEAN:
- return DataTypeGDF.BOOLEAN;
- case DOUBLE:
- return DataTypeGDF.DOUBLE;
- case FLOAT:
- return DataTypeGDF.FLOAT;
- case INT:
- return DataTypeGDF.INTEGER;
- case LONG:
- return DataTypeGDF.INTEGER;
- case STRING:
- return DataTypeGDF.VARCHAR;
- case DYNAMIC_BOOLEAN:
- return DataTypeGDF.BOOLEAN;
- case DYNAMIC_DOUBLE:
- return DataTypeGDF.DOUBLE;
- case DYNAMIC_FLOAT:
- return DataTypeGDF.FLOAT;
- case DYNAMIC_INT:
- return DataTypeGDF.INTEGER;
- case DYNAMIC_LONG:
- return DataTypeGDF.INTEGER;
- case DYNAMIC_STRING:
- return DataTypeGDF.VARCHAR;
- default:
- return DataTypeGDF.VARCHAR;
+ private DataTypeGDF getDataTypeGDF(Class type) {
+ if (AttributeUtils.isDynamicType(type)) {
+ type = AttributeUtils.getStaticType((Class extends TimestampValueSet>) type);
+ }
+ if (type.equals(Boolean.class)) {
+ return DataTypeGDF.BOOLEAN;
+ } else if (type.equals(Double.class)) {
+ return DataTypeGDF.DOUBLE;
+ } else if (type.equals(Float.class)) {
+ return DataTypeGDF.FLOAT;
+ } else if (type.equals(Integer.class)) {
+ return DataTypeGDF.INTEGER;
+ } else if (type.equals(Long.class)) {
+ return DataTypeGDF.INTEGER;
+ } else if (type.equals(Short.class)) {
+ return DataTypeGDF.INTEGER;
+ } else if (type.equals(Byte.class)) {
+ return DataTypeGDF.TINYINT;
+ } else if (type.equals(String.class)) {
+ return DataTypeGDF.VARCHAR;
+ } else {
+ return DataTypeGDF.VARCHAR;
}
}
@@ -868,22 +834,27 @@ public class ExporterGDF implements GraphExporter, CharacterExporter, LongTask {
}
}
+ @Override
public boolean isExportVisible() {
return exportVisible;
}
+ @Override
public void setExportVisible(boolean exportVisible) {
this.exportVisible = exportVisible;
}
+ @Override
public void setWriter(Writer writer) {
this.writer = writer;
}
+ @Override
public Workspace getWorkspace() {
return workspace;
}
+ @Override
public void setWorkspace(Workspace workspace) {
this.workspace = workspace;
}
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGEXF.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGEXF.java
index 9f0616bf5871939b3350fa3f3b96d8531a0fc91d..1e0c3d4453eb03ae18f78b4f2c5493939fb62783 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGEXF.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGEXF.java
@@ -42,33 +42,13 @@
package org.gephi.io.exporter.plugin;
import java.io.Writer;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import javanet.staxutils.IndentingXMLStreamWriter;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamWriter;
-import org.gephi.data.attributes.api.*;
-import org.gephi.data.attributes.type.DynamicType;
-import org.gephi.data.attributes.type.Interval;
-import org.gephi.data.attributes.type.TimeInterval;
-import org.gephi.data.attributes.type.TypeConvertor;
-import org.gephi.data.properties.PropertiesColumn;
-import org.gephi.dynamic.DynamicUtilities;
-import org.gephi.dynamic.api.DynamicController;
import org.gephi.dynamic.api.DynamicModel;
import org.gephi.graph.api.*;
-import org.gephi.io.exporter.api.FileType;
import org.gephi.io.exporter.spi.CharacterExporter;
import org.gephi.io.exporter.spi.GraphExporter;
import org.gephi.project.api.Workspace;
import org.gephi.utils.longtask.spi.LongTask;
-import org.gephi.utils.progress.Progress;
import org.gephi.utils.progress.ProgressTicket;
-import org.openide.util.Lookup;
-import org.openide.util.NbBundle;
/**
*
@@ -135,8 +115,6 @@ public class ExporterGEXF implements GraphExporter, CharacterExporter, LongTask
private boolean exportVisible;
private Writer writer;
private GraphModel graphModel;
- private AttributeModel attributeModel;
- private TimeInterval visibleInterval;
private DynamicModel dynamicModel;
//Settings
private boolean normalize = false;
@@ -156,537 +134,540 @@ public class ExporterGEXF implements GraphExporter, CharacterExporter, LongTask
private float minZ;
private float maxZ;
+ @Override
public boolean execute() {
- attributeModel = workspace.getLookup().lookup(AttributeModel.class);
- graphModel = workspace.getLookup().lookup(GraphModel.class);
- dynamicModel = Lookup.getDefault().lookup(DynamicController.class).getModel(workspace);
- HierarchicalGraph graph;
- if (exportVisible) {
- graph = graphModel.getHierarchicalGraphVisible();
- } else {
- graph = graphModel.getHierarchicalGraph();
- }
- Progress.start(progress);
- graph.readLock();
-
- //Is it a dynamic graph?
- exportDynamic = exportDynamic && dynamicModel.isDynamicGraph();
-
- //Options
- if (normalize) {
- calculateMinMax(graph);
- }
-
- //Calculate progress units count
- int max = 0;
- if (exportHierarchy) {
- for (Node n : graph.getNodesTree()) {
- max++;
- }
- for (Edge e : graph.getEdgesTree()) {
- max++;
- }
- } else {
- max = graph.getNodeCount();
- for (Edge e : graph.getEdgesAndMetaEdges()) {
- max++;
- }
- }
- Progress.switchToDeterminate(progress, max);
-
- try {
- XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
- outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.FALSE);
-
- XMLStreamWriter xmlWriter = outputFactory.createXMLStreamWriter(writer);
- xmlWriter = new IndentingXMLStreamWriter(xmlWriter);
-
- xmlWriter.writeStartDocument("UTF-8", "1.0");
- xmlWriter.setPrefix("", GEXF_NAMESPACE);
- xmlWriter.writeStartElement(GEXF_NAMESPACE, GEXF);
- xmlWriter.writeNamespace("", GEXF_NAMESPACE);
- xmlWriter.writeAttribute(GEXF_VERSION, "1.2");
-
- if (exportColors || exportPosition || exportSize) {
- xmlWriter.writeNamespace(VIZ, VIZ_NAMESPACE);
- }
- xmlWriter.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
- xmlWriter.writeAttribute("xsi:schemaLocation", GEXF_NAMESPACE_LOCATION);
-
- if (exportDynamic) {
- DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class);
- dynamicModel = dynamicController != null ? dynamicController.getModel(workspace) : null;
- visibleInterval = dynamicModel == null ? null : exportVisible ? dynamicModel.getVisibleInterval() : new TimeInterval(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
- }
-
- writeMeta(xmlWriter);
- writeGraph(xmlWriter, graph);
-
- xmlWriter.writeEndElement();
- xmlWriter.writeEndDocument();
- xmlWriter.close();
-
- } catch (Exception e) {
- graph.readUnlockAll();
- if (e instanceof RuntimeException) {
- throw (RuntimeException) e;
- }
- throw new RuntimeException(e);
- }
-
- graph.readUnlock();
-
- Progress.finish(progress);
+// attributeModel = workspace.getLookup().lookup(AttributeModel.class);
+// graphModel = workspace.getLookup().lookup(GraphModel.class);
+// dynamicModel = Lookup.getDefault().lookup(DynamicController.class).getModel(workspace);
+// HierarchicalGraph graph;
+// if (exportVisible) {
+// graph = graphModel.getHierarchicalGraphVisible();
+// } else {
+// graph = graphModel.getHierarchicalGraph();
+// }
+// Progress.start(progress);
+// graph.readLock();
+//
+// //Is it a dynamic graph?
+// exportDynamic = exportDynamic && dynamicModel.isDynamicGraph();
+//
+// //Options
+// if (normalize) {
+// calculateMinMax(graph);
+// }
+//
+// //Calculate progress units count
+// int max = 0;
+// if (exportHierarchy) {
+// for (Node n : graph.getNodesTree()) {
+// max++;
+// }
+// for (Edge e : graph.getEdgesTree()) {
+// max++;
+// }
+// } else {
+// max = graph.getNodeCount();
+// for (Edge e : graph.getEdgesAndMetaEdges()) {
+// max++;
+// }
+// }
+// Progress.switchToDeterminate(progress, max);
+//
+// try {
+// XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+// outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.FALSE);
+//
+// XMLStreamWriter xmlWriter = outputFactory.createXMLStreamWriter(writer);
+// xmlWriter = new IndentingXMLStreamWriter(xmlWriter);
+//
+// xmlWriter.writeStartDocument("UTF-8", "1.0");
+// xmlWriter.setPrefix("", GEXF_NAMESPACE);
+// xmlWriter.writeStartElement(GEXF_NAMESPACE, GEXF);
+// xmlWriter.writeNamespace("", GEXF_NAMESPACE);
+// xmlWriter.writeAttribute(GEXF_VERSION, "1.2");
+//
+// if (exportColors || exportPosition || exportSize) {
+// xmlWriter.writeNamespace(VIZ, VIZ_NAMESPACE);
+// }
+// xmlWriter.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
+// xmlWriter.writeAttribute("xsi:schemaLocation", GEXF_NAMESPACE_LOCATION);
+//
+// if (exportDynamic) {
+// DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class);
+// dynamicModel = dynamicController != null ? dynamicController.getModel(workspace) : null;
+// visibleInterval = dynamicModel == null ? null : exportVisible ? dynamicModel.getVisibleInterval() : new TimeInterval(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
+// }
+//
+// writeMeta(xmlWriter);
+// writeGraph(xmlWriter, graph);
+//
+// xmlWriter.writeEndElement();
+// xmlWriter.writeEndDocument();
+// xmlWriter.close();
+//
+// } catch (Exception e) {
+// graph.readUnlockAll();
+// if (e instanceof RuntimeException) {
+// throw (RuntimeException) e;
+// }
+// throw new RuntimeException(e);
+// }
+//
+// graph.readUnlock();
+//
+// Progress.finish(progress);
return !cancel;
}
- private void writeGraph(XMLStreamWriter xmlWriter, HierarchicalGraph graph) throws Exception {
- xmlWriter.writeStartElement(GRAPH);
- if (!(graph instanceof MixedGraph)) {
- xmlWriter.writeAttribute(GRAPH_DEFAULT_EDGETYPE, graph instanceof DirectedGraph ? "directed" : "undirected");
- }
-
- if (exportDynamic) {
- if (!Double.isInfinite(visibleInterval.getLow())) {
- String intervalLow = formatTime(visibleInterval.getLow());
- xmlWriter.writeAttribute(GRAPH_START, intervalLow);
- }
- if (!Double.isInfinite(visibleInterval.getHigh())) {
- String intervalHigh = formatTime(visibleInterval.getHigh());
- xmlWriter.writeAttribute(GRAPH_END, intervalHigh);
- }
- String timeFormat = dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DATE) ? "date"
- : dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DATETIME) ? "datetime" : "double";
- xmlWriter.writeAttribute(GRAPH_TIMEFORMAT, timeFormat);
- }
- xmlWriter.writeAttribute(GRAPH_MODE, exportDynamic ? "dynamic" : "static");
-
- writeAttributes(xmlWriter, attributeModel.getNodeTable());
- writeAttributes(xmlWriter, attributeModel.getEdgeTable());
- writeNodes(xmlWriter, graph);
- writeEdges(xmlWriter, graph);
-
- xmlWriter.writeEndElement();
- }
-
- private void writeMeta(XMLStreamWriter xmlWriter) throws Exception {
- xmlWriter.writeStartElement(META);
- xmlWriter.writeAttribute(META_LASTMODIFIEDDATE, getDateTime());
-
- xmlWriter.writeStartElement(META_CREATOR);
- xmlWriter.writeCharacters("Gephi 0.8.1");
- xmlWriter.writeEndElement();
-
- xmlWriter.writeStartElement(META_DESCRIPTION);
- xmlWriter.writeCharacters("");
- xmlWriter.writeEndElement();
-
- xmlWriter.writeEndElement();
- }
-
- private void writeAttributes(XMLStreamWriter xmlWriter, AttributeTable table) throws Exception {
- List staticCols = new ArrayList();
- List dynamicCols = new ArrayList();
- String attClass = table == attributeModel.getNodeTable() ? "node" : "edge";
-
- for (AttributeColumn col : table.getColumns()) {
-
- if (!col.getOrigin().equals(AttributeOrigin.PROPERTY)) {
- if (exportDynamic && col.getType().isDynamicType()) {
- dynamicCols.add(col);
- } else {
- staticCols.add(col);
- }
- } else if (exportDynamic && col.getType().isDynamicType() && col.getType() != AttributeType.TIME_INTERVAL
- && col.getOrigin().equals(AttributeOrigin.PROPERTY) && col.getIndex() == PropertiesColumn.EDGE_WEIGHT.getIndex()) {
- dynamicCols.add(col);
- }
- }
-
- if (!staticCols.isEmpty()) {
- writeAttributes(xmlWriter, staticCols.toArray(new AttributeColumn[0]), "static", attClass);
- }
- if (!dynamicCols.isEmpty()) {
- writeAttributes(xmlWriter, dynamicCols.toArray(new AttributeColumn[0]), "dynamic", attClass);
- }
- }
-
- private void writeAttributes(XMLStreamWriter xmlWriter, AttributeColumn[] cols, String mode, String attClass) throws Exception {
- if (exportAttributes && cols.length != 0) {
- xmlWriter.writeStartElement(ATTRIBUTES);
- xmlWriter.writeAttribute(ATTRIBUTES_CLASS, attClass);
- xmlWriter.writeAttribute(ATTRIBUTES_MODE, mode);
-
- for (AttributeColumn col : cols) {
- if (!col.getOrigin().equals(AttributeOrigin.PROPERTY)
- || (exportDynamic && col.getOrigin().equals(AttributeOrigin.PROPERTY) && col.getIndex() == PropertiesColumn.EDGE_WEIGHT.getIndex())) {
- xmlWriter.writeStartElement(ATTRIBUTE);
- xmlWriter.writeAttribute(ATTRIBUTE_ID, col.getId());
- xmlWriter.writeAttribute(ATTRIBUTE_TITLE, col.getTitle());
- if (col.getType().equals(AttributeType.INT)) {
- xmlWriter.writeAttribute(ATTRIBUTE_TYPE, "integer");
- } else if (col.getType().isListType()) {
- if (col.getType().equals(AttributeType.LIST_INTEGER)) {
- xmlWriter.writeAttribute(ATTRIBUTE_TYPE, "listint");
- } else if (col.getType().equals(AttributeType.LIST_CHARACTER)) {
- xmlWriter.writeAttribute(ATTRIBUTE_TYPE, "listchar");
- } else {
- xmlWriter.writeAttribute(ATTRIBUTE_TYPE, col.getType().getTypeString().toLowerCase().replace("_", ""));
- }
- } else if (col.getType().isDynamicType()) {
- AttributeType staticType = TypeConvertor.getStaticType(col.getType());
- if (staticType.equals(AttributeType.INT)) {
- xmlWriter.writeAttribute(ATTRIBUTE_TYPE, "integer");
- } else {
- xmlWriter.writeAttribute(ATTRIBUTE_TYPE, staticType.getTypeString().toLowerCase());
- }
- } else {
- xmlWriter.writeAttribute(ATTRIBUTE_TYPE, col.getType().getTypeString().toLowerCase());
- }
- if (col.getDefaultValue() != null) {
- xmlWriter.writeStartElement(ATTRIBUTE_DEFAULT);
- xmlWriter.writeCharacters(col.getDefaultValue().toString());
- xmlWriter.writeEndElement();
- }
- xmlWriter.writeEndElement();
- }
- }
-
- xmlWriter.writeEndElement();
- }
- }
-
- private void writeNodes(XMLStreamWriter xmlWriter, HierarchicalGraph graph) throws Exception {
- if (cancel) {
- return;
- }
- xmlWriter.writeStartElement(NODES);
-
- AttributeColumn dynamicCol = attributeModel.getNodeTable().getColumn(DynamicModel.TIMEINTERVAL_COLUMN);
-
- NodeIterable nodeIterable = exportHierarchy ? graph.getNodesTree() : graph.getNodes();
- for (Node node : nodeIterable) {
- xmlWriter.writeStartElement(NODE);
-
- String id = node.getNodeData().getId();
- xmlWriter.writeAttribute(NODE_ID, id);
- if (node.getNodeData().getLabel() != null && !node.getNodeData().getLabel().isEmpty()) {
- xmlWriter.writeAttribute(NODE_LABEL, node.getNodeData().getLabel());
- }
-
- if (exportHierarchy) {
- Node parent = graph.getParent(node);
- if (parent != null) {
- xmlWriter.writeAttribute(NODE_PID, parent.getNodeData().getId());
- }
- }
-
- if (exportDynamic && dynamicCol != null && visibleInterval != null) {
- TimeInterval timeInterval = (TimeInterval) node.getNodeData().getAttributes().getValue(dynamicCol.getIndex());
- if (timeInterval != null) {
- writeTimeInterval(xmlWriter, timeInterval);
- }
- }
-
- if (exportAttributes && node.getNodeData().getAttributes() != null) {
- AttributeRow attributeRow = (AttributeRow) node.getNodeData().getAttributes();
- writeAttValues(xmlWriter, attributeRow, visibleInterval);
- }
-
- if (exportSize) {
- writeNodeSize(xmlWriter, node);
- }
-
- if (exportPosition) {
- writeNodePosition(xmlWriter, node);
- }
-
- if (exportColors) {
- writeNodeColor(xmlWriter, node);
- }
-
- xmlWriter.writeEndElement();
- Progress.progress(progress);
- if (cancel) {
- break;
- }
- }
-
- xmlWriter.writeEndElement();
- }
-
- private void writeAttValues(XMLStreamWriter xmlWriter, AttributeRow row, TimeInterval visibleInterval) throws Exception {
- xmlWriter.writeStartElement(ATTVALUES);
- for (AttributeValue val : row.getValues()) {
- AttributeColumn col = val.getColumn();
- if (!col.getOrigin().equals(AttributeOrigin.PROPERTY)
- || (exportDynamic && col.getType().isDynamicType()
- && col.getOrigin().equals(AttributeOrigin.PROPERTY)
- && col.getIndex() == PropertiesColumn.EDGE_WEIGHT.getIndex())) {
- AttributeType type = col.getType();
- if (type.isDynamicType()) {
- DynamicType dynamicValue = (DynamicType) val.getValue();
- if (dynamicValue != null && visibleInterval != null && exportDynamic) {
- List> intervals = dynamicValue.getIntervals(visibleInterval.getLow(), visibleInterval.getHigh());
- for (Interval> interval : intervals) {
- Object value = interval.getValue();
- if (value != null) {
- xmlWriter.writeStartElement(ATTVALUE);
- xmlWriter.writeAttribute(ATTVALUE_FOR, col.getId());
- xmlWriter.writeAttribute(ATTVALUE_VALUE, value.toString());
- if (!Double.isInfinite(interval.getLow())) {
- String intervalLow = formatTime(interval.getLow());
- xmlWriter.writeAttribute(interval.isLowExcluded() ? START_OPEN : START, intervalLow);
- }
- if (!Double.isInfinite(interval.getHigh())) {
- String intervalHigh = formatTime(interval.getHigh());
- xmlWriter.writeAttribute(interval.isHighExcluded() ? END_OPEN : END, intervalHigh);
- }
- xmlWriter.writeEndElement();
- }
- }
- } else if (dynamicValue != null) {
- TimeInterval interval = visibleInterval;
- if (interval == null) {
- interval = new TimeInterval();
- }
- Object value = DynamicUtilities.getDynamicValue(dynamicValue, interval.getLow(), interval.getHigh());
- if (value != null) {
- xmlWriter.writeStartElement(ATTVALUE);
- xmlWriter.writeAttribute(ATTVALUE_FOR, val.getColumn().getId());
- xmlWriter.writeAttribute(ATTVALUE_VALUE, value.toString());
- xmlWriter.writeEndElement();
- }
- }
- } else {
- if (val.getValue() != null) {
- xmlWriter.writeStartElement(ATTVALUE);
- xmlWriter.writeAttribute(ATTVALUE_FOR, col.getId());
- xmlWriter.writeAttribute(ATTVALUE_VALUE, val.getValue().toString());
- xmlWriter.writeEndElement();
- }
- }
- }
- }
- xmlWriter.writeEndElement();
- }
-
- private void writeNodePosition(XMLStreamWriter xmlWriter, Node node) throws Exception {
- float x = node.getNodeData().x();
- if (normalize && x != 0.0) {
- x = (x - minX) / (maxX - minX);
- }
- float y = node.getNodeData().y();
- if (normalize && y != 0.0) {
- y = (y - minY) / (maxY - minY);
- }
- float z = node.getNodeData().z();
- if (normalize && z != 0.0) {
- z = (z - minZ) / (maxZ - minZ);
- }
- if (!(x == 0 && y == 0 && z == 0)) {
- xmlWriter.writeStartElement(VIZ, NODE_POSITION, VIZ_NAMESPACE);
- xmlWriter.writeAttribute("x", "" + x);
- xmlWriter.writeAttribute("y", "" + y);
- xmlWriter.writeAttribute("z", "" + z);
- xmlWriter.writeEndElement();
- }
- }
-
- private void writeNodeSize(XMLStreamWriter xmlWriter, Node node) throws Exception {
- xmlWriter.writeStartElement(VIZ, NODE_SIZE, VIZ_NAMESPACE);
- float size = node.getNodeData().getSize();
- if (normalize) {
- size = (size - minSize) / (maxSize - minSize);
- }
- xmlWriter.writeAttribute("value", "" + size);
- xmlWriter.writeEndElement();
- }
-
- private void writeNodeColor(XMLStreamWriter xmlWriter, Node node) throws Exception {
- int r = Math.round(node.getNodeData().r() * 255f);
- int g = Math.round(node.getNodeData().g() * 255f);
- int b = Math.round(node.getNodeData().b() * 255f);
- if (r != 0 || g != 0 || b != 0) {
- xmlWriter.writeStartElement(VIZ, NODE_COLOR, VIZ_NAMESPACE);
- xmlWriter.writeAttribute("r", "" + r);
- xmlWriter.writeAttribute("g", "" + g);
- xmlWriter.writeAttribute("b", "" + b);
- xmlWriter.writeEndElement();
- }
- }
-
- private void writeTimeInterval(XMLStreamWriter xmlWriter, TimeInterval timeInterval) throws Exception {
- List> intervals = timeInterval.getIntervals(visibleInterval.getLow(), visibleInterval.getHigh());
- if (intervals.size() > 1) {
- xmlWriter.writeStartElement(SPELLS);
- for (Interval interval : intervals) {
- xmlWriter.writeStartElement(SPELL);
- if (!Double.isInfinite(interval.getLow())) {
- String intervalLow = formatTime(interval.getLow());
- xmlWriter.writeAttribute(interval.isLowExcluded() ? START_OPEN : START, intervalLow);
- }
- if (!Double.isInfinite(interval.getHigh())) {
- String intervalHigh = formatTime(interval.getHigh());
- xmlWriter.writeAttribute(interval.isHighExcluded() ? END_OPEN : END, intervalHigh);
- }
- xmlWriter.writeEndElement();
- }
- xmlWriter.writeEndElement();
- } else if (intervals.size() == 1) {
- Interval interval = intervals.get(0);
- if (!Double.isInfinite(interval.getLow())) {
- String intervalLow = formatTime(interval.getLow());
- xmlWriter.writeAttribute(interval.isLowExcluded() ? START_OPEN : START, intervalLow);
- }
- if (!Double.isInfinite(interval.getHigh())) {
- String intervalHigh = formatTime(interval.getHigh());
- xmlWriter.writeAttribute(interval.isHighExcluded() ? END_OPEN : END, intervalHigh);
- }
- }
- }
-
- private void writeEdges(XMLStreamWriter xmlWriter, HierarchicalGraph graph) throws Exception {
- if (cancel) {
- return;
- }
- xmlWriter.writeStartElement(EDGES);
-
- AttributeColumn dynamicCol = attributeModel.getEdgeTable().getColumn(DynamicModel.TIMEINTERVAL_COLUMN);
-
- EdgeIterable edgeIterable = exportHierarchy ? graph.getEdgesTree() : graph.getEdgesAndMetaEdges();
- for (Edge edge : edgeIterable) {
- xmlWriter.writeStartElement(EDGE);
-
- if (edge.getEdgeData().getId() != null && !edge.getEdgeData().getId().equals(Integer.toString(edge.getId()))) {
- xmlWriter.writeAttribute(EDGE_ID, edge.getEdgeData().getId());
- }
- xmlWriter.writeAttribute(EDGE_SOURCE, edge.getSource().getNodeData().getId());
- xmlWriter.writeAttribute(EDGE_TARGET, edge.getTarget().getNodeData().getId());
-
- if (edge.isDirected() && graphModel.isMixed()) {
- xmlWriter.writeAttribute(EDGE_TYPE, "directed");
- } else if (!edge.isDirected() && graphModel.isMixed()) {
- xmlWriter.writeAttribute(EDGE_TYPE, "undirected");
- }
-
- String label = edge.getEdgeData().getLabel();
- if (label != null && !label.isEmpty()) {
- xmlWriter.writeAttribute(EDGE_LABEL, label);
- }
-
- AttributeColumn weightCol = attributeModel.getEdgeTable().getColumn(EDGE_WEIGHT);
- if(weightCol != null && !weightCol.getType().isDynamicType()) {
- float weight = edge.getWeight();
- if (weight != 1f) {
- xmlWriter.writeAttribute(EDGE_WEIGHT, "" + weight);
- }
- }
-
- if (exportDynamic && dynamicCol != null && visibleInterval != null) {
- TimeInterval timeInterval = (TimeInterval) edge.getEdgeData().getAttributes().getValue(dynamicCol.getIndex());
- if (timeInterval != null) {
- writeTimeInterval(xmlWriter, timeInterval);
- }
- }
-
- if (exportColors) {
- writeEdgeColor(xmlWriter, edge);
- }
-
- if (exportAttributes && edge.getEdgeData().getAttributes() != null) {
- AttributeRow attributeRow = (AttributeRow) edge.getEdgeData().getAttributes();
- writeAttValues(xmlWriter, attributeRow, visibleInterval);
- }
-
- xmlWriter.writeEndElement();
- Progress.progress(progress);
- if (cancel) {
- break;
- }
- }
-
- xmlWriter.writeEndElement();
- }
-
- private void writeEdgeColor(XMLStreamWriter xmlWriter, Edge edge) throws Exception {
- if (edge.getEdgeData().r() != -1) { //Edge has custom color
- int r = Math.round(edge.getEdgeData().r() * 255f);
- int g = Math.round(edge.getEdgeData().g() * 255f);
- int b = Math.round(edge.getEdgeData().b() * 255f);
- if (r != 0 || g != 0 || b != 0) {
- xmlWriter.writeStartElement(VIZ, EDGE_COLOR, VIZ_NAMESPACE);
- xmlWriter.writeAttribute("r", "" + r);
- xmlWriter.writeAttribute("g", "" + g);
- xmlWriter.writeAttribute("b", "" + b);
- if (edge.getEdgeData().alpha() != 1f) {
- xmlWriter.writeAttribute("a", "" + b);
- }
- xmlWriter.writeEndElement();
- }
- }
- }
-
- private void calculateMinMax(Graph graph) {
- minX = Float.POSITIVE_INFINITY;
- maxX = Float.NEGATIVE_INFINITY;
- minY = Float.POSITIVE_INFINITY;
- maxY = Float.NEGATIVE_INFINITY;
- minZ = Float.POSITIVE_INFINITY;
- maxZ = Float.NEGATIVE_INFINITY;
- minSize = Float.POSITIVE_INFINITY;
- maxSize = Float.NEGATIVE_INFINITY;
-
- for (Node node : graph.getNodes()) {
- NodeData nodeData = node.getNodeData();
- minX = Math.min(minX, nodeData.x());
- maxX = Math.max(maxX, nodeData.x());
- minY = Math.min(minY, nodeData.y());
- maxY = Math.max(maxY, nodeData.y());
- minZ = Math.min(minZ, nodeData.z());
- maxZ = Math.max(maxZ, nodeData.z());
- minSize = Math.min(minSize, nodeData.getSize());
- maxSize = Math.max(maxSize, nodeData.getSize());
- }
- }
-
- private String formatTime(double time) {
- if (dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DATE)) {
- String t = DynamicUtilities.getXMLDateStringFromDouble(time);
- if (t.endsWith("T00:00:00.000")) {
- t = t.substring(0, t.length() - 13);
- }
- return t;
- } else if (dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DATETIME)) {
- return DynamicUtilities.getXMLDateStringFromDouble(time);
- } else {
- return Double.toString(time);
- }
- }
-
+// private void writeGraph(XMLStreamWriter xmlWriter, HierarchicalGraph graph) throws Exception {
+// xmlWriter.writeStartElement(GRAPH);
+// if (!(graph instanceof MixedGraph)) {
+// xmlWriter.writeAttribute(GRAPH_DEFAULT_EDGETYPE, graph instanceof DirectedGraph ? "directed" : "undirected");
+// }
+//
+// if (exportDynamic) {
+// if (!Double.isInfinite(visibleInterval.getLow())) {
+// String intervalLow = formatTime(visibleInterval.getLow());
+// xmlWriter.writeAttribute(GRAPH_START, intervalLow);
+// }
+// if (!Double.isInfinite(visibleInterval.getHigh())) {
+// String intervalHigh = formatTime(visibleInterval.getHigh());
+// xmlWriter.writeAttribute(GRAPH_END, intervalHigh);
+// }
+// String timeFormat = dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DATE) ? "date"
+// : dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DATETIME) ? "datetime" : "double";
+// xmlWriter.writeAttribute(GRAPH_TIMEFORMAT, timeFormat);
+// }
+// xmlWriter.writeAttribute(GRAPH_MODE, exportDynamic ? "dynamic" : "static");
+//
+// writeAttributes(xmlWriter, attributeModel.getNodeTable());
+// writeAttributes(xmlWriter, attributeModel.getEdgeTable());
+// writeNodes(xmlWriter, graph);
+// writeEdges(xmlWriter, graph);
+//
+// xmlWriter.writeEndElement();
+// }
+//
+// private void writeMeta(XMLStreamWriter xmlWriter) throws Exception {
+// xmlWriter.writeStartElement(META);
+// xmlWriter.writeAttribute(META_LASTMODIFIEDDATE, getDateTime());
+//
+// xmlWriter.writeStartElement(META_CREATOR);
+// xmlWriter.writeCharacters("Gephi 0.8.1");
+// xmlWriter.writeEndElement();
+//
+// xmlWriter.writeStartElement(META_DESCRIPTION);
+// xmlWriter.writeCharacters("");
+// xmlWriter.writeEndElement();
+//
+// xmlWriter.writeEndElement();
+// }
+//
+// private void writeAttributes(XMLStreamWriter xmlWriter, AttributeTable table) throws Exception {
+// List staticCols = new ArrayList();
+// List dynamicCols = new ArrayList();
+// String attClass = table == attributeModel.getNodeTable() ? "node" : "edge";
+//
+// for (AttributeColumn col : table.getColumns()) {
+//
+// if (!col.getOrigin().equals(AttributeOrigin.PROPERTY)) {
+// if (exportDynamic && col.getType().isDynamicType()) {
+// dynamicCols.add(col);
+// } else {
+// staticCols.add(col);
+// }
+// } else if (exportDynamic && col.getType().isDynamicType() && col.getType() != AttributeType.TIME_INTERVAL
+// && col.getOrigin().equals(AttributeOrigin.PROPERTY) && col.getIndex() == PropertiesColumn.EDGE_WEIGHT.getIndex()) {
+// dynamicCols.add(col);
+// }
+// }
+//
+// if (!staticCols.isEmpty()) {
+// writeAttributes(xmlWriter, staticCols.toArray(new AttributeColumn[0]), "static", attClass);
+// }
+// if (!dynamicCols.isEmpty()) {
+// writeAttributes(xmlWriter, dynamicCols.toArray(new AttributeColumn[0]), "dynamic", attClass);
+// }
+// }
+//
+// private void writeAttributes(XMLStreamWriter xmlWriter, AttributeColumn[] cols, String mode, String attClass) throws Exception {
+// if (exportAttributes && cols.length != 0) {
+// xmlWriter.writeStartElement(ATTRIBUTES);
+// xmlWriter.writeAttribute(ATTRIBUTES_CLASS, attClass);
+// xmlWriter.writeAttribute(ATTRIBUTES_MODE, mode);
+//
+// for (AttributeColumn col : cols) {
+// if (!col.getOrigin().equals(AttributeOrigin.PROPERTY)
+// || (exportDynamic && col.getOrigin().equals(AttributeOrigin.PROPERTY) && col.getIndex() == PropertiesColumn.EDGE_WEIGHT.getIndex())) {
+// xmlWriter.writeStartElement(ATTRIBUTE);
+// xmlWriter.writeAttribute(ATTRIBUTE_ID, col.getId());
+// xmlWriter.writeAttribute(ATTRIBUTE_TITLE, col.getTitle());
+// if (col.getType().equals(AttributeType.INT)) {
+// xmlWriter.writeAttribute(ATTRIBUTE_TYPE, "integer");
+// } else if (col.getType().isListType()) {
+// if (col.getType().equals(AttributeType.LIST_INTEGER)) {
+// xmlWriter.writeAttribute(ATTRIBUTE_TYPE, "listint");
+// } else if (col.getType().equals(AttributeType.LIST_CHARACTER)) {
+// xmlWriter.writeAttribute(ATTRIBUTE_TYPE, "listchar");
+// } else {
+// xmlWriter.writeAttribute(ATTRIBUTE_TYPE, col.getType().getTypeString().toLowerCase().replace("_", ""));
+// }
+// } else if (col.getType().isDynamicType()) {
+// AttributeType staticType = TypeConvertor.getStaticType(col.getType());
+// if (staticType.equals(AttributeType.INT)) {
+// xmlWriter.writeAttribute(ATTRIBUTE_TYPE, "integer");
+// } else {
+// xmlWriter.writeAttribute(ATTRIBUTE_TYPE, staticType.getTypeString().toLowerCase());
+// }
+// } else {
+// xmlWriter.writeAttribute(ATTRIBUTE_TYPE, col.getType().getTypeString().toLowerCase());
+// }
+// if (col.getDefaultValue() != null) {
+// xmlWriter.writeStartElement(ATTRIBUTE_DEFAULT);
+// xmlWriter.writeCharacters(col.getDefaultValue().toString());
+// xmlWriter.writeEndElement();
+// }
+// xmlWriter.writeEndElement();
+// }
+// }
+//
+// xmlWriter.writeEndElement();
+// }
+// }
+//
+// private void writeNodes(XMLStreamWriter xmlWriter, HierarchicalGraph graph) throws Exception {
+// if (cancel) {
+// return;
+// }
+// xmlWriter.writeStartElement(NODES);
+//
+// AttributeColumn dynamicCol = attributeModel.getNodeTable().getColumn(DynamicModel.TIMEINTERVAL_COLUMN);
+//
+// NodeIterable nodeIterable = exportHierarchy ? graph.getNodesTree() : graph.getNodes();
+// for (Node node : nodeIterable) {
+// xmlWriter.writeStartElement(NODE);
+//
+// String id = node.getNodeData().getId();
+// xmlWriter.writeAttribute(NODE_ID, id);
+// if (node.getNodeData().getLabel() != null && !node.getNodeData().getLabel().isEmpty()) {
+// xmlWriter.writeAttribute(NODE_LABEL, node.getNodeData().getLabel());
+// }
+//
+// if (exportHierarchy) {
+// Node parent = graph.getParent(node);
+// if (parent != null) {
+// xmlWriter.writeAttribute(NODE_PID, parent.getNodeData().getId());
+// }
+// }
+//
+// if (exportDynamic && dynamicCol != null && visibleInterval != null) {
+// TimeInterval timeInterval = (TimeInterval) node.getNodeData().getAttributes().getValue(dynamicCol.getIndex());
+// if (timeInterval != null) {
+// writeTimeInterval(xmlWriter, timeInterval);
+// }
+// }
+//
+// if (exportAttributes && node.getNodeData().getAttributes() != null) {
+// AttributeRow attributeRow = (AttributeRow) node.getNodeData().getAttributes();
+// writeAttValues(xmlWriter, attributeRow, visibleInterval);
+// }
+//
+// if (exportSize) {
+// writeNodeSize(xmlWriter, node);
+// }
+//
+// if (exportPosition) {
+// writeNodePosition(xmlWriter, node);
+// }
+//
+// if (exportColors) {
+// writeNodeColor(xmlWriter, node);
+// }
+//
+// xmlWriter.writeEndElement();
+// Progress.progress(progress);
+// if (cancel) {
+// break;
+// }
+// }
+//
+// xmlWriter.writeEndElement();
+// }
+//
+// private void writeAttValues(XMLStreamWriter xmlWriter, AttributeRow row, TimeInterval visibleInterval) throws Exception {
+// xmlWriter.writeStartElement(ATTVALUES);
+// for (AttributeValue val : row.getValues()) {
+// AttributeColumn col = val.getColumn();
+// if (!col.getOrigin().equals(AttributeOrigin.PROPERTY)
+// || (exportDynamic && col.getType().isDynamicType()
+// && col.getOrigin().equals(AttributeOrigin.PROPERTY)
+// && col.getIndex() == PropertiesColumn.EDGE_WEIGHT.getIndex())) {
+// AttributeType type = col.getType();
+// if (type.isDynamicType()) {
+// DynamicType dynamicValue = (DynamicType) val.getValue();
+// if (dynamicValue != null && visibleInterval != null && exportDynamic) {
+// List> intervals = dynamicValue.getIntervals(visibleInterval.getLow(), visibleInterval.getHigh());
+// for (Interval> interval : intervals) {
+// Object value = interval.getValue();
+// if (value != null) {
+// xmlWriter.writeStartElement(ATTVALUE);
+// xmlWriter.writeAttribute(ATTVALUE_FOR, col.getId());
+// xmlWriter.writeAttribute(ATTVALUE_VALUE, value.toString());
+// if (!Double.isInfinite(interval.getLow())) {
+// String intervalLow = formatTime(interval.getLow());
+// xmlWriter.writeAttribute(interval.isLowExcluded() ? START_OPEN : START, intervalLow);
+// }
+// if (!Double.isInfinite(interval.getHigh())) {
+// String intervalHigh = formatTime(interval.getHigh());
+// xmlWriter.writeAttribute(interval.isHighExcluded() ? END_OPEN : END, intervalHigh);
+// }
+// xmlWriter.writeEndElement();
+// }
+// }
+// } else if (dynamicValue != null) {
+// TimeInterval interval = visibleInterval;
+// if (interval == null) {
+// interval = new TimeInterval();
+// }
+// Object value = DynamicUtilities.getDynamicValue(dynamicValue, interval.getLow(), interval.getHigh());
+// if (value != null) {
+// xmlWriter.writeStartElement(ATTVALUE);
+// xmlWriter.writeAttribute(ATTVALUE_FOR, val.getColumn().getId());
+// xmlWriter.writeAttribute(ATTVALUE_VALUE, value.toString());
+// xmlWriter.writeEndElement();
+// }
+// }
+// } else {
+// if (val.getValue() != null) {
+// xmlWriter.writeStartElement(ATTVALUE);
+// xmlWriter.writeAttribute(ATTVALUE_FOR, col.getId());
+// xmlWriter.writeAttribute(ATTVALUE_VALUE, val.getValue().toString());
+// xmlWriter.writeEndElement();
+// }
+// }
+// }
+// }
+// xmlWriter.writeEndElement();
+// }
+//
+// private void writeNodePosition(XMLStreamWriter xmlWriter, Node node) throws Exception {
+// float x = node.getNodeData().x();
+// if (normalize && x != 0.0) {
+// x = (x - minX) / (maxX - minX);
+// }
+// float y = node.getNodeData().y();
+// if (normalize && y != 0.0) {
+// y = (y - minY) / (maxY - minY);
+// }
+// float z = node.getNodeData().z();
+// if (normalize && z != 0.0) {
+// z = (z - minZ) / (maxZ - minZ);
+// }
+// if (!(x == 0 && y == 0 && z == 0)) {
+// xmlWriter.writeStartElement(VIZ, NODE_POSITION, VIZ_NAMESPACE);
+// xmlWriter.writeAttribute("x", "" + x);
+// xmlWriter.writeAttribute("y", "" + y);
+// xmlWriter.writeAttribute("z", "" + z);
+// xmlWriter.writeEndElement();
+// }
+// }
+//
+// private void writeNodeSize(XMLStreamWriter xmlWriter, Node node) throws Exception {
+// xmlWriter.writeStartElement(VIZ, NODE_SIZE, VIZ_NAMESPACE);
+// float size = node.getNodeData().getSize();
+// if (normalize) {
+// size = (size - minSize) / (maxSize - minSize);
+// }
+// xmlWriter.writeAttribute("value", "" + size);
+// xmlWriter.writeEndElement();
+// }
+//
+// private void writeNodeColor(XMLStreamWriter xmlWriter, Node node) throws Exception {
+// int r = Math.round(node.getNodeData().r() * 255f);
+// int g = Math.round(node.getNodeData().g() * 255f);
+// int b = Math.round(node.getNodeData().b() * 255f);
+// if (r != 0 || g != 0 || b != 0) {
+// xmlWriter.writeStartElement(VIZ, NODE_COLOR, VIZ_NAMESPACE);
+// xmlWriter.writeAttribute("r", "" + r);
+// xmlWriter.writeAttribute("g", "" + g);
+// xmlWriter.writeAttribute("b", "" + b);
+// xmlWriter.writeEndElement();
+// }
+// }
+//
+// private void writeTimeInterval(XMLStreamWriter xmlWriter, TimeInterval timeInterval) throws Exception {
+// List> intervals = timeInterval.getIntervals(visibleInterval.getLow(), visibleInterval.getHigh());
+// if (intervals.size() > 1) {
+// xmlWriter.writeStartElement(SPELLS);
+// for (Interval interval : intervals) {
+// xmlWriter.writeStartElement(SPELL);
+// if (!Double.isInfinite(interval.getLow())) {
+// String intervalLow = formatTime(interval.getLow());
+// xmlWriter.writeAttribute(interval.isLowExcluded() ? START_OPEN : START, intervalLow);
+// }
+// if (!Double.isInfinite(interval.getHigh())) {
+// String intervalHigh = formatTime(interval.getHigh());
+// xmlWriter.writeAttribute(interval.isHighExcluded() ? END_OPEN : END, intervalHigh);
+// }
+// xmlWriter.writeEndElement();
+// }
+// xmlWriter.writeEndElement();
+// } else if (intervals.size() == 1) {
+// Interval interval = intervals.get(0);
+// if (!Double.isInfinite(interval.getLow())) {
+// String intervalLow = formatTime(interval.getLow());
+// xmlWriter.writeAttribute(interval.isLowExcluded() ? START_OPEN : START, intervalLow);
+// }
+// if (!Double.isInfinite(interval.getHigh())) {
+// String intervalHigh = formatTime(interval.getHigh());
+// xmlWriter.writeAttribute(interval.isHighExcluded() ? END_OPEN : END, intervalHigh);
+// }
+// }
+// }
+//
+// private void writeEdges(XMLStreamWriter xmlWriter, HierarchicalGraph graph) throws Exception {
+// if (cancel) {
+// return;
+// }
+// xmlWriter.writeStartElement(EDGES);
+//
+// AttributeColumn dynamicCol = attributeModel.getEdgeTable().getColumn(DynamicModel.TIMEINTERVAL_COLUMN);
+//
+// EdgeIterable edgeIterable = exportHierarchy ? graph.getEdgesTree() : graph.getEdgesAndMetaEdges();
+// for (Edge edge : edgeIterable) {
+// xmlWriter.writeStartElement(EDGE);
+//
+// if (edge.getEdgeData().getId() != null && !edge.getEdgeData().getId().equals(Integer.toString(edge.getId()))) {
+// xmlWriter.writeAttribute(EDGE_ID, edge.getEdgeData().getId());
+// }
+// xmlWriter.writeAttribute(EDGE_SOURCE, edge.getSource().getNodeData().getId());
+// xmlWriter.writeAttribute(EDGE_TARGET, edge.getTarget().getNodeData().getId());
+//
+// if (edge.isDirected() && graphModel.isMixed()) {
+// xmlWriter.writeAttribute(EDGE_TYPE, "directed");
+// } else if (!edge.isDirected() && graphModel.isMixed()) {
+// xmlWriter.writeAttribute(EDGE_TYPE, "undirected");
+// }
+//
+// String label = edge.getEdgeData().getLabel();
+// if (label != null && !label.isEmpty()) {
+// xmlWriter.writeAttribute(EDGE_LABEL, label);
+// }
+//
+// AttributeColumn weightCol = attributeModel.getEdgeTable().getColumn(EDGE_WEIGHT);
+// if(weightCol != null && !weightCol.getType().isDynamicType()) {
+// float weight = edge.getWeight();
+// if (weight != 1f) {
+// xmlWriter.writeAttribute(EDGE_WEIGHT, "" + weight);
+// }
+// }
+//
+// if (exportDynamic && dynamicCol != null && visibleInterval != null) {
+// TimeInterval timeInterval = (TimeInterval) edge.getEdgeData().getAttributes().getValue(dynamicCol.getIndex());
+// if (timeInterval != null) {
+// writeTimeInterval(xmlWriter, timeInterval);
+// }
+// }
+//
+// if (exportColors) {
+// writeEdgeColor(xmlWriter, edge);
+// }
+//
+// if (exportAttributes && edge.getEdgeData().getAttributes() != null) {
+// AttributeRow attributeRow = (AttributeRow) edge.getEdgeData().getAttributes();
+// writeAttValues(xmlWriter, attributeRow, visibleInterval);
+// }
+//
+// xmlWriter.writeEndElement();
+// Progress.progress(progress);
+// if (cancel) {
+// break;
+// }
+// }
+//
+// xmlWriter.writeEndElement();
+// }
+//
+// private void writeEdgeColor(XMLStreamWriter xmlWriter, Edge edge) throws Exception {
+// if (edge.getEdgeData().r() != -1) { //Edge has custom color
+// int r = Math.round(edge.getEdgeData().r() * 255f);
+// int g = Math.round(edge.getEdgeData().g() * 255f);
+// int b = Math.round(edge.getEdgeData().b() * 255f);
+// if (r != 0 || g != 0 || b != 0) {
+// xmlWriter.writeStartElement(VIZ, EDGE_COLOR, VIZ_NAMESPACE);
+// xmlWriter.writeAttribute("r", "" + r);
+// xmlWriter.writeAttribute("g", "" + g);
+// xmlWriter.writeAttribute("b", "" + b);
+// if (edge.getEdgeData().alpha() != 1f) {
+// xmlWriter.writeAttribute("a", "" + b);
+// }
+// xmlWriter.writeEndElement();
+// }
+// }
+// }
+//
+// private void calculateMinMax(Graph graph) {
+// minX = Float.POSITIVE_INFINITY;
+// maxX = Float.NEGATIVE_INFINITY;
+// minY = Float.POSITIVE_INFINITY;
+// maxY = Float.NEGATIVE_INFINITY;
+// minZ = Float.POSITIVE_INFINITY;
+// maxZ = Float.NEGATIVE_INFINITY;
+// minSize = Float.POSITIVE_INFINITY;
+// maxSize = Float.NEGATIVE_INFINITY;
+//
+// for (Node node : graph.getNodes()) {
+// NodeData nodeData = node.getNodeData();
+// minX = Math.min(minX, nodeData.x());
+// maxX = Math.max(maxX, nodeData.x());
+// minY = Math.min(minY, nodeData.y());
+// maxY = Math.max(maxY, nodeData.y());
+// minZ = Math.min(minZ, nodeData.z());
+// maxZ = Math.max(maxZ, nodeData.z());
+// minSize = Math.min(minSize, nodeData.getSize());
+// maxSize = Math.max(maxSize, nodeData.getSize());
+// }
+// }
+//
+// private String formatTime(double time) {
+// if (dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DATE)) {
+// String t = DynamicUtilities.getXMLDateStringFromDouble(time);
+// if (t.endsWith("T00:00:00.000")) {
+// t = t.substring(0, t.length() - 13);
+// }
+// return t;
+// } else if (dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DATETIME)) {
+// return DynamicUtilities.getXMLDateStringFromDouble(time);
+// } else {
+// return Double.toString(time);
+// }
+// }
+//
+ @Override
public boolean cancel() {
cancel = true;
return true;
}
+ @Override
public void setProgressTicket(ProgressTicket progressTicket) {
this.progress = progressTicket;
}
-
- public String getName() {
- return NbBundle.getMessage(getClass(), "ExporterGEXF_name");
- }
-
- public FileType[] getFileTypes() {
- FileType ft = new FileType(".gexf", NbBundle.getMessage(getClass(), "fileType_GEXF_Name"));
- return new FileType[]{ft};
- }
-
- private String getDateTime() {
- DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
- Date date = new Date();
- return dateFormat.format(date);
- }
+//
+// public String getName() {
+// return NbBundle.getMessage(getClass(), "ExporterGEXF_name");
+// }
+//
+// public FileType[] getFileTypes() {
+// FileType ft = new FileType(".gexf", NbBundle.getMessage(getClass(), "fileType_GEXF_Name"));
+// return new FileType[]{ft};
+// }
+//
+// private String getDateTime() {
+// DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+// Date date = new Date();
+// return dateFormat.format(date);
+// }
public void setExportAttributes(boolean exportAttributes) {
this.exportAttributes = exportAttributes;
@@ -736,6 +717,7 @@ public class ExporterGEXF implements GraphExporter, CharacterExporter, LongTask
return normalize;
}
+ @Override
public boolean isExportVisible() {
return exportVisible;
}
@@ -748,18 +730,22 @@ public class ExporterGEXF implements GraphExporter, CharacterExporter, LongTask
return exportHierarchy;
}
+ @Override
public void setExportVisible(boolean exportVisible) {
this.exportVisible = exportVisible;
}
+ @Override
public void setWriter(Writer writer) {
this.writer = writer;
}
+ @Override
public Workspace getWorkspace() {
return workspace;
}
+ @Override
public void setWorkspace(Workspace workspace) {
this.workspace = workspace;
}
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGML.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGML.java
index 87a9780f8565e0cd43375e1b2d7d4edaea8f1314..d85abf7507d9802654fd8836924e9acd3f520461 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGML.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGML.java
@@ -43,12 +43,11 @@ package org.gephi.io.exporter.plugin;
import java.io.IOException;
import java.io.Writer;
-import org.gephi.data.attributes.api.AttributeModel;
-import org.gephi.data.attributes.type.TimeInterval;
-import org.gephi.dynamic.DynamicUtilities;
-import org.gephi.dynamic.api.DynamicModel;
+import org.gephi.attribute.api.AttributeModel;
+import org.gephi.attribute.api.Column;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Graph;
+import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
import org.gephi.graph.api.Node;
import org.gephi.io.exporter.spi.CharacterExporter;
@@ -57,6 +56,7 @@ import org.gephi.project.api.Workspace;
import org.gephi.utils.longtask.spi.LongTask;
import org.gephi.utils.progress.ProgressTicket;
import org.openide.util.Exceptions;
+import org.openide.util.Lookup;
/**
*
@@ -66,11 +66,10 @@ public class ExporterGML implements GraphExporter, CharacterExporter, LongTask {
private boolean exportVisible = false;
private Workspace workspace;
- private Writer writer;
private GraphModel graphModel;
private AttributeModel attributeModel;
+ private Writer writer;
private ProgressTicket progressTicket;
- private TimeInterval visibleInterval;
private boolean cancel = false;
//options
private int spaces = 2;
@@ -79,6 +78,7 @@ public class ExporterGML implements GraphExporter, CharacterExporter, LongTask {
private boolean exportCoordinates = true;
private boolean exportNodeSize = true;
private boolean exportEdgeSize = true;
+ private boolean exportDynamicWeight = true;
private boolean exportColor = true;
private boolean exportNotRecognizedElements = true;
//data to normalize
@@ -87,9 +87,6 @@ public class ExporterGML implements GraphExporter, CharacterExporter, LongTask {
double minY, maxY;
double minZ, maxZ;
double minSize, maxSize;
-
- private double getLow;//borders for dynamic edge weight
- private double getHigh;
public boolean isNormalize() {
return normalize;
@@ -99,35 +96,29 @@ public class ExporterGML implements GraphExporter, CharacterExporter, LongTask {
this.normalize = normalize;
}
+ @Override
public void setExportVisible(boolean exportVisible) {
this.exportVisible = exportVisible;
}
+ @Override
public boolean isExportVisible() {
return exportVisible;
}
+ @Override
public boolean execute() {
- attributeModel = workspace.getLookup().lookup(AttributeModel.class);
- graphModel = workspace.getLookup().lookup(GraphModel.class);
- Graph graph;
+ GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
+ graphModel = graphController.getGraphModel(workspace);
+ attributeModel = graphController.getAttributeModel(workspace);
+ Graph graph = null;
if (exportVisible) {
graph = graphModel.getGraphVisible();
} else {
graph = graphModel.getGraph();
}
progressTicket.start(graph.getNodeCount() + graph.getEdgeCount());
- DynamicModel dynamicModel = workspace.getLookup().lookup(DynamicModel.class);
- visibleInterval = dynamicModel != null && exportVisible ? dynamicModel.getVisibleInterval() : new TimeInterval();
-
- getLow = Double.NEGATIVE_INFINITY;//whole interval, if graph is not dynamic
- getHigh = Double.POSITIVE_INFINITY;
- if (visibleInterval != null)
- {
- getLow = visibleInterval.getLow();
- getHigh = visibleInterval.getHigh();
- }
-
+
graph.readLock();
if (normalize) {
@@ -143,7 +134,7 @@ public class ExporterGML implements GraphExporter, CharacterExporter, LongTask {
graph.readUnlock();
return !cancel;
}
-
+
private void printOpen(String s) throws IOException {
for (int i = 0; i < currentSpaces; i++) {
writer.write(' ');
@@ -177,38 +168,42 @@ public class ExporterGML implements GraphExporter, CharacterExporter, LongTask {
private void exportData(Graph graph) throws IOException {
printOpen("graph");
printTag("Creator Gephi");
- if (graph.getGraphModel().isDirected()) {
+ if (graph.isDirected() || graph.isMixed()) {
printTag("directed 1");
- } else if (graph.getGraphModel().isUndirected()) {
+ } else if (graph.isUndirected()) {
printTag("directed 0");
}
for (Node node : graph.getNodes()) {
if (cancel) {
break;
}
- printNode(node);
+ printNode(node, graph);
}
for (Edge edge : graph.getEdges()) {
if (cancel) {
break;
}
- printEdge(edge, graph.getGraphModel().isMixed());
+ printEdge(edge, graph);
}
printClose();
}
- private void printEdge(Edge edge, boolean graphMixed) throws IOException {
+ private void printEdge(Edge edge, Graph graph) throws IOException {
printOpen("edge");
printTag("id " + edge.getId());
printTag("source " + edge.getSource().getId());
printTag("target " + edge.getTarget().getId());
- if (exportLabel && edge.getEdgeData().getLabel() != null) {
- printTag("label \"" + edge.getEdgeData().getLabel() + "\"");
+ if (exportLabel && edge.getLabel() != null) {
+ printTag("label \"" + edge.getLabel() + "\"");
}
if (exportEdgeSize) {
- printTag("value " + edge.getWeight(getLow, getHigh));
+ if (exportDynamicWeight) {
+ printTag("value " + edge.getWeight(graph.getView()));
+ } else {
+ printTag("value " + edge.getWeight());
+ }
}
- if (graphMixed) { //if graph not mixed, then all edges have the same direction, described earlier
+ if (graph.isMixed()) { //if graph not mixed, then all edges have the same direction, described earlier
if (edge.isDirected()) {
printTag("directed 1");
} else if (!edge.isDirected()) {
@@ -217,14 +212,12 @@ public class ExporterGML implements GraphExporter, CharacterExporter, LongTask {
}
if (exportNotRecognizedElements) {
- for (int i = 0; i < edge.getAttributes().countValues(); i++) {
- String s = attributeModel.getEdgeTable().getColumn(i).getTitle();
- //don't print again standart attributes
- if (edge.getAttributes().getValue(i) != null && !s.equals("Weight")
- && !s.equals("Id") && !s.equals("Time Interval")
- && DynamicUtilities.getDynamicValue(edge.getAttributes().getValue(i),
- visibleInterval.getLow(), visibleInterval.getHigh()) != null) {
- printTag(formatTitle(s) + " \"" + formatValue(edge.getAttributes().getValue(i)) + "\"");
+ for (Column col : attributeModel.getEdgeTable()) {
+ if (!col.isProperty()) {
+ Object value = edge.getAttribute(col, graph.getView());
+ if (value != null) {
+ printTag(formatTitle(col.getTitle()) + " \"" + formatValue(value) + "\"");
+ }
}
}
}
@@ -233,51 +226,48 @@ public class ExporterGML implements GraphExporter, CharacterExporter, LongTask {
progressTicket.progress();
}
- private void printNode(Node node) throws IOException {
+ private void printNode(Node node, Graph graph) throws IOException {
printOpen("node");
printTag("id " + node.getId());
- if (exportLabel && node.getNodeData().getLabel() != null) {
- printTag("label \"" + node.getNodeData().getLabel() + "\"");
+ if (exportLabel && node.getLabel() != null) {
+ printTag("label \"" + node.getLabel() + "\"");
}
if (exportCoordinates || exportNodeSize || exportColor) {
printOpen("graphics");
if (exportCoordinates) {
if (!normalize) {
- printTag("x " + node.getNodeData().x());
- printTag("y " + node.getNodeData().y());
- printTag("z " + node.getNodeData().z());
+ printTag("x " + node.x());
+ printTag("y " + node.y());
+ printTag("z " + node.z());
} else {
- printTag("x " + (node.getNodeData().x() - minX) / (maxX - minX));
- printTag("y " + (node.getNodeData().y() - minY) / (maxY - minY));
- printTag("z " + (node.getNodeData().z() - minZ) / (maxZ - minZ));
+ printTag("x " + (node.x() - minX) / (maxX - minX));
+ printTag("y " + (node.y() - minY) / (maxY - minY));
+ printTag("z " + (node.z() - minZ) / (maxZ - minZ));
}
}
if (exportNodeSize) {
if (!normalize) {
- printTag("w " + node.getNodeData().getSize());
- printTag("h " + node.getNodeData().getSize());
- printTag("d " + node.getNodeData().getSize());
+ printTag("w " + node.size());
+ printTag("h " + node.size());
+ printTag("d " + node.size());
} else {
- printTag("w " + (node.getNodeData().getSize() - minSize) / (maxSize - minSize));
- printTag("h " + (node.getNodeData().getSize() - minSize) / (maxSize - minSize));
- printTag("d " + (node.getNodeData().getSize() - minSize) / (maxSize - minSize));
+ printTag("w " + (node.size() - minSize) / (maxSize - minSize));
+ printTag("h " + (node.size() - minSize) / (maxSize - minSize));
+ printTag("d " + (node.size() - minSize) / (maxSize - minSize));
}
}
if (exportColor) {
- printTag("fill \"#" + Integer.toString((int) (node.getNodeData().r() * 255), 16)
- + Integer.toString((int) (node.getNodeData().g() * 255), 16) + Integer.toString((int) (node.getNodeData().b() * 255), 16) + "\"");
+ printTag("fill \"#" + Integer.toString((int) (node.r() * 255), 16)
+ + Integer.toString((int) (node.g() * 255), 16) + Integer.toString((int) (node.b() * 255), 16) + "\"");
}
printClose();
}
if (exportNotRecognizedElements) {
- for (int i = 0; i < node.getAttributes().countValues(); i++) {
- if (node.getAttributes().getValue(i) != null) {
- String s = attributeModel.getNodeTable().getColumn(i).getTitle();
- //don't print again standart attributes
- if (!s.equals("d") && !s.equals("Label") && !s.equals("Id") && !s.equals("Time Interval")
- && DynamicUtilities.getDynamicValue(node.getAttributes().getValue(i),
- visibleInterval.getLow(), visibleInterval.getHigh()) != null) {
- printTag(formatTitle(s) + " \"" + formatValue(node.getAttributes().getValue(i)) + "\"");
+ for (Column col : attributeModel.getNodeTable()) {
+ if (!col.isProperty()) {
+ Object value = node.getAttribute(col, graph.getView());
+ if (value != null) {
+ printTag(formatTitle(col.getTitle()) + " \"" + formatValue(value) + "\"");
}
}
}
@@ -286,23 +276,28 @@ public class ExporterGML implements GraphExporter, CharacterExporter, LongTask {
progressTicket.progress();
}
+ @Override
public void setWorkspace(Workspace workspace) {
this.workspace = workspace;
}
+ @Override
public Workspace getWorkspace() {
return workspace;
}
+ @Override
public void setWriter(Writer writer) {
this.writer = writer;
}
+ @Override
public boolean cancel() {
cancel = true;
return true;
}
+ @Override
public void setProgressTicket(ProgressTicket progressTicket) {
this.progressTicket = progressTicket;
}
@@ -378,16 +373,16 @@ public class ExporterGML implements GraphExporter, CharacterExporter, LongTask {
if (cancel) {
break;
}
- minX = Math.min(minX, node.getNodeData().x());
- minY = Math.min(minY, node.getNodeData().y());
- minZ = Math.min(minZ, node.getNodeData().z());
+ minX = Math.min(minX, node.x());
+ minY = Math.min(minY, node.y());
+ minZ = Math.min(minZ, node.z());
- maxX = Math.max(maxX, node.getNodeData().x());
- maxY = Math.max(maxY, node.getNodeData().y());
- maxZ = Math.max(maxZ, node.getNodeData().z());
+ maxX = Math.max(maxX, node.x());
+ maxY = Math.max(maxY, node.y());
+ maxZ = Math.max(maxZ, node.z());
- minSize = Math.min(minSize, node.getNodeData().getSize());
- maxSize = Math.max(maxSize, node.getNodeData().getSize());
+ minSize = Math.min(minSize, node.size());
+ maxSize = Math.max(maxSize, node.size());
}
}
@@ -403,14 +398,7 @@ public class ExporterGML implements GraphExporter, CharacterExporter, LongTask {
}
private String formatValue(Object obj) {
- System.err.println("tos " + obj.toString());
- String res;
- if (visibleInterval != null) {
- //dynamic value could be null, if it doesn't exist in visibleInterval, but such cases are filtered higher
- res = DynamicUtilities.getDynamicValue(obj, visibleInterval.getLow(), visibleInterval.getHigh()).toString();
- } else {
- res = obj.toString();
- }
+ String res = obj.toString();
return res.replace("\r\n", " ").replace("\n", " ").replace('\"', ' ');//remove " and line feeds
}
-}
\ No newline at end of file
+}
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGraphML.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGraphML.java
index 35ada9b4ac851c67e332a2f32f2c6b6bc61ee4c0..597bc18d7c910c3495e9349ac74ab98c91a8896f 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGraphML.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterGraphML.java
@@ -1,48 +1,47 @@
/*
-Copyright 2008-2010 Gephi
-Authors : Mathieu Bastian ,
-Sebastien Heymann
-Website : http://www.gephi.org
-
-This file is part of Gephi.
-
-DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
-
-Copyright 2011 Gephi Consortium. All rights reserved.
-
-The contents of this file are subject to the terms of either the GNU
-General Public License Version 3 only ("GPL") or the Common
-Development and Distribution License("CDDL") (collectively, the
-"License"). You may not use this file except in compliance with the
-License. You can obtain a copy of the License at
-http://gephi.org/about/legal/license-notice/
-or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
-specific language governing permissions and limitations under the
-License. When distributing the software, include this License Header
-Notice in each file and include the License files at
-/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
-License Header, with the fields enclosed by brackets [] replaced by
-your own identifying information:
-"Portions Copyrighted [year] [name of copyright owner]"
-
-If you wish your version of this file to be governed by only the CDDL
-or only the GPL Version 3, indicate your decision by adding
-"[Contributor] elects to include this software in this distribution
-under the [CDDL or GPL Version 3] license." If you do not indicate a
-single choice of license, a recipient has the option to distribute
-your version of this file under either the CDDL, the GPL Version 3 or
-to extend the choice of license to its licensees as provided above.
-However, if you add GPL Version 3 code and therefore, elected the GPL
-Version 3 license, then the option applies only if the new code is
-made subject to such option by the copyright holder.
-
-Contributor(s):
-
-Portions Copyrighted 2011 Gephi Consortium.
+ Copyright 2008-2010 Gephi
+ Authors : Mathieu Bastian ,
+ Sebastien Heymann
+ Website : http://www.gephi.org
+
+ This file is part of Gephi.
+
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+
+ Copyright 2011 Gephi Consortium. All rights reserved.
+
+ The contents of this file are subject to the terms of either the GNU
+ General Public License Version 3 only ("GPL") or the Common
+ Development and Distribution License("CDDL") (collectively, the
+ "License"). You may not use this file except in compliance with the
+ License. You can obtain a copy of the License at
+ http://gephi.org/about/legal/license-notice/
+ or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
+ specific language governing permissions and limitations under the
+ License. When distributing the software, include this License Header
+ Notice in each file and include the License files at
+ /cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
+ License Header, with the fields enclosed by brackets [] replaced by
+ your own identifying information:
+ "Portions Copyrighted [year] [name of copyright owner]"
+
+ If you wish your version of this file to be governed by only the CDDL
+ or only the GPL Version 3, indicate your decision by adding
+ "[Contributor] elects to include this software in this distribution
+ under the [CDDL or GPL Version 3] license." If you do not indicate a
+ single choice of license, a recipient has the option to distribute
+ your version of this file under either the CDDL, the GPL Version 3 or
+ to extend the choice of license to its licensees as provided above.
+ However, if you add GPL Version 3 code and therefore, elected the GPL
+ Version 3 license, then the option applies only if the new code is
+ made subject to such option by the copyright holder.
+
+ Contributor(s):
+
+ Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.io.exporter.plugin;
-import java.awt.Color;
import java.io.Writer;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -56,26 +55,22 @@ import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import org.gephi.data.attributes.api.AttributeColumn;
-import org.gephi.data.attributes.api.AttributeModel;
-import org.gephi.data.attributes.api.AttributeOrigin;
-import org.gephi.data.attributes.type.TimeInterval;
-import org.gephi.dynamic.DynamicUtilities;
-import org.gephi.dynamic.api.DynamicModel;
+import org.gephi.attribute.api.AttributeModel;
+import org.gephi.attribute.api.AttributeUtils;
+import org.gephi.attribute.api.Column;
import org.gephi.graph.api.Edge;
-import org.gephi.graph.api.EdgeIterable;
import org.gephi.graph.api.Graph;
+import org.gephi.graph.api.GraphController;
import org.gephi.graph.api.GraphModel;
-import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.graph.api.Node;
-import org.gephi.graph.api.NodeData;
import org.gephi.io.exporter.api.FileType;
-import org.gephi.io.exporter.spi.GraphExporter;
import org.gephi.io.exporter.spi.CharacterExporter;
+import org.gephi.io.exporter.spi.GraphExporter;
import org.gephi.project.api.Workspace;
import org.gephi.utils.longtask.spi.LongTask;
import org.gephi.utils.progress.Progress;
import org.gephi.utils.progress.ProgressTicket;
+import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -100,8 +95,8 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
private boolean exportColors = true;
private boolean exportPosition = true;
private boolean exportSize = true;
+ private boolean exportDynamicWeight = true;
private boolean exportAttributes = true;
- private boolean exportHierarchy = false;
//Settings Helper
private float minSize;
private float maxSize;
@@ -111,20 +106,17 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
private float maxY;
private float minZ;
private float maxZ;
- //Dynamic
- private TimeInterval visibleInterval;
+ @Override
public boolean execute() {
- attributeModel = workspace.getLookup().lookup(AttributeModel.class);
- graphModel = workspace.getLookup().lookup(GraphModel.class);
- HierarchicalGraph graph = null;
+ GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
+ graphModel = graphController.getGraphModel(workspace);
+ Graph graph = null;
if (exportVisible) {
- graph = graphModel.getHierarchicalGraphVisible();
+ graph = graphModel.getGraphVisible();
} else {
- graph = graphModel.getHierarchicalGraph();
+ graph = graphModel.getGraph();
}
- DynamicModel dynamicModel = workspace.getLookup().lookup(DynamicModel.class);
- visibleInterval = dynamicModel != null && exportVisible ? dynamicModel.getVisibleInterval() : new TimeInterval();
try {
exportData(createDocument(), graph, attributeModel);
} catch (Exception e) {
@@ -154,19 +146,19 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
}
/*
- public Schema getSchema() {
- try {
- SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- return sf.newSchema(new URL("http://www.gexf.net/1.1draft/gexf.xsd"));
- } catch (MalformedURLException ex) {
- Exceptions.printStackTrace(ex);
- } catch (SAXException ex) {
- Exceptions.printStackTrace(ex);
- }
- return null;
- }
+ public Schema getSchema() {
+ try {
+ SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ return sf.newSchema(new URL("http://www.gexf.net/1.1draft/gexf.xsd"));
+ } catch (MalformedURLException ex) {
+ Exceptions.printStackTrace(ex);
+ } catch (SAXException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ return null;
+ }
*/
- public boolean exportData(Document document, HierarchicalGraph graph, AttributeModel model) throws Exception {
+ public boolean exportData(Document document, Graph graph, AttributeModel model) throws Exception {
Progress.start(progressTicket);
graph.readLock();
@@ -175,13 +167,8 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
calculateMinMax(graph);
//Calculate progress units count
- int max;
- if (graphModel.isHierarchical()) {
- HierarchicalGraph hgraph = graphModel.getHierarchicalGraph();
- max = hgraph.getNodeCount() + hgraph.getEdgeCount();
- } else {
- max = graph.getNodeCount() + graph.getEdgeCount();
- }
+ int max = graph.getNodeCount() + graph.getEdgeCount();
+
Progress.switchToDeterminate(progressTicket, max);
Element root = document.createElementNS("http://graphml.graphdrawing.org/xmlns", "graphml");
@@ -268,7 +255,7 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
positionKey2E.setAttribute("attr.type", "float");
positionKey2E.setAttribute("for", "node");
root.appendChild(positionKey2E);
-
+
if (minZ != 0f || maxZ != 0f) {
Element positionKey3E = document.createElement("key");
positionKey3E.setAttribute("id", "z");
@@ -291,16 +278,16 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
//Attributes
if (attributeModel != null && exportAttributes) {
//Node attributes
- for (AttributeColumn column : attributeModel.getNodeTable().getColumns()) {
- if (!column.getOrigin().equals(AttributeOrigin.PROPERTY)) {
+ for (Column column : attributeModel.getNodeTable()) {
+ if (!column.isProperty()) {
Element attributeE = createAttribute(document, column);
attributeE.setAttribute("for", "node");
root.appendChild(attributeE);
}
}
- for (AttributeColumn column : attributeModel.getEdgeTable().getColumns()) {
- if (!column.getOrigin().equals(AttributeOrigin.PROPERTY)) {
+ for (Column column : attributeModel.getEdgeTable()) {
+ if (!column.isProperty()) {
//Data or computed
Element attributeE = createAttribute(document, column);
attributeE.setAttribute("for", "edge");
@@ -313,14 +300,14 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
private Element createGraph(Document document, Graph graph) throws Exception {
Element graphE = document.createElement("graph");
- if (graphModel.isDirected()) {
+ if (graphModel.isDirected() || graphModel.isMixed()) {
graphE.setAttribute("edgedefault", "directed");
} else {
graphE.setAttribute("edgedefault", "undirected"); // defaultValue
}
//Nodes
- createNodes(document, graphE, graph, null);
+ createNodes(document, graphE, graph);
//Edges
createEdges(document, graphE, graph);
@@ -328,17 +315,16 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
return graphE;
}
- private Element createAttribute(Document document, AttributeColumn column) {
+ private Element createAttribute(Document document, Column column) {
Element attributeE = document.createElement("key");
attributeE.setAttribute("id", column.getId());
attributeE.setAttribute("attr.name", column.getTitle());
- switch (column.getType()) {
- case INT:
- attributeE.setAttribute("attr.type", "int");
- break;
- default:
- attributeE.setAttribute("attr.type", column.getType().getTypeString().toLowerCase());
- break;
+ if (column.getTypeClass().equals(Integer.class)
+ || column.getTypeClass().equals(Short.class)
+ || column.getTypeClass().equals(Byte.class)) {
+ attributeE.setAttribute("attr.type", "int");
+ } else {
+ attributeE.setAttribute("attr.type", AttributeUtils.getTypeName(column.getTypeClass()));
}
if (column.getDefaultValue() != null) {
Element defaultE = document.createElement("default");
@@ -348,11 +334,9 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
return attributeE;
}
- private Element createNodeAttvalue(Document document, AttributeColumn column, Node n) throws Exception {
- int index = column.getIndex();
- if (n.getNodeData().getAttributes().getValue(index) != null) {
- Object val = n.getNodeData().getAttributes().getValue(index);
- val = DynamicUtilities.getDynamicValue(val, visibleInterval.getLow(), visibleInterval.getHigh());
+ private Element createNodeAttvalue(Document document, Column column, Graph graph, Node n) throws Exception {
+ Object val = n.getAttribute(column, graph.getView());
+ if (val != null) {
String value = val.toString();
String id = column.getId();
@@ -364,11 +348,9 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
return null;
}
- private Element createEdgeAttvalue(Document document, AttributeColumn column, Edge e) throws Exception {
- int index = column.getIndex();
- if (e.getEdgeData().getAttributes().getValue(index) != null) {
- Object val = e.getEdgeData().getAttributes().getValue(index);
- val = DynamicUtilities.getDynamicValue(val, visibleInterval.getLow(), visibleInterval.getHigh());
+ private Element createEdgeAttvalue(Document document, Column column, Graph graph, Edge e) throws Exception {
+ Object val = e.getAttribute(column, graph.getView());
+ if (val != null) {
String value = val.toString();
String id = column.getId();
@@ -380,58 +362,33 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
return null;
}
- private void createNodes(Document document, Element parentE, Graph graph, Node nodeParent) throws Exception {
-
- if (nodeParent != null) {
- Element graphE = document.createElement("graph");
-
- if (graphModel.isDirected()) {
- graphE.setAttribute("edgedefault", "directed");
- } else {
- graphE.setAttribute("edgedefault", "undirected"); // defaultValue
- }
- // we are inside the tree
- HierarchicalGraph hgraph = graphModel.getHierarchicalGraph();
- for (Node n : hgraph.getChildren(nodeParent)) {
- Element childE = createNode(document, graph, n);
- graphE.appendChild(childE);
- }
- parentE.appendChild(graphE);
- } else if (exportHierarchy && graphModel.isHierarchical()) {
- // we are on the top of the tree
- HierarchicalGraph hgraph = graphModel.getHierarchicalGraph();
- for (Node n : hgraph.getTopNodes()) {
- Element nodeE = createNode(document, hgraph, n);
- parentE.appendChild(nodeE);
- }
- } else {
- // there is no tree
- for (Node n : graph.getNodes()) {
- if (cancel) {
- break;
- }
- Element nodeE = createNode(document, graph, n);
- parentE.appendChild(nodeE);
+ private void createNodes(Document document, Element parentE, Graph graph) throws Exception {
+ // there is no tree
+ for (Node n : graph.getNodes()) {
+ if (cancel) {
+ break;
}
+ Element nodeE = createNode(document, graph, n);
+ parentE.appendChild(nodeE);
}
}
private Element createNode(Document document, Graph graph, Node n) throws Exception {
Element nodeE = document.createElement("node");
- nodeE.setAttribute("id", n.getNodeData().getId());
+ nodeE.setAttribute("id", n.getId().toString());
//Label
- if (n.getNodeData().getLabel() != null && !n.getNodeData().getLabel().isEmpty()) {
+ if (n.getLabel() != null && !n.getLabel().isEmpty()) {
Element labelE = createNodeLabel(document, n);
nodeE.appendChild(labelE);
}
//Attribute values
if (attributeModel != null && exportAttributes) {
- for (AttributeColumn column : attributeModel.getNodeTable().getColumns()) {
- if (!column.getOrigin().equals(AttributeOrigin.PROPERTY)) {
+ for (Column column : attributeModel.getNodeTable()) {
+ if (!column.isProperty()) {
//Data or computed
- Element attvalueE = createNodeAttvalue(document, column, n);
+ Element attvalueE = createNodeAttvalue(document, column, graph, n);
if (attvalueE != null) {
nodeE.appendChild(attvalueE);
}
@@ -465,55 +422,39 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
}
}
- //Hierarchy
- if (exportHierarchy && graphModel.isHierarchical()) {
- HierarchicalGraph hgraph = graphModel.getHierarchicalGraph();
- int childCount = hgraph.getChildrenCount(n);
- if (childCount != 0) {
- createNodes(document, nodeE, graph, n);
- }
- }
Progress.progress(progressTicket);
return nodeE;
}
private void createEdges(Document document, Element edgesE, Graph graph) throws Exception {
-
- EdgeIterable it;
- HierarchicalGraph hgraph = graphModel.getHierarchicalGraph();
- if (exportHierarchy && graphModel.isHierarchical()) {
- it = hgraph.getEdgesTree();
- } else {
- it = hgraph.getEdgesAndMetaEdges();
- }
- for (Edge e : it.toArray()) {
+ for (Edge e : graph.getEdges()) {
if (cancel) {
break;
}
- Element edgeE = createEdge(document, e);
+ Element edgeE = createEdge(document, e, graph);
edgesE.appendChild(edgeE);
}
}
- private Element createEdge(Document document, Edge e) throws Exception {
+ private Element createEdge(Document document, Edge e, Graph graph) throws Exception {
Element edgeE = document.createElement("edge");
- edgeE.setAttribute("source", e.getSource().getNodeData().getId());
- edgeE.setAttribute("target", e.getTarget().getNodeData().getId());
+ edgeE.setAttribute("source", e.getSource().getId().toString());
+ edgeE.setAttribute("target", e.getTarget().getId().toString());
- if (e.getEdgeData().getId() != null && !e.getEdgeData().getId().isEmpty() && !String.valueOf(e.getId()).equals(e.getEdgeData().getId())) {
+ if (e.getId() != null && !e.getId().toString().isEmpty() && !String.valueOf(e.getId()).equals(e.getId())) {
Element idE = createEdgeId(document, e);
edgeE.appendChild(idE);
}
//Label
- if (e.getEdgeData().getLabel() != null && !e.getEdgeData().getLabel().isEmpty()) {
+ if (e.getLabel() != null && !e.getLabel().isEmpty()) {
Element labelE = createEdgeLabel(document, e);
edgeE.appendChild(labelE);
}
- Element weightE = createEdgeWeight(document, e);
+ Element weightE = createEdgeWeight(document, e, graph);
edgeE.appendChild(weightE);
if (e.isDirected() && !graphModel.isDirected()) {
@@ -524,10 +465,10 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
//Attribute values
if (attributeModel != null) {
- for (AttributeColumn column : attributeModel.getEdgeTable().getColumns()) {
- if (!column.getOrigin().equals(AttributeOrigin.PROPERTY)) {
+ for (Column column : attributeModel.getEdgeTable()) {
+ if (!column.isProperty()) {
//Data or computed
- Element attvalueE = createEdgeAttvalue(document, column, e);
+ Element attvalueE = createEdgeAttvalue(document, column, graph, e);
if (attvalueE != null) {
edgeE.appendChild(attvalueE);
}
@@ -541,7 +482,7 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
private Element createNodeSize(Document document, Node n) throws Exception {
Element sizeE = document.createElement("data");
- float size = n.getNodeData().getSize();
+ float size = n.size();
if (normalize) {
size = (size - minSize) / (maxSize - minSize);
}
@@ -552,7 +493,7 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
}
private Element createNodeColorR(Document document, Node n) throws Exception {
- int r = Math.round(n.getNodeData().r() * 255f);
+ int r = Math.round(n.r() * 255f);
Element colorE = document.createElement("data");
colorE.setAttribute("key", "r");
colorE.setTextContent("" + r);
@@ -560,7 +501,7 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
}
private Element createNodeColorG(Document document, Node n) throws Exception {
- int g = Math.round(n.getNodeData().g() * 255f);
+ int g = Math.round(n.g() * 255f);
Element colorE = document.createElement("data");
colorE.setAttribute("key", "g");
colorE.setTextContent("" + g);
@@ -568,7 +509,7 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
}
private Element createNodeColorB(Document document, Node n) throws Exception {
- int b = Math.round(n.getNodeData().b() * 255f);
+ int b = Math.round(n.b() * 255f);
Element colorE = document.createElement("data");
colorE.setAttribute("key", "b");
colorE.setTextContent("" + b);
@@ -577,7 +518,7 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
private Element createNodePositionX(Document document, Node n) throws Exception {
Element positionXE = document.createElement("data");
- float x = n.getNodeData().x();
+ float x = n.x();
if (normalize && x != 0.0) {
x = (x - minX) / (maxX - minX);
}
@@ -588,7 +529,7 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
private Element createNodePositionY(Document document, Node n) throws Exception {
Element positionYE = document.createElement("data");
- float y = n.getNodeData().y();
+ float y = n.y();
if (normalize && y != 0.0) {
y = (y - minY) / (maxY - minY);
}
@@ -600,7 +541,7 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
private Element createNodePositionZ(Document document, Node n) throws Exception {
Element positionZE = document.createElement("data");
- float z = n.getNodeData().z();
+ float z = n.z();
if (normalize && z != 0.0) {
z = (z - minZ) / (maxZ - minZ);
}
@@ -613,7 +554,7 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
private Element createNodeLabel(Document document, Node n) throws Exception {
Element labelE = document.createElement("data");
labelE.setAttribute("key", "label");
- labelE.setTextContent(n.getNodeData().getLabel());
+ labelE.setTextContent(n.getLabel());
return labelE;
}
@@ -621,15 +562,21 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
private Element createEdgeId(Document document, Edge e) throws Exception {
Element idE = document.createElement("data");
idE.setAttribute("key", "edgeid");
- idE.setTextContent(e.getEdgeData().getId());
+ idE.setTextContent(e.getId().toString());
return idE;
}
- private Element createEdgeWeight(Document document, Edge e) throws Exception {
+ private Element createEdgeWeight(Document document, Edge e, Graph graph) throws Exception {
Element weightE = document.createElement("data");
weightE.setAttribute("key", "weight");
- weightE.setTextContent(Float.toString(e.getWeight(visibleInterval.getLow(), visibleInterval.getHigh())));
+ Double weight;
+ if (exportDynamicWeight) {
+ weight = e.getWeight(graph.getView());
+ } else {
+ weight = e.getWeight();
+ }
+ weightE.setTextContent(weight.toString());
return weightE;
}
@@ -637,7 +584,7 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
private Element createEdgeLabel(Document document, Edge e) throws Exception {
Element labelE = document.createElement("data");
labelE.setAttribute("key", "edgelabel");
- labelE.setTextContent(e.getEdgeData().getLabel());
+ labelE.setTextContent(e.getLabel());
return labelE;
}
@@ -653,23 +600,24 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
maxSize = Float.NEGATIVE_INFINITY;
for (Node node : graph.getNodes()) {
- NodeData nodeData = node.getNodeData();
- minX = Math.min(minX, nodeData.x());
- maxX = Math.max(maxX, nodeData.x());
- minY = Math.min(minY, nodeData.y());
- maxY = Math.max(maxY, nodeData.y());
- minZ = Math.min(minZ, nodeData.z());
- maxZ = Math.max(maxZ, nodeData.z());
- minSize = Math.min(minSize, nodeData.getSize());
- maxSize = Math.max(maxSize, nodeData.getSize());
+ minX = Math.min(minX, node.x());
+ maxX = Math.max(maxX, node.x());
+ minY = Math.min(minY, node.y());
+ maxY = Math.max(maxY, node.y());
+ minZ = Math.min(minZ, node.z());
+ maxZ = Math.max(maxZ, node.z());
+ minSize = Math.min(minSize, node.size());
+ maxSize = Math.max(maxSize, node.size());
}
}
+ @Override
public boolean cancel() {
cancel = true;
return true;
}
+ @Override
public void setProgressTicket(ProgressTicket progressTicket) {
this.progressTicket = progressTicket;
}
@@ -723,31 +671,28 @@ public class ExporterGraphML implements GraphExporter, CharacterExporter, LongTa
return normalize;
}
+ @Override
public boolean isExportVisible() {
return exportVisible;
}
+ @Override
public void setExportVisible(boolean exportVisible) {
this.exportVisible = exportVisible;
}
+ @Override
public void setWriter(Writer writer) {
this.writer = writer;
}
+ @Override
public Workspace getWorkspace() {
return workspace;
}
+ @Override
public void setWorkspace(Workspace workspace) {
this.workspace = workspace;
}
-
- public boolean isExportHierarchy() {
- return exportHierarchy;
- }
-
- public void setExportHierarchy(boolean exportHierarchy) {
- this.exportHierarchy = exportHierarchy;
- }
}
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterPajek.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterPajek.java
index 554c668806bc74181faf387c9cd84c8688665881..759c5e232e5fa37dd1a01cd4fa47ff96310c6fc0 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterPajek.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterPajek.java
@@ -1,51 +1,51 @@
/*
-Copyright 2008-2011 Gephi
-Authors : Daniel Bernardes
-Website : http://www.gephi.org
-
-This file is part of Gephi.
-
-DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
-
-Copyright 2011 Gephi Consortium. All rights reserved.
-
-The contents of this file are subject to the terms of either the GNU
-General Public License Version 3 only ("GPL") or the Common
-Development and Distribution License("CDDL") (collectively, the
-"License"). You may not use this file except in compliance with the
-License. You can obtain a copy of the License at
-http://gephi.org/about/legal/license-notice/
-or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
-specific language governing permissions and limitations under the
-License. When distributing the software, include this License Header
-Notice in each file and include the License files at
-/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
-License Header, with the fields enclosed by brackets [] replaced by
-your own identifying information:
-"Portions Copyrighted [year] [name of copyright owner]"
-
-If you wish your version of this file to be governed by only the CDDL
-or only the GPL Version 3, indicate your decision by adding
-"[Contributor] elects to include this software in this distribution
-under the [CDDL or GPL Version 3] license." If you do not indicate a
-single choice of license, a recipient has the option to distribute
-your version of this file under either the CDDL, the GPL Version 3 or
-to extend the choice of license to its licensees as provided above.
-However, if you add GPL Version 3 code and therefore, elected the GPL
-Version 3 license, then the option applies only if the new code is
-made subject to such option by the copyright holder.
-
-Contributor(s):
-
-Portions Copyrighted 2011 Gephi Consortium.
+ Copyright 2008-2011 Gephi
+ Authors : Daniel Bernardes
+ Website : http://www.gephi.org
+
+ This file is part of Gephi.
+
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+
+ Copyright 2011 Gephi Consortium. All rights reserved.
+
+ The contents of this file are subject to the terms of either the GNU
+ General Public License Version 3 only ("GPL") or the Common
+ Development and Distribution License("CDDL") (collectively, the
+ "License"). You may not use this file except in compliance with the
+ License. You can obtain a copy of the License at
+ http://gephi.org/about/legal/license-notice/
+ or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
+ specific language governing permissions and limitations under the
+ License. When distributing the software, include this License Header
+ Notice in each file and include the License files at
+ /cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
+ License Header, with the fields enclosed by brackets [] replaced by
+ your own identifying information:
+ "Portions Copyrighted [year] [name of copyright owner]"
+
+ If you wish your version of this file to be governed by only the CDDL
+ or only the GPL Version 3, indicate your decision by adding
+ "[Contributor] elects to include this software in this distribution
+ under the [CDDL or GPL Version 3] license." If you do not indicate a
+ single choice of license, a recipient has the option to distribute
+ your version of this file under either the CDDL, the GPL Version 3 or
+ to extend the choice of license to its licensees as provided above.
+ However, if you add GPL Version 3 code and therefore, elected the GPL
+ Version 3 license, then the option applies only if the new code is
+ made subject to such option by the copyright holder.
+
+ Contributor(s):
+
+ Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.io.exporter.plugin;
import java.io.Writer;
import java.util.HashMap;
import org.gephi.graph.api.Edge;
+import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphModel;
-import org.gephi.graph.api.HierarchicalGraph;
import org.gephi.graph.api.Node;
import org.gephi.graph.api.UndirectedGraph;
import org.gephi.io.exporter.api.FileType;
@@ -72,11 +72,11 @@ public class ExporterPajek implements GraphExporter, CharacterExporter, LongTask
private boolean exportVisible;
private boolean cancel = false;
private ProgressTicket progressTicket;
-
+
public void setExportEdgeWeight(boolean exportEdgeWeight) {
this.exportEdgeWeight = exportEdgeWeight;
}
-
+
public boolean isExportEdgeWeight() {
return exportEdgeWeight;
}
@@ -84,40 +84,47 @@ public class ExporterPajek implements GraphExporter, CharacterExporter, LongTask
public void setExportPosition(boolean exportPosition) {
this.exportPosition = exportPosition;
}
-
+
public boolean isExportPosition() {
return exportPosition;
}
-
+
+ @Override
public boolean cancel() {
cancel = true;
return true;
}
+ @Override
public void setProgressTicket(ProgressTicket progressTicket) {
this.progressTicket = progressTicket;
}
+ @Override
public boolean isExportVisible() {
return exportVisible;
}
+ @Override
public void setExportVisible(boolean exportVisible) {
this.exportVisible = exportVisible;
}
+ @Override
public void setWriter(Writer writer) {
this.writer = writer;
}
+ @Override
public Workspace getWorkspace() {
return workspace;
}
+ @Override
public void setWorkspace(Workspace workspace) {
this.workspace = workspace;
}
-
+
public String getName() {
return NbBundle.getMessage(getClass(), "ExporterPajek_name");
}
@@ -127,13 +134,14 @@ public class ExporterPajek implements GraphExporter, CharacterExporter, LongTask
return new FileType[]{ft};
}
+ @Override
public boolean execute() {
GraphModel graphModel = workspace.getLookup().lookup(GraphModel.class);
- HierarchicalGraph graph = null;
+ Graph graph = null;
if (exportVisible) {
- graph = graphModel.getHierarchicalGraphVisible();
+ graph = graphModel.getGraphVisible();
} else {
- graph = graphModel.getHierarchicalGraph();
+ graph = graphModel.getGraph();
}
try {
exportData(graph);
@@ -144,9 +152,9 @@ public class ExporterPajek implements GraphExporter, CharacterExporter, LongTask
return !cancel;
}
- private void exportData(HierarchicalGraph graph) throws Exception {
- int max = graph.getNodeCount(), i=1;
- HashMap idx = new HashMap(3*max/2+1);
+ private void exportData(Graph graph) throws Exception {
+ int max = graph.getNodeCount(), i = 1;
+ HashMap idx = new HashMap(3 * max / 2 + 1);
Progress.start(progressTicket, max);
graph.readLock();
@@ -155,12 +163,12 @@ public class ExporterPajek implements GraphExporter, CharacterExporter, LongTask
for (Node node : graph.getNodes()) {
writer.append(Integer.toString(i));
- writer.append(" \"" + node.getNodeData().getLabel() + "\"");
- if(exportPosition) {
- writer.append(" "+node.getNodeData().x()+" "+node.getNodeData().y()+" "+node.getNodeData().z());
+ writer.append(" \"" + node.getLabel() + "\"");
+ if (exportPosition) {
+ writer.append(" " + node.x() + " " + node.y() + " " + node.z());
}
writer.append("\n");
- idx.put(node.getNodeData().getId(), i++); // assigns Ids from the interval [1..max]
+ idx.put(node.getId().toString(), i++); // assigns Ids from the interval [1..max]
}
if (graph instanceof UndirectedGraph) {
@@ -169,13 +177,13 @@ public class ExporterPajek implements GraphExporter, CharacterExporter, LongTask
writer.append("*Arcs\n");
}
- for (Edge edge : graph.getEdgesAndMetaEdges()) {
+ for (Edge edge : graph.getEdges()) {
if (cancel) {
break;
}
if (edge != null) {
- writer.append(Integer.toString(idx.get(edge.getSource().getNodeData().getId())) + " ");
- writer.append(Integer.toString(idx.get(edge.getTarget().getNodeData().getId())));
+ writer.append(Integer.toString(idx.get(edge.getSource().getId().toString())) + " ");
+ writer.append(Integer.toString(idx.get(edge.getTarget().getId().toString())));
if (exportEdgeWeight) {
writer.append(" " + edge.getWeight());
}
@@ -189,5 +197,4 @@ public class ExporterPajek implements GraphExporter, CharacterExporter, LongTask
Progress.finish(progressTicket);
}
-
}
diff --git a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterVNA.java b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterVNA.java
index c14968ae3bf329c2aee9f1079939ced124cefb90..bf7d2d3fced0af2a37396984c8c080befcc400b0 100644
--- a/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterVNA.java
+++ b/modules/ExportPlugin/src/main/java/org/gephi/io/exporter/plugin/ExporterVNA.java
@@ -43,11 +43,8 @@ package org.gephi.io.exporter.plugin;
import java.io.IOException;
import java.io.Writer;
-import java.util.Arrays;
-import org.gephi.data.attributes.api.AttributeModel;
-import org.gephi.data.attributes.type.TimeInterval;
-import org.gephi.dynamic.DynamicUtilities;
-import org.gephi.dynamic.api.DynamicModel;
+import org.gephi.attribute.api.AttributeModel;
+import org.gephi.attribute.api.Column;
import org.gephi.graph.api.Edge;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.GraphModel;
@@ -68,15 +65,14 @@ public class ExporterVNA implements GraphExporter, CharacterExporter, LongTask {
private Workspace workspace;
private boolean cancel = false;
private ProgressTicket progressTicket;
- private TimeInterval visibleInterval;
private AttributeModel attributeModel;
- private DynamicModel dynamicModel;
//settings
private boolean exportEdgeWeight = true;
private boolean exportCoords = true;
private boolean exportSize = true;
private boolean exportShortLabel = true;
private boolean exportColor = true;
+ private boolean exportDynamicWeight = true;
private boolean exportAttributes = true;
private boolean normalize = false;
private Writer writer;
@@ -91,14 +87,17 @@ public class ExporterVNA implements GraphExporter, CharacterExporter, LongTask {
private double getLow;//borders for dynamic edge weight
private double getHigh;
+ @Override
public void setExportVisible(boolean exportVisible) {
this.exportVisible = exportVisible;
}
+ @Override
public boolean isExportVisible() {
return exportVisible;
}
+ @Override
public boolean execute() {
attributeModel = workspace.getLookup().lookup(AttributeModel.class);
GraphModel graphModel = workspace.getLookup().lookup(GraphModel.class);
@@ -108,15 +107,6 @@ public class ExporterVNA implements GraphExporter, CharacterExporter, LongTask {
} else {
graph = graphModel.getGraph();
}
- dynamicModel = workspace.getLookup().lookup(DynamicModel.class);
- visibleInterval = dynamicModel != null && exportVisible ? dynamicModel.getVisibleInterval() : new TimeInterval();
-
- getLow = Double.NEGATIVE_INFINITY;//whole interval, if graph is not dynamic
- getHigh = Double.POSITIVE_INFINITY;
- if (visibleInterval != null) {
- getLow = visibleInterval.getLow();
- getHigh = visibleInterval.getHigh();
- }
graph.readLock();
@@ -152,8 +142,7 @@ public class ExporterVNA implements GraphExporter, CharacterExporter, LongTask {
/*
* For non-standart and string attributes
*/
- private String printParameter(Object s) {
- Object val = DynamicUtilities.getDynamicValue(s, visibleInterval.getLow(), visibleInterval.getHigh());
+ private String printParameter(Object val) {
if (val == null) {
return valueForEmptyAttributes;
}
@@ -164,13 +153,10 @@ public class ExporterVNA implements GraphExporter, CharacterExporter, LongTask {
return res;
}
}
- //sorted arrays
- static final private String[] standartNodeAttributes = {"Id", "Label", "Time Interval"};
- static final private String[] standartEdgeAttributes = {"Id", "Label", "Time Interval", "Weight"};
private boolean atLeastOneNonStandartAttribute() {
- for (int i = 0; i < attributeModel.getNodeTable().getColumns().length; i++) {
- if (Arrays.binarySearch(standartNodeAttributes, attributeModel.getNodeTable().getColumn(i).getTitle()) < 0) {
+ for (Column col : attributeModel.getNodeTable()) {
+ if (!col.isProperty()) {
return true;
}
}
@@ -184,10 +170,9 @@ public class ExporterVNA implements GraphExporter, CharacterExporter, LongTask {
//header
stringBuilder.append("*Node data\n");
stringBuilder.append("ID");
- for (int i = 0; i < attributeModel.getNodeTable().getColumns().length; i++) {
- if (Arrays.binarySearch(standartNodeAttributes, attributeModel.getNodeTable().getColumn(i).getTitle()) < 0) //ignore standart
- {
- stringBuilder.append(" ").append(attributeModel.getNodeTable().getColumn(i).getTitle().replace(' ', '_').toString());
+ for (Column column : attributeModel.getNodeTable()) {
+ if (!column.isProperty()) {
+ stringBuilder.append(" ").append(column.getTitle().replace(' ', '_').toString());
//replace spaces because importer can't read attributes titles in quotes
}
}
@@ -199,13 +184,12 @@ public class ExporterVNA implements GraphExporter, CharacterExporter, LongTask {
if (cancel) {
break;
}
- stringBuilder.append(printParameter(node.getNodeData().getId()));
-
- for (int i = 0; i < attributeModel.getNodeTable().getColumns().length; i++) {
- if (Arrays.binarySearch(standartNodeAttributes, attributeModel.getNodeTable().getColumn(i).getTitle()) < 0) //ignore standart
- {
- if (node.getNodeData().getAttributes().getValue(i) != null) {
- stringBuilder.append(" ").append(printParameter(node.getNodeData().getAttributes().getValue(i)));
+ stringBuilder.append(printParameter(node.getId()));
+ for (Column column : attributeModel.getNodeTable()) {
+ if (!column.isProperty()) {
+ Object value = node.getAttribute(column, graph.getView());
+ if (value != null) {
+ stringBuilder.append(" ").append(printParameter(value));
} else {
stringBuilder.append(" ").append(valueForEmptyAttributes);
}
@@ -230,14 +214,14 @@ public class ExporterVNA implements GraphExporter, CharacterExporter, LongTask {
if (cancel) {
break;
}
- minX = Math.min(minX, node.getNodeData().x());
- maxX = Math.max(maxX, node.getNodeData().x());
+ minX = Math.min(minX, node.x());
+ maxX = Math.max(maxX, node.x());
- minY = Math.min(minY, node.getNodeData().y());
- maxY = Math.max(maxY, node.getNodeData().y());
+ minY = Math.min(minY, node.y());
+ maxY = Math.max(maxY, node.y());
- minSize = Math.min(minSize, node.getNodeData().r());
- maxSize = Math.max(maxSize, node.getNodeData().r());
+ minSize = Math.min(minSize, node.r());
+ maxSize = Math.max(maxSize, node.r());
}
}
@@ -268,48 +252,54 @@ public class ExporterVNA implements GraphExporter, CharacterExporter, LongTask {
if (cancel) {
break;
}
- stringBuilder.append(node.getNodeData().getId());
+ stringBuilder.append(node.getId());
if (exportCoords) {
if (!normalize) {
- stringBuilder.append(" ").append(node.getNodeData().x()).append(" ").append(node.getNodeData().y());
+ stringBuilder.append(" ").append(node.x()).append(" ").append(node.y());
} else {
- stringBuilder.append(" ").append((node.getNodeData().x() - minX) / (maxX - minX)).append(" ").append((node.getNodeData().y() - minY) / (maxY - minY));
+ stringBuilder.append(" ").append((node.x() - minX) / (maxX - minX)).append(" ").append((node.y() - minY) / (maxY - minY));
}
}
if (exportSize) {
if (!normalize) {
- stringBuilder.append(" ").append(node.getNodeData().getRadius());
+ stringBuilder.append(" ").append(node.size());
} else {
- stringBuilder.append(" ").append((node.getNodeData().getRadius() - minSize) / (maxSize - minSize));
+ stringBuilder.append(" ").append((node.size() - minSize) / (maxSize - minSize));
}
}
if (exportColor) {
- stringBuilder.append(" ").append((int) (node.getNodeData().r() * 255f));//[0..1] to [0..255]
+ stringBuilder.append(" ").append((int) (node.r() * 255f));//[0..1] to [0..255]
}
if (exportShortLabel) {
- if (node.getNodeData().getLabel() != null) {
- stringBuilder.append(" ").append(printParameter(node.getNodeData().getLabel()));
+ if (node.getLabel() != null) {
+ stringBuilder.append(" ").append(printParameter(node.getLabel()));
} else {
- stringBuilder.append(" ").append(printParameter(node.getNodeData().getId()));
+ stringBuilder.append(" ").append(printParameter(node.getId()));
}
}
stringBuilder.append("\n");
}
}
- void printEdgeData(Edge edge, Node source, Node target) {
- stringBuilder.append(printParameter(source.getNodeData().getId()));//from
- stringBuilder.append(" ").append(printParameter(target.getNodeData().getId()));//to
+ void printEdgeData(Edge edge, Node source, Node target, Graph graph) {
+ stringBuilder.append(printParameter(source.getId()));//from
+ stringBuilder.append(" ").append(printParameter(target.getId()));//to
if (exportEdgeWeight) {
- stringBuilder.append(" ").append(edge.getWeight(getLow, getHigh));//strength
+ Double weight;
+ if (exportDynamicWeight) {
+ weight = edge.getWeight(graph.getView());
+ } else {
+ weight = edge.getWeight();
+ }
+ stringBuilder.append(" ").append(weight.toString());
}
if (exportAttributes) {
- for (int i = 0; i < attributeModel.getEdgeTable().getColumns().length; i++) {
- if (Arrays.binarySearch(standartEdgeAttributes, attributeModel.getEdgeTable().getColumn(i).getTitle()) < 0) //ignore standart
- {
- if (edge.getEdgeData().getAttributes().getValue(i) != null) {
- stringBuilder.append(" ").append(printParameter(edge.getEdgeData().getAttributes().getValue(i)));
+ for (Column column : attributeModel.getEdgeTable()) {
+ if (!column.isProperty()) {
+ Object value = edge.getAttribute(column, graph.getView());
+ if (value != null) {
+ stringBuilder.append(" ").append(printParameter(value));
} else {
stringBuilder.append(" " + valueForEmptyAttributes);
}
@@ -329,10 +319,9 @@ public class ExporterVNA implements GraphExporter, CharacterExporter, LongTask {
stringBuilder.append(" strength");
}
if (exportAttributes) {
- for (int i = 0; i < attributeModel.getEdgeTable().getColumns().length; i++) {
- if (Arrays.binarySearch(standartEdgeAttributes, attributeModel.getEdgeTable().getColumn(i).getTitle()) < 0) //ignore standart
- {
- stringBuilder.append(" ").append(printParameter(attributeModel.getEdgeTable().getColumn(i).getTitle()).replace(' ', '_'));
+ for (Column col : attributeModel.getEdgeTable()) {
+ if (!col.isProperty()) {
+ stringBuilder.append(" ").append(printParameter(col.getTitle()).replace(' ', '_'));
//replace spaces because importer can't read attributes titles in quotes
}
}
@@ -344,30 +333,35 @@ public class ExporterVNA implements GraphExporter, CharacterExporter, LongTask {
break;
}
progressTicket.progress();
- printEdgeData(edge, edge.getSource(), edge.getTarget());//all edges in vna are directed, so make clone
+ printEdgeData(edge, edge.getSource(), edge.getTarget(), graph);//all edges in vna are directed, so make clone
if (!edge.isDirected() && !edge.isSelfLoop()) {
- printEdgeData(edge, edge.getTarget(), edge.getSource());
+ printEdgeData(edge, edge.getTarget(), edge.getSource(), graph);
}
}
}
+ @Override
public void setWorkspace(Workspace workspace) {
this.workspace = workspace;
}
+ @Override
public Workspace getWorkspace() {
return workspace;
}
+ @Override
public boolean cancel() {
cancel = true;
return true;
}
+ @Override
public void setProgressTicket(ProgressTicket progressTicket) {
this.progressTicket = progressTicket;
}
+ @Override
public void setWriter(Writer writer) {
this.writer = writer;
}