1 19 20 package org.netbeans.modules.editor.bookmarks; 21 22 import java.awt.event.ActionEvent ; 23 import javax.swing.Action ; 24 import javax.swing.JEditorPane ; 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 40 41 public class WrapperBookmarkAction extends NodeAction { 42 43 static final long serialVersionUID = 0L; 44 45 private Action originalAction; 46 47 public WrapperBookmarkAction(Action originalAction) { 48 this.originalAction = originalAction; 49 putValue("noIconInMenu", Boolean.TRUE); } 53 54 public String getName() { 55 String name = (String )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 panes[] = ec.getOpenedPanes(); 65 if (panes != null && panes.length > 0) { 66 JEditorPane pane = panes[0]; 67 ActionEvent paneEvt = new ActionEvent (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 iconResource() { 87 return (String )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 |