Skip to content

Commit ed4517b

Browse files
committed
Write exporter settings to preferences #1790
1 parent 7883e5b commit ed4517b

File tree

9 files changed

+200
-142
lines changed

9 files changed

+200
-142
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.gephi.ui.exporter.plugin;
2+
3+
import org.openide.util.NbPreferences;
4+
5+
public abstract class AbstractExporterSettings {
6+
7+
protected boolean get(String name, boolean defaultValue) {
8+
return NbPreferences.forModule(AbstractExporterSettings.class).getBoolean(name, defaultValue);
9+
}
10+
11+
protected void put(String name, boolean value) {
12+
NbPreferences.forModule(AbstractExporterSettings.class).putBoolean(name, value);
13+
}
14+
15+
protected int get(String name, int defaultValue) {
16+
return NbPreferences.forModule(AbstractExporterSettings.class).getInt(name, defaultValue);
17+
}
18+
19+
protected void put(String name, int value) {
20+
NbPreferences.forModule(AbstractExporterSettings.class).putInt(name, value);
21+
}
22+
23+
protected char get(String name, char defaultValue) {
24+
return (char) NbPreferences.forModule(AbstractExporterSettings.class).getInt(name, defaultValue);
25+
}
26+
27+
protected void put(String name, char value) {
28+
NbPreferences.forModule(AbstractExporterSettings.class).putInt(name, value);
29+
}
30+
}

modules/ExportPluginUI/src/main/java/org/gephi/ui/exporter/plugin/UIExporterCSV.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ Development and Distribution License("CDDL") (collectively, the
5555
@ServiceProvider(service = ExporterUI.class)
5656
public class UIExporterCSV implements ExporterUI {
5757

58+
private final ExporterCSVSettings settings = new ExporterCSVSettings();
5859
private UIExporterCSVPanel panel;
5960
private ExporterCSV exporterCSV;
60-
private final ExporterCSVSettings settings = new ExporterCSVSettings();
6161

6262
@Override
6363
public void setup(Exporter exporter) {
@@ -92,25 +92,28 @@ public String getDisplayName() {
9292
return NbBundle.getMessage(UIExporterCSV.class, "UIExporterCSV.name");
9393
}
9494

95-
private static class ExporterCSVSettings {
95+
private static class ExporterCSVSettings extends AbstractExporterSettings {
9696

97-
private boolean edgeWeight = true;
98-
private boolean writeZero = true;
99-
private boolean header = true;
100-
private boolean list = false;
97+
// Preference names
98+
private final static String EDGE_WEIGHT = "CSV_edgeWeight";
99+
private final static String WRITE_ZERO = "CSV_writeZero";
100+
private final static String HEADER = "CSV_header";
101+
private final static String LIST = "CSV_list";
102+
// Default
103+
private final static ExporterCSV DEFAULT = new ExporterCSV();
101104

102105
private void save(ExporterCSV exporterCSV) {
103-
this.edgeWeight = exporterCSV.isEdgeWeight();
104-
this.writeZero = exporterCSV.isWriteZero();
105-
this.header = exporterCSV.isHeader();
106-
this.list = exporterCSV.isList();
106+
put(EDGE_WEIGHT, exporterCSV.isEdgeWeight());
107+
put(WRITE_ZERO, exporterCSV.isWriteZero());
108+
put(HEADER, exporterCSV.isHeader());
109+
put(LIST, exporterCSV.isList());
107110
}
108111

109112
private void load(ExporterCSV exporterCSV) {
110-
exporterCSV.setEdgeWeight(edgeWeight);
111-
exporterCSV.setWriteZero(writeZero);
112-
exporterCSV.setHeader(header);
113-
exporterCSV.setList(list);
113+
exporterCSV.setEdgeWeight(get(EDGE_WEIGHT, DEFAULT.isEdgeWeight()));
114+
exporterCSV.setWriteZero(get(WRITE_ZERO, DEFAULT.isWriteZero()));
115+
exporterCSV.setHeader(get(HEADER, DEFAULT.isHeader()));
116+
exporterCSV.setList(get(LIST, DEFAULT.isList()));
114117
}
115118
}
116119
}

modules/ExportPluginUI/src/main/java/org/gephi/ui/exporter/plugin/UIExporterDL.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ Development and Distribution License("CDDL") (collectively, the
5252
@ServiceProvider(service = ExporterUI.class)
5353
public class UIExporterDL implements ExporterUI {
5454

55+
private final ExporterDLSettings settings = new ExporterDLSettings();
5556
private UIExporterDLPanel panel;
5657
private ExporterDL exporter;
57-
private final ExporterDLSettings settings = new ExporterDLSettings();
5858

5959
@Override
6060
public JPanel getPanel() {
@@ -90,21 +90,25 @@ public String getDisplayName() {
9090
return NbBundle.getMessage(UIExporterDL.class, "UIExporterDL.name");
9191
}
9292

93-
private static class ExporterDLSettings {
94-
private boolean useListFormat = true;
95-
private boolean useMatrixFormat = false;
96-
private boolean makeSymmetricMatrix = false;
93+
private static class ExporterDLSettings extends AbstractExporterSettings {
94+
95+
// Preference names
96+
private final static String USE_LIST_FORMAT = "DL_useListFormat";
97+
private final static String USE_MATRIX_FORMAT = "DL_useMatrixFormat";
98+
private final static String MAKE_SYMMETRIC_MATRIX = "DL_makeSymmetricMatrix";
99+
// Default
100+
private final static ExporterDL DEFAULT = new ExporterDL();
97101

98102
private void load(ExporterDL exporterDL) {
99-
exporterDL.setUseListFormat(useListFormat);
100-
exporterDL.setUseMatrixFormat(useMatrixFormat);
101-
exporterDL.setMakeSymmetricMatrix(makeSymmetricMatrix);
103+
exporterDL.setUseListFormat(get(USE_LIST_FORMAT, DEFAULT.isUseListFormat()));
104+
exporterDL.setUseMatrixFormat(get(USE_MATRIX_FORMAT, DEFAULT.isUseMatrixFormat()));
105+
exporterDL.setMakeSymmetricMatrix(get(MAKE_SYMMETRIC_MATRIX, DEFAULT.isMakeSymmetricMatrix()));
102106
}
103107

104108
private void save(ExporterDL exporterDL) {
105-
useListFormat = exporterDL.isUseListFormat();
106-
useMatrixFormat = exporterDL.isUseMatrixFormat();
107-
makeSymmetricMatrix = exporterDL.isMakeSymmetricMatrix();
109+
put(USE_LIST_FORMAT, exporterDL.isUseListFormat());
110+
put(USE_MATRIX_FORMAT, exporterDL.isUseMatrixFormat());
111+
put(MAKE_SYMMETRIC_MATRIX, exporterDL.isMakeSymmetricMatrix());
108112
}
109113
}
110114
}

modules/ExportPluginUI/src/main/java/org/gephi/ui/exporter/plugin/UIExporterGDF.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ Development and Distribution License("CDDL") (collectively, the
5555
@ServiceProvider(service = ExporterUI.class)
5656
public class UIExporterGDF implements ExporterUI {
5757

58+
private final ExporterGDFSettings settings = new ExporterGDFSettings();
5859
private UIExporterGDFPanel panel;
5960
private ExporterGDF exporterGDF;
60-
private final ExporterGDFSettings settings = new ExporterGDFSettings();
6161

6262
@Override
6363
public void setup(Exporter exporter) {
@@ -92,34 +92,37 @@ public String getDisplayName() {
9292
return NbBundle.getMessage(UIExporterGDF.class, "UIExporterGDF.name");
9393
}
9494

95-
private static class ExporterGDFSettings {
95+
private static class ExporterGDFSettings extends AbstractExporterSettings {
9696

97-
private boolean normalize = false;
98-
private boolean simpleQuotes = false;
99-
private boolean useQuotes = true;
100-
private boolean exportColors = true;
101-
private boolean exportPosition = true;
102-
private boolean exportAttributes = true;
103-
private boolean exportVisibility = false;
97+
// Preference names
98+
private final static String NORMALIZE = "GDF_normalize";
99+
private final static String SIMPLE_QUOTES = "GDF_simpleQuotes";
100+
private final static String USE_QUOTES = "GDF_useQuotes";
101+
private final static String EXPORT_COLORS = "GDF_exportColors";
102+
private final static String EXPORT_POSITION = "GDF_exportPosition";
103+
private final static String EXPORT_ATTRIBUTES = "GDF_exportAttributes";
104+
private final static String EXPORT_VISIBILITY = "GDF_exportVisibility";
105+
// Default
106+
private final static ExporterGDF DEFAULT = new ExporterGDF();
104107

105108
private void save(ExporterGDF exporterGDF) {
106-
this.normalize = exporterGDF.isNormalize();
107-
this.simpleQuotes = exporterGDF.isSimpleQuotes();
108-
this.useQuotes = exporterGDF.isUseQuotes();
109-
this.exportColors = exporterGDF.isExportColors();
110-
this.exportPosition = exporterGDF.isExportPosition();
111-
this.exportAttributes = exporterGDF.isExportAttributes();
112-
this.exportVisibility = exporterGDF.isExportVisibility();
109+
put(NORMALIZE, exporterGDF.isNormalize());
110+
put(SIMPLE_QUOTES, exporterGDF.isSimpleQuotes());
111+
put(USE_QUOTES, exporterGDF.isUseQuotes());
112+
put(EXPORT_COLORS, exporterGDF.isExportColors());
113+
put(EXPORT_POSITION, exporterGDF.isExportPosition());
114+
put(EXPORT_ATTRIBUTES, exporterGDF.isExportAttributes());
115+
put(EXPORT_VISIBILITY, exporterGDF.isExportVisibility());
113116
}
114117

115118
private void load(ExporterGDF exporterGDF) {
116-
exporterGDF.setNormalize(normalize);
117-
exporterGDF.setSimpleQuotes(simpleQuotes);
118-
exporterGDF.setUseQuotes(useQuotes);
119-
exporterGDF.setExportColors(exportColors);
120-
exporterGDF.setExportAttributes(exportAttributes);
121-
exporterGDF.setExportPosition(exportPosition);
122-
exporterGDF.setExportVisibility(exportVisibility);
119+
exporterGDF.setNormalize(get(NORMALIZE, DEFAULT.isNormalize()));
120+
exporterGDF.setSimpleQuotes(get(SIMPLE_QUOTES, DEFAULT.isSimpleQuotes()));
121+
exporterGDF.setUseQuotes(get(USE_QUOTES, DEFAULT.isUseQuotes()));
122+
exporterGDF.setExportColors(get(EXPORT_COLORS, DEFAULT.isExportColors()));
123+
exporterGDF.setExportAttributes(get(EXPORT_ATTRIBUTES, DEFAULT.isExportAttributes()));
124+
exporterGDF.setExportPosition(get(EXPORT_POSITION, DEFAULT.isExportPosition()));
125+
exporterGDF.setExportVisibility(get(EXPORT_VISIBILITY, DEFAULT.isExportVisibility()));
123126
}
124127
}
125128
}

modules/ExportPluginUI/src/main/java/org/gephi/ui/exporter/plugin/UIExporterGEXF.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,31 +92,37 @@ public String getDisplayName() {
9292
return NbBundle.getMessage(UIExporterGEXF.class, "UIExporterGEXF.name");
9393
}
9494

95-
private static class ExporterGEXFSettings {
96-
97-
private boolean normalize = false;
98-
private boolean exportColors = true;
99-
private boolean exportPosition = true;
100-
private boolean exportSize = true;
101-
private boolean exportAttributes = true;
102-
private boolean exportDynamics = true;
95+
private static class ExporterGEXFSettings extends AbstractExporterSettings {
96+
97+
// Preference names
98+
private final static String NORMALIZE = "GEXF_normalize";
99+
private final static String EXPORT_COLORS = "GEXF_exportColors";
100+
private final static String EXPORT_POSITION = "GEXF_exportPosition";
101+
private final static String EXPORT_ATTRIBUTES = "GEXF_exportAttributes";
102+
private final static String EXPORT_SIZE = "GEXF_exportSize";
103+
private final static String EXPORT_DYNAMICS = "GEXF_exportDynamics";
104+
private final static String EXPORT_META = "GEXF_exportMeta";
105+
// Default
106+
private final static ExporterGEXF DEFAULT = new ExporterGEXF();
103107

104108
private void save(ExporterGEXF exporterGEXF) {
105-
this.normalize = exporterGEXF.isNormalize();
106-
this.exportColors = exporterGEXF.isExportColors();
107-
this.exportPosition = exporterGEXF.isExportPosition();
108-
this.exportSize = exporterGEXF.isExportSize();
109-
this.exportAttributes = exporterGEXF.isExportAttributes();
110-
this.exportDynamics = exporterGEXF.isExportDynamic();
109+
put(NORMALIZE, exporterGEXF.isNormalize());
110+
put(EXPORT_COLORS, exporterGEXF.isExportColors());
111+
put(EXPORT_POSITION, exporterGEXF.isExportPosition());
112+
put(EXPORT_SIZE, exporterGEXF.isExportSize());
113+
put(EXPORT_ATTRIBUTES, exporterGEXF.isExportAttributes());
114+
put(EXPORT_DYNAMICS, exporterGEXF.isExportDynamic());
115+
put(EXPORT_META, exporterGEXF.isExportMeta());
111116
}
112117

113118
private void load(ExporterGEXF exporterGEXF) {
114-
exporterGEXF.setNormalize(normalize);
115-
exporterGEXF.setExportColors(exportColors);
116-
exporterGEXF.setExportAttributes(exportAttributes);
117-
exporterGEXF.setExportPosition(exportPosition);
118-
exporterGEXF.setExportSize(exportSize);
119-
exporterGEXF.setExportDynamic(exportDynamics);
119+
exporterGEXF.setNormalize(get(NORMALIZE, DEFAULT.isNormalize()));
120+
exporterGEXF.setExportColors(get(EXPORT_COLORS, DEFAULT.isExportColors()));
121+
exporterGEXF.setExportAttributes(get(EXPORT_ATTRIBUTES, DEFAULT.isExportAttributes()));
122+
exporterGEXF.setExportPosition(get(EXPORT_POSITION, DEFAULT.isExportPosition()));
123+
exporterGEXF.setExportSize(get(EXPORT_SIZE, DEFAULT.isExportSize()));
124+
exporterGEXF.setExportDynamic(get(EXPORT_DYNAMICS, DEFAULT.isExportDynamic()));
125+
exporterGEXF.setExportMeta(get(EXPORT_META, DEFAULT.isExportMeta()));
120126
}
121127
}
122128
}

modules/ExportPluginUI/src/main/java/org/gephi/ui/exporter/plugin/UIExporterGML.java

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -95,37 +95,41 @@ public String getDisplayName() {
9595
return NbBundle.getMessage(UIExporterGEXF.class, "UIExporterGML.name");
9696
}
9797

98-
private static class ExporterGMLSettings {
99-
100-
private boolean exportLabel = true;
101-
private boolean exportCoordinates = true;
102-
private boolean exportNodeSize = true;
103-
private boolean exportEdgeSize = true;
104-
private boolean exportColor = true;
105-
private boolean exportNotRecognizedElements = true;
106-
private boolean normalize = false;
107-
private int spaces = 2;
98+
private static class ExporterGMLSettings extends AbstractExporterSettings {
99+
100+
// Preference names
101+
private final static String EXPORT_LABEL = "GML_exportLabel";
102+
private final static String EXPORT_COORDINATES = "GML_exportCoordinates";
103+
private final static String EXPORT_NODE_SIZE = "GML_exportNodeSize";
104+
private final static String EXPORT_EDGE_SIZE = "GML_exportEdgeSize";
105+
private final static String EXPORT_COLOR = "GML_exportColor";
106+
private final static String EXPORT_NOT_RECOGNIZES_ELEMENTS = "GML_exportNotRecognizedElements";
107+
private final static String NORMALIZE = "GML_normalize";
108+
private final static String SPACES = "GML_spaces";
109+
// Default
110+
private final static ExporterGML DEFAULT = new ExporterGML();
108111

109112
private void load(ExporterGML exporter) {
110-
exporter.setExportColor(exportColor);
111-
exporter.setExportCoordinates(exportCoordinates);
112-
exporter.setExportEdgeSize(exportEdgeSize);
113-
exporter.setExportLabel(exportLabel);
114-
exporter.setExportNodeSize(exportNodeSize);
115-
exporter.setExportNotRecognizedElements(exportNotRecognizedElements);
116-
exporter.setNormalize(normalize);
117-
exporter.setSpaces(spaces);
113+
exporter.setExportColor(get(EXPORT_COLOR, DEFAULT.isExportColor()));
114+
exporter.setExportCoordinates(get(EXPORT_COORDINATES, DEFAULT.isExportCoordinates()));
115+
exporter.setExportEdgeSize(get(EXPORT_EDGE_SIZE, DEFAULT.isExportEdgeSize()));
116+
exporter.setExportLabel(get(EXPORT_LABEL, DEFAULT.isExportLabel()));
117+
exporter.setExportNodeSize(get(EXPORT_NODE_SIZE, DEFAULT.isExportNodeSize()));
118+
exporter.setExportNotRecognizedElements(get(EXPORT_NOT_RECOGNIZES_ELEMENTS,
119+
DEFAULT.isExportNotRecognizedElements()));
120+
exporter.setNormalize(get(NORMALIZE, DEFAULT.isNormalize()));
121+
exporter.setSpaces(get(SPACES, DEFAULT.getSpaces()));
118122
}
119123

120124
private void save(ExporterGML exporter) {
121-
exportColor = exporter.isExportColor();
122-
exportCoordinates = exporter.isExportCoordinates();
123-
exportEdgeSize = exporter.isExportEdgeSize();
124-
exportLabel = exporter.isExportLabel();
125-
exportNodeSize = exporter.isExportNodeSize();
126-
exportNotRecognizedElements = exporter.isExportNotRecognizedElements();
127-
normalize = exporter.isNormalize();
128-
spaces = exporter.getSpaces();
125+
put(EXPORT_COLOR, exporter.isExportColor());
126+
put(EXPORT_COORDINATES, exporter.isExportCoordinates());
127+
put(EXPORT_EDGE_SIZE, exporter.isExportEdgeSize());
128+
put(EXPORT_LABEL, exporter.isExportLabel());
129+
put(EXPORT_NODE_SIZE, exporter.isExportNodeSize());
130+
put(EXPORT_NOT_RECOGNIZES_ELEMENTS, exporter.isExportNotRecognizedElements());
131+
put(NORMALIZE, exporter.isNormalize());
132+
put(SPACES, exporter.getSpaces());
129133
}
130134
}
131135
}

modules/ExportPluginUI/src/main/java/org/gephi/ui/exporter/plugin/UIExporterGraphML.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ Development and Distribution License("CDDL") (collectively, the
5555
@ServiceProvider(service = ExporterUI.class)
5656
public class UIExporterGraphML implements ExporterUI {
5757

58+
private final ExporterGraphMLSettings settings = new ExporterGraphMLSettings();
5859
private UIExporterGraphMLPanel panel;
5960
private ExporterGraphML exporterGraphML;
60-
private final ExporterGraphMLSettings settings = new ExporterGraphMLSettings();
6161

6262
@Override
6363
public void setup(Exporter exporter) {
@@ -92,29 +92,31 @@ public String getDisplayName() {
9292
return NbBundle.getMessage(UIExporterGraphML.class, "UIExporterGraphML.name");
9393
}
9494

95-
private static class ExporterGraphMLSettings {
95+
private static class ExporterGraphMLSettings extends AbstractExporterSettings {
9696

97-
private boolean normalize = false;
98-
private boolean exportColors = true;
99-
private boolean exportPosition = true;
100-
private boolean exportSize = true;
101-
private boolean exportAttributes = true;
102-
private final boolean exportHierarchy = false;
97+
// Preference names
98+
private final static String NORMALIZE = "GraphML_normalize";
99+
private final static String EXPORT_COLORS = "GraphML_exportColors";
100+
private final static String EXPORT_POSITION = "GraphML_exportPosition";
101+
private final static String EXPORT_ATTRIBUTES = "GraphML_exportAttributes";
102+
private final static String EXPORT_SIZE = "GraphML_exportSize";
103+
// Default
104+
private final static ExporterGraphML DEFAULT = new ExporterGraphML();
103105

104106
private void save(ExporterGraphML exporterGraphML) {
105-
this.normalize = exporterGraphML.isNormalize();
106-
this.exportColors = exporterGraphML.isExportColors();
107-
this.exportPosition = exporterGraphML.isExportPosition();
108-
this.exportSize = exporterGraphML.isExportSize();
109-
this.exportAttributes = exporterGraphML.isExportAttributes();
107+
put(NORMALIZE, exporterGraphML.isNormalize());
108+
put(EXPORT_COLORS, exporterGraphML.isExportColors());
109+
put(EXPORT_POSITION, exporterGraphML.isExportPosition());
110+
put(EXPORT_SIZE, exporterGraphML.isExportSize());
111+
put(EXPORT_ATTRIBUTES, exporterGraphML.isExportAttributes());
110112
}
111113

112114
private void load(ExporterGraphML exporterGraphML) {
113-
exporterGraphML.setNormalize(normalize);
114-
exporterGraphML.setExportColors(exportColors);
115-
exporterGraphML.setExportAttributes(exportAttributes);
116-
exporterGraphML.setExportPosition(exportPosition);
117-
exporterGraphML.setExportSize(exportSize);
115+
exporterGraphML.setNormalize(get(NORMALIZE, DEFAULT.isNormalize()));
116+
exporterGraphML.setExportColors(get(EXPORT_COLORS, DEFAULT.isExportColors()));
117+
exporterGraphML.setExportAttributes(get(EXPORT_ATTRIBUTES, DEFAULT.isExportAttributes()));
118+
exporterGraphML.setExportPosition(get(EXPORT_POSITION, DEFAULT.isExportPosition()));
119+
exporterGraphML.setExportSize(get(EXPORT_SIZE, DEFAULT.isExportSize()));
118120
}
119121
}
120122
}

0 commit comments

Comments
 (0)