Skip to content

Commit fd7efc1

Browse files
committed
suppress parser error dialog when refreshing automatically
1 parent 40d6c4a commit fd7efc1

File tree

3 files changed

+55
-37
lines changed

3 files changed

+55
-37
lines changed

src/main/java/com/tagtraum/perf/gcviewer/ChartPanelView.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,17 @@ public ChartPanelView(GCDocument gcDocument, URL url) throws DataReaderException
9191
}
9292

9393
/**
94-
* @return true, if the files has been reloaded
94+
* Reloads the model displayed in this chart panel if it has changed. Using the parameter
95+
* the parser error dialog can be suppressed.
96+
*
97+
* @param showParserErrors if <code>true</code> parser errors will be shown
98+
* @return <code>true</code>, if the file has been reloaded
9599
* @throws DataReaderException if something went wrong reading the file
96100
*/
97-
public boolean reloadModel() throws DataReaderException {
101+
public boolean reloadModel(boolean showParserErrors) throws DataReaderException {
98102
if (model.getURL() == null) return false;
99103
if (model.isDifferent(model.getURL())) {
100-
setModel(dataReaderFacade.loadModel(this.model.getURL(), true, gcDocument));
104+
setModel(dataReaderFacade.loadModel(this.model.getURL(), showParserErrors, gcDocument));
101105
return true;
102106
}
103107
return false;

src/main/java/com/tagtraum/perf/gcviewer/GCDocument.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public void setShowModelPanel(boolean showModelPanel) {
127127
public boolean reloadModels(boolean background) throws DataReaderException {
128128
boolean reloaded = false;
129129
for (ChartPanelView chartPanelView : chartPanelViews) {
130-
reloaded |= chartPanelView.reloadModel();
130+
reloaded |= chartPanelView.reloadModel(!refreshWatchDog.isRunning());
131131
}
132132
if (!background) {
133133
relayout();

src/main/java/com/tagtraum/perf/gcviewer/RefreshWatchDog.java

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,94 @@
11
package com.tagtraum.perf.gcviewer;
22

3-
import javax.swing.*;
4-
import java.awt.*;
5-
import java.awt.event.ActionEvent;
6-
import java.awt.event.ActionListener;
3+
import java.awt.Toolkit;
74
import java.util.TimerTask;
85

6+
import javax.swing.Action;
7+
import javax.swing.ImageIcon;
8+
import javax.swing.SwingUtilities;
9+
910
/**
11+
* Timer to trigger refresh of changed log files.
1012
*
11-
* Date: May 26, 2005
12-
* Time: 2:04:38 PM
13+
* <p>Date: May 26, 2005</p>
14+
* <p>Time: 2:04:38 PM</p>
1315
* @author <a href="mailto:[email protected]">Hendrik Schreiber</a>
1416
*/
1517
public class RefreshWatchDog {
1618
private GCDocument gcDocument;
17-
private javax.swing.Timer animationTimer;
1819
private java.util.Timer reloadTimer;
1920
private Action action;
21+
private boolean isRunning;
2022
public static final ImageIcon WATCH_ICON = new ImageIcon(Toolkit.getDefaultToolkit().getImage(GCViewerGui.class.getResource("images/watch.png")));
2123
private static final ImageIcon CLOCK_ICON = new ImageIcon(Toolkit.getDefaultToolkit().getImage(GCViewerGui.class.getResource("images/clock.png")));
22-
/*
23-
private static final ImageIcon CLOCK_N_ICON = new ImageIcon(Toolkit.getDefaultToolkit().getImage(GCViewer.class.getResource("images/clock_n.gif")));
24-
private static final ImageIcon CLOCK_NE_ICON = new ImageIcon(Toolkit.getDefaultToolkit().getImage(GCViewer.class.getResource("images/clock_ne.gif")));
25-
private static final ImageIcon CLOCK_E_ICON = new ImageIcon(Toolkit.getDefaultToolkit().getImage(GCViewer.class.getResource("images/clock_e.gif")));
26-
private static final ImageIcon CLOCK_SE_ICON = new ImageIcon(Toolkit.getDefaultToolkit().getImage(GCViewer.class.getResource("images/clock_se.gif")));
27-
private static final ImageIcon CLOCK_S_ICON = new ImageIcon(Toolkit.getDefaultToolkit().getImage(GCViewer.class.getResource("images/clock_s.gif")));
28-
private static final ImageIcon CLOCK_SW_ICON = new ImageIcon(Toolkit.getDefaultToolkit().getImage(GCViewer.class.getResource("images/clock_sw.gif")));
29-
private static final ImageIcon CLOCK_W_ICON = new ImageIcon(Toolkit.getDefaultToolkit().getImage(GCViewer.class.getResource("images/clock_w.gif")));
30-
private static final ImageIcon CLOCK_NW_ICON = new ImageIcon(Toolkit.getDefaultToolkit().getImage(GCViewer.class.getResource("images/clock_nw.gif")));
31-
private static final ImageIcon[] CLOCK_ICONS = new ImageIcon[] {CLOCK_N_ICON, CLOCK_NE_ICON, CLOCK_E_ICON, CLOCK_SE_ICON, CLOCK_S_ICON, CLOCK_SW_ICON, CLOCK_W_ICON, CLOCK_NW_ICON};
32-
*/
33-
private static final int ANIMATION_DELAY = 250;
3424
private static final int RELOAD_DELAY = 1000;
3525

26+
/**
27+
* Get the {@link GCDocument} this watchdog is used for.
28+
* @return GCDocument for this watchdog
29+
*/
3630
public GCDocument getGcDocument() {
3731
return gcDocument;
3832
}
3933

34+
/**
35+
* Set the {@link GCDocument} this watchdog should trigger refreshes for.
36+
* @param gcDocument to be refreshed
37+
*/
4038
public void setGcDocument(GCDocument gcDocument) {
4139
this.gcDocument = gcDocument;
4240
}
4341

42+
/**
43+
* Get action that is triggered by the watchdog.
44+
* @return Action to be triggered
45+
*/
4446
public Action getAction() {
4547
return action;
4648
}
4749

50+
/**
51+
* Set action to be triggered by this watchdog.
52+
* @param action Action to be triggered
53+
*/
4854
public void setAction(Action action) {
4955
this.action = action;
5056
}
5157

58+
/**
59+
* Start the watchdog.
60+
*/
5261
public void start() {
53-
animationTimer = new javax.swing.Timer(ANIMATION_DELAY, new ClockAnimation());
5462
reloadTimer = new java.util.Timer(true);
5563
reloadTimer.schedule(new ModelReloader(), 0, RELOAD_DELAY);
5664
action.putValue(Action.SMALL_ICON, CLOCK_ICON);
57-
animationTimer.start();
65+
isRunning = true;
5866
}
5967

68+
/**
69+
* Stop the watchdog.
70+
*/
6071
public void stop() {
6172
if (reloadTimer != null) reloadTimer.cancel();
62-
if (animationTimer != null && animationTimer.isRunning()) animationTimer.stop();
6373
if (action != null) action.putValue(Action.SMALL_ICON, WATCH_ICON);
74+
isRunning = false;
6475
}
65-
66-
private class ClockAnimation implements ActionListener {
67-
private int clockIndex;
68-
public void actionPerformed(final ActionEvent e) {
69-
if (action != null) {
70-
//clockIndex = (clockIndex+1) % CLOCK_ICONS.length;
71-
//action.putValue(Action.SMALL_ICON, CLOCK_ICONS[clockIndex]);
72-
}
73-
}
76+
77+
/**
78+
* Is the watchdog timer currently running and triggering refreshes of the logs?
79+
* @return <code>true</code> if it is running, <code>false</code> otherwise.
80+
*/
81+
public boolean isRunning() {
82+
return isRunning;
7483
}
7584

85+
/**
86+
* Implementation of the task to reload the model.
87+
*
88+
* <p>Date: May 26, 2005</p>
89+
* <p>Time: 2:04:38 PM</p>
90+
* @author <a href="mailto:[email protected]">Hendrik Schreiber</a>
91+
*/
7692
private class ModelReloader extends TimerTask {
7793
public void run() {
7894
try {
@@ -81,8 +97,6 @@ public void run() {
8197
SwingUtilities.invokeAndWait(new Runnable() {
8298
public void run() {
8399
gcDocument.relayout();
84-
//gcDocument.scrollToRightEdge();
85-
//gcDocument.repaint();
86100
}
87101
});
88102
}

0 commit comments

Comments
 (0)