| final var switchState = new HardwareSwitchState( | ||
| hwSwitch, hwState, switchValue ); | ||
| + | ||
| + // Clear the text before redrawing to prevent discord between the | ||
| + // label colour and the hardware switch's background. | ||
| + if( switchState.isSwitchState( SWITCH_RELEASED ) ) { | ||
| + getHardwareComponent( switchState ).removeAll(); | ||
| + } | ||
| + | ||
| updateSwitchState( switchState ); | ||
| final var keyValue = state.getValue(); | ||
| final var keyColour = KEY_COLOURS.get( state.getHardwareState() ); | ||
| - | ||
| - if( state.isSwitchState( SWITCH_RELEASED ) ) { | ||
| - container.removeAll(); | ||
| - } | ||
| if( state.isModifier() ) { | ||
| 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; | ||
| HardwareComponent<HardwareSwitchState, Image> | ||
| > mSwitches = new HashMap<>(); | ||
| - | ||
| - /** | ||
| - * Images are scaled to these dimensions, maintaining aspect ratio. The | ||
| - * height constrains the width, so as long as the width is sufficiently | ||
| - * large, the application's window will adjust to fit. | ||
| - */ | ||
| - private final Dimension mDimension = new Dimension( 1024, 90 ); | ||
| public HardwareImages() { | ||
| try { | ||
| final var diagram = sRasterizer.loadDiagram( resource ); | ||
| - final var scale = sRasterizer.calculateScale( diagram, mDimension ); | ||
| - final var image = sRasterizer.rasterize( diagram, mDimension ); | ||
| + final var scale = sRasterizer.calculateScale( diagram, APP_DIMENSIONS ); | ||
| + final var image = sRasterizer.rasterize( diagram, APP_DIMENSIONS ); | ||
| return new Pair<>( image, scale ); | ||
| */ | ||
| SWITCH_PRESSED, | ||
| + | ||
| /** | ||
| * Defines when a hardware switch is up. |
| } | ||
| + // This could be thrown when a mouse button is pressed that does not have | ||
| + // a visual representation. | ||
| throw new NoSuchElementException( name ); | ||
| } |
| initWindowFrame(); | ||
| initWindowContents(); | ||
| - initListeners(); | ||
| pack(); | ||
| + initListeners(); | ||
| setVisible( true ); | ||
| } | ||
| addNativeKeyListener( keyboardListener ); | ||
| keyboardListener.addPropertyChangeListener( listener ); | ||
| + keyboardListener.initModifiers(); | ||
| } | ||
| } | ||
| + /** | ||
| + * Unused. Key up and key down are tracked separately from a typed key. | ||
| + * | ||
| + * @param e Ignored. | ||
| + */ | ||
| @Override | ||
| public void nativeKeyTyped( final NativeKeyEvent e ) { | ||
| + } | ||
| + | ||
| + /** | ||
| + * Sets the initial state of the modifiers. | ||
| + */ | ||
| + public void initModifiers() { | ||
| + for( final var key : mSwitches.keySet() ) { | ||
| + final var state = mSwitches.get( key ); | ||
| + | ||
| + // By default, the keys are all "false", so fire fake events indicating | ||
| + // that has one has just transitioned to "false". This will cause the | ||
| + // GUI to repaint with the text label affixed to each key, drawn in the | ||
| + // released state. This happens before the frame is set to visible. | ||
| + tryFire( key, !state, state ); | ||
| + } | ||
| } | ||
| } | ||
| + /** | ||
| + * Unused. | ||
| + * | ||
| + * @param e Ignored. | ||
| + */ | ||
| public void nativeMouseClicked( final NativeMouseEvent e ) { | ||
| -// System.out.println( "Clicked # Times: " + e.getClickCount() ); | ||
| -// System.out.println( "Button clicked: " + e.getButton() ); | ||
| } | ||
| + /** | ||
| + * Unused. | ||
| + * | ||
| + * @param e Ignored. | ||
| + */ | ||
| public void nativeMouseMoved( final NativeMouseEvent e ) { | ||
| -// System.out.println( "Mouse Moved: " + e.getX() + ", " + e.getY() ); | ||
| } | ||
| + /** | ||
| + * Unused. | ||
| + * | ||
| + * @param e Ignored. | ||
| + */ | ||
| public void nativeMouseDragged( final NativeMouseEvent e ) { | ||
| -// System.out.println( "Mouse Dragged: " + e.getX() + ", " + e.getY() ); | ||
| } | ||
| } |
| */ | ||
| public class Constants { | ||
| + /** | ||
| + * Use with {@code setOpaque( false )}. | ||
| + */ | ||
| public static final Color TRANSPARENT = new Color( 0, 0, 0, 0 ); | ||
| + | ||
| + /** | ||
| + * Partially see-through. | ||
| + */ | ||
| public static final Color TRANSLUCENT = new Color( .2f, .2f, .2f, 0.5f ); | ||
| + | ||
| + /** | ||
| + * 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 sufficiently large, the application's window will adjust to | ||
| + * fit. | ||
| + */ | ||
| + public static final Dimension APP_DIMENSIONS = new Dimension( 1024, 90 ); | ||
| /** | ||
| * Default insets, has no padding. | ||
| */ | ||
| - public final static Insets INSETS_EMPTY = | ||
| - new Insets( 0, 0, 0, 0 ); | ||
| + public final static Insets INSETS_EMPTY = new Insets( 0, 0, 0, 0 ); | ||
| /** |
| Author | DaveJarvis <email> |
|---|---|
| Date | 2020-07-22 00:33:28 GMT-0700 |
| Commit | f9402e12b6236b93b99387778d7e4b11bda6fb05 |
| Parent | a18d2dc |
| Delta | 66 lines added, 20 lines removed, 46-line increase |