javauis/eswt_qt/com.nokia.swt.extensions/extensions/org/eclipse/swt/internal/extension/InternalUI.java
changeset 78 71ad690e91f5
parent 72 1f0034e370aa
child 80 d6dafc5d983f
equal deleted inserted replaced
72:1f0034e370aa 78:71ad690e91f5
     1 /*******************************************************************************
       
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     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  *     Nokia Corporation - initial implementation
       
    10  *******************************************************************************/
       
    11 
       
    12 package org.eclipse.swt.internal.extension;
       
    13 
       
    14 import org.eclipse.swt.internal.qt.midp.UIThreadLauncher;
       
    15 import org.eclipse.swt.widgets.Display;
       
    16 import org.eclipse.swt.widgets.Internal_PackageSupport;
       
    17 
       
    18 /**
       
    19  * A class that encapsulates services that enable the use of eSWT UI before the
       
    20  * application has initialized its UI. This is achieved by utilizing an
       
    21  * 'internal' instance of the Display class. I.e. an instance that is not
       
    22  * revealed to the application but is only used internally within the API
       
    23  * implementation.
       
    24  * 
       
    25  * The same rules apply to the internal Display instance that apply to the
       
    26  * Display normally. When the Display is created then the creating thread
       
    27  * becomes the UI thread of the process. The application needs to be able to
       
    28  * obtain control of the UI thread. The services for interfacing with the
       
    29  * application are provided by the class ApplicationUI.
       
    30  * 
       
    31  * @see ApplicationUI
       
    32  */
       
    33 public final class InternalUI {
       
    34 	/**
       
    35 	 * Obtains the platform specific UI thread where SWT UI APIs can be accessed
       
    36 	 * in and calls the provided Runnable in it. This method instantly returns
       
    37 	 * leaving two threads running concurrently: the calling thread and the UI
       
    38 	 * thread. Only one UI thread can exist per process and this method can be
       
    39 	 * called only once to obtain it. Subsequent calls will result in an
       
    40 	 * exception being thrown. This method can be called by any thread.
       
    41 	 * 
       
    42 	 * @param runnable
       
    43 	 *            A Runnable to call back in the UI thread.
       
    44 	 * @exception RuntimeException
       
    45 	 *                If starting the UI thread fails
       
    46 	 */
       
    47 	public static void startInUIThread(Runnable runnable) {
       
    48 		if(!UIThreadLauncher.startInUIThread(runnable)) {
       
    49 			throw new RuntimeException("Failed to start the UI thread");
       
    50 		}
       
    51 	}
       
    52 	
       
    53 	/**
       
    54 	 * Creates the internal instance of Display. Must be called only once.
       
    55 	 * 
       
    56 	 * This means that the native resources required by the eSWT UI will be
       
    57 	 * initialized and a Display instance is returned that can be used to access
       
    58 	 * them normally via the public eSWT APIs. 
       
    59 	 * 
       
    60 	 * @return The internal Display instance
       
    61 	 * @see getInternalDisplayInstance
       
    62 	 */
       
    63 	public synchronized static Display createInternalDisplay() {
       
    64 		if(getInternalDisplayInstance() != null) {
       
    65 			throw new RuntimeException("Display already exists");
       
    66 		}
       
    67 		return Internal_PackageSupport.internalInstance();
       
    68 	}
       
    69 	
       
    70 	/**
       
    71 	 * Returns the internal Display instance or null if it doesn't exist. 
       
    72 	 * @return The internal Display instance or null
       
    73 	 */
       
    74 	public synchronized static Display getInternalDisplayInstance() {
       
    75 		return Internal_PackageSupport.getInternalDisplayInstance();
       
    76 	}
       
    77 }