1 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 ; 27 import java.io.Serializable ; 28 import java.io.File ; 29 import java.net.URL ; 30 import java.text.MessageFormat ; 31 import java.util.Timer ; 32 import java.util.TimerTask ; 33 34 38 public class WingSet implements Serializable { 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 infoWriter; 47 static final Timer timer = new Timer (); 48 static long oldRequestCount = 0; 49 static long oldSessionCount = 0; 50 51 private SFrame frame; 52 private SLabel timeMeasure; 54 private final TimeMeasure stopWatch; 55 56 static final TimerTask infoTask = new TimerTask () { 57 public void run() { 58 StringBuffer result = new StringBuffer (); 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 ex) { 83 ex.printStackTrace(); 84 } 85 } 86 }; 87 88 static { 89 if (SHOW_STATISTICS) { 90 try { 91 infoWriter = new FileWriter (File.createTempFile("wingsmemory","log"), false); 92 93 StringBuffer result = new StringBuffer (); 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 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 final Browser browser = frame.getSession().getUserAgent(); 122 String cssURL = "../wingset-gecko.css"; 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 ("<html><b>{0}</b>: {1} (<i>x {2}</i>)<br/>")); 128 timeMeasure = new SLabel(); 129 130 SContainer contentPane = frame.getContentPane(); 131 try { 132 URL 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 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 208 209 } 210 } 211 212 213 | Popular Tags |