From bb91a873047ff5619dd7e5ae02398d69740008a3 Mon Sep 17 00:00:00 2001 From: Sandro Rossi Date: Mon, 9 Sep 2019 07:33:50 +0200 Subject: [PATCH 1/2] When a chart is exported as a PNG file, instead of applying the selected View properties for the current chart, the application reloads the definitions found on gcviewer.properties. This small fix corrects this behaviour, capturing the current view configurations for the chart (E.g. if a specific GC line is visible or not) while exporting a PNG file. --- .../perf/gcviewer/ctrl/action/Export.java | 7 +++-- .../gcviewer/exp/impl/DataWriterFactory.java | 3 ++- .../perf/gcviewer/exp/impl/PNGDataWriter.java | 27 ++++++++++++++++--- .../gcviewer/view/SimpleChartRenderer.java | 4 +++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/tagtraum/perf/gcviewer/ctrl/action/Export.java b/src/main/java/com/tagtraum/perf/gcviewer/ctrl/action/Export.java index 4ad89915..6cc7a98a 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/ctrl/action/Export.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/ctrl/action/Export.java @@ -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; @@ -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 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) { diff --git a/src/main/java/com/tagtraum/perf/gcviewer/exp/impl/DataWriterFactory.java b/src/main/java/com/tagtraum/perf/gcviewer/exp/impl/DataWriterFactory.java index 536dca11..de0b1e9b 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/exp/impl/DataWriterFactory.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/exp/impl/DataWriterFactory.java @@ -17,6 +17,7 @@ * @author Hendrik Schreiber */ public class DataWriterFactory { + public static final String GC_PREFERENCES = "gcPreferences"; /** * Standard factory method to retrieve one of the DataWriter implementations. @@ -53,7 +54,7 @@ public static DataWriter getDataWriter(File file, DataWriterType type, Mapconfiguration parameter. + * + * @param outputStream FileOutputStream, file where the image should be written to + * @param configuration Configuration for this PNGDataWriter; expected contents of the parameter: + *
    + *
  • String: DataWriterFactory.GC_PREFERENCES
  • + *
  • Object: Instance of GCPreferences (E.g. current screen selection for chart) + *
+ */ + public PNGDataWriter(OutputStream outputStream, Map 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); + } } } diff --git a/src/main/java/com/tagtraum/perf/gcviewer/view/SimpleChartRenderer.java b/src/main/java/com/tagtraum/perf/gcviewer/view/SimpleChartRenderer.java index c36ffb5c..9932076b 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/view/SimpleChartRenderer.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/view/SimpleChartRenderer.java @@ -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); From 236c90bc58e0b18e16559eb3641ef853f9ed9003 Mon Sep 17 00:00:00 2001 From: chewiebug Date: Sat, 14 Sep 2019 17:46:19 +0200 Subject: [PATCH 2/2] add Sandro Rossi to list of contributors --- pom.xml | 4 ++++ .../java/com/tagtraum/perf/gcviewer/view/AboutDialog.java | 1 + 2 files changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index 3848ec96..ca4cb000 100644 --- a/pom.xml +++ b/pom.xml @@ -135,6 +135,10 @@ Fred Rolland https://github.com/rollandf + + Sandro Rossi + https://github.com/rossisandro + Heiko W. Rupp https://github.com/pilhuhn diff --git a/src/main/java/com/tagtraum/perf/gcviewer/view/AboutDialog.java b/src/main/java/com/tagtraum/perf/gcviewer/view/AboutDialog.java index 8a1b4ad6..c5c59650 100644 --- a/src/main/java/com/tagtraum/perf/gcviewer/view/AboutDialog.java +++ b/src/main/java/com/tagtraum/perf/gcviewer/view/AboutDialog.java @@ -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",