KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > components > project > file > CContainerProjectFile


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

45
46 public abstract class CContainerProjectFile implements ComponentContainer, XJMenuBarCustomizer, XJMenuBarDelegate {
47
48     public CContainerProject project;
49     public ProjectFileItem item;
50
51     public ComponentEditor editor;
52     public ComponentDocument document;
53
54     public XJMainMenuBar mainMenuBar;
55
56     public CContainerProjectFile(CContainerProject project, ProjectFileItem item) {
57         this.project = project;
58         this.item = item;
59
60         document = createDocument();
61         document.setJavaContainer(project.getJavaContainer());
62         document.setDocumentData(new XJDataPlainText());
63         document.setComponentContainer(this);
64
65         editor = createEditor();
66         editor.create();
67         editor.assemble();
68         editor.componentDidAwake();
69
70         item.setComponentContainer(this);
71
72         awake();
73     }
74
75     public void awake() {
76
77     }
78
79     public abstract ComponentDocument createDocument();
80     public abstract ComponentEditor createEditor();
81
82     public void createMainMenuBar() {
83         if(mainMenuBar == null) {
84             mainMenuBar = XJMainMenuBar.createInstance();
85             mainMenuBar.setCustomizer(this);
86             mainMenuBar.setDelegate(this);
87             mainMenuBar.createMenuBar();
88         }
89     }
90
91     public XJMainMenuBar getMainMenuBar() {
92         if(mainMenuBar == null)
93             createMainMenuBar();
94         return mainMenuBar;
95     }
96
97     public ComponentEditor getEditor() {
98         return editor;
99     }
100
101     public XJDocument getDocument() {
102         return document;
103     }
104
105     public XJFrameInterface getXJFrame() {
106         return project.getXJFrame();
107     }
108
109     public void loadText(String JavaDoc text) {
110         editor.loadText(text);
111     }
112
113     public String JavaDoc getText() {
114         return editor.getText();
115     }
116
117     public void close() {
118         editor.close();
119         document.performClose(true);
120
121         if(getMainMenuBar() == getMainMenuBar()) {
122             // If the main menu bar is the one of the editor,
123
// the replace it by the default project menu bar.
124
project.setDefaultMainMenuBar();
125         }
126         XJMainMenuBar.removeInstance(getMainMenuBar());
127     }
128
129     public boolean willSaveDocument() {
130         return editor.componentDocumentWillSave();
131     }
132
133     public void setDirty() {
134         getDocument().setDirty(true);
135         project.fileDidBecomeDirty(this, item);
136     }
137
138     public static final String JavaDoc KEY_EDITOR_DATA = "KEY_EDITOR_DATA";
139
140     public void setPersistentData(Map JavaDoc data) {
141         if(data == null)
142             return;
143
144         getEditor().setPersistentData((Map JavaDoc)data.get(KEY_EDITOR_DATA));
145     }
146
147     public Map JavaDoc getPersistentData() {
148         Map JavaDoc<String JavaDoc, Map JavaDoc<String JavaDoc, Object JavaDoc>> data = new HashMap JavaDoc<String JavaDoc, Map JavaDoc<String JavaDoc, Object JavaDoc>>();
149         data.put(KEY_EDITOR_DATA, getEditor().getPersistentData());
150         return data;
151     }
152
153     /** Menu delegate and customizer
154      * Note:
155      * Because each project's file owns its main menu bar,
156      * we have to redirect every menu event to the project itself
157      * so it has a chance to handle them.
158      */

159
160     public void customizeFileMenu(XJMenu menu) {
161         project.customizeFileMenu(menu);
162         editor.customizeFileMenu(menu);
163     }
164
165     public void customizeEditMenu(XJMenu menu) {
166         project.customizeEditMenu(menu);
167         editor.customizeEditMenu(menu);
168     }
169
170     public void customizeWindowMenu(XJMenu menu) {
171         project.customizeWindowMenu(menu);
172         editor.customizeWindowMenu(menu);
173     }
174
175     public void customizeHelpMenu(XJMenu menu) {
176         project.customizeHelpMenu(menu);
177         editor.customizeHelpMenu(menu);
178     }
179
180     public void customizeMenuBar(XJMainMenuBar menubar) {
181         project.customizeMenuBar(menubar);
182         editor.customizeMenuBar(menubar);
183     }
184
185     public void menuItemState(XJMenuItem item) {
186         project.menuItemState(item);
187         editor.menuItemState(item);
188     }
189
190     public void handleMenuEvent(XJMenu menu, XJMenuItem item) {
191         project.handleMenuEvent(menu, item);
192     }
193
194     public void handleMenuSelected(XJMenu menu) {
195         project.handleMenuSelected(menu);
196     }
197
198 }
199
Popular Tags