KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.eclipse.ui.texteditor;
13
14
15 import java.util.ResourceBundle JavaDoc;
16
17 import org.eclipse.jface.text.IMarkRegionTarget;
18
19 /**
20  * An action to handle emacs-like marked regions.
21  *
22  * @since 2.0
23  */

24 public class MarkAction extends TextEditorAction {
25
26     /** Sets the mark. */
27     public static final int SET_MARK= 0;
28     /** Clears the mark. */
29     public static final int CLEAR_MARK= 1;
30     /** Swaps the mark and the cursor position. */
31     public static final int SWAP_MARK= 2;
32
33     /** The mark action type. */
34     private final int fType;
35
36     /**
37      * Constructor for MarkAction.
38      *
39      * @param bundle the resource bundle
40      * @param prefix a prefix to be prepended to the various resource keys
41      * (described in <code>ResourceAction</code> constructor), or
42      * <code>null</code> if none
43      * @param editor the text editor
44      * @param type the mark action type, must be one of
45      * <code>SET_MARK</code>, <code>CLEAR_MARK</code> or <code>SWAP_MARK</code>.
46      */

47     public MarkAction(ResourceBundle JavaDoc bundle, String JavaDoc prefix, ITextEditor editor, int type) {
48         super(bundle, prefix, editor);
49         fType= type;
50     }
51
52     /*
53      * @see IAction#run()
54      */

55     public void run() {
56
57         ITextEditor editor= getTextEditor();
58         if (editor == null)
59             return;
60
61         IMarkRegionTarget target= (IMarkRegionTarget) editor.getAdapter(IMarkRegionTarget.class);
62         if (target == null)
63             return;
64
65         switch (fType) {
66         case SET_MARK:
67             target.setMarkAtCursor(true);
68             break;
69
70         case CLEAR_MARK:
71             target.setMarkAtCursor(false);
72             break;
73
74         case SWAP_MARK:
75             target.swapMarkAndCursor();
76             break;
77         }
78     }
79 }
80
Popular Tags