1 16 package com.google.gwt.dev.util.log; 17 18 import com.google.gwt.dev.shell.LowLevel; 19 20 import org.eclipse.swt.layout.FillLayout; 21 import org.eclipse.swt.widgets.Display; 22 import org.eclipse.swt.widgets.Shell; 23 24 29 public class DetachedTreeLoggerWindow implements Runnable { 30 private static DetachedTreeLoggerWindow singleton; 31 32 42 public static synchronized DetachedTreeLoggerWindow getInstance( 43 final String caption, final int width, final int height, 44 final boolean autoScroll) { 45 if (singleton == null) { 46 singleton = new DetachedTreeLoggerWindow(caption, width, height, 47 autoScroll); 48 } 49 return singleton; 50 } 51 52 private final Shell shell; 53 private final AbstractTreeLogger logger; 54 private boolean isRunning = false; 55 56 private DetachedTreeLoggerWindow(final String caption, final int width, 57 final int height, final boolean autoScroll) { 58 59 shell = new Shell(Display.getCurrent()); 60 shell.setText(caption); 61 FillLayout fillLayout = new FillLayout(); 62 fillLayout.marginWidth = 0; 63 fillLayout.marginHeight = 0; 64 shell.setLayout(fillLayout); 65 66 final TreeLoggerWidget treeLoggerWidget = new TreeLoggerWidget(shell); 67 treeLoggerWidget.setAutoScroll(autoScroll); 68 logger = treeLoggerWidget.getLogger(); 69 70 shell.setImage(LowLevel.loadImage("gwt.ico")); 71 shell.setSize(width, height); 72 shell.open(); 73 } 74 75 public AbstractTreeLogger getLogger() { 76 return logger; 77 } 78 79 public synchronized boolean isRunning() { 80 return isRunning; 81 } 82 83 public void run() { 84 if (!maybeStart()) { 85 throw new IllegalStateException ( 86 "DetachedTreeLogger window is already running."); 87 } 88 89 final Display display = shell.getDisplay(); 90 while (!shell.isDisposed()) { 91 if (!display.readAndDispatch()) { 92 display.sleep(); 93 } 94 } 95 } 96 97 private synchronized boolean maybeStart() { 98 if (isRunning) { 99 return false; 100 } 101 isRunning = true; 102 return true; 103 } 104 } 105 | Popular Tags |