KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > plugin > container > PluginContainer


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

51
52 public class PluginContainer implements ComponentContainer {
53     private JRootPane rootPane;
54     private CEditorGrammar editor;
55
56     private XJPreferences prefs;
57     private CDocumentGrammar document;
58     private XJMainMenuBar mainMenuBar;
59
60     private PCXJFrameInterface frameInterface;
61     private PCMenuHelpDelegate menuHelpDelegate;
62     private PCXJApplicationInterface appInterface = new PCXJApplicationInterface(this);
63     private PluginContainerDelegate delegate;
64
65     public PluginContainer() {
66         XJApplication.setShared(appInterface);
67         
68         frameInterface = new PCXJFrameInterface(this);
69         menuHelpDelegate = new PCMenuHelpDelegate(this);
70
71         rootPane = new JRootPane();
72
73         prefs = new XJPreferences(getClass());
74         document = new CDocumentGrammar();
75         document.setComponentContainer(this);
76         document.setDocumentData(new XJDataPlainText());
77
78         editor = new CEditorGrammar(this);
79         editor.create();
80         
81         mainMenuBar = new XJMainMenuBar();
82         mainMenuBar.setDelegate(new PCMenuBarDelegate(this));
83         mainMenuBar.setCustomizer(new PCMenuCustomizer(this));
84         mainMenuBar.createMenuBar(XJMainMenuBar.IGNORE_FILEMENU
85                 | XJMainMenuBar.IGNORE_WINDOWMENU);
86     }
87
88     public void setDelegate(PluginContainerDelegate delegate) {
89         this.delegate = delegate;
90     }
91
92     public void setEditorGrammarDelegate(CEditorGrammarDefaultDelegate delegate) {
93         editor.setDelegate(delegate);
94     }
95
96     public XJMenuItemDelegate getMenuHelpDelegate() {
97         return menuHelpDelegate;
98     }
99
100     public XJPreferences getPreferences() {
101         return prefs;
102     }
103
104     public Container getParent() {
105         return XJDialog.resolveOwner(getRootPane());
106     }
107
108     public JRootPane getRootPane() {
109         return rootPane;
110     }
111
112     public JComponent getEditorComponent() {
113         return editor.getTextEditor();
114     }
115
116     public JComponent getRulesComponent() {
117         return editor.getRulesComponent();
118     }
119
120     public JComponent getTabbedComponent() {
121         return editor.getTabbedComponent();
122     }
123
124     public JComponent getMenubarComponent() {
125         return mainMenuBar.getJMenuBar();
126     }
127
128     public JComponent getToolbarComponent() {
129         return editor.getToolbarComponent();
130     }
131
132     public JComponent getStatusComponent() {
133         return editor.getStatusComponent();
134     }
135
136     public void load(String JavaDoc file) {
137         document.performLoad(file);
138     }
139
140     public Container getContentPane() {
141         return rootPane.getContentPane();
142     }
143
144     public JLayeredPane getLayeredPane() {
145         return rootPane.getLayeredPane();
146     }
147
148     public void becomingVisibleForTheFirstTime() {
149         editor.componentDidAwake();
150         editor.componentShouldLayout(rootPane.getSize());
151     }
152
153     public static void showAbout() {
154         new DialogAbout().show();
155     }
156
157     public void activate() {
158         XJApplication.setShared(appInterface);
159     }
160
161     public void deactivate() {
162
163     }
164
165     // ******** ComponentContainer **********
166

167     public void loadText(String JavaDoc text) {
168         editor.loadText(text);
169     }
170
171     public String JavaDoc getText() {
172         return editor.getText();
173     }
174
175     public boolean willSaveDocument() {
176         return editor.componentDocumentWillSave();
177     }
178
179     public void close() {
180         editor.close();
181     }
182
183     public void setPersistentData(Map JavaDoc data) {
184     }
185
186     public Map JavaDoc getPersistentData() {
187         return null;
188     }
189
190     public ComponentEditor getEditor() {
191         return editor;
192     }
193
194     public void setDirty() {
195         if(delegate != null)
196             delegate.pluginDocumentDidChange();
197     }
198
199     public XJDocument getDocument() {
200         return document;
201     }
202
203     public XJFrameInterface getXJFrame() {
204         return frameInterface;
205     }
206
207     public XJMainMenuBar getMainMenuBar() {
208         return mainMenuBar;
209     }
210
211 }
212
Popular Tags