001: package org.acm.seguin.completer.popup;
002:
003: import org.acm.seguin.ide.jedit.Navigator.NavigatorLogger; //import anthelper.utils.ReflectUtils;
004: import org.acm.seguin.completer.Completer;
005:
006: import java.awt.*;
007: import java.awt.event.*;
008: import java.util.*;
009: import javax.swing.*;
010: import javax.swing.BoxLayout;
011: import javax.swing.event.*;
012: import org.gjt.sp.jedit.*;
013: import org.gjt.sp.jedit.View;
014: import org.gjt.sp.jedit.gui.KeyEventWorkaround;
015: import org.gjt.sp.jedit.textarea.*;
016:
017: /**
018: * The base popup
019: *
020: * @author btateyama@yahoo.com
021: * @created December 10, 2002
022: */
023: public abstract class BasePopup extends JWindow {
024: final static NavigatorLogger logger = Completer
025: .getLogger(BasePopup.class);
026:
027: /**
028: * Description of the Field
029: */
030: protected View _view = null;
031:
032: /**
033: * Description of the Field
034: */
035: protected JEditTextArea _textArea = null;
036: /**
037: * Description of the Field
038: */
039: protected Buffer _buffer = null;
040:
041: /**
042: * Constructor for the BasePopup object
043: *
044: * @param argView Description of the Parameter
045: */
046: protected BasePopup(View argView) {
047: super (argView);
048: _view = argView;
049: _buffer = argView.getBuffer();
050: _textArea = argView.getTextArea();
051: }
052:
053: JScrollPane createScrollPane(JList argList) {
054: // stupid scrollbar policy is an attempt to work around
055: // bugs people have been seeing with IBM's JDK -- 7 Sep 2000
056: JScrollPane scroller = new JScrollPane(argList,
057: JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
058: JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
059: //JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
060:
061: return scroller;
062: }
063:
064: protected JPanel createMainPanel() {
065: return new JPanel(new BorderLayout()) {
066: /**
067: * Returns if this component can be traversed by pressing the
068: * Tab key. This returns false.
069: *
070: * @return The managingFocus value
071: */
072: public boolean isManagingFocus() {
073: return true;
074: //false;
075: }
076:
077: /**
078: * Makes the tab key work in Java 1.4.
079: *
080: * @return The focusTraversalKeysEnabled value
081: */
082: public boolean getFocusTraversalKeysEnabled() {
083: return false;
084: }
085: };
086: }
087:
088: /**
089: * Called after super.show if popup is to be shown (i.e. no other visible popups)
090: */
091: protected abstract void postShow();
092:
093: /**
094: * Description of the Method
095: */
096: public void show() {
097: Completer dc = Completer.getDotCompleterForView(_view);
098: if (dc.lockPopup(this )) {
099: super .show();
100: postShow();
101: } else {
102: super .dispose();
103: }
104: }
105:
106: /**
107: * Dispose and unlock the popup
108: */
109: public void dispose() {
110: super .dispose();
111: try {
112: Completer dc = Completer.getDotCompleterForView(_view);
113: if (dc != null) {
114: // it will be null during final window closing
115: dc.unlockPopup(this );
116: } else {
117: logger.warning("DC for view (" + _view.getName()
118: + ") could not be found");
119: }
120: //DotCompletePlugin.getDotCompleterForView(_view).unlockPopup(this);
121: } catch (Exception e) {
122: logger.error("Error while disposing popup!", e);
123: } finally {
124: // do this last in finally since it can mess up focus if not done.
125: _view.setKeyEventInterceptor(null);
126: PopupUtils.requestFocusOnTextArea(_textArea);
127: }
128: }
129:
130: }
|