Constructors Summary |
---|
public MultiLineLabel(String label, int margin_width, int margin_height, int alignment)
newLabel(label);
this.margin_width = margin_width;
this.margin_height = margin_height;
this.alignment = alignment;
|
public MultiLineLabel(String label, int margin_width, int margin_height)
this(label, margin_width, margin_height, LEFT);
|
public MultiLineLabel(String label, int alignment)
this(label, 10, 10, alignment);
|
public MultiLineLabel(String label)
this(label, 10, 10, LEFT);
|
Methods Summary |
---|
public void | addNotify() super.addNotify(); measure();
|
public int | getAlignment() return alignment;
|
public int | getMarginHeight() return margin_height;
|
public int | getMarginWidth() return margin_width;
|
protected void | measure()
FontMetrics fm = this.getFontMetrics(this.getFont());
// If we don't have font metrics yet, just return.
if (fm == null) return;
line_height = fm.getHeight();
line_ascent = fm.getAscent();
max_width = 0;
for(int i = 0; i < num_lines; i++) {
line_widths[i] = fm.stringWidth(lines[i]);
if (line_widths[i] > max_width) max_width = line_widths[i];
}
|
public java.awt.Dimension | minimumSize()
return new Dimension(max_width, num_lines * line_height);
|
protected void | newLabel(java.lang.String label) // The alignment of the text.
// This method breaks a specified label up into an array of lines.
// It uses the StringTokenizer utility class.
StringTokenizer t = new StringTokenizer(label, "\n");
num_lines = t.countTokens();
lines = new String[num_lines];
line_widths = new int[num_lines];
for(int i = 0; i < num_lines; i++) lines[i] = t.nextToken();
|
public void | paint(java.awt.Graphics g)
int x, y;
Dimension d = this.size();
y = line_ascent + (d.height - num_lines * line_height)/2;
for(int i = 0; i < num_lines; i++, y += line_height) {
switch(alignment) {
case LEFT:
x = margin_width; break;
case CENTER:
default:
x = (d.width - line_widths[i])/2; break;
case RIGHT:
x = d.width - margin_width - line_widths[i]; break;
}
g.drawString(lines[i], x, y);
}
|
public java.awt.Dimension | preferredSize()
return new Dimension(max_width + 2*margin_width,
num_lines * line_height + 2*margin_height);
|
public void | setAlignment(int a) alignment = a; repaint();
|
public void | setFont(java.awt.Font f)
super.setFont(f);
measure();
repaint();
|
public void | setForeground(java.awt.Color c)
super.setForeground(c);
repaint();
|
public void | setLabel(java.lang.String label)
newLabel(label);
measure();
repaint();
|
public void | setMarginHeight(int mh) margin_height = mh; repaint();
|
public void | setMarginWidth(int mw) margin_width = mw; repaint();
|