Package org.apache.pivot.wtk
Class ApplicationContext
- java.lang.Object
-
- org.apache.pivot.wtk.ApplicationContext
-
- All Implemented Interfaces:
java.lang.Thread.UncaughtExceptionHandler
,Application.UncaughtExceptionHandler
- Direct Known Subclasses:
BrowserApplicationContext
,DesktopApplicationContext
public abstract class ApplicationContext extends java.lang.Object implements Application.UncaughtExceptionHandler
Base class for application contexts.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ApplicationContext.DisplayHost
Native display host.static class
ApplicationContext.QueuedCallback
Class representing a queued callback.static class
ApplicationContext.ResourceCacheDictionary
Resource cache dictionary implementation.static class
ApplicationContext.ScheduledCallback
Class representing a scheduled callback.
-
Field Summary
Fields Modifier and Type Field Description protected static ArrayList<Application>
applications
protected static ArrayList<Display>
displays
protected static java.net.URL
origin
-
Constructor Summary
Constructors Constructor Description ApplicationContext()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
applyStylesheet(java.lang.String resourceName)
Adds the styles from a named stylesheet to the named or typed style collections.static void
applyStylesheet(java.lang.String resourceName, boolean allowMacros)
Adds the styles from a named stylesheet to the named or typed style collections.protected static void
createTimer()
static void
defaultUncaughtExceptionHandler(java.lang.Thread thread, java.lang.Throwable exception)
protected static void
destroyTimer()
static List<Display>
getDisplays()
static Version
getJavaVersion()
Returns the current Java Runtime version, parsed from the "java.runtime.version" system property.static Version
getJVMVersion()
Returns the current JVM version, parsed from the "java.vm.version" system property.static java.net.URL
getOrigin()
Returns this application's origin (the URL of it's originating server).static Version
getPivotVersion()
Returns the current Pivot version.static ApplicationContext.ResourceCacheDictionary
getResourceCache()
static void
handleUncaughtException(java.lang.Thread thread, java.lang.Throwable exception)
static void
handleUncaughtException(java.lang.Throwable exception)
protected static void
invalidateDisplays()
static ApplicationContext.QueuedCallback
queueCallback(java.lang.Runnable callback)
Queues a task to execute after all pending events have been processed and returns without waiting for the task to complete.static ApplicationContext.QueuedCallback
queueCallback(java.lang.Runnable callback, boolean wait)
Queues a task to execute after all pending events have been processed and optionally waits for the task to complete.static ApplicationContext.ScheduledCallback
runAndScheduleRecurringCallback(java.lang.Runnable callback, long period)
Runs a task and then schedules it for repeated execution.static ApplicationContext.ScheduledCallback
runAndScheduleRecurringCallback(java.lang.Runnable callback, long delay, long period)
Runs a task once and then schedules it for repeated execution.static ApplicationContext.ScheduledCallback
scheduleCallback(java.lang.Runnable callback, long delay)
Schedules a task for one-time execution.static ApplicationContext.ScheduledCallback
scheduleRecurringCallback(java.lang.Runnable callback, long period)
Schedules a task for repeated execution.static ApplicationContext.ScheduledCallback
scheduleRecurringCallback(java.lang.Runnable callback, long delay, long period)
Schedules a task for repeated execution.void
uncaughtException(java.lang.Thread thread, java.lang.Throwable exception)
-
-
-
Field Detail
-
origin
protected static java.net.URL origin
-
applications
protected static ArrayList<Application> applications
-
-
Method Detail
-
getOrigin
public static java.net.URL getOrigin()
Returns this application's origin (the URL of it's originating server).- Returns:
- The application's origin, or
null
if the origin cannot be determined.
-
getResourceCache
public static ApplicationContext.ResourceCacheDictionary getResourceCache()
- Returns:
- The dictionary of cached resources.
-
applyStylesheet
public static void applyStylesheet(java.lang.String resourceName)
Adds the styles from a named stylesheet to the named or typed style collections.Does not allow macros (standard behavior) which can also be 25x faster than allowing macros.
- Parameters:
resourceName
- The resource name of the stylesheet to apply.
-
applyStylesheet
public static void applyStylesheet(java.lang.String resourceName, boolean allowMacros)
Adds the styles from a named stylesheet to the named or typed style collections.- Parameters:
resourceName
- The resource name of the stylesheet to apply.allowMacros
- Whether or not there will be macros in the stylesheet.
-
getJVMVersion
public static Version getJVMVersion()
Returns the current JVM version, parsed from the "java.vm.version" system property.- Returns:
- The current JVM version, or an "empty" version if it can't be determined (that is, "0.0.0_00").
-
getJavaVersion
public static Version getJavaVersion()
Returns the current Java Runtime version, parsed from the "java.runtime.version" system property.- Returns:
- The current Java version, or an "empty" version if it can't be determined (that is, "0.0.0_00").
-
getPivotVersion
public static Version getPivotVersion()
Returns the current Pivot version.- Returns:
- The current Pivot version (determined at build time), or an "empty" version if it can't be determined (that is, "0.0.0_00").
-
scheduleCallback
public static ApplicationContext.ScheduledCallback scheduleCallback(java.lang.Runnable callback, long delay)
Schedules a task for one-time execution. The task will be executed on the UI thread.- Parameters:
callback
- The task to execute.delay
- The length of time to wait before executing the task (in milliseconds).- Returns:
- The callback object.
-
scheduleRecurringCallback
public static ApplicationContext.ScheduledCallback scheduleRecurringCallback(java.lang.Runnable callback, long period)
Schedules a task for repeated execution. The task will be executed on the UI thread and will begin executing immediately.- Parameters:
callback
- The task to execute.period
- The interval at which the task will be repeated (in milliseconds).- Returns:
- The callback object.
-
scheduleRecurringCallback
public static ApplicationContext.ScheduledCallback scheduleRecurringCallback(java.lang.Runnable callback, long delay, long period)
Schedules a task for repeated execution. The task will be executed on the UI thread.- Parameters:
callback
- The task to execute.delay
- The length of time to wait before the first execution of the task (milliseconds) (can be 0).period
- The interval at which the task will be repeated (also in milliseconds).- Returns:
- The callback object.
-
runAndScheduleRecurringCallback
public static ApplicationContext.ScheduledCallback runAndScheduleRecurringCallback(java.lang.Runnable callback, long period)
Runs a task and then schedules it for repeated execution. The task will be executed on the UI thread and will begin executing immediately.- Parameters:
callback
- The task to execute.period
- The interval at which the task will be repeated (in milliseconds).- Returns:
- The callback object.
-
runAndScheduleRecurringCallback
public static ApplicationContext.ScheduledCallback runAndScheduleRecurringCallback(java.lang.Runnable callback, long delay, long period)
Runs a task once and then schedules it for repeated execution. The task will be executed on the UI thread. This is a common pattern for caret blink, scrolling, etc. to have an immediate effect, with recurring execution after that.- Parameters:
callback
- The task to execute.delay
- The length of time to wait before the next execution of the task (milliseconds).period
- The interval at which the task will be repeated (also in milliseconds).- Returns:
- The callback object.
-
queueCallback
public static ApplicationContext.QueuedCallback queueCallback(java.lang.Runnable callback)
Queues a task to execute after all pending events have been processed and returns without waiting for the task to complete.- Parameters:
callback
- The task to execute.- Returns:
- The callback object (used to manipulate or wait for the task).
-
queueCallback
public static ApplicationContext.QueuedCallback queueCallback(java.lang.Runnable callback, boolean wait)
Queues a task to execute after all pending events have been processed and optionally waits for the task to complete.- Parameters:
callback
- The task to execute.wait
- Iftrue
, does not return until the task has executed. Otherwise, returns immediately.- Returns:
- The callback object (used to manipulate or wait for the task).
-
createTimer
protected static void createTimer()
-
destroyTimer
protected static void destroyTimer()
-
invalidateDisplays
protected static void invalidateDisplays()
-
defaultUncaughtExceptionHandler
public static void defaultUncaughtExceptionHandler(java.lang.Thread thread, java.lang.Throwable exception)
-
uncaughtException
public void uncaughtException(java.lang.Thread thread, java.lang.Throwable exception)
- Specified by:
uncaughtException
in interfacejava.lang.Thread.UncaughtExceptionHandler
-
handleUncaughtException
public static void handleUncaughtException(java.lang.Throwable exception)
-
handleUncaughtException
public static void handleUncaughtException(java.lang.Thread thread, java.lang.Throwable exception)
-
-