001: package org.acm.seguin.completer.popup;
002:
003: //import anthelper.adapters.Plugin;
004: //import anthelper.adapters.Plugin;
005: import javax.swing.AbstractAction; //import anthelper.adapters.JIndexUtils;
006: //import anthelper.utils.SrcInfoUtils;
007: //import anthelper.JavaUtils;
008: import javax.swing.BoxLayout;
009: import org.acm.seguin.ide.jedit.Navigator;
010: import org.acm.seguin.completer.Completer;
011: import java.awt.*;
012: import java.awt.event.*;
013: import javax.swing.*;
014: import javax.swing.BoxLayout;
015: import javax.swing.Timer;
016: import javax.swing.border.*;
017: import javax.swing.event.*;
018: import org.gjt.sp.jedit.*;
019: import org.gjt.sp.jedit.gui.KeyEventWorkaround;
020: import org.gjt.sp.jedit.textarea.*;
021:
022: /**
023: * A popup offering some options about the code at point.
024: *
025: * @author btateyama@yahoo.com
026: * @created December 10, 2002
027: */
028: public class PointPopup extends BasePopup {
029: final static Navigator.NavigatorLogger logger = Completer
030: .getLogger(PointPopup.class);
031:
032: JMenuItem _miJavaDoc = null;
033: JMenuItem _miClassBrowser = null;
034: JMenuItem _miCopy = null;
035: JMenuItem _miCancel = null;
036: /**
037: * Description of the Field
038: */
039: protected String _strType = null;
040: /**
041: * Description of the Field
042: */
043: protected View _view;
044:
045: /**
046: * Constructor for the PointPopup object
047: *
048: * @param argView Description of the Parameter
049: * @param argType Description of the Parameter
050: */
051: public PointPopup(View argView, String argType) {
052: super (argView);
053: _view = argView;
054: _strType = argType;
055:
056: setContentPane(createRootPanel());
057: pack();
058:
059: Point point = PopupUtils.getPointOnTextArea(_view, "");
060: setLocation(point.x, point.y + 2);
061: }
062:
063: /**
064: * Description of the Method
065: */
066: protected void postShow() {
067: KeyHandler keyHandler = new KeyHandler();
068: addKeyListener(keyHandler);
069: _view.setKeyEventInterceptor(keyHandler);
070: }
071:
072: void handleByMnemonic(int argMnemonic) {
073: if (argMnemonic == 'D' || argMnemonic == 'd') {
074: //FIXME: if (Plugin.JINDEX.isInstalled()) {
075: //FIXME: JIndexUtils.lookUp(_view, _strType);
076: //FIXME: }
077: } else if (argMnemonic == 'B' || argMnemonic == 'b') {
078: //FIXME: JavaUtils.viewClassInfo(_view, _strType);
079: } else if (argMnemonic == 'C' || argMnemonic == 'c') {
080: Registers.setRegister('$', _strType);
081: logger.msg("Set register $", _strType);
082: } else if (argMnemonic == 'N' || argMnemonic == 'n') {
083: logger.msg("Closing");
084: }
085: }
086:
087: JPanel createRootPanel() {
088: _miJavaDoc = createMenuItem("Java doc (JIndex)", 'D');
089: _miJavaDoc.setEnabled(false); //FIXME: Plugin.JINDEX.isInstalled());
090: _miClassBrowser = createMenuItem("View in Class Browser", 'B');
091: _miCopy = createMenuItem("Copy", 'C');
092: _miCancel = createMenuItem("Cancel", 'N');
093:
094: JLabel labelType = new JLabel(" " + _strType);
095: labelType.setFont(labelType.getFont().deriveFont(Font.BOLD));
096: labelType.addMouseListener(new MouseHandler());
097:
098: // get the default, focus handling panel
099: JPanel panel = createMainPanel();
100: panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
101: panel.add(labelType);
102: panel.add(new JPopupMenu.Separator());
103: panel.add(_miClassBrowser);
104: panel.add(_miJavaDoc);
105: panel.add(new JPopupMenu.Separator());
106: panel.add(_miCopy);
107: panel.add(new JPopupMenu.Separator());
108: panel.add(_miCancel);
109:
110: return panel;
111: }
112:
113: JMenuItem createMenuItem(String argText, char argMnemonic) {
114: JMenuItem mi = new JMenuItem(argText);
115: mi.setMnemonic(argMnemonic);
116: mi.addActionListener(new AbstractAction() {
117: public void actionPerformed(ActionEvent argEvent) {
118: JMenuItem mi = (JMenuItem) argEvent.getSource();
119: handleByMnemonic(mi.getMnemonic());
120: dispose();
121: }
122: });
123: return mi;
124: }
125:
126: class KeyHandler extends KeyAdapter {
127: /**
128: * Description of the Method
129: *
130: * @param evt Description of the Parameter
131: */
132: public void keyPressed(KeyEvent evt) {
133:
134: handleByMnemonic(evt.getKeyChar());
135:
136: int iKeyCode = evt.getKeyCode();
137: if (PopupUtils.isCompleteWord(evt)) {
138: // this is a hack to execute complete word
139: iKeyCode = KeyEvent.VK_A;
140: }
141: switch (iKeyCode) {
142: case KeyEvent.VK_TAB:
143: case KeyEvent.VK_ESCAPE:
144: case KeyEvent.VK_UP:
145: case KeyEvent.VK_DOWN:
146: case KeyEvent.VK_ENTER:
147: case KeyEvent.VK_BACK_SPACE:
148: dispose();
149: evt.consume();
150: break;
151: default:
152: //logger.msg("default");
153: PopupUtils.processJEditCommand(_view, PointPopup.this ,
154: evt);
155: break;
156: }
157: }
158:
159: /**
160: * Description of the Method
161: *
162: * @param evt Description of the Parameter
163: */
164: public void keyTyped(KeyEvent evt) {
165: logger.msg("typed");
166: evt = KeyEventWorkaround.processKeyEvent(evt);
167: if (evt == null) {
168: return;
169: } else if (evt.getKeyChar() != '\b') {
170: // if char is not control character
171: //_textArea.userInput(ch);
172: }
173: dispose();
174: }
175: }
176:
177: class MouseHandler extends MouseAdapter {
178: /**
179: * Description of the Method
180: *
181: * @param evt Description of the Parameter
182: */
183: public void mouseClicked(MouseEvent evt) {
184: dispose();
185: }
186: }
187:
188: /**
189: * The main program for the PointPopup class
190: *
191: * @param args The command line arguments
192: */
193: public static void main(String[] args) {
194: try {
195: JFrame frame = new JFrame();
196: frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
197: frame.setSize(200, 200);
198: frame.setLocation(200, 200);
199: //frame.getContentPane().addMouseListener(new PopupListener());
200: frame.getContentPane().setLayout(
201: new BoxLayout(frame.getContentPane(),
202: BoxLayout.X_AXIS));
203: frame.getContentPane().add(new JButton("test1"));
204: frame.getContentPane().add(new JButton("test2"));
205: frame.getContentPane().add(new JButton("test3"));
206: frame.show();
207: } catch (Throwable t) {
208: t.printStackTrace();
209: }
210: }
211: }
|