KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > Document


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jface.text;
13
14
15 /**
16  * Default document implementation. Uses a {@link org.eclipse.jface.text.GapTextStore} wrapped
17  * inside a {@link org.eclipse.jface.text.CopyOnWriteTextStore} as text store.
18  * <p>
19  * The used line tracker considers the following strings as line delimiters: "\n", "\r", "\r\n".
20  * </p>
21  * <p>
22  * The document is ready to use. It has a default position category for which a default position
23  * updater is installed.
24  * </p>
25  * <p>
26  * <strong>Performance:</strong> The implementation should perform reasonably well for typical
27  * source code documents. It is not designed for very large documents of a size of several
28  * megabytes. Space-saving implementations are initially used for both the text store and the line
29  * tracker; the first modification after a {@link #set(String) set} incurs the cost to transform the
30  * document structures to efficiently handle updates.
31  * </p>
32  * <p>
33  * See {@link GapTextStore} and <code>TreeLineTracker</code> for algorithmic behavior of the used
34  * document structures.
35  * </p>
36  *
37  * @see org.eclipse.jface.text.GapTextStore
38  * @see org.eclipse.jface.text.CopyOnWriteTextStore
39  */

40 public class Document extends AbstractDocument {
41     /**
42      * Creates a new empty document.
43      */

44     public Document() {
45         super();
46         setTextStore(new CopyOnWriteTextStore(new GapTextStore()));
47         setLineTracker(new DefaultLineTracker());
48         completeInitialization();
49     }
50
51     /**
52      * Creates a new document with the given initial content.
53      *
54      * @param initialContent the document's initial content
55      */

56     public Document(String JavaDoc initialContent) {
57         super();
58         setTextStore(new CopyOnWriteTextStore(new GapTextStore()));
59         setLineTracker(new DefaultLineTracker());
60         getStore().set(initialContent);
61         getTracker().set(initialContent);
62         completeInitialization();
63     }
64 }
65
Popular Tags