Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Gayed2007-08-24 17:49:21 +0000
committerGrant Gayed2007-08-24 17:49:21 +0000
commit2714d1aedfa884938b6f4895d2c057e3d1f79ae1 (patch)
treea7ad0b1d10dfa719018565f865d3793bfcf2b06e
parentdf88720ffacc1e4aedc46ad9c7993c18542607af (diff)
downloadeclipse.platform.swt-2714d1aedfa884938b6f4895d2c057e3d1f79ae1.tar.gz
eclipse.platform.swt-2714d1aedfa884938b6f4895d2c057e3d1f79ae1.tar.xz
eclipse.platform.swt-2714d1aedfa884938b6f4895d2c057e3d1f79ae1.zip
*** empty log message ***
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet277.java95
1 files changed, 58 insertions, 37 deletions
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
index c652fe361e..aa1a17c428 100644
--- 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
@@ -12,6 +12,8 @@ package org.eclipse.swt.snippets;
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;
@@ -30,13 +32,12 @@ import org.mozilla.xpcom.Mozilla;
*/
public class Snippet277 {
static Shell shell;
- static Label statusLabel;
- static Button cancelButton;
- static nsICancelable nsICancelable;
+ 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;
@@ -46,27 +47,22 @@ public class Snippet277 {
System.out.println ("Could not instantiate Browser: " + e.getMessage ());
return;
}
+ GridData data = new GridData (GridData.FILL_BOTH);
+ data.minimumHeight = 800;
+ data.minimumWidth = 800;
+ browser.setLayoutData (data);
- statusLabel = new Label (shell, SWT.WRAP | SWT.BORDER);
- cancelButton = new Button (shell, SWT.PUSH);
- cancelButton.setText ("Cancel");
- cancelButton.setEnabled (false);
- cancelButton.addListener (SWT.Selection, new Listener () {
- public void handleEvent (Event event) {
- if (nsICancelable != null) {
- nsICancelable.cancel (Mozilla.NS_ERROR_ABORT);
- nsICancelable = null;
- }
- cancelButton.setEnabled (false);
- statusLabel.setData ("");
- statusLabel.setText ("");
- }
- });
+ 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";
- final nsITransfer transfer = createTransfer ();
registrar.registerFactory (NS_DOWNLOAD_CID, "Transfer", NS_TRANSFER_CONTRACTID, new nsIFactory () {
public nsISupports queryInterface (String uuid) {
if (uuid.equals (nsIFactory.NS_IFACTORY_IID) ||
@@ -74,16 +70,13 @@ public class Snippet277 {
return null;
}
public nsISupports createInstance (nsISupports outer, String iid) {
- return transfer;
+ return createTransfer ();
}
public void lockFactory (boolean lock) {}
});
- browser.setUrl ("http://download.eclipse.org/downloads");
- shell.setBounds (10, 10, 800, 600);
- browser.setBounds (10, 10, 780, 450);
- statusLabel.setBounds (10, 470, 680, 100);
- cancelButton.setBounds (710, 470, 80, 50);
+ browser.setUrl ("http://www.eclipse.org/downloads");
+ shell.pack ();
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
@@ -103,29 +96,57 @@ public class Snippet277 {
}
public void onStateChange (nsIWebProgress webProgress, nsIRequest request, long stateFlags, long status) {
if ((stateFlags & nsIWebProgressListener.STATE_STOP) != 0) {
- nsICancelable = null;
- cancelButton.setEnabled (false);
- statusLabel.setData ("");
- statusLabel.setText ("");
+ removeFromTable ();
}
}
public void onProgressChange64 (nsIWebProgress webProgress, nsIRequest request, long curSelfProgress, long maxSelfProgress, long curTotalProgress, long maxTotalProgress) {
long currentKBytes = curTotalProgress / 1024;
long totalKBytes = maxTotalProgress / 1024;
- String string = (String)statusLabel.getData () + " (" + currentKBytes + "/" + totalKBytes + ")";
- statusLabel.setText (string);
+ 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, nsICancelable cancelable) {
- nsICancelable = cancelable;
- cancelButton.setEnabled (true);
- String string = "Downloading " + source.getSpec () + " to " + target.getSpec ();
- statusLabel.setData (string);
- statusLabel.setText (string);
+ 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 () {
+ 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 ().pack ();
}
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 ().pack ();
+ }
};
}
}

Back to the top