Source Code Cross Referenced for KeyStrokeTest.java in  » UML » jrefactory » org » acm » seguin » completer » popup » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » UML » jrefactory » org.acm.seguin.completer.popup 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.acm.seguin.completer.popup;
002:
003:        import java.io.FileNotFoundException;
004:        import java.io.IOException;
005:        import org.acm.seguin.ide.jedit.Navigator;
006:        import org.acm.seguin.completer.Completer;
007:        import org.acm.seguin.completer.info.ClassInfo;
008:        import org.acm.seguin.completer.info.FieldInfo;
009:        import org.acm.seguin.completer.info.MemberInfo;
010:        import java.awt.Color;
011:        import java.awt.Graphics;
012:        import java.awt.Point;
013:        import java.awt.event.*;
014:        import java.awt.event.KeyAdapter;
015:        import java.awt.event.KeyEvent;
016:        import java.lang.reflect.Field;
017:        import java.util.Iterator;
018:        import java.util.Vector;
019:        import javax.swing.JComponent;
020:        import javax.swing.JFrame;
021:        import javax.swing.JPanel;
022:        import javax.swing.KeyStroke;
023:        import org.gjt.sp.jedit.Buffer;
024:        import org.gjt.sp.jedit.View;
025:        import org.gjt.sp.jedit.gui.DefaultInputHandler;
026:        import org.gjt.sp.jedit.gui.InputHandler;
027:        import org.gjt.sp.jedit.jEdit;
028:        import org.gjt.sp.jedit.textarea.JEditTextArea;
029:
030:        public class KeyStrokeTest {
031:            static final Navigator.NavigatorLogger logger = Navigator
032:                    .getLogger(KeyStrokeTest.class);
033:
034:            class TestKeyListener extends KeyAdapter {
035:
036:                public TestKeyListener() {
037:                }
038:
039:                public void keyPressed2(KeyEvent argEvent) {
040:                    logger.msg("-pressed", argEvent.hashCode());
041:                    int iKeyCode = argEvent.getKeyCode();
042:                    if (iKeyCode == KeyEvent.VK_C && argEvent.isControlDown()) {
043:                        logger.msg("Self destructing...");
044:                        jEdit.getActiveView().setKeyEventInterceptor(null);
045:                    } else if (argEvent.isAltDown()) {
046:                        logger.msg("yum");
047:                        argEvent.consume();
048:                    }
049:                }
050:
051:                public void keyTyped(KeyEvent argEvent) {
052:                    logger.msg("typed", argEvent.hashCode());
053:
054:                }
055:
056:                public void keyReleased(KeyEvent argEvent) {
057:                    logger.msg("released", argEvent.hashCode());
058:                }
059:
060:                public void keyPressed(KeyEvent argEvent) {
061:                    int iKeyCode = argEvent.getKeyCode();
062:                    if (iKeyCode == KeyEvent.VK_C && argEvent.isControlDown()) {
063:                        logger.msg("Self destructing...");
064:                        jEdit.getActiveView().setKeyEventInterceptor(null);
065:                    } else {
066:                        logger.msg("isCompleteWord", ""
067:                                + isCompleteWord(argEvent));
068:                        /*
069:
070:                        KeyStroke keyStroke = KeyStroke.getKeyStrokeForEvent(argEvent);
071:
072:                        DefaultInputHandler inputHandler = (DefaultInputHandler) jEdit.getActiveView().getInputHandler();
073:
074:                        inputHandler.keyPressed(argEvent);
075:
076:                        if (argEvent.isConsumed()){
077:
078:                            logger.msg("it ate it");
079:
080:                        }else{
081:
082:                            logger.msg("still ok");
083:
084:                        }
085:
086:                        StringBuffer sbBinding = new StringBuffer();
087:
088:                        sbBinding.append(DefaultInputHandler.getModifierString(argEvent));
089:
090:                        sbBinding.append("+");
091:
092:                        
093:
094:                        String strSym = getSymbolicName(argEvent.getKeyCode());
095:
096:                        if (strSym != null){
097:
098:                            sbBinding.append(strSym);
099:
100:                            Object obj = inputHandler.getKeyBinding(sbBinding.toString());
101:
102:                            if (obj != null){
103:
104:                                logger.msg("obj", obj.toString());
105:
106:                                logger.msg("obj", obj.getClass().getName());
107:
108:                            }else{
109:
110:                                logger.msg("obj is null");
111:
112:                            }
113:
114:                        }
115:
116:                        logger.msg("binding", sbBinding.toString());
117:
118:                         */
119:
120:                    }
121:
122:                }
123:
124:            }
125:
126:            static boolean isCompleteWord(KeyEvent argEvent) {
127:
128:                boolean bIsCompleteWord = false;
129:
130:                StringBuffer sbBinding = new StringBuffer();
131:
132:                sbBinding.append(DefaultInputHandler
133:                        .getModifierString(argEvent));
134:
135:                sbBinding.append("+");
136:
137:                String strSym = getSymbolicName(argEvent.getKeyCode());
138:
139:                if (strSym != null) {
140:
141:                    sbBinding.append(strSym);
142:
143:                    String strB = sbBinding.toString();
144:
145:                    bIsCompleteWord = (strB.equals(jEdit
146:                            .getProperty("complete-word.shortcut")) ||
147:
148:                    strB.equals(jEdit.getProperty("complete-word.shortcut2")));
149:
150:                    // hmm..we could also do a cross ref of actions
151:
152:                }
153:
154:                return bIsCompleteWord;
155:
156:            }
157:
158:            private static String getSymbolicName(int keyCode)
159:
160:            {
161:
162:                if (keyCode == KeyEvent.VK_UNDEFINED)
163:
164:                    return null;
165:
166:                /* else if(keyCode == KeyEvent.VK_OPEN_BRACKET)
167:
168:                	return "[";
169:
170:                else if(keyCode == KeyEvent.VK_CLOSE_BRACKET)
171:
172:                	return "]"; */
173:
174:                if (keyCode >= KeyEvent.VK_A && keyCode <= KeyEvent.VK_Z)
175:
176:                    return String
177:                            .valueOf(Character.toLowerCase((char) keyCode));
178:
179:                try
180:
181:                {
182:
183:                    Field[] fields = KeyEvent.class.getFields();
184:
185:                    for (int i = 0; i < fields.length; i++)
186:
187:                    {
188:
189:                        Field field = fields[i];
190:
191:                        String name = field.getName();
192:
193:                        if (name.startsWith("VK_")
194:
195:                        && field.getInt(null) == keyCode)
196:
197:                        {
198:
199:                            return name.substring(3);
200:
201:                        }
202:
203:                    }
204:
205:                }
206:
207:                catch (Exception e)
208:
209:                {
210:
211:                    logger.error("Error enum fields", e);
212:
213:                }
214:
215:                return null;
216:
217:            } //}}}
218:
219:            void testKeyStroke() {
220:
221:                View view = jEdit.getActiveView();
222:
223:                JEditTextArea textArea = view.getTextArea();
224:
225:                Buffer buffer = view.getBuffer();
226:
227:                view.setKeyEventInterceptor(new TestKeyListener());
228:
229:            }
230:
231:            void testFrame() {
232:
233:                JFrame frame = new JFrame() {
234:
235:                    public boolean isDoubleBuffered() {
236:                        return false;
237:                    }
238:
239:                };
240:
241:                JPanel panel = new JPanel() {
242:
243:                    public boolean isDoubleBuffered() {
244:                        return false;
245:                    }
246:
247:                };
248:
249:                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
250:
251:                frame.setLocation(200, 200);
252:
253:                frame.setSize(100, 100);
254:
255:                //frame.pack();
256:
257:                Color colorTest = new Color(255, 0, 0, 100);
258:
259:                frame.setBackground(colorTest);
260:
261:                frame.setContentPane(panel);
262:
263:                frame.getContentPane().setBackground(colorTest);
264:
265:                //frame.
266:
267:                frame.show();
268:
269:            }
270:
271:            void testFrame2() {
272:
273:                logger.msg("test frame 2");
274:
275:                View view = jEdit.getActiveView();
276:
277:                JEditTextArea textArea = view.getTextArea();
278:
279:                Point p = PopupUtils.getPointOnTextArea(view, "");
280:
281:                MyGlassPane glassPane = new MyGlassPane(view);
282:
283:                glassPane.setBackground(new Color(255, 0, 0, 100));
284:
285:                glassPane.setPoint(p);
286:
287:                view.setGlassPane(glassPane);
288:
289:                view.getGlassPane().setVisible(true);
290:
291:            }
292:
293:            class MyGlassPane extends JComponent implements  MouseListener {
294:
295:                JFrame _frame = null;
296:
297:                Point _point = null;
298:
299:                MyGlassPane(JFrame argFrame) {
300:
301:                    _frame = argFrame;
302:
303:                    addMouseListener(this );
304:
305:                }
306:
307:                public void paintComponent(Graphics g) {
308:
309:                    Color colorBG = new Color(0, 0, 255, 100);
310:
311:                    Color colorFG = new Color(255, 0, 255);
312:
313:                    g.setColor(colorBG);
314:
315:                    g.fillRect(_point.x, _point.y, 100, 100);
316:
317:                    g.setColor(colorFG);
318:
319:                    g.drawString("test", _point.x + 10, _point.y + 2
320:                            * g.getFontMetrics().getHeight());
321:
322:                    //g2.setComposite (AlphaComposite.getInstance (AlphaComposite.SRC_OVER, 0.55f));
323:
324:                    //g2.setColor (getBackground());
325:
326:                    //            g2.setColor (calcColor);
327:
328:                    //          g2.setColor(new Color(255, 0, 0, 100));
329:
330:                    //          g2.fill`Rect (0, 0, getWidth(), getLastComponentYBound());
331:
332:                    //          paintChildren(g2);
333:
334:                }
335:
336:                public void mousePressed(MouseEvent argEvent) {
337:
338:                    setVisible(false);
339:
340:                    //_frame.setGlassPane(null);
341:
342:                    logger.msg("killed");
343:
344:                }
345:
346:                public void setPoint(Point arg) {
347:
348:                    _point = arg;
349:
350:                }
351:
352:                public void mouseClicked(MouseEvent argEvent) {
353:                }
354:
355:                public void mouseReleased(MouseEvent argEvent) {
356:                }
357:
358:                public void mouseEntered(MouseEvent argEvent) {
359:                }
360:
361:                public void mouseExited(MouseEvent argEvent) {
362:                }
363:
364:            }
365:
366:            /**
367:
368:             * We have to provide our own glass pane so that it can paint.
369:
370:            
371:
372:            class MyGlassPane extends JComponent {
373:
374:            Point point;
375:
376:
377:
378:            public void paintComponent(Graphics g) {
379:
380:                Graphics2D g2 = (Graphics2D) g;
381:
382:                //g2.setComposite (AlphaComposite.getInstance (AlphaComposite.SRC_OVER, 0.55f));
383:
384:
385:
386:                //g2.setColor (getBackground());
387:
388:                //            g2.setColor (calcColor);
389:
390:            //          g2.setColor(new Color(255, 0, 0, 100));
391:
392:            //          g2.fillRect (0, 0, getWidth(), getLastComponentYBound());
393:
394:            //          paintChildren(g2);
395:
396:
397:
398:                 if (point != null) {
399:
400:                    g2.setComposite (AlphaComposite.getInstance (AlphaComposite.SRC_OVER, 0.60f));
401:
402:                    g2.setColor (new java.awt.Color (25,15,2));
403:
404:                    g2.fillRect (0, 0, getWidth(), getHeight());
405:
406:                    g2.setColor (java.awt.Color.lightGray);
407:
408:                    g2.drawRect (2, 2, getWidth()-4, getHeight()-4);
409:
410:                    g2.drawRect (3, 3, getWidth()-6, getHeight() -6);
411:
412:                    g2.setColor (java.awt.Color.yellow);
413:
414:                    g2.setComposite (AlphaComposite.getInstance (AlphaComposite.SRC, 1.0f));
415:
416:                    FontMetrics fm = g.getFontMetrics();
417:
418:                    int sw = fm.stringWidth("foobar");
419:
420:                    int sh = fm.getHeight();
421:
422:                    int ascent = fm.getAscent();
423:
424:                    g.drawRect(4, 4, sw + 10, sh + 10);
425:
426:                    g.drawString("foobar", 4, 4 + ascent + 5);
427:
428:                    //super.paint(g);
429:
430:                
431:
432:            //                g2.setColor(new Color(255, 0, 0, 100));
433:
434:            //                System.out.println(getWidth());
435:
436:            //                System.out.println(getLastComponentYBound());
437:
438:            //                g2.fillRect (point.x, point.y, getWidth(), 10);
439:
440:            //                //paintChildren(g2);
441:
442:            //                //g2.fillOval(point.x - 10, point.y - 10, 30, 30);
443:
444:                 }
445:
446:            }
447:
448:             */
449:
450:            public KeyStrokeTest() {
451:                try {
452:                    //testFrame();
453:                    testFrame2();
454:                    //testKeyStroke();
455:                } catch (Exception e) {
456:                    logger.error("Error testing JavaParser", e);
457:                }
458:            }
459:
460:            public static void main(String[] args) {
461:                try {
462:                } catch (Throwable t) {
463:                    t.printStackTrace();
464:                }
465:            }
466:
467:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.