Skip to content

added chart datestamp setting on model loading #88

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
Feb 26, 2014
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions src/main/java/com/tagtraum/perf/gcviewer/GCDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,19 @@ public void resetPolygonCache() {
}
}

@Override
public void setShowDateStamp(boolean showDateStamp) {
for (ChartPanelView chartPanelView : chartPanelViews) {
chartPanelView.getModelChart().setShowDateStamp(showDateStamp);
}
}

@Override
public boolean isShowDateStamp() {
if (chartPanelViews.isEmpty()) return false;
return chartPanelViews.get(0).getModelChart().isShowDateStamp();

}
}

private class ScrollBarMaximumChangeListener implements ChangeListener {
Expand Down
84 changes: 49 additions & 35 deletions src/main/java/com/tagtraum/perf/gcviewer/GCPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

/**
* Stores preferences of GCViewer in a file.
*
*
* @author <a href="mailto:[email protected]">Joerg Wuethrich</a>
* <p>created on: 20.11.2011</p>
*/
Expand All @@ -32,34 +32,35 @@ public class GCPreferences {
public static final String INITIAL_MARK_LEVEL = "initialmarklevel";
public static final String CONCURRENT_COLLECTION_BEGIN_END = "concurrentcollectionbeginend";
public static final String ANTI_ALIAS = "antialias";

public static final String SHOW_DATA_PANEL = "showdatapanel";

public static final String SHOW_DATE_STAMP = "showdatestamp";

private static final String GC_LINE_PREFIX = "view.";

private static final String WINDOW_WIDTH = "window.width";
private static final String WINDOW_HEIGHT = "window.height";
private static final String WINDOW_X = "window.x";
private static final String WINDOW_Y = "window.y";
private static final String LASTFILE = "lastfile";
private static final String RECENT_FILE_PREFIX = "recent.";

private static final int WINDOW_WIDTH_DEFAULT = 800;
private static final int WINDOW_HEIGHT_DEFAULT = 600;
private static final int WINDOW_X_DEFAULT = 0;
private static final int WINDOW_Y_DEFAULT = 0;

private static final Logger LOGGER = Logger.getLogger(GCPreferences.class.getName());

private Properties properties = new Properties();
private boolean propertiesLoaded = false;
private boolean propertiesLoaded = false;

public GCPreferences() {
super();

load();
}

public void store() {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(getPreferencesFile()))) {
properties.store(writer, "GCViewer preferences");
Expand All @@ -70,80 +71,80 @@ public void store() {
}
}
}

public void load() {
if (getPreferencesFile().exists()) {
try (BufferedReader reader = new BufferedReader(new FileReader(getPreferencesFile()))) {
propertiesLoaded = true;
properties.load(reader);
}
}
catch (IOException e) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.warning("could not load preferences (" + e.toString() + ")");
}
}
}
}

public boolean isPropertiesLoaded() {
return propertiesLoaded;
}

public boolean getBooleanProperty(String key) {
return getBooleanValue(key, true);
}

public void setBooleanProperty(String key, boolean value) {
properties.setProperty(key, Boolean.toString(value));
}

public int getWindowWidth() {
return getIntValue(WINDOW_WIDTH, WINDOW_WIDTH_DEFAULT);
}

public void setWindowWidth(int value) {
properties.setProperty(WINDOW_WIDTH, Integer.toString(value));
}

public int getWindowHeight() {
return getIntValue(WINDOW_HEIGHT, WINDOW_HEIGHT_DEFAULT);
}

public void setWindowHeight(int value) {
properties.setProperty(WINDOW_HEIGHT, Integer.toString(value));
}

public int getWindowX() {
return getIntValue(WINDOW_X, WINDOW_X_DEFAULT);
}

public void setWindowX(int value) {
properties.setProperty(WINDOW_X, Integer.toString(value));
}

public int getWindowY() {
return getIntValue(WINDOW_Y, WINDOW_Y_DEFAULT);
}

public void setWindowY(int value) {
properties.setProperty(WINDOW_Y, Integer.toString(value));
}

public void setLastFile(String filename) {
properties.setProperty(LASTFILE, filename);
}

public String getLastFile() {
return properties.getProperty(LASTFILE);
}

public void setRecentFiles(List<String> fileNames) {
int i = 0;
for (String fileName : fileNames) {
properties.setProperty(RECENT_FILE_PREFIX + i++, fileName);
}
}

public List<String> getRecentFiles() {
List<String> recentFiles = new LinkedList<String>();
String filename;
Expand All @@ -154,22 +155,26 @@ public List<String> getRecentFiles() {
recentFiles.add(filename);
}
} while (filename != null);

return recentFiles;
}

public boolean getGcLineProperty(String key) {
return getBooleanValue(GC_LINE_PREFIX + key, true);
}


public boolean getGcLineProperty(String key, boolean defaultValue) {
return getBooleanValue(GC_LINE_PREFIX + key, defaultValue);
}

public void setGcLineProperty(String key, boolean value) {
properties.setProperty(GC_LINE_PREFIX + key, Boolean.toString(value));
}

private boolean getBooleanValue(String key, boolean defaultValue) {
return Boolean.parseBoolean(properties.getProperty(key, Boolean.toString(defaultValue)));
}

