001: package org.acm.seguin.completer.popup;
002:
003: import org.acm.seguin.ide.jedit.Navigator;
004: import org.acm.seguin.completer.Completer;
005: import org.acm.seguin.completer.Completer;
006: import java.awt.*;
007: import java.awt.event.*;
008: import javax.swing.*;
009: import javax.swing.BoxLayout;
010: import javax.swing.Timer;
011: import javax.swing.border.*;
012: import javax.swing.event.*;
013: import org.gjt.sp.jedit.*;
014: import org.gjt.sp.jedit.gui.KeyEventWorkaround;
015: import org.gjt.sp.jedit.textarea.*;
016:
017: /**
018: * A message popup that will kill itself in a given time frame
019: *
020: * @author btateyama@yahoo.com
021: * @created December 10, 2002
022: */
023: public class SuicidalMsgPopup extends BasePopup {
024: final static Navigator.NavigatorLogger logger = Completer
025: .getLogger(SuicidalMsgPopup.class);
026:
027: String _strMsg = null;
028: int _iTimeToLiveMs = 1000;
029: Timer _timer = null;
030:
031: /**
032: * Constructor for the CodePopup object
033: */
034: public SuicidalMsgPopup(View argView, String argMsg,
035: int argTimeToLiveMs) {
036: this (argView, argMsg, argTimeToLiveMs, Color.yellow,
037: Color.black);
038: }
039:
040: /**
041: * Constructor for the CodePopup object
042: */
043: public SuicidalMsgPopup(View argView, String argMsg,
044: int argTimeToLiveMs, Color argBGColor, Color argFGColor) {
045:
046: super (argView);
047:
048: _view = argView;
049: _buffer = argView.getBuffer();
050: _textArea = argView.getTextArea();
051: _iTimeToLiveMs = argTimeToLiveMs;
052: _strMsg = argMsg;
053: _timer = new Timer(_iTimeToLiveMs, new ActionListener() {
054: public void actionPerformed(ActionEvent argEvent) {
055: dispose();
056: }
057: });
058:
059: setContentPane(createMainPanel());
060: getContentPane().add(
061: createLabel(argMsg, argBGColor, argFGColor),
062: BorderLayout.CENTER);
063: pack();
064:
065: Point point = PopupUtils.getPointOnTextArea(argView, "");
066: //point.x += 2;
067: point.y += 2;
068: setLocation(point);
069: }
070:
071: protected void postShow() {
072: KeyHandler keyHandler = new KeyHandler();
073: addKeyListener(keyHandler);
074: _view.setKeyEventInterceptor(keyHandler);
075: _timer.start();
076: }
077:
078: public void dispose() {
079: super .dispose();
080: _timer.stop();
081: }
082:
083: Component createLabel(String argText, Color argBGColor,
084: Color argFGColor) {
085:
086: JPanel panel = new JPanel();
087: panel.setLayout(new GridBagLayout());
088: panel.setBorder(BorderFactory.createLineBorder(argFGColor, 1));
089: panel.setBackground(argBGColor);
090:
091: //panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
092: GridBagConstraints c = new GridBagConstraints();
093: c.insets = new Insets(5, 5, 5, 5);
094: JLabel label = new JLabel(argText);
095: label.setForeground(argFGColor);
096: label.addMouseListener(new MouseHandler());
097: panel.add(label, c);
098: return panel;
099: }
100:
101: class KeyHandler extends KeyAdapter {
102: /**
103: * Description of the Method
104: *
105: * @param evt Description of the Parameter
106: */
107: public void keyPressed(KeyEvent evt) {
108: // spoof keycodes to extend functionality
109: int iKeyCode = evt.getKeyCode();
110: if (PopupUtils.isCompleteWord(evt)) {
111: // this is a hack to execute complete word
112: iKeyCode = KeyEvent.VK_A;
113: }
114:
115: /*
116: if (evt.isControlDown() || evt.isAltDown() ){
117: iKeyCode = KeyEvent.VK_ESCAPE;
118: }
119: */
120: switch (iKeyCode) {
121: case KeyEvent.VK_TAB:
122: case KeyEvent.VK_ESCAPE:
123: case KeyEvent.VK_UP:
124: case KeyEvent.VK_DOWN:
125: case KeyEvent.VK_ENTER:
126: dispose();
127: evt.consume();
128: break;
129: case KeyEvent.VK_BACK_SPACE:
130: _textArea.backspace();
131: dispose();
132: evt.consume();
133: break;
134: default:
135: /*
136: if (PopupUtils.processJEditCommand(_view, evt)){
137: dispose();
138: } else if (evt.isActionKey()) {
139: dispose();
140: _view.processKeyEvent(evt);
141: }
142: */
143: PopupUtils.processJEditCommand(_view,
144: SuicidalMsgPopup.this , evt);
145: break;
146: }
147: }
148:
149: /**
150: * Description of the Method
151: *
152: * @param evt Description of the Parameter
153: */
154: public void keyTyped(KeyEvent evt) {
155: char ch = evt.getKeyChar();
156: evt = KeyEventWorkaround.processKeyEvent(evt);
157: if (evt == null) {
158: return;
159: } else if (ch != '\b') {
160: // if char is not control character
161: _textArea.userInput(ch);
162: }
163: dispose();
164: }
165: }
166:
167: class MouseHandler extends MouseAdapter {
168: /**
169: * Description of the Method
170: *
171: * @param evt Description of the Parameter
172: */
173: public void mouseClicked(MouseEvent evt) {
174: dispose();
175: }
176: }
177: }
|