|
|
|
|
|
public class EventHandler implements PropertyChangeListener { |
|
|
- private static final Font DEFAULT_FONT = new Font( "DejaVu Sans", BOLD, 12 ); |
|
|
- private static final Color COLOUR_LABEL = new Color( 33, 33, 33 ); |
|
|
+ private static final Font LABEL_FONT = new Font( "DejaVu Sans", BOLD, 12 ); |
|
|
+ private static final Color LABEL_COLOUR = new Color( 33, 33, 33 ); |
|
|
|
|
|
private final HardwareImages mHardwareImages; |
 |
|
|
final HardwareState state, final String value ) { |
|
|
if( state.isModifier() ) { |
|
|
- //final var pressed = parseBoolean( value ); |
|
|
- //System.out.println( "Modifier pressed: " + pressed ); |
|
|
+ System.out.println( parseBoolean( value ) ); |
|
|
} |
|
|
else { |
 |
|
|
|
|
|
final var label = new JLabel( text ); |
|
|
- label.setFont( DEFAULT_FONT ); |
|
|
+ label.setFont( LABEL_FONT ); |
|
|
label.setSize( width, height ); |
|
|
- label.setForeground( COLOUR_LABEL ); |
|
|
- //label.setBorder( BorderFactory.createLineBorder( Color.RED ) ); |
|
|
+ label.setForeground( LABEL_COLOUR ); |
|
|
|
|
|
- final var scaledFont = scale( label, r, graphics ); |
|
|
+ final var scaledFont = scaleFont( label, r, graphics ); |
|
|
label.setFont( scaledFont ); |
|
|
|
 |
|
|
* string within the bounds of the given {@link Rectangle}. |
|
|
*/ |
|
|
- private Font scale( |
|
|
+ public Font scaleFont( |
|
|
final JLabel label, final Rectangle dst, final Graphics graphics ) { |
|
|
assert label != null; |
 |
|
|
float scaledPt = scaledFont.getSize(); |
|
|
|
|
|
- while( maxSizePt - minSizePt > 2 ) { |
|
|
+ while( maxSizePt - minSizePt > 1f ) { |
|
|
scaledFont = scaledFont.deriveFont( scaledPt ); |
|
|
|
|
|
-// final var layout = new TextLayout( text, scaledFont, frc ); |
|
|
-// final float fontWidthPx = layout.getVisibleAdvance(); |
|
|
- final var fm = graphics.getFontMetrics(scaledFont); |
|
|
- final float fontWidthPx = (float)fm.getStringBounds( text, graphics ).getWidth(); |
|
|
+ final var layout = new TextLayout( text, scaledFont, frc ); |
|
|
+ final var fontWidthPx = layout.getVisibleAdvance(); |
|
|
|
|
|
final var metrics = scaledFont.getLineMetrics( text, frc ); |
|
|
- final float fontHeightPx = metrics.getHeight(); |
|
|
+ final var fontHeightPx = metrics.getHeight(); |
|
|
|
|
|
if( (fontWidthPx > dstWidthPx) || (fontHeightPx > dstHeightPx) ) { |
 |
|
|
} |
|
|
|
|
|
- return scaledFont; |
|
|
+ return scaledFont.deriveFont( (float) Math.floor( scaledPt ) ); |
|
|
} |
|
|
} |