KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > texteditor > TextNavigationAction


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
12
13 package org.eclipse.ui.texteditor;
14
15
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.custom.StyledText;
18 import org.eclipse.swt.events.HelpListener;
19 import org.eclipse.swt.graphics.Point;
20 import org.eclipse.swt.widgets.Event;
21
22 import org.eclipse.jface.action.Action;
23 import org.eclipse.jface.action.IMenuCreator;
24 import org.eclipse.jface.resource.ImageDescriptor;
25 import org.eclipse.jface.util.IPropertyChangeListener;
26
27
28 /**
29  * An <code>Action</code> wrapper for text widget navigation and selection actions.
30  * @since 2.0
31  */

32 public class TextNavigationAction extends Action {
33
34     /** The text widget */
35     private StyledText fTextWidget;
36     /** The styled text action id */
37     private int fAction;
38     /** The action's action id */
39     private String JavaDoc fActionId;
40     /** This action's action definition id */
41     private String JavaDoc fActionDefinitionId;
42
43
44     /**
45      * Creates a new <code>TextNavigationAction</code>.
46      * @param textWidget the text widget
47      * @param action the styled text widget action
48      */

49     public TextNavigationAction(StyledText textWidget, int action) {
50         fTextWidget= textWidget;
51         fAction= action;
52     }
53
54     /**
55      * Returns the text widget this actions is bound to.
56      *
57      * @return returns the text widget this actions is bound to
58      */

59     protected StyledText getTextWidget() {
60         return fTextWidget;
61     }
62
63     /*
64      * @see IAction#run()
65      */

66     public void run() {
67         Point selection= fTextWidget.getSelection();
68         fTextWidget.invokeAction(fAction);
69         fireSelectionChanged(selection);
70     }
71
72     private void doFireSelectionChanged(Point selection) {
73         Event event= new Event();
74         event.x= selection.x;
75         event.y= selection.y;
76         fTextWidget.notifyListeners(SWT.Selection, event);
77     }
78
79     /**
80      * Sends a selection event with the current selection to all
81      * selection listeners of the action's text widget
82      *
83      * @since 3.0
84      */

85     protected void fireSelectionChanged() {
86         fireSelectionChanged(null);
87     }
88
89     /**
90      * Fires a selection event to all selection listener of the action's
91      * text widget if the current selection differs from the given selection.
92      *
93      * @param oldSelection the old selection
94      * @since 3.0
95      */

96     protected void fireSelectionChanged(Point oldSelection) {
97         Point selection= fTextWidget.getSelection();
98         if (oldSelection == null || !selection.equals(oldSelection))
99             doFireSelectionChanged(selection);
100     }
101
102     /*
103      * @see IAction#runWithEvent(Event)
104      */

105     public void runWithEvent(Event event) {
106         run();
107     }
108
109     /*
110      * @see IAction#setActionDefinitionId(String)
111      */

112     public void setActionDefinitionId(String JavaDoc id) {
113         fActionDefinitionId= id;
114     }
115
116     /*
117      * @see IAction#getActionDefinitionId()
118      */

119     public String JavaDoc getActionDefinitionId() {
120         return fActionDefinitionId;
121     }
122
123     /*
124      * @see IAction#setId(String)
125      */

126     public void setId(String JavaDoc id) {
127         fActionId= id;
128     }
129
130     /*
131      * @see IAction#getId()
132      */

133     public String JavaDoc getId() {
134         return fActionId;
135     }
136
137
138 // ----------------------------------------------------------------------------------------------------------------------------------
139
// All the subsequent methods are just empty method bodies.
140

141     /*
142      * @see IAction#addPropertyChangeListener(IPropertyChangeListener)
143      */

144     public void addPropertyChangeListener(IPropertyChangeListener listener) {
145     }
146
147     /*
148      * @see IAction#getAccelerator()
149      */

150     public int getAccelerator() {
151         return 0;
152     }
153
154     /*
155      * @see IAction#getDescription()
156      */

157     public String JavaDoc getDescription() {
158         return null;
159     }
160
161     /*
162      * @see IAction#getDisabledImageDescriptor()
163      */

164     public ImageDescriptor getDisabledImageDescriptor() {
165         return null;
166     }
167
168     /*
169      * @see IAction#getHelpListener()
170      */

171     public HelpListener getHelpListener() {
172         return null;
173     }
174
175     /*
176      * @see IAction#getHoverImageDescriptor()
177      */

178     public ImageDescriptor getHoverImageDescriptor() {
179         return null;
180     }
181
182     /*
183      * @see IAction#getImageDescriptor()
184      */

185     public ImageDescriptor getImageDescriptor() {
186         return null;
187     }
188
189     /*
190      * @see IAction#getMenuCreator()
191      */

192     public IMenuCreator getMenuCreator() {
193         return null;
194     }
195
196     /*
197      * @see IAction#getStyle()
198      */

199     public int getStyle() {
200         return 0;
201     }
202
203     /*
204      * @see IAction#getText()
205      */

206     public String JavaDoc getText() {
207         return null;
208     }
209
210     /*
211      * @see IAction#getToolTipText()
212      */

213     public String JavaDoc getToolTipText() {
214         return null;
215     }
216
217     /*
218      * @see IAction#isChecked()
219      */

220     public boolean isChecked() {
221         return false;
222     }
223
224     /*
225      * @see IAction#isEnabled()
226      */

227     public boolean isEnabled() {
228         return true;
229     }
230
231     /*
232      * @see IAction#removePropertyChangeListener(IPropertyChangeListener)
233      */

234     public void removePropertyChangeListener(IPropertyChangeListener listener) {
235     }
236
237     /*
238      * @see org.eclipse.jface.action.IAction#setAccelerator(int)
239      */

240     public void setAccelerator(int keycode) {
241     }
242
243     /*
244      * @see IAction#setChecked(boolean)
245      */

246     public void setChecked(boolean checked) {
247     }
248
249     /*
250      * @see IAction#setDescription(String)
251      */

252     public void setDescription(String JavaDoc text) {
253     }
254
255     /*
256      * @see IAction#setDisabledImageDescriptor(ImageDescriptor)
257      */

258     public void setDisabledImageDescriptor(ImageDescriptor newImage) {
259     }
260
261     /*
262      * @see IAction#setEnabled(boolean)
263      */

264     public void setEnabled(boolean enabled) {
265     }
266
267     /*
268      * @see IAction#setHelpListener(HelpListener)
269      */

270     public void setHelpListener(HelpListener listener) {
271     }
272
273     /*
274      * @see IAction#setHoverImageDescriptor(ImageDescriptor)
275      */

276     public void setHoverImageDescriptor(ImageDescriptor newImage) {
277     }
278
279     /*
280      * @see IAction#setImageDescriptor(ImageDescriptor)
281      */

282     public void setImageDescriptor(ImageDescriptor newImage) {
283     }
284
285     /*
286      * @see IAction#setMenuCreator(IMenuCreator)
287      */

288     public void setMenuCreator(IMenuCreator creator) {
289     }
290
291     /*
292      * @see IAction#setText(String)
293      */

294     public void setText(String JavaDoc text) {
295     }
296
297     /*
298      * @see IAction#setToolTipText(String)
299      */

300     public void setToolTipText(String JavaDoc text) {
301     }
302 }
303
Popular Tags