-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZonePanel is now processing key presses in a reactive way (#271)
- Loading branch information
1 parent
8fbf021
commit 11a4bb3
Showing
6 changed files
with
183 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
dz3r-swing/src/main/java/net/sf/dz3r/view/swing/KeyFlux.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package net.sf.dz3r.view.swing; | ||
|
||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Sinks; | ||
|
||
import java.awt.event.KeyEvent; | ||
import java.awt.event.KeyListener; | ||
import java.time.Duration; | ||
|
||
/** | ||
* Reactive adapter for the {@link KeyListener} interface. | ||
* | ||
* @author Copyright © <a href="mailto:vt@homeclimatecontrol.com">Vadim Tkachenko</a> 2001-2023 | ||
*/ | ||
public class KeyFlux implements KeyListener { | ||
|
||
private final Sinks.Many<KeyEvent> sink; | ||
public final Flux<KeyEvent> flux; | ||
|
||
public KeyFlux() { | ||
sink = Sinks.many().replay().limit(Duration.ofMinutes(1)); | ||
flux = sink.asFlux(); | ||
} | ||
|
||
@Override | ||
public void keyTyped(KeyEvent e) { | ||
sink.tryEmitNext(e); | ||
} | ||
|
||
@Override | ||
public void keyPressed(KeyEvent e) { | ||
sink.tryEmitNext(e); | ||
} | ||
|
||
@Override | ||
public void keyReleased(KeyEvent e) { | ||
sink.tryEmitNext(e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.