Source Code Cross Referenced for WinGraphicsConfiguration.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.GraphicsConfiguration;
023:        import java.awt.GraphicsDevice;
024:        import java.awt.Rectangle;
025:        import java.awt.Transparency;
026:        import java.awt.geom.AffineTransform;
027:        import java.awt.image.BufferedImage;
028:        import java.awt.image.ColorModel;
029:        import java.awt.image.DirectColorModel;
030:        import java.awt.image.VolatileImage;
031:
032:        import org.apache.harmony.awt.internal.nls.Messages;
033:        import org.apache.harmony.awt.nativebridge.windows.Win32;
034:        import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
035:
036:        /**
037:         * Windows GraphicsConfiguration implementation
038:         *
039:         */
040:        public class WinGraphicsConfiguration extends GraphicsConfiguration {
041:            private static final Win32 win32 = Win32.getInstance();
042:
043:            private WinGraphicsDevice device;
044:            private ColorModel cm;
045:            private long flags;
046:            private byte pixelType;
047:
048:            private int bits = -1;
049:            private byte redBits = -1;
050:            private byte redShift = -1;
051:            private int rmask = -1;
052:            private byte greenBits = -1;
053:            private byte greenShift = -1;
054:            private int gmask = -1;
055:            private byte blueBits = -1;
056:            private byte blueShift = -1;
057:            private int bmask = -1;
058:            private byte alphaBits = -1;
059:            private byte alphaShift = -1;
060:            private int amask = -1;
061:
062:            private int index;
063:
064:            public WinGraphicsConfiguration(WinGraphicsDevice device,
065:                    int index, Win32.PIXELFORMATDESCRIPTOR pfd) {
066:                this .device = device;
067:                this .index = index;
068:                init(pfd);
069:            }
070:
071:            public WinGraphicsConfiguration(long hwnd, long hdc) {
072:                this .device = new WinGraphicsDevice(hwnd);
073:                this .index = -1;
074:
075:                int dci = win32.GetPixelFormat(hdc);
076:                dci = (dci > 0) ? dci : 1;
077:                Win32.PIXELFORMATDESCRIPTOR pfd = win32
078:                        .createPIXELFORMATDESCRIPTOR(false);
079:                win32.DescribePixelFormat(hdc, dci, pfd.size(), pfd);
080:                init(pfd);
081:                pfd.free();
082:            }
083:
084:            /**
085:             * Initializes private fileds with info from
086:             * native PIXELFORMATDESCRIPTOR structure.
087:             * 
088:             * @param pfd PIXELFORMATDESCRIPTOR structure.
089:             */
090:            private void init(Win32.PIXELFORMATDESCRIPTOR pfd) {
091:                flags = pfd.get_dwFlags();
092:                pixelType = pfd.get_iPixelType();
093:                bits = pfd.get_cColorBits();
094:
095:                if (bits == 0) {
096:                    return;
097:                }
098:
099:                if ((pixelType & WindowsDefs.PFD_TYPE_COLORINDEX) != WindowsDefs.PFD_TYPE_COLORINDEX) {
100:                    redBits = pfd.get_cRedBits();
101:                    redShift = pfd.get_cRedShift();
102:                    rmask = (int) (Math.pow(2, redBits) - 1) << redShift;
103:
104:                    greenBits = pfd.get_cGreenBits();
105:                    greenShift = pfd.get_cGreenShift();
106:                    gmask = (int) (Math.pow(2, greenBits) - 1) << greenShift;
107:
108:                    blueBits = pfd.get_cBlueBits();
109:                    blueShift = pfd.get_cBlueShift();
110:                    bmask = (int) (Math.pow(2, blueBits) - 1) << blueShift;
111:
112:                    alphaBits = pfd.get_cAlphaBits();
113:                    alphaShift = pfd.get_cAlphaShift();
114:                    amask = (int) (Math.pow(2, alphaBits) - 1) << alphaShift;
115:                }
116:
117:                long hdc = win32.CreateDCW(null, device.getIDstring(), null,
118:                        null);
119:                cm = createColorModel(hdc);
120:                win32.DeleteDC(hdc);
121:
122:            }
123:
124:            @Override
125:            public GraphicsDevice getDevice() {
126:                return device;
127:            }
128:
129:            @Override
130:            public Rectangle getBounds() {
131:                return device.getBounds();
132:            }
133:
134:            @Override
135:            public AffineTransform getDefaultTransform() {
136:                return new AffineTransform();
137:            }
138:
139:            @Override
140:            public AffineTransform getNormalizingTransform() {
141:                return new AffineTransform();
142:            }
143:
144:            @Override
145:            public BufferedImage createCompatibleImage(int width, int height) {
146:                return new BufferedImage(cm, cm.createCompatibleWritableRaster(
147:                        width, height), false, null);
148:            }
149:
150:            @Override
151:            public BufferedImage createCompatibleImage(int width, int height,
152:                    int transparency) {
153:                ColorModel cmt = getColorModel(transparency);
154:                if (cmt == null) {
155:                    // awt.18=Transparency is not supported.
156:                    throw new IllegalArgumentException(Messages
157:                            .getString("awt.18")); //$NON-NLS-1$
158:                }
159:
160:                return new BufferedImage(cmt, cmt
161:                        .createCompatibleWritableRaster(width, height), false,
162:                        null);
163:            }
164:
165:            @Override
166:            public ColorModel getColorModel() {
167:                return cm;
168:            }
169:
170:            @Override
171:            public ColorModel getColorModel(int transparency) {
172:                switch (transparency) {
173:                case Transparency.BITMASK:
174:                    return new DirectColorModel(25, 0xFF0000, 0xFF00, 0xFF,
175:                            0x1000000);
176:                case Transparency.TRANSLUCENT:
177:                    return ColorModel.getRGBdefault();
178:                default:
179:                    return cm;
180:                }
181:            }
182:
183:            @Override
184:            public VolatileImage createCompatibleVolatileImage(int width,
185:                    int height) {
186:                return new WinVolatileImage(this , width, height);
187:            }
188:
189:            @Override
190:            public VolatileImage createCompatibleVolatileImage(int width,
191:                    int height, int transparency) {
192:                return createCompatibleVolatileImage(width, height);
193:            }
194:
195:            public long getFlags() {
196:                return flags;
197:            }
198:
199:            @Override
200:            public boolean equals(Object obj) {
201:                if (!(obj instanceof  WinGraphicsConfiguration)) {
202:                    return false;
203:                }
204:
205:                WinGraphicsConfiguration gc = (WinGraphicsConfiguration) obj;
206:
207:                // We do not use flags now. So GraphicsConfigurations with
208:                // different flags are same for us.
209:                //if (flags != gc.flags)
210:                //  return false;
211:
212:                if (pixelType != gc.pixelType) {
213:                    return false;
214:                }
215:
216:                if (bits != gc.bits) {
217:                    return false;
218:                }
219:
220:                if (redBits != gc.redBits) {
221:                    return false;
222:                }
223:
224:                if (redShift != gc.redShift) {
225:                    return false;
226:                }
227:
228:                if (greenBits != gc.greenBits) {
229:                    return false;
230:                }
231:
232:                if (greenShift != gc.greenShift) {
233:                    return false;
234:                }
235:
236:                if (blueBits != gc.blueBits) {
237:                    return false;
238:                }
239:
240:                if (blueShift != gc.blueShift) {
241:                    return false;
242:                }
243:
244:                if (alphaBits != gc.alphaBits) {
245:                    return false;
246:                }
247:
248:                if (alphaShift != gc.alphaShift) {
249:                    return false;
250:                }
251:
252:                return true;
253:            }
254:
255:            public int getIndex() {
256:                return index;
257:            }
258:
259:            private native ColorModel createColorModel(long hdc);
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.