01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.shell;
17:
18: import com.google.gwt.core.ext.TreeLogger;
19:
20: import org.eclipse.swt.SWT;
21: import org.eclipse.swt.browser.Browser;
22: import org.eclipse.swt.browser.LocationEvent;
23: import org.eclipse.swt.browser.LocationListener;
24: import org.eclipse.swt.browser.TitleEvent;
25: import org.eclipse.swt.browser.TitleListener;
26: import org.eclipse.swt.widgets.Composite;
27: import org.eclipse.swt.widgets.Control;
28: import org.eclipse.swt.widgets.Shell;
29:
30: import java.net.URL;
31:
32: /**
33: * A composite containing a browser widget.
34: */
35: public class BrowserDialog extends DialogBase {
36:
37: private final String html;
38:
39: private final URL url;
40:
41: private final TreeLogger logger;
42:
43: public BrowserDialog(Shell parent, TreeLogger logger, String html) {
44: super (parent, 550, 520, true, false);
45: this .logger = logger;
46: this .html = html;
47: this .url = null;
48: }
49:
50: @Override
51: protected Control createContents(Composite parent) {
52: Browser browser = new Browser(parent, SWT.BORDER);
53:
54: browser.addTitleListener(new TitleListener() {
55: public void changed(TitleEvent event) {
56: BrowserDialog.this .setText(event.title);
57: }
58: });
59:
60: if (html != null) {
61: browser.setText(html);
62: } else if (url != null) {
63: browser.setUrl(url.toString());
64: }
65:
66: browser.addLocationListener(new LocationListener() {
67: public void changed(LocationEvent event) {
68: }
69:
70: public void changing(LocationEvent event) {
71: event.doit = false;
72: BrowserWidget.launchExternalBrowser(logger,
73: event.location);
74: }
75: });
76:
77: return browser;
78: }
79: }
|