public final class BrwsrCtx extends Object implements Executor
net.java.html.json.Model
and other objects
operate in. The context is usually a particular HTML page in a browser.
The context is also associated with the actual HTML technology
in the HTML page - there is likely to be different context for
knockout.js and different one
for angular. Since version 1.1
the content of contexts can be selected by registering
implementations under specific
technology identifiers and requesting them during
construction of the
context.| Modifier and Type | Field and Description |
|---|---|
static BrwsrCtx |
EMPTY
Dummy context without binding to any real browser or technology.
|
public static final BrwsrCtx EMPTY
public static BrwsrCtx findDefault(Class<?> requestor)
EMPTY context is returned. One can enter
a context by calling execute(java.lang.Runnable).requestor - the class that makes the requestpublic final void execute(Runnable exec)
Runs provided code in the context of this BrwsrCtx.
If there is an Executor registered in the context
it is used to perform the given code. While the code exec
is running the value of findDefault(java.lang.Class) returns
this. If the executor supports a single thread execution
policy, it may execute the runnable later (in such case this method
returns immediately). If the call to this method is done on the right
thread, the runnable should be executed synchronously.
Example Using a Timer
public final class Periodicaly extendsTimerTask{ private finalBrwsrCtxctx; private Periodicaly(BrwsrCtx ctx) { // remember the browser context and use it later this.ctx = ctx; } public void run() { // arrives on wrong thread, needs to be re-scheduled ctx.execute(new Runnable() { public void run() { // code that needs to run in a browser environment } }); } // called when your page is ready public static void onPageLoad(String... args) throws Exception { // the context at the time of page initialization BrwsrCtx initialCtx = BrwsrCtx.findDefault(getClass()); // the task that is associated with context Periodicaly task = new Periodicaly(initialCtx); // creates a timerTimert = newTimer("Move the box"); // run the task ever 100ms t.scheduleAtFixedRate(task, 0, 100); } }
Copyright © 2015 NetBeans. All Rights Reserved.