本文整理匯總了Java中org.openide.util.RequestProcessor.postRequest方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestProcessor.postRequest方法的具體用法?Java RequestProcessor.postRequest怎麽用?Java RequestProcessor.postRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openide.util.RequestProcessor
的用法示例。
在下文中一共展示了RequestProcessor.postRequest方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fireTreeAndStatus
import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
/** Fire tree and status change. */
private void fireTreeAndStatus() {
final int fireStatus = status;
final int fireOldStatus = oldStatus;
final Object fireTree = getDocumentRoot();
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("Firing tree status transition: " + oldStatus + "=>" + status); // NOI18N
RequestProcessor.postRequest( new Runnable() {
public void run() {
pchs.firePropertyChange (PROP_STATUS, fireOldStatus, fireStatus);
pchs.firePropertyChange (PROP_DOCUMENT_ROOT, null, fireTree);
}
});
}
示例2: testScheduleWhileRunning
import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
/** Ensure that it is safe to call schedule() while the task is running
* (should finish the task and run it again).
*/
public void testScheduleWhileRunning() throws Exception {
class X implements Runnable {
public synchronized void run() {
try {
if (cnt == 0) {
this.notify(); // #1
this.wait(9999); // #2
cnt++;
} else {
cnt++;
this.notify(); // #3
}
} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
public int cnt = 0;
}
X x = new X();
synchronized (x) {
RequestProcessor.Task task = RequestProcessor.postRequest(x);
x.wait(9999); // #1
assertEquals(0, x.cnt);
task.schedule(0);
x.notify(); // #2
x.wait(9999); // #3
assertEquals(2, x.cnt);
}
}
示例3: testWaitFinishedFromNotification
import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
/** Make sure it is safe to call waitFinished() on a task from within
* a task listener.
*/
public void testWaitFinishedFromNotification() throws Exception {
class X implements Runnable {
private Task task;
private int cnt;
public synchronized Task start() {
if (task == null) {
task = RequestProcessor.postRequest(this);
}
return task;
}
public void run() {
cnt++;
}
public int getCount() {
return cnt;
}
public void block() {
start().waitFinished();
}
}
final X x = new X();
final Object lock = "wait for task to finish";
final boolean[] finished = new boolean[1];
x.start().addTaskListener(new TaskListener() {
public void taskFinished(Task t) {
x.block();
finished[0] = true;
synchronized (lock) {
lock.notify();
}
}
});
synchronized (lock) {
lock.wait(5000);
}
assertTrue(finished[0]);
assertEquals(1, x.getCount());
}
示例4: testCancel
import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
/** Make sure that successfully canceled task is not performed.
*/
public void testCancel() throws Exception {
class X implements Runnable {
public boolean performed = false;
public void run() {
performed = true;
}
}
X x = new X();
final boolean[] finished = new boolean[1];
finished[0] = false;
// post task with some delay
RequestProcessor.Task task = RequestProcessor.postRequest(x, 1000);
task.addTaskListener(new TaskListener() {
@Override
public void taskFinished(Task t) {
finished[0] = true;
}
});
boolean canceled = task.cancel();
assertTrue("Task is canceled now", canceled);
assertTrue("Cancelling actually means finished", finished[0]);
Thread.sleep(1500); // wait longer than task delay
assertFalse("Task should not be performed", x.performed);
}
示例5: performAction
import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
/** Check all selected nodes. */
protected void performAction (Node[] nodes) {
if (nodes == null) return;
RequestProcessor.postRequest(
new CheckAction.RunAction (nodes));
}
示例6: testOrder
import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
/** A test to check that objects are executed in the right order.
*/
public void testOrder () throws Exception {
final int[] count = new int[1];
final String[] fail = new String[1];
class X extends Object
implements Runnable, Comparable {
public int order;
public void run () {
if (order != count[0]++) {
if (fail[0] == null) {
fail[0] = "Executing task " + order + " instead of " + count[0];
}
}
}
public int compareTo (Object o) {
X x = (X)o;
return System.identityHashCode (x) - System.identityHashCode (this);
}
@Override
public String toString () {
return "O: " + order;
}
}
// prepare the tasks
X[] arr = new X[10];
for (int i = 0; i < arr.length; i++) {
arr[i] = new X ();
}
// sort it
// Arrays.sort (arr);
for (int i = 0; i < arr.length; i++) {
arr[i].order = i;
}
// execute the task as quickly as possible (only those with the same time
// can have wrong order
RequestProcessor.Task[] wait = new RequestProcessor.Task[arr.length];
for (int i = 0; i < arr.length; i++) {
wait[i] = RequestProcessor.postRequest (arr[i]);
}
// wait to all tasks to finish
for (int i = 0; i < arr.length; i++) {
wait[i].waitFinished ();
}
if (fail[0] != null) {
fail (fail[0]);
}
}
示例7: performAction
import org.openide.util.RequestProcessor; //導入方法依賴的package包/類
/** Check all selected nodes. */
protected void performAction (Node[] nodes) {
if (nodes == null) return;
RequestProcessor.postRequest(
new CheckDTDAction.RunAction (nodes));
}