private int getIntValue(String key, int defaultValue) {
int result = defaultValue;
try {
Expand All @@ -178,20 +183,29 @@ private int getIntValue(String key, int defaultValue) {
catch (NumberFormatException e) {
e.printStackTrace();
}

return result;
}

private File getPreferencesFile() {
return new File(System.getProperty("user.home") + "/gcviewer.properties");
}

public void setShowDataPanel(boolean showDataPanel) {
setBooleanProperty(GC_LINE_PREFIX + SHOW_DATA_PANEL, showDataPanel);
}

public boolean isShowDataPanel() {
return getBooleanProperty(GC_LINE_PREFIX + SHOW_DATA_PANEL);
}

public boolean isShowDateStamp() {
return getBooleanProperty(GC_LINE_PREFIX + SHOW_DATE_STAMP);
}

public void setShowDateStamp(boolean showDateStamp) {
setBooleanProperty(GC_LINE_PREFIX + SHOW_DATE_STAMP, showDateStamp);
}


}
5 changes: 5 additions & 0 deletions src/main/java/com/tagtraum/perf/gcviewer/ModelChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,9 @@ public interface ModelChart {
void setAntiAlias(boolean antiAlias);

void resetPolygonCache();

void setShowDateStamp(boolean showDateStamp);

boolean isShowDateStamp();

}
36 changes: 27 additions & 9 deletions src/main/java/com/tagtraum/perf/gcviewer/ModelChartImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ModelChartImpl() {
this.chart.setPreferredSize(new Dimension(0, 0));
setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);

// order of the renderers determines what is painted first and last
// we start with what's painted last
GridBagConstraints gridBagConstraints = new GridBagConstraints();
Expand Down Expand Up @@ -103,7 +103,7 @@ public ModelChartImpl() {
horizontalScrollBar = getHorizontalScrollBar();
horizontalScrollBar.setUnitIncrement(50);
horizontalScrollBar.setBlockIncrement(getViewport().getWidth());

JPanel rowHeaderPanel = new JPanel();
GridBagLayout layout = new GridBagLayout();
rowHeaderPanel.setLayout(layout);
Expand Down Expand Up @@ -154,6 +154,7 @@ public void actionPerformed(ActionEvent e) {
}
};
timeOffsetPanel.setOkAction(setOffsetAction);
timeOffsetPanel.setOffsetSet(timestampRuler.getOffset() != 0);
this.timestampRuler.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e) {
maybePopup(e);
Expand Down Expand Up @@ -198,7 +199,7 @@ public void invalidate() {
public void resetPolygonCache() {
chart.resetPolygons();
}

public double getScaleFactor() {
return scaleFactor;
}
Expand All @@ -215,7 +216,7 @@ public void setScaleFactor(double scaleFactor) {
memoryRuler.setSize((int)memoryRuler.getPreferredSize().getWidth(), getViewport().getHeight());
pauseRuler.setSize((int)pauseRuler.getPreferredSize().getWidth(), getViewport().getHeight());
timestampRuler.setSize((int)(getViewport().getWidth()*getScaleFactor()), (int)timestampRuler.getPreferredSize().getHeight());

repaint();
}

Expand All @@ -237,7 +238,7 @@ public boolean isShowTenured() {
@Override
public void setShowTenured(boolean showTenured) {
totalTenuredRenderer.setVisible(showTenured);

// reset cache because young generation needs to be repainted
resetPolygonCache();
}
Expand Down Expand Up @@ -341,23 +342,39 @@ public void setShowInitialMarkLevel(boolean showInitialMarkLevel) {
public boolean isShowInitialMarkLevel() {
return initialMarkLevelRenderer.isVisible();
}

@Override
public void setShowConcurrentCollectionBeginEnd(boolean showConcurrentCollectionBeginEnd) {
concurrentGcLineRenderer.setVisible(showConcurrentCollectionBeginEnd);
}

@Override
public void setShowDateStamp(boolean showDateStamp) {
if (showDateStamp && model.hasDateStamp()) {
timeOffsetPanel.setDate(model.getFirstDateStamp());
timestampRuler.setOffset(timeOffsetPanel.getDate().getTime() / 1000);
timeOffsetPanel.setOffsetSet(true);
timestampRuler.revalidate();
timestampRuler.repaint();
}
}
@Override
public boolean isShowDateStamp(){
return timeOffsetPanel.isOffsetSet();
}


@Override
public boolean isShowConcurrentCollectionBeginEnd() {
return concurrentGcLineRenderer.isVisible();
}

public void setModel(GCModel model, GCPreferences preferences) {
this.model = model;

applyPreferences(preferences);
}

private void applyPreferences(GCPreferences preferences) {
setAntiAlias(preferences.getGcLineProperty(GCPreferences.ANTI_ALIAS));
setShowTenured(preferences.getGcLineProperty(GCPreferences.TENURED_MEMORY));
Expand All @@ -372,6 +389,7 @@ private void applyPreferences(GCPreferences preferences) {
setShowUsedYoungMemoryLine(preferences.getGcLineProperty(GCPreferences.USED_YOUNG_MEMORY));
setShowInitialMarkLevel(preferences.getGcLineProperty(GCPreferences.INITIAL_MARK_LEVEL));
setShowConcurrentCollectionBeginEnd(preferences.getGcLineProperty(GCPreferences.CONCURRENT_COLLECTION_BEGIN_END));
setShowDateStamp(preferences.getGcLineProperty(GCPreferences.SHOW_DATE_STAMP, false));
}

public GCModel getModel() {
Expand Down Expand Up @@ -423,7 +441,7 @@ public Dimension getPreferredSize() {
private int scaleX(double d) {
return (int) (d * getScaleFactor());
}

/**
* Reset the cached polygons of all {@link PolygonChartRenderer}s stored in this chart.
*/
Expand Down
Loading