KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > web > Customized


1 /*
2   Copyright (C) 2002-2003 Renaud Pawlak <renaud@aopsys.com>,
3                           Laurent Martelli <laurent@aopsys.com>
4   
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU Lesser General Public License as
7   published by the Free Software Foundation; either version 2 of the
8   License, or (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   GNU Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

18
19 package org.objectweb.jac.aspects.gui.web;
20
21 import java.io.IOException JavaDoc;
22 import java.io.PrintWriter JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Vector JavaDoc;
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     // JPanel contentPanel;
40
PanelView mainView;
41
42     /**
43      * Builds a customized view.
44      * @param factory the view factory
45      * @param context the display context
46      * @param customized the customized GUI to build a view of
47      * @param panels if not null, overrides the content of the view
48      * (panelID -> PanelContent)
49      */

50     public Customized(ViewFactory factory, DisplayContext context,
51                       CustomizedGUI customized, Map JavaDoc 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 JavaDoc[] {
63                     new Integer JavaDoc(customized.getSubPanesCount()),
64                     new Integer JavaDoc(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         // setPosition(customized.getLeft(),customized.getUp(),
75
// customized.getWidth(),customized.getHeight());
76
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 JavaDoc 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     // View interface
101

102     public void setContext(DisplayContext context) {
103         super.setContext(context);
104         loggerContext.debug("setContext on "+getClass().getName());
105         // recursively set the display of inner components
106
Iterator JavaDoc 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 JavaDoc 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 JavaDoc getViews() {
124         return mainView.getViews();
125     }
126
127     public View getView(Object JavaDoc id) {
128         return mainView.getView(id);
129     }
130
131     public void removeAllViews(boolean validate) {
132         mainView.removeAllViews(validate);
133     }
134
135     // CustomizedView interface
136

137     public CustomizedGUI getCustomizedGUI() {
138         return customized;
139     }
140
141     Vector JavaDoc menuBars = new Vector JavaDoc();
142     MenuView topMenuBar;
143     MenuView bottomMenuBar;
144     MenuView leftMenuBar;
145     MenuView rightMenuBar;
146
147     public void setMenuBar(MenuView menuBar,String JavaDoc 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 JavaDoc position) {
186         this.statusBar=statusBar;
187         statusBar.setPosition(position);
188     }
189
190     public void showStatus(String JavaDoc message) {
191         statusBar.showMessage(message);
192     }
193
194     public PanelView getPanelView() {
195         return mainView;
196     }
197
198     public void requestFocus() {
199     }
200
201     // HTMLViewer interface
202

203     public void genHTML(PrintWriter JavaDoc out) throws IOException JavaDoc {
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 JavaDoc 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 JavaDoc out) throws IOException JavaDoc {
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         // out.println(" ");
252
((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     // WindowListener interface
284

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