KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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
14 /**
15  * This event is sent to implementers of
16  * {@link org.eclipse.jface.text.ITextListener}. It represents a change applied
17  * to text viewer. The change is specified as a replace command using offset,
18  * length, inserted text, and replaced text. The text viewer issues a text event
19  * after the viewer has been changed either in response to a change of the
20  * viewer's document or when the viewer's visual content has been changed. In
21  * the first case, the text event also carries the original document event.
22  * Depending on the viewer's presentation mode, the text event coordinates are
23  * different from the document event's coordinates.
24  * <p>
25  * An empty text event usually indicates a change of the viewer's redraw state.</p>
26  * <p>
27  * Clients other than text viewer's don't create instances of this class.</p>
28  *
29  * @see org.eclipse.jface.text.ITextListener
30  * @see org.eclipse.jface.text.ITextViewer
31  * @see org.eclipse.jface.text.DocumentEvent
32  */

33 public class TextEvent {
34
35     /** Start offset of the change */
36     private int fOffset;
37     /** The length of the change */
38     private int fLength;
39     /** Inserted text */
40     private String JavaDoc fText;
41     /** Replaced text */
42     private String JavaDoc fReplacedText;
43     /** The original document event, may by null */
44     private DocumentEvent fDocumentEvent;
45     /**
46      * The redraw state of the viewer issuing this event
47      * @since 2.0
48      */

49     private boolean fViewerRedrawState;
50
51     /**
52      * Creates a new <code>TextEvent</code> based on the specification.
53      *
54      * @param offset the offset
55      * @param length the length
56      * @param text the inserted text
57      * @param replacedText the replaced text
58      * @param event the associated document event or <code>null</code> if none
59      * @param viewerRedrawState the redraw state of the viewer
60      */

61     protected TextEvent(int offset, int length, String JavaDoc text, String JavaDoc replacedText, DocumentEvent event, boolean viewerRedrawState) {
62         fOffset= offset;
63         fLength= length;
64         fText= text;
65         fReplacedText= replacedText;
66         fDocumentEvent= event;
67         fViewerRedrawState= viewerRedrawState;
68     }
69
70     /**
71      * Returns the offset of the event.
72      *
73      * @return the offset of the event
74      */

75     public int getOffset() {
76         return fOffset;
77     }
78
79     /**
80      * Returns the length of the event.
81      *
82      * @return the length of the event
83      */

84     public int getLength() {
85         return fLength;
86     }
87
88     /**
89      * Returns the text of the event.
90      *
91      * @return the text of the event
92      */

93     public String JavaDoc getText() {
94         return fText;
95     }
96
97     /**
98      * Returns the text replaced by this event.
99      *
100      * @return the text replaced by this event
101      */

102     public String JavaDoc getReplacedText() {
103         return fReplacedText;
104     }
105
106     /**
107      * Returns the corresponding document event that caused the viewer change
108      *
109      * @return the corresponding document event, <code>null</code> if a visual change only
110      */

111     public DocumentEvent getDocumentEvent() {
112         return fDocumentEvent;
113     }
114
115     /**
116      * Returns the viewer's redraw state.
117      *
118      * @return <code>true</code> if the viewer's redraw state is <code>true</code>
119      * @since 2.0
120      */

121     public boolean getViewerRedrawState() {
122         return fViewerRedrawState;
123     }
124 }
125
Popular Tags