package gamegui;

import java.awt.FontMetrics;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Font;

public class Label extends Member {
    private String text;
    private Font font;
    private boolean centered;
    
    public Label(final String newName, final int newX, final int newY, final int newWidth, final int newHeight, final String newText, final Font newFont, final boolean isCentered) {
        super(newName, newX, newY, newWidth, newHeight);
        this.text = new String(newText);
        this.font = newFont;
        this.centered = isCentered;
    }
    
    public void draw(final Graphics g) {
        final FontMetrics metrics = g.getFontMetrics(this.font);
        g.setColor(Color.green);
        g.setFont(this.font);
        if (this.centered) {
            g.drawString(this.text, this.getX() + (this.getWidth() - metrics.stringWidth(this.text)) / 2, this.getY() + (this.getHeight() + metrics.getHeight()) / 2 - 2);
        } else {
            g.drawString(this.text, this.getX(), this.getY() + (this.getHeight() + metrics.getHeight()) / 2 - 2);
        }
    }
}