package e4s.tutorial; import e4s.util.E4Images; import e4s.html.*; import e4s.html.style.*; import e4s.servlet.*; import e4s.translate.E4LabelNone; import java.io.*; import java.util.*; import java.text.*; /** * Cascading style sheet handling. * * {@tutorial Example_CSS_01} * * @see e4s.html.style.STYLE_Name * @see e4s.html.style.CLASS_Name * @see e4s.html.style.E4CssFile * @see e4s.html.style.CSS_Name */ public class Example_CSS_01 extends E4ModuleImplementation { public static E4Method start = null; public static E4Method toggleStyleEditing = null; private void initCSS() { try { getServlet().assignCSS(E4CssFile.LEVEL_APPLICATION,new CSS_Name("Example_CSS_01")); } catch( Exception e ) { System.out.println(e); } } public void start( HTML html ) { initCSS(); CLASS_Name table_class = new CLASS_Name("my_table_class"); BODY body = html.BODY(); body.setSTYLE(new CLASS_Name("my_body_class")); body.Message(E4Message.CAPTION,E4LabelNone("E4CSS editing")); body.P(); body.print("This is a table, the whole table is assigned the class-name " + table_class.getName() + ", "); body.print("additional, if row and column matches (diagonal) then a particular class name will be assigned."); body.BR(); body.print("You can use the E4CSS editing capabilities to view and edit the different styles, using the "); body.print("interactive online style editor. Just turn on style editing first and click on the "); body.IMG(E4Images.css_do_edit); body.print("-Symbol"); body.P(); TABLE table = body.TABLE(); table.setBorder(); table.setSTYLE(table_class); int N = 5; for( int row = 1; row <= N; row++ ) { TR tr = table.TR(); for( int col = 1; col <= N; col++ ) { TD td = tr.TD(); td.FONT(FONT.ARIAL_smaller).print( row + "." + col ); if (col == row) td.setSTYLE(new CLASS_Name("cell_" + row + "_" + col)); } } body.P(); FONT special = body.FONT(); special.setSTYLE(new CLASS_Name("my_font")); special.print("To be or not to be.."); body.P(); A href = body.A(toggleStyleEditing); if ( getServlet().sessionCanEditStyles() ) href.println("[turn OFF style editing]"); else href.println("[turn ON style editing]"); body.A(start).println("[display again]"); } public void toggleStyleEditing( HTML html ) { E4ServletImplementation_Intf servlet = getServlet(); if (servlet.sessionCanEditStyles()) servlet.sessionCanEditStyles(false); else servlet.sessionCanEditStyles(true); start(html); } }