KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > bookmarks > WrapperBookmarkAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.editor.bookmarks;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import javax.swing.Action JavaDoc;
24 import javax.swing.JEditorPane JavaDoc;
25 import org.netbeans.editor.BaseAction;
26 import org.netbeans.lib.editor.bookmarks.actions.ClearDocumentBookmarksAction;
27 import org.netbeans.lib.editor.bookmarks.actions.GotoBookmarkAction;
28 import org.netbeans.lib.editor.bookmarks.actions.ToggleBookmarkAction;
29 import org.openide.cookies.EditorCookie;
30 import org.openide.nodes.Node;
31 import org.openide.util.actions.NodeAction;
32
33
34 /**
35  * Action wrapping the bookmark actions.
36  *
37  * @author Miloslav Metelka
38  * @version 1.00
39  */

40
41 public class WrapperBookmarkAction extends NodeAction {
42     
43     static final long serialVersionUID = 0L;
44     
45     private Action JavaDoc originalAction;
46
47     public WrapperBookmarkAction(Action JavaDoc originalAction) {
48         this.originalAction = originalAction;
49         putValue("noIconInMenu", Boolean.TRUE); // NOI18N
50
// Re-add the property as SystemAction.putValue() is final
51
// putValue(BaseAction.ICON_RESOURCE_PROPERTY, getValue(BaseAction.ICON_RESOURCE_PROPERTY));
52
}
53     
54     public String JavaDoc getName() {
55         String JavaDoc name = (String JavaDoc)originalAction.getValue(Action.SHORT_DESCRIPTION);
56         assert (name != null);
57         return name;
58     }
59
60     public void performAction(Node[] activatedNodes) {
61         if (activatedNodes != null && activatedNodes.length == 1) {
62             EditorCookie ec = (EditorCookie)activatedNodes[0].getCookie(EditorCookie.class);
63             if (ec != null) {
64                 JEditorPane JavaDoc panes[] = ec.getOpenedPanes();
65                 if (panes != null && panes.length > 0) {
66                     JEditorPane JavaDoc pane = panes[0];
67                     ActionEvent JavaDoc paneEvt = new ActionEvent JavaDoc(pane, 0, "");
68                     originalAction.actionPerformed(paneEvt);
69                 }
70             }
71         }
72     }
73     
74     protected boolean enable(Node[] activatedNodes) {
75         return true;
76     }
77
78     public org.openide.util.HelpCtx getHelpCtx() {
79         return null;
80     }
81
82     protected boolean asynchronous() {
83         return false;
84     }
85
86     protected String JavaDoc iconResource() {
87         return (String JavaDoc)originalAction.getValue(BaseAction.ICON_RESOURCE_PROPERTY);
88     }
89
90     public static final class Next extends WrapperBookmarkAction {
91         
92         public Next() {
93             super(GotoBookmarkAction.createNext());
94         }
95
96     }
97
98     public static final class Previous extends WrapperBookmarkAction {
99         
100         public Previous() {
101             super(GotoBookmarkAction.createPrevious());
102         }
103
104     }
105
106     public static final class ClearDocumentBookmarks extends WrapperBookmarkAction {
107         
108         public ClearDocumentBookmarks() {
109             super(new ClearDocumentBookmarksAction());
110         }
111
112     }
113
114 }
115
116
Popular Tags