129
|
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 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.text.DocumentClone;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17 import dwtx.core.runtime.Assert;
|
|
18
|
|
19
|
|
20 /**
|
|
21 * An {@link dwtx.jface.text.IDocument} that is a read-only clone of another document.
|
|
22 *
|
|
23 * @since 3.0
|
|
24 */
|
|
25 class DocumentClone : AbstractDocument {
|
|
26
|
|
27 private static class StringTextStore : ITextStore {
|
|
28
|
|
29 private String fContent;
|
|
30
|
|
31 /**
|
|
32 * Creates a new string text store with the given content.
|
|
33 *
|
|
34 * @param content the content
|
|
35 */
|
|
36 public StringTextStore(String content) {
|
|
37 Assert.isNotNull(content);
|
|
38 fContent= content;
|
|
39 }
|
|
40
|
|
41 /*
|
|
42 * @see dwtx.jface.text.ITextStore#get(int)
|
|
43 */
|
|
44 public char get(int offset) {
|
|
45 return fContent.charAt(offset);
|
|
46 }
|
|
47
|
|
48 /*
|
|
49 * @see dwtx.jface.text.ITextStore#get(int, int)
|
|
50 */
|
|
51 public String get(int offset, int length) {
|
|
52 return fContent.substring(offset, offset + length);
|
|
53 }
|
|
54
|
|
55 /*
|
|
56 * @see dwtx.jface.text.ITextStore#getLength()
|
|
57 */
|
|
58 public int getLength() {
|
|
59 return fContent.length();
|
|
60 }
|
|
61
|
|
62 /*
|
|
63 * @see dwtx.jface.text.ITextStore#replace(int, int, java.lang.String)
|
|
64 */
|
|
65 public void replace(int offset, int length, String text) {
|
|
66 }
|
|
67
|
|
68 /*
|
|
69 * @see dwtx.jface.text.ITextStore#set(java.lang.String)
|
|
70 */
|
|
71 public void set(String text) {
|
|
72 }
|
|
73
|
|
74 }
|
|
75
|
|
76 /**
|
|
77 * Creates a new document clone with the given content.
|
|
78 *
|
|
79 * @param content the content
|
|
80 * @param lineDelimiters the line delimiters
|
|
81 */
|
|
82 public DocumentClone(String content, String[] lineDelimiters) {
|
|
83 super();
|
|
84 setTextStore(new StringTextStore(content));
|
|
85 ConfigurableLineTracker tracker= new ConfigurableLineTracker(lineDelimiters);
|
|
86 setLineTracker(tracker);
|
|
87 getTracker().set(content);
|
|
88 completeInitialization();
|
|
89 }
|
|
90 }
|