KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcckit > graphic > Text


1 /*
2  * Copyright 2003-2004, Franz-Josef Elmer, All rights reserved
3  *
4  * This library is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details
13  * (http://www.gnu.org/copyleft/lesser.html).
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package jcckit.graphic;
20
21 /**
22  * A single line of text.
23  *
24  * @author Franz-Josef Elmer
25  */

26 public class Text extends BasicGraphicalElement {
27   private final GraphPoint _position;
28   private final String JavaDoc _text;
29
30
31   /**
32    * Creates an instance with the specified parameters.
33    * @param position Position of the text.
34    * @param text Text.
35    * @param attributes Drawing attributes. Can be <tt>null</tt>.
36    */

37   public Text(GraphPoint position, String JavaDoc text, GraphicAttributes attributes) {
38     super(attributes);
39     _position = position;
40     _text = text;
41   }
42
43   /** Returns the position. */
44   public GraphPoint getPosition() {
45     return _position;
46   }
47
48   /** Returns the text string. */
49   public String JavaDoc getText() {
50     return _text;
51   }
52
53   /**
54    * Renders this line with the specified {@link Renderer}.
55    * @param renderer An instance of {@link TextRenderer}.
56    * @throws IllegalArgumentException if <tt>renderer</tt> is not
57    * an instance of <tt>TextRenderer</tt>.
58    */

59   public void renderWith(Renderer renderer) {
60     if (renderer instanceof TextRenderer) {
61       ((TextRenderer) renderer).render(this);
62     } else {
63       throw new IllegalArgumentException JavaDoc(renderer
64                             + " does not implements TextRenderer.");
65     }
66   }
67 }
68
Popular Tags