11package 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 ;
74import 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 */
1517public 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