Webber: A Website Construction Application


AreaLabel.java


// A multi-line label component

package library;

import java.awt.*;

public class AreaLabel extends Component {
	private String text = null;

	// Constructors
	public AreaLabel() {}
	public AreaLabel(String text) { setText(text); }

	// Set the text for this label
	public void setText(String text) { this.text = text; }

	// Return the margin insets for the text
	public Insets getInsets() { return new Insets(10, 10, 10, 10); }

	// Draw the text with word-wrap within the current margins
	public void paint(Graphics g) {
		if (text==null) return;				// Abort if no text
		Rectangle r = g.getClipBounds();		// Get clip area
		Insets i = getInsets();				// Get margin insets
		g.clipRect(i.left, i.top,			// Modify clip area
			   r.width-(i.left+i.right),
			   r.height-(i.top+i.bottom));
		Lib.drawStringWrap(text, g);			// Draw string with wrap
	}
}

Go To: Source Code