Bug in centering dynamic property label when it changes

I have a counter that displays a dynamic property $STATUS$ that can vary from the values “”, “FALLEN”, “DX -2”, and “DEAD”. It is always displayed properly (centered) the first time it’s drawn.

However, when the value of the DP changes, the label is centered as if it was the same initial value. For example, if “FALLEN” is the first drawn value of the label and it changes to “DEAD”, the new label appears to be left of center, starting from the precise location of “FALLEN”.

Being a Java coder, I looked at the 3.1.10 sources from sourceforge and believe I spotted the cause of this bug in the file counters/Labeler.java, beginning at line 230:

final int width = g.getFontMetrics().stringWidth(text + " "); final int height = g.getFontMetrics().getHeight(); int x0 = x; int y0 = y; switch (hAlign) { case CENTER: x0 = x - width / 2; break; case LEFT: x0 = x - width; break; }
The “final” qualifier won’t let width (or height) change its initial value. I’m not sure why it’s final, but I believe it is the reason this bug exists.

Thus spake “fuhrmanator”:

width and height are local variables here. The problem is something else.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)