KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.eclipse.jface.text;
12
13 import org.eclipse.core.runtime.Assert;
14
15
16 /**
17  * An {@link org.eclipse.jface.text.IDocument} that is a read-only clone of another document.
18  *
19  * @since 3.0
20  */

21 class DocumentClone extends AbstractDocument {
22
23     private static class StringTextStore implements ITextStore {
24
25         private String JavaDoc fContent;
26
27         /**
28          * Creates a new string text store with the given content.
29          *
30          * @param content the content
31          */

32         public StringTextStore(String JavaDoc content) {
33             Assert.isNotNull(content);
34             fContent= content;
35         }
36
37         /*
38          * @see org.eclipse.jface.text.ITextStore#get(int)
39          */

40         public char get(int offset) {
41             return fContent.charAt(offset);
42         }
43
44         /*
45          * @see org.eclipse.jface.text.ITextStore#get(int, int)
46          */

47         public String JavaDoc get(int offset, int length) {
48             return fContent.substring(offset, offset + length);
49         }
50
51         /*
52          * @see org.eclipse.jface.text.ITextStore#getLength()
53          */

54         public int getLength() {
55             return fContent.length();
56         }
57
58         /*
59          * @see org.eclipse.jface.text.ITextStore#replace(int, int, java.lang.String)
60          */

61         public void replace(int offset, int length, String JavaDoc text) {
62         }
63
64         /*
65          * @see org.eclipse.jface.text.ITextStore#set(java.lang.String)
66          */

67         public void set(String JavaDoc text) {
68         }
69
70     }
71
72     /**
73      * Creates a new document clone with the given content.
74      *
75      * @param content the content
76      * @param lineDelimiters the line delimiters
77      */

78     public DocumentClone(String JavaDoc content, String JavaDoc[] lineDelimiters) {
79         super();
80         setTextStore(new StringTextStore(content));
81         ConfigurableLineTracker tracker= new ConfigurableLineTracker(lineDelimiters);
82         setLineTracker(tracker);
83         getTracker().set(content);
84         completeInitialization();
85     }
86 }
87
Popular Tags