package e4s.tutorial; import e4s.html.*; import e4s.servlet.E4ModuleImplementation; import e4s.servlet.E4ServletImplementation_Intf; /** * Define a reusable element of HTML tags that covers some specific layout or logic and * add it to other elements within the HTML output context. * * {@tutorial Example_HtmlElement_Intf} */ public class Example_HtmlElement_Intf extends E4ModuleImplementation { public static E4Method start = null; /** * The element holds a caption and 7x entries, one for each weekday. */ public class MyElement extends E4HtmlContentElement implements E4HtmlElement_Intf { private boolean m_set[] = new boolean[7]; private String m_label = null; /** * Construct an element with a specified caption. * * @param label the caption to be displayed */ public MyElement( String label ) { m_label = label; } /** * Render some content (a table tag with two rows and one holding 7 td tags). */ public void createContent() { final String WDAYS[] = {"Su","Mo","Tu","We","Th","Fr","Sa"}; TABLE table = TABLE(TABLE.E4S_DEFAULT_TABLE()); TD tdHeader = table.TR().TD(); tdHeader.setColspan(7); tdHeader.setAlign(Align.CENTER); tdHeader.print(m_label); TD td[] = table.TR().TD(7); for( int i = 0; i < 7; i++ ) { td[i].I().print(WDAYS[i]); if (m_set[i]) td[i].setBgColor(E4Color.LIGHT_BLUE); } } /** * Set one particular day * * @param n (0=Sunday .. 6=Saturday) */ public void set( int n ) { m_set[n] = true; } } /** * This is our main function. Make some HTML output but also use the MyElement class in two cases. */ public void start( HTML html ) { MyElement departure = new MyElement("Departure"); departure.set(0); departure.set(2); departure.set(5); departure.createContent(); MyElement arrival = new MyElement("Arrival"); arrival.set(1); arrival.set(3); arrival.set(6); arrival.createContent(); BODY body = html.BODY(); body.B().print("Last Train to London.."); TABLE table = html.BODY().TABLE(); TR tr = table.TR(); tr.TD().addElement(departure); tr.TD().addElement(arrival); } }