KickJava   Java API By Example, From Geeks To Geeks.

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


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: BLink.java,v 1.21 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.comp;
21
22 import java.io.*;
23 import java.util.*;
24
25 import org.apache.log4j.*;
26 import org.w3c.dom.*;
27 import org.w3c.dom.html.*;
28
29 import org.enhydra.barracuda.core.comp.renderer.*;
30 import org.enhydra.barracuda.core.comp.renderer.html.*;
31 import org.enhydra.barracuda.core.event.*;
32 import org.enhydra.barracuda.core.event.events.*;
33 import org.enhydra.barracuda.core.util.dom.*;
34 import org.enhydra.barracuda.core.view.*;
35 import org.enhydra.barracuda.plankton.*;
36
37
38 /**
39  * BLink is used to manipulate any element in a DOM template that
40  * is capable of generating a URL request. In the case of HTML, this
41  * would typically include <a>, <input>, and <button>
42  * elements.
43  *
44  * <p>In most cases you will not actually need to bind the component
45  * to a view in order to use it--if you return it from a model, this
46  * will be done for you automatically. If however, you intend to use
47  * the component <em>standalone</em> (ie. manually attaching it to a
48  * specific node in the DOM) or <em>inline</em> (ie. in a toString()),
49  * then you MUST BIND IT TO A VIEW before rendering, or an error will
50  * be generated.
51  *
52  * <p>Because BLink may often be used for inling, it includes constructors
53  * that conveniently allow you to specify the a ViewContext (ie. instead of
54  * an actual View)
55  */

56 public class BLink extends BAction {
57
58     //public vars
59
protected static final Logger logger = Logger.getLogger(BLink.class.getName());
60     
61     //private vars
62
protected String JavaDoc text = null;
63     protected String JavaDoc target = null;
64     protected boolean allowMarkupInText = false; //csc_092701.1
65

66     //--------------- Constructors -------------------------------
67
/**
68      * Public noargs constructor
69      */

70     public BLink() {}
71     
72     /**
73      * Public constructor which creates the component and sets the text,
74      * and target values. This link will fire the default action event (unless
75      * you manually specify an action).
76      *
77      * @param itext the text string that backs this component
78      */

79     public BLink(String JavaDoc itext) {
80         if (itext!=null) setText(itext);
81     }
82
83     /**
84      * Public constructor which creates the component and sets the text
85      * and action values.
86      *
87      * @param itext the text string that backs this component
88      * @param iactionUrl the action url to be fired (opt--if null, the default
89      * action specified in the template will be fired)
90      */

91     public BLink(String JavaDoc itext, String JavaDoc iactionUrl) {
92         this(itext, iactionUrl, null);
93     }
94
95     /**
96      * Public constructor which creates the component and sets the text
97      * and action values. This constructor takes a ViewContext object which
98      * will be used to create a default view for the component (ie. use this
99      * constructor for inling a BLink)
100      *
101      * @param itext the text string that backs this component
102      * @param iactionUrl the action url to be fired (opt--if null, the default
103      * action specified in the template will be fired)
104      * @param idvc the default ViewContext (opt--its presence allows the
105      * component to be rendered as markup in toString())
106      */

107     public BLink(String JavaDoc itext, String JavaDoc iactionUrl, ViewContext idvc) {
108         if (idvc!=null) setDefaultViewContext(idvc);
109         if (itext!=null) setText(itext);
110         if (iactionUrl!=null) setAction(iactionUrl);
111     }
112
113     /**
114      * Public constructor which creates the component and sets the text
115      * and action values.
116      *
117      * @param itext the text string that backs this component
118      * @param iactionEvent the action event to be fired (opt--if null, the default
119      * ActionEvent will be fired)
120      */

121     public BLink(String JavaDoc itext, ControlEvent iactionEvent) {
122         this(itext, iactionEvent, null);
123     }
124     
125     /**
126      * Public constructor which creates the component and sets the text
127      * and action values. This constructor takes a ViewContext object which
128      * will be used to create a default view for the component (ie. use this
129      * constructor for inling a BLink)
130      *
131      * @param itext the text string that backs this component
132      * @param iactionEvent the action event to be fired (opt--if null, the default
133      * ActionEvent will be fired)
134      * @param idvc the default ViewContext (opt--its presence allows the
135      * component to be rendered as markup in toString())
136      */

137     public BLink(String JavaDoc itext, ControlEvent iactionEvent, ViewContext idvc) {
138         if (idvc!=null) setDefaultViewContext(idvc);
139         if (itext!=null) setText(itext);
140         if (iactionEvent!=null) setAction(iactionEvent);
141     }
142
143
144
145     //--------------- Renderer -----------------------------------
146
/**
147      * Default component renderer factory registrations
148      */

149     static {
150         HTMLRendererFactory rfHTML = new HTMLRendererFactory();
151         installRendererFactory(rfHTML, BLink.class, HTMLElement.class);
152     }
153
154     /**
155      * HTML RendererFactory
156      */

157     static class HTMLRendererFactory implements RendererFactory {
158         public Renderer getInstance() {return new HTMLLinkRenderer();}
159     }
160
161
162
163     //--------------- BLink --------------------------------------
164
/**
165      * Set the text for this particular component
166      *
167      * @param itext the text representation of this component
168      */

169     public void setText(String JavaDoc itext) {
170         text = itext;
171         invalidate();
172     }
173     
174     /**
175      * Get the text for this particular component
176      *
177      * @return the text for this particular component
178      */

179     public String JavaDoc getText() {
180         return text;
181     }
182     
183     /**
184      * Set the target for this particular component
185      *
186      * @param itarget the ext representation of the target
187      */

188     public void setTarget(String JavaDoc itarget) {
189         target = itarget;
190         invalidate();
191     }
192     
193     /**
194      * Get the target for this particular component
195      *
196      * @return the target for this particular component
197      */

198     public String JavaDoc getTarget() {
199         return target;
200     }
201
202     /**
203      * Do we wish to allow markup in this text (defaults to false)
204      *
205      * @param val true if we wish to allow markup in the text
206      */

207     public void setAllowMarkupInText(boolean val) {
208         allowMarkupInText = val;
209         invalidate();
210     }
211     
212     /**
213      * See if we allow markup in the text
214      *
215      * @return true if we wish to allow markup in the text
216      */

217     public boolean allowMarkupInText() {
218         return allowMarkupInText;
219     }
220     
221     
222 }
Popular Tags