diff options
author | Christophe Cornu | 2004-10-15 19:34:05 +0000 |
---|---|---|
committer | Christophe Cornu | 2004-10-15 19:34:05 +0000 |
commit | 8831e7196b59c7f6a28972c9b52839a2e825cbaf (patch) | |
tree | 008bf420a40bba7a244191b87a029328269d835b /examples | |
parent | d2ddfc32951da0946164c31d7145c25600f5b599 (diff) | |
download | eclipse.platform.swt-8831e7196b59c7f6a28972c9b52839a2e825cbaf.tar.gz eclipse.platform.swt-8831e7196b59c7f6a28972c9b52839a2e825cbaf.tar.xz eclipse.platform.swt-8831e7196b59c7f6a28972c9b52839a2e825cbaf.zip |
*** empty log message ***
Diffstat (limited to 'examples')
-rw-r--r-- | examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet161.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet161.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet161.java new file mode 100644 index 0000000000..8076826357 --- /dev/null +++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet161.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.swt.snippets; + +/* + * Browser example snippet: Modify DOM (executing javascript) + * + * For a list of all SWT example snippets see + * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets + */ +import org.eclipse.swt.*; +import org.eclipse.swt.browser.*; +import org.eclipse.swt.layout.*; +import org.eclipse.swt.widgets.*; + +public class Snippet161 { + public static void main(String [] args) { + final String html = "<html><title>Snippet</title><body><p id='myid'>Best Friends</p><p id='myid2'>Cat and Dog</p></body></html>"; + Display display = new Display(); + final Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + final Browser browser = new Browser(shell, SWT.BORDER); + Composite comp = new Composite(shell, SWT.NONE); + comp.setLayout(new FillLayout(SWT.VERTICAL)); + final Text text = new Text(comp, SWT.MULTI); + text.setText("var newNode = document.createElement('P'); \r\n"+ + "var text = document.createTextNode('At least when I am around');\r\n"+ + "newNode.appendChild(text);\r\n"+ + "document.getElementById('myid').appendChild(newNode);\r\n"+ + "\r\n"+ + "document.bgColor=Math.round(Math.random()*0xffffff);"); + final Button button = new Button(comp, SWT.PUSH); + button.setText("Execute Script"); + button.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event event) { + browser.execute(text.getText()); + } + }); + browser.setText(html); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + display.dispose(); + } +} + + |