FileDocCategorySizeDatePackage
VerticalLabel.javaAPI DocExample3358Mon Mar 24 02:02:58 GMT 1997None

VerticalLabel

public class VerticalLabel extends Component

Fields Summary
public static final int
LEFT
public static final int
CENTER
public static final int
RIGHT
private String
text
private int
vgap
private int
alignment
Dimension
mySize
int
textLength
char[]
chars
Constructors Summary
public VerticalLabel()

   // constructors
      
        this (null, 0, CENTER);
   
public VerticalLabel(String text)

        this (text, 0, CENTER);
   
public VerticalLabel(String text, int vgap, int alignment)

      this.text = text;
      this.vgap = vgap;
      this.alignment = alignment;
   
Methods Summary
public voidaddNotify()

       super.addNotify();
       init();  // Component must be visible for init to work
   
public intgetAlignment()

      return alignment;
   
public java.lang.StringgetText()

 return text; 
public intgetVgap()

 return vgap; 
voidinit()

                      
      textLength = text.length();
      chars = new char[textLength];
      text.getChars (0, textLength, chars, 0);
      Font f = getFont();
      FontMetrics fm = getFontMetrics (f);
      mySize = new Dimension(0,0);
      mySize.height = (fm.getHeight() * textLength) + (vgap * 2);
      for (int i=0; i < textLength; i++) {
          mySize.width = Math.max (mySize.width, fm.charsWidth(chars, i, 1));
      }
   
public java.awt.DimensionminimumSize()

 return mySize; 
public voidpaint(java.awt.Graphics g)

      int x,y;
      int xPositions[];
      int yPositions[];
// Must redo this each time since font/screen area might change
// Use actual width for alignment
      Font f = getFont();
      FontMetrics fm = getFontMetrics (f);
      xPositions = new int[textLength];
      for (int i=0; i < textLength; i++) {
         if (alignment == RIGHT) {
            xPositions[i] = size().width - fm.charWidth (chars[i]);
         } else if (alignment == LEFT) {
            xPositions[i] = 0;
         } else { // CENTER
            xPositions[i] = (size().width - fm.charWidth (chars[i])) / 2; 
         }
      }
      yPositions = new int[textLength];
      for (int i=0; i < textLength; i++) {
         yPositions[i] = (fm.getHeight() * (i+1)) + vgap;
      }
      for (int i = 0; i < textLength; i++) {
         x = xPositions[i];
         y = yPositions[i];
         g.drawChars (chars, i, 1, x, y);
      }

   
protected java.lang.StringparamString()

      String str=",align=";
      switch (alignment) {
         case LEFT:    str += "left"; break;
         case CENTER:  str += "center"; break;
         case RIGHT:   str += "right"; break;
      }
      if (vgap!=0) str+= ",vgap=" + vgap;
      return super.paramString() + str + ",label=" + text;
   
public java.awt.DimensionpreferredSize()

 return mySize; 
public voidsetText(java.lang.String text)

 this.text = text; init();
public voidsetVgap(int vgap)

 this.vgap = vgap; init();