Added two useful constructors that allow specifying additional label

configuration options.  Added layout(Component).


git-svn-id: https://samskivert.googlecode.com/svn/trunk@872 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
shaper
2002-10-17 00:32:47 +00:00
parent de4dccabe4
commit 72a05fa745
@@ -1,5 +1,5 @@
//
// $Id: Label.java,v 1.20 2002/09/25 08:42:00 mdb Exp $
// $Id: Label.java,v 1.21 2002/10/17 00:32:47 shaper Exp $
//
// samskivert library - useful routines for java programs
// Copyright (C) 2002 Michael Bayne
@@ -21,6 +21,7 @@
package com.samskivert.swing;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
@@ -62,15 +63,38 @@ public class Label implements SwingConstants, LabelStyleConstants
*/
public Label ()
{
setText("");
this("");
}
/**
* Constructs a label with the supplied text.
*/
public Label (String text)
{
this(text, null, null);
}
/**
* Constructs a label with the supplied text and configuration
* parameters.
*/
public Label (String text, Color textColor, Font font)
{
this(text, NORMAL, textColor, null, font);
}
/**
* Constructs a label with the supplied text and configuration
* parameters.
*/
public Label (
String text, int style, Color textColor, Color altColor, Font font)
{
setText(text);
setStyle(style);
setTextColor(textColor);
setAlternateColor(altColor);
setFont(font);
}
/**
@@ -202,6 +226,19 @@ public class Label implements SwingConstants, LabelStyleConstants
return _size;
}
/**
* Calls {@link #layout(Graphics2D)} with the graphics context for the
* given component.
*/
public void layout (Component comp)
{
Graphics2D gfx = (Graphics2D)comp.getGraphics();
if (gfx != null) {
layout(gfx);
gfx.dispose();
}
}
/**
* Requests that this label lay out its text, obtaining information
* from the supplied graphics context to do so. It is expected that