001: /*
002: * Sun Public License Notice
003: *
004: * The contents of this file are subject to the Sun Public License
005: * Version 1.0 (the "License"). You may not use this file except in
006: * compliance with the License. A copy of the License is available at
007: * http://www.sun.com/
008: *
009: * The Original Code is NetBeans. The Initial Developer of the Original
010: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
011: * Microsystems, Inc. All Rights Reserved.
012: */
013:
014: package org.netbeans.editor.ext;
015:
016: import java.awt.event.ActionEvent;
017:
018: import javax.swing.Action;
019: import javax.swing.JPopupMenu;
020: import javax.swing.text.JTextComponent;
021:
022: import org.netbeans.editor.BaseKit;
023: import org.netbeans.editor.EditorUI;
024: import org.netbeans.editor.Utilities;
025:
026: /**
027: * Editor UI for the component. All the additional UI features like advanced
028: * scrolling, info about fonts, abbreviations, keyword matching are based on
029: * this class.
030: *
031: * @author Miloslav Metelka
032: * @version 1.00
033: */
034: public class ExtEditorUI extends EditorUI {
035:
036: private ToolTipSupport toolTipSupport;
037:
038: private JPopupMenu popupMenu;
039:
040: private Completion completion;
041:
042: private boolean noCompletion; // no completion available
043:
044: public ExtEditorUI() {
045:
046: getToolTipSupport();
047: getCompletion();
048: }
049:
050: public ToolTipSupport getToolTipSupport() {
051: if (toolTipSupport == null) {
052: toolTipSupport = new ToolTipSupport(this );
053: }
054: return toolTipSupport;
055: }
056:
057: public Completion getCompletion() {
058: if (completion == null) {
059: if (noCompletion) {
060: return null;
061: }
062:
063: synchronized (getComponentLock()) {
064: JTextComponent component = getComponent();
065: if (component != null) {
066: BaseKit kit = Utilities.getKit(component);
067: if (kit != null && kit instanceof ExtKit) {
068: completion = ((ExtKit) kit)
069: .createCompletion(this );
070:
071: if (completion == null) {
072: noCompletion = true;
073: }
074: }
075: }
076: }
077: }
078:
079: return completion;
080: }
081:
082: public void showPopupMenu(int x, int y) {
083: // First call the build-popup-menu action to possibly rebuild the popup
084: // menu
085: JTextComponent component = getComponent();
086: if (component != null) {
087: BaseKit kit = Utilities.getKit(component);
088: if (kit != null) {
089: Action a = kit
090: .getActionByName(ExtKit.buildPopupMenuAction);
091: if (a != null) {
092: a
093: .actionPerformed(new ActionEvent(component,
094: 0, "")); // NOI18N
095: }
096: }
097:
098: JPopupMenu pm = getPopupMenu();
099: if (pm != null) {
100: if (component.isShowing()) { // fix of #18808
101: pm.show(component, x, y);
102: }
103: }
104: }
105: }
106:
107: public void hidePopupMenu() {
108: JPopupMenu pm = getPopupMenu();
109: if (pm != null) {
110: pm.setVisible(false);
111: }
112: }
113:
114: public JPopupMenu getPopupMenu() {
115: return popupMenu;
116: }
117:
118: public void setPopupMenu(JPopupMenu popupMenu) {
119: this.popupMenu = popupMenu;
120: }
121:
122: }
|