Dave Jarvis' Repositories

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

Paint component immediately, set bounds not size

Author DaveJarvis <email>
Date 2020-07-27 13:26:24 GMT-0700
Commit 975e767e21a50be76b3c9c087495de16fc20efee
Parent 1d59bf3
src/main/com/whitemagicsoftware/kmcaster/EventHandler.java
component.removeAll();
}
+
+ component.paintImmediately( component.getBounds()) ;
}
}
src/main/com/whitemagicsoftware/kmcaster/HardwareState.java
/**
* Returns the {@link HardwareState} that corresponds to the given
- * state string. If the state string equals {@link Boolean#FALSE} (case
- * is sensitive), then this will return {@link #SWITCH_RELEASED}. Any
- * other value will return {@link #SWITCH_PRESSED}.
+ * state string. If the state equals {@link Boolean#FALSE} (case is
+ * sensitive) or is empty, then this will return {@link #SWITCH_RELEASED},
+ * otherwise {@link #SWITCH_PRESSED}.
*
* @param state The state to convert to an enumerated type.
src/main/com/whitemagicsoftware/kmcaster/HardwareSwitch.java
*/
public boolean isKeyboard() {
- return isPrefix( "KEY" );
- }
-
- /**
- * Answers whether this hardware switch represents a mouse button.
- *
- * @return {@code true} when this is a mouse button.
- */
- public boolean isMouse() {
- return isPrefix( "MOUSE" );
- }
-
- /**
- * Answers whether the enum's name starts with the given string, using
- * a case sensitive comparison.
- *
- * @param prefix The prefix to check against.
- * @return {@code true} when the prefix matches the enumerated name.
- */
- private boolean isPrefix( final String prefix ) {
- return name().startsWith( prefix );
+ return name().startsWith( "KEY" );
}
src/main/com/whitemagicsoftware/kmcaster/KmCaster.java
*/
public KmCaster() {
+ super( KmCaster.class.getSimpleName() );
}
.stackTraces( Style.italic )
.build();
+ }
+
+ /**
+ * Invoked after the command-line arguments are parsed.
+ *
+ * @return Exit level zero.
+ */
+ @Override
+ public Integer call() {
+ init();
+ return 0;
}
final var kc = new KmCaster();
- final var cli = new CommandLine( kc );
- cli.setColorScheme( createColourScheme() );
+ final var parser = new CommandLine( kc );
+ parser.setColorScheme( createColourScheme() );
invokeLater( () -> {
- final var exitCode = cli.execute( args );
- final var parseResult = cli.getParseResult();
+ final var exitCode = parser.execute( args );
+ final var parseResult = parser.getParseResult();
if( parseResult.isUsageHelpRequested() ) {
System.exit( exitCode );
}
} );
- }
-
- @Override
- public Integer call() {
- init();
- return 0;
}
}
src/main/com/whitemagicsoftware/kmcaster/ui/AutofitLabel.java
import java.awt.*;
-import static java.awt.Toolkit.getDefaultToolkit;
import static java.awt.event.HierarchyEvent.PARENT_CHANGED;
import static java.lang.Math.floor;
public AutofitLabel( final String text, final Font font ) {
super( text );
+ setDoubleBuffered( true );
setFont( font );
addHierarchyListener( e -> {
final var parent = getParent();
if( (e.getChangeFlags() & PARENT_CHANGED) != 0 &&
(e.getChangedParent() == parent) ) {
- final var bounds = BoundsCalculator.getBounds( parent );
-
- setSize( bounds.width, bounds.height );
- setLocation( bounds.x, bounds.y );
+ setBounds( BoundsCalculator.getBounds( parent ) );
}
} );
}
/**
* Note that {@link #setSize(Dimension)} eventually delegates to calling this
* method, so there's no need to override both. The {@link Graphics} context
* must be valid before calling this method.
- *
- * @param w The new width constraint.
- * @param h The new height constraint.
- */
- @Override
- public void setSize( final int w, final int h ) {
- super.setSize( w, h );
- rescale();
- }
-
- /**
+ * <p>
* Rescales the constructed font to fit within the label's dimensions,
* governed by {@link #getWidth()} and {@link #getHeight()}. This must only
* be called after a {@link Graphics} context is available to compute the
* maximum {@link Font} size that will fit the label's {@link Rectangle}
* bounds.
+ * </p>
+ *
+ * @param x The new horizontal position.
+ * @param y The new horizontal position.
+ * @param w The new width constraint.
+ * @param h The new height constraint.
*/
- private void rescale() {
+ @Override
+ public void setBounds( final int x, final int y, final int w, final int h ) {
+ super.setBounds( x, y, w, h );
setFont( computeScaledFont() );
paintImmediately( getBounds() );
var minSizePt = 1;
- var maxSizePt = 100;
+ var maxSizePt = 200;
var scaledFont = getFont();
var scaledPt = scaledFont.getSize();
Delta 35 lines added, 52 lines removed, 17-line decrease