Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/kmcaster.git

Bubble double-key presses for regular keys

Author DaveJarvis <email>
Date 2020-07-25 16:13:39 GMT-0700
Commit b99c06dcedfa707e71c08f735b6230cfc64194f4
Parent cbd288d
src/main/com/whitemagicsoftware/kmcaster/EventHandler.java
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
import static com.whitemagicsoftware.kmcaster.HardwareState.SWITCH_PRESSED;
component.setState( switchState );
}
+
+
/**
final var keyValue = state.getValue();
final var keyColour = KEY_COLOURS.get( state.getHardwareState() );
+
+// if( state.isHardwareState( SWITCH_RELEASED ) ) {
+// //System.out.println( "RELEASED: " + keyValue );
+// }
if( state.isModifier() ) {
src/main/com/whitemagicsoftware/kmcaster/listeners/KeyboardListener.java
assert n != null;
- tryFire( KEY_REGULAR, o, n );
+ fire( KEY_REGULAR, o, n );
mRegularHeld = n;
}
src/main/com/whitemagicsoftware/kmcaster/listeners/PropertyDispatcher.java
package com.whitemagicsoftware.kmcaster.listeners;
+import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
/**
* Called to fire the property change with the two given values differ.
+ * Normally events for the same old and new value are swallowed silently,
+ * which prevents double-key presses from bubbling up. Tracking double-key
+ * presses is used to increment a counter that is displayed on the key when
+ * the user continually types the same regular key.
*
- * @param p The property name that has changed.
+ * @param p Property name that has changed.
* @param o Old property value.
* @param n New property value.
*/
- protected void tryFire(
- final P p, final String o, final String n ) {
- if( !o.equals( n ) ) {
- mDispatcher.firePropertyChange( p.toString(), o, n );
- }
+ protected void fire( final P p, final String o, final String n ) {
+ final var pName = p.toString();
+ final var event = new PropertyChangeEvent( mDispatcher, pName, o, n );
+ mDispatcher.firePropertyChange( event );
}
/**
- * Delegates to {@link #tryFire(P, String, String)} with
- * {@link Boolean}
- * values as strings.
+ * Delegates to {@link #fire(P, String, String)} with {@link Boolean} values
+ * as strings.
*
- * @param p The property name that has changed.
+ * @param p Property name that has changed.
* @param o Old property value.
* @param n New property value.
*/
- protected void tryFire(
- final P p, final boolean o, final boolean n ) {
- tryFire( p, Boolean.toString( o ), Boolean.toString( n ) );
+ protected void tryFire( final P p, final boolean o, final boolean n ) {
+ if( o != n ) {
+ fire( p, Boolean.toString( o ), Boolean.toString( n ) );
+ }
}
}
Delta 26 lines added, 14 lines removed, 12-line increase