diff options
| author | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-05-03 16:38:41 -0700 |
| commit | e1e781bb2135ef78592226f1a3eaba4925702f1f (patch) | |
| tree | 8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/console/TextCanvas.java | |
| download | worlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.tar.xz worlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.zip | |
Diffstat (limited to 'NET/worlds/console/TextCanvas.java')
| -rw-r--r-- | NET/worlds/console/TextCanvas.java | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/NET/worlds/console/TextCanvas.java b/NET/worlds/console/TextCanvas.java new file mode 100644 index 0000000..2175b19 --- /dev/null +++ b/NET/worlds/console/TextCanvas.java @@ -0,0 +1,109 @@ +/* */ 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<String> 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 + */
\ No newline at end of file |