Source Code Cross Referenced for HelpUtil.java in  » Project-Management » OpenProj » com » projity » help » 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 » Project Management » OpenProj » com.projity.help 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Sep 10, 2007
003:         *
004:         * Copyright 2004, Projity Inc.
005:         */
006:        package com.projity.help;
007:
008:        import java.awt.Component;
009:        import java.awt.Container;
010:        import java.awt.Frame;
011:        import java.awt.KeyEventDispatcher;
012:        import java.awt.KeyboardFocusManager;
013:        import java.awt.MouseInfo;
014:        import java.awt.Point;
015:        import java.awt.event.KeyEvent;
016:        import java.util.HashMap;
017:
018:        import javax.swing.JComponent;
019:        import javax.swing.JDialog;
020:        import javax.swing.table.JTableHeader;
021:
022:        import com.projity.configuration.Settings;
023:        import com.projity.field.Field;
024:        import com.projity.pm.graphic.IconManager;
025:        import com.projity.pm.graphic.spreadsheet.SpreadSheet;
026:        import com.projity.pm.graphic.spreadsheet.SpreadSheetModel;
027:        import com.projity.util.BrowserControl;
028:        import com.projity.util.Environment;
029:
030:        public class HelpUtil implements  KeyEventDispatcher {
031:            private HashMap<Component, String> map = new HashMap<Component, String>();
032:            private static HelpUtil instance = null;
033:            private static final int DELAY_BETWEEN_HELPS = 5000;
034:            private long lastHelpTime = 0L;
035:            public boolean noHelp = false;
036:
037:            private synchronized static HelpUtil getInstance() {
038:                if (instance == null)
039:                    instance = new HelpUtil();
040:                return instance;
041:            }
042:
043:            private HelpUtil() {
044:                noHelp = Environment.getOs() == Environment.MAC
045:                        && Environment.isApplet();
046:                if (noHelp)
047:                    System.out.print("no help");
048:                if (noHelp)
049:                    return;
050:                KeyboardFocusManager.getCurrentKeyboardFocusManager()
051:                        .addKeyEventDispatcher(this );
052:
053:            }
054:
055:            public static String helpTipImg = "<img src=\""
056:                    + IconManager.class
057:                            .getResource("/toolbarButtonGraphics/general/Information16.gif")
058:                    + "\"> F2";
059:            // a tooltip with a help icon and F1
060:            public static String helpTipHtml = "<html><img src=\""
061:                    + IconManager.class
062:                            .getResource("/toolbarButtonGraphics/general/Information16.gif")
063:                    + "\"> F2</html>";
064:
065:            public static void addHelp(Component c, String address) {
066:                if (getInstance().noHelp)
067:                    return;
068:                if (c instanceof  JComponent
069:                        && ((JComponent) c).getToolTipText() == null)
070:                    ((JComponent) c).setToolTipText(helpTipHtml);
071:                getInstance().map.put(c, address);
072:            }
073:
074:            public static void addDocHelp(Component c, String address) {
075:                addHelp(c, Settings.HELP_HOME + address);
076:            }
077:
078:            public static String findHelp(Component c) {
079:                if (getInstance().noHelp)
080:                    return null;
081:                String result = null;
082:                while (c != null) {
083:                    if ((result = getInstance().map.get(c)) != null)
084:                        break;
085:                    c = c.getParent();
086:                }
087:                return result;
088:            }
089:
090:            public static boolean doHelp(Component c) {
091:                if (getInstance().noHelp)
092:                    return false;
093:                String help = findHelp(c);
094:                if (help != null) {
095:                    long time = System.currentTimeMillis();
096:                    boolean doHelp = time - getInstance().lastHelpTime > DELAY_BETWEEN_HELPS;
097:                    getInstance().lastHelpTime = time;
098:
099:                    if (doHelp) { // prevents doubles which arrive for some reason
100:                        BrowserControl.displayURL(help);
101:                        return true;
102:                    }
103:                }
104:                return false;
105:            }
106:
107:            public static boolean doHelp() {
108:                if (getInstance().noHelp)
109:                    return false;
110:                Point pt = MouseInfo.getPointerInfo().getLocation();
111:                Component owner = KeyboardFocusManager
112:                        .getCurrentKeyboardFocusManager().getFocusOwner();
113:
114:                while (owner != null) { // get dialog or frame which is focus owner
115:                    if (owner instanceof  JDialog || owner instanceof  Frame) {
116:                        break;
117:                    }
118:                    owner = owner.getParent();
119:                }
120:                // Get component at point
121:                Component c = null;
122:                Point loc = owner.getLocationOnScreen();
123:                Point offsetPoint = new Point(pt.x - loc.x, pt.y - loc.y);
124:                c = ((Container) owner).findComponentAt(offsetPoint);
125:
126:                if (c == null)
127:                    c = owner;
128:
129:                // do help for most detailed item
130:                while (c != null) {
131:                    if (c instanceof  JTableHeader) { // if clicked on row header, see if there is help for the field
132:                        JTableHeader th = (JTableHeader) c;
133:                        loc = c.getLocationOnScreen();
134:                        offsetPoint = new Point(pt.x - loc.x, pt.y - loc.y);
135:                        int col = th.columnAtPoint(offsetPoint);
136:                        SpreadSheet ss = (SpreadSheet) th.getTable();
137:                        Field f = ((SpreadSheetModel) ss.getModel())
138:                                .getFieldInColumn(col + 1);
139:                        if (f.getHelp() != null) {
140:                            BrowserControl.displayURL(Settings.HELP_HOME
141:                                    + f.getHelp());
142:                            return true;
143:                        }
144:                    }
145:                    if (doHelp(c))
146:                        return true;
147:                    c = c.getParent();
148:                }
149:                return false;
150:
151:            }
152:
153:            public boolean dispatchKeyEvent(KeyEvent e) {
154:                if (noHelp)
155:                    return false;
156:                if ((e.getKeyCode() == KeyEvent.VK_F2 || e.getKeyCode() == KeyEvent.VK_F1)
157:                        && !e.isConsumed())
158:                    if (doHelp()) {
159:                        e.consume();
160:                        return true;
161:                    }
162:                return false;
163:            }
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.