KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tags > rendering > SelectTag


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

18 package org.apache.beehive.netui.tags.rendering;
19
20 import org.apache.beehive.netui.tags.html.HtmlConstants;
21
22 import java.util.HashMap JavaDoc;
23
24 /**
25  * Body, Start Tag: optional, End tag: optional
26  * Required href
27  */

28 public abstract class SelectTag extends TagHtmlBase implements HtmlConstants
29 {
30     public static void add(HashMap JavaDoc html, HashMap JavaDoc htmlQuirks, HashMap JavaDoc xhtml)
31     {
32         html.put(SELECT_TAG, new HtmlRendering());
33         htmlQuirks.put(SELECT_TAG, new HtmlRendering());
34         xhtml.put(SELECT_TAG, new XhtmlRendering());
35     }
36
37     public static class State extends AbstractHtmlControlState
38     {
39         public boolean disabled;
40         public boolean multiple;
41         public int size;
42
43         public void clear()
44         {
45             super.clear();
46             disabled = false;
47             multiple = false;
48             size = 0;
49         }
50     }
51
52     public void doStartTag(AbstractRenderAppender sb, AbstractTagState renderState)
53     {
54         assert(sb != null) : "Parameter 'sb' must not be null";
55         assert(renderState != null) : "Parameter 'renderState' must not be null";
56         assert(renderState instanceof State) : "Paramater 'renderState' must be an instance of SelectTag.State";
57
58         State state = (State) renderState;
59
60         renderTag(sb, SELECT);
61         renderAttribute(sb, NAME, state.name);
62         renderAttribute(sb, ID, state.id);
63         renderAttribute(sb, CLASS, state.styleClass);
64         renderMultiple(sb, state.multiple);
65         renderDisabled(sb, state.disabled);
66         if (state.size > 0)
67             renderAttribute(sb, SIZE, Integer.toString(state.size));
68
69         renderAttributes(AbstractHtmlState.ATTR_GENERAL, sb, state);
70         renderAttribute(sb, STYLE, state.style);
71         renderAttributes(AbstractHtmlState.ATTR_JAVASCRIPT, sb, state);
72         sb.append(">");
73     }
74
75     public void doEndTag(AbstractRenderAppender sb)
76     {
77         renderEndTag(sb, SELECT);
78     }
79
80     abstract protected void renderDisabled(AbstractRenderAppender sb, boolean disabled);
81
82     abstract protected void renderMultiple(AbstractRenderAppender sb, boolean readonly);
83
84     private static class HtmlRendering extends SelectTag
85     {
86         protected void renderDisabled(AbstractRenderAppender sb, boolean disabled)
87         {
88             if (disabled)
89                 sb.append(" disabled");
90
91         }
92
93         protected void renderMultiple(AbstractRenderAppender sb, boolean multiple)
94         {
95             if (multiple)
96                 sb.append(" multiple");
97
98         }
99     }
100
101     private static class XhtmlRendering extends SelectTag
102     {
103         protected void renderDisabled(AbstractRenderAppender sb, boolean disabled)
104         {
105             if (disabled)
106                 renderAttribute(sb, "disabled", "disabled");
107
108         }
109
110         protected void renderMultiple(AbstractRenderAppender sb, boolean multiple)
111         {
112             if (multiple)
113                 renderAttribute(sb, "multiple", "multiple");
114
115         }
116     }
117 }
118
Popular Tags