Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
135 lines (118 loc) · 3.28 KB

File metadata and controls

135 lines (118 loc) · 3.28 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/*
* A class that monitors inactivity in an application.
*
* It does this by using a Swing Timer and by listening for specified
* AWT events. When an event is received the Timer is restarted.
* If no event is received during the specified time interval then the
* timer will fire and invoke the specified Action.
*
* When creating the listener the inactivity interval is specified in
* minutes. However, once the listener has been created you can reset
* this value in milliseconds if you need to.
*
* Some common event masks have be defined with the class:
*
* KEY_EVENTS
* MOUSE_EVENTS - which includes mouse motion events
* USER_EVENTS - includes KEY_EVENTS and MOUSE_EVENT (this is the default)
*
* The inactivity interval and event mask can be changed at any time,
* however, they will not become effective until you stop and start
* the listener.
*/
class InactivityListener implements ActionListener, AWTEventListener
{
public final static long KEY_EVENTS = AWTEvent.KEY_EVENT_MASK;
public final static long MOUSE_EVENTS =
AWTEvent.MOUSE_MOTION_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK;
public final static long USER_EVENTS = KEY_EVENTS + MOUSE_EVENTS;
private Action action;
private int interval;
private long eventMask;
private Timer timer = new Timer(0, this);
/*
* Use a default inactivity interval of 1 minute and listen for
* USER_EVENTS
*/
public InactivityListener(Action action)
{
this(action, 1);
}
/*
* Specify the inactivity interval and listen for USER_EVENTS
*/
public InactivityListener(Action action, int interval)
{
this(action, interval, USER_EVENTS);
}
/*
* Specify the inactivity interval and the events to listen for
*/
public InactivityListener(Action action, int minutes, long eventMask)
{
setAction( action );
setInterval( minutes );
setEventMask( eventMask );
}
/*
* The Action to be invoked after the specified inactivity period
*/
public void setAction(Action action)
{
this.action = action;
}
/*
* The interval before the Action is invoked specified in minutes
*/
public void setInterval(int minutes)
{
setIntervalInMillis(minutes * 60000);
}
/*
* The interval before the Action is invoked specified in milliseconds
*/
public void setIntervalInMillis(int interval)
{
this.interval = interval;
timer.setInitialDelay(interval);
}
/*
* A mask specifying the events to be passed to the AWTEventListener
*/
public void setEventMask(long eventMask)
{
this.eventMask = eventMask;
}
/*
* Start listening for events.
*/
public void start()
{
timer.setInitialDelay(interval);
timer.setRepeats(false);
timer.start();
Toolkit.getDefaultToolkit().addAWTEventListener(this, eventMask);
}
/*
* Stop listening for events
*/
public void stop()
{
Toolkit.getDefaultToolkit().removeAWTEventListener(this);
timer.stop();
}
// Implement ActionListener for the Timer
public void actionPerformed(ActionEvent e)
{
action.actionPerformed(e);
}
// Implement AWTEventListener
public void eventDispatched(AWTEvent e)
{
if (timer.isRunning())
timer.restart();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.