KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > ext > ExtEditorUI


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.editor.ext;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import javax.swing.JPopupMenu JavaDoc;
24 import javax.swing.Action JavaDoc;
25 import javax.swing.text.JTextComponent JavaDoc;
26 import org.netbeans.editor.EditorUI;
27 import org.netbeans.editor.BaseKit;
28 import org.netbeans.editor.Utilities;
29 import org.netbeans.editor.PopupManager;
30
31
32 /**
33 * Editor UI for the component. All the additional UI features
34 * like advanced scrolling, info about fonts, abbreviations,
35 * keyword matching are based on this class.
36 *
37 * @author Miloslav Metelka
38 * @version 1.00
39 */

40 public class ExtEditorUI extends EditorUI {
41
42     private ToolTipSupport toolTipSupport;
43
44     private JPopupMenu JavaDoc popupMenu;
45
46     private Completion completion;
47     
48     private PopupManager popupManager;
49
50     private CompletionJavaDoc completionJavaDoc;
51     
52     private boolean noCompletion; // no completion available
53

54     private boolean noCompletionJavaDoc; // no completion available
55

56
57     
58     public ExtEditorUI() {
59
60         getToolTipSupport();
61         getCompletion();
62         getCompletionJavaDoc();
63     }
64
65     public ToolTipSupport getToolTipSupport() {
66         if (toolTipSupport == null) {
67             toolTipSupport = new ToolTipSupport(this);
68         }
69         return toolTipSupport;
70     }
71
72     public Completion getCompletion() {
73         
74         if (completion == null) {
75             if (noCompletion) {
76                 return null;
77             }
78
79             synchronized (getComponentLock()) {
80                 JTextComponent JavaDoc component = getComponent();
81                 if (component != null) {
82                     BaseKit kit = Utilities.getKit(component);
83                     if (kit != null && kit instanceof ExtKit) {
84                         completion = ((ExtKit)kit).createCompletion(this);
85                         if (completion == null) {
86                             noCompletion = true;
87                         }
88                     }
89                 }
90             }
91         }
92
93         return completion;
94     }
95
96     
97     public CompletionJavaDoc getCompletionJavaDoc() {
98         if (completionJavaDoc == null) {
99             if (noCompletionJavaDoc) {
100                 return null;
101             }
102
103             synchronized (getComponentLock()) {
104                 JTextComponent JavaDoc component = getComponent();
105                 if (component != null) {
106                     BaseKit kit = Utilities.getKit(component);
107                     if (kit != null && kit instanceof ExtKit) {
108                         completionJavaDoc = ((ExtKit)kit).createCompletionJavaDoc(this);
109                         if (completionJavaDoc == null) {
110                             noCompletionJavaDoc = true;
111                         }
112                     }
113                 }
114             }
115         }
116
117         return completionJavaDoc;
118     }
119     
120     
121     public PopupManager getPopupManager() {
122         if (popupManager == null) {
123
124             synchronized (getComponentLock()) {
125                 JTextComponent JavaDoc component = getComponent();
126                 if (component != null) {
127                     popupManager = new PopupManager(component);
128                 }
129             }
130         }
131
132         return popupManager;
133     }
134     
135
136     
137     public void showPopupMenu(int x, int y) {
138         // First call the build-popup-menu action to possibly rebuild the popup menu
139
JTextComponent JavaDoc component = getComponent();
140         if (component != null) {
141             BaseKit kit = Utilities.getKit(component);
142             if (kit != null) {
143                 Action JavaDoc a = kit.getActionByName(ExtKit.buildPopupMenuAction);
144                 if (a != null) {
145                     a.actionPerformed(new ActionEvent JavaDoc(component, 0, "")); // NOI18N
146
}
147             }
148
149             JPopupMenu JavaDoc pm = getPopupMenu();
150             if (pm != null) {
151                 if (component.isShowing()) { // fix of #18808
152
pm.show(component, x, y);
153                 }
154             }
155         }
156     }
157
158     public void hidePopupMenu() {
159         JPopupMenu JavaDoc pm = getPopupMenu();
160         if (pm != null) {
161             pm.setVisible(false);
162         }
163     }
164
165     public JPopupMenu JavaDoc getPopupMenu() {
166         return popupMenu;
167     }
168
169     public void setPopupMenu(JPopupMenu JavaDoc popupMenu) {
170         this.popupMenu = popupMenu;
171     }
172
173 }
174
Popular Tags