Skip to content

Commit

Permalink
Merge pull request #229 from chewiebug/feature/#129/fix-png-export-to…
Browse files Browse the repository at this point in the history
…-use-current-configuration

Feature/#129/fix png export to use current configuration
  • Loading branch information
chewiebug authored Sep 14, 2019
2 parents bc21c8f + 236c90b commit 695f8f4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@
<name>Fred Rolland</name>
<url>https://github.com/rollandf</url>
</developer>
<developer>
<name>Sandro Rossi</name>
<url>https://github.com/rossisandro</url>
</developer>
<developer>
<name>Heiko W. Rupp</name>
<url>https://github.com/pilhuhn</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.Map;
import java.util.HashMap;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import javax.swing.filechooser.FileFilter;

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

try (DataWriter writer = DataWriterFactory.getDataWriter(file, dataWriterType)) {
Map<String, Object> configuration = new HashMap<>();
configuration.put(DataWriterFactory.GC_PREFERENCES, gcViewer.getSelectedGCDocument().getPreferences());
try (DataWriter writer = DataWriterFactory.getDataWriter(file, dataWriterType, configuration)) {
writer.write(model);
}
catch (Exception ioe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @author <a href="mailto:[email protected]">Hendrik Schreiber</a>
*/
public class DataWriterFactory {
public static final String GC_PREFERENCES = "gcPreferences";

/**
* Standard factory method to retrieve one of the <code>DataWriter</code> implementations.
Expand Down Expand Up @@ -53,7 +54,7 @@ public static DataWriter getDataWriter(File file, DataWriterType type, Map<Strin
case CSV_TS : return new CSVTSDataWriter(outputStream);
case SIMPLE : return new SimpleGcWriter(outputStream);
case SUMMARY : return new SummaryDataWriter(outputStream, configuration);
case PNG : return new PNGDataWriter(outputStream);
case PNG : return new PNGDataWriter(outputStream, configuration);
default : throw new IOException(LocalisationHelper.getString("datawriterfactory_instantiation_failed") + " " + file);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;

import com.tagtraum.perf.gcviewer.view.SimpleChartRenderer;
import com.tagtraum.perf.gcviewer.exp.AbstractDataWriter;
import com.tagtraum.perf.gcviewer.model.GCModel;
import com.tagtraum.perf.gcviewer.view.model.GCPreferences;

/**
* PNG data writter
Expand All @@ -15,16 +17,33 @@
*
*/
public class PNGDataWriter extends AbstractDataWriter {
private FileOutputStream out;
private final FileOutputStream out;

public PNGDataWriter(OutputStream outputStream) {
super(outputStream);
/**
* Constructor for PNGDataWriter with additional <code>configuration</code> parameter.
*
* @param outputStream FileOutputStream, file where the image should be written to
* @param configuration Configuration for this PNGDataWriter; expected contents of the parameter:
* <ul>
* <li>String: <code>DataWriterFactory.GC_PREFERENCES</code></li>
* <li>Object: Instance of GCPreferences (E.g. current screen selection for chart)
* </ul>
*/
public PNGDataWriter(OutputStream outputStream, Map<String, Object> configuration) {
super(outputStream, configuration);
out = (FileOutputStream)outputStream;
}

@Override
public void write(GCModel model) throws IOException {
new SimpleChartRenderer().render(model, out);
SimpleChartRenderer simpleChartRenderer = new SimpleChartRenderer();

Object gcPreferences = getConfiguration().get(DataWriterFactory.GC_PREFERENCES);
if (gcPreferences instanceof GCPreferences) {
simpleChartRenderer.render(model, out, (GCPreferences)gcPreferences);
} else {
simpleChartRenderer.render(model, out);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class AboutDialog extends ScreenCenteredDialog implements ActionListener
"Thomas Peyrard",
"Rupesh Ramachandran",
"Fred Rolland",
"Sandro Rossi",
"Heiko W. Rupp",
"Stephan Schroevers",
"François Secherre",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public class SimpleChartRenderer {
public void render(GCModel model, FileOutputStream outputStream) throws IOException {
GCPreferences gcPreferences = new GCPreferences();
gcPreferences.load();
render(model, outputStream, gcPreferences);
}

public void render(GCModel model, FileOutputStream outputStream, GCPreferences gcPreferences) throws IOException {
Dimension d = new Dimension(gcPreferences.getWindowWidth(), gcPreferences.getWindowHeight());

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

0 comments on commit 695f8f4

Please sign in to comment.