KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > wingset > WingSet


1 /*
2  * $Id: WingSet.java,v 1.16 2005/05/27 12:53:18 blueshift Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package wingset;
15
16
17 import org.wings.*;
18 import org.wings.style.CSSProperty;
19 import org.wings.header.Link;
20 import org.wings.resource.DefaultURLResource;
21 import org.wings.session.WingsStatistics;
22 import org.wings.session.Browser;
23 import org.wings.session.BrowserType;
24 import org.wings.util.TimeMeasure;
25
26 import java.io.FileWriter JavaDoc;
27 import java.io.Serializable JavaDoc;
28 import java.io.File JavaDoc;
29 import java.net.URL JavaDoc;
30 import java.text.MessageFormat JavaDoc;
31 import java.util.Timer JavaDoc;
32 import java.util.TimerTask JavaDoc;
33
34 /**
35  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
36  * @version $Revision: 1.16 $
37  */

38 public class WingSet implements Serializable JavaDoc {
39     private final static SIcon JAVA_CUP_ICON = new SResourceIcon("org/wings/icons/JavaCup.gif");
40     private final static SIcon SMALL_COW_ICON = new SURLIcon("../icons/cowSmall.gif");
41     private final static SURLIcon STANDARD_TAB_BACKGROUND = new SURLIcon("../icons/ButtonsBackground.gif");
42     private final static SURLIcon SELECTED_TAB_BACKGROUND = new SURLIcon("../icons/ButtonsBackgroundHighlighted.gif");
43
44     static final boolean SHOW_STATISTICS = false;
45     static final long birthday = System.currentTimeMillis();
46     static FileWriter JavaDoc infoWriter;
47     static final Timer JavaDoc timer = new Timer JavaDoc();
48     static long oldRequestCount = 0;
49     static long oldSessionCount = 0;
50
51     private SFrame frame;
52     // time measurement (a little hacky)
53
private SLabel timeMeasure;
54     private final TimeMeasure stopWatch;
55
56     static final TimerTask JavaDoc infoTask = new TimerTask JavaDoc() {
57         public void run() {
58             StringBuffer JavaDoc result = new StringBuffer JavaDoc();
59             long totalmem = Runtime.getRuntime().totalMemory();
60             long freemem = Runtime.getRuntime().freeMemory();
61
62             WingsStatistics stats = WingsStatistics.getStatistics();
63
64             result.append(System.currentTimeMillis()).append(' ')
65                     .append(stats.getUptime()).append(' ')
66                     .append(stats.getOverallSessionCount()).append(' ')
67                     .append(stats.getOverallSessionCount() - oldSessionCount).append(' ')
68                     .append(stats.getActiveSessionCount()).append(' ')
69                     .append(stats.getAllocatedSessionCount()).append(' ')
70                     .append(stats.getRequestCount()).append(' ')
71                     .append(stats.getRequestCount() - oldRequestCount).append(' ')
72                     .append(totalmem).append(' ')
73                     .append(freemem).append(' ')
74                     .append(totalmem - freemem).append('\n');
75
76             oldRequestCount = stats.getRequestCount();
77             oldSessionCount = stats.getOverallSessionCount();
78
79             try {
80                 infoWriter.write(result.toString());
81                 infoWriter.flush();
82             } catch (Exception JavaDoc ex) {
83                 ex.printStackTrace();
84             }
85         }
86     };
87
88     static {
89         if (SHOW_STATISTICS) {
90             try {
91                 infoWriter = new FileWriter JavaDoc(File.createTempFile("wingsmemory","log"), false);
92
93                 StringBuffer JavaDoc result = new StringBuffer JavaDoc();
94                 result.append("timestamp").append(' ')
95                         .append("uptime").append(' ')
96                         .append("overall_sessions").append(' ')
97                         .append("new_sessions").append(' ')
98                         .append("active_sessions").append(' ')
99                         .append("allocated_sessions").append(' ')
100                         .append("overall_processed requests").append(' ')
101                         .append("processed_requests").append(' ')
102                         .append("total_memory").append(' ')
103                         .append("free_memory").append(' ')
104                         .append("used_memory").append('\n');
105                 infoWriter.write(result.toString());
106                 infoWriter.flush();
107             } catch (Exception JavaDoc ex) {
108                 ex.printStackTrace();
109             }
110
111             timer.scheduleAtFixedRate(infoTask,0,10 * 1000);
112         }
113     }
114
115     public WingSet() {
116         frame = new SFrame("WingSet");
117         frame.setTitle("WingSet Demo");
118         frame.setAttribute(CSSProperty.MARGIN, "8px !important");
119
120         // Register our user style sheet
121
final Browser browser = frame.getSession().getUserAgent();
122         String JavaDoc cssURL = "../wingset-gecko.css"; //"../wingset-" + browser.getBrowserType().getShortName() + ".css";
123
if (browser.getBrowserType().equals(BrowserType.IE))
124             cssURL = "../wingset-msie.css";
125         frame.addHeader(new Link("stylesheet", null, "text/css", null, new DefaultURLResource(cssURL)));
126
127         stopWatch = new TimeMeasure(new MessageFormat JavaDoc("<html><b>{0}</b>: {1} (<i>x {2}</i>)<br/>"));
128         timeMeasure = new SLabel();
129
130         SContainer contentPane = frame.getContentPane();
131         try {
132             URL JavaDoc templateURL = frame.getSession().getServletContext().getResource("/templates/ExampleFrame.thtml");
133             if (templateURL != null) {
134                 SRootLayout layout = new SRootLayout(templateURL);
135                 frame.setLayout(layout);
136             }
137         } catch (java.io.IOException JavaDoc except) {
138             except.printStackTrace();
139         }
140         
141         final STabbedPane tab = new STabbedPane();
142         tab.setName("examples");
143         tab.setTabPlacement(SConstants.TOP);
144
145         tab.setAttribute(STabbedPane.SELECTOR_UNSELECTED_TAB, CSSProperty.BACKGROUND_IMAGE, STANDARD_TAB_BACKGROUND);
146         tab.setAttribute(STabbedPane.SELECTOR_SELECTED_TAB, CSSProperty.BACKGROUND_IMAGE, SELECTED_TAB_BACKGROUND);
147
148         tab.add(new WingsImage(), "wingS!");
149         tab.add(new LabelExample(), "Label");
150         tab.add(new BorderExample(), "Border");
151         tab.add(new TextComponentExample(), "Text Component");
152         tab.addTab("Tree", JAVA_CUP_ICON, new TreeExample(), "Tree Tool Tip");
153         tab.add(new OptionPaneExample(), "OptionPane");
154         tab.add(new TableExample(), "Table");
155         tab.add(new ListExample(), "List");
156         tab.add(new ButtonExample(), "Button");
157         tab.add(new ToggleButtonExample(), "ToggleButton");
158         tab.add(new CheckBoxExample(), "CheckBox");
159         tab.add(new RadioButtonExample(), "RadioButton");
160         tab.add(new Faces(), "Faces");
161         tab.add(new FileChooserExample(), "FileChooser");
162         tab.add(new ScrollPaneExample(), "ScrollPane");
163         tab.add(new PageScrollerExample(), "PageScroller");
164         tab.add(new MenuExample(), "Menu");
165         tab.add(new TabbedPaneExample(), "Tabbed Pane");
166         tab.addTab("Template Layout", SMALL_COW_ICON, new TemplateExample(), "Template Layout Manager");
167         tab.add(new InteractiveTemplateExample(), "Interactive Template");
168         tab.add(new ProgressBarExample(), "ProgressBar");
169         tab.add(new MemUsageExample(), "Memory Usage");
170         tab.add(new JavaScriptListenerExample(), "Script Listener");
171         tab.add(new PopupExample(), "Popup Menu");
172         tab.add(new KeyboardBindingsExample(), "Keyboard Bindings");
173         tab.add(new DynamicLayoutExample(), "Dynamic Layouts");
174         tab.add(new BackButtonExample(),"Browser Back");
175         tab.add(new DesktopPaneExample(),"DesktopPane");
176
177         contentPane.add(tab, "WingSetApp");
178         contentPane.add(timeMeasure, "TimeLabel");
179
180         frame.show();
181
182         /* for testing purpose, to get information what events are requested
183
184         final SLabel paramLabel = new SLabel();
185         contentPane.add(paramLabel, "ParamLabel");
186
187         SessionManager.getSession().addRequestListener(new SRequestListener() {
188                 public void processRequest(SRequestEvent e) {
189                     if ( e.getType()==SRequestEvent.DISPATCH_START ) {
190                         StringBuffer label = new StringBuffer();
191
192                         HttpServletRequest req =
193                             SessionManager.getSession().getServletRequest();
194                         
195                         for (Enumeration en = req.getParameterNames(); en.hasMoreElements();) {
196                             String paramName = (String)en.nextElement();
197                             String[] value = req.getParameterValues(paramName);
198
199                             label.append(paramName).append(": ").
200                                 append(value[0]).append("<br>");
201                         }
202
203                         paramLabel.setText(label.toString());
204                     }
205                 }
206             });
207         */

208
209     }
210 }
211
212
213
Popular Tags