Source Code Cross Referenced for WinGraphicsDevice.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » awt » gl » windows » 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.gl.windows 
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 Alexey A. Petrenko
019:         * @version $Revision$
020:         */package org.apache.harmony.awt.gl.windows;
021:
022:        import java.awt.Dimension;
023:        import java.awt.DisplayMode;
024:        import java.awt.GraphicsConfiguration;
025:        import java.awt.Rectangle;
026:        import java.util.Vector;
027:
028:        import org.apache.harmony.awt.gl.GLGraphicsDevice;
029:        import org.apache.harmony.awt.internal.nls.Messages;
030:        import org.apache.harmony.awt.nativebridge.windows.Win32;
031:        import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
032:
033:        /**
034:         * Windows GraphicsDevice implementation
035:         *
036:         */
037:        public class WinGraphicsDevice extends GLGraphicsDevice {
038:            private DisplayMode displayMode = null;
039:
040:            private static final Win32 win32 = Win32.getInstance();
041:
042:            private final int type;
043:            private final Rectangle bounds;
044:            private final String id;
045:            private final boolean primary;
046:
047:            private Dimension resolution = null;
048:
049:            private WinGraphicsConfiguration defaultConfig = null;
050:            private WinGraphicsConfiguration[] configs = null;
051:
052:            private byte[] idBytes = null;
053:
054:            static boolean useOpenGL;
055:            static boolean useGDI;
056:            static {
057:                String opengl = System.getProperty("java2d.opengl"); //$NON-NLS-1$
058:                String gdi = System.getProperty("java2d.gdi"); //$NON-NLS-1$
059:                useOpenGL = opengl != null && opengl.equals("true"); //$NON-NLS-1$
060:                useGDI = gdi != null && gdi.equals("true"); //$NON-NLS-1$
061:            };
062:
063:            public WinGraphicsDevice(int left, int top, int right, int bottom,
064:                    String id, boolean primary) {
065:                type = TYPE_RASTER_SCREEN;
066:                bounds = new Rectangle(left, top, right - left, bottom - top);
067:                displayMode = new DisplayMode(bounds.width, bounds.height,
068:                        DisplayMode.BIT_DEPTH_MULTI,
069:                        DisplayMode.REFRESH_RATE_UNKNOWN);
070:                this .id = id;
071:                this .primary = primary;
072:            }
073:
074:            public WinGraphicsDevice(long hwnd) {
075:                type = TYPE_RASTER_SCREEN;
076:
077:                long hmon = win32.MonitorFromWindow(hwnd,
078:                        WindowsDefs.MONITOR_DEFAULTTOPRIMARY);
079:                Win32.MONITORINFOEXW mi = win32.createMONITORINFOEXW(true);
080:                mi.get_MONITORINFO().set_cbSize(mi.size());
081:                if (win32.GetMonitorInfoW(hmon, mi.shortLockPointer()) == 0) {
082:                    // awt.15=Can not get monitor info
083:                    throw new RuntimeException(Messages.getString("awt.15")); //$NON-NLS-1$
084:                }
085:                Win32.RECT rect = mi.get_MONITORINFO().get_rcMonitor();
086:                int x = rect.get_left();
087:                int y = rect.get_top();
088:                int width = rect.get_right() - x;
089:                int height = rect.get_bottom() - y;
090:                bounds = new Rectangle(x, y, width, height);
091:                displayMode = new DisplayMode(bounds.width, bounds.height,
092:                        DisplayMode.BIT_DEPTH_MULTI,
093:                        DisplayMode.REFRESH_RATE_UNKNOWN);
094:                id = mi.get_szDevice().getString();
095:                primary = (mi.get_MONITORINFO().get_dwFlags() & WindowsDefs.MONITORINFOF_PRIMARY) == WindowsDefs.MONITORINFOF_PRIMARY;
096:                rect.free();
097:                mi.free();
098:            }
099:
100:            @Override
101:            public int getType() {
102:                return type;
103:            }
104:
105:            @Override
106:            public GraphicsConfiguration getDefaultConfiguration() {
107:                if (defaultConfig == null) {
108:                    long hdc = win32.CreateDCW(null, id, null, null);
109:                    if (hdc == 0) {
110:                        // awt.16=Can not create DC for device
111:                        throw new RuntimeException(Messages.getString("awt.16")); //$NON-NLS-1$
112:                    }
113:
114:                    int dci = win32.GetPixelFormat(hdc);
115:                    Win32.PIXELFORMATDESCRIPTOR pfd = win32
116:                            .createPIXELFORMATDESCRIPTOR(false);
117:                    if (win32.DescribePixelFormat(hdc, dci, pfd.size(), pfd) > 0) {
118:                        defaultConfig = useOpenGL ? new WGLGraphicsConfiguration(
119:                                this , dci, pfd)
120:                                : new WinGraphicsConfiguration(this , dci, pfd);
121:                    } else {
122:                        getConfigurations();
123:                    }
124:                    win32.DeleteDC(hdc);
125:                }
126:
127:                return defaultConfig;
128:            }
129:
130:            @Override
131:            public GraphicsConfiguration[] getConfigurations() {
132:                if (configs == null) {
133:                    long hdc = win32.CreateDCW(null, id, null, null);
134:                    if (hdc == 0) {
135:                        // awt.16=Can not create DC for device
136:                        throw new RuntimeException(Messages.getString("awt.16")); //$NON-NLS-1$
137:                    }
138:
139:                    // If we created DC why do not ask it about resolution?
140:                    if (resolution == null) {
141:                        int width = win32.GetDeviceCaps(hdc,
142:                                WindowsDefs.LOGPIXELSY);
143:                        int height = win32.GetDeviceCaps(hdc,
144:                                WindowsDefs.LOGPIXELSX);
145:                        resolution = new Dimension(width, height);
146:                    }
147:
148:                    Win32.PIXELFORMATDESCRIPTOR pfd = win32
149:                            .createPIXELFORMATDESCRIPTOR(false);
150:                    int pfnum = win32.DescribePixelFormat(hdc, 1, pfd.size(),
151:                            pfd);
152:                    if (pfnum == 0) {
153:                        return null;
154:                    }
155:
156:                    // Choose default configuration
157:                    int dci = win32.GetPixelFormat(hdc);
158:
159:                    Vector<WinGraphicsConfiguration> gcv = new Vector<WinGraphicsConfiguration>(
160:                            100);
161:                    int i = 1;
162:                    while (win32.DescribePixelFormat(hdc, i, pfd.size(), pfd) > 0) {
163:                        WinGraphicsConfiguration gc = useOpenGL ? new WGLGraphicsConfiguration(
164:                                this , i, pfd)
165:                                : new WinGraphicsConfiguration(this , i, pfd);
166:
167:                        if (!gcv.contains(gc)) {
168:                            gcv.add(gc);
169:                        }
170:
171:                        // Is default PixelFormat?
172:                        if (dci == i) {
173:                            int idx = gcv.indexOf(gc);
174:                            gcv.set(idx, gc);
175:                            defaultConfig = gc;
176:                        }
177:
178:                        i++;
179:                    }
180:                    pfd.free();
181:
182:                    win32.DeleteDC(hdc);
183:
184:                    configs = new WinGraphicsConfiguration[gcv.size()];
185:                    gcv.toArray(configs);
186:
187:                    // If we can not find default PixelFormat
188:                    // let's use first one
189:                    // Probably not best idea...
190:                    if (defaultConfig == null) {
191:                        defaultConfig = configs[0];
192:                    }
193:                }
194:
195:                return configs;
196:            }
197:
198:            @Override
199:            public String getIDstring() {
200:                return id;
201:            }
202:
203:            public boolean isDefaultDevice() {
204:                return primary;
205:            }
206:
207:            public Rectangle getBounds() {
208:                return bounds;
209:            }
210:
211:            @Override
212:            public String toString() {
213:                return getClass().getName()
214:                        + "[Bounds: " + bounds + ", ID: " + id + ", primary: " + primary + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
215:            }
216:
217:            byte[] getIDBytes() {
218:                if (idBytes == null) {
219:                    idBytes = (id + "\0x00").getBytes(); //$NON-NLS-1$
220:                }
221:
222:                return idBytes;
223:            }
224:
225:            @Override
226:            public DisplayMode getDisplayMode() {
227:                return displayMode;
228:            }
229:
230:            @Override
231:            public DisplayMode[] getDisplayModes() {
232:                DisplayMode[] dms = { displayMode };
233:                return dms;
234:            }
235:
236:            @Override
237:            public Dimension getResolution() {
238:                if (resolution == null) {
239:                    long hdc = win32.CreateDCW(null, id, null, null);
240:                    if (hdc == 0) {
241:                        // awt.16=Can not create DC for device
242:                        throw new RuntimeException(Messages.getString("awt.16")); //$NON-NLS-1$
243:                    }
244:
245:                    if (resolution == null) {
246:                        int width = win32.GetDeviceCaps(hdc,
247:                                WindowsDefs.LOGPIXELSY);
248:                        int height = win32.GetDeviceCaps(hdc,
249:                                WindowsDefs.LOGPIXELSX);
250:                        resolution = new Dimension(width, height);
251:                    }
252:
253:                    win32.DeleteDC(hdc);
254:                }
255:
256:                return resolution;
257:            }
258:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.