Source Code Cross Referenced for LinuxWindowFactory.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » awt » wtk » linux » 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 » org package » org.apache.harmony.awt.wtk.linux 
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 Michael Danilov
019:         * @version $Revision$
020:         */package org.apache.harmony.awt.wtk.linux;
021:
022:        import java.awt.Dimension;
023:        import java.awt.Frame;
024:        import java.awt.Point;
025:        import java.util.Collections;
026:        import java.util.HashMap;
027:        import java.util.Map;
028:
029:        import org.apache.harmony.awt.nativebridge.CLongPointer;
030:        import org.apache.harmony.awt.nativebridge.Int32Pointer;
031:        import org.apache.harmony.awt.nativebridge.Int8Pointer;
032:        import org.apache.harmony.awt.nativebridge.NativeBridge;
033:        import org.apache.harmony.awt.nativebridge.linux.X11;
034:        import org.apache.harmony.awt.nativebridge.linux.X11Defs;
035:        import org.apache.harmony.awt.wtk.CreationParams;
036:        import org.apache.harmony.awt.wtk.NativeWindow;
037:        import org.apache.harmony.awt.wtk.WindowFactory;
038:
039:        public final class LinuxWindowFactory implements  WindowFactory {
040:
041:            private static final X11 x11 = X11.getInstance();
042:            private static final NativeBridge bridge = NativeBridge
043:                    .getInstance();
044:
045:            private final XServerConnection xConnection = XServerConnection
046:                    .getInstance();
047:            private final long display = xConnection.getDisplay();
048:            private final int screen = xConnection.getScreen();
049:            final WindowManager wm;
050:
051:            private final long javaWindow;
052:            private final LinuxWindowMap allWindows = new LinuxWindowMap();
053:
054:            /**
055:             * Returns current root window id.
056:             * @return root window id
057:             */
058:            long getRootWindow() {
059:                return x11.XRootWindow(display, screen);
060:            }
061:
062:            public long getDisplay() {
063:                return display;
064:            }
065:
066:            public int getScreen() {
067:                return screen;
068:            }
069:
070:            public long getDisplayImpl() {
071:                return display;
072:            }
073:
074:            public int getScreenImpl() {
075:                return screen;
076:            }
077:
078:            public LinuxWindowFactory() {
079:                javaWindow = x11.XCreateSimpleWindow(display, x11
080:                        .XDefaultRootWindow(display), 0, 0, 1, 1, 0, 0, 0);
081:                x11.XSelectInput(display, javaWindow,
082:                        X11Defs.StructureNotifyMask);
083:
084:                long rootWindow = getRootWindow();
085:                X11.XWindowAttributes attributes = x11
086:                        .createXWindowAttributes(false);
087:                x11.XGetWindowAttributes(display, rootWindow, attributes);
088:                x11.XSelectInput(display, rootWindow, attributes
089:                        .get_your_event_mask()
090:                        | X11Defs.StructureNotifyMask);
091:
092:                wm = new WindowManager(this );
093:            }
094:
095:            public NativeWindow createWindow(CreationParams p) {
096:                LinuxWindow lw = new LinuxWindow(this , p);
097:                allWindows.put(lw);
098:                if (!lw.isChild() && !lw.isUndecorated()) {
099:                    p.child = true;
100:                    p.parentId = lw.getId();
101:                    p.x = 0;
102:                    p.y = 0;
103:                    ContentWindow cw = new ContentWindow(this , p);
104:                    allWindows.put(cw);
105:                    lw.setContentWindow(cw);
106:                    lw = cw;
107:                }
108:                x11.XFlush(display);
109:                return lw;
110:            }
111:
112:            public NativeWindow getWindowById(long id) {
113:                return allWindows.get(id);
114:            }
115:
116:            boolean validWindowId(long id) {
117:                return allWindows.contains(id);
118:            }
119:
120:            void onWindowDispose(long windowID) {
121:                allWindows.remove(windowID);
122:            }
123:
124:            public String getAtomName(long atom) {
125:                long atomNamePtr = x11.XGetAtomName(display, atom);
126:                Int8Pointer rawName = bridge.createInt8Pointer(atomNamePtr);
127:                String atomName = rawName.getStringUTF();
128:                x11.XFree(atomNamePtr);
129:
130:                return atomName;
131:            }
132:
133:            public long internAtom(String name) {
134:                return x11.XInternAtom(display, name, 0);
135:            }
136:
137:            /**
138:             * @see org.apache.harmony.awt.wtk.WindowFactory#getWindowFromPoint(java.awt.Point)
139:             */
140:            public NativeWindow getWindowFromPoint(Point p) {
141:                long rootID = getRootWindow();
142:                long childID = rootID;
143:                Int32Pointer x = bridge.createInt32Pointer(1, false);
144:                Int32Pointer y = bridge.createInt32Pointer(1, false);
145:                CLongPointer childWindow = bridge.createCLongPointer(1, false);
146:
147:                //recursevily ask for child containing p
148:                //until the deepest child is found
149:                //or until our top-level window is found
150:                while (childID != X11Defs.None) {
151:                    x11.XTranslateCoordinates(display, rootID, childID, p.x,
152:                            p.y, x, y, childWindow);
153:                    long nextID = childWindow.get(0);
154:                    // avoid endless loop
155:                    if (childID == nextID) {
156:                        return null;
157:                    }
158:                    childID = nextID;
159:                    if (validWindowId(childID)) {
160:                        break;
161:                    }
162:                }
163:
164:                LinuxWindow win = ((childID != 0) ? (LinuxWindow) getWindowById(childID)
165:                        : null);
166:                if (win != null) {
167:                    LinuxWindow content = win.getContentWindow();
168:                    if ((content != null) && validWindowId(content.getId())) {
169:                        return content;
170:                    }
171:                }
172:                return win;
173:
174:            }
175:
176:            public boolean isWindowStateSupported(int state) {
177:                switch (state) {
178:                case Frame.NORMAL:
179:                case Frame.ICONIFIED:
180:                case Frame.MAXIMIZED_BOTH:
181:                    return true;
182:                default:
183:                    return false;
184:                }
185:            }
186:
187:            public NativeWindow attachWindow(long nativeWindowId) {
188:                return new LinuxWindow(nativeWindowId, this );
189:            }
190:
191:            public void setCaretPosition(int x, int y) {
192:            }
193:
194:            /**
195:             * @see org.apache.harmony.awt.wtk.WindowFactory#getWindowSizeById(long)
196:             */
197:            public Dimension getWindowSizeById(long id) {
198:                Int32Pointer x = bridge.createInt32Pointer(1, false);
199:                Int32Pointer y = bridge.createInt32Pointer(1, false);
200:                Int32Pointer w = bridge.createInt32Pointer(1, false);
201:                Int32Pointer h = bridge.createInt32Pointer(1, false);
202:                CLongPointer root = bridge.createCLongPointer(1, false);
203:                Int32Pointer border = bridge.createInt32Pointer(1, false);
204:                Int32Pointer depth = bridge.createInt32Pointer(1, false);
205:
206:                x11.XGetGeometry(display, id, root, x, y, w, h, border, depth);
207:                return new Dimension(w.get(0), h.get(0));
208:            }
209:
210:            public long getJavaWindow() {
211:                return javaWindow;
212:            }
213:
214:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.