KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > HelpUIEventLoop


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.ui.internal;
12 import org.eclipse.help.internal.base.*;
13 import org.eclipse.swt.widgets.*;
14 public class HelpUIEventLoop {
15     /**
16      * Indicates whether run had a chance to execute and display got created
17      */

18     private static boolean started = false;
19     /**
20      * Indicates whether it is still running
21      */

22     private static boolean running = false;
23     private static Display display;
24     /**
25      * Called by base in stand-alone help since it cannot run event loop
26      */

27     public static void run() {
28         try {
29             if (display == null)
30                 display = Display.getCurrent();
31             if (display == null)
32                 display = new Display();
33         } finally {
34             started = true;
35         }
36         try {
37             running = true;
38             while (HelpApplication.isRunning()) {
39                 try {
40                     if (!display.readAndDispatch()) {
41                         display.sleep();
42                     }
43                 } catch (Throwable JavaDoc t) {
44                     HelpBasePlugin.logError(t.getMessage(), t);
45                 }
46             }
47             display.dispose();
48             display = null;
49         } finally {
50             running = false;
51         }
52     }
53     public static void wakeup() {
54         Display d = display;
55         if (d != null)
56             try {
57                 d.wake();
58             } catch (Exception JavaDoc e) {
59             }
60     }
61     /**
62      * Blocks until the loop is started (Display created)
63      */

64     public static void waitFor() {
65         while (!started && HelpApplication.isRunning()) {
66             try {
67                 Thread.sleep(100);
68             } catch (InterruptedException JavaDoc ie) {
69             }
70         }
71     }
72     /**
73      * @return Returns if loop is running.
74      */

75     public static boolean isRunning() {
76         return running;
77     }
78 }
79
Popular Tags