未验证 提交 46ff5bab 编写于 作者: M Mathieu Bastian 提交者: GitHub

#2674 Json export (#2676)

* Initial implementation, work in progress

* Add tests and UI

* Minor tweaks

* Do not export undirected for each edge when undirected

* Formatting

* Fix color and options
上级 40a92a83
......@@ -24,7 +24,7 @@
<gephi.jfreechart.version>1.0.19</gephi.jfreechart.version>
<gephi.pdfbox.version>2.0.27</gephi.pdfbox.version>
<gephi.trove4j.version>3.0.3</gephi.trove4j.version>
<gephi.gson.version>2.9.1</gephi.gson.version>
<gephi.gson.version>2.10</gephi.gson.version>
</properties>
<dependencies>
......
......@@ -31,6 +31,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>utils-longtask</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>utils</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>core-library-wrapper</artifactId>
......
package org.gephi.io.exporter.plugin;
import org.gephi.io.exporter.api.FileType;
import org.gephi.io.exporter.spi.GraphExporter;
import org.gephi.io.exporter.spi.GraphFileExporterBuilder;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
@ServiceProvider(service = GraphFileExporterBuilder.class)
public class ExporterBuilderJson implements GraphFileExporterBuilder {
@Override
public GraphExporter buildExporter() {
return new ExporterJson();
}
@Override
public FileType[] getFileTypes() {
FileType ft = new FileType(".json", NbBundle.getMessage(ExporterBuilderJson.class, "fileType_Json_Name"));
return new FileType[] {ft};
}
@Override
public String getName() {
return "Json";
}
}
package org.gephi.io.exporter.plugin;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import org.gephi.graph.api.*;
import org.gephi.io.exporter.spi.CharacterExporter;
import org.gephi.io.exporter.spi.GraphExporter;
import org.gephi.project.api.Workspace;
import org.gephi.utils.VersionUtils;
import org.gephi.utils.longtask.spi.LongTask;
import org.gephi.utils.progress.Progress;
import org.gephi.utils.progress.ProgressTicket;
import org.joda.time.DateTimeZone;
import org.openide.util.Lookup;
import java.awt.*;
import java.io.IOException;
import java.io.Writer;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ExporterJson implements GraphExporter, CharacterExporter, LongTask {
// Architecture
private boolean cancel = false;
private ProgressTicket progress;
private Workspace workspace;
private boolean exportVisible;
private Writer writer;
private Graph graph;
// Settings
private boolean normalize = false;
private boolean exportColors = true;
private boolean exportPosition = true;
private boolean exportSize = true;
private boolean exportAttributes = true;
private boolean exportDynamic = true;
private boolean exportMeta = true;
private boolean prettyPrint = true;
// Helper
private NormalizationHelper normalization;
// Formats
public enum Format {Graphology}
private Format format = Format.Graphology;
@Override
public boolean execute() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = graphController.getGraphModel(workspace);
graph = exportVisible ? graphModel.getGraphVisible() : graphModel.getGraph();
Progress.start(progress);
graph.readLock();
//Is it a dynamic graph?
exportDynamic = exportDynamic && graphModel.isDynamic();
//Calculate min & max
normalization = NormalizationHelper.build(normalize, graph);
Progress.switchToDeterminate(progress, graph.getNodeCount() + graph.getEdgeCount());
try {
exportData();
} catch (Exception e) {
Logger.getLogger(ExporterGEXF.class.getName()).log(Level.SEVERE, null, e);
} finally {
graph.readUnlock();
Progress.finish(progress);
}
return !cancel;
}
private void exportData() {
GsonBuilder gsonBuilder = new GsonBuilder()
.registerTypeAdapter(Color.class, new ColorAdapter())
.registerTypeAdapterFactory(new GraphTypeAdapterFactory());
if (prettyPrint) {
gsonBuilder = gsonBuilder.setPrettyPrinting();
}
Gson gson = gsonBuilder
.create();
gson.toJson(graph, writer);
}
private class ColorAdapter extends WriteTypeAdapter<Color> {
@Override
public void write(JsonWriter out, Color value) throws IOException {
if (exportColors) {
out.name("color");
if (value.getAlpha() < 255) {
out.value(String.format("#%08x", (value.getRGB() << 8) | value.getAlpha()));
} else {
out.value(String.format("#%06x", value.getRGB() & 0x00FFFFFF));
}
}
}
}
private class GraphTypeAdapter extends WriteTypeAdapter<Graph> {
private final TypeAdapter<Node> nodeTypeAdapter;
private final TypeAdapter<Edge> edgeTypeAdapter;
public GraphTypeAdapter(Gson gson) {
nodeTypeAdapter = gson.getAdapter(Node.class);
edgeTypeAdapter = gson.getAdapter(Edge.class);
}
@Override
public void write(JsonWriter out, Graph graph) throws IOException {
out.beginObject();
// Attributes
writeAttributes(out);
// Options
writeOptions(out, graph);
// Nodes
out.name("nodes");
out.beginArray();
for (Node node : graph.getNodes()) {
if (!cancel) {
nodeTypeAdapter.write(out, node);
}
}
out.endArray();
// Edges
out.name("edges");
out.beginArray();
for (Edge edge : graph.getEdges()) {
if (!cancel) {
edgeTypeAdapter.write(out, edge);
}
}
out.endArray();
out.endObject();
}
protected void writeOptions(JsonWriter out, Graph graph) throws IOException {
out.name("options");
out.beginObject();
out.name("multi");
out.value(graph.getModel().getEdgeTypeLabels(false).length > 1);
out.name("allowSelfLoops");
out.value(true);
out.name("type");
out.value(
graph.getModel().isUndirected() ? "undirected" : graph.getModel().isMixed() ? "mixed" : "directed");
out.endObject();
}
protected void writeAttributes(JsonWriter out) throws IOException {
if (exportMeta) {
out.name("attributes");
out.beginObject();
out.name("creator");
out.value(VersionUtils.getGephiVersion());
if (exportDynamic) {
Configuration graphConfig = graph.getModel().getConfiguration();
TimeFormat timeFormat = graph.getModel().getTimeFormat();
out.name("timeformat");
out.value(timeFormat.toString().toLowerCase());
out.name("timerepresentation");
out.value(graphConfig.getTimeRepresentation().toString().toLowerCase());
out.name("timezone");
out.value(graph.getModel().getTimeZone().getID());
}
out.endObject();
}
}
}
private class ElementTypeAdapter<T extends Element> extends WriteTypeAdapter<T> {
private final TypeAdapter<Color> colorAdapter;
public ElementTypeAdapter(Gson gson) {
this.colorAdapter = gson.getAdapter(Color.class);
}
@Override
public void write(JsonWriter out, T element) throws IOException {
throw new UnsupportedOperationException("Not to be called directly");
}
protected void writeAttValues(JsonWriter out, T element) throws IOException {
if (exportAttributes) {
TimeFormat timeFormat = graph.getModel().getTimeFormat();
DateTimeZone timeZone = graph.getModel().getTimeZone();
for (Column column : element.getAttributeColumns()) {
if (!column.isProperty() ||
(element instanceof Edge &&
column.getId().equals("weight"))) {
// Col header, similar to spreadsheet
String columnId = column.getId();
String columnTitle = column.getTitle();
String columnHeader =
columnId.equalsIgnoreCase(columnTitle) && !column.isProperty() ? columnTitle : columnId;
Object value = exportDynamic ? element.getAttribute(column) :
element.getAttribute(column, graph.getView());
out.name(columnHeader);
if (value instanceof Number) {
out.value((Number) value);
} else if (value instanceof Boolean) {
out.value((Boolean) value);
} else {
out.value(AttributeUtils.print(value, timeFormat, timeZone));
}
}
}
}
}
protected void writeColor(JsonWriter out, Color color) throws IOException {
if (exportColors) {
colorAdapter.write(out, color);
}
}
protected void writeLabel(JsonWriter out, T element) throws IOException {
if (element.getLabel() != null && !element.getLabel().isEmpty()) {
out.name("label");
out.value(element.getLabel());
}
}
}
private class NodeTypeAdapter extends ElementTypeAdapter<Node> {
public NodeTypeAdapter(Gson gson) {
super(gson);
}
@Override
public void write(JsonWriter out, Node node) throws IOException {
out.beginObject();
out.name("key");
out.value(node.getId().toString());
writeAttributes(out, node);
out.endObject();
Progress.progress(progress);
}
private void writeAttributes(JsonWriter out, Node node) throws IOException {
out.name("attributes");
out.beginObject();
// Label
writeLabel(out, node);
// Positions
writePositions(out, node);
// Size
writeSize(out, node);
// Colors
writeColor(out, node.getColor());
// Att values
writeAttValues(out, node);
out.endObject();
}
protected void writeSize(JsonWriter out, Node node) throws IOException {
if (exportSize) {
float size = normalization.normalizeSize(node.size());
if (normalize || size != 0) {
out.name("size");
out.value(size);
}
}
}
private void writePositions(JsonWriter out, Node node) throws IOException {
if (exportPosition) {
float x = normalization.normalizeX(node.x());
float y = normalization.normalizeY(node.y());
float z = normalization.normalizeZ(node.z());
if (!(x == 0 && y == 0 && z == 0)) {
out.name("x");
out.value(node.x());
out.name("y");
out.value(node.y());
if (normalization.minZ != 0 || normalization.maxZ != 0) {
out.name("z");
out.value(node.z());
}
}
}
}
}
private class EdgeTypeAdapter extends ElementTypeAdapter<Edge> {
public EdgeTypeAdapter(Gson gson) {
super(gson);
}
@Override
public void write(JsonWriter out, Edge edge) throws IOException {
out.beginObject();
out.name("key");
out.value(edge.getId().toString());
out.name("source");
out.value(edge.getSource().getId().toString());
out.name("target");
out.value(edge.getTarget().getId().toString());
if (!edge.isDirected() && graph.isMixed()) {
out.name("undirected");
out.value(Boolean.TRUE);
}
writeAttributes(out, edge);
out.endObject();
Progress.progress(progress);
}
private void writeAttributes(JsonWriter out, Edge edge) throws IOException {
out.name("attributes");
out.beginObject();
// Type/Kind
if (edge.getType() != 0) {
out.name("type");
out.value(edge.getTypeLabel().toString());
}
// Label
writeLabel(out, edge);
// Colors
if (edge.alpha() != 0) { //Edge has custom color
writeColor(out, edge.getColor());
}
// Att values
writeAttValues(out, edge);
out.endObject();
}
}
private class GraphTypeAdapterFactory implements TypeAdapterFactory {
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (Node.class.isAssignableFrom(type.getRawType())) {
return (TypeAdapter<T>) new NodeTypeAdapter(gson);
} else if (Edge.class.isAssignableFrom(type.getRawType())) {
return (TypeAdapter<T>) new EdgeTypeAdapter(gson);
} else if (Graph.class.isAssignableFrom(type.getRawType())) {
return (TypeAdapter<T>) new GraphTypeAdapter(gson);
} else {
return null;
}
}
}
@Override
public boolean cancel() {
cancel = true;
return true;
}
@Override
public void setProgressTicket(ProgressTicket progressTicket) {
this.progress = progressTicket;
}
@Override
public boolean isExportVisible() {
return exportVisible;
}
@Override
public void setExportVisible(boolean exportVisible) {
this.exportVisible = exportVisible;
}
@Override
public void setWriter(Writer writer) {
this.writer = writer;
}
@Override
public Workspace getWorkspace() {
return workspace;
}
@Override
public void setWorkspace(Workspace workspace) {
this.workspace = workspace;
}
public boolean isNormalize() {
return normalize;
}
public void setNormalize(boolean normalize) {
this.normalize = normalize;
}
public boolean isExportColors() {
return exportColors;
}
public void setExportColors(boolean exportColors) {
this.exportColors = exportColors;
}
public boolean isExportPosition() {
return exportPosition;
}
public void setExportPosition(boolean exportPosition) {
this.exportPosition = exportPosition;
}
public boolean isExportSize() {
return exportSize;
}
public void setExportSize(boolean exportSize) {
this.exportSize = exportSize;
}
public boolean isExportAttributes() {
return exportAttributes;
}
public void setExportAttributes(boolean exportAttributes) {
this.exportAttributes = exportAttributes;
}
public boolean isExportDynamic() {
return exportDynamic;
}
public void setExportDynamic(boolean exportDynamic) {
this.exportDynamic = exportDynamic;
}
public boolean isExportMeta() {
return exportMeta;
}
public boolean isPrettyPrint() {
return prettyPrint;
}
public void setPrettyPrint(boolean prettyPrint) {
this.prettyPrint = prettyPrint;
}
public Format getFormat() {
return format;
}
public void setFormat(Format format) {
this.format = format;
}
public void setExportMeta(boolean exportMeta) {
this.exportMeta = exportMeta;
}
/**
* For convenience, the same as {@link TypeAdapter} but without the read support.
*
* @param <T> type
*/
private abstract static class WriteTypeAdapter<T> extends TypeAdapter<T> {
@Override
public T read(JsonReader in) throws IOException {
throw new UnsupportedOperationException("Not supported.");
}
}
}
......@@ -10,3 +10,4 @@ fileType_Pajek_Name = NET Files (Pajek)
fileType_DL_Name = DL files (UCINET)
fileType_VNA_Name= VNA files(Netdraw)
fileType_Spreadsheet_Name = Spreadsheet Files
fileType_Json_Name = JSON Files
\ No newline at end of file
package org.gephi.io.exporter.plugin;
import java.awt.*;
import java.io.IOException;
import org.gephi.graph.GraphGenerator;
import org.gephi.graph.api.Graph;
import org.gephi.graph.api.Node;
import org.gephi.project.api.Workspace;
import org.junit.Test;
public class JsonTest {
@Test
public void testEmpty() throws IOException {
GraphGenerator graphGenerator =
GraphGenerator.build().withWorkspace();
Utils.assertExporterMatch("json/empty.json", createExporter(graphGenerator));
}
@Test
public void testTinyGraph() throws IOException {
GraphGenerator graphGenerator =
GraphGenerator.build().withWorkspace().generateTinyGraph();
Utils.assertExporterMatch("json/tiny.json", createExporter(graphGenerator));
}
@Test
public void testNodeColumn() throws IOException {
GraphGenerator graphGenerator =
GraphGenerator.build().withWorkspace().generateTinyGraph().addDoubleNodeColumn();
Utils.assertExporterMatch("json/column.json", createExporter(graphGenerator));
}
@Test
public void testLabels() throws IOException {
GraphGenerator graphGenerator =
GraphGenerator.build().withWorkspace().generateTinyGraph().addNodeLabels().addEdgeLabels();
Utils.assertExporterMatch("json/labels.json", createExporter(graphGenerator));
}
@Test
public void testMulti() throws IOException {
GraphGenerator graphGenerator =
GraphGenerator.build().withWorkspace().generateTinyMultiGraph();
Utils.assertExporterMatch("json/multi.json", createExporter(graphGenerator));
}
@Test
public void testUndirected() throws IOException {
GraphGenerator graphGenerator =
GraphGenerator.build().withWorkspace().generateTinyUndirectedGraph();
Utils.assertExporterMatch("json/undirected.json", createExporter(graphGenerator));
}
@Test
public void testMixed() throws IOException {
GraphGenerator graphGenerator =
GraphGenerator.build().withWorkspace().generateTinyMixedGraph();
Utils.assertExporterMatch("json/mixed.json", createExporter(graphGenerator));
}
@Test
public void testColors() throws IOException {
GraphGenerator graphGenerator =
GraphGenerator.build().withWorkspace().generateTinyGraph();
Graph graph = graphGenerator.getGraph();
Node n1 = graph.getNode(GraphGenerator.FIRST_NODE);
Node n2 = graph.getNode(GraphGenerator.SECOND_NODE);
n1.setColor(Color.CYAN);
n2.setColor(new Color(255, 100, 120, 254));
ExporterJson exporterJson = createExporter(graphGenerator);
exporterJson.setExportColors(true);
Utils.assertExporterMatch("json/colors.json", exporterJson);
}
private static ExporterJson createExporter(GraphGenerator graphGenerator) {
Workspace workspace = graphGenerator.getWorkspace();
ExporterJson exporterJson = new ExporterJson();
exporterJson.setWorkspace(workspace);
exporterJson.setExportMeta(false);
exporterJson.setExportColors(false);
exporterJson.setExportPosition(false);
exporterJson.setExportSize(false);
return exporterJson;
}
}
......@@ -11,6 +11,14 @@ import org.xmlunit.diff.Difference;
public class Utils {
public static void print(CharacterExporter exporter) throws IOException {
StringWriter writer = new StringWriter();
exporter.setWriter(writer);
exporter.execute();
writer.close();
System.out.println(writer);
}
public static void assertExporterMatch(String expectedFilename, CharacterExporter exporter) throws IOException {
String expected = getResourceContent(expectedFilename);
StringWriter writer = new StringWriter();
......
{
"options": {
"multi": false,
"allowSelfLoops": true,
"type": "directed"
},
"nodes": [
{
"key": "1",
"attributes": {
"color": "#00ffff"
}
},
{
"key": "2",
"attributes": {
"color": "#ff6478fe"
}
}
],
"edges": [
{
"key": "1",
"source": "1",
"target": "2",
"attributes": {
"color": "#000000",
"weight": 1.0
}
}
]
}
\ No newline at end of file
{
"options": {
"multi": false,
"allowSelfLoops": true,
"type": "directed"
},
"nodes": [
{
"key": "1",
"attributes": {
"value": 10.0
}
},
{
"key": "2",
"attributes": {
"value": 11.0
}
}
],
"edges": [
{
"key": "1",
"source": "1",
"target": "2",
"attributes": {
"weight": 1.0
}
}
]
}
\ No newline at end of file
{
"options": {
"multi": false,
"allowSelfLoops": true,
"type": "directed"
},
"nodes": [],
"edges": []
}
\ No newline at end of file
{
"options": {
"multi": false,
"allowSelfLoops": true,
"type": "directed"
},
"nodes": [
{
"key": "1",
"attributes": {
"label": "1"
}
},
{
"key": "2",
"attributes": {
"label": "2"
}
}
],
"edges": [
{
"key": "1",
"source": "1",
"target": "2",
"attributes": {
"label": "1",
"weight": 1.0
}
}
]
}
\ No newline at end of file
{
"options": {
"multi": false,
"allowSelfLoops": true,
"type": "mixed"
},
"nodes": [
{
"key": "1",
"attributes": {}
},
{
"key": "2",
"attributes": {}
},
{
"key": "3",
"attributes": {}
}
],
"edges": [
{
"key": "1",
"source": "1",
"target": "2",
"undirected": true,
"attributes": {
"weight": 1.0
}
},
{
"key": "2",
"source": "1",
"target": "3",
"attributes": {
"weight": 1.0
}
}
]
}
\ No newline at end of file
{
"options": {
"multi": true,
"allowSelfLoops": true,
"type": "directed"
},
"nodes": [
{
"key": "1",
"attributes": {}
},
{
"key": "2",
"attributes": {}
}
],
"edges": [
{
"key": "1",
"source": "1",
"target": "2",
"attributes": {
"weight": 1.0
}
},
{
"key": "2",
"source": "1",
"target": "2",
"attributes": {
"type": "1",
"weight": 1.0
}
}
]
}
\ No newline at end of file
{
"options": {
"multi": false,
"allowSelfLoops": true,
"type": "directed"
},
"nodes": [
{
"key": "1",
"attributes": {}
},
{
"key": "2",
"attributes": {}
}
],
"edges": [
{
"key": "1",
"source": "1",
"target": "2",
"attributes": {
"weight": 1.0
}
}
]
}
\ No newline at end of file
{
"options": {
"multi": false,
"allowSelfLoops": true,
"type": "undirected"
},
"nodes": [
{
"key": "1",
"attributes": {}
},
{
"key": "2",
"attributes": {}
}
],
"edges": [
{
"key": "1",
"source": "1",
"target": "2",
"attributes": {
"weight": 1.0
}
}
]
}
\ No newline at end of file
/*
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.ui.exporter.plugin;
import javax.swing.JPanel;
import org.gephi.io.exporter.plugin.ExporterJson;
import org.gephi.io.exporter.spi.Exporter;
import org.gephi.io.exporter.spi.ExporterUI;
import org.openide.util.NbBundle;
import org.openide.util.lookup.ServiceProvider;
/**
* @author Mathieu Bastian
*/
@ServiceProvider(service = ExporterUI.class)
public class UIExporterJson implements ExporterUI {
private final ExporterJsonSettings settings = new ExporterJsonSettings();
private UIExporterJsonPanel panel;
private ExporterJson exporterJson;
@Override
public void setup(Exporter exporter) {
exporterJson = (ExporterJson) exporter;
settings.load(exporterJson);
if (panel != null) {
panel.setup(exporterJson);
}
}
@Override
public void unsetup(boolean update) {
if (update) {
panel.unsetup(exporterJson);
settings.save(exporterJson);
}
panel = null;
exporterJson = null;
}
@Override
public JPanel getPanel() {
panel = new UIExporterJsonPanel();
return panel;
}
@Override
public boolean isUIForExporter(Exporter exporter) {
return exporter instanceof ExporterJson;
}
@Override
public String getDisplayName() {
return NbBundle.getMessage(UIExporterJson.class, "UIExporterJson.name");
}
private static class ExporterJsonSettings extends AbstractExporterSettings {
// Preference names
private final static String NORMALIZE = "Json_normalize";
private final static String EXPORT_COLORS = "Json_exportColors";
private final static String EXPORT_POSITION = "Json_exportPosition";
private final static String EXPORT_ATTRIBUTES = "Json_exportAttributes";
private final static String EXPORT_SIZE = "Json_exportSize";
private final static String EXPORT_DYNAMICS = "Json_exportDynamics";
private final static String EXPORT_META = "Json_exportMeta";
private final static String PRETTY_PRINT = "Json_prettyPrint";
private final static String FORMAT = "Json_format";
// Default
private final static ExporterJson DEFAULT = new ExporterJson();
private void save(ExporterJson exporterJson) {
put(NORMALIZE, exporterJson.isNormalize());
put(EXPORT_COLORS, exporterJson.isExportColors());
put(EXPORT_POSITION, exporterJson.isExportPosition());
put(EXPORT_SIZE, exporterJson.isExportSize());
put(EXPORT_ATTRIBUTES, exporterJson.isExportAttributes());
put(EXPORT_DYNAMICS, exporterJson.isExportDynamic());
put(EXPORT_META, exporterJson.isExportMeta());
put(FORMAT, exporterJson.getFormat().name());
put(PRETTY_PRINT, exporterJson.isPrettyPrint());
}
private void load(ExporterJson exporterJson) {
exporterJson.setNormalize(get(NORMALIZE, DEFAULT.isNormalize()));
exporterJson.setExportColors(get(EXPORT_COLORS, DEFAULT.isExportColors()));
exporterJson.setExportAttributes(get(EXPORT_ATTRIBUTES, DEFAULT.isExportAttributes()));
exporterJson.setExportPosition(get(EXPORT_POSITION, DEFAULT.isExportPosition()));
exporterJson.setExportSize(get(EXPORT_SIZE, DEFAULT.isExportSize()));
exporterJson.setExportDynamic(get(EXPORT_DYNAMICS, DEFAULT.isExportDynamic()));
exporterJson.setExportMeta(get(EXPORT_META, DEFAULT.isExportMeta()));
exporterJson.setFormat(ExporterJson.Format.valueOf(get(FORMAT, DEFAULT.getFormat().name())));
exporterJson.setPrettyPrint(get(PRETTY_PRINT, DEFAULT.isPrettyPrint()));
}
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="normalizeCheckbox" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="labelNormalize" pref="225" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="labelExport" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="attributesExportCheckbox" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="sizeExportCheckbox" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="colorsExportCheckbox" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="positionExportCheckbox" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="dynamicExportCheckbox" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Component id="prettyPrintCheckbox" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="labelFormat" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="formatCombo" min="-2" pref="177" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="labelFormat" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="formatCombo" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="13" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="labelExport" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="positionExportCheckbox" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="colorsExportCheckbox" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="sizeExportCheckbox" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="attributesExportCheckbox" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="dynamicExportCheckbox" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="normalizeCheckbox" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="labelNormalize" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="prettyPrintCheckbox" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="15" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="labelExport">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/exporter/plugin/Bundle.properties" key="UIExporterJsonPanel.labelExport.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="positionExportCheckbox">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/exporter/plugin/Bundle.properties" key="UIExporterJsonPanel.positionExportCheckbox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="colorsExportCheckbox">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/exporter/plugin/Bundle.properties" key="UIExporterJsonPanel.colorsExportCheckbox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="attributesExportCheckbox">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/exporter/plugin/Bundle.properties" key="UIExporterJsonPanel.attributesExportCheckbox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="sizeExportCheckbox">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/exporter/plugin/Bundle.properties" key="UIExporterJsonPanel.sizeExportCheckbox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="labelNormalize">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="10" style="0"/>
</Property>
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="66" green="66" red="66" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/exporter/plugin/Bundle.properties" key="UIExporterJsonPanel.labelNormalize.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="normalizeCheckbox">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/exporter/plugin/Bundle.properties" key="UIExporterJsonPanel.normalizeCheckbox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="dynamicExportCheckbox">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/exporter/plugin/Bundle.properties" key="UIExporterJsonPanel.dynamicExportCheckbox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="prettyPrintCheckbox">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/exporter/plugin/Bundle.properties" key="UIExporterJsonPanel.prettyPrintCheckbox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="labelFormat">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/gephi/ui/exporter/plugin/Bundle.properties" key="UIExporterJsonPanel.labelFormat.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="formatCombo">
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;ExporterJson.Format&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Form>
/*
Copyright 2008-2010 Gephi
Authors : Mathieu Bastian <mathieu.bastian@gephi.org>
Website : http://www.gephi.org
This file is part of Gephi.
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
Copyright 2011 Gephi Consortium. All rights reserved.
The contents of this file are subject to the terms of either the GNU
General Public License Version 3 only ("GPL") or the Common
Development and Distribution License("CDDL") (collectively, the
"License"). You may not use this file except in compliance with the
License. You can obtain a copy of the License at
http://gephi.org/about/legal/license-notice/
or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the
specific language governing permissions and limitations under the
License. When distributing the software, include this License Header
Notice in each file and include the License files at
/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the
License Header, with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
If you wish your version of this file to be governed by only the CDDL
or only the GPL Version 3, indicate your decision by adding
"[Contributor] elects to include this software in this distribution
under the [CDDL or GPL Version 3] license." If you do not indicate a
single choice of license, a recipient has the option to distribute
your version of this file under either the CDDL, the GPL Version 3 or
to extend the choice of license to its licensees as provided above.
However, if you add GPL Version 3 code and therefore, elected the GPL
Version 3 license, then the option applies only if the new code is
made subject to such option by the copyright holder.
Contributor(s):
Portions Copyrighted 2011 Gephi Consortium.
*/
package org.gephi.ui.exporter.plugin;
import javax.swing.DefaultComboBoxModel;
import org.gephi.io.exporter.plugin.ExporterJson;
/**
* @author Mathieu Bastian
*/
public class UIExporterJsonPanel extends javax.swing.JPanel {
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox attributesExportCheckbox;
private javax.swing.JCheckBox colorsExportCheckbox;
private javax.swing.JCheckBox dynamicExportCheckbox;
private javax.swing.JComboBox<ExporterJson.Format> formatCombo;
private javax.swing.JLabel labelExport;
private javax.swing.JLabel labelFormat;
private javax.swing.JLabel labelNormalize;
private javax.swing.JCheckBox normalizeCheckbox;
private javax.swing.JCheckBox positionExportCheckbox;
private javax.swing.JCheckBox prettyPrintCheckbox;
private javax.swing.JCheckBox sizeExportCheckbox;
// End of variables declaration//GEN-END:variables
public UIExporterJsonPanel() {
initComponents();
// Init format combo
DefaultComboBoxModel<ExporterJson.Format> comboBoxModel =
new DefaultComboBoxModel<>(ExporterJson.Format.values());
formatCombo.setModel(comboBoxModel);
}
public void setup(ExporterJson exporterJson) {
formatCombo.setSelectedItem(exporterJson.getFormat());
colorsExportCheckbox.setSelected(exporterJson.isExportColors());
positionExportCheckbox.setSelected(exporterJson.isExportPosition());
sizeExportCheckbox.setSelected(exporterJson.isExportSize());
attributesExportCheckbox.setSelected(exporterJson.isExportAttributes());
normalizeCheckbox.setSelected(exporterJson.isNormalize());
dynamicExportCheckbox.setSelected(exporterJson.isExportDynamic());
prettyPrintCheckbox.setSelected(exporterJson.isPrettyPrint());
}
public void unsetup(ExporterJson exporterJson) {
exporterJson.setFormat((ExporterJson.Format) formatCombo.getSelectedItem());
exporterJson.setExportAttributes(attributesExportCheckbox.isSelected());
exporterJson.setExportColors(colorsExportCheckbox.isSelected());
exporterJson.setExportSize(sizeExportCheckbox.isSelected());
exporterJson.setExportPosition(positionExportCheckbox.isSelected());
exporterJson.setNormalize(normalizeCheckbox.isSelected());
exporterJson.setExportDynamic(dynamicExportCheckbox.isSelected());
exporterJson.setPrettyPrint(prettyPrintCheckbox.isSelected());
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
labelExport = new javax.swing.JLabel();
positionExportCheckbox = new javax.swing.JCheckBox();
colorsExportCheckbox = new javax.swing.JCheckBox();
attributesExportCheckbox = new javax.swing.JCheckBox();
sizeExportCheckbox = new javax.swing.JCheckBox();
labelNormalize = new javax.swing.JLabel();
normalizeCheckbox = new javax.swing.JCheckBox();
dynamicExportCheckbox = new javax.swing.JCheckBox();
prettyPrintCheckbox = new javax.swing.JCheckBox();
labelFormat = new javax.swing.JLabel();
formatCombo = new javax.swing.JComboBox<>();
labelExport.setText(org.openide.util.NbBundle.getMessage(UIExporterJsonPanel.class, "UIExporterJsonPanel.labelExport.text")); // NOI18N
positionExportCheckbox.setText(org.openide.util.NbBundle.getMessage(UIExporterJsonPanel.class, "UIExporterJsonPanel.positionExportCheckbox.text")); // NOI18N
colorsExportCheckbox.setText(org.openide.util.NbBundle.getMessage(UIExporterJsonPanel.class, "UIExporterJsonPanel.colorsExportCheckbox.text")); // NOI18N
attributesExportCheckbox.setText(org.openide.util.NbBundle.getMessage(UIExporterJsonPanel.class, "UIExporterJsonPanel.attributesExportCheckbox.text")); // NOI18N
sizeExportCheckbox.setText(org.openide.util.NbBundle.getMessage(UIExporterJsonPanel.class, "UIExporterJsonPanel.sizeExportCheckbox.text")); // NOI18N
labelNormalize.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
labelNormalize.setForeground(new java.awt.Color(102, 102, 102));
labelNormalize.setText(org.openide.util.NbBundle.getMessage(UIExporterJsonPanel.class, "UIExporterJsonPanel.labelNormalize.text")); // NOI18N
normalizeCheckbox.setText(org.openide.util.NbBundle.getMessage(UIExporterJsonPanel.class, "UIExporterJsonPanel.normalizeCheckbox.text")); // NOI18N
dynamicExportCheckbox.setText(org.openide.util.NbBundle.getMessage(UIExporterJsonPanel.class, "UIExporterJsonPanel.dynamicExportCheckbox.text")); // NOI18N
prettyPrintCheckbox.setText(org.openide.util.NbBundle.getMessage(UIExporterJsonPanel.class, "UIExporterJsonPanel.prettyPrintCheckbox.text")); // NOI18N
labelFormat.setText(org.openide.util.NbBundle.getMessage(UIExporterJsonPanel.class, "UIExporterJsonPanel.labelFormat.text")); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(normalizeCheckbox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(labelNormalize, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(labelExport)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(attributesExportCheckbox)
.addComponent(sizeExportCheckbox)
.addComponent(colorsExportCheckbox)
.addComponent(positionExportCheckbox)
.addComponent(dynamicExportCheckbox)))
.addComponent(prettyPrintCheckbox)
.addGroup(layout.createSequentialGroup()
.addComponent(labelFormat)
.addGap(18, 18, 18)
.addComponent(formatCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelFormat)
.addComponent(formatCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(labelExport)
.addComponent(positionExportCheckbox))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(colorsExportCheckbox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(sizeExportCheckbox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(attributesExportCheckbox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(dynamicExportCheckbox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(normalizeCheckbox)
.addComponent(labelNormalize))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(prettyPrintCheckbox)
.addGap(15, 15, 15))
);
}// </editor-fold>//GEN-END:initComponents
}
......@@ -9,6 +9,7 @@ UIExporterPajek.name = Pajek
UIExporterDL.name = DL
UIExporterVNA.name = VNA
UIExporterSpreadsheetPanel.name = Spreadsheet
UIExporterJson.name = Json
UIExporterGDFPanel.jRadioButton1.text=Simple quotes
UIExporterGDFPanel.positionExportCheckbox.text=Position (x,y)
......@@ -83,3 +84,14 @@ UIExporterSpreadsheetPanel.normalizeCheckbox.text=Normalize
UIExporterSpreadsheetPanel.labelNormalize.text=Scale position and size between 0 and 1
UIExporterSpreadsheetPanel.labelExport.text=Export:
UIExporterGEXFPanel.includeAttValuesNullCheckbox.text=Include null attribute values
UIExporterJsonPanel.normalizeCheckbox.text=Normalize
UIExporterJsonPanel.labelNormalize.text=Scale position and size between 0 and 1
UIExporterJsonPanel.sizeExportCheckbox.text=Size
UIExporterJsonPanel.attributesExportCheckbox.text=Attributes
UIExporterJsonPanel.colorsExportCheckbox.text=Colors
UIExporterJsonPanel.positionExportCheckbox.text=Position (x,y,z)
UIExporterJsonPanel.labelExport.text=Export:
UIExporterJsonPanel.dynamicExportCheckbox.text=Dynamic
UIExporterJsonPanel.prettyPrintCheckbox.text=Pretty print
UIExporterJsonPanel.labelFormat.text=Format:
......@@ -30,6 +30,7 @@ public class GraphGenerator {
public static final String INTERVAL_DOUBLE_COLUMN = "price";
public static final String FIRST_NODE = "1";
public static final String SECOND_NODE = "2";
public static final String THIRD_NODE = "3";
public static final String FIRST_EDGE = "1";
public static final String SECOND_EDGE = "2";
public static final String[] STRING_COLUMN_VALUES = new String[] {"France", "Germany"};
......@@ -87,6 +88,30 @@ public class GraphGenerator {
return this;
}
public GraphGenerator generateTinyUndirectedGraph() {
Node n1 = graphModel.factory().newNode(FIRST_NODE);
Node n2 = graphModel.factory().newNode(SECOND_NODE);
Edge e = graphModel.factory().newEdge(FIRST_EDGE, n1, n2, 0, 1.0, false);
graphModel.getDirectedGraph().addNode(n1);
graphModel.getDirectedGraph().addNode(n2);
graphModel.getDirectedGraph().addEdge(e);
return this;
}
public GraphGenerator generateTinyMixedGraph() {
Node n1 = graphModel.factory().newNode(FIRST_NODE);
Node n2 = graphModel.factory().newNode(SECOND_NODE);
Node n3 = graphModel.factory().newNode(THIRD_NODE);
Edge e1 = graphModel.factory().newEdge(FIRST_EDGE, n1, n2, 0, 1.0, false);
Edge e2 = graphModel.factory().newEdge(SECOND_EDGE, n1, n3, 0, 1.0, true);
graphModel.getGraph().addNode(n1);
graphModel.getGraph().addNode(n2);
graphModel.getGraph().addNode(n3);
graphModel.getGraph().addEdge(e1);
graphModel.getGraph().addEdge(e2);
return this;
}
public GraphGenerator addNodeLabels() {
for (Node n : graphModel.getGraph().getNodes()) {
n.setLabel(n.getId().toString());
......
......@@ -24,6 +24,10 @@
<groupId>${project.groupId}</groupId>
<artifactId>core-library-wrapper</artifactId>
</dependency>
<dependency>
<groupId>org.netbeans.api</groupId>
<artifactId>org-openide-util</artifactId>
</dependency>
</dependencies>
<build>
......
package org.gephi.utils;
import org.openide.util.NbBundle;
public class VersionUtils {
/**
* Returns the current version of the Gephi application.
*
* @return gephi version
*/
public static String getGephiVersion() {
return NbBundle.getBundle("org.netbeans.core.startup.Bundle").getString("currentVersion")
.replaceAll("( [0-9]{12})$", "");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册