1 6 7 package com.thoughtriver.open.vectorvisuals; 8 9 import java.awt.*; 10 import java.awt.font.*; 11 import java.awt.geom.*; 12 13 24 public class VisualTextObject extends VisualObject { 25 26 27 private static final FontRenderContext context = new FontRenderContext(new AffineTransform(), true, false); 28 29 30 private String text = null; 31 32 33 private Font font = null; 34 35 36 private GlyphVector glyphVector = null; 37 38 49 public VisualTextObject(final String text, final Font font, final Brush lineBrush, final Brush fillBrush) { 50 super(new Area(), lineBrush, fillBrush); 51 setText(text); 52 setFont(font); 53 } 54 55 61 public void setText(final String text) { 62 if (text == null) { 63 this.text = ""; 64 } 65 else { 66 this.text = text; 67 } 68 69 if (font != null) { 70 glyphVector = font.createGlyphVector(context, text); 71 super.setShape(glyphVector.getOutline()); 72 } 73 } 74 75 80 public String getText() { 81 return text; 82 } 83 84 90 public void setFont(final Font font) { 91 if (font == null) { 92 this.font = FontManager.getSharedInstance().getFont("Dialog-PLAIN-12"); 93 } 94 else { 95 this.font = font; 96 } 97 98 if (text != null) { 99 glyphVector = this.font.createGlyphVector(context, text); 100 super.setShape(glyphVector.getOutline()); 101 } 102 } 103 104 109 public Font getFont() { 110 return font; 111 } 112 } 113 | Popular Tags |