Source Code Cross Referenced for EditBus.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » jEdit » org.gjt.sp.jedit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * EditBus.java - The EditBus
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 1999 Slava Pestov
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:
023:        package org.gjt.sp.jedit;
024:
025:        import java.util.*;
026:        import org.gjt.sp.util.Log;
027:
028:        /**
029:         * jEdit's global event notification mechanism.<p>
030:         *
031:         * Plugins register with the EditBus to receive messages reflecting
032:         * changes in the application's state, including changes in buffers,
033:         * views and edit panes, changes in the set of properties maintained
034:         * by the application, and the closing of the application.<p>
035:         *
036:         * The EditBus maintains a list of objects that have requested to receive
037:         * messages. When a message is sent using this class, all registered
038:         * components receive it in turn. Classes for objects that subscribe to
039:         * the EditBus must implement the {@link EBComponent} interface, which
040:         * defines the single method {@link EBComponent#handleMessage(EBMessage)}.<p>
041:         *
042:         * A plugin core class that extends the
043:         * {@link EBPlugin} abstract class (and whose name ends with
044:         * <code>Plugin</code> for identification purposes) will automatically be
045:         * added to the EditBus during jEdit's startup routine.  Any other
046:         * class - for example, a dockable window that needs to receive
047:         * notification of buffer changes - must perform its own registration by calling
048:         * {@link #addToBus(EBComponent)} during its initialization.
049:         * A convenient place to register in a class derived from <code>JComponent</code>
050:         * would be in an implementation of the <code>JComponent</code> method
051:         * <code>addNotify()</code>.<p>
052:         *
053:         * Message types sent by jEdit can be found in the
054:         * {@link org.gjt.sp.jedit.msg} package.<p>
055:         *
056:         * Plugins can also send their own messages - any object can send a message to
057:         * the EditBus by calling the static method {@link #send(EBMessage)}.
058:         * Most plugins, however, only concern themselves with receiving, not
059:         * sending, messages.
060:         *
061:         * @see org.gjt.sp.jedit.EBComponent
062:         * @see org.gjt.sp.jedit.EBMessage
063:         *
064:         * @author Slava Pestov
065:         * @author John Gellene (API documentation)
066:         * @version $Id: EditBus.java 4669 2003-05-01 02:21:27Z spestov $
067:         *
068:         * @since jEdit 2.2pre6
069:         */
070:        public class EditBus {
071:            //{{{ addToBus() method
072:            /**
073:             * Adds a component to the bus. It will receive all messages sent
074:             * on the bus.
075:             *
076:             * @param comp The component to add
077:             */
078:            public static void addToBus(EBComponent comp) {
079:                synchronized (components) {
080:                    components.add(comp);
081:                    copyComponents = null;
082:                }
083:            } //}}}
084:
085:            //{{{ removeFromBus() method
086:            /**
087:             * Removes a component from the bus.
088:             * @param comp The component to remove
089:             */
090:            public static void removeFromBus(EBComponent comp) {
091:                synchronized (components) {
092:                    components.remove(comp);
093:                    copyComponents = null;
094:                }
095:            } //}}}
096:
097:            //{{{ getComponents() method
098:            /**
099:             * Returns an array of all components connected to the bus.
100:             */
101:            public static EBComponent[] getComponents() {
102:                synchronized (components) {
103:                    if (copyComponents == null) {
104:                        copyComponents = (EBComponent[]) components
105:                                .toArray(new EBComponent[components.size()]);
106:                    }
107:                    return copyComponents;
108:                }
109:            } //}}}
110:
111:            //{{{ send() method
112:            /**
113:             * Sends a message to all components on the bus in turn.
114:             * @param message The message
115:             */
116:            public static void send(EBMessage message) {
117:                Log.log(Log.DEBUG, EditBus.class, message.toString());
118:
119:                // To avoid any problems if components are added or removed
120:                // while the message is being sent
121:                EBComponent[] comps = getComponents();
122:
123:                for (int i = 0; i < comps.length; i++) {
124:                    try {
125:                        EBComponent comp = comps[i];
126:                        if (Debug.EB_TIMER) {
127:                            long start = System.currentTimeMillis();
128:                            comp.handleMessage(message);
129:                            long time = (System.currentTimeMillis() - start);
130:                            if (time != 0) {
131:                                Log.log(Log.DEBUG, EditBus.class, comp + ": "
132:                                        + time + " ms");
133:                            }
134:                        } else
135:                            comps[i].handleMessage(message);
136:                    } catch (Throwable t) {
137:                        Log.log(Log.ERROR, EditBus.class, "Exception"
138:                                + " while sending message on EditBus:");
139:                        Log.log(Log.ERROR, EditBus.class, t);
140:                    }
141:                }
142:            } //}}}
143:
144:            //{{{ Private members
145:            private static ArrayList components = new ArrayList();
146:            private static EBComponent[] copyComponents;
147:
148:            // can't create new instances
149:            private EditBus() {
150:            }
151:            //}}}
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.