KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > figures > TextFigure


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * Project author: Daniel Mazurek <Daniel.Mazurek [at] nightlabs [dot] org> *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin St, Fifth Floor, *
20  * Boston, MA 02110-1301 USA *
21  * *
22  * Or get it online : *
23  * http://www.gnu.org/copyleft/lesser.html *
24  * *
25  * *
26  ******************************************************************************/

27
28 package org.nightlabs.editor2d.figures;
29
30 import java.awt.Font JavaDoc;
31 import java.awt.font.FontRenderContext JavaDoc;
32 import java.awt.font.TextLayout JavaDoc;
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 // public boolean containsPoint(int x, int y)
45
// {
46
// return super.containsPoint(x, y);
47
// }
48

49 // protected void fillShape(Graphics graphics)
50
// {
51
// if (graphics instanceof J2DGraphics)
52
// {
53
// j2d = (J2DGraphics) graphics;
54
// g2d = j2d.createGraphics2D();
55
// g2d.setClip(null);
56
// g2d.setPaint(J2DUtil.toAWTColor(getBackgroundColor()));
57
// g2d.fill(getGeneralShape());
58
// g2d.dispose();
59
// }
60
// }
61

62 // protected void outlineShape(Graphics graphics)
63
// {
64
// if (graphics instanceof J2DGraphics)
65
// {
66
// j2d = (J2DGraphics) graphics;
67
// Graphics2D g2d = j2d.createGraphics2D();
68
// fontRenderContext = g2d.getFontRenderContext();
69
// textLayout.draw(g2d, getLocation().x, getLocation().y);
70
// }
71
// }
72

73   protected FontRenderContext JavaDoc fontRenderContext;
74   public FontRenderContext JavaDoc getFontRenderContext()
75   {
76     if (fontRenderContext == null)
77       fontRenderContext = new FontRenderContext JavaDoc(null, false, false);
78     
79     return fontRenderContext;
80   }
81  
82   protected TextLayout JavaDoc textLayout;
83   protected void setTextlayout(String JavaDoc text, Font JavaDoc font)
84   {
85     at.setToIdentity();
86     this.textLayout = new TextLayout JavaDoc(text, font, getFontRenderContext());
87     setGeneralShape(new GeneralShape(textLayout.getOutline(at)));
88   }
89     
90   protected String JavaDoc text = "text";
91   public void setText(String JavaDoc text)
92   {
93     this.text = text;
94     setTextlayout(text, font);
95   }
96   
97   protected Font JavaDoc font;
98   public void setAWTFont(Font JavaDoc font) {
99     
100     this.font = font;
101     setTextlayout(text, font);
102   }
103
104 }
105
Popular Tags