Skip to content

Commit 695f8f4

Browse files
authored
Merge pull request #229 from chewiebug/feature/#129/fix-png-export-to-use-current-configuration
Feature/#129/fix png export to use current configuration
2 parents bc21c8f + 236c90b commit 695f8f4

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@
135135
<name>Fred Rolland</name>
136136
<url>https://github.com/rollandf</url>
137137
</developer>
138+
<developer>
139+
<name>Sandro Rossi</name>
140+
<url>https://github.com/rossisandro</url>
141+
</developer>
138142
<developer>
139143
<name>Heiko W. Rupp</name>
140144
<url>https://github.com/pilhuhn</url>

src/main/java/com/tagtraum/perf/gcviewer/ctrl/action/Export.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
import java.awt.Toolkit;
44
import java.awt.event.ActionEvent;
55
import java.io.File;
6+
import java.util.Map;
7+
import java.util.HashMap;
68

79
import javax.swing.AbstractAction;
810
import javax.swing.JFileChooser;
911
import javax.swing.JOptionPane;
1012
import javax.swing.KeyStroke;
11-
import javax.swing.filechooser.FileFilter;
1213

1314
import com.tagtraum.perf.gcviewer.exp.DataWriter;
1415
import com.tagtraum.perf.gcviewer.exp.DataWriterType;
@@ -86,7 +87,9 @@ public void exportFile(final GCModel model, File file, final String extension, f
8687
LocalisationHelper.getString("fileexport_dialog_title"),
8788
JOptionPane.YES_NO_OPTION)) {
8889

89-
try (DataWriter writer = DataWriterFactory.getDataWriter(file, dataWriterType)) {
90+
Map<String, Object> configuration = new HashMap<>();
91+
configuration.put(DataWriterFactory.GC_PREFERENCES, gcViewer.getSelectedGCDocument().getPreferences());
92+
try (DataWriter writer = DataWriterFactory.getDataWriter(file, dataWriterType, configuration)) {
9093
writer.write(model);
9194
}
9295
catch (Exception ioe) {

src/main/java/com/tagtraum/perf/gcviewer/exp/impl/DataWriterFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* @author <a href="mailto:hs@tagtraum.com">Hendrik Schreiber</a>
1818
*/
1919
public class DataWriterFactory {
20+
public static final String GC_PREFERENCES = "gcPreferences";
2021

2122
/**
2223
* Standard factory method to retrieve one of the <code>DataWriter</code> implementations.
@@ -53,7 +54,7 @@ public static DataWriter getDataWriter(File file, DataWriterType type, Map<Strin
5354
case CSV_TS : return new CSVTSDataWriter(outputStream);
5455
case SIMPLE : return new SimpleGcWriter(outputStream);
5556
case SUMMARY : return new SummaryDataWriter(outputStream, configuration);
56-
case PNG : return new PNGDataWriter(outputStream);
57+
case PNG : return new PNGDataWriter(outputStream, configuration);
5758
default : throw new IOException(LocalisationHelper.getString("datawriterfactory_instantiation_failed") + " " + file);
5859
}
5960
}

src/main/java/com/tagtraum/perf/gcviewer/exp/impl/PNGDataWriter.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import java.io.FileOutputStream;
44
import java.io.IOException;
55
import java.io.OutputStream;
6+
import java.util.Map;
67

78
import com.tagtraum.perf.gcviewer.view.SimpleChartRenderer;
89
import com.tagtraum.perf.gcviewer.exp.AbstractDataWriter;
910
import com.tagtraum.perf.gcviewer.model.GCModel;
11+
import com.tagtraum.perf.gcviewer.view.model.GCPreferences;
1012

1113
/**
1214
* PNG data writter
@@ -15,16 +17,33 @@
1517
*
1618
*/
1719
public class PNGDataWriter extends AbstractDataWriter {
18-
private FileOutputStream out;
20+
private final FileOutputStream out;
1921

20-
public PNGDataWriter(OutputStream outputStream) {
21-
super(outputStream);
22+
/**
23+
* Constructor for PNGDataWriter with additional <code>configuration</code> parameter.
24+
*
25+
* @param outputStream FileOutputStream, file where the image should be written to
26+
* @param configuration Configuration for this PNGDataWriter; expected contents of the parameter:
27+
* <ul>
28+
* <li>String: <code>DataWriterFactory.GC_PREFERENCES</code></li>
29+
* <li>Object: Instance of GCPreferences (E.g. current screen selection for chart)
30+
* </ul>
31+
*/
32+
public PNGDataWriter(OutputStream outputStream, Map<String, Object> configuration) {
33+
super(outputStream, configuration);
2234
out = (FileOutputStream)outputStream;
2335
}
2436

2537
@Override
2638
public void write(GCModel model) throws IOException {
27-
new SimpleChartRenderer().render(model, out);
39+
SimpleChartRenderer simpleChartRenderer = new SimpleChartRenderer();
40+
41+
Object gcPreferences = getConfiguration().get(DataWriterFactory.GC_PREFERENCES);
42+
if (gcPreferences instanceof GCPreferences) {
43+
simpleChartRenderer.render(model, out, (GCPreferences)gcPreferences);
44+
} else {
45+
simpleChartRenderer.render(model, out);
46+
}
2847
}
2948

3049
}

src/main/java/com/tagtraum/perf/gcviewer/view/AboutDialog.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public class AboutDialog extends ScreenCenteredDialog implements ActionListener
6767
"Thomas Peyrard",
6868
"Rupesh Ramachandran",
6969
"Fred Rolland",
70+
"Sandro Rossi",
7071
"Heiko W. Rupp",
7172
"Stephan Schroevers",
7273
"François Secherre",

src/main/java/com/tagtraum/perf/gcviewer/view/SimpleChartRenderer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public class SimpleChartRenderer {
2222
public void render(GCModel model, FileOutputStream outputStream) throws IOException {
2323
GCPreferences gcPreferences = new GCPreferences();
2424
gcPreferences.load();
25+
render(model, outputStream, gcPreferences);
26+
}
27+
28+
public void render(GCModel model, FileOutputStream outputStream, GCPreferences gcPreferences) throws IOException {
2529
Dimension d = new Dimension(gcPreferences.getWindowWidth(), gcPreferences.getWindowHeight());
2630

2731
BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);

0 commit comments

Comments
 (0)