KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > components > text > CEditorText


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

43
44 public class CEditorText extends ComponentEditor implements ATEPanelDelegate {
45
46     protected ATEPanel textEditor;
47     protected ATELanguageSyntaxEngine syntaxEngine;
48
49     protected JLabel cursorLabel;
50
51     public CEditorText(ComponentContainer container) {
52         super(container);
53     }
54
55     public void create() {
56         syntaxEngine = createLanguageEngine();
57
58         textEditor = new ATEPanel(getXJFrame());
59         textEditor.setParserEngine(syntaxEngine);
60         textEditor.setSyntaxColoring(true);
61         textEditor.setAnalysisColumnVisible(false);
62         textEditor.setDelegate(this);
63         applyPrefs();
64
65         cursorLabel = new JLabel();
66
67         statusBar.add(Box.createHorizontalStrut(5));
68         statusBar.add(cursorLabel);
69         statusBar.add(Box.createHorizontalStrut(5));
70         statusBar.add(createSeparator());
71     }
72
73     public void assemble() {
74         mainPanel.add(textEditor, BorderLayout.CENTER);
75     }
76
77     public ATELanguageSyntaxEngine createLanguageEngine() {
78         return new ATELanguageSyntaxEngine();
79     }
80
81     public void applyPrefs() {
82         textEditor.setFoldingEnabled(AWPrefs.getFoldingEnabled());
83         textEditor.setLineNumberEnabled(AWPrefs.getLineNumberEnabled());
84         textEditor.setHighlightCursorLine(AWPrefs.getHighlightCursorEnabled());
85         textEditor.refresh();
86         applyFont();
87     }
88
89     public void applyFont() {
90         getTextPane().setFont(new Font(AWPrefs.getEditorFont(), Font.PLAIN, AWPrefs.getEditorFontSize()));
91         getTextPane().setTabSize(AWPrefs.getEditorTabSize());
92     }
93
94     public void loadText(String JavaDoc text) {
95         textEditor.loadText(text);
96     }
97
98     public String JavaDoc getText() {
99         return getTextPane().getText();
100     }
101
102     public void close() {
103         super.close();
104     }
105
106     public void notificationPrefsChanged() {
107         applyPrefs();
108     }
109
110     public void componentDocumentContentChanged() {
111         int oldCursorPosition = getTextPane().getCaretPosition();
112         getDocument().reload();
113         getTextPane().setCaretPosition(oldCursorPosition);
114     }
115
116     public void componentIsSelected() {
117         getTextPane().requestFocusInWindow();
118     }
119     
120     public ATETextPane getTextPane() {
121         return textEditor.getTextPane();
122     }
123
124     public void ateCaretUpdate(int index) {
125         cursorLabel.setText(textEditor.getCurrentLinePosition()+":"+textEditor.getCurrentColumnPosition());
126     }
127
128     public void ateChangeUpdate(int offset, int length, boolean insert) {
129         container.setDirty();
130     }
131
132     public void ateAutoIndent(int offset, int length) {
133     }
134
135     public void ateMousePressed(Point point) {
136     }
137
138     public void ateMouseExited() {
139     }
140
141     public void ateMouseMoved(Point relativePoint) {
142     }
143
144     public void ateInvokePopUp(Component component, int x, int y) {
145     }
146
147     public void ateParserWillParse() {
148     }
149
150     public void ateParserDidParse() {
151     }
152 }
153
Popular Tags