KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > components > ComponentEditor


1 package org.antlr.works.components;
2
3 import org.antlr.xjlib.appkit.document.XJDocument;
4 import org.antlr.xjlib.appkit.frame.XJFrameInterface;
5 import org.antlr.xjlib.appkit.menu.XJMainMenuBar;
6 import org.antlr.xjlib.appkit.menu.XJMenu;
7 import org.antlr.xjlib.appkit.menu.XJMenuItem;
8 import org.antlr.xjlib.appkit.undo.XJUndo;
9 import org.antlr.xjlib.foundation.notification.XJNotificationCenter;
10 import org.antlr.xjlib.foundation.notification.XJNotificationObserver;
11 import org.antlr.works.debugger.Debugger;
12 import org.antlr.works.prefs.AWPrefsDialog;
13
14 import javax.swing.*;
15 import java.awt.*;
16 import java.awt.event.ComponentAdapter JavaDoc;
17 import java.awt.event.ComponentEvent JavaDoc;
18 import java.beans.PropertyChangeEvent JavaDoc;
19 import java.beans.PropertyChangeListener JavaDoc;
20 import java.util.Map JavaDoc;
21
22 /*
23
24 [The "BSD licence"]
25 Copyright (c) 2005 Jean Bovet
26 All rights reserved.
27
28 Redistribution and use in source and binary forms, with or without
29 modification, are permitted provided that the following conditions
30 are met:
31
32 1. Redistributions of source code must retain the above copyright
33 notice, this list of conditions and the following disclaimer.
34 2. Redistributions in binary form must reproduce the above copyright
35 notice, this list of conditions and the following disclaimer in the
36 documentation and/or other materials provided with the distribution.
37 3. The name of the author may not be used to endorse or promote products
38 derived from this software without specific prior written permission.
39
40 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
41 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
43 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
44 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
46 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
47 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
48 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
49 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50
51 */

52
53 public abstract class ComponentEditor implements XJNotificationObserver {
54
55     protected ComponentContainer container;
56     protected JPanel mainPanel;
57     protected Box statusBar;
58
59     public ComponentEditor(ComponentContainer container) {
60         this.container = container;
61
62         mainPanel = new JPanel(new BorderLayout());
63         mainPanel.addComponentListener(new MainPanelComponentListener());
64
65         statusBar = new ComponentStatusBar();
66         statusBar.setPreferredSize(new Dimension(0, 30));
67
68         XJNotificationCenter.defaultCenter().addObserver(this, AWPrefsDialog.NOTIF_PREFS_APPLIED);
69         XJNotificationCenter.defaultCenter().addObserver(this, Debugger.NOTIF_DEBUG_STARTED);
70         XJNotificationCenter.defaultCenter().addObserver(this, Debugger.NOTIF_DEBUG_STOPPED);
71
72         KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
73         focusManager.addPropertyChangeListener(
74                 new PropertyChangeListener JavaDoc() {
75                     public void propertyChange(PropertyChangeEvent JavaDoc e) {
76                         String JavaDoc prop = e.getPropertyName();
77                         if(prop.equals("permanentFocusOwner"))
78                             XJMainMenuBar.refreshAllMenuBars();
79                     }
80                 }
81         );
82
83     }
84
85     public void refreshMainMenuBar() {
86         if(getXJFrame().getMainMenuBar() != null)
87             getXJFrame().getMainMenuBar().refreshState();
88     }
89
90     public JComponent getToolbarComponent() {
91         return null;
92     }
93
94     public JComponent getStatusComponent() {
95         return statusBar;
96     }
97
98     public XJDocument getDocument() {
99         return container.getDocument();
100     }
101
102     public XJFrameInterface getXJFrame() {
103         return container.getXJFrame();
104     }
105
106     public Container getJavaContainer() {
107         return getXJFrame().getJavaContainer();
108     }
109
110     public JPanel getPanel() {
111         return mainPanel;
112     }
113
114     public XJUndo getCurrentUndo() {
115         return getXJFrame().getCurrentUndo();
116     }
117
118     public void notificationFire(Object JavaDoc source, String JavaDoc name) {
119         if(name.equals(AWPrefsDialog.NOTIF_PREFS_APPLIED)) {
120             notificationPrefsChanged();
121         } else if(name.equals(Debugger.NOTIF_DEBUG_STARTED)) {
122             notificationDebuggerStarted();
123         } else if(name.equals(Debugger.NOTIF_DEBUG_STOPPED)) {
124             notificationDebuggerStopped();
125         }
126     }
127
128     protected static JComponent createSeparator() {
129         JSeparator s = new JSeparator(SwingConstants.VERTICAL);
130         Dimension d = s.getMaximumSize();
131         d.width = 2;
132         s.setMaximumSize(d);
133         return s;
134     }
135
136     /** For subclass only
137      *
138      */

139
140     public abstract void create();
141     public abstract void assemble();
142
143     public abstract void loadText(String JavaDoc text);
144
145     public abstract String JavaDoc getText();
146
147     public void close() {
148         XJNotificationCenter.defaultCenter().removeObserver(this);
149     }
150
151     public abstract void componentDocumentContentChanged();
152
153     public boolean componentDocumentWillSave() {
154         return true;
155     }
156
157     public void setPersistentData(Map JavaDoc data) {
158
159     }
160
161     public Map JavaDoc<String JavaDoc, Object JavaDoc> getPersistentData() {
162         return null;
163     }
164
165     public void componentShouldLayout(Dimension size) {
166
167     }
168
169     public void componentDidAwake() {
170     }
171
172     public void customizeFileMenu(XJMenu menu) {
173     }
174
175     public void customizeEditMenu(XJMenu menu) {
176     }
177
178     public void customizeWindowMenu(XJMenu menu) {
179     }
180
181     public void customizeHelpMenu(XJMenu menu) {
182     }
183
184     public void customizeMenuBar(XJMainMenuBar menubar) {
185     }
186
187     public void menuItemState(XJMenuItem item) {
188     }
189
190     public void handleMenuSelected(XJMenu menu) {
191     }
192
193     public void componentActivated() {
194     }
195
196     public void componentDidHide() {
197
198     }
199
200     public void componentIsSelected() {
201     }
202
203     public void notificationPrefsChanged() {
204     }
205
206     public void notificationDebuggerStarted() {
207     }
208
209     public void notificationDebuggerStopped() {
210     }
211
212     protected class MainPanelComponentListener extends ComponentAdapter JavaDoc {
213         public void componentHidden(ComponentEvent JavaDoc e) {
214             componentDidHide();
215         }
216     }
217
218 }
219
Popular Tags