View Javadoc

1   /*
2    * Copyright 2006-2016 The JGUIraffe Team.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License")
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.jguiraffe.gui.builder.utils;
17  
18  /**
19   * <p>
20   * Definition of an interface that supports updating GUI components from
21   * different threads.
22   * </p>
23   * <p>
24   * Typical Java GUI libraries use a specific thread (e.g. event dispatch thread)
25   * that is alone responsible for updating GUI components. When working with
26   * multiple threads special care has to be taken if GUI components are to be
27   * accessed; it has to be ensured that such operations are only performed on the
28   * event dispatch thread.
29   * </p>
30   * <p>
31   * This interface provides a generic way for such updates. It defines typical
32   * operations that deal with an event dispatch thread: to invoke a code block
33   * synchronously or asynchronously on this thread. Concrete, platform specific
34   * implementations have to use the appropriate means provided by the platform
35   * they encapsulate to ensure that this code gets executed on the event dispatch
36   * thread.
37   * </p>
38   *
39   * @author Oliver Heger
40   * @version $Id: GUISynchronizer.java 205 2012-01-29 18:29:57Z oheger $
41   */
42  public interface GUISynchronizer
43  {
44      /**
45       * Invokes the given runnable object asynchronously on the event dispatch
46       * thread. This method will no block, the code of the runnable will be
47       * executed some time in the future.
48       *
49       * @param runnable the code to be executed on the event dispatch thread
50       */
51      void asyncInvoke(Runnable runnable);
52  
53      /**
54       * Invokes the given runnable object synchronously on the event dispatch
55       * thread. The calling thread will block until the runnable's execution is
56       * finished.
57       *
58       * @param runnable the code to be executed on the event dispatch thread
59       * @throws GUIRuntimeException if an error occurs
60       */
61      void syncInvoke(Runnable runnable) throws GUIRuntimeException;
62  
63      /**
64       * Returns a flag whether the current thread is the event dispatch thread.
65       *
66       * @return a flag if the current thread is the event dispatch thread
67       */
68      boolean isEventDispatchThread();
69  }