/* */ package NET.worlds.console; /* */ /* */ import java.awt.Canvas; /* */ import java.awt.Color; /* */ import java.awt.Dimension; /* */ import java.awt.Font; /* */ import java.awt.FontMetrics; /* */ import java.awt.Graphics; /* */ import java.awt.Toolkit; /* */ import java.util.Vector; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class TextCanvas /* */ extends Canvas /* */ { /* */ private static final long serialVersionUID = 2808978760046610505L; /* */ private Dimension calcSize; /* */ private Font font; /* */ private FontMetrics metrics; /* 31 */ private Vector lines = new Vector(); /* */ /* */ public TextCanvas(String text, int width) { /* 34 */ this.font = new Font(Console.message("CanvasFont"), 0, 12); /* */ /* 36 */ this.metrics = Toolkit.getDefaultToolkit().getFontMetrics(this.font); /* 37 */ char[] chars = text.toCharArray(); /* */ /* */ /* 40 */ int start = 0; /* 41 */ int end = 0; /* 42 */ int prevEnd = 0; /* 43 */ int lineWidth = 0; /* 44 */ for (end = start; end < chars.length;) { /* 45 */ char c = chars[end]; /* 46 */ boolean isEOL = c == '\n'; /* 47 */ if ((!isEOL) && (end == chars.length - 1)) { /* 48 */ isEOL = true; /* 49 */ end++; /* */ } /* */ /* */ /* 53 */ if ((c == ' ') || (isEOL)) { /* 54 */ lineWidth = this.metrics.charsWidth(chars, start, end - start); /* 55 */ if ((width != -1) && (lineWidth > width)) { /* 56 */ end = prevEnd; /* 57 */ } else if (((width == -1) || (lineWidth < width)) && (!isEOL)) { /* 58 */ prevEnd = end; /* 59 */ end++; /* 60 */ continue; /* */ } /* */ /* */ /* 64 */ this.lines.addElement(new String(chars, start, end - start)); /* */ /* */ /* 67 */ start = end + 1; /* 68 */ while ((start < chars.length) && (chars[start] == ' ')) /* 69 */ start++; /* 70 */ prevEnd = end = start; /* */ } else { /* 72 */ end++; /* */ } /* */ } /* */ /* 76 */ this.calcSize = new Dimension(width == -1 ? lineWidth : width, /* 77 */ this.metrics.getHeight() * this.lines.size()); /* */ } /* */ /* */ /* */ public void paint(Graphics g) /* */ { /* 83 */ super.paint(g); /* 84 */ g.setFont(this.font); /* 85 */ g.setColor(Color.black); /* 86 */ int height = this.metrics.getHeight(); /* */ /* */ /* 89 */ int y = this.metrics.getAscent() + this.metrics.getLeading(); /* */ /* */ /* 92 */ for (int i = 0; i < this.lines.size(); i++) { /* 93 */ String line = (String)this.lines.elementAt(i); /* 94 */ g.drawString(line, 0, y); /* 95 */ y += height; /* */ } /* */ } /* */ /* */ public Dimension getPreferredSize() /* */ { /* 101 */ return this.calcSize; /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\TextCanvas.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */