home *** CD-ROM | disk | FTP | other *** search
- package icontrols;
-
- import com.ms.wd.ui.Brush;
- import com.ms.wd.ui.Color;
- import com.ms.wd.ui.Font;
- import com.ms.wd.ui.Graphics;
- import com.ms.wd.ui.Rectangle;
-
- public class StringDisplayer {
- public static final int ALIGN_LEFT = 1;
- public static final int ALIGN_RIGHT = 2;
- public static final int ALIGN_HCENTER = 4;
- public static final int ALIGN_TOP = 16;
- public static final int ALIGN_BOTTOM = 32;
- public static final int ALIGN_VCENTER = 64;
- public static final int ALIGN_NONE = Integer.MIN_VALUE;
- private int m_align = Integer.MIN_VALUE;
- private boolean m_wrap = false;
- private boolean m_ellipsis = false;
- private Font m_font = null;
- private Color m_backColor = null;
- private Color m_foreColor = null;
- private String m_string = null;
- private Brush m_backBrush = null;
-
- public void setForeColor(Color color) {
- this.m_foreColor = color;
- }
-
- public Color getForeColor() {
- return this.m_foreColor;
- }
-
- public void setString(String str) {
- this.m_string = str;
- }
-
- public String getString() {
- return this.m_string;
- }
-
- public void paintIn(Graphics g, Rectangle bounds, Rectangle clipRect, String str) {
- int format = 0;
- Font oldFont = null;
- Color colorOldBack = null;
- Color colorOldFore = null;
- if (this.m_font != null) {
- oldFont = g.getFont();
- g.setFont(this.m_font);
- }
-
- if (this.m_backColor != null) {
- colorOldBack = g.getBackColor();
- g.setBackColor(this.m_backColor);
- }
-
- g.clearRect(bounds);
- if (this.m_foreColor != null) {
- colorOldFore = g.getTextColor();
- g.setTextColor(this.m_foreColor);
- }
-
- if (this.m_align != Integer.MIN_VALUE) {
- if ((this.m_align & 1) != 0) {
- format |= 0;
- } else if ((this.m_align & 2) != 0) {
- format |= 2;
- } else if ((this.m_align & 4) != 0) {
- format |= 1;
- }
-
- if ((this.m_align & 16) != 0) {
- format |= 32;
- } else if ((this.m_align & 32) != 0) {
- format |= 40;
- } else if ((this.m_align & 64) != 0) {
- format |= 36;
- }
- }
-
- if (this.m_ellipsis) {
- format |= 262144;
- }
-
- if (this.m_wrap) {
- format |= 16;
- }
-
- g.drawString(str, bounds, format);
- if (colorOldBack != null) {
- g.setBackColor(colorOldBack);
- }
-
- if (colorOldFore != null) {
- g.setTextColor(colorOldFore);
- }
-
- if (oldFont != null) {
- g.setFont(oldFont);
- }
-
- }
-
- public void setWrap(boolean wrap) {
- this.m_wrap = wrap;
- }
-
- public void setFont(Font font) {
- this.m_font = font;
- }
-
- public Font getFont() {
- return this.m_font;
- }
-
- public boolean isWrap() {
- return this.m_wrap;
- }
-
- public void setBackColor(Color color) {
- boolean changed = false;
- if (this.m_backColor != null) {
- changed = !this.m_backColor.equals(color);
- } else {
- changed = color != null;
- }
-
- if (changed) {
- this.m_backColor = color;
- if (color != null) {
- this.m_backBrush = new Brush(color);
- }
- }
-
- }
-
- public Color getBackColor() {
- return this.m_backColor;
- }
-
- public void setUseEllipsis(boolean bEllipsis) {
- this.m_ellipsis = bEllipsis;
- }
-
- public boolean isUseEllipsis() {
- return this.m_ellipsis;
- }
-
- public void setAlignment(int nAlign) {
- this.m_align = nAlign;
- }
-
- public int getAlignment() {
- return this.m_align;
- }
- }
-