first commit
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
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.
|
||||
*
|
||||
* <PRE>
|
||||
* Revision History:
|
||||
* v1.0 (Mar. 13, 2004) - Created the LFancyLabel class
|
||||
* </PRE>
|
||||
*
|
||||
* @author <A HREF="mailto:gtg308i@mail.gatech.edu">Vladimir Urazov</A>
|
||||
* @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 <code>LFancyLabel</code> instance.
|
||||
*/
|
||||
public LFancyLabel() {
|
||||
this(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>LFancyLabel</code> instance.
|
||||
*
|
||||
* @param text a <code>String</code> value
|
||||
*/
|
||||
public LFancyLabel(String text) {
|
||||
this(text, DEFAULT_FONT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>LFancyLabel</code> instance.
|
||||
*
|
||||
* @param text a <code>String</code> value
|
||||
* @param font a <code>Font</code> value
|
||||
*/
|
||||
public LFancyLabel(String text, Font font) {
|
||||
super(text);
|
||||
|
||||
setFont(font);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the fint associated with this label.
|
||||
*
|
||||
* @return a <code>Font</code> value
|
||||
*/
|
||||
public Font getFont() {
|
||||
return currentFont;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a new font value.
|
||||
*
|
||||
* @param newFont a <code>Font</code> value
|
||||
*/
|
||||
public void setFont(Font newFont) {
|
||||
if (newFont == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
currentFont = newFont;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deep-copies self <b>into the component</b> passed in.
|
||||
*
|
||||
* @param component a <code>LComponent</code> 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 <code>Graphics</code> value
|
||||
* @return a <code>boolean</code> 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user