comparison dwtx/jface/text/DocumentEvent.d @ 129:eb30df5ca28b

Added JFace Text sources
author Frank Benoit <benoit@tionex.de>
date Sat, 23 Aug 2008 19:10:48 +0200
parents
children c4fb132a086c
comparison
equal deleted inserted replaced
128:8df1d4193877 129:eb30df5ca28b
1 /*******************************************************************************
2 * Copyright (c) 2000, 2008 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
14 module dwtx.jface.text.DocumentEvent;
15
16 import dwt.dwthelper.utils;
17
18 import dwtx.core.runtime.Assert;
19
20
21 /**
22 * Specification of changes applied to documents. All changes are represented as
23 * replace commands, i.e. specifying a document range whose text gets replaced
24 * with different text. In addition to this information, the event also contains
25 * the changed document.
26 *
27 * @see dwtx.jface.text.IDocument
28 */
29 public class DocumentEvent {
30
31 /**
32 * Debug option for asserting that text is not null.
33 * If the <code>dwtx.text/debug/DocumentEvent/assertTextNotNull</code>
34 * system property is <code>true</code>
35 *
36 * @since 3.3
37 */
38 private static final bool ASSERT_TEXT_NOT_NULL= Boolean.getBoolean("dwtx.text/debug/DocumentEvent/assertTextNotNull"); //$NON-NLS-1$
39
40 /** The changed document */
41 public IDocument fDocument;
42 /** The document offset */
43 public int fOffset;
44 /** Length of the replaced document text */
45 public int fLength;
46 /** Text inserted into the document */
47 public String fText= ""; //$NON-NLS-1$
48 /**
49 * The modification stamp of the document when firing this event.
50 * @since 3.1 and public since 3.3
51 */
52 public long fModificationStamp;
53
54 /**
55 * Creates a new document event.
56 *
57 * @param doc the changed document
58 * @param offset the offset of the replaced text
59 * @param length the length of the replaced text
60 * @param text the substitution text
61 */
62 public DocumentEvent(IDocument doc, int offset, int length, String text) {
63
64 Assert.isNotNull(doc);
65 Assert.isTrue(offset >= 0);
66 Assert.isTrue(length >= 0);
67
68 if (ASSERT_TEXT_NOT_NULL)
69 Assert.isNotNull(text);
70
71 fDocument= doc;
72 fOffset= offset;
73 fLength= length;
74 fText= text;
75
76 if (fDocument instanceof IDocumentExtension4)
77 fModificationStamp= ((IDocumentExtension4)fDocument).getModificationStamp();
78 else
79 fModificationStamp= IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP;
80 }
81
82 /**
83 * Creates a new, not initialized document event.
84 */
85 public DocumentEvent() {
86 }
87
88 /**
89 * Returns the changed document.
90 *
91 * @return the changed document
92 */
93 public IDocument getDocument() {
94 return fDocument;
95 }
96
97 /**
98 * Returns the offset of the change.
99 *
100 * @return the offset of the change
101 */
102 public int getOffset() {
103 return fOffset;
104 }
105
106 /**
107 * Returns the length of the replaced text.
108 *
109 * @return the length of the replaced text
110 */
111 public int getLength() {
112 return fLength;
113 }
114
115 /**
116 * Returns the text that has been inserted.
117 *
118 * @return the text that has been inserted
119 */
120 public String getText() {
121 return fText;
122 }
123
124 /**
125 * Returns the document's modification stamp at the
126 * time when this event was sent.
127 *
128 * @return the modification stamp or {@link IDocumentExtension4#UNKNOWN_MODIFICATION_STAMP}.
129 * @see IDocumentExtension4#getModificationStamp()
130 * @since 3.1
131 */
132 public long getModificationStamp() {
133 return fModificationStamp;
134 }
135
136 /*
137 * @see java.lang.Object#toString()
138 * @since 3.4
139 */
140 public String toString() {
141 StringBuffer buffer= new StringBuffer();
142 buffer.append("offset: " ); //$NON-NLS-1$
143 buffer.append(fOffset);
144 buffer.append(", length: " ); //$NON-NLS-1$
145 buffer.append(fLength);
146 buffer.append(", timestamp: " ); //$NON-NLS-1$
147 buffer.append(fModificationStamp);
148 buffer.append("\ntext:>" ); //$NON-NLS-1$
149 buffer.append(fText);
150 buffer.append("<\n" ); //$NON-NLS-1$
151 return buffer.toString();
152 }
153 }