KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > comp > BText


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library 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 GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: BText.java,v 1.14 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.comp;
21
22 import java.util.*;
23
24 import org.apache.log4j.*;
25 import org.w3c.dom.*;
26 import org.w3c.dom.html.*;
27
28 import org.enhydra.barracuda.core.comp.renderer.*;
29 import org.enhydra.barracuda.core.comp.renderer.html.*;
30 import org.enhydra.barracuda.core.comp.renderer.xml.*;
31 import org.enhydra.barracuda.core.util.dom.DOMUtil;
32 import org.enhydra.barracuda.core.view.*;
33 import org.enhydra.barracuda.plankton.*;
34 import org.enhydra.barracuda.plankton.data.*;
35
36
37 /**
38  * BText is used for rendering text into a DOM. You can bind it to just
39  * about any type of node, and it will do its best to put the text in
40  * the proper place.
41  *
42  * <p>In most cases you will not actually need to bind the component
43  * to a view in order to use it--if you return it from a model, this
44  * will be done for you automatically. If however, you intend to use
45  * the component <em>standalone</em> (ie. manually attaching it to a
46  * specific node in the DOM) or <em>inline</em> (ie. in a toString()),
47  * then you MUST BIND IT TO A VIEW before rendering, or an error will
48  * be generated.
49  */

50 public class BText extends BComponent {
51
52     //public vars
53
protected static final Logger logger = Logger.getLogger(BText.class.getName());
54     
55     //private vars
56
protected String JavaDoc text = null;
57     protected boolean allowMarkupInText = false; //csc_092701.1
58

59     //--------------- Constructors -------------------------------
60
/**
61      * Public noargs constructor
62      */

63     public BText() {}
64     
65     /**
66      * Public constructor which creates the component and sets
67      * the text.
68      *
69      * <p>You should generally only use this constructor when returning
70      * BText from a Model, as the model components will automatically
71      * bind the component to a view for you. If you use this constructor
72      * in some other situation, you should manually bind the component
73      * to the proper view.
74      *
75      * @param text the text string that backs this component
76      */

77     public BText(String JavaDoc text) {
78         this(text, null);
79     }
80
81     /**
82      * Public constructor which creates the component and
83      * binds it to a view, and sets the text
84      *
85      * <p>Null values may be passed in for any parameters,
86      * but if you do so you will need manually provide these
87      * values (via the accessor methods) prior to actually
88      * rendering the component
89      *
90      * @param text the text string that backs this component
91      * @param view the View the component should be bound to
92      */

93     BText(String JavaDoc text, View view) {
94         if (text!=null) this.setText(text);
95         if (view!=null) this.addView(view);
96     }
97
98
99     //--------------- Renderer -----------------------------------
100
/**
101      * Default component renderer factory registrations
102      */

103     static {
104         HTMLRendererFactory rfHTML = new HTMLRendererFactory();
105         installRendererFactory(rfHTML, BText.class, HTMLElement.class);
106         installRendererFactory(rfHTML, BText.class, HTMLDocument.class);
107 /*
108         WMLRendererFactory rfWML = new WMLRendererFactory();
109         installRendererFactory(rfWML, BText.class, HTMLElement.class);
110         installRendererFactory(rfWML, BText.class, HTMLDocument.class);
111 */

112         XMLRendererFactory rfXML = new XMLRendererFactory();
113         installRendererFactory(rfXML, BText.class, Node.class);
114     }
115
116     /**
117      * HTML RendererFactory
118      */

119     static class HTMLRendererFactory implements RendererFactory {
120         public Renderer getInstance() {return new HTMLTextRenderer();}
121     }
122
123     /**
124      * XML RendererFactory
125      */

126     static class XMLRendererFactory implements RendererFactory {
127         public Renderer getInstance() {return new XMLTextRenderer();}
128     }
129
130
131     //--------------- BComponent ---------------------------------
132
/**
133      * Set the text for this particular component
134      *
135      * @param itext the text representation of this component
136      */

137     public void setText(String JavaDoc itext) {
138         text = itext;
139         invalidate();
140     }
141     
142     /**
143      * Get the text for this particular component
144      *
145      * @return the text for this particular component
146      */

147     public String JavaDoc getText() {
148         return text;
149     }
150     
151     /**
152      * Do we wish to allow markup in this text (defaults to false)
153      *
154      * @param val true if we wish to allow markup in the text
155      */

156     public void setAllowMarkupInText(boolean val) {
157         allowMarkupInText = val;
158         invalidate();
159     }
160     
161     /**
162      * See if we allow markup in the text
163      *
164      * @return true if we wish to allow markup in the text
165      */

166     public boolean allowMarkupInText() {
167         return allowMarkupInText;
168     }
169     
170     /**
171      * Render a specific view for the component.
172      *
173      * @param view View to be rendered
174      * @param vc ViewContext for the client view
175      * @throws RenderException if the particular View is not supported
176      * @param list a List of all the views for this component
177      */

178 /*
179 //021102.3_csc - removed, because now its in BComponent
180     protected void renderView (View view, ViewContext vc, int depth) throws RenderException {
181         if (logger.isInfoEnabled()) logger.info("rendering view: "+view);
182
183         //actually render the view according to known interfaces
184         try {
185             Renderer r = getRenderer(view);
186             r.renderComponent(this, view, vc);
187         } catch (DOMException e) {
188             logger.warn("DOM Error:", e);
189             throw new DOMAccessException("Error rendering component in view:"+e, e);
190         }
191     }
192 */

193     /**
194      * Get a String representation of the component
195      */

196     public String JavaDoc toString() {
197         return text;
198     }
199
200 }
Popular Tags