blob: 2682f924401c48f41c0549d0fbca8a9d2bf4661a [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2002-2006 Innoopract Informationssysteme GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Innoopract Informationssysteme GmbH - initial API and implementation
******************************************************************************/
package org.eclipse.swt.browser;
import org.eclipse.swt.SWT;
import org.eclipse.swt.internal.widgets.IBrowserAdapter;
import org.eclipse.swt.widgets.Composite;
/**
* <p>Currently implemented</p>
* <ul><li>text and url property</li></ul>
* <p>The enabled property in not (yet) evaluated.</p>
* <p>Focus events are not yet implemented</p>
*/
// TODO [rh] implement refresh method
// TODO [rh] bring focus events to work
public class Browser extends Composite {
private final class BrowserAdapter implements IBrowserAdapter {
public String getText() {
return Browser.this.html;
}
}
private static final String ABOUT_BLANK = "about:blank";
private String url;
private String html;
private final IBrowserAdapter browserAdapter = new BrowserAdapter();
/**
* <p>The <code>style</code> flag is not yet evaluated.</p>
*/
public Browser( final Composite composite, final int style ) {
super( composite, style );
}
public boolean setUrl( final String url ) {
checkWidget();
if( url == null ) {
SWT.error( SWT.ERROR_NULL_ARGUMENT );
}
LocationEvent event;
event = new LocationEvent( this, LocationEvent.CHANGING, url );
event.processEvent();
boolean result = event.doit;
if( result ) {
this.url = url;
html = null;
event = new LocationEvent( this, LocationEvent.CHANGED, url );
event.processEvent();
}
return result;
}
public String getUrl() {
checkWidget();
return url;
}
public boolean setText( final String html ) {
checkWidget();
if( html == null ) {
SWT.error( SWT.ERROR_NULL_ARGUMENT );
}
LocationEvent event;
event = new LocationEvent( this, LocationEvent.CHANGING, ABOUT_BLANK );
event.processEvent();
boolean result = event.doit;
if( result ) {
this.html = html;
url = null;
event = new LocationEvent( this, LocationEvent.CHANGED, ABOUT_BLANK );
event.processEvent();
}
return result;
}
public void addLocationListener( final LocationListener listener ) {
LocationEvent.addListener( this, listener );
}
public void removeLocationListener( final LocationListener listener ) {
LocationEvent.removeListener( this, listener );
}
public Object getAdapter( final Class adapter ) {
Object result;
if( IBrowserAdapter.class.equals( adapter ) ) {
result = browserAdapter;
} else {
result = super.getAdapter( adapter );
}
return result;
}
}