1 16 package com.google.gwt.dev.shell; 17 18 import com.google.gwt.core.ext.TreeLogger; 19 import com.google.gwt.core.ext.UnableToCompleteException; 20 import com.google.gwt.dev.GWTShell; 21 import com.google.gwt.dev.util.Util; 22 import com.google.gwt.dev.util.log.AbstractTreeLogger; 23 import com.google.gwt.dev.util.log.TreeLoggerWidget; 24 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.events.DisposeEvent; 27 import org.eclipse.swt.events.DisposeListener; 28 import org.eclipse.swt.events.SelectionAdapter; 29 import org.eclipse.swt.events.SelectionEvent; 30 import org.eclipse.swt.events.ShellEvent; 31 import org.eclipse.swt.events.ShellListener; 32 import org.eclipse.swt.graphics.Color; 33 import org.eclipse.swt.layout.FillLayout; 34 import org.eclipse.swt.layout.GridData; 35 import org.eclipse.swt.layout.GridLayout; 36 import org.eclipse.swt.widgets.Composite; 37 import org.eclipse.swt.widgets.Shell; 38 import org.eclipse.swt.widgets.ToolItem; 39 40 43 public class ShellMainWindow extends Composite implements DisposeListener, 44 ShellListener { 45 46 private class Toolbar extends HeaderBarBase { 47 48 private ToolItem about; 49 50 private ToolItem clearLog; 51 private ToolItem collapseAll; 52 private ToolItem expandAll; 53 private ToolItem newWindow; 54 55 public Toolbar(Composite parent) { 56 super(parent); 57 58 newWindow = newItem("new-window.gif", "&Hosted Browser", 59 "Opens a new hosted mode browser window for debugging"); 60 newWindow.addSelectionListener(new SelectionAdapter() { 61 public void widgetSelected(SelectionEvent event) { 62 String startupUrl = serverWindow.normalizeURL("/"); 63 try { 64 BrowserWidget bw = serverWindow.openNewBrowserWindow(); 65 bw.go(startupUrl); 66 } catch (UnableToCompleteException e) { 67 getLogger().log(TreeLogger.ERROR, 68 "Unable to open a new hosted browser window", e); 69 } 70 } 71 }); 72 73 newSeparator(); 74 75 collapseAll = newItem("collapse.gif", "&Collapse All", 76 "Collapses all log entries"); 77 collapseAll.addSelectionListener(new SelectionAdapter() { 78 public void widgetSelected(SelectionEvent e) { 79 logPane.collapseAll(); 80 } 81 }); 82 83 expandAll = newItem("expand.gif", "&Expand All", 84 "Expands all log entries"); 85 expandAll.addSelectionListener(new SelectionAdapter() { 86 public void widgetSelected(SelectionEvent e) { 87 logPane.expandAll(); 88 } 89 }); 90 91 clearLog = newItem("clear-log.gif", "Clear &Log", 92 "Removes all log entries"); 93 clearLog.addSelectionListener(new SelectionAdapter() { 94 public void widgetSelected(SelectionEvent e) { 95 logPane.removeAll(); 96 } 97 }); 98 99 newSeparator(); 100 101 about = newItem("about.gif", " &About ", "About..."); 102 about.addSelectionListener(new SelectionAdapter() { 103 public void widgetSelected(SelectionEvent e) { 104 String aboutHtml = Util.getFileFromInstallPath("about.html"); 105 if (aboutHtml != null) { 106 String serial = verify("TwysxNpVumPBvFyBoxzLy"); 107 StringBuffer sb = new StringBuffer (); 108 sb.append("<div style='overflow:hidden;width:100%;white-space:nowrap;font-size:1px'><br/><br/><br/><br/><font style='background-color:gray;color:lightgrey'>"); 109 for (int i = 0; i < 100; ++i) { 110 sb.append(serial); 111 } 112 sb.append("</font></div>"); 113 serial = sb.toString(); 114 int pos; 115 while ((pos = aboutHtml.indexOf("<hr/>")) >= 0) { 116 aboutHtml = aboutHtml.substring(0, pos) + serial 117 + aboutHtml.substring(pos + 5); 118 } 119 while ((pos = aboutHtml.indexOf("<body>")) >= 0) { 120 aboutHtml = aboutHtml.substring(0, pos) 121 + "<body oncontextmenu='return false'>" 122 + aboutHtml.substring(pos + 6); 123 } 124 } else { 125 aboutHtml = "Could not locate 'about.html' in installation directory."; 126 } 127 BrowserDialog browserDialog = new BrowserDialog(getShell(), 128 getLogger(), aboutHtml); 129 browserDialog.open(true); 130 } 131 }); 132 } 133 } 134 135 private static String verify(String hash) { 136 char[] in = hash.toCharArray(); 137 char[] ou = new char[in.length]; 138 for (int i = 0, c = 0; i < in.length; ++i) { 139 if (in[i] < 'a') { 140 c += in[i] - 'A'; 141 } else { 142 c += in[i] - 'a' - 26; 143 } 144 145 if (c == 0) { 146 ou[i] = ' '; 147 } else { 148 ou[i] = (char) ('@' + c); 149 } 150 } 151 return String.valueOf(ou); 152 } 153 154 private Color colorWhite; 155 156 private TreeLoggerWidget logPane; 157 158 private GWTShell serverWindow; 159 160 private Toolbar toolbar; 161 162 public ShellMainWindow(GWTShell serverWindow, final Shell parent, 163 int serverPort, boolean checkForUpdates) { 164 super(parent, SWT.NONE); 165 166 this.serverWindow = serverWindow; 167 168 colorWhite = new Color(null, 255, 255, 255); 169 170 addDisposeListener(this); 171 parent.addShellListener(this); 172 173 setLayout(new FillLayout()); 174 if (serverPort > 0) { 175 parent.setText("Google Web Toolkit Development Shell / Port " 176 + serverPort); 177 } else { 178 parent.setText("Google Web Toolkit Development Shell"); 179 } 180 181 GridLayout gridLayout = new GridLayout(1, true); 182 gridLayout.marginWidth = 0; 183 gridLayout.marginHeight = 0; 184 gridLayout.horizontalSpacing = 0; 185 gridLayout.verticalSpacing = 0; 186 setLayout(gridLayout); 187 188 { 191 toolbar = new Toolbar(this); 192 GridData data = new GridData(); 193 data.grabExcessHorizontalSpace = true; 194 data.horizontalAlignment = GridData.FILL; 195 toolbar.setLayoutData(data); 196 } 197 198 { 201 logPane = new TreeLoggerWidget(this); 202 GridData data = new GridData(); 203 data.grabExcessHorizontalSpace = true; 204 data.grabExcessVerticalSpace = true; 205 data.horizontalAlignment = GridData.FILL; 206 data.verticalAlignment = GridData.FILL; 207 logPane.setLayoutData(data); 208 } 209 210 if (checkForUpdates) { 212 try { 213 final CheckForUpdates updateChecker = PlatformSpecific.createUpdateChecker(); 214 if (updateChecker != null) { 215 final CheckForUpdates.UpdateAvailableCallback callback = new CheckForUpdates.UpdateAvailableCallback() { 216 public void onUpdateAvailable(final String html) { 217 parent.getDisplay().asyncExec(new Runnable () { 220 public void run() { 221 new BrowserDialog(parent, getLogger(), html).open(true); 222 } 223 224 }); 225 } 226 }; 227 228 Thread checkerThread = new Thread () { 231 public void run() { 232 updateChecker.check(callback); 233 } 234 }; 235 236 checkerThread.setDaemon(true); 237 checkerThread.start(); 238 } 239 } catch (Throwable e) { 240 } 242 } 243 } 244 245 public AbstractTreeLogger getLogger() { 246 return logPane.getLogger(); 247 } 248 249 public void shellActivated(ShellEvent e) { 250 } 251 252 public void shellClosed(ShellEvent e) { 253 if (serverWindow.hasBrowserWindowsOpen()) { 254 boolean closeWindows = true; 255 if (System.getProperty("gwt.shell.endquick") == null) { 256 closeWindows = DialogBase.confirmAction((Shell) e.widget, 257 "Closing the development shell will close " 258 + "all hosted mode browsers. Continue?", "Confirm close"); 259 } 260 261 if (closeWindows) { 262 serverWindow.closeAllBrowserWindows(); 263 e.doit = true; 264 } else { 265 e.doit = false; 266 } 267 } 268 } 269 270 public void shellDeactivated(ShellEvent e) { 271 } 272 273 public void shellDeiconified(ShellEvent e) { 274 } 275 276 public void shellIconified(ShellEvent e) { 277 } 278 279 public void widgetDisposed(DisposeEvent e) { 280 colorWhite.dispose(); 281 } 282 } 283 | Popular Tags |