23 * have any questions. |
23 * have any questions. |
24 */ |
24 */ |
25 package javax.swing.text; |
25 package javax.swing.text; |
26 |
26 |
27 import java.util.Vector; |
27 import java.util.Vector; |
28 import sun.awt.AppContext; |
|
29 |
28 |
30 /** |
29 /** |
31 * A queue of text layout tasks. |
30 * A queue of text layout tasks. |
32 * |
31 * |
33 * @author Timothy Prinzing |
32 * @author Timothy Prinzing |
34 * @see AsyncBoxView |
33 * @see AsyncBoxView |
35 * @since 1.3 |
34 * @since 1.3 |
36 */ |
35 */ |
37 public class LayoutQueue { |
36 public class LayoutQueue { |
38 |
37 |
39 private static final Object DEFAULT_QUEUE = new Object(); |
38 Vector<Runnable> tasks; |
|
39 Thread worker; |
40 |
40 |
41 private Vector<Runnable> tasks; |
41 static LayoutQueue defaultQueue; |
42 private Thread worker; |
|
43 |
42 |
44 /** |
43 /** |
45 * Construct a layout queue. |
44 * Construct a layout queue. |
46 */ |
45 */ |
47 public LayoutQueue() { |
46 public LayoutQueue() { |
50 |
49 |
51 /** |
50 /** |
52 * Fetch the default layout queue. |
51 * Fetch the default layout queue. |
53 */ |
52 */ |
54 public static LayoutQueue getDefaultQueue() { |
53 public static LayoutQueue getDefaultQueue() { |
55 AppContext ac = AppContext.getAppContext(); |
54 if (defaultQueue == null) { |
56 synchronized (DEFAULT_QUEUE) { |
55 defaultQueue = new LayoutQueue(); |
57 LayoutQueue defaultQueue = (LayoutQueue) ac.get(DEFAULT_QUEUE); |
|
58 if (defaultQueue == null) { |
|
59 defaultQueue = new LayoutQueue(); |
|
60 ac.put(DEFAULT_QUEUE, defaultQueue); |
|
61 } |
|
62 return defaultQueue; |
|
63 } |
56 } |
|
57 return defaultQueue; |
64 } |
58 } |
65 |
59 |
66 /** |
60 /** |
67 * Set the default layout queue. |
61 * Set the default layout queue. |
68 * |
62 * |
69 * @param defaultQueue the new queue. |
63 * @param q the new queue. |
70 */ |
64 */ |
71 public static void setDefaultQueue(LayoutQueue defaultQueue) { |
65 public static void setDefaultQueue(LayoutQueue q) { |
72 synchronized (DEFAULT_QUEUE) { |
66 defaultQueue = q; |
73 AppContext ac = AppContext.getAppContext(); |
|
74 if (defaultQueue == null) { |
|
75 ac.remove(DEFAULT_QUEUE); |
|
76 } else { |
|
77 ac.put(DEFAULT_QUEUE, defaultQueue); |
|
78 } |
|
79 } |
|
80 } |
67 } |
81 |
68 |
82 /** |
69 /** |
83 * Add a task that is not needed immediately because |
70 * Add a task that is not needed immediately because |
84 * the results are not believed to be visible. |
71 * the results are not believed to be visible. |