001: /*
002: * Copyright (c) 2001, Jacob Smullyan.
003: *
004: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
005: * for the latest version.
006: *
007: * SkunkDAV is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License as published
009: * by the Free Software Foundation; either version 2, or (at your option)
010: * any later version.
011: *
012: * SkunkDAV is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with SkunkDAV; see the file COPYING. If not, write to the Free
019: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021: */
022: package org.skunk.swing.text.syntax;
023:
024: import java.util.Enumeration;
025: import javax.swing.SwingUtilities;
026: import javax.swing.event.DocumentEvent;
027: import javax.swing.event.DocumentListener;
028: import javax.swing.event.UndoableEditEvent;
029: import javax.swing.text.AbstractDocument;
030: import javax.swing.text.AttributeSet;
031: import javax.swing.text.BadLocationException;
032: import javax.swing.text.DefaultStyledDocument;
033: import javax.swing.text.Element;
034: import javax.swing.text.Segment;
035: import javax.swing.text.Style;
036: import javax.swing.text.StyleContext;
037: import javax.swing.text.StyledDocument;
038: import javax.swing.undo.AbstractUndoableEdit;
039: import javax.swing.undo.UndoableEdit;
040: import org.skunk.trace.Debug;
041: import org.skunk.util.GappedIntArray;
042:
043: public class SyntaxDocument extends DefaultStyledDocument {
044: private SyntaxContent content;
045:
046: public SyntaxDocument() {
047: super (new SyntaxContent(), StyleContext
048: .getDefaultStyleContext());
049: this .content = (SyntaxContent) getContent();
050: //an unfortunate hack -- content needs a reference to the document class, at least
051: //until the content class knows where line breaks are
052: content.setSyntaxDocument(this );
053: }
054:
055: public SyntaxTokenizer getSyntaxTokenizer() {
056: return content.getSyntaxTokenizer();
057: }
058:
059: public void setSyntaxTokenizer(SyntaxTokenizer syntaxTokenizer) {
060: content.setSyntaxTokenizer(syntaxTokenizer);
061: }
062:
063: public boolean isTokenizing() {
064: return content.isTokenizing();
065: }
066:
067: public void setTokenizing(boolean tokenizing) {
068: content.setTokenizing(tokenizing);
069: }
070:
071: protected final GappedIntArray getStyleBuffer() {
072: return content.getStyleBuffer();
073: }
074:
075: /**
076: * sets the file mode.
077: * @param mode the file mode
078: */
079: public void setFileMode(FileMode mode) {
080: content.setFileMode(mode);
081: }
082:
083: /**
084: * returns the file mode of this tokenizer.
085: * @return the file mode, or null if the tokenizer currently has no mode
086: */
087: public FileMode getFileMode() {
088: return content.getFileMode();
089: }
090:
091: public void retokenizeAll() {
092: if (isTokenizing())
093: getSyntaxTokenizer().tokenize(this , 0, getLength(), 0);
094: }
095: }
096:
097: /* $Log: SyntaxDocument.java,v $
098: /* Revision 1.17 2001/02/14 19:15:37 smulloni
099: /* modified usage of the style buffer to pack state information into its ints.
100: /* Previously, I had stipulated that a style could only be used in one state
101: /* per mode; that restriction may now be lifted.
102: /*
103: /* Revision 1.16 2001/02/11 22:55:39 smulloni
104: /* in order to capture undo and redo events, moving the style buffer and the
105: /* tokenizer into the SyntaxContent class, a subclass of GapContent.
106: /*
107: /* Revision 1.15 2001/02/09 20:00:01 smulloni
108: /* fixed particularly nasty bug in GappedIntArray.set(int, int[]), and other
109: /* bugs in the syntax highlighting system.
110: /*
111: /* Revision 1.14 2001/02/02 23:30:33 smulloni
112: /* adding customization features to the text editor.
113: /*
114: /* Revision 1.13 2001/01/30 23:03:19 smulloni
115: /* beginning of integration of syntax highlighting into SimpleTextEditor.
116: /*
117: /* Revision 1.12 2001/01/30 18:01:27 smulloni
118: /* first working beta of syntax highlighting. Nasty bug in
119: /* GappedIntArray.remove() fixed.
120: /*
121: /* Revision 1.11 2001/01/29 22:28:47 smulloni
122: /* syntax highlighting package now uses a custom view for painting the
123: /* highlights. Fixed bug in get(int, int[]) in GappedIntArray.
124: /*
125: /* Revision 1.10 2001/01/25 22:50:48 smulloni
126: /* integrating JFlex into still-broken syntax highlighting package.
127: /*
128: /* Revision 1.9 2001/01/20 00:16:07 smulloni
129: /* moved style buffer to SyntaxDocument class. I may move it out again.
130: /*
131: /* Revision 1.8 2001/01/18 22:29:21 smulloni
132: /* experimental work on syntax package.
133: /*
134: /* Revision 1.7 2001/01/17 23:02:29 smulloni
135: /* beginning to rework SyntaxDocument, SyntaxTokenizer, to shift the
136: /* responsibility for handling context requirements from the document
137: /* to the tokenizer.
138: /*
139: /* Revision 1.6 2001/01/16 21:13:24 smulloni
140: /* more work on syntax highlighting infrastructure.
141: /*
142: /* Revision 1.5 2001/01/15 23:31:29 smulloni
143: /* the syntax highlighting system crawls pitifully towards being less
144: /* contemptible.
145: /*
146: /* Revision 1.4 2001/01/12 23:30:06 smulloni
147: /* more hacking on syntax highlighting, which still sucks.
148: /*
149: /* Revision 1.3 2001/01/11 00:00:03 smulloni
150: /* work on syntax highlighting, still very rough.
151: /*
152: /* Revision 1.2 2000/12/28 21:58:57 smulloni
153: /* fiddling with syntax highlighting, not to much purpose.
154: /*
155: /* Revision 1.1 2000/12/27 22:05:09 smulloni
156: /* work on syntax highlighting.
157: /* */
|