001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.ui;
016:
017: import org.eclipse.core.runtime.IProgressMonitor;
018: import org.eclipse.swt.widgets.Display;
019: import org.eclipse.swt.widgets.Widget;
020:
021: class OffThreadProgressMonitor implements IProgressMonitor {
022:
023: private IProgressMonitor monitor;
024: private Display display;
025: private Widget widget;
026:
027: public OffThreadProgressMonitor(IProgressMonitor part,
028: Display display) {
029: this .monitor = part;
030: this .display = display;
031: if (part instanceof Widget)
032: widget = (Widget) part;
033: }
034:
035: public void beginTask(final String name, final int totalWork) {
036: PlatformGIS.syncInDisplayThread(display, new Runnable() {
037: public void run() {
038:
039: monitor.beginTask(name, totalWork);
040: }
041: });
042: }
043:
044: public void done() {
045: PlatformGIS.syncInDisplayThread(display, new Runnable() {
046: public void run() {
047: monitor.done();
048: }
049: });
050: }
051:
052: public void internalWorked(final double work) {
053: PlatformGIS.syncInDisplayThread(display, new Runnable() {
054: public void run() {
055: if (widget != null && widget.isDisposed())
056: return;
057: monitor.internalWorked(work);
058: }
059: });
060: }
061:
062: public boolean isCanceled() {
063: final boolean[] cancelled = new boolean[1];
064: PlatformGIS.syncInDisplayThread(display, new Runnable() {
065: public void run() {
066: if (widget != null && widget.isDisposed())
067: return;
068: cancelled[0] = monitor.isCanceled();
069: }
070: });
071: return cancelled[0];
072: }
073:
074: public void setCanceled(final boolean value) {
075: PlatformGIS.syncInDisplayThread(display, new Runnable() {
076: public void run() {
077: if (widget != null && widget.isDisposed())
078: return;
079: monitor.setCanceled(value);
080: }
081: });
082: }
083:
084: public void setTaskName(final String name) {
085: PlatformGIS.syncInDisplayThread(display, new Runnable() {
086: public void run() {
087: if (widget != null && widget.isDisposed())
088: return;
089: monitor.setTaskName(name);
090: }
091: });
092: }
093:
094: public void subTask(final String name) {
095: PlatformGIS.syncInDisplayThread(display, new Runnable() {
096: public void run() {
097: if (widget != null && widget.isDisposed())
098: return;
099: monitor.subTask(name);
100: }
101: });
102: }
103:
104: public void worked(final int work) {
105: PlatformGIS.syncInDisplayThread(display, new Runnable() {
106: public void run() {
107: if (widget != null && widget.isDisposed())
108: return;
109: monitor.worked(work);
110: }
111: });
112: }
113:
114: }
|