KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > html > Image


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.html;
16
17 import org.apache.tapestry.AbstractComponent;
18 import org.apache.tapestry.IAsset;
19 import org.apache.tapestry.IMarkupWriter;
20 import org.apache.tapestry.IRequestCycle;
21 import org.apache.tapestry.Tapestry;
22
23 /**
24  * Used to insert an image. To create a rollover image, use the
25  * {@link Rollover} class, which integrates a link with the image assets
26  * used with the button.
27  *
28  * [<a HREF="../../../../../ComponentReference/Image.html">Component Reference</a>]
29  *
30  *
31  * @author Howard Lewis Ship
32  *
33  **/

34
35 public abstract class Image extends AbstractComponent
36 {
37     /**
38      * Renders the &lt;img&gt; element.
39      *
40      *
41      **/

42
43     protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
44     {
45         // Doesn't contain a body so no need to do anything on rewind (assumes no
46
// sideffects to accessor methods via bindings).
47

48         if (cycle.isRewinding())
49             return;
50
51         IAsset imageAsset = getImage();
52
53         if (imageAsset == null)
54             throw Tapestry.createRequiredParameterException(this, "image");
55
56         String JavaDoc imageURL = imageAsset.buildURL(cycle);
57
58         writer.beginEmpty("img");
59
60         writer.attribute("src", imageURL);
61
62         writer.attribute("border", getBorder());
63
64         renderInformalParameters(writer, cycle);
65
66         writer.closeTag();
67
68     }
69
70     public abstract IAsset getImage();
71
72     public abstract int getBorder();
73 }
Popular Tags