提交 2b2721f7 编写于 作者: M Mathieu Bastian

Update ExportPlugin code to the new GraphAPI

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