1 18 19 package org.objectweb.jac.aspects.gui.web; 20 21 import java.io.IOException ; 22 import java.io.PrintWriter ; 23 import java.util.Collection ; 24 import java.util.Iterator ; 25 import java.util.Map ; 26 import java.util.Vector ; 27 import org.apache.log4j.Logger; 28 import org.objectweb.jac.aspects.gui.*; 29 import org.objectweb.jac.aspects.gui.Menu; 30 31 public class Customized extends AbstractCompositeView 32 implements CustomizedView, HTMLViewer, WindowListener 33 { 34 static Logger logger = Logger.getLogger("web"); 35 static Logger loggerContext = Logger.getLogger("display.context"); 36 static Logger loggerEditor = Logger.getLogger("gui.editor"); 37 38 CustomizedGUI customized; 39 PanelView mainView; 41 42 50 public Customized(ViewFactory factory, DisplayContext context, 51 CustomizedGUI customized, Map panels) { 52 this.factory = factory; 53 this.customized = customized; 54 this.context = context; 55 context.setCustomizedView(this); 56 57 logger.debug("building cutomized..."); 58 try { 59 mainView = (PanelView)factory.createCompositeView( 60 "main", 61 "Panel", 62 new Object [] { 63 new Integer (customized.getSubPanesCount()), 64 new Integer (customized.getGeometry()), 65 customized.getPaneContainers(), 66 customized.getScrollings(), 67 customized.getSplitters() }, 68 context 69 ); 70 } catch (ViewFactory.UnhandledViewTypeException e) { 71 e.printStackTrace(); 72 } 73 74 try { 77 GenericFactory.initCustomized(factory, context, mainView, 78 customized, panels); 79 if (customized.hasMenuBar()) 80 GenericFactory.setMenuBars(factory, context, 81 this, customized.getMenus()); 82 if (customized.hasToolBar()) 83 GenericFactory.setToolBar(factory, context, 84 this, customized.getToolbar()); 85 if (customized.hasStatusBar()) 86 GenericFactory.setStatusBar(factory, context, 87 this, customized.getStatusBarMethod(), 88 customized.getStatusPosition()); 89 90 } catch (Exception e) { 91 logger.error("Customized("+customized+")",e); 92 } 93 logger.debug("building cutomized DONE"); 94 } 95 96 public void close(boolean validate) { 97 mainView.close(validate); 98 } 99 100 102 public void setContext(DisplayContext context) { 103 super.setContext(context); 104 loggerContext.debug("setContext on "+getClass().getName()); 105 Iterator i = mainView.getViews().iterator(); 107 while (i.hasNext()) { 108 View view = (View)i.next(); 109 loggerContext.debug("set context on subView "+view); 110 view.setContext(context); 111 } 112 } 113 114 public void addView(View view, Object extraInfos) { 115 view.setContext(context); 116 mainView.addView(view,extraInfos); 117 } 118 119 public void addView(View view) { 120 addView(view,null); 121 } 122 123 public Collection getViews() { 124 return mainView.getViews(); 125 } 126 127 public View getView(Object id) { 128 return mainView.getView(id); 129 } 130 131 public void removeAllViews(boolean validate) { 132 mainView.removeAllViews(validate); 133 } 134 135 137 public CustomizedGUI getCustomizedGUI() { 138 return customized; 139 } 140 141 Vector menuBars = new Vector (); 142 MenuView topMenuBar; 143 MenuView bottomMenuBar; 144 MenuView leftMenuBar; 145 MenuView rightMenuBar; 146 147 public void setMenuBar(MenuView menuBar,String position) { 148 if (position==null) 149 position = Menu.LEFT; 150 menuBar.setPosition(position); 151 if (position.equals(Menu.TOP)) { 152 topMenuBar=menuBar; 153 } else if(position.equals(Menu.BOTTOM)) { 154 bottomMenuBar=menuBar; 155 } else if(position.equals(Menu.LEFT)) { 156 leftMenuBar=menuBar; 157 } else if(position.equals(Menu.RIGHT)) { 158 rightMenuBar=menuBar; 159 } 160 this.menuBars.add(menuBar); 161 } 162 163 public MenuView getTopMenuBar() { 164 return topMenuBar; 165 } 166 167 public MenuView getBottomMenuBar() { 168 return bottomMenuBar; 169 } 170 171 public MenuView getLeftMenuBar() { 172 return leftMenuBar; 173 } 174 175 public MenuView getRightMenuBar() { 176 return rightMenuBar; 177 } 178 179 MenuView toolBar; 180 public void setToolBar(MenuView toolBar) { 181 this.toolBar = toolBar; 182 } 183 184 StatusView statusBar; 185 public void setStatusBar(StatusView statusBar,String position) { 186 this.statusBar=statusBar; 187 statusBar.setPosition(position); 188 } 189 190 public void showStatus(String message) { 191 statusBar.showMessage(message); 192 } 193 194 public PanelView getPanelView() { 195 return mainView; 196 } 197 198 public void requestFocus() { 199 } 200 201 203 public void genHTML(PrintWriter out) throws IOException { 204 out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">"); 205 out.println("<html>"); 206 out.println(" <head>"); 207 out.println(" <title>"+label+"</title>"); 208 out.println(" <meta name=\"Author\" content=\"JAC web-gui server\">" ); 209 out.println(" <script type=\"text/javascript\" SRC=\""+javascript+"\"></script>"); 210 if (customized.getIcon()!=null) { 211 String resource = ResourceManager.getResource(customized.getIcon()); 212 if (resource!=null) 213 out.println(" <link rel=\"icon\" HREF=\"resources/"+resource+"\" />"); 214 } 215 genStyleSheets(out,context.getCustomizedView()); 216 out.println(" </head>"); 217 out.println(" <body>"); 218 genBody(out); 219 out.println(" </body>"); 220 out.println("</html>"); 221 } 222 223 protected void genBody(PrintWriter out) throws IOException { 224 openForm(out); 225 out.println("<table class=\"customized\">"); 226 if (statusBar!=null && statusBar.getPosition().equals(CustomizedGUI.TOP)) { 227 out.println(" <tr>\n <td class=\"statusBar\" colspan=\"3\">"); 228 ((HTMLViewer)statusBar).genHTML(out); 229 out.println(" </td>\n </tr>"); 230 } 231 if (topMenuBar!=null) { 232 out.println(" <tr>\n <td class=\"menuBarT\" colspan=\"3\">"); 233 ((HTMLViewer)topMenuBar).genHTML(out); 234 if (toolBar!=null) { 235 ((HTMLViewer)toolBar).genHTML(out); 236 } 237 out.println(" </td>\n </tr>"); 238 } 239 out.println(" <tr>"); 240 int colspan = 1; 241 if (leftMenuBar==null) 242 colspan++; 243 if (rightMenuBar==null) 244 colspan++; 245 if (leftMenuBar!=null) { 246 out.println(" <td class=\"menuBarL\">"); 247 ((HTMLViewer)leftMenuBar).genHTML(out); 248 out.println(" </td>"); 249 } 250 out.println(" <td"+(colspan>1?(" colspan=\""+colspan+"\""):"")+" class=\"mainView\"><div class=\"mainView\">"); 251 ((HTMLViewer)mainView).genHTML(out); 253 out.println(" \n</div>\n </td>"); 254 if (rightMenuBar!=null) { 255 out.println(" <td class=\"menuBarR\">"); 256 ((HTMLViewer)rightMenuBar).genHTML(out); 257 out.println(" </td>"); 258 } 259 out.println(" </tr>"); 260 if (bottomMenuBar!=null) { 261 out.println(" <tr>\n <td class=\"menuBarB\" colspan=\"3\">"); 262 ((HTMLViewer)bottomMenuBar).genHTML(out); 263 out.println(" </td>\n </tr>"); 264 } 265 if (statusBar!=null && statusBar.getPosition().equals(CustomizedGUI.BOTTOM)) { 266 out.println(" <tr>\n <td class=\"statusBar\" colspan=\"3\">"); 267 ((HTMLViewer)statusBar).genHTML(out); 268 out.println(" </td>\n </tr>"); 269 } 270 out.println("</table>"); 271 272 if (context.hasEnabledEditor()) { 273 out.println("<div id=\"buttons\">"); 274 loggerEditor.debug("editors = "+context.getEditors()); 275 showButton(out,null,GuiAC.getLabelOK(),"onOK"); 276 showButton(out,null,GuiAC.getLabelCancel(),"onCancel"); 277 out.println("</div>"); 278 } 279 280 closeForm(out); 281 } 282 283 285 public void onOK(JacRequest request) { 286 WebDisplay display = (WebDisplay)context.getDisplay(); 287 WebDisplay.readValuesAndRefresh(context,request,true); 288 } 289 290 public void onRefresh(JacRequest request) { 291 WebDisplay display = (WebDisplay)context.getDisplay(); 292 WebDisplay.readValuesAndRefresh(context,request,true); 293 } 294 295 public void onCancel() { 296 ((WebDisplay)context.getDisplay()).refresh(); 297 } 298 299 public void onValidate(JacRequest request) { 300 WebDisplay.readValues(context,request,true); 301 } 302 303 } 304 305 | Popular Tags |