KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > util > ImagePanel


1 package fr.improve.struts.taglib.layout.util;
2
3 import java.util.MissingResourceException JavaDoc;
4
5 import javax.servlet.jsp.JspException JavaDoc;
6 import javax.servlet.jsp.PageContext JavaDoc;
7 import javax.servlet.jsp.tagext.Tag JavaDoc;
8 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
9
10 import fr.improve.struts.taglib.layout.HtmlTag;
11 import fr.improve.struts.taglib.layout.PanelTag;
12 import fr.improve.struts.taglib.layout.skin.Skin;
13 /**
14  * Insert the type's description here.
15  * Creation date: (06/06/01 13:14:21)
16  * @author: Jean-NoŽl Ribette
17  */

18 public class ImagePanel implements PanelInterface {
19     private String JavaDoc styleClass;
20     private boolean isNested = false;
21     
22     private String JavaDoc bg_width;
23     private String JavaDoc bg_height;
24     private String JavaDoc bg_bottom_height;
25     private String JavaDoc bg_top_height;
26     private String JavaDoc bottom;
27     private String JavaDoc bottom_LEFT;
28     private String JavaDoc bottom_RIGHT;
29     private String JavaDoc left;
30     private String JavaDoc right;
31     private String JavaDoc top;
32     private String JavaDoc top_LEFT;
33     private String JavaDoc top_RIGHT;
34     
35     private String JavaDoc imageDir;
36     public void doAfterBody(StringBuffer JavaDoc buffer) {
37     buffer.append("</table></td>\n");
38 }
39     public void doBeforeBody(StringBuffer JavaDoc buffer, String JavaDoc align) {
40     buffer.append("<td class=");
41     buffer.append(styleClass);
42     buffer.append("><table width=\"100%\"");
43     if (align!=null) {
44             buffer.append(" align=\"");
45             buffer.append(align);
46             buffer.append("\"");
47     }
48     buffer.append(" border=0>\n");
49 }
50 /**
51  * doEndPanel method comment.
52  */

53 public void doEndPanel(StringBuffer JavaDoc buffer) {
54     // buffer.append("</table></td>\n");
55

56     // end of the middle line
57
buffer.append("<td width=\"");
58     buffer.append(bg_width);
59     buffer.append("\" background=\"");
60     buffer.append(right);
61     buffer.append("\" style=\"background-repeat:repeat-y;\">" + doPrintClearPix() + "</td>");
62     buffer.append("</tr>");
63
64     // last line
65
buffer.append("<tr>");
66
67     buffer.append("<td width=\"");
68     buffer.append(bg_width);
69     buffer.append("\" height=\"");
70     buffer.append(bg_bottom_height);
71     buffer.append("\"><img SRC=\"");
72     buffer.append(bottom_LEFT);
73     buffer.append("\"></td>");
74     
75     buffer.append("<td height=\"");
76     buffer.append(bg_bottom_height);
77     buffer.append("\" background=\"");
78     buffer.append(bottom);
79     buffer.append("\" style=\"background-repeat:repeat-x;\">"+ doPrintClearPix() + "</td>");
80
81     buffer.append("<td width=\"");
82     buffer.append(bg_width);
83     buffer.append("\" height=\"");
84     buffer.append(bg_bottom_height);
85     buffer.append("\"><img SRC=\"");
86     buffer.append(bottom_RIGHT);
87     buffer.append("\" valign=\"top\"></td>");
88     
89     buffer.append("</tr>");
90
91     //end table
92
buffer.append("</table>");
93     }
94
95     public String JavaDoc doPrintClearPix(){
96         return "<img SRC=\""+imageDir+ "/clearpix.gif\" height=\"1\" width=\"1\" border=\"0\">";
97     }
98     
99     public void doPrintBlankLine(StringBuffer JavaDoc buffer, int cols) {
100         buffer.append("<tr><td colspan=" + cols + ">" + doPrintClearPix() + "</td></tr>\n");
101     }
102 /**
103  * doPrintTitle method comment.
104  */

105 public void doPrintTitle(StringBuffer JavaDoc buffer, String JavaDoc title) {
106     buffer.append("<td");
107
108     if (title!=null) {
109         buffer.append("><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"");
110         buffer.append(styleClass);
111         buffer.append("\"><tr><th class=\"");
112         buffer.append(styleClass);
113         buffer.append("\" height=\"");
114         buffer.append(bg_top_height);
115         buffer.append("\" background=\"");
116         buffer.append(top);
117         buffer.append("\" style=\"background-repeat:repeat-x;\"");
118         buffer.append("\">");
119         buffer.append(title);
120         buffer.append("</th></tr></table>");
121     } else {
122         buffer.append(" height=\"");
123         buffer.append(bg_top_height);
124         buffer.append("\" background=\"");
125         buffer.append(top);
126         buffer.append("\" style=\"background-repeat:repeat-x;\">" + doPrintClearPix());
127     }
128     buffer.append("</td>");
129
130     buffer.append("<td width=\"");
131     buffer.append(bg_width);
132     buffer.append("\" height=\"");
133     buffer.append(bg_top_height);
134     buffer.append("\"><img SRC=\"");
135     buffer.append(top_RIGHT);
136     buffer.append("\"></td>");
137     
138     buffer.append("</tr>");
139     
140     // middle
141
buffer.append("<tr>");
142
143     buffer.append("<td width=\"");
144     buffer.append(bg_width);
145     buffer.append("\" background=\"");
146     buffer.append(left);
147     buffer.append("\" style=\"background-repeat:repeat-y;\">" + doPrintClearPix() + "</td>");
148         
149     // buffer.append("<td><table cellspacing=0 cellpadding=0 border=0 width=100%>\n");
150
}
151 /**
152  * doStartPanel method comment.
153  */

154 public void doStartPanel(StringBuffer JavaDoc buffer, String JavaDoc align, String JavaDoc width) {
155     // table
156
buffer.append("<table cellspacing=0 cellpadding=0 border=0");
157     if (align!=null) {
158         buffer.append(" align=");
159         buffer.append(align);
160     }
161     if (width!=null) {
162         buffer.append(" width=");
163         buffer.append(width);
164     }
165     buffer.append(">");
166     
167     // top line
168
buffer.append("<tr>");
169
170     buffer.append("<td width=\"");
171     buffer.append(bg_width);
172     buffer.append("\" height=\"");
173     buffer.append(bg_top_height);
174     buffer.append("\"><img SRC=\"");
175     buffer.append(top_LEFT);
176     buffer.append("\"></td>");
177 }
178     public void init(PageContext JavaDoc pageContext, String JavaDoc in_styleClass, TagSupport JavaDoc in_panel) throws JspException JavaDoc {
179         this.styleClass = in_styleClass;
180         
181         Skin l_skin = LayoutUtils.getSkin(pageContext.getSession());
182         imageDir = l_skin.getImageDirectory(pageContext.getRequest());
183         
184         try {
185             bg_width = l_skin.getProperty("width");
186             bg_height = l_skin.getProperty("height");
187             
188             top_LEFT = l_skin.getProperty("top_LEFT");
189             top = l_skin.getProperty("top");
190             top_RIGHT = l_skin.getProperty("top_RIGHT");
191             left = l_skin.getProperty("left");
192             right = l_skin.getProperty("right");
193             bottom_LEFT = l_skin.getProperty("bottom_LEFT");
194             bottom = l_skin.getProperty("bottom");
195             bottom_RIGHT = l_skin.getProperty("bottom_RIGHT");
196         } catch (MissingResourceException JavaDoc e) {
197             throw new JspException JavaDoc("Bad imagepanel configuration: can't find key " + e.getKey() + " in file " + e.getClassName());
198         }
199         
200         try {
201             bg_top_height = l_skin.getProperty("top_height");
202             bg_bottom_height = l_skin.getProperty("bottom_height");
203         
204         } catch (MissingResourceException JavaDoc e) {
205             if (bg_height.length()!=0){
206                 bg_bottom_height = bg_height;
207                 bg_top_height = bg_height;
208             }
209         }
210         
211         Tag JavaDoc lc_parent = in_panel!=null ? TagSupport.findAncestorWithClass(in_panel, PanelTag.class) : null;
212         isNested = !LayoutUtils.isPanelNesting() && lc_parent != null && !(lc_parent instanceof HtmlTag);
213     }
214 }
215
Popular Tags