home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / COMMON / TOOLS / VB / CABINETS / MSDAO350.CAB / icontrols / StringDisplayer.class (.txt) < prev   
Encoding:
Java Class File  |  1998-01-08  |  3.6 KB  |  157 lines

  1. package icontrols;
  2.  
  3. import com.ms.wd.ui.Brush;
  4. import com.ms.wd.ui.Color;
  5. import com.ms.wd.ui.Font;
  6. import com.ms.wd.ui.Graphics;
  7. import com.ms.wd.ui.Rectangle;
  8.  
  9. public class StringDisplayer {
  10.    public static final int ALIGN_LEFT = 1;
  11.    public static final int ALIGN_RIGHT = 2;
  12.    public static final int ALIGN_HCENTER = 4;
  13.    public static final int ALIGN_TOP = 16;
  14.    public static final int ALIGN_BOTTOM = 32;
  15.    public static final int ALIGN_VCENTER = 64;
  16.    public static final int ALIGN_NONE = Integer.MIN_VALUE;
  17.    private int m_align = Integer.MIN_VALUE;
  18.    private boolean m_wrap = false;
  19.    private boolean m_ellipsis = false;
  20.    private Font m_font = null;
  21.    private Color m_backColor = null;
  22.    private Color m_foreColor = null;
  23.    private String m_string = null;
  24.    private Brush m_backBrush = null;
  25.  
  26.    public void setForeColor(Color color) {
  27.       this.m_foreColor = color;
  28.    }
  29.  
  30.    public Color getForeColor() {
  31.       return this.m_foreColor;
  32.    }
  33.  
  34.    public void setString(String str) {
  35.       this.m_string = str;
  36.    }
  37.  
  38.    public String getString() {
  39.       return this.m_string;
  40.    }
  41.  
  42.    public void paintIn(Graphics g, Rectangle bounds, Rectangle clipRect, String str) {
  43.       int format = 0;
  44.       Font oldFont = null;
  45.       Color colorOldBack = null;
  46.       Color colorOldFore = null;
  47.       if (this.m_font != null) {
  48.          oldFont = g.getFont();
  49.          g.setFont(this.m_font);
  50.       }
  51.  
  52.       if (this.m_backColor != null) {
  53.          colorOldBack = g.getBackColor();
  54.          g.setBackColor(this.m_backColor);
  55.       }
  56.  
  57.       g.clearRect(bounds);
  58.       if (this.m_foreColor != null) {
  59.          colorOldFore = g.getTextColor();
  60.          g.setTextColor(this.m_foreColor);
  61.       }
  62.  
  63.       if (this.m_align != Integer.MIN_VALUE) {
  64.          if ((this.m_align & 1) != 0) {
  65.             format |= 0;
  66.          } else if ((this.m_align & 2) != 0) {
  67.             format |= 2;
  68.          } else if ((this.m_align & 4) != 0) {
  69.             format |= 1;
  70.          }
  71.  
  72.          if ((this.m_align & 16) != 0) {
  73.             format |= 32;
  74.          } else if ((this.m_align & 32) != 0) {
  75.             format |= 40;
  76.          } else if ((this.m_align & 64) != 0) {
  77.             format |= 36;
  78.          }
  79.       }
  80.  
  81.       if (this.m_ellipsis) {
  82.          format |= 262144;
  83.       }
  84.  
  85.       if (this.m_wrap) {
  86.          format |= 16;
  87.       }
  88.  
  89.       g.drawString(str, bounds, format);
  90.       if (colorOldBack != null) {
  91.          g.setBackColor(colorOldBack);
  92.       }
  93.  
  94.       if (colorOldFore != null) {
  95.          g.setTextColor(colorOldFore);
  96.       }
  97.  
  98.       if (oldFont != null) {
  99.          g.setFont(oldFont);
  100.       }
  101.  
  102.    }
  103.  
  104.    public void setWrap(boolean wrap) {
  105.       this.m_wrap = wrap;
  106.    }
  107.  
  108.    public void setFont(Font font) {
  109.       this.m_font = font;
  110.    }
  111.  
  112.    public Font getFont() {
  113.       return this.m_font;
  114.    }
  115.  
  116.    public boolean isWrap() {
  117.       return this.m_wrap;
  118.    }
  119.  
  120.    public void setBackColor(Color color) {
  121.       boolean changed = false;
  122.       if (this.m_backColor != null) {
  123.          changed = !this.m_backColor.equals(color);
  124.       } else {
  125.          changed = color != null;
  126.       }
  127.  
  128.       if (changed) {
  129.          this.m_backColor = color;
  130.          if (color != null) {
  131.             this.m_backBrush = new Brush(color);
  132.          }
  133.       }
  134.  
  135.    }
  136.  
  137.    public Color getBackColor() {
  138.       return this.m_backColor;
  139.    }
  140.  
  141.    public void setUseEllipsis(boolean bEllipsis) {
  142.       this.m_ellipsis = bEllipsis;
  143.    }
  144.  
  145.    public boolean isUseEllipsis() {
  146.       return this.m_ellipsis;
  147.    }
  148.  
  149.    public void setAlignment(int nAlign) {
  150.       this.m_align = nAlign;
  151.    }
  152.  
  153.    public int getAlignment() {
  154.       return this.m_align;
  155.    }
  156. }
  157.