KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > components > grammar > CContainerGrammar


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

31
32 package org.antlr.works.components.grammar;
33
34 import org.antlr.xjlib.appkit.frame.XJFrameInterface;
35 import org.antlr.xjlib.appkit.frame.XJWindow;
36 import org.antlr.xjlib.appkit.menu.XJMainMenuBar;
37 import org.antlr.xjlib.appkit.menu.XJMenu;
38 import org.antlr.xjlib.appkit.menu.XJMenuItem;
39 import org.antlr.xjlib.appkit.app.XJApplication;
40 import org.antlr.works.components.ComponentContainer;
41 import org.antlr.works.components.ComponentEditor;
42 import org.antlr.works.prefs.AWPrefs;
43
44 import javax.swing.*;
45 import java.awt.*;
46 import java.util.Map JavaDoc;
47
48 public class CContainerGrammar extends XJWindow implements ComponentContainer {
49
50     protected ComponentEditor editor;
51
52     public CContainerGrammar() {
53         editor = new CEditorGrammar(this);
54         editor.create();
55         editor.assemble();
56
57         JPanel panel = new JPanel(new BorderLayout());
58         panel.add(editor.getToolbarComponent(), BorderLayout.NORTH);
59         panel.add(editor.getPanel(), BorderLayout.CENTER);
60         panel.add(editor.getStatusComponent(), BorderLayout.SOUTH);
61
62         getContentPane().add(panel);
63
64         pack();
65     }
66
67     public String JavaDoc autosaveName() {
68         if(AWPrefs.getRestoreWindows())
69             return getDocument().getDocumentPath();
70         else
71             return null;
72     }
73
74     public void setDefaultSize() {
75         if(XJApplication.shared().useDesktopMode()) {
76             super.setDefaultSize();
77             return;
78         }
79
80         Rectangle r = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
81         r.width *= 0.8;
82         r.height *= 0.8;
83         getRootPane().setPreferredSize(r.getSize());
84     }
85
86     public void loadText(String JavaDoc text) {
87         editor.loadText(text);
88     }
89
90     public String JavaDoc getText() {
91         return editor.getText();
92     }
93
94     public boolean willSaveDocument() {
95         return editor.componentDocumentWillSave();
96     }
97
98     public void close() {
99         editor.close();
100         super.close();
101     }
102
103     public void setPersistentData(Map JavaDoc data) {
104     }
105
106     public Map JavaDoc getPersistentData() {
107         return null;
108     }
109
110     public void becomingVisibleForTheFirstTime() {
111         editor.componentDidAwake();
112         editor.componentShouldLayout(getSize());
113     }
114
115     public ComponentEditor getEditor() {
116         return editor;
117     }
118
119     public XJFrameInterface getXJFrame() {
120         return this;
121     }
122
123     public void customizeFileMenu(XJMenu menu) {
124         editor.customizeFileMenu(menu);
125     }
126
127     public void customizeWindowMenu(XJMenu menu) {
128         editor.customizeWindowMenu(menu);
129     }
130
131     public void customizeHelpMenu(XJMenu menu) {
132         editor.customizeHelpMenu(menu);
133     }
134
135     public void customizeMenuBar(XJMainMenuBar menubar) {
136         editor.customizeMenuBar(menubar);
137     }
138
139     public void menuItemState(XJMenuItem item) {
140         super.menuItemState(item);
141         editor.menuItemState(item);
142     }
143
144     public void handleMenuSelected(XJMenu menu) {
145         super.handleMenuSelected(menu);
146         editor.handleMenuSelected(menu);
147     }
148
149     public void windowActivated() {
150         super.windowActivated();
151         editor.componentActivated();
152     }
153
154     public void windowDocumentPathDidChange() {
155         // Called when the document associated file has changed on the disk
156
editor.componentDocumentContentChanged();
157     }
158
159 }
160
Popular Tags