Dave Jarvis' Repositories

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

Replace bounds calculation with static method

AuthorDaveJarvis <email>
Date2020-07-25 21:09:59 GMT-0700
Commit30d24366e6e68594968c803591c089d205ce109e
Parent1d3c9fb
src/main/com/whitemagicsoftware/kmcaster/EventHandler.java
final var keyValue = state.getValue();
+ // A non-modifier key has been pressed.
if( pressed ) {
- // A non-modifier key has been pressed.
- System.out.println( "KEY PRESSED: " + keyValue );
-
// Determine whether there are separate parts for the key label.
final var index = keyValue.indexOf( ' ' );
- final var calculator = new BoundsCalculator( component );
- final var bounds = calculator.getBounds();
- final var compDimen = new ScalableDimension( bounds.width, bounds.height );
+ final var bounds = BoundsCalculator.getBounds( component );
+ final var compDimen = new ScalableDimension(
+ bounds.width, bounds.height );
// If there's a space in the name, the text before the space is
final var ty = bounds.y;
- tally.setLocation( (int)tx, ty );
+ tally.setLocation( (int) tx, ty );
tally.setVisible( true );
}
src/main/com/whitemagicsoftware/kmcaster/ui/AutofitLabel.java
if( (e.getChangeFlags() & PARENT_CHANGED) != 0 &&
(e.getChangedParent() == parent) ) {
- final var calculator = new BoundsCalculator( parent );
- final var bounds = calculator.getBounds();
+ final var bounds = BoundsCalculator.getBounds( parent );
setSize( bounds.width, bounds.height );
src/main/com/whitemagicsoftware/kmcaster/ui/BoundsCalculator.java
* {@link Container}'s bounds {@link Rectangle} and {@link Insets}.
*/
-public class BoundsCalculator {
- private final Container mContainer;
-
- public BoundsCalculator( final Container container ) {
- assert container != null;
-
- mContainer = container;
- }
+public final class BoundsCalculator {
/**
* Returns the total width and height of an area that is safe for
* writing on the {@link Container} parameter provided during construction.
*
* @return The {@link Container}'s safe area, based on the
* {@link Container}'s bounded dimensions and insets.
*/
- public Rectangle getBounds() {
- final var container = getContainer();
- final var insets = getInsets();
+ public static Rectangle getBounds( final Container container ) {
+ final var insets = container.getInsets();
return new Rectangle(
insets.left, insets.top,
container.getWidth() - (insets.left + insets.right),
container.getHeight() - (insets.top + insets.bottom)
);
- }
-
- public Insets getInsets() {
- return mContainer.getInsets();
- }
-
- private Container getContainer() {
- return mContainer;
}
}
Delta9 lines added, 28 lines removed, 19-line decrease