Dave Jarvis' Repositories

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

Start to add mouse click delay

Author DaveJarvis <email>
Date 2020-07-31 19:56:55 GMT-0700
Commit 1a0c8809bbcb239c24a175661739f2b816f9a6a0
Parent 460f0b0
src/main/com/whitemagicsoftware/kmcaster/EventHandler.java
if( hwState == SWITCH_RELEASED ) {
- timer.addActionListener( ( event ) -> {
- updateSwitchState( switchState );
- updateSwitchLabel( switchState );
- } );
+ timer.addActionListener(
+ ( event ) -> updateKeyboardLabel( switchState )
+ );
}
else {
timer.stop();
- updateSwitchState( switchState );
- updateSwitchLabel( switchState );
+ updateKeyboardLabel( switchState );
}
}
else {
updateSwitchState( switchState );
}
}
protected void updateSwitchState( final HardwareSwitchState switchState ) {
- final var component = getHardwareComponent( switchState );
- component.setState( switchState );
+ getHardwareComponent( switchState ).setState( switchState );
}
* @param state The key that has changed.
*/
- protected synchronized void updateSwitchLabel(
+ protected synchronized void updateKeyboardLabel(
final HardwareSwitchState state ) {
+ updateSwitchState( state );
final var hwState = state.getHardwareState();
// Label for number pad keys or icon glyphs.
main.setText( keyValue.substring( index + 1 ) );
- main.transform( .9f );
+ main.transform( .8f );
// Shift the main label down away from the superscript.
final var mainLoc = main.getLocation();
- main.setLocation( mainLoc.x, mainLoc.y + (sup.getHeight() / 3) );
+ main.setLocation( mainLoc.x, mainLoc.y + (sup.getHeight() / 2) );
main.setVisible( true );
src/main/com/whitemagicsoftware/kmcaster/HardwareSwitch.java
MOUSE_MIDDLE( "2" ),
MOUSE_RIGHT( "3" ),
+ MOUSE_REGULAR("4"),
KEY_SHIFT( "shift", SHIFT_MASK ),
KEY_CTRL( "ctrl", CTRL_MASK ),
src/main/com/whitemagicsoftware/kmcaster/KmCaster.java
/**
+ * Milliseconds to wait before releasing (clearing) any mouse button.
+ */
+ @Option(
+ names = {"-c", "--delay-click"},
+ description = "Delay for releasing mouse buttons (${DEFAULT-VALUE} " +
+ "milliseconds)",
+ paramLabel = "delay",
+ defaultValue = "200"
+ )
+ private int mDelayMouseClick = 200;
+
+ /**
* Empty constructor so that command line arguments may be parsed.
*/
for( final var hwSwitch : HardwareSwitch.values() ) {
final var component = hardwareImages.get( hwSwitch );
- panel.add( component );
+
+ // If there is no image for the switch, it may be a a mouse button
+ // without a direct visual representation.
+ if( component != null ) {
+ panel.add( component );
+ }
}
src/main/com/whitemagicsoftware/kmcaster/ui/ResetTimer.java
* A one-off timer that can be reset to its initial delay.
*/
-public class ResetTimer extends Timer {
+public final class ResetTimer extends Timer {
/**
* @inheritDoc
Delta 29 lines added, 13 lines removed, 16-line increase