KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > editor > util > swing > PriorityDocumentListenerList


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.lib.editor.util.swing;
21
22 import java.util.EventListener JavaDoc;
23 import javax.swing.event.DocumentEvent JavaDoc;
24 import javax.swing.event.DocumentListener JavaDoc;
25 import javax.swing.text.Document JavaDoc;
26 import org.netbeans.lib.editor.util.PriorityListenerList;
27
28 /**
29  * Priority listener list that acts as DocumentListener itself
30  * firing all added document listeners according to their priority.
31  *
32  * @author Miloslav Metelka
33  * @version 1.00
34  */

35
36 class PriorityDocumentListenerList extends PriorityListenerList<DocumentListener JavaDoc> implements DocumentListener JavaDoc {
37     
38     /**
39      * Implementation of DocumentListener's method fires all the added
40      * listeners according to their priority.
41      */

42     public void insertUpdate(DocumentEvent JavaDoc evt) {
43         // Fire the prioritized listeners
44
EventListener JavaDoc[][] listenersArray = getListenersArray();
45         for (int priority = listenersArray.length - 1; priority >= 0; priority--) {
46             EventListener JavaDoc[] listeners = listenersArray[priority];
47             for (int i = listeners.length - 1; i >= 0; i--) {
48                 ((DocumentListener JavaDoc)listeners[i]).insertUpdate(evt);
49             }
50         }
51     }
52
53     /**
54      * Implementation of DocumentListener's method fires all the added
55      * listeners according to their priority.
56      */

57     public void removeUpdate(DocumentEvent JavaDoc evt) {
58         // Fire the prioritized listeners
59
EventListener JavaDoc[][] listenersArray = getListenersArray();
60         for (int priority = listenersArray.length - 1; priority >= 0; priority--) {
61             EventListener JavaDoc[] listeners = listenersArray[priority];
62             for (int i = listeners.length - 1; i >= 0; i--) {
63                 ((DocumentListener JavaDoc)listeners[i]).removeUpdate(evt);
64             }
65         }
66     }
67
68     /**
69      * Implementation of DocumentListener's method fires all the added
70      * listeners according to their priority.
71      */

72     public void changedUpdate(DocumentEvent JavaDoc evt) {
73         // Fire the prioritized listeners
74
EventListener JavaDoc[][] listenersArray = getListenersArray();
75         for (int priority = listenersArray.length - 1; priority >= 0; priority--) {
76             EventListener JavaDoc[] listeners = listenersArray[priority];
77             for (int i = listeners.length - 1; i >= 0; i--) {
78                 ((DocumentListener JavaDoc)listeners[i]).changedUpdate(evt);
79             }
80         }
81     }
82
83 }
84
Popular Tags