1 8 package com.nightlabs.editor2d.figures; 9 10 import java.awt.Font ; 11 import java.awt.font.FontRenderContext ; 12 import java.awt.font.TextLayout ; 13 14 import com.nightlabs.editor2d.j2d.GeneralShape; 15 16 public class TextFigure 17 extends AbstractShapeFigure 18 { 19 public TextFigure() 20 { 21 super(); 22 } 23 24 29 42 53 protected FontRenderContext fontRenderContext; 54 public FontRenderContext getFontRenderContext() 55 { 56 if (fontRenderContext == null) 57 fontRenderContext = new FontRenderContext (null, false, false); 58 59 return fontRenderContext; 60 } 61 62 protected TextLayout textLayout; 63 protected void setTextlayout(String text, Font font) 64 { 65 at.setToIdentity(); 66 this.textLayout = new TextLayout (text, font, getFontRenderContext()); 67 setGeneralShape(new GeneralShape(textLayout.getOutline(at))); 68 } 69 70 protected String text = "text"; 71 public void setText(String text) 72 { 73 this.text = text; 74 setTextlayout(text, font); 75 } 76 77 protected Font font; 78 public void setAWTFont(Font font) { 79 80 this.font = font; 81 setTextlayout(text, font); 82 } 83 84 } 85 | Popular Tags |