Skip to content

Command line graph generation random issue #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions src/main/java/com/tagtraum/perf/gcviewer/SimpleChartRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,51 @@

import javax.imageio.ImageIO;
import javax.swing.*;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class SimpleChartRenderer {
private static final Logger LOGGER = Logger.getLogger(SimpleChartRenderer.class.getName());

public void render(GCModel model, String chartFilePath) throws IOException {
GCPreferences gcPreferences = new GCPreferences();
public void render(final GCModel model, String chartFilePath) throws IOException {
final GCPreferences gcPreferences = new GCPreferences();
gcPreferences.load();
final Dimension d = new Dimension(gcPreferences.getWindowWidth(), gcPreferences.getWindowHeight());

final ModelChartImpl pane = new ModelChartImpl();
pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

pane.setModel(model, gcPreferences);
pane.setFootprint(model.getFootprint());
pane.setMaxPause(model.getPause().getMax());
pane.setRunningTime(model.getRunningTime());

Dimension d = new Dimension(gcPreferences.getWindowWidth(), gcPreferences.getWindowHeight());
pane.setSize(d);
pane.addNotify();
pane.validate();

pane.autoSetScaleFactor();

final BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
final Graphics2D graphics = image.createGraphics();
graphics.setBackground(Color.WHITE);
graphics.clearRect(0, 0, image.getWidth(), image.getHeight());
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
ModelChartImpl pane = new ModelChartImpl();
pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

pane.setModel(model, gcPreferences);
pane.setFootprint(model.getFootprint());
pane.setMaxPause(model.getPause().getMax());
pane.setRunningTime(model.getRunningTime());

pane.setSize(d);
pane.addNotify();
pane.validate();

pane.autoSetScaleFactor();
pane.paint(graphics);
}
});
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to paint graphic", e);
}

pane.paint(graphics);

ImageIO.write(image, "png", new File(chartFilePath));
}
Expand Down