package edu.gatech.cs2335.lemmings.gui; import java.awt.Font; import java.awt.Graphics; import java.awt.GraphicsEnvironment; /** * Class LFancyLabel: In addition to the regular label functionality, * this guy allows you to specify different fonts for the label. * *
* Revision History: * v1.0 (Mar. 13, 2004) - Created the LFancyLabel class ** * @author Vladimir Urazov * @version Version 1.0, Mar. 13, 2004 */ public final class LFancyLabel extends LLabel { /** * Show lots of debug output? */ private static final boolean VERBOSE = false; /** * The default font. */ public static final Font DEFAULT_FONT; static { //Initialize default font to the first font available Font temp = GraphicsEnvironment .getLocalGraphicsEnvironment().getAllFonts()[0]; DEFAULT_FONT = temp.deriveFont(Font.PLAIN, 16.0f); } /** * The font used to render this fancy label. */ private Font currentFont; /** * Creates a new
LFancyLabel instance.
*/
public LFancyLabel() {
this(" ");
}
/**
* Creates a new LFancyLabel instance.
*
* @param text a String value
*/
public LFancyLabel(String text) {
this(text, DEFAULT_FONT);
}
/**
* Creates a new LFancyLabel instance.
*
* @param text a String value
* @param font a Font value
*/
public LFancyLabel(String text, Font font) {
super(text);
setFont(font);
}
/**
* Returns the fint associated with this label.
*
* @return a Font value
*/
public Font getFont() {
return currentFont;
}
/**
* Sets up a new font value.
*
* @param newFont a Font value
*/
public void setFont(Font newFont) {
if (newFont == null) {
throw new NullPointerException();
}
currentFont = newFont;
}
/**
* Deep-copies self into the component passed in.
*
* @param component a LComponent value
*/
protected void copy(LComponent component) {
super.copy(component);
LFancyLabel target = (LFancyLabel) component;
target.setFont(new Font(getFont().getName(), getFont().getStyle(),
getFont().getSize()));
}
/**
* Performs all of the necessary drawing for this control only. The
* children will be taken care of separately. This method need not
* concern itself with them.
*
* @param g a Graphics value
* @return a boolean value
*/
protected boolean paint(Graphics g) {
if (VERBOSE) {
System.out.println("LFancyLabel: Rendering with:");
System.out.println("\t" + getFont());
System.out.flush();
}
g.setColor(this.getForeground());
g.setFont(this.getFont());
g.drawString(this.getText(), this.getBounds().x, this.getBounds().y);
return true;
}
}