01: package com.tagtraum.perf.gcviewer.action;
02:
03: import com.tagtraum.perf.gcviewer.GCDocument;
04: import com.tagtraum.perf.gcviewer.GCViewer;
05:
06: import javax.swing.*;
07: import java.awt.*;
08: import java.awt.event.ActionEvent;
09:
10: /**
11: *
12: * @author <a href="mailto:hs@tagtraum.com">Hendrik Schreiber</a>
13: * Date: May 20, 2005
14: * Time: 1:59:59 PM
15: *
16: */
17: public class Watch extends AbstractAction {
18: private GCViewer gcViewer;
19: private static final ImageIcon WATCH_ICON = new ImageIcon(Toolkit
20: .getDefaultToolkit().getImage(
21: GCViewer.class.getResource("images/watch.png")));
22:
23: public Watch(final GCViewer gcViewer) {
24: this .gcViewer = gcViewer;
25: putValue(NAME, GCViewer.localStrings
26: .getString("main_frame_menuitem_watch"));
27: putValue(SHORT_DESCRIPTION, GCViewer.localStrings
28: .getString("main_frame_menuitem_hint_watch"));
29: putValue(MNEMONIC_KEY, new Integer(GCViewer.localStrings
30: .getString("main_frame_menuitem_mnemonic_watch")
31: .charAt(0)));
32: putValue(ACTION_COMMAND_KEY, "watch");
33: putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('W',
34: Event.CTRL_MASK));
35: putValue(SMALL_ICON, WATCH_ICON);
36: setEnabled(false);
37: }
38:
39: public void actionPerformed(final ActionEvent ae) {
40: final AbstractButton source = (AbstractButton) ae.getSource();
41: if (source.isSelected()) {
42: final GCDocument selectedGCDocument = gcViewer
43: .getSelectedGCDocument();
44: selectedGCDocument.setWatched(true);
45: selectedGCDocument.getRefreshWatchDog().setAction(this );
46: selectedGCDocument.getRefreshWatchDog().start();
47: } else {
48: final GCDocument selectedGCDocument = gcViewer
49: .getSelectedGCDocument();
50: selectedGCDocument.setWatched(false);
51: selectedGCDocument.getRefreshWatchDog().stop();
52: }
53: }
54:
55: public void setEnabled(final boolean newValue) {
56: super.setEnabled(newValue);
57: if (!newValue) {
58: putValue(SMALL_ICON, WATCH_ICON);
59: }
60: }
61: }
|