KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > editor > EditorView


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
21 package org.netbeans.modules.tasklist.editor;
22
23 import org.netbeans.editor.PopupManager;
24 import org.netbeans.editor.BaseTextUI;
25 import org.netbeans.editor.EditorUI;
26 import org.netbeans.editor.ext.ExtEditorUI;
27 import org.openide.windows.WindowManager;
28 import org.openide.windows.Mode;
29 import org.openide.windows.TopComponent;
30 import org.openide.text.CloneableEditor;
31 import org.openide.text.CloneableEditorSupport;
32 import org.openide.nodes.Node;
33 import org.openide.cookies.EditorCookie;
34
35 import javax.swing.text.JTextComponent JavaDoc;
36 import javax.swing.*;
37
38 /**
39  * Presents suggestions right in editor view.
40  *
41  * @author Petr Kuzel
42  */

43 public final class EditorView {
44
45     private EditorView() {
46
47     }
48
49     /** Show selected component if currently vissible editor. */
50     public static void show(JComponent component) {
51         Mode mode = WindowManager.getDefault().findMode(CloneableEditorSupport.EDITOR_MODE);
52         if (mode == null) return;
53         TopComponent tc = mode.getSelectedTopComponent();
54         Node[] nodes = tc.getActivatedNodes();
55         if (nodes == null) return;
56
57         EditorCookie cake = (EditorCookie) nodes[0].getCookie(EditorCookie.class);
58         JEditorPane[] panes = cake.getOpenedPanes();
59
60         PopupManager pop = getPopup(panes[0]);
61         pop.install(component);
62     }
63
64     private static PopupManager getPopup(JEditorPane pane) {
65         ExtEditorUI ui = getEditorUI(pane);
66         return ui.getPopupManager();
67     }
68
69     private static BaseTextUI getBaseTextUI(JEditorPane pane){
70         return (pane!=null)?(BaseTextUI)pane.getUI():null;
71     }
72
73     private static ExtEditorUI getEditorUI(JEditorPane pane){
74         BaseTextUI btui = getBaseTextUI(pane);
75         return (btui!=null) ? (ExtEditorUI)btui.getEditorUI() : null;
76     }
77
78 }
79
Popular Tags