Lines 41-52
Link Here
|
41 |
|
41 |
|
42 |
package org.netbeans.editor; |
42 |
package org.netbeans.editor; |
43 |
|
43 |
|
44 |
import java.lang.ref.WeakReference; |
44 |
import java.beans.PropertyChangeEvent; |
45 |
import java.util.ArrayList; |
45 |
import java.beans.PropertyChangeListener; |
|
|
46 |
import java.lang.reflect.Method; |
46 |
import java.util.Iterator; |
47 |
import java.util.Iterator; |
|
|
48 |
import java.util.List; |
47 |
import javax.swing.text.JTextComponent; |
49 |
import javax.swing.text.JTextComponent; |
48 |
import javax.swing.event.ChangeListener; |
50 |
import javax.swing.event.ChangeListener; |
49 |
import javax.swing.event.ChangeEvent; |
51 |
import javax.swing.event.ChangeEvent; |
|
|
52 |
import javax.swing.text.Document; |
53 |
import org.netbeans.api.editor.EditorRegistry; |
54 |
import org.openide.modules.PatchedPublic; |
50 |
|
55 |
|
51 |
/** |
56 |
/** |
52 |
* All the documents and components register here so that |
57 |
* All the documents and components register here so that |
Lines 61-92
Link Here
|
61 |
*/ |
66 |
*/ |
62 |
public class Registry { |
67 |
public class Registry { |
63 |
|
68 |
|
64 |
private static final WeakReference[] EMPTY = new WeakReference[0]; |
|
|
65 |
|
66 |
/** Array of weak references to documents */ |
67 |
private static WeakReference[] docRefs = EMPTY; |
68 |
|
69 |
/** Number of the document references */ |
70 |
private static int docRefsCount; |
71 |
|
72 |
/** Array of activated document numbers */ |
73 |
private static final ArrayList docAct = new ArrayList(); |
74 |
|
75 |
/** Array list of weak references to components */ |
76 |
private static WeakReference[] compRefs = EMPTY; |
77 |
|
78 |
/** Number of the document references */ |
79 |
private static int compRefsCount; |
80 |
|
81 |
/** Array of activated component numbers */ |
82 |
private static final ArrayList<Integer> compAct = new ArrayList<Integer>(); |
83 |
|
84 |
/** List of the registered changes listeners */ |
69 |
/** List of the registered changes listeners */ |
85 |
private static final WeakEventListenerList listenerList |
70 |
private static final WeakEventListenerList listenerList |
86 |
= new WeakEventListenerList(); |
71 |
= new WeakEventListenerList(); |
|
|
72 |
|
73 |
private static PropertyChangeListener editorRegistryListener = null; |
87 |
|
74 |
|
88 |
private static int consolidateCounter; |
|
|
89 |
|
90 |
/** Add weak listener to listen to change of activity of documents or components. |
75 |
/** Add weak listener to listen to change of activity of documents or components. |
91 |
* The caller must |
76 |
* The caller must |
92 |
* hold the listener object in some instance variable to prevent it |
77 |
* hold the listener object in some instance variable to prevent it |
Lines 94-99
Link Here
|
94 |
* @param l listener to add |
79 |
* @param l listener to add |
95 |
*/ |
80 |
*/ |
96 |
public static void addChangeListener(ChangeListener l) { |
81 |
public static void addChangeListener(ChangeListener l) { |
|
|
82 |
registerListener(); |
97 |
listenerList.add(ChangeListener.class, l); |
83 |
listenerList.add(ChangeListener.class, l); |
98 |
} |
84 |
} |
99 |
|
85 |
|
Lines 103-108
Link Here
|
103 |
* @param l listener to remove |
89 |
* @param l listener to remove |
104 |
*/ |
90 |
*/ |
105 |
public static void removeChangeListener(ChangeListener l) { |
91 |
public static void removeChangeListener(ChangeListener l) { |
|
|
92 |
registerListener(); |
106 |
listenerList.remove(ChangeListener.class, l); |
93 |
listenerList.remove(ChangeListener.class, l); |
107 |
} |
94 |
} |
108 |
|
95 |
|
Lines 110-126
Link Here
|
110 |
* @return document id or -1 if document was not yet added to the registry |
97 |
* @return document id or -1 if document was not yet added to the registry |
111 |
* by <code>addDocument()</code>. |
98 |
* by <code>addDocument()</code>. |
112 |
*/ |
99 |
*/ |
113 |
public static synchronized int getID(BaseDocument doc) { |
100 |
@PatchedPublic |
114 |
Integer i = getIDInteger(doc); |
101 |
private static int getID(BaseDocument doc) { |
115 |
return (i != null) ? i.intValue() : -1; |
102 |
registerListener(); |
|
|
103 |
return -1; |
116 |
} |
104 |
} |
117 |
|
105 |
|
118 |
/** Get component ID from the component. |
106 |
/** Get component ID from the component. |
119 |
* @return component id or -1 if component was not yet added to the registry |
107 |
* @return component id or -1 if component was not yet added to the registry |
120 |
* by <code>addComponent()</code>. |
108 |
* by <code>addComponent()</code>. |
121 |
*/ |
109 |
*/ |
122 |
public static synchronized int getID(JTextComponent c) { |
110 |
@PatchedPublic |
123 |
return getIDImpl(c); |
111 |
private static int getID(JTextComponent c) { |
|
|
112 |
registerListener(); |
113 |
return -1; |
124 |
} |
114 |
} |
125 |
|
115 |
|
126 |
/** Get document when its ID is known. |
116 |
/** Get document when its ID is known. |
Lines 129-141
Link Here
|
129 |
* by <code>getID(doc)</code>. |
119 |
* by <code>getID(doc)</code>. |
130 |
* @return document instance or null when document no longer exists |
120 |
* @return document instance or null when document no longer exists |
131 |
*/ |
121 |
*/ |
132 |
public static synchronized BaseDocument getDocument(int docID) { |
122 |
@PatchedPublic |
133 |
if (docID < 0 || docID >= docRefsCount) { |
123 |
private static BaseDocument getDocument(int docID) { |
134 |
return null; |
124 |
registerListener(); |
135 |
} |
125 |
return null; |
136 |
|
|
|
137 |
WeakReference wr = docRefs[docID]; |
138 |
return (wr != null) ? (BaseDocument)wr.get() : null; |
139 |
} |
126 |
} |
140 |
|
127 |
|
141 |
/** Get component when its ID is known. |
128 |
/** Get component when its ID is known. |
Lines 144-175
Link Here
|
144 |
* by <code>getID(c)</code>. |
131 |
* by <code>getID(c)</code>. |
145 |
* @return component instance or null when document no longer exists |
132 |
* @return component instance or null when document no longer exists |
146 |
*/ |
133 |
*/ |
147 |
public static synchronized JTextComponent getComponent(int compID) { |
134 |
@PatchedPublic |
148 |
if (compID < 0 || compID >= compRefsCount) { |
135 |
private static JTextComponent getComponent(int compID) { |
149 |
return null; |
136 |
registerListener(); |
150 |
} |
137 |
return null; |
151 |
|
|
|
152 |
WeakReference wr = compRefs[compID]; |
153 |
return (wr != null) ? (JTextComponent)wr.get() : null; |
154 |
} |
138 |
} |
155 |
|
139 |
|
156 |
/** Add document to registry. Doesn't search for repetitive |
140 |
/** Add document to registry. Doesn't search for repetitive |
157 |
* adding. |
141 |
* adding. |
158 |
* @return registry unique ID of the document |
142 |
* @return registry unique ID of the document |
159 |
*/ |
143 |
*/ |
160 |
public static synchronized int addDocument(BaseDocument doc) { |
144 |
@PatchedPublic |
161 |
Integer docID = getIDInteger(doc); |
145 |
private static int addDocument(BaseDocument doc) { |
162 |
if (docID != null) { // already added |
146 |
registerListener(); |
163 |
return docID.intValue(); |
147 |
return -1; |
164 |
} |
|
|
165 |
|
166 |
if (docRefsCount >= docRefs.length) { |
167 |
docRefs = realloc(docRefs); |
168 |
} |
169 |
|
170 |
docRefs[docRefsCount] = new WeakReference(doc); |
171 |
doc.putProperty(BaseDocument.ID_PROP, new Integer(docRefsCount)); |
172 |
return docRefsCount++; |
173 |
} |
148 |
} |
174 |
|
149 |
|
175 |
/** Add component to registry. If the component is already registered |
150 |
/** Add component to registry. If the component is already registered |
Lines 177-198
Link Here
|
177 |
* to the component is _not_ registered automatically. |
152 |
* to the component is _not_ registered automatically. |
178 |
* @return ID of the component |
153 |
* @return ID of the component |
179 |
*/ |
154 |
*/ |
180 |
public static synchronized int addComponent(JTextComponent c) { |
155 |
@PatchedPublic |
181 |
int compID = getIDImpl(c); |
156 |
private static int addComponent(JTextComponent c) { |
182 |
if (compID != -1) { |
157 |
registerListener(); |
183 |
if (compRefs[compID] == null) { // unregistered previously by removeComponent() |
158 |
return -1; |
184 |
compRefs[compID] = new WeakReference<JTextComponent>(c); |
|
|
185 |
} |
186 |
return compID; // already registered |
187 |
} |
188 |
|
189 |
if (compRefsCount >= compRefs.length) { |
190 |
compRefs = realloc(compRefs); |
191 |
} |
192 |
|
193 |
compRefs[compRefsCount] = new WeakReference(c); |
194 |
((BaseTextUI)c.getUI()).componentID = compRefsCount; |
195 |
return compRefsCount++; |
196 |
} |
159 |
} |
197 |
|
160 |
|
198 |
/** Remove component from registry. It's usually done when |
161 |
/** Remove component from registry. It's usually done when |
Lines 201-278
Link Here
|
201 |
* new ID will be different from this one. -1 will be returned |
164 |
* new ID will be different from this one. -1 will be returned |
202 |
* if the component was not yet added to the registry. |
165 |
* if the component was not yet added to the registry. |
203 |
*/ |
166 |
*/ |
204 |
public static int removeComponent(JTextComponent c) { |
167 |
@PatchedPublic |
205 |
int compID; |
168 |
private static int removeComponent(JTextComponent c) { |
206 |
boolean lastComponent = false; |
169 |
registerListener(); |
207 |
|
170 |
return -1; |
208 |
synchronized (Registry.class) { |
|
|
209 |
compID = getIDImpl(c); |
210 |
|
211 |
if (compID != -1) { |
212 |
compRefs[compID] = null; |
213 |
// Search whether was activated |
214 |
for (int i = compAct.size() - 1; i >= 0; i--) { |
215 |
if (compAct.get(i) == compID) { |
216 |
compAct.remove(i); |
217 |
break; |
218 |
} |
219 |
} |
220 |
|
221 |
lastComponent = compAct.isEmpty(); |
222 |
} |
223 |
} |
224 |
|
225 |
if (lastComponent) { |
226 |
fireChange(); |
227 |
} |
228 |
|
229 |
return compID; |
230 |
} |
171 |
} |
231 |
|
172 |
|
232 |
/** Put the component to the first position in the array of last accessed |
173 |
/** Put the component to the first position in the array of last accessed |
233 |
* components. The activate of document is also called automatically. |
174 |
* components. The activate of document is also called automatically. |
234 |
*/ |
175 |
*/ |
235 |
public static void activate(JTextComponent c) { |
176 |
@PatchedPublic |
236 |
boolean activated = true; |
177 |
private static void activate(JTextComponent c) { |
237 |
synchronized (Registry.class) { |
178 |
registerListener(); |
238 |
int compID = getIDImpl(c); |
|
|
239 |
if (compID == -1) { // c not registered |
240 |
return; |
241 |
} |
242 |
|
243 |
int actSize = compAct.size(); |
244 |
int ind = 0; |
245 |
while (ind < actSize) { |
246 |
int id = compAct.get(ind); |
247 |
if (id == compID) { // found |
248 |
if (ind == 0) { |
249 |
break; |
250 |
} |
251 |
compAct.add(0, compAct.remove(ind)); |
252 |
activated = true; |
253 |
break; |
254 |
} |
255 |
|
256 |
ind++; |
257 |
} |
258 |
|
259 |
if (ind == actSize) { |
260 |
compAct.add(0, compID); |
261 |
activated = true; |
262 |
} |
263 |
|
264 |
// Try to activate component's document too |
265 |
Object doc = c.getDocument(); |
266 |
if (doc instanceof BaseDocument) { |
267 |
if (doActivate((BaseDocument)doc)) { |
268 |
activated = true; |
269 |
} |
270 |
} |
271 |
} |
272 |
|
273 |
if (activated) { |
274 |
fireChange(); |
275 |
} |
276 |
} |
179 |
} |
277 |
|
180 |
|
278 |
/** Put the document to the first position in the array of last accessed |
181 |
/** Put the document to the first position in the array of last accessed |
Lines 280-319
Link Here
|
280 |
* is done. |
183 |
* is done. |
281 |
* @param doc document to be activated |
184 |
* @param doc document to be activated |
282 |
*/ |
185 |
*/ |
283 |
public static void activate(BaseDocument doc) { |
186 |
@PatchedPublic |
284 |
boolean activated; |
187 |
private static void activate(BaseDocument doc) { |
285 |
synchronized (Registry.class) { |
188 |
registerListener(); |
286 |
activated = doActivate(doc); |
|
|
287 |
} |
288 |
|
289 |
if (activated) { |
290 |
fireChange(); |
291 |
} |
292 |
} |
189 |
} |
293 |
|
190 |
|
294 |
public static synchronized BaseDocument getMostActiveDocument() { |
191 |
public static BaseDocument getMostActiveDocument() { |
295 |
return getValidDoc(0, true); |
192 |
registerListener(); |
|
|
193 |
JTextComponent jtc = getMostActiveComponent(); |
194 |
return jtc == null ? null : Utilities.getDocument(jtc); |
296 |
} |
195 |
} |
297 |
|
196 |
|
298 |
public static synchronized BaseDocument getLeastActiveDocument() { |
197 |
public static BaseDocument getLeastActiveDocument() { |
299 |
int lastInd = docAct.size() - 1; |
198 |
registerListener(); |
300 |
return getValidDoc(lastInd, false); |
199 |
JTextComponent jtc = getLeastActiveComponent(); |
|
|
200 |
return jtc == null ? null : Utilities.getDocument(jtc); |
301 |
} |
201 |
} |
302 |
|
202 |
|
303 |
public static BaseDocument getLessActiveDocument(BaseDocument doc) { |
203 |
@PatchedPublic |
304 |
return getLessActiveDocument(getID(doc)); |
204 |
private static BaseDocument getLessActiveDocument(BaseDocument doc) { |
|
|
205 |
registerListener(); |
206 |
return null; |
305 |
} |
207 |
} |
306 |
|
208 |
|
307 |
public static synchronized BaseDocument getLessActiveDocument(int docID) { |
209 |
@PatchedPublic |
308 |
return getNextActiveDoc(docID, true); |
210 |
private static BaseDocument getLessActiveDocument(int docID) { |
|
|
211 |
registerListener(); |
212 |
return null; |
309 |
} |
213 |
} |
310 |
|
214 |
|
311 |
public static BaseDocument getMoreActiveDocument(BaseDocument doc) { |
215 |
@PatchedPublic |
312 |
return getMoreActiveDocument(getID(doc)); |
216 |
private static BaseDocument getMoreActiveDocument(BaseDocument doc) { |
|
|
217 |
registerListener(); |
218 |
return null; |
313 |
} |
219 |
} |
314 |
|
220 |
|
315 |
public static synchronized BaseDocument getMoreActiveDocument(int docID) { |
221 |
@PatchedPublic |
316 |
return getNextActiveDoc(docID, false); |
222 |
private static BaseDocument getMoreActiveDocument(int docID) { |
|
|
223 |
registerListener(); |
224 |
return null; |
317 |
} |
225 |
} |
318 |
|
226 |
|
319 |
/** Get the iterator over the active documents. It starts with |
227 |
/** Get the iterator over the active documents. It starts with |
Lines 321-527
Link Here
|
321 |
* It's just the current snapshot so the iterator will |
229 |
* It's just the current snapshot so the iterator will |
322 |
* not reflect future changes. |
230 |
* not reflect future changes. |
323 |
*/ |
231 |
*/ |
324 |
public static synchronized Iterator getDocumentIterator() { |
232 |
public static Iterator<? extends Document> getDocumentIterator() { |
325 |
consolidate(); |
233 |
registerListener(); |
|
|
234 |
final Iterator<? extends JTextComponent> cIt = getComponentIterator(); |
235 |
return new Iterator<Document>() { |
236 |
public boolean hasNext() { |
237 |
return cIt.hasNext(); |
238 |
} |
326 |
|
239 |
|
327 |
ArrayList docList = new ArrayList(); |
240 |
public Document next() { |
328 |
int actSize = docAct.size(); |
241 |
return cIt.next().getDocument(); |
329 |
for (int i = 0; i < actSize; i++) { |
|
|
330 |
int ind = ((Integer)docAct.get(i)).intValue(); |
331 |
WeakReference wr = docRefs[ind]; |
332 |
if (wr != null) { |
333 |
Object doc = wr.get(); |
334 |
if (doc != null) { |
335 |
docList.add(doc); |
336 |
} |
337 |
} |
242 |
} |
338 |
} |
|
|
339 |
|
243 |
|
340 |
return docList.iterator(); |
244 |
public void remove() { |
|
|
245 |
cIt.remove(); |
246 |
} |
247 |
}; |
341 |
} |
248 |
} |
342 |
|
249 |
|
343 |
public static synchronized JTextComponent getMostActiveComponent() { |
250 |
public static JTextComponent getMostActiveComponent() { |
344 |
return getValidComp(0, true); |
251 |
registerListener(); |
|
|
252 |
return EditorRegistry.focusedComponent(); |
345 |
} |
253 |
} |
346 |
|
254 |
|
347 |
public static synchronized JTextComponent getLeastActiveComponent() { |
255 |
public static JTextComponent getLeastActiveComponent() { |
348 |
int lastInd = compAct.size() - 1; |
256 |
registerListener(); |
349 |
return getValidComp(lastInd, false); |
257 |
List<? extends JTextComponent> l = EditorRegistry.componentList(); |
|
|
258 |
return l.size() > 0 ? l.get(l.size() - 1) : null; |
350 |
} |
259 |
} |
351 |
|
260 |
|
352 |
public static JTextComponent getLessActiveComponent(JTextComponent c) { |
261 |
@PatchedPublic |
353 |
return getLessActiveComponent(getID(c)); |
262 |
private static JTextComponent getLessActiveComponent(JTextComponent c) { |
|
|
263 |
registerListener(); |
264 |
return null; |
354 |
} |
265 |
} |
355 |
|
266 |
|
356 |
public static synchronized JTextComponent getLessActiveComponent(int compID) { |
267 |
@PatchedPublic |
357 |
return getNextActiveComp(compID, true); |
268 |
private static JTextComponent getLessActiveComponent(int compID) { |
|
|
269 |
registerListener(); |
270 |
return null; |
358 |
} |
271 |
} |
359 |
|
272 |
|
360 |
public static JTextComponent getMoreActiveComponent(JTextComponent c) { |
273 |
@PatchedPublic |
361 |
return getMoreActiveComponent(getID(c)); |
274 |
private static JTextComponent getMoreActiveComponent(JTextComponent c) { |
|
|
275 |
registerListener(); |
276 |
return null; |
362 |
} |
277 |
} |
363 |
|
278 |
|
364 |
public static synchronized JTextComponent getMoreActiveComponent(int compID) { |
279 |
@PatchedPublic |
365 |
return getNextActiveComp(compID, false); |
280 |
private static JTextComponent getMoreActiveComponent(int compID) { |
|
|
281 |
registerListener(); |
282 |
return null; |
366 |
} |
283 |
} |
367 |
|
284 |
|
368 |
/** Get the iterator over the active components. It starts with |
285 |
/** Get the iterator over the active components. It starts with |
369 |
* the most active component till the least active component. |
286 |
* the most active component till the least active component. |
370 |
*/ |
287 |
*/ |
371 |
public static synchronized Iterator getComponentIterator() { |
288 |
public static Iterator<? extends JTextComponent> getComponentIterator() { |
372 |
consolidate(); |
289 |
registerListener(); |
373 |
|
290 |
return EditorRegistry.componentList().iterator(); |
374 |
ArrayList compList = new ArrayList(); |
|
|
375 |
int actSize = compAct.size(); |
376 |
for (int i = 0; i < actSize; i++) { |
377 |
int ind = compAct.get(i); |
378 |
WeakReference wr = compRefs[ind]; |
379 |
if (wr != null) { |
380 |
Object comp = wr.get(); |
381 |
if (comp != null) { |
382 |
compList.add(comp); |
383 |
} |
384 |
} |
385 |
} |
386 |
|
387 |
return compList.iterator(); |
388 |
} |
291 |
} |
389 |
|
292 |
|
390 |
private static WeakReference[] realloc(WeakReference[] refs) { |
293 |
private static synchronized void registerListener() { |
391 |
WeakReference[] tmp = new WeakReference[refs.length * 2 + 4]; |
294 |
if (editorRegistryListener == null) { |
392 |
System.arraycopy(refs, 0, tmp, 0, refs.length); |
295 |
editorRegistryListener = new PropertyChangeListener() { |
393 |
return tmp; |
296 |
public void propertyChange(PropertyChangeEvent evt) { |
394 |
} |
297 |
fireChange(); |
395 |
|
298 |
} |
396 |
private static void consolidate() { |
299 |
}; |
397 |
while (++consolidateCounter >= 20) { // after every 20th call |
300 |
EditorRegistry.addPropertyChangeListener(editorRegistryListener); |
398 |
consolidateCounter = 0; |
|
|
399 |
|
400 |
// Remove empty document references |
401 |
for (int i = docAct.size() - 1; i >= 0; i--) { |
402 |
int ind = ((Integer)docAct.get(i)).intValue(); |
403 |
WeakReference wr = docRefs[ind]; |
404 |
if (wr != null) { |
405 |
if (wr.get() == null) { // empty reference |
406 |
docAct.remove(i); |
407 |
docRefs[ind] = null; |
408 |
} |
409 |
} |
410 |
} |
411 |
|
412 |
// Remove empty component references |
413 |
for (int i = compAct.size() - 1; i >= 0; i--) { |
414 |
int ind = compAct.get(i); |
415 |
WeakReference wr = compRefs[ind]; |
416 |
if (wr != null) { |
417 |
if (wr.get() == null) { // empty reference |
418 |
compAct.remove(i); |
419 |
compRefs[ind] = null; |
420 |
} |
421 |
} |
422 |
} |
423 |
} |
424 |
} |
425 |
|
426 |
private static int getIDImpl(JTextComponent c) { |
427 |
if (c == null) { |
428 |
return -1; |
429 |
} |
301 |
} |
430 |
return ((BaseTextUI)c.getUI()).componentID; |
|
|
431 |
} |
432 |
|
433 |
private static Integer getIDInteger(BaseDocument doc) { |
434 |
if (doc == null) { |
435 |
return null; |
436 |
} |
437 |
|
438 |
return (Integer)doc.getProperty(BaseDocument.ID_PROP); |
439 |
} |
440 |
|
441 |
private static boolean doActivate(BaseDocument doc) { |
442 |
Integer docIDInteger = getIDInteger(doc); |
443 |
|
444 |
if (docIDInteger == null) { |
445 |
return false; // document not added to registry |
446 |
} |
447 |
|
448 |
int docID = (docIDInteger != null) ? docIDInteger.intValue() : -1; |
449 |
|
450 |
int size = docAct.size(); |
451 |
for (int ind = 0; ind < size; ind++) { |
452 |
int id = ((Integer)docAct.get(ind)).intValue(); |
453 |
if (id == docID) { |
454 |
if (ind == 0) { // no change |
455 |
return false; |
456 |
} |
457 |
|
458 |
docAct.add(0, docAct.remove(ind)); |
459 |
return true; |
460 |
} |
461 |
} |
462 |
|
463 |
docAct.add(0, docIDInteger); |
464 |
return true; |
465 |
} |
466 |
|
467 |
private static BaseDocument getValidDoc(int ind, boolean forward) { |
468 |
consolidate(); |
469 |
|
470 |
int actSize = docAct.size(); |
471 |
while (ind >= 0 && ind < actSize) { |
472 |
int docID = ((Integer)docAct.get(ind)).intValue(); |
473 |
WeakReference wr = docRefs[docID]; |
474 |
BaseDocument doc = (wr != null) ? (BaseDocument)wr.get() : null; |
475 |
if (doc != null) { |
476 |
return doc; |
477 |
} |
478 |
ind += forward ? +1 : -1; |
479 |
} |
480 |
return null; |
481 |
} |
482 |
|
483 |
private static BaseDocument getNextActiveDoc(int docID, boolean forward) { |
484 |
consolidate(); |
485 |
|
486 |
int actSize = docAct.size(); |
487 |
int ind = forward ? 0 : (actSize - 1); |
488 |
while (ind >= 0 && ind < actSize) { |
489 |
if (((Integer)docAct.get(ind)).intValue() == docID) { |
490 |
ind += forward ? +1 : -1; // get next one |
491 |
return getValidDoc(ind, forward); |
492 |
} |
493 |
ind += forward ? +1 : -1; |
494 |
} |
495 |
return null; |
496 |
} |
497 |
|
498 |
private static JTextComponent getValidComp(int ind, boolean forward) { |
499 |
consolidate(); |
500 |
|
501 |
int actSize = compAct.size(); |
502 |
while (ind >= 0 && ind < actSize) { |
503 |
int compID = compAct.get(ind); |
504 |
WeakReference wr = compRefs[compID]; |
505 |
JTextComponent c = (wr != null) ? (JTextComponent)wr.get() : null; |
506 |
if (c != null) { |
507 |
return c; |
508 |
} |
509 |
ind += forward ? +1 : -1; |
510 |
} |
511 |
return null; |
512 |
} |
513 |
|
514 |
private static JTextComponent getNextActiveComp(int compID, boolean forward) { |
515 |
int actSize = compAct.size(); |
516 |
int ind = forward ? 0 : (actSize - 1); |
517 |
while (ind >= 0 && ind < actSize) { |
518 |
if (compAct.get(ind) == compID) { |
519 |
ind += forward ? +1 : -1; |
520 |
return getValidComp(ind, forward); |
521 |
} |
522 |
ind += forward ? +1 : -1; |
523 |
} |
524 |
return null; |
525 |
} |
302 |
} |
526 |
|
303 |
|
527 |
private static void fireChange() { |
304 |
private static void fireChange() { |
Lines 534-567
Link Here
|
534 |
} |
311 |
} |
535 |
|
312 |
|
536 |
/** Debug the registry into string. */ |
313 |
/** Debug the registry into string. */ |
537 |
public static synchronized String registryToString() { |
314 |
public static String registryToString() { |
538 |
StringBuffer sb = new StringBuffer(); |
315 |
registerListener(); |
539 |
sb.append("Document References:\n"); // NOI18N |
316 |
try { |
540 |
for (int i = 0; i < docRefsCount; i++) { |
317 |
Method m = EditorRegistry.class.getDeclaredMethod("dumpItemList"); //NOI18N |
541 |
WeakReference wr = docRefs[i]; |
318 |
return (String) m.invoke(null); |
542 |
sb.append("docRefs[" + i + "]=" + ((wr != null) ? wr.get() : "null") + "\n"); // NOI18N |
319 |
} catch (Exception e) { |
|
|
320 |
// ignore; |
321 |
return ""; //NOI18N |
543 |
} |
322 |
} |
544 |
sb.append("Component References:\n"); // NOI18N |
|
|
545 |
for (int i = 0; i < compRefsCount; i++) { |
546 |
WeakReference wr = (WeakReference)compRefs[i]; |
547 |
sb.append("compRefs[" + i + "]=" + ((wr != null) ? wr.get() : "null") + "\n"); // NOI18N |
548 |
} |
549 |
sb.append("\nActive Document Indexes:\n"); // NOI18N |
550 |
for (int i = 0; i < docAct.size(); i++) { |
551 |
sb.append(docAct.get(i)); |
552 |
if (i != docAct.size() - 1) { |
553 |
sb.append(", "); // NOI18N |
554 |
} |
555 |
} |
556 |
sb.append("\nActive Component Indexes:\n"); // NOI18N |
557 |
for (int i = 0; i < compAct.size(); i++) { |
558 |
sb.append(compAct.get(i)); |
559 |
if (i != compAct.size() - 1) { |
560 |
sb.append(", "); // NOI18N |
561 |
} |
562 |
} |
563 |
|
564 |
return sb.toString(); |
565 |
} |
323 |
} |
566 |
|
324 |
|
567 |
} |
325 |
} |