import java.awt.*;
+import static java.lang.String.valueOf;
+
+/**
+ * Represents a single character on the text canvas.
+ */
public class CanvasCharacter extends AbstractCoordinateShape {
private static final int MAX_FONT_SIZE = 500;
+
+ /**
+ * Cached fonts.
+ */
private static final Font[] fonts = new Font[MAX_FONT_SIZE];
- private String value;
+
+ /**
+ * The character to be rendered.
+ */
+ private char value;
private eu.svjatoslav.sixth.e3d.renderer.raster.Color foregroundColor;
- private Color foregroundAwtColor;
private eu.svjatoslav.sixth.e3d.renderer.raster.Color backgroundColor;
super(5);
coordinates[0].coordinate = point;
- value = String.valueOf(character);
+ value = character;
this.foregroundColor = foregroundColor;
- foregroundAwtColor = foregroundColor.toAwtColor();
this.backgroundColor = backgroundColor;
}
}
+ /**
+ * Returns a font of the specified size.
+ * <p>
+ * If the font of the specified size is already cached, it will be
+ * returned. Otherwise, a new font will be created, cached and returned.
+ *
+ *
+ * @param size the size of the font
+ * @return the font
+ */
public static Font getFont(final int size) {
if (fonts[size] != null)
return fonts[size];
return font;
}
+ /**
+ * Returns color of the background.
+ */
public eu.svjatoslav.sixth.e3d.renderer.raster.Color getBackgroundColor() {
return backgroundColor;
}
+ /**
+ * Sets color of the background.
+ */
public void setBackgroundColor(
final eu.svjatoslav.sixth.e3d.renderer.raster.Color backgroundColor) {
this.backgroundColor = backgroundColor;
}
+ /**
+ * Returns color of the foreground.
+ * @return the color
+ */
public eu.svjatoslav.sixth.e3d.renderer.raster.Color getForegroundColor() {
return foregroundColor;
}
+ /**
+ * Sets color of the foreground.
+ * @param foregroundColor the color
+ */
public void setForegroundColor(
final eu.svjatoslav.sixth.e3d.renderer.raster.Color foregroundColor) {
this.foregroundColor = foregroundColor;
- foregroundAwtColor = foregroundColor.toAwtColor();
}
@Override
return;
renderingContext.graphics.setFont(getFont(size));
- renderingContext.graphics.setColor(foregroundAwtColor);
+ renderingContext.graphics.setColor(foregroundColor.toAwtColor());
renderingContext.graphics.drawString(
- value,
+ valueOf(value),
(int) onScreenLocation.x - (int) (size / 3.2),
(int) onScreenLocation.y + (int) (size / 2.5));
}
public void setValue(final char value) {
- this.value = String.valueOf(value);
+ this.value = value;
}
}