2000-07-23 02:24:14 +02:00
|
|
|
/* Copyright (C) 2000 Free Software Foundation
|
|
|
|
|
|
|
|
This file is part of libjava.
|
|
|
|
|
|
|
|
This software is copyrighted work licensed under the terms of the
|
|
|
|
Libjava License. Please consult the file "LIBJAVA_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
package java.awt;
|
2000-07-31 01:19:57 +02:00
|
|
|
import java.awt.peer.ComponentPeer;
|
|
|
|
import java.awt.peer.LabelPeer;
|
2000-07-23 02:24:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Tom Tromey <tromey@cygnus.com>
|
|
|
|
* @date April 12, 2000
|
|
|
|
*/
|
|
|
|
|
|
|
|
public class Label extends Component
|
|
|
|
{
|
|
|
|
public static final int CENTER = 1;
|
|
|
|
public static final int LEFT = 0;
|
|
|
|
public static final int RIGHT = 2;
|
|
|
|
|
|
|
|
public Label ()
|
|
|
|
{
|
|
|
|
this ("", LEFT);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Label (String text)
|
|
|
|
{
|
|
|
|
this (text, LEFT);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Label (String text, int alignment)
|
|
|
|
{
|
|
|
|
if (alignment != CENTER && alignment != LEFT && alignment != RIGHT)
|
|
|
|
throw new IllegalArgumentException ();
|
|
|
|
this.text = text;
|
|
|
|
this.alignment = alignment;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addNotify ()
|
|
|
|
{
|
2000-07-31 04:03:51 +02:00
|
|
|
if (peer == null)
|
|
|
|
peer = (ComponentPeer) getToolkit ().createLabel (this);
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getAlignment ()
|
|
|
|
{
|
|
|
|
return alignment;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getText ()
|
|
|
|
{
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String paramString ()
|
|
|
|
{
|
|
|
|
return "Label[" + alignment + "," + text + "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAlignment (int alignment)
|
|
|
|
{
|
|
|
|
if (alignment != CENTER && alignment != LEFT && alignment != RIGHT)
|
|
|
|
throw new IllegalArgumentException ();
|
|
|
|
this.alignment = alignment;
|
2000-07-31 01:19:57 +02:00
|
|
|
if (peer != null)
|
|
|
|
{
|
|
|
|
LabelPeer lp = (LabelPeer) peer;
|
|
|
|
lp.setAlignment (alignment);
|
|
|
|
}
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setText (String text)
|
|
|
|
{
|
|
|
|
this.text = text;
|
2000-07-31 01:19:57 +02:00
|
|
|
if (peer != null)
|
|
|
|
{
|
|
|
|
LabelPeer lp = (LabelPeer) peer;
|
|
|
|
lp.setText (text);
|
|
|
|
}
|
2000-07-23 02:24:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private String text;
|
|
|
|
private int alignment;
|
|
|
|
}
|