Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/org.eclipse.swt.snippets/.classpath_cocoa2
-rw-r--r--examples/org.eclipse.swt.snippets/.classpath_gtk2
-rw-r--r--examples/org.eclipse.swt.snippets/.classpath_win322
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet267.java92
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet277.java154
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet306.java81
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet321.java103
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet323.java226
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet329.java91
9 files changed, 3 insertions, 750 deletions
diff --git a/examples/org.eclipse.swt.snippets/.classpath_cocoa b/examples/org.eclipse.swt.snippets/.classpath_cocoa
index 27f2f18c2c..0e42ac5abe 100644
--- a/examples/org.eclipse.swt.snippets/.classpath_cocoa
+++ b/examples/org.eclipse.swt.snippets/.classpath_cocoa
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry excluding="org/eclipse/swt/snippets/Snippet123.java|org/eclipse/swt/snippets/Snippet157.java|org/eclipse/swt/snippets/Snippet174.java|org/eclipse/swt/snippets/Snippet186.java|org/eclipse/swt/snippets/Snippet187.java|org/eclipse/swt/snippets/Snippet195.java|org/eclipse/swt/snippets/Snippet199.java|org/eclipse/swt/snippets/Snippet209.java|org/eclipse/swt/snippets/Snippet261.java|org/eclipse/swt/snippets/Snippet262.java|org/eclipse/swt/snippets/Snippet263.java|org/eclipse/swt/snippets/Snippet264.java|org/eclipse/swt/snippets/Snippet265.java|org/eclipse/swt/snippets/Snippet267.java|org/eclipse/swt/snippets/Snippet277.java|org/eclipse/swt/snippets/Snippet305.java|org/eclipse/swt/snippets/Snippet306.java|org/eclipse/swt/snippets/Snippet321.java|org/eclipse/swt/snippets/Snippet323.java|org/eclipse/swt/snippets/Snippet329.java|org/eclipse/swt/snippets/Snippet341.java|org/eclipse/swt/snippets/Snippet81.java|org/eclipse/swt/snippets/Snippet83.java" kind="src" path="src"/>
+ <classpathentry excluding="org/eclipse/swt/snippets/Snippet123.java|org/eclipse/swt/snippets/Snippet157.java|org/eclipse/swt/snippets/Snippet174.java|org/eclipse/swt/snippets/Snippet186.java|org/eclipse/swt/snippets/Snippet187.java|org/eclipse/swt/snippets/Snippet195.java|org/eclipse/swt/snippets/Snippet199.java|org/eclipse/swt/snippets/Snippet209.java|org/eclipse/swt/snippets/Snippet261.java|org/eclipse/swt/snippets/Snippet262.java|org/eclipse/swt/snippets/Snippet263.java|org/eclipse/swt/snippets/Snippet264.java|org/eclipse/swt/snippets/Snippet265.java|org/eclipse/swt/snippets/Snippet305.java|org/eclipse/swt/snippets/Snippet341.java|org/eclipse/swt/snippets/Snippet81.java|org/eclipse/swt/snippets/Snippet83.java" kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/examples/org.eclipse.swt.snippets/.classpath_gtk b/examples/org.eclipse.swt.snippets/.classpath_gtk
index 27f2f18c2c..0e42ac5abe 100644
--- a/examples/org.eclipse.swt.snippets/.classpath_gtk
+++ b/examples/org.eclipse.swt.snippets/.classpath_gtk
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry excluding="org/eclipse/swt/snippets/Snippet123.java|org/eclipse/swt/snippets/Snippet157.java|org/eclipse/swt/snippets/Snippet174.java|org/eclipse/swt/snippets/Snippet186.java|org/eclipse/swt/snippets/Snippet187.java|org/eclipse/swt/snippets/Snippet195.java|org/eclipse/swt/snippets/Snippet199.java|org/eclipse/swt/snippets/Snippet209.java|org/eclipse/swt/snippets/Snippet261.java|org/eclipse/swt/snippets/Snippet262.java|org/eclipse/swt/snippets/Snippet263.java|org/eclipse/swt/snippets/Snippet264.java|org/eclipse/swt/snippets/Snippet265.java|org/eclipse/swt/snippets/Snippet267.java|org/eclipse/swt/snippets/Snippet277.java|org/eclipse/swt/snippets/Snippet305.java|org/eclipse/swt/snippets/Snippet306.java|org/eclipse/swt/snippets/Snippet321.java|org/eclipse/swt/snippets/Snippet323.java|org/eclipse/swt/snippets/Snippet329.java|org/eclipse/swt/snippets/Snippet341.java|org/eclipse/swt/snippets/Snippet81.java|org/eclipse/swt/snippets/Snippet83.java" kind="src" path="src"/>
+ <classpathentry excluding="org/eclipse/swt/snippets/Snippet123.java|org/eclipse/swt/snippets/Snippet157.java|org/eclipse/swt/snippets/Snippet174.java|org/eclipse/swt/snippets/Snippet186.java|org/eclipse/swt/snippets/Snippet187.java|org/eclipse/swt/snippets/Snippet195.java|org/eclipse/swt/snippets/Snippet199.java|org/eclipse/swt/snippets/Snippet209.java|org/eclipse/swt/snippets/Snippet261.java|org/eclipse/swt/snippets/Snippet262.java|org/eclipse/swt/snippets/Snippet263.java|org/eclipse/swt/snippets/Snippet264.java|org/eclipse/swt/snippets/Snippet265.java|org/eclipse/swt/snippets/Snippet305.java|org/eclipse/swt/snippets/Snippet341.java|org/eclipse/swt/snippets/Snippet81.java|org/eclipse/swt/snippets/Snippet83.java" kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/examples/org.eclipse.swt.snippets/.classpath_win32 b/examples/org.eclipse.swt.snippets/.classpath_win32
index 19e9a89de1..ecdf7f80b6 100644
--- a/examples/org.eclipse.swt.snippets/.classpath_win32
+++ b/examples/org.eclipse.swt.snippets/.classpath_win32
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry excluding="org/eclipse/swt/snippets/Snippet174.java|org/eclipse/swt/snippets/Snippet195.java|org/eclipse/swt/snippets/Snippet209.java|org/eclipse/swt/snippets/Snippet267.java|org/eclipse/swt/snippets/Snippet277.java|org/eclipse/swt/snippets/Snippet306.java|org/eclipse/swt/snippets/Snippet321.java|org/eclipse/swt/snippets/Snippet323.java|org/eclipse/swt/snippets/Snippet329.java|org/eclipse/swt/snippets/Snippet341.java" kind="src" path="src"/>
+ <classpathentry excluding="org/eclipse/swt/snippets/Snippet174.java|org/eclipse/swt/snippets/Snippet195.java|org/eclipse/swt/snippets/Snippet209.java|org/eclipse/swt/snippets/Snippet341.java" kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet267.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet267.java
deleted file mode 100644
index 70a06e726a..0000000000
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet267.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2013 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.snippets;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTError;
-import org.eclipse.swt.browser.Browser;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-import org.mozilla.interfaces.*;
-
-/*
- * Browser example snippet: Toggle a Mozilla Browser between Design mode and View mode.
- *
- * IMPORTANT: For this snippet to work properly all of the requirements
- * for using JavaXPCOM in a stand-alone application must be satisfied
- * (see http://www.eclipse.org/swt/faq.php#howusejavaxpcom).
- *
- * For a list of all SWT example snippets see
- * http://www.eclipse.org/swt/snippets/
- *
- * @since 3.3
- */
-public class Snippet267 {
- static Browser browser;
- public static void main (String [] args) {
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new GridLayout(2, true));
- shell.setText("Use Mozilla's Design Mode");
- try {
- browser = new Browser(shell, SWT.MOZILLA);
- } catch (SWTError e) {
- System.out.println("Could not instantiate Browser: " + e.getMessage());
- display.dispose();
- return;
- }
- browser.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1));
-
- final Button offButton = new Button(shell, SWT.RADIO);
- offButton.setText("Design Mode Off");
- offButton.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
- if (!offButton.getSelection()) return;
- setDesignMode("off");
- }
- });
- final Button onButton = new Button(shell, SWT.RADIO);
- onButton.setText("Design Mode On");
- onButton.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
- if (!onButton.getSelection()) return;
- boolean success = setDesignMode("on");
- if (!success) {
- onButton.setSelection(false);
- offButton.setSelection(true);
- }
- }
- });
- offButton.setSelection(true);
-
- browser.setUrl("http://www.google.com");
- shell.setSize(400,400);
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) display.sleep();
- }
- display.dispose();
- }
- public static boolean setDesignMode(String value) {
- nsIWebBrowser webBrowser = (nsIWebBrowser)browser.getWebBrowser();
- if (webBrowser == null) {
- System.out.println("Could not get the nsIWebBrowser from the Browser widget");
- return false;
- }
- nsIDOMWindow window = webBrowser.getContentDOMWindow();
- nsIDOMDocument document = window.getDocument();
- nsIDOMNSHTMLDocument nsDocument = (nsIDOMNSHTMLDocument)document.queryInterface(nsIDOMNSHTMLDocument.NS_IDOMNSHTMLDOCUMENT_IID);
- nsDocument.setDesignMode(value);
- return true;
- }
-}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet277.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet277.java
deleted file mode 100644
index 45b9b7ebff..0000000000
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet277.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2013 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.snippets;
-
-/*
- * Browser example snippet: Implement a custom download handler for a Mozilla Browser.
- *
- * IMPORTANT: For this snippet to work properly all of the requirements
- * for using JavaXPCOM in a stand-alone application must be satisfied
- * (see http://www.eclipse.org/swt/faq.php#howusejavaxpcom).
- *
- * For a list of all SWT example snippets see
- * http://www.eclipse.org/swt/snippets/
- *
- * @since 3.3
- */
-import org.eclipse.swt.*;
-import org.eclipse.swt.browser.*;
-import org.eclipse.swt.custom.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-import org.mozilla.interfaces.*;
-import org.mozilla.xpcom.Mozilla;
-
-public class Snippet277 {
- static Shell shell;
- static Table table;
-
- public static void main (String [] args) {
- Display display = new Display ();
- shell = new Shell (display);
- shell.setLayout(new GridLayout ());
- shell.setText ("Custom Download Handler");
-
- Browser browser;
- try {
- browser = new Browser (shell, SWT.MOZILLA);
- } catch (SWTError e) {
- System.out.println ("Could not instantiate Browser: " + e.getMessage ());
- display.dispose();
- return;
- }
- GridData data = new GridData (GridData.FILL_BOTH);
- data.minimumHeight = 800;
- data.minimumWidth = 800;
- browser.setLayoutData (data);
-
- table = new Table (shell, SWT.NONE);
- table.setForeground (display.getSystemColor (SWT.COLOR_RED));
- data = new GridData (GridData.FILL_HORIZONTAL);
- data.exclude = true;
- table.setLayoutData (data);
- new TableColumn (table, SWT.NONE);
- new TableColumn (table, SWT.NONE);
-
- nsIComponentRegistrar registrar = Mozilla.getInstance ().getComponentRegistrar ();
- String NS_DOWNLOAD_CID = "e3fa9D0a-1dd1-11b2-bdef-8c720b597445";
- String NS_TRANSFER_CONTRACTID = "@mozilla.org/transfer;1";
- registrar.registerFactory (NS_DOWNLOAD_CID, "Transfer", NS_TRANSFER_CONTRACTID, new nsIFactory () {
- public nsISupports queryInterface (String uuid) {
- if (uuid.equals (nsIFactory.NS_IFACTORY_IID) ||
- uuid.equals (nsIFactory.NS_ISUPPORTS_IID)) return this;
- return null;
- }
- public nsISupports createInstance (nsISupports outer, String iid) {
- return createTransfer ();
- }
- public void lockFactory (boolean lock) {}
- });
-
- browser.setUrl ("http://www.eclipse.org/downloads");
- shell.pack ();
- shell.open ();
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
- display.dispose ();
- }
-
- static nsITransfer createTransfer () {
- /* nsITransfer is documented at http://www.xulplanet.com/references/xpcomref/ifaces/nsITransfer.html */
- return new nsITransfer () {
- public nsISupports queryInterface (String uuid) {
- if (uuid.equals (nsITransfer.NS_ITRANSFER_IID) ||
- uuid.equals (nsITransfer.NS_IWEBPROGRESSLISTENER2_IID) ||
- uuid.equals (nsITransfer.NS_IWEBPROGRESSLISTENER_IID) ||
- uuid.equals (nsITransfer.NS_ISUPPORTS_IID)) return this;
- return null;
- }
- public void onStateChange (nsIWebProgress webProgress, nsIRequest request, long stateFlags, long status) {
- if ((stateFlags & nsIWebProgressListener.STATE_STOP) != 0) {
- removeFromTable ();
- }
- }
- public void onProgressChange64 (nsIWebProgress webProgress, nsIRequest request, long curSelfProgress, long maxSelfProgress, long curTotalProgress, long maxTotalProgress) {
- long currentKBytes = curTotalProgress / 1024;
- long totalKBytes = maxTotalProgress / 1024;
- tableItem.setText (1, baseString + " (" + currentKBytes + "/" + totalKBytes + ")");
- table.getColumn (1).pack ();
- }
- public void init (nsIURI source, nsIURI target, String displayName, nsIMIMEInfo MIMEInfo, double startTime, nsILocalFile tempFile, final nsICancelable cancelable) {
- tableItem = new TableItem (table, SWT.NONE);
- button = new Button (table, SWT.PUSH);
- button.setText ("Cancel");
- button.pack ();
- button.addListener (SWT.Selection, new Listener () {
- @Override
- public void handleEvent (Event event) {
- cancelable.cancel (Mozilla.NS_ERROR_ABORT);
- removeFromTable ();
- }
- });
- TableEditor editor = new TableEditor (table);
- editor.setEditor (button, tableItem, 0);
- editor.minimumWidth = button.computeSize (SWT.DEFAULT, SWT.DEFAULT).x;
- baseString = "Downloading to " + target.getPath ();
- tableItem.setText (1, baseString);
- if (table.getItemCount () == 1) {
- ((GridData)table.getLayoutData ()).exclude = false; /* show the table */
- table.getColumn (0).setWidth (editor.minimumWidth);
- }
- table.getColumn (1).pack ();
- table.getShell ().layout ();
- }
- public void onStatusChange (nsIWebProgress webProgress, nsIRequest request, long status, String message) {}
- public void onSecurityChange (nsIWebProgress webProgress, nsIRequest request, long state) {}
- public void onProgressChange (nsIWebProgress webProgress, nsIRequest request, int curSelfProgress, int maxSelfProgress, int curTotalProgress, int maxTotalProgress) {}
- public void onLocationChange (nsIWebProgress webProgress, nsIRequest request, nsIURI location) {}
-
- /* the following are not part of the nsITransfer interface but are here for the snippet's convenience */
- Button button;
- TableItem tableItem;
- String baseString;
-
- void removeFromTable () {
- tableItem.dispose ();
- button.dispose ();
- if (table.getItemCount () == 0) {
- ((GridData)table.getLayoutData ()).exclude = true; /* hide the table */
- }
- table.getColumn (1).pack ();
- table.getShell ().layout ();
- }
- };
- }
-}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet306.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet306.java
deleted file mode 100644
index 326a9da583..0000000000
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet306.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.snippets;
-
-/*
- * Browser example snippet: Show an HTML element-specific context menu
- * in a Mozilla Browser.
- *
- * IMPORTANT: For this snippet to work properly all of the requirements
- * for using JavaXPCOM in a stand-alone application must be satisfied
- * (see http://www.eclipse.org/swt/faq.php#howusejavaxpcom).
- *
- * For a list of all SWT example snippets see
- * http://www.eclipse.org/swt/snippets/
- *
- * @since 3.3
- */
-import org.eclipse.swt.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.browser.*;
-import org.mozilla.interfaces.*;
-
-public class Snippet306 {
-
-public static void main (String [] args) {
- Display display = new Display ();
- final Shell shell = new Shell (display);
- shell.setLayout (new FillLayout ());
- final Browser browser;
- try {
- browser = new Browser (shell, SWT.MOZILLA);
- } catch (SWTError e) {
- System.out.println ("Could not instantiate Browser: " + e.getMessage ());
- display.dispose();
- return;
- }
- browser.addProgressListener (new ProgressAdapter () {
- @Override
- public void completed (ProgressEvent event) {
- nsIWebBrowser webBrowser = (nsIWebBrowser)browser.getWebBrowser ();
- nsIDOMWindow domWindow = webBrowser.getContentDOMWindow ();
- nsIDOMEventTarget target = (nsIDOMEventTarget)domWindow.queryInterface (nsIDOMEventTarget.NS_IDOMEVENTTARGET_IID);
- nsIDOMEventListener listener = new nsIDOMEventListener () {
- public nsISupports queryInterface (String uuid) {
- if (uuid.equals (nsIDOMEventListener.NS_IDOMEVENTLISTENER_IID) ||
- uuid.equals (nsIDOMEventListener.NS_ISUPPORTS_IID)) {
- return this;
- }
- return null;
- }
- public void handleEvent (nsIDOMEvent event) {
- nsIDOMElement element = (nsIDOMElement)event.getTarget ().queryInterface (nsIDOMElement.NS_IDOMELEMENT_IID);
- Menu menu = new Menu (browser);
- MenuItem item = new MenuItem (menu, SWT.NONE);
- item.setText ("custom menu for element with tag: " + element.getTagName ());
- nsIDOMMouseEvent mouseEvent = (nsIDOMMouseEvent)event.queryInterface (nsIDOMMouseEvent.NS_IDOMMOUSEEVENT_IID);
- menu.setLocation (mouseEvent.getScreenX (), mouseEvent.getScreenY ());
- menu.setVisible (true);
- }
- };
- target.addEventListener ("contextmenu", listener, false);
- }
- });
- shell.open ();
- browser.setUrl ("http://www.eclipse.org");
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
- display.dispose ();
-}
-
-}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet321.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet321.java
deleted file mode 100644
index 5be5d4cd88..0000000000
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet321.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.snippets;
-
-/*
- * Browser example snippet: Examine request and response headers in a Mozilla Browser
- *
- * IMPORTANT: For this snippet to work properly all of the requirements
- * for using JavaXPCOM in a stand-alone application must be satisfied
- * (see http://www.eclipse.org/swt/faq.php#howusejavaxpcom).
- *
- * For a list of all SWT example snippets see
- * http://www.eclipse.org/swt/snippets/
- *
- * @since 3.3
- */
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTError;
-import org.eclipse.swt.browser.Browser;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.widgets.*;
-import org.mozilla.interfaces.*;
-import org.mozilla.xpcom.Mozilla;
-
-public class Snippet321 {
-
-public static void main(String [] args) {
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setBounds(10,10,200,200);
- shell.setLayout(new FillLayout());
- Browser browser;
- try {
- browser = new Browser(shell, SWT.MOZILLA);
- } catch (SWTError e) {
- System.out.println("Could not instantiate Browser: " + e.getMessage());
- display.dispose();
- return;
- }
-
- nsIObserver observer = new nsIObserver() {
- public nsISupports queryInterface(String aIID) {
- if (aIID.equals(nsIObserver.NS_IOBSERVER_IID) || aIID.equals(nsIObserver.NS_ISUPPORTS_IID)) {
- return this;
- }
- return null;
- }
- public void observe(nsISupports subject, String topic, String data) {
- nsIHttpChannel channel = (nsIHttpChannel)subject.queryInterface(nsIHttpChannel.NS_IHTTPCHANNEL_IID);
- nsIRequest request = (nsIRequest)subject.queryInterface(nsIRequest.NS_IREQUEST_IID);
- if (topic.equals("http-on-modify-request")) {
- System.out.println("---------------------\nSome Request Header Values for " + request.getName() + ':');
- printRequestHeader(channel, "accept");
- printRequestHeader(channel, "accept-language");
- printRequestHeader(channel, "host");
- printRequestHeader(channel, "user-agent");
- } else {
- /* http-on-examine-response */
- System.out.println("---------------------\n\tSome Response Header Values for " + request.getName() + ':');
- printResponseHeader(channel, "content-length");
- printResponseHeader(channel, "content-type");
- printResponseHeader(channel, "expires");
- printResponseHeader(channel, "server");
- }
- }
- void printRequestHeader(nsIHttpChannel channel, String header) {
- try {
- System.out.println(header + '=' + channel.getRequestHeader(header));
- } catch (Exception e) {
- // the header did not exist, just continue
- }
- }
- void printResponseHeader(nsIHttpChannel channel, String header) {
- try {
- System.out.println('\t' + header + '=' + channel.getResponseHeader(header));
- } catch (Exception e) {
- // the header did not exist, just continue
- }
- }
- };
- nsIObserverService observerService = (nsIObserverService)Mozilla.getInstance().getServiceManager().getServiceByContractID(
- "@mozilla.org/observer-service;1", nsIObserverService.NS_IOBSERVERSERVICE_IID);
- observerService.addObserver(observer, "http-on-modify-request", false);
- observerService.addObserver(observer, "http-on-examine-response", false);
-
- browser.setUrl("http://www.eclipse.org");
- shell.open();
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) display.sleep();
- }
- display.dispose();
-}
-
-}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet323.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet323.java
deleted file mode 100644
index 629d4f74cf..0000000000
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet323.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.snippets;
-
-/*
- * Browser example snippet: View DOM tree and edit node values in a Mozilla Browser
- *
- * IMPORTANT: For this snippet to work properly all of the requirements
- * for using JavaXPCOM in a stand-alone application must be satisfied
- * (see http://www.eclipse.org/swt/faq.php#howusejavaxpcom).
- *
- * For a list of all SWT example snippets see
- * http://www.eclipse.org/swt/snippets/
- *
- * @since 3.3
- */
-import static org.eclipse.swt.events.SelectionListener.*;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.browser.*;
-import org.eclipse.swt.custom.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-import org.mozilla.interfaces.*;
-
-public class Snippet323 {
-
-public static void main (String[] args) {
- new Snippet323 ().run ();
-}
-
-void run () {
- final Display display = new Display ();
- final Shell shell = new Shell (display);
- shell.setBounds (10,10,500,500);
- shell.setLayout (new FillLayout ());
- final Browser browser = new Browser (shell, SWT.MOZILLA);
- browser.setUrl ("http://www.google.com");
- browser.addProgressListener (new ProgressAdapter () {
- @Override
- public void completed (ProgressEvent event) {
- nsIWebBrowser webBrowser = (nsIWebBrowser)browser.getWebBrowser ();
- nsIDOMWindow domWindow = webBrowser.getContentDOMWindow ();
- nsIDOMDocument document = domWindow.getDocument ();
- nsIDOMElement documentElement = document.getDocumentElement ();
- DOMEditor domEditor = new DOMEditor (shell);
- domEditor.populate (documentElement);
- }
- });
-
- shell.open ();
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
- display.dispose ();
-}
-
-class DOMEditor {
- Tree tree;
-
- public DOMEditor (Shell parent) {
- super ();
- Shell shell = new Shell (parent, SWT.SHELL_TRIM);
- shell.setText ("DOM Editor");
- shell.setBounds (510,10,400,400);
- shell.setLayout (new FillLayout ());
-
- tree = new Tree (shell, SWT.NONE);
- shell.open ();
- final TreeItem[] lastItem = new TreeItem[1];
- final TreeEditor editor = new TreeEditor (tree);
- tree.addSelectionListener (widgetDefaultSelectedAdapter(e -> {
- final TreeItem item = (TreeItem)e.item;
- final nsIDOMNode node = (nsIDOMNode)item.getData ();
- if (node == null) return; /* not editable */
- if (item != null && item == lastItem[0]) {
- final Composite composite = new Composite (tree, SWT.NONE);
- final Text text = new Text (composite, SWT.NONE);
- final int inset = 1;
- composite.addListener (SWT.Resize, e -> {
- Rectangle rect = composite.getClientArea ();
- text.setBounds (rect.x + inset, rect.y + inset, rect.width - inset * 2, rect.height - inset * 2);
- });
- Listener textListener = new Listener () {
- @Override
- public void handleEvent (final Event e) {
- switch (e.type) {
- case SWT.FocusOut:
- String string = text.getText ();
- node.setNodeValue (string);
- item.setText ("Node Value: " + node.getNodeValue ());
- composite.dispose ();
- break;
- case SWT.Verify:
- String newText = text.getText ();
- String leftText = newText.substring (0, e.start);
- String rightText = newText.substring (e.end, newText.length ());
- GC gc = new GC (text);
- Point size = gc.textExtent (leftText + e.text + rightText);
- gc.dispose ();
- size = text.computeSize (size.x, SWT.DEFAULT);
- editor.horizontalAlignment = SWT.LEFT;
- Rectangle itemRect = item.getBounds (), rect = tree.getClientArea ();
- editor.minimumWidth = Math.max (size.x, itemRect.width) + inset * 2;
- int left = itemRect.x, right = rect.x + rect.width;
- editor.minimumWidth = Math.min (editor.minimumWidth, right - left);
- editor.minimumHeight = size.y + inset * 2;
- editor.layout ();
- break;
- case SWT.Traverse:
- switch (e.detail) {
- case SWT.TRAVERSE_RETURN:
- string = text.getText ();
- node.setNodeValue (string);
- item.setText ("Node Value: " + node.getNodeValue ());
- //FALL THROUGH
- case SWT.TRAVERSE_ESCAPE:
- composite.dispose ();
- e.doit = false;
- }
- break;
- }
- }
- };
- text.addListener (SWT.FocusOut, textListener);
- text.addListener (SWT.Traverse, textListener);
- text.addListener (SWT.Verify, textListener);
- editor.setEditor (composite, item);
- String nodeValue = node.getNodeValue ();
- text.setText (nodeValue == null ? "null" : nodeValue);
- text.selectAll ();
- text.setFocus ();
- }
- lastItem [0] = item;
- }));
- }
-
- public void populate (nsIDOMElement element) {
- tree.removeAll ();
- TreeItem root = new TreeItem (tree, SWT.NONE);
- root.setText ("Root: " + element.getTagName ());
- populate (root, element);
- }
-
- void populate (TreeItem parentItem, nsIDOMNode node) {
- String nodeName = node.getNodeName ();
- if (nodeName.length () > 0) {
- new TreeItem (parentItem, SWT.NONE).setText ("Node Name: " + nodeName);
- }
- String localName = node.getLocalName ();
- if (localName != null && localName.length () > 0) {
- new TreeItem (parentItem, SWT.NONE).setText ("Local Name: " + localName);
- }
-
- TreeItem valueItem = new TreeItem (parentItem, SWT.NONE);
- String nodeValue = node.getNodeValue ();
- valueItem.setText ("Node Value: " + nodeValue);
- if (node != null) {
- valueItem.setData (node);
- Color red = parentItem.getDisplay ().getSystemColor (SWT.COLOR_RED);
- valueItem.setForeground (red);
- }
-
- String prefix = node.getPrefix ();
- if (prefix != null && prefix.length () > 0) {
- new TreeItem (parentItem, SWT.NONE).setText ("Prefix: " + prefix);
- }
- String namespaceURI = node.getNamespaceURI ();
- if (namespaceURI != null && namespaceURI.length () > 0) {
- new TreeItem (parentItem, SWT.NONE).setText ("Namespace URI: " + namespaceURI);
- }
-
- nsIDOMNamedNodeMap attributes = node.getAttributes ();
- if (attributes != null) {
- int count = (int)attributes.getLength ();
- if (count > 0) {
- for (int i = 0; i < count; i++) {
- TreeItem attributeItem = new TreeItem (parentItem, SWT.NONE);
- nsIDOMNode child = attributes.item (i);
- attributeItem.setText ("Attribute " + i + " (" + child.getNodeName () + ")");
- populate (attributeItem, child);
- }
- }
- }
- String typeString;
- switch (node.getNodeType ()) {
- case 1: typeString = "ELEMENT_NODE"; break;
- case 2: typeString = "ATTRIBUTE_NODE"; break;
- case 3: typeString = "TEXT_NODE"; break;
- case 4: typeString = "CDATA_SECTION_NODE"; break;
- case 5: typeString = "ENTITY_REFERENCE_NODE"; break;
- case 6: typeString = "ENTITY_NODE"; break;
- case 7: typeString = "PROCESSING_INSTRUCTION_NODE"; break;
- case 8: typeString = "COMMENT_NODE"; break;
- case 9: typeString = "DOCUMENT_NODE"; break;
- case 10: typeString = "DOCUMENT_TYPE_NODE"; break;
- case 11: typeString = "DOCUMENT_FRAGMENT_NODE"; break;
- case 12: typeString = "NOTATION_NODE"; break;
- default: typeString = "unknown?!?";
- }
- new TreeItem (parentItem, SWT.NONE).setText ("Type: " + typeString);
-
- nsIDOMNodeList children = node.getChildNodes ();
- int count = (int)children.getLength ();
- if (count > 0) {
- for (int i = 0; i < count; i++) {
- TreeItem childItem = new TreeItem (parentItem, SWT.NONE);
- nsIDOMNode child = children.item (i);
- childItem.setText ("Child " + i + " (" + child.getNodeName () + ")");
- populate (childItem, child);
- }
- }
- }
-}
-
-}
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet329.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet329.java
deleted file mode 100644
index 3fd275c9c8..0000000000
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet329.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.snippets;
-
-/*
- * Browser example snippet: Zoom HTML page content in a Mozilla Browser
- * (note that XULRunner 1.9 or newer is required).
- *
- * IMPORTANT: For this snippet to work properly all of the requirements
- * for using JavaXPCOM in a stand-alone application must be satisfied
- * (see http://www.eclipse.org/swt/faq.php#howusejavaxpcom).
- *
- * For a list of all SWT example snippets see
- * http://www.eclipse.org/swt/snippets/
- *
- * @since 3.3
- */
-import org.eclipse.swt.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.browser.*;
-import org.eclipse.swt.layout.*;
-import org.mozilla.interfaces.*;
-
-public class Snippet329 {
- static int zoom = 10;
- static Browser browser;
-
-public static void main(String [] args) {
- Display display = new Display();
- Shell shell = new Shell(display);
- shell.setLayout(new GridLayout(2, true));
-
- try {
- browser = new Browser(shell, SWT.MOZILLA);
- } catch (SWTError e) {
- System.out.println("Could not instantiate Browser: " + e.getMessage());
- display.dispose();
- return;
- }
- GridData data = new GridData();
- data.heightHint = data.widthHint = 400;
- data.horizontalSpan = 2;
- browser.setLayoutData(data);
-
- Button zoomIn = new Button(shell, SWT.PUSH);
- zoomIn.setText("Zoom In");
- zoomIn.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
- setZoom(++zoom);
- }
- });
- Button zoomOut = new Button(shell, SWT.PUSH);
- zoomOut.setText("Zoom Out");
- zoomOut.addListener(SWT.Selection, new Listener() {
- @Override
- public void handleEvent(Event event) {
- if (zoom > 1) {
- setZoom(--zoom);
- }
- }
- });
-
- shell.pack();
- shell.open();
- browser.setUrl("http://www.eclipse.org");
- while (!shell.isDisposed()) {
- if (!display.readAndDispatch()) display.sleep();
- }
- display.dispose();
-}
-static void setZoom(int zoom) {
- nsIWebBrowser webBrowser = (nsIWebBrowser)browser.getWebBrowser();
- nsIInterfaceRequestor req = (nsIInterfaceRequestor)webBrowser.queryInterface(nsIInterfaceRequestor.NS_IINTERFACEREQUESTOR_IID);
- nsIDocShell docShell = (nsIDocShell)req.getInterface(nsIDocShell.NS_IDOCSHELL_IID);
- nsIContentViewer contentView = docShell.getContentViewer();
- nsIMarkupDocumentViewer docView = (nsIMarkupDocumentViewer)contentView.queryInterface(nsIMarkupDocumentViewer.NS_IMARKUPDOCUMENTVIEWER_IID);
- float value = zoom / 10f;
- System.out.println("zoom: " + value);
- docView.setFullZoom(value);
-}
-
-} \ No newline at end of file

Back to the top