mbien commented on PR #8276:
URL: https://github.com/apache/netbeans/pull/8276#issuecomment-2681930534
usage wise: if you replace `start()` with `enable()` and `hide()` with
`disable()` you can do the exact same thing with the impl of this PR.
using swing Timer and dropping the life span concept (since that would
require two timers) the impl would look like:
```java
/// Shows the wait cursor after an initial delay.
/// Can be used in ARM-blocks.
private static class DelayedWaitCursor implements AutoCloseable {
private static final int SPAWN_DELAY = 200;
private final JRootPane root;
private Timer timer;
private DelayedWaitCursor(JRootPane root) {
this.root = root;
}
private synchronized void enable() {
if (timer != null) {
return;
}
timer = new Timer(SPAWN_DELAY, (e) -> {
root.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
root.getGlassPane().setVisible(true);
});
timer.setRepeats(false);
timer.start();
}
private synchronized void disable() {
if (timer != null) {
timer.stop();
SwingUtilities.invokeLater(() -> {
root.getGlassPane().setVisible(false);
root.getGlassPane().setCursor(null);
});
timer = null;
}
}
@Override
public void close() {
disable();
}
}
```
this would also work since the timer has a global reentrant lock for the
queue. So i believe there can't be a race between stop() and wait cursor
activation - which is the main concern since this leads to stuck cursors.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists