Skip to main content
summaryrefslogtreecommitdiffstats
blob: 22c1d30099f07f4053f75b25964c9e8dec8bc7c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**********************************************************************
Copyright (c) 2000, 2002 IBM Corp. and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Common Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/cpl-v10.html

Contributors:
    IBM Corporation - Initial implementation
**********************************************************************/

package org.eclipse.jface.text;


/**
 * This event is sent to implementers of <code>ITextListener</code>. It represents a 
 * change applied to text viewer. The change is specified as a replace command using 
 * offset, length, inserted text, and replaced text. The text viewer issues a text event
 * after the viewer has been changed either in response to a change of the viewer's document
 * or when the viewer's visual content has been changed. In the first case, the text event
 * also carries the original document event. Depending on the viewer's presentation mode,
 * the text event coordinates are different from the document event's coordinates.
 * Client's other than text viewer's don't create instances of this class.
 *
 * @see ITextListener
 * @see ITextViewer
 * @see DocumentEvent
 */
public class TextEvent {
	
	/** Start offset of the change */ 
	private int fOffset;
	/** The length of the change */
	private int fLength;
	/** Inserted text */
	private String fText;
	/** Replaced text */
	private String fReplacedText;
	/** The original document event, may by null */
	private DocumentEvent fDocumentEvent;
	/** 
	 * The redraw state of the viewer issuing this event
	 * @since 2.0
	 */
	private boolean fViewerRedrawState;
	
	/**
	 * Creates a new <code>TextEvent</code> based on the specification.
	 * 
	 * @param offset the offset
	 * @param length the length
	 * @param replacedText the replaced text
	 * @param event the associated document event or <code>null</code> if none
	 * @param viewerRedrawState the redraw state of the viewer
	 */
	protected TextEvent(int offset, int length, String text, String replacedText, DocumentEvent event, boolean viewerRedrawState) {
		fOffset= offset;
		fLength= length;
		fText= text;
		fReplacedText= replacedText;
		fDocumentEvent= event;
		fViewerRedrawState= viewerRedrawState;
	}
			
	/**
	 * Returns the offset of the event.
	 *
	 * @return the offset of the event
	 */
	public int getOffset() {
		return fOffset;
	}
		
	/**
	 * Returns the length of the event.
	 *
	 * @return the length of the event
	 */
	public int getLength() {
		return fLength;
	}
	
	/**
	 * Returns the text of the event.
	 *
	 * @return the text of the event
	 */
	public String getText() {
		return fText;
	}
	
	/**
	 * Returns the text replaced by this event.
	 *
	 * @return the text replaced by this event
	 */
	public String getReplacedText() {
		return fReplacedText;
	}
	
	/**
	 * Returns the corresponding document event that caused the viewer change
	 *
	 * @return the corresponding document event, <code>null</code> if a visual change only
	 */
	public DocumentEvent getDocumentEvent() {
		return fDocumentEvent;
	}
	
	/**
	 * Returns the viewer's redraw state.
	 * 
	 * @return <code>true</code> if the viewer's redraw state is <code>true</code>
	 * @since 2.0
	 */
	public boolean getViewerRedrawState() {
		return fViewerRedrawState;
	}
}

Back to the top