Source Code Cross Referenced for PopupBox.java in  » Apache-Harmony-Java-SE » java-package » java » awt » 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 » Apache Harmony Java SE » java package » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Pavel Dolgov
019:         *
020:         * @version $Revision$
021:         */package java.awt;
022:
023:        import org.apache.harmony.awt.gl.MultiRectArea;
024:        import org.apache.harmony.awt.wtk.NativeWindow;
025:
026:        /**
027:         * Non-component window for displaying menus and drop-down lists
028:         */
029:        abstract class PopupBox {
030:
031:            NativeWindow nativeWindow;
032:
033:            final Dimension size = new Dimension();
034:            final Point location = new Point();
035:            private Window owner;
036:            private PopupBox parent;
037:            private PopupBox activeChild;
038:            private boolean visible;
039:            private ModalContext modalContext;
040:
041:            final Toolkit toolkit = Toolkit.getDefaultToolkit();
042:
043:            PopupBox() {
044:            }
045:
046:            void addNotify() {
047:                if (nativeWindow == null) {
048:                    nativeWindow = toolkit.createPopupNativeWindow(this );
049:                }
050:            }
051:
052:            void removeNotify() {
053:                if (nativeWindow != null) {
054:                    toolkit.removePopupNativeWindow(nativeWindow);
055:                    NativeWindow temp = nativeWindow;
056:                    nativeWindow = null;
057:                    temp.dispose();
058:                }
059:            }
060:
061:            Dimension getSize() {
062:                return new Dimension(size);
063:            }
064:
065:            int getHeight() {
066:                return getSize().height;
067:            }
068:
069:            Point getLocation() {
070:                return new Point(location);
071:            }
072:
073:            Point getScreenLocation() {
074:                return new Point(location);
075:            }
076:
077:            boolean contains(Point p) {
078:                Rectangle r = new Rectangle(getScreenLocation(), getSize());
079:                return r.contains(p);
080:            }
081:
082:            Window getOwner() {
083:                return owner;
084:            }
085:
086:            PopupBox getParent() {
087:                return parent;
088:            }
089:
090:            void setParent(PopupBox p) {
091:                parent = p;
092:            }
093:
094:            final PopupBox getActiveChild() {
095:                return activeChild;
096:            }
097:
098:            final NativeWindow getNativeWindow() {
099:                return nativeWindow;
100:            }
101:
102:            final boolean isVisible() {
103:                return visible;
104:            }
105:
106:            boolean isMenu() {
107:                return false;
108:            }
109:
110:            final void setModal(boolean modal) {
111:                if (modal) {
112:                    if (modalContext == null) {
113:                        modalContext = new ModalContext();
114:                    }
115:                } else {
116:                    if (modalContext != null) {
117:                        if (modalContext.isModalLoopRunning()) {
118:                            modalContext.endModalLoop();
119:                        }
120:                        modalContext = null;
121:                    }
122:                }
123:            }
124:
125:            final boolean isModal() {
126:                return modalContext != null;
127:            }
128:
129:            boolean isMenuBar() {
130:                return false;
131:            }
132:
133:            Rectangle calculateBounds() {
134:                return new Rectangle(location, size);
135:            }
136:
137:            void paint(MultiRectArea clipArea) {
138:                if (nativeWindow != null) {
139:                    Graphics gr = getGraphics(clipArea);
140:                    if (gr != null) {
141:                        paint(gr);
142:                    }
143:                    gr.dispose();
144:                }
145:            }
146:
147:            abstract void paint(Graphics gr);
148:
149:            /**
150:             * Mouse events handler
151:             * @param eventId - one of the MouseEvent.MOUSE_* constants
152:             * @param where - mouse location
153:             * @param mouseButton - mouse button that was pressed or released
154:             * @param when - event time
155:             * @param modifiers - input event modifiers
156:             */
157:            abstract void onMouseEvent(int eventId, Point where,
158:                    int mouseButton, long when, int modifiers, int wheelRotation);
159:
160:            /**
161:             * Keyboard events handler
162:             * @param eventId - one of the KeyEvent.KEY_* constants
163:             * @param vKey - the key code
164:             * @param when - event time
165:             * @param modifiers - input event modifiers
166:             */
167:            abstract void onKeyEvent(int eventId, int vKey, long when,
168:                    int modifiers);
169:
170:            /**
171:             * Determine if the pop-up box should be hidden if the mouse button was 
172:             * pressed at the <code>start</code> position 
173:             * and released at the <code>end</code> position
174:             * @param start - the location where mouse button was pressed
175:             * @param end - the location where mouse button was released
176:             * @return true if the pop-up box should be hidden; false otherwise 
177:             */
178:            boolean closeOnUngrab(Point start, Point end) {
179:                return true;
180:            }
181:
182:            /**
183:             * Pass the keyboard event to the topmost active pop-up box
184:             * @param eventId - one of the KeyEvent.KEY_* constants
185:             * @param vKey - the key code
186:             * @param when - event time
187:             * @param modifiers - input event modifiers
188:             */
189:            final void dispatchKeyEvent(int eventId, int vKey, long when,
190:                    int modifiers) {
191:                if (activeChild != null) {
192:                    activeChild
193:                            .dispatchKeyEvent(eventId, vKey, when, modifiers);
194:                } else {
195:                    onKeyEvent(eventId, vKey, when, modifiers);
196:                }
197:            }
198:
199:            void setDefaultCursor() {
200:                Cursor.getDefaultCursor().getNativeCursor().setCursor(
201:                        nativeWindow.getId());
202:            }
203:
204:            private void show(int x, int y, int w, int h) {
205:                visible = true;
206:                addNotify();
207:
208:                location.setLocation(x, y);
209:                size.setSize(w, h);
210:                nativeWindow.setBounds(x, y, w, h, 0);
211:                nativeWindow.setVisible(true);
212:                setDefaultCursor();
213:            }
214:
215:            void show(Frame owner) {
216:                this .owner = owner;
217:
218:                Rectangle bounds = calculateBounds();
219:                show(bounds.x, bounds.y, bounds.width, bounds.height);
220:            }
221:
222:            void show(Point location, Dimension size, Window owner) {
223:                this .owner = owner;
224:                if (parent != null) {
225:                    parent.activeChild = this ;
226:                }
227:                show(location.x, location.y, size.width, size.height);
228:
229:                toolkit.dispatcher.popupDispatcher.activate(this );
230:                if (modalContext != null) {
231:                    modalContext.runModalLoop();
232:                }
233:            }
234:
235:            void hide() {
236:                if (!visible) {
237:                    return;
238:                }
239:                visible = false;
240:
241:                if (activeChild != null) {
242:                    activeChild.hide();
243:                }
244:
245:                if (nativeWindow != null) {
246:                    nativeWindow.setVisible(false);
247:                }
248:
249:                if (parent != null) {
250:                    parent.activeChild = null;
251:                }
252:
253:                if (modalContext != null) {
254:                    modalContext.endModalLoop();
255:                }
256:
257:                toolkit.dispatcher.popupDispatcher.deactivate(this );
258:            }
259:
260:            Graphics getGraphics(MultiRectArea clip) {
261:                Dimension size = getSize();
262:                Graphics gr = toolkit.getGraphicsFactory().getGraphics2D(
263:                        nativeWindow, 0, 0, size.width, size.height);
264:                if (gr != null && clip != null) {
265:                    gr.setClip(clip);
266:                }
267:                return gr;
268:            }
269:
270:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.