KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > dev > shell > BrowserDialog


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
31
32 /**
33  * A composite containing a browser widget.
34  */

35 public class BrowserDialog extends DialogBase {
36
37   private final String JavaDoc html;
38
39   private final URL JavaDoc url;
40
41   private final TreeLogger logger;
42
43   public BrowserDialog(Shell parent, TreeLogger logger, String JavaDoc html) {
44     super(parent, 550, 520, true, false);
45     this.logger = logger;
46     this.html = html;
47     this.url = null;
48   }
49
50   protected Control createContents(Composite parent) {
51     Browser browser = new Browser(parent, SWT.BORDER);
52
53     browser.addTitleListener(new TitleListener() {
54       public void changed(TitleEvent event) {
55         BrowserDialog.this.setText(event.title);
56       }
57     });
58
59     if (html != null) {
60       browser.setText(html);
61     } else if (url != null) {
62       browser.setUrl(url.toString());
63     }
64
65     browser.addLocationListener(new LocationListener() {
66       public void changed(LocationEvent event) {
67       }
68
69       public void changing(LocationEvent event) {
70         event.doit = false;
71         BrowserWidget.launchExternalBrowser(logger, event.location);
72       }
73     });
74
75     return browser;
76   }
77 }
78
Popular Tags