1 27 28 package org.nightlabs.editor2d.figures; 29 30 import java.awt.Font ; 31 import java.awt.font.FontRenderContext ; 32 import java.awt.font.TextLayout ; 33 34 import org.nightlabs.editor2d.j2d.GeneralShape; 35 36 public class TextFigure 37 extends AbstractShapeFigure 38 { 39 public TextFigure() 40 { 41 super(); 42 } 43 44 49 62 73 protected FontRenderContext fontRenderContext; 74 public FontRenderContext getFontRenderContext() 75 { 76 if (fontRenderContext == null) 77 fontRenderContext = new FontRenderContext (null, false, false); 78 79 return fontRenderContext; 80 } 81 82 protected TextLayout textLayout; 83 protected void setTextlayout(String text, Font font) 84 { 85 at.setToIdentity(); 86 this.textLayout = new TextLayout (text, font, getFontRenderContext()); 87 setGeneralShape(new GeneralShape(textLayout.getOutline(at))); 88 } 89 90 protected String text = "text"; 91 public void setText(String text) 92 { 93 this.text = text; 94 setTextlayout(text, font); 95 } 96 97 protected Font font; 98 public void setAWTFont(Font font) { 99 100 this.font = font; 101 setTextlayout(text, font); 102 } 103 104 } 105 | Popular Tags |