Source Code Cross Referenced for XGraphicsConfiguration.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » awt » gl » 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.gl.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 Oleg V. Khaschansky
019:         * @version $Revision$
020:         *
021:         * @date: Nov 15, 2005
022:         */package org.apache.harmony.awt.gl.linux;
023:
024:        import org.apache.harmony.awt.internal.nls.Messages;
025:        import org.apache.harmony.awt.nativebridge.*;
026:        import org.apache.harmony.awt.nativebridge.linux.X11;
027:        import org.apache.harmony.awt.nativebridge.linux.X11Defs;
028:
029:        import java.awt.*;
030:        import java.awt.image.*;
031:        import java.awt.geom.AffineTransform;
032:
033:        public class XGraphicsConfiguration extends GraphicsConfiguration {
034:            // X11 atom, required for getting the default colormap
035:            private static final long XA_RGB_DEFAULT_MAP = 27;
036:
037:            protected static final X11 x11 = X11.getInstance();
038:
039:            XGraphicsDevice dev;
040:            X11.XVisualInfo info;
041:            ColorModel cm = null;
042:
043:            long xcolormap;
044:
045:            XGraphicsConfiguration(XGraphicsDevice dev, X11.XVisualInfo info) {
046:                this .dev = dev;
047:                this .info = info;
048:                xcolormap = obtainRGBColorMap();
049:            }
050:
051:            public long getXColormap() {
052:                return xcolormap;
053:            }
054:
055:            public int getDepth() {
056:                return info.get_depth();
057:            }
058:
059:            public X11.Visual getVisual() {
060:                return info.get_visual();
061:            }
062:
063:            private long obtainRGBColorMap() {
064:                X11.Visual defVisual = x11.createVisual(x11.XDefaultVisual(
065:                        dev.display, dev.screen));
066:                if (info.get_visualid() == defVisual.get_visualid()) {
067:                    return x11.XDefaultColormap(dev.display, dev.screen);
068:                }
069:
070:                X11.Visual vis = info.get_visual();
071:                long rootWindow = x11.XRootWindow(dev.display, dev.screen);
072:
073:                int status = x11.XmuLookupStandardColormap(dev.display,
074:                        dev.screen, info.get_visualid(), info.get_depth(),
075:                        XA_RGB_DEFAULT_MAP, X11Defs.False, X11Defs.True);
076:
077:                if (status == 1) {
078:                    Int32Pointer nCmaps = NativeBridge.getInstance()
079:                            .createInt32Pointer(1, true);
080:                    PointerPointer stdCmaps = NativeBridge.getInstance()
081:                            .createPointerPointer(1, true);
082:
083:                    status = x11.XGetRGBColormaps(dev.display, rootWindow,
084:                            stdCmaps, nCmaps, XA_RGB_DEFAULT_MAP);
085:
086:                    int numCmaps = nCmaps.get(0);
087:                    VoidPointer ptr = stdCmaps.get(0);
088:                    nCmaps.free();
089:                    stdCmaps.free();
090:
091:                    if (status == 1) {
092:                        for (int i = 0; i < numCmaps; i++) {
093:
094:                            X11.XStandardColormap stdCmap = x11
095:                                    .createXStandardColormap(ptr.byteBase
096:                                            .getElementPointer(i
097:                                                    * X11.XStandardColormap.sizeof));
098:
099:                            if (stdCmap.get_visualid() == info.get_visualid()) {
100:                                long cmap = stdCmap.get_colormap();
101:                                x11.XFree(ptr);
102:                                return cmap;
103:                            }
104:                        }
105:
106:                        x11.XFree(ptr);
107:                    }
108:                }
109:
110:                long cmap = x11.XCreateColormap(dev.display, rootWindow, vis
111:                        .lock(), X11Defs.AllocNone);
112:                vis.unlock();
113:                return cmap;
114:            }
115:
116:            public GraphicsDevice getDevice() {
117:                return dev;
118:            }
119:
120:            public Rectangle getBounds() {
121:                return new Rectangle(dev.getDisplayWidth(), dev
122:                        .getDisplayHeight());
123:            }
124:
125:            public AffineTransform getDefaultTransform() {
126:                return new AffineTransform();
127:            }
128:
129:            public AffineTransform getNormalizingTransform() {
130:                return new AffineTransform(); // XXX - todo
131:            }
132:
133:            public BufferedImage createCompatibleImage(int width, int height) {
134:                return new BufferedImage(getColorModel(), getColorModel()
135:                        .createCompatibleWritableRaster(width, height), false,
136:                        null);
137:            }
138:
139:            public BufferedImage createCompatibleImage(int width, int height,
140:                    int transparency) {
141:                return new BufferedImage(getColorModel(transparency),
142:                        getColorModel(transparency)
143:                                .createCompatibleWritableRaster(width, height),
144:                        false, null);
145:            }
146:
147:            public ColorModel getColorModel() {
148:                if (cm == null) {
149:                    switch (info.get_class()) {
150:                    case X11Defs.TrueColor:
151:                    case X11Defs.DirectColor:
152:                        cm = new DirectColorModel(info.get_depth(), (int) info
153:                                .get_red_mask(), (int) info.get_green_mask(),
154:                                (int) info.get_blue_mask());
155:                        break;
156:                    case X11Defs.StaticGray:
157:                        // looks like native colormap differs from the colors given
158:                        // by the gray ICC profile
159:                        /*
160:                        // This should be enough
161:                        cm = new ComponentColorModel(
162:                                ColorSpace.getInstance(ColorSpace.CS_GRAY),
163:                                new int[]{info.get_depth()},
164:                                false,
165:                                false,
166:                                Transparency.OPAQUE,
167:                                DataBuffer.TYPE_BYTE
168:                        );
169:                        break;
170:                         */
171:                    case X11Defs.PseudoColor:
172:                    case X11Defs.GrayScale:
173:                    case X11Defs.StaticColor: {
174:                        // Always use default colormap to create ColorModel.
175:                        // This should be sufficient for the first time.
176:                        int defCmapSize = ((XGraphicsConfiguration) dev
177:                                .getDefaultConfiguration()).info
178:                                .get_colormap_size();
179:
180:                        // Create array of XColor and fill pixel values
181:                        Int8Pointer xColors = NativeBridge.getInstance()
182:                                .createInt8Pointer(
183:                                        X11.XColor.sizeof * defCmapSize, true);
184:                        int xColorsIdx = 0;
185:                        for (int i = 0; i < defCmapSize; i++, xColorsIdx += X11.XColor.sizeof) {
186:                            X11.XColor color = x11.createXColor(xColors
187:                                    .getElementPointer(xColorsIdx));
188:                            color.set_pixel(i);
189:                        }
190:
191:                        // Get the rgb values from the default colormap and create cm
192:                        x11.XQueryColors(dev.display, xcolormap,
193:                                xColors.lock(), defCmapSize);
194:                        xColors.unlock();
195:
196:                        byte redVals[] = new byte[defCmapSize];
197:                        byte greenVals[] = new byte[defCmapSize];
198:                        byte blueVals[] = new byte[defCmapSize];
199:
200:                        xColorsIdx = 0;
201:                        for (int i = 0; i < defCmapSize; i++, xColorsIdx += X11.XColor.sizeof) {
202:                            X11.XColor color = x11.createXColor(xColors
203:                                    .getElementPointer(xColorsIdx));
204:                            redVals[i] = (byte) ((color.get_red() >> 8) & 0xFF);
205:                            greenVals[i] = (byte) ((color.get_green() >> 8) & 0xFF);
206:                            blueVals[i] = (byte) ((color.get_blue() >> 8) & 0xFF);
207:                        }
208:
209:                        cm = new IndexColorModel(info.get_depth(), defCmapSize,
210:                                redVals, greenVals, blueVals, -1);
211:
212:                        xColors.free();
213:                        break;
214:                    }
215:                    default:
216:                        // awt.0C=Unknown visual class
217:                        throw new InternalError(Messages.getString("awt.0C")); //$NON-NLS-1$
218:                    }
219:                }
220:
221:                return cm;
222:            }
223:
224:            public ColorModel getColorModel(int transparency) {
225:                switch (transparency) {
226:                case Transparency.OPAQUE:
227:                    return getColorModel();
228:                case Transparency.TRANSLUCENT:
229:                    return ColorModel.getRGBdefault();
230:                case Transparency.BITMASK:
231:                    return new DirectColorModel(25, 0xFF0000, 0xFF00, 0xFF,
232:                            0x1000000);
233:                default:
234:                    // awt.0D=Invalid transparency
235:                    throw new IllegalArgumentException(Messages
236:                            .getString("awt.0D")); //$NON-NLS-1$
237:                }
238:            }
239:
240:            public VolatileImage createCompatibleVolatileImage(int width,
241:                    int height) {
242:                if (width <= 0 || height <= 0)
243:                    // awt.0E=Dimensions of the image should be positive
244:                    throw new IllegalArgumentException(Messages
245:                            .getString("awt.0E")); //$NON-NLS-1$
246:
247:                return new XVolatileImage(this , width, height);
248:            }
249:
250:            public VolatileImage createCompatibleVolatileImage(int width,
251:                    int height, int transparency) {
252:                // XXX - todo - implement transparency
253:                return createCompatibleVolatileImage(width, height);
254:            }
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.