Dave Jarvis' Repositories

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

Align key cap to center

Author DaveJarvis <email>
Date 2020-07-19 21:59:29 GMT-0700
Commit 91311b37658137a4cd9f2420c29c9047cde12b33
Parent d4dc956
src/main/com/whitemagicsoftware/kmcaster/EventHandler.java
import static java.awt.Font.BOLD;
import static java.lang.Boolean.parseBoolean;
+import static javax.swing.SwingConstants.CENTER;
public class EventHandler implements PropertyChangeListener {
if( !"false".equals( value ) ) {
final var label = new AutofitLabel( value, LABEL_FONT, LABEL_COLOUR );
+ label.setHorizontalAlignment( CENTER );
component.add( label );
src/main/com/whitemagicsoftware/kmcaster/HardwareComponent.java
/**
* Constructs a new {@link HardwareComponent} without an initial state. The
- * initial state must be set by calling {@link #setState(Object)} before
- * drawing the image.
+ * initial state must be set by calling {@link #setState(Object)}
+ * or {@link #put(Object, Image)} before drawing the image.
+ * <p>
+ * The default insets will be empty.
+ * </p>
*/
public HardwareComponent() {
this( INSETS_EMPTY );
}
+ /**
+ * Constructs a new {@link HardwareComponent} without an initial state. The
+ * initial state must be set by calling {@link #setState(Object)}
+ * or {@link #put(Object, Image)} before drawing the image.
+ *
+ * @param insets The padding to use around the component so that letters
+ * can be drawn within a safe region, without extending beyond
+ * what we'd expected to see visually for key cap text.
+ */
public HardwareComponent( final Insets insets ) {
mInsets = insets;
src/main/com/whitemagicsoftware/kmcaster/listeners/KeyboardListener.java
import static com.whitemagicsoftware.kmcaster.HardwareSwitch.*;
+import static java.lang.Boolean.FALSE;
import static java.util.Map.entry;
import static org.jnativehook.keyboard.NativeKeyEvent.getKeyText;
);
+ /**
+ * Stores the state of modifier keys.
+ */
private final Map<HardwareSwitch, Boolean> mModifiers = new HashMap<>();
@Override
public void nativeKeyReleased( final NativeKeyEvent e ) {
- updateRegular( getDisplayText( e ), "false" );
+ updateRegular( getDisplayText( e ), FALSE.toString() );
updateModifiers( e );
}
src/main/com/whitemagicsoftware/kmcaster/ui/AutofitLabel.java
setSize( bounds.width, bounds.height );
setFont( computeScaledFont() );
+ setHorizontalAlignment( CENTER );
}
Delta 22 lines added, 3 lines removed, 19-line increase