1 19 20 package org.netbeans.editor.ext; 21 22 import java.awt.event.ActionEvent ; 23 import javax.swing.JPopupMenu ; 24 import javax.swing.Action ; 25 import javax.swing.text.JTextComponent ; 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 40 public class ExtEditorUI extends EditorUI { 41 42 private ToolTipSupport toolTipSupport; 43 44 private JPopupMenu popupMenu; 45 46 private Completion completion; 47 48 private PopupManager popupManager; 49 50 private CompletionJavaDoc completionJavaDoc; 51 52 private boolean noCompletion; 54 private boolean noCompletionJavaDoc; 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 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 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 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 JTextComponent component = getComponent(); 140 if (component != null) { 141 BaseKit kit = Utilities.getKit(component); 142 if (kit != null) { 143 Action a = kit.getActionByName(ExtKit.buildPopupMenuAction); 144 if (a != null) { 145 a.actionPerformed(new ActionEvent (component, 0, "")); } 147 } 148 149 JPopupMenu pm = getPopupMenu(); 150 if (pm != null) { 151 if (component.isShowing()) { pm.show(component, x, y); 153 } 154 } 155 } 156 } 157 158 public void hidePopupMenu() { 159 JPopupMenu pm = getPopupMenu(); 160 if (pm != null) { 161 pm.setVisible(false); 162 } 163 } 164 165 public JPopupMenu getPopupMenu() { 166 return popupMenu; 167 } 168 169 public void setPopupMenu(JPopupMenu popupMenu) { 170 this.popupMenu = popupMenu; 171 } 172 173 } 174 | Popular Tags |