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 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 text) { 95 textEditor.loadText(text); 96 } 97 98 public String 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 |