Skip to content

Commit

Permalink
Also write Preview export settings to preferences gephi#1790
Browse files Browse the repository at this point in the history
  • Loading branch information
mbastian committed Mar 10, 2022
1 parent ed4517b commit be67be6
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class SVGExporter implements CharacterExporter, VectorExporter, LongTask
private SVGTarget target;
//Settings
private boolean scaleStrokes = false;
private final float margin = 4;
private float margin = 4;

@Override
public boolean execute() {
Expand Down Expand Up @@ -155,4 +155,12 @@ public boolean isScaleStrokes() {
public void setScaleStrokes(boolean scaleStrokes) {
this.scaleStrokes = scaleStrokes;
}

public float getMargin() {
return margin;
}

public void setMargin(float margin) {
this.margin = margin;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.gephi.ui.exporter.preview;

import org.openide.util.NbPreferences;

public abstract class AbstractExporterSettings {

protected boolean get(String name, boolean defaultValue) {
return NbPreferences.forModule(AbstractExporterSettings.class).getBoolean(name, defaultValue);
}

protected void put(String name, boolean value) {
NbPreferences.forModule(AbstractExporterSettings.class).putBoolean(name, value);
}

protected int get(String name, int defaultValue) {
return NbPreferences.forModule(AbstractExporterSettings.class).getInt(name, defaultValue);
}

protected void put(String name, int value) {
NbPreferences.forModule(AbstractExporterSettings.class).putInt(name, value);
}

protected float get(String name, float defaultValue) {
return NbPreferences.forModule(AbstractExporterSettings.class).getFloat(name, defaultValue);
}

protected void put(String name, float value) {
NbPreferences.forModule(AbstractExporterSettings.class).putFloat(name, value);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Development and Distribution License("CDDL") (collectively, the

package org.gephi.ui.exporter.preview;

import com.itextpdf.text.Rectangle;
import javax.swing.JPanel;
import org.gephi.io.exporter.preview.PDFExporter;
import org.gephi.io.exporter.spi.Exporter;
Expand All @@ -56,20 +57,23 @@ Development and Distribution License("CDDL") (collectively, the
@ServiceProvider(service = ExporterUI.class)
public class UIExporterPDF implements ExporterUI {

private final ExporterPDFSettings settings = new ExporterPDFSettings();
private UIExporterPDFPanel panel;
private ValidationPanel validationPanel;
private PDFExporter exporterPDF;

@Override
public void setup(Exporter exporter) {
exporterPDF = (PDFExporter) exporter;
settings.load(exporterPDF);
panel.setup(exporterPDF);
}

@Override
public void unsetup(boolean update) {
if (update) {
panel.unsetup(exporterPDF);
settings.save(exporterPDF);
}
panel = null;
exporterPDF = null;
Expand All @@ -91,4 +95,39 @@ public boolean isUIForExporter(Exporter exporter) {
public String getDisplayName() {
return NbBundle.getMessage(UIExporterPDF.class, "UIExporterPDF.name");
}

private static class ExporterPDFSettings extends AbstractExporterSettings {

// Preference names
private final static String MARGIN_TOP = "PDF_marginTop";
private final static String MARGIN_BOTTOM = "PDF_marginBottom";
private final static String MARGIN_LEFT = "PDF_marginLeft";
private final static String MARGIN_RIGHT = "PDF_marginRight";
private final static String LANDSCAPE = "PDF_landscape";
private final static String PAGE_SIZE_WIDTH = "PDF_pageSizeWidth";
private final static String PAGE_SIZE_HEIGHT = "PDF_pageSizeHeight";
// Default
private final static PDFExporter DEFAULT = new PDFExporter();

private void load(PDFExporter exporter) {
exporter.setMarginTop(get(MARGIN_TOP, DEFAULT.getMarginTop()));
exporter.setMarginBottom(get(MARGIN_BOTTOM, DEFAULT.getMarginBottom()));
exporter.setMarginLeft(get(MARGIN_LEFT, DEFAULT.getMarginLeft()));
exporter.setMarginRight(get(MARGIN_RIGHT, DEFAULT.getMarginRight()));
exporter.setLandscape(get(LANDSCAPE, DEFAULT.isLandscape()));
float width = get(PAGE_SIZE_WIDTH, DEFAULT.getPageSize().getWidth());
float height = get(PAGE_SIZE_HEIGHT, DEFAULT.getPageSize().getHeight());
exporter.setPageSize(new Rectangle(width, height));
}

private void save(PDFExporter exporter) {
put(MARGIN_TOP, exporter.getMarginTop());
put(MARGIN_BOTTOM, exporter.getMarginBottom());
put(MARGIN_LEFT, exporter.getMarginLeft());
put(MARGIN_RIGHT, exporter.getMarginRight());
put(LANDSCAPE, exporter.isLandscape());
put(PAGE_SIZE_WIDTH, exporter.getPageSize().getWidth());
put(PAGE_SIZE_HEIGHT, exporter.getPageSize().getHeight());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public class UIExporterPDFPanel extends javax.swing.JPanel implements Validation
private static final double INCH = 72.0;
private static final double MM = 2.8346456692895527;
private final String customSizeString;
private boolean millimeter = true;
private final NumberFormat sizeFormatter;
private final NumberFormat marginFormatter;
private boolean millimeter = true;
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField bottomMarginTextField;
private javax.swing.JTextField heightTextField;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ Development and Distribution License("CDDL") (collectively, the
@ServiceProvider(service = ExporterUI.class)
public class UIExporterPNG implements ExporterUI {

private final ExporterPNGSettings settings = new ExporterPNGSettings();
private UIExporterPNGPanel panel;
private PNGExporter exporter;
private final ExporterPNGSettings settings = new ExporterPNGSettings();
private ValidationPanel validationPanel;

@Override
Expand Down Expand Up @@ -96,25 +96,28 @@ public String getDisplayName() {
return NbBundle.getMessage(UIExporterPDF.class, "UIExporterPNG.name");
}

private static class ExporterPNGSettings {
private static class ExporterPNGSettings extends AbstractExporterSettings {

private int width = 1024;
private int height = 1024;
private int margin = 4;
private boolean transparentBackground;
// Preference names
private final static String WIDTH = "PNG_width";
private final static String HEIGHT = "PNG_height";
private final static String MARGIN = "PNG_margin";
private final static String TRANSPARENT_BACKGROUND = "PNG_transparentBackground";
// Default
private final static PNGExporter DEFAULT = new PNGExporter();

void load(PNGExporter exporter) {
exporter.setHeight(height);
exporter.setWidth(width);
exporter.setMargin(margin);
exporter.setTransparentBackground(transparentBackground);
exporter.setHeight(get(HEIGHT, DEFAULT.getHeight()));
exporter.setWidth(get(WIDTH, DEFAULT.getWidth()));
exporter.setMargin(get(MARGIN, DEFAULT.getMargin()));
exporter.setTransparentBackground(get(TRANSPARENT_BACKGROUND, DEFAULT.isTransparentBackground()));
}

void save(PNGExporter exporter) {
height = exporter.getHeight();
width = exporter.getWidth();
margin = exporter.getMargin();
transparentBackground = exporter.isTransparentBackground();
put(HEIGHT, exporter.getHeight());
put(WIDTH, exporter.getWidth());
put(MARGIN, exporter.getMargin());
put(TRANSPARENT_BACKGROUND, exporter.isTransparentBackground());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ Development and Distribution License("CDDL") (collectively, the
import org.gephi.io.exporter.spi.Exporter;
import org.gephi.io.exporter.spi.ExporterUI;
import org.openide.util.NbBundle;
import org.openide.util.NbPreferences;
import org.openide.util.lookup.ServiceProvider;

/**
Expand All @@ -56,21 +55,22 @@ Development and Distribution License("CDDL") (collectively, the
@ServiceProvider(service = ExporterUI.class)
public class UIExporterSVG implements ExporterUI {

private final ExporterSVGSettings settings = new ExporterSVGSettings();
private UIExporterSVGPanel panel;
private SVGExporter exporterSVG;

@Override
public void setup(Exporter exporter) {
exporterSVG = (SVGExporter) exporter;
loadPreferences();
settings.load(exporterSVG);
panel.setup(exporterSVG);
}

@Override
public void unsetup(boolean update) {
if (update) {
panel.unsetup(exporterSVG);
savePreferences();
settings.save(exporterSVG);
}
panel = null;
exporterSVG = null;
Expand All @@ -92,12 +92,22 @@ public String getDisplayName() {
return NbBundle.getMessage(UIExporterPDF.class, "UIExporterSVG.name");
}

private void loadPreferences() {
boolean strokeScale = NbPreferences.forModule(UIExporterSVG.class).getBoolean("ScaleStrokeWidth", false);
exporterSVG.setScaleStrokes(strokeScale);
}
private static class ExporterSVGSettings extends AbstractExporterSettings {

// Preference names
private final static String SCALE_STROKES = "SVG_strokeScale";
private final static String MARGIN = "SVG_margin";
// Default
private final static SVGExporter DEFAULT = new SVGExporter();

private void savePreferences() {
NbPreferences.forModule(UIExporterSVG.class).putBoolean("ScaleStrokeWidth", exporterSVG.isScaleStrokes());
void load(SVGExporter exporter) {
exporter.setScaleStrokes(get(SCALE_STROKES, DEFAULT.isScaleStrokes()));
exporter.setMargin(get(MARGIN, DEFAULT.getMargin()));
}

void save(SVGExporter exporter) {
put(SCALE_STROKES, exporter.isScaleStrokes());
put(MARGIN, exporter.getMargin());
}
}
}

0 comments on commit be67be6

Please sign in to comment.