/* * Copyright (c) 2004 Christopher Lenz and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: * Christopher Lenz - initial implementation * * $Id: HTMLPreviewPage.java,v 1.1 2004-09-02 18:13:31 jsurfer Exp $ */ package net.sourceforge.phpeclipse.html.ui.internal.preview; import java.net.URL; import org.eclipse.swt.SWT; import org.eclipse.swt.browser.Browser; import org.eclipse.swt.browser.LocationAdapter; import org.eclipse.swt.browser.LocationEvent; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.ui.part.Page; import org.eclipse.ui.texteditor.IUpdate; import net.sourceforge.phpeclipse.ui.views.preview.IBrowserPreviewPage; /** * Provides a HTML preview page based on the SWT browser control. */ public class HTMLPreviewPage extends Page implements IBrowserPreviewPage, IUpdate { // Instance Variables ------------------------------------------------------ /** The browser widget. */ private Browser browser; /** The URL of the resource to preview. */ private URL location; // Constructors ------------------------------------------------------------ /** * Constructor. * * @param location the URL of the resource to preview */ public HTMLPreviewPage(URL location) { this.location = location; } // IPage Implementation ---------------------------------------------------- /* * @see org.eclipse.ui.part.IPage#createControl(Composite) */ public void createControl(Composite parent) { browser = new Browser(parent, SWT.NONE); browser.setLayout(new FillLayout()); browser.setUrl(location.toString()); browser.addLocationListener(new LocationAdapter() { public void changing(LocationEvent event) { if (event.location != null) { event.doit = false; } } }); } /* * @see org.eclipse.ui.part.IPage#getControl() */ public Control getControl() { return browser; } /* * @see org.eclipse.ui.part.IPage#setFocus() */ public void setFocus() { browser.setFocus(); } // IUpdate Implementation -------------------------------------------------- /* * @see IUpdate#update() */ public void update() { browser.refresh(); } }