1 package fr.improve.struts.taglib.layout; 2 3 import javax.servlet.jsp.JspException ; 4 5 import fr.improve.struts.taglib.layout.event.ComputeLayoutSpanEvent; 6 import fr.improve.struts.taglib.layout.event.ComputeLayoutSpanEventListener; 7 import fr.improve.struts.taglib.layout.event.EndLayoutEvent; 8 import fr.improve.struts.taglib.layout.event.LayoutEventListener; 9 import fr.improve.struts.taglib.layout.event.StartLayoutEvent; 10 import fr.improve.struts.taglib.layout.event.StaticCodeIncludeLayoutEvent; 11 import fr.improve.struts.taglib.layout.event.StaticCodeIncludeListener; 12 import fr.improve.struts.taglib.layout.util.LayoutUtils; 13 import fr.improve.struts.taglib.layout.util.TagUtils; 14 15 18 public class GridLayoutTag extends LayoutTagSupport implements LayoutEventListener, ComputeLayoutSpanEventListener, StaticCodeIncludeListener { 19 protected String cols = "2"; 20 21 protected boolean space = true; 22 23 protected String styleClass; 24 protected String width; 25 protected String align; 26 27 30 protected int borderSpacing = 0; 31 32 protected String id; 33 protected String height; 34 35 protected int currentCols = 1; 36 protected int currentSpan = 1; 37 protected String jspStyleClass; 38 39 protected StringBuffer staticCode = new StringBuffer (); 40 41 protected void initDynamicValues() { 42 jspStyleClass = styleClass; 43 if (styleClass==null){ 44 styleClass = LayoutUtils.getSkin(pageContext.getSession()).getProperty("styleclass.grid",null); 45 } 46 } 47 protected void reset() { 48 styleClass = jspStyleClass; 49 jspStyleClass = null; 50 staticCode = new StringBuffer (); 51 } 52 53 public int doStartLayoutTag() throws JspException { 54 int lc_fieldColumnNumber = LayoutUtils.getSkin(pageContext.getSession()).getFieldInterface().getColumnNumber(); 55 new StartLayoutEvent(this, "<td colspan=\"" + lc_fieldColumnNumber + "\">").send(); 56 57 if (id!=null || height!=null) { 58 TagUtils.write(pageContext, "<div style=\""); 59 if (height!=null) { 60 TagUtils.write(pageContext, "height:"); 61 TagUtils.write(pageContext, height); 62 TagUtils.write(pageContext, ";"); 63 } 64 TagUtils.write(pageContext,"overflow-y:scroll;overflow:-moz-scrollbars-vertical;"); 65 if (id!=null) { 66 TagUtils.write(pageContext, "\" id=\""); 67 TagUtils.write(pageContext, id); 68 } 69 TagUtils.write(pageContext, "\">"); 70 } 71 72 TagUtils.write(pageContext, "<table border=\"0\" cellspacing=\""); 73 TagUtils.write(pageContext, String.valueOf(borderSpacing)); 74 TagUtils.write(pageContext,"\" cellpadding=\"0\""); 75 if (styleClass!=null) { 76 TagUtils.write(pageContext, " class=\""); 77 TagUtils.write(pageContext, styleClass); 78 TagUtils.write(pageContext, "\""); 79 } 80 if (width!=null) { 81 TagUtils.write(pageContext, " width=\""); 82 TagUtils.write(pageContext, width); 83 TagUtils.write(pageContext, "\""); 84 } 85 if (align!=null) { 86 TagUtils.write(pageContext, " align=\""); 87 TagUtils.write(pageContext, align); 88 TagUtils.write(pageContext, "\""); 89 } 90 TagUtils.write(pageContext,"><tr>"); 91 return EVAL_BODY_INCLUDE; 92 } 93 public int doEndLayoutTag() throws JspException { 94 currentCols = 1; 95 TagUtils.write(pageContext, "</tr></table>"); 96 97 if (id!=null || height!=null) { 98 TagUtils.write(pageContext, "</div>"); 99 } 100 if (staticCode.length()!=0) { 101 TagUtils.write(pageContext, staticCode.toString()); 102 } 103 104 new EndLayoutEvent(this, "</td>").send(); 105 return EVAL_PAGE; 106 } 107 public void release() { 108 super.release(); 109 cols = "2"; 110 space = true; 111 styleClass = null; 112 height = null; 113 id = null; 114 width = null; 115 align = null; 116 borderSpacing = 0; 117 } 118 119 public Object processStartLayoutEvent(StartLayoutEvent in_event) throws JspException { 120 if (currentCols > Integer.parseInt(cols)) { 121 TagUtils.write(pageContext, "</tr><tr>"); 122 currentCols = 1; 123 } 124 currentCols += currentSpan; 125 currentSpan = 1; 126 return in_event.consume(pageContext, ""); 127 } 128 public Object processEndLayoutEvent(EndLayoutEvent in_event) throws JspException { 129 return in_event.consume(pageContext, space ? "<td> </td>" : ""); 130 } 131 132 public Integer computeColspan(ComputeLayoutSpanEvent in_event) throws JspException { 133 currentSpan = in_event.getColspan(); 134 if (space) { 135 int lc_value = ((Integer )in_event.consume(this)).intValue(); 137 138 lc_value += in_event.getColspan(); 140 141 lc_value -= 1; 143 144 return new Integer (lc_value); 146 } else { 147 return (Integer ) in_event.consume(this); 149 } 150 151 } 152 153 157 public void setCols(String cols) { 158 this.cols = cols; 159 } 160 161 165 public boolean isSpace() { 166 return space; 167 } 168 169 173 public void setSpace(boolean space) { 174 this.space = space; 175 } 176 177 181 public void setStyleClass(String styleClass) { 182 this.styleClass = styleClass; 183 } 184 185 189 public void setHeight(String height) { 190 this.height = height; 191 } 192 193 197 public void setId(String id) { 198 this.id = id; 199 } 200 201 public void setWidth(String in_string) { 202 width = in_string; 203 } 204 205 public void setBorderSpacing(int in_spacing) { 206 borderSpacing = in_spacing; 207 } 208 209 public String getAlign() { 210 return align; 211 } 212 213 public void setAlign(String align) { 214 this.align = align; 215 } 216 217 220 public Object processStaticCodeIncludeEvent(StaticCodeIncludeLayoutEvent in_event) throws JspException { 221 String lc_value = (String ) in_event.sendToParent(this); 222 if (height==null && id==null) { 223 return lc_value; 224 } else { 225 staticCode.append(lc_value); 226 return ""; 227 } 228 } 229 } 230 | Popular Tags |