home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 1.9 KB | 95 lines |
- // TextPanel.java
- // 25.03.96
- //
- // a panel for text
-
- package cybcerone.utils;
-
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.FontMetrics;
- import java.awt.Event;
-
- /**
- * A panel to put some text in.
- */
- public class TextPanel extends IdPanel {
- private Font textFont;
- private Color textColor = Color.white;
- private Color highlightColor = Color.red;
-
- protected String text;
- protected int y;
- protected FontMetrics metrics;
-
- public TextPanel (String id, String statusText, Appletlike app) {
- super (id, statusText, app);
- setForeground (textColor);
-
- textFont = Fonts.bigFont;
- }
-
- public void setFont (Font textFont) {
- this.textFont = textFont;
- setMetrics ();
- }
-
- protected void setMetrics () {
- metrics = getFontMetrics (textFont);
- y = size().height - metrics.getMaxDescent ();
- }
-
- public void setColor (Color textColor) {
- this.textColor = textColor;
- setForeground (textColor);
- }
-
- public void setHighlight (Color highlightColor) {
- this.highlightColor = highlightColor;
- }
-
- public void setText (String text) {
- this.text = text;
- if (metrics == null)
- setMetrics ();
-
- repaint ();
- }
-
- public String getText () { return text; }
-
- public boolean mouseEnter (Event evt, int x, int y) {
- if (getNext () != null) {
- setForeground (highlightColor);
- repaint ();
- }
- return super.mouseEnter (evt, x, y);
- }
-
- public boolean mouseExit (Event evt, int x, int y) {
- if (getNext () != null) {
- setForeground (textColor);
- repaint ();
- }
- return super.mouseExit (evt, x, y);
- }
-
- public void paint (Graphics g) {
- g.setColor (getBackground ());
- g.fillRect (0, 0, size().width, size().height);
-
- super.paint (g);
-
- g.setFont (textFont);
- g.setColor (getForeground ());
- paintText (g);
- }
-
- protected void paintText (Graphics g) {
- if (text != null) {
- g.drawString (text, 0, y);
- }
- }
- }
-