1 2 package $packageName$; 3 4 import org.eclipse.swt.SWT; 5 import org.eclipse.swt.browser.Browser; 6 import org.eclipse.swt.browser.ProgressEvent; 7 import org.eclipse.swt.browser.ProgressListener; 8 import org.eclipse.swt.events.SelectionEvent; 9 import org.eclipse.swt.events.SelectionListener; 10 import org.eclipse.swt.layout.GridData; 11 import org.eclipse.swt.layout.GridLayout; 12 import org.eclipse.swt.widgets.Button; 13 import org.eclipse.swt.widgets.Shell; 14 import org.eclipse.ui.splash.AbstractSplashHandler; 15 16 20 public class BrowserSplashHandler extends AbstractSplashHandler { 21 22 private final static String F_BROWSER_URL = "http://www.google.com"; 24 private Browser fBrowser; 25 26 private Button fButton; 27 28 private boolean fClose; 29 30 33 public BrowserSplashHandler() { 34 fBrowser = null; 35 fButton = null; 36 fClose = false; 37 } 38 39 45 public void init(final Shell splash) { 46 super.init(splash); 48 configureUISplash(); 50 createUI(); 52 createUIListeners(); 54 splash.layout(true); 56 doEventLoop(); 59 } 60 61 64 private void doEventLoop() { 65 Shell splash = getSplash(); 66 while (fClose == false) { 67 if (splash.getDisplay().readAndDispatch() == false) { 68 splash.getDisplay().sleep(); 69 } 70 } 71 } 72 73 76 private void createUIListeners() { 77 createUIListenersBrowser(); 79 createUIListenersButton(); 81 } 82 83 86 private void createUIListenersButton() { 87 fButton.addSelectionListener(new SelectionListener() { 88 public void widgetDefaultSelected(SelectionEvent e) { 89 } 91 public void widgetSelected(SelectionEvent e) { 92 fClose = true; 93 } 94 }); 95 } 96 97 100 private void createUIListenersBrowser() { 101 fBrowser.addProgressListener(new ProgressListener() { 102 public void changed(ProgressEvent event) { 103 } 105 public void completed(ProgressEvent event) { 106 fBrowser.setVisible(true); 109 fButton.setVisible(true); 110 } 111 }); 112 } 113 114 117 private void createUI() { 118 createUIBrowser(); 120 createUIButton(); 122 } 123 124 127 private void createUIButton() { 128 Shell splash = getSplash(); 129 fButton = new Button(splash, SWT.PUSH); 130 fButton.setText("Close"); fButton.setVisible(false); 132 configureUIButtonBounds(); 134 GridData data = new GridData(SWT.CENTER, SWT.FILL, false, false); 136 data.widthHint = 80; 137 fButton.setLayoutData(data); 138 } 139 140 143 private void configureUIButtonBounds() { 144 Shell splash = getSplash(); 145 146 int button_x_coord = (splash.getSize().x / 2) 147 - (fButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).x / 2); 148 int button_y_coord = splash.getSize().y 149 - fButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; 150 int button_x_width = splash.getSize().x; 151 int button_y_width = fButton.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; 152 153 fButton.setBounds(button_x_coord, button_y_coord, button_x_width, 154 button_y_width); 155 } 156 157 160 private void createUIBrowser() { 161 fBrowser = new Browser(getSplash(), SWT.NONE); 162 fBrowser.setUrl(F_BROWSER_URL); 163 fBrowser.setVisible(false); 164 GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); 166 fBrowser.setLayoutData(data); 167 } 168 169 172 private void configureUISplash() { 173 GridLayout layout = new GridLayout(1, true); 174 getSplash().setLayout(layout); 175 } 176 177 } 178 | Popular Tags |