Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/kmcaster.git
build.gradle
dependencies {
+ // Command-line parsing
+ implementation 'info.picocli:picocli:4.4.0'
+
// SVG
implementation fileTree(include: ['**/*.jar'], dir: 'libs')
src/main/com/whitemagicsoftware/kmcaster/HardwareImages.java
import static com.whitemagicsoftware.kmcaster.HardwareSwitch.*;
import static com.whitemagicsoftware.kmcaster.exceptions.Rethrowable.rethrow;
-import static com.whitemagicsoftware.kmcaster.ui.Constants.APP_DIMENSIONS;
import static java.lang.String.format;
private final static SvgRasterizer sRasterizer = new SvgRasterizer();
+
+ private final Dimension mAppDimensions;
private final Map<
HardwareSwitch,
HardwareComponent<HardwareSwitchState, Image>
> mSwitches = new HashMap<>();
- public HardwareImages() {
+ public HardwareImages( final Dimension appDimensions ) {
+ mAppDimensions = appDimensions;
+
final var mouseStates = createHardwareComponent();
final var mouseReleased = mouseImage( "0" );
try {
- final var diagram = sRasterizer.loadDiagram( resource );
- final var scale = sRasterizer.calculateScale( diagram, APP_DIMENSIONS );
- final var image = sRasterizer.rasterize( diagram, APP_DIMENSIONS );
+ final var d = sRasterizer.loadDiagram( resource );
+ final var scale = sRasterizer.calculateScale( d, getAppDimensions() );
+ final var image = sRasterizer.rasterize( d, getAppDimensions() );
return new Pair<>( image, scale );
} catch( final Exception ex ) {
rethrow( ex );
}
final var msg = format( "Missing resource %s", resource );
throw new RuntimeException( msg );
+ }
+
+ private Dimension getAppDimensions() {
+ return mAppDimensions;
}
}
src/main/com/whitemagicsoftware/kmcaster/KmCaster.java
import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
+import picocli.CommandLine.Command;
import javax.swing.*;
+import java.awt.*;
import java.beans.PropertyChangeListener;
import java.io.IOException;
/**
- * This class is responsible for logging key presses and mouse clicks on the
+ * This class is responsible for casting key presses and mouse clicks on the
* screen. While there is a plethora of software out here that does this,
* none meet all the following criteria: small size, easily positioned,
* </ol>
*/
-@SuppressWarnings("unused")
+@Command(
+ name = "KmCaster",
+ mixinStandardHelpOptions = true,
+ description = "Displays key presses and mouse clicks on the screen."
+)
public class KmCaster extends JFrame {
- private final HardwareImages mHardwareImages = new HardwareImages();
- private final EventHandler mEventHandler =
- new EventHandler( mHardwareImages );
/**
- * Empty constructor; create an instance then call {@link #init()} from
- * within the {@link SwingUtilities#invokeLater(Runnable)} thread.
+ * Application dimensions in pixels. Images are scaled to these dimensions,
+ * maintaining aspect ratio. The height constrains the width, so as long as
+ * the width is large enough, the application's window will adjust to fit.
+ */
+ public static final Dimension APP_DIMENSIONS = new Dimension( 1024, 70 );
+
+ /**
+ * Milliseconds to wait before releasing (clearing) the regular key.
+ */
+ public final static int DELAY_KEY_REGULAR = 250;
+
+ /**
+ * Milliseconds to wait before releasing (clearing) any modifier key.
+ */
+ public final static int DELAY_KEY_MODIFIER = 150;
+
+ private final HardwareImages mHardwareImages;
+ private final EventHandler mEventHandler;
+
+ /**
+ * Create an instance then call {@link #init()} from within the
+ * {@link SwingUtilities#invokeLater(Runnable)} thread.
*/
public KmCaster() {
+ mHardwareImages = new HardwareImages( APP_DIMENSIONS );
+ mEventHandler = new EventHandler( mHardwareImages );
}
src/main/com/whitemagicsoftware/kmcaster/ui/Constants.java
/**
- * Application dimensions in pixels. Images are scaled to these dimensions,
- * maintaining aspect ratio. The height constrains the width, so as long as
- * the width is large enough, the application's window will adjust to fit.
- */
- public static final Dimension APP_DIMENSIONS = new Dimension( 1024, 100 );
-
- /**
* Default insets, has no padding.
*/
public final static Insets INSETS_EMPTY = new Insets( 0, 0, 0, 0 );
-
- /**
- * Milliseconds to wait before releasing (clearing) the regular key.
- */
- public final static int DELAY_KEY_REGULAR = 250;
-
- /**
- * Milliseconds to wait before releasing (clearing) any modifier key.
- */
- public final static int DELAY_KEY_MODIFIER = 150;
/**

Migrate constants for command-line parsing

Author DaveJarvis <email>
Date 2020-07-25 19:25:27 GMT-0700
Commit ee8e594c12acd91f6ec6c97fca1c628e9d5bc46d
Parent 3472b42
Delta 47 lines added, 29 lines removed, 18-line increase