intial source from ttp://www.sf.net/projects/wdte
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.html.ui / src / net / sourceforge / phpeclipse / html / ui / internal / preview / HTMLPreviewPage.java
1 /*
2  * Copyright (c) 2004 Christopher Lenz and others
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     Christopher Lenz - initial implementation
10  * 
11  * $Id: HTMLPreviewPage.java,v 1.1 2004-09-02 18:13:31 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.html.ui.internal.preview;
15
16 import java.net.URL;
17
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.browser.Browser;
20 import org.eclipse.swt.browser.LocationAdapter;
21 import org.eclipse.swt.browser.LocationEvent;
22 import org.eclipse.swt.layout.FillLayout;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Control;
25 import org.eclipse.ui.part.Page;
26 import org.eclipse.ui.texteditor.IUpdate;
27
28 import net.sourceforge.phpeclipse.ui.views.preview.IBrowserPreviewPage;
29
30 /**
31  * Provides a HTML preview page based on the SWT browser control.
32  */
33 public class HTMLPreviewPage extends Page
34         implements IBrowserPreviewPage, IUpdate {
35
36         // Instance Variables ------------------------------------------------------
37
38         /** The browser widget. */
39         private Browser browser;
40
41         /** The URL of the resource to preview. */
42         private URL location;
43
44         // Constructors ------------------------------------------------------------
45
46         /**
47          * Constructor.
48          * 
49          * @param location the URL of the resource to preview
50          */
51         public HTMLPreviewPage(URL location) {
52                 this.location = location;
53         }
54
55         // IPage Implementation ----------------------------------------------------
56
57         /* 
58          * @see org.eclipse.ui.part.IPage#createControl(Composite)
59          */
60         public void createControl(Composite parent) {
61                 browser = new Browser(parent, SWT.NONE);
62                 browser.setLayout(new FillLayout());
63                 browser.setUrl(location.toString());
64                 browser.addLocationListener(new LocationAdapter() {
65                         public void changing(LocationEvent event) {
66                                 if (event.location != null) {
67                                         event.doit = false;
68                                 }
69                         }
70                 });
71         }
72
73         /* 
74          * @see org.eclipse.ui.part.IPage#getControl()
75          */
76         public Control getControl() {
77                 return browser;
78         }
79
80         /* 
81          * @see org.eclipse.ui.part.IPage#setFocus()
82          */
83         public void setFocus() {
84                 browser.setFocus();
85         }
86
87         // IUpdate Implementation --------------------------------------------------
88
89         /* 
90          * @see IUpdate#update()
91          */
92         public void update() {
93                 browser.refresh();
94         }
95
96 }