File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
rxjava-contrib/rxjava-swing/src/main/java/rx Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 15
15
*/
16
16
package rx ;
17
17
18
+ import static rx .Observable .filter ;
19
+
18
20
import java .awt .event .ActionEvent ;
19
21
import java .awt .event .KeyEvent ;
22
+ import java .util .Set ;
20
23
21
24
import javax .swing .AbstractButton ;
22
25
import javax .swing .JComponent ;
23
26
24
27
import rx .swing .sources .AbstractButtonSource ;
25
28
import rx .swing .sources .KeyEventSource ;
29
+ import rx .util .functions .Func1 ;
26
30
27
31
/**
28
32
* Allows creating observables from various sources specific to Swing.
@@ -50,4 +54,20 @@ public static Observable<ActionEvent> fromButtonAction(AbstractButton button) {
50
54
public static Observable <KeyEvent > fromKeyEvents (JComponent component ) {
51
55
return KeyEventSource .fromKeyEventsOf (component );
52
56
}
57
+
58
+ /**
59
+ * Creates an observable corresponding to raw key events, restricted a set of given key codes.
60
+ *
61
+ * @param component
62
+ * The component to register the observable for.
63
+ * @return Observable of key events.
64
+ */
65
+ public static Observable <KeyEvent > fromKeyEvents (JComponent component , final Set <Integer > keyCodes ) {
66
+ return filter (fromKeyEvents (component ), new Func1 <KeyEvent , Boolean >() {
67
+ @ Override
68
+ public Boolean call (KeyEvent event ) {
69
+ return keyCodes .contains (event .getKeyCode ());
70
+ }
71
+ });
72
+ }
53
73
}
You can’t perform that action at this time.
0 commit comments