Source Code Cross Referenced for WinSystemProperties.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » awt » wtk » 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.wtk.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 Pavel Dolgov, Dmitry A. Durnev
019:         * @version $Revision$
020:         */package org.apache.harmony.awt.wtk.windows;
021:
022:        import java.awt.Color;
023:        import java.awt.Font;
024:        import java.awt.Toolkit;
025:        import java.awt.font.TextAttribute;
026:        import java.awt.im.InputMethodHighlight;
027:        import java.util.Map;
028:        import java.util.TreeSet;
029:        import org.apache.harmony.awt.ComponentInternals;
030:        import org.apache.harmony.awt.nativebridge.Int16Pointer;
031:        import org.apache.harmony.awt.nativebridge.Int32Pointer;
032:        import org.apache.harmony.awt.nativebridge.NativeBridge;
033:        import org.apache.harmony.awt.nativebridge.windows.Win32;
034:        import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
035:        import org.apache.harmony.awt.wtk.SystemProperties;
036:
037:        /**
038:         * WinSystemProperties
039:         * More information about Windows Desktop Properties can be found at http://java.sun.com/j2se/1.5.0/docs/guide/swing/1.4/w2k_props.html
040:         */
041:
042:        public class WinSystemProperties implements  SystemProperties {
043:
044:            private static final Win32 win32 = Win32.getInstance();
045:
046:            private static final int SPI_GETFONTSMOOTHINGTYPE = 0x200A;
047:            private static final int SPI_SETFONTSMOOTHINGTYPE = 0x200B;
048:            private static final int SPI_GETFONTSMOOTHINGCONTRAST = 0x200C;
049:            private static final int SPI_SETFONTSMOOTHINGCONTRAST = 0x200D;
050:
051:            private static final int sysColorIndices[] = { // SystemColor.* constants
052:                    WindowsDefs.COLOR_DESKTOP, // 0 DESKTOP
053:                    WindowsDefs.COLOR_ACTIVECAPTION, // 1 ACTIVE_CAPTION
054:                    WindowsDefs.COLOR_CAPTIONTEXT, // 2 ACTIVE_CAPTION_TEXT
055:                    WindowsDefs.COLOR_ACTIVEBORDER, // 3 ACTIVE_CAPTION_BORDER
056:                    WindowsDefs.COLOR_INACTIVECAPTION, // 4 INACTIVE_CAPTION
057:                    WindowsDefs.COLOR_INACTIVECAPTIONTEXT, // 5 INACTIVE_CAPTION_TEXT
058:                    WindowsDefs.COLOR_INACTIVEBORDER, // 6 INACTIVE_CAPTION_BORDER
059:                    WindowsDefs.COLOR_WINDOW, // 7 WINDOW
060:                    WindowsDefs.COLOR_WINDOWFRAME, // 8 WINDOW_BORDER
061:                    WindowsDefs.COLOR_WINDOWTEXT, // 9 WINDOW_TEXT
062:                    WindowsDefs.COLOR_MENU, // 10 MENU
063:                    WindowsDefs.COLOR_MENUTEXT, // 11 MENU_TEXT
064:                    WindowsDefs.COLOR_WINDOW, // 12 TEXT
065:                    WindowsDefs.COLOR_WINDOWTEXT, // 13 TEXT_TEXT
066:                    WindowsDefs.COLOR_HIGHLIGHT, // 14 TEXT_HIGHLIGHT
067:                    WindowsDefs.COLOR_HIGHLIGHTTEXT, // 15 TEXT_HIGHLIGHT_TEXT
068:                    WindowsDefs.COLOR_GRAYTEXT, // 16 TEXT_INACTIVE_TEXT
069:                    WindowsDefs.COLOR_3DFACE, // 17 CONTROL
070:                    WindowsDefs.COLOR_BTNTEXT, // 18 CONTROL_TEXT
071:                    WindowsDefs.COLOR_3DLIGHT, // 19 CONTROL_HIGHLIGHT
072:                    WindowsDefs.COLOR_3DHILIGHT, // 20 CONTROL_LT_HIGHLIGHT
073:                    WindowsDefs.COLOR_3DSHADOW, // 21 CONTROL_SHADOW
074:                    WindowsDefs.COLOR_3DDKSHADOW, // 22 CONTROL_DK_SHADOW
075:                    WindowsDefs.COLOR_SCROLLBAR, // 23 SCROLLBAR
076:                    WindowsDefs.COLOR_INFOBK, // 24 INFO
077:                    WindowsDefs.COLOR_INFOTEXT, // 25 INFO_TEXT
078:                    // colors not present in SystemColor class:
079:                    WindowsDefs.COLOR_GRADIENTACTIVECAPTION,
080:                    WindowsDefs.COLOR_GRADIENTINACTIVECAPTION,
081:                    WindowsDefs.COLOR_HOTLIGHT, WindowsDefs.COLOR_APPWORKSPACE,
082:                    WindowsDefs.COLOR_MENUBAR, };
083:
084:            private static final String sysColorProps[] = { // color property names
085:            "win.desktop.backgroundColor", // 0 DESKTOP //$NON-NLS-1$
086:                    "win.frame.activeCaptionColor", // 1 ACTIVE_CAPTION //$NON-NLS-1$
087:                    "win.frame.captionTextColor", // 2 ACTIVE_CAPTION_TEXT //$NON-NLS-1$
088:                    "win.frame.activeBorderColor", // 3 ACTIVE_CAPTION_BORDER //$NON-NLS-1$
089:                    "win.frame.inactiveCaptionColor", // 4 INACTIVE_CAPTION //$NON-NLS-1$
090:                    "win.frame.inactiveCaptionTextColor", // 5 INACTIVE_CAPTION_TEXT //$NON-NLS-1$
091:                    "win.frame.inactiveBorderColor", // 6 INACTIVE_CAPTION_BORDER //$NON-NLS-1$
092:                    "win.frame.backgroundColor", // 7 WINDOW //$NON-NLS-1$
093:                    "win.frame.color", //? 8 WINDOW_BORDER //$NON-NLS-1$
094:                    "win.frame.textColor", // 9 WINDOW_TEXT //$NON-NLS-1$
095:                    "win.menu.backgroundColor", // 10 MENU //$NON-NLS-1$
096:                    "win.menu.textColor", // 11 MENU_TEXT //$NON-NLS-1$
097:                    "win.frame.backgroundColor", // 12 TEXT //$NON-NLS-1$
098:                    "win.frame.textColor", // 13 TEXT_TEXT //$NON-NLS-1$
099:                    "win.item.highlightColor", // 14 TEXT_HIGHLIGHT //$NON-NLS-1$
100:                    "win.item.highlightTextColor", // 15 TEXT_HIGHLIGHT_TEXT //$NON-NLS-1$
101:                    "win.text.grayedTextColor", // 16 TEXT_INACTIVE_TEXT //$NON-NLS-1$
102:                    "win.3d.backgroundColor", // 17 CONTROL //$NON-NLS-1$
103:                    "win.button.textColor", // 18 CONTROL_TEXT //$NON-NLS-1$
104:                    "win.3d.lightColor", // 19 CONTROL_HIGHLIGHT //$NON-NLS-1$
105:                    "win.3d.highlightColor", // 20 CONTROL_LT_HIGHLIGHT //$NON-NLS-1$
106:                    "win.3d.shadowColor", // 21 CONTROL_SHADOW //$NON-NLS-1$
107:                    "win.3d.darkShadowColor", // 22 CONTROL_DK_SHADOW //$NON-NLS-1$
108:                    "win.scrollbar.backgroundColor", // 23 SCROLLBAR //$NON-NLS-1$
109:                    "win.tooltip.backgroundColor", // 24 INFO //$NON-NLS-1$
110:                    "win.tooltip.textColor", // 25 INFO_TEXT //$NON-NLS-1$
111:                    // colors not present in SystemColor class:
112:                    "win.frame.activeCaptionGradientColor", //$NON-NLS-1$
113:                    "win.frame.inactiveCaptionGradientColor", //$NON-NLS-1$
114:                    "win.item.hotTrackedColor", //$NON-NLS-1$
115:                    "win.mdi.backgroundColor", //$NON-NLS-1$
116:                    "win.menubar.backgroundColor", //$NON-NLS-1$
117:            };
118:
119:            private static final int sysFontIndices[] = {
120:
121:            WindowsDefs.ANSI_FIXED_FONT, WindowsDefs.ANSI_VAR_FONT,
122:                    WindowsDefs.DEFAULT_GUI_FONT,
123:                    WindowsDefs.DEVICE_DEFAULT_FONT,
124:                    WindowsDefs.OEM_FIXED_FONT, WindowsDefs.SYSTEM_FONT,
125:                    WindowsDefs.SYSTEM_FIXED_FONT,
126:
127:            };
128:
129:            private static final String sysFontDesktopProps[] = { // color property names
130:            "win.ansiFixed.font", // 0 ANSI_FIXED_FONT //$NON-NLS-1$
131:                    "win.ansiVar.font", // 1 ANSI_VAR_FONT //$NON-NLS-1$
132:                    "win.defaultGUI.font", // 2 DEFAULT_GUI_FONT //$NON-NLS-1$
133:                    "win.deviceDefault.font", // 3 DEVICE_DEFAULT_FONT             //$NON-NLS-1$
134:                    "win.oemFixed.font", // 4 OEM_FIXED_FONT             //$NON-NLS-1$
135:                    "win.system.font", // 5 SYSTEM_FONT //$NON-NLS-1$
136:                    "win.systemFixed.font", // 6 SYSTEM_FIXED_FONT             //$NON-NLS-1$
137:            };
138:
139:            private class WinPlaySound implements  Runnable {
140:                final String sndName;
141:
142:                WinPlaySound(String snd) {
143:                    sndName = snd;
144:                }
145:
146:                public void run() {
147:                    final int flags = (WindowsDefs.SND_ALIAS
148:                            | WindowsDefs.SND_SYNC | WindowsDefs.SND_NODEFAULT);
149:                    // have to start another thread to wait until playing ends
150:                    new Thread() {
151:                        @Override
152:                        public void run() {
153:                            win32.PlaySoundW(sndName, 0, flags);
154:                        }
155:                    }.start();
156:                }
157:
158:                @Override
159:                public String toString() {
160:                    return ("WinPlaySound(" + sndName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
161:                }
162:            };
163:
164:            private int sysColorCache[];
165:
166:            private Font defaultFont;
167:
168:            private class CacheLock {
169:            }
170:
171:            private final Object cacheLock = new CacheLock();
172:
173:            public int getSystemColorARGB(int index) {
174:                synchronized (cacheLock) {
175:                    if (sysColorCache == null) {
176:                        updateColorCache();
177:                    }
178:                    return sysColorCache[index];
179:                }
180:            }
181:
182:            void resetSystemColors() {
183:                synchronized (cacheLock) {
184:                    sysColorCache = null;
185:                    updateColorCache();
186:                    updateColorDesktopProperties(null);
187:                }
188:            }
189:
190:            private void updateColorCache() {
191:                sysColorCache = new int[sysColorIndices.length];
192:                for (int i = 0; i < sysColorIndices.length; i++) {
193:                    int n = sysColorIndices[i];
194:                    int bgr = win32.GetSysColor(n);
195:                    int b = (bgr & 0xFF0000) >> 16;
196:                    int g = (bgr & 0xFF00);
197:                    int r = (bgr & 0xFF) << 16;
198:                    sysColorCache[i] = (0xFF000000 | r | g | b);
199:
200:                }
201:            }
202:
203:            private void updateColorDesktopProperties(Map<String, Object> props) {
204:                for (int i = 0; i < sysColorIndices.length; i++) {
205:                    String name = sysColorProps[i];
206:                    Color val = new Color(sysColorCache[i]);
207:
208:                    setDesktopProperty(name, val, props);
209:                }
210:            }
211:
212:            private void setDesktopProperty(String name, Object val,
213:                    Map<String, Object> props) {
214:                if (props != null) {
215:                    props.put(name, val);
216:                    return; // skip firing property change
217:                }
218:                ComponentInternals ci = ComponentInternals
219:                        .getComponentInternals();
220:                ci.setDesktopProperty(name, val);
221:            }
222:
223:            public Font getDefaultFont() {
224:                synchronized (cacheLock) {
225:                    if (defaultFont == null) {
226:                        defaultFont = (Font) Toolkit.getDefaultToolkit()
227:                                .getDesktopProperty("win.defaultGUI.font"); //$NON-NLS-1$
228:                    }
229:                    return defaultFont;
230:                }
231:            }
232:
233:            private Font getFont(long hFont) {
234:                Win32.LOGFONTW logFont = win32.createLOGFONTW(false);
235:                win32.GetObjectW(hFont, logFont.size(), logFont
236:                        .longLockPointer());
237:                logFont.unlock();
238:                return getFont(logFont);
239:            }
240:
241:            private Font getFont(Win32.LOGFONTW logFont) {
242:                String name = logFont.get_lfFaceName().getString();
243:                int size = Math.abs(logFont.get_lfHeight());
244:                int weight = logFont.get_lfWeight();
245:                int bold = (weight == WindowsDefs.FW_BOLD ? Font.BOLD : 0);
246:                int italic = (logFont.get_lfItalic() != 0) ? Font.ITALIC : 0;
247:                return new Font(name, bold | italic, size);
248:            }
249:
250:            private void initSysFonts(Map<String, Object> props) {
251:                for (int i = 0; i < sysFontIndices.length; i++) {
252:                    long hFont = win32.GetStockObject(sysFontIndices[i]);
253:                    Font font = getFont(hFont);
254:                    if (props != null) {
255:                        String propName = sysFontDesktopProps[i];
256:                        setFontProperty(propName, font, props);
257:                    }
258:                }
259:            }
260:
261:            private void setBoolProperty(String propName, int val,
262:                    Map<String, Object> props) {
263:                setDesktopProperty(propName, (val != 0 ? Boolean.TRUE
264:                        : Boolean.FALSE), props);
265:            }
266:
267:            private void setIntProperty(String propName, int val,
268:                    Map<String, Object> props) {
269:                setDesktopProperty(propName, new Integer(val), props);
270:            }
271:
272:            private void setFontProperty(String propName, Font font,
273:                    Map<String, Object> props) {
274:                setDesktopProperty(propName, font, props);
275:                setIntProperty(propName + ".height", font.getSize(), props); //$NON-NLS-1$
276:            }
277:
278:            @SuppressWarnings("unchecked")//$NON-NLS-1$
279:            public void init(Map<String, ?> deskProps) {
280:                Map<String, Object> desktopProperties = (Map<String, Object>) deskProps;
281:                synchronized (cacheLock) {
282:                    getDnDProps(desktopProperties);
283:                    getShellProps(desktopProperties);
284:                    getMouseProps(desktopProperties);
285:                    if (sysColorCache == null) {
286:                        updateColorCache();
287:                    }
288:                    updateColorDesktopProperties(desktopProperties);
289:                    initSysFonts(desktopProperties);
290:                    getNonClientMetrics(desktopProperties);
291:                    getIconMetrics(desktopProperties);
292:                    getDragSize(true, desktopProperties);
293:                    getDragSize(false, desktopProperties);
294:                    getGradientCaptions(desktopProperties);
295:                    getFullWindowDrags(desktopProperties);
296:                    getHighContrast(desktopProperties);
297:                    getHotTracking(desktopProperties);
298:                    getKeyboardCues(desktopProperties);
299:                    getFontSmooth(desktopProperties);
300:                    getFontSmoothContrast(desktopProperties);
301:                    getFontSmoothType(desktopProperties);
302:                    getXPTheme(desktopProperties);
303:                    initSoundProps(desktopProperties);
304:                    TreeSet<String> keySet = new TreeSet<String>(
305:                            desktopProperties.keySet());
306:                    keySet.add("awt.dynamicLayoutSupported"); //$NON-NLS-1$
307:                    String[] propNames = keySet.toArray(new String[0]);
308:                    desktopProperties.put("win.propNames", propNames); //$NON-NLS-1$
309:
310:                }
311:
312:            }
313:
314:            void processSettingChange(long idx) {
315:                switch ((int) idx) {
316:                case WindowsDefs.SPI_SETNONCLIENTMETRICS:
317:                    getNonClientMetrics(null);
318:                    break;
319:                case WindowsDefs.SPI_SETICONMETRICS:
320:                    getIconMetrics(null);
321:                    break;
322:                case WindowsDefs.SPI_SETDRAGHEIGHT:
323:                case WindowsDefs.SPI_SETDRAGWIDTH:
324:                    getDragSize(idx == WindowsDefs.SPI_SETDRAGWIDTH, null);
325:                    break;
326:                case WindowsDefs.SPI_SETGRADIENTCAPTIONS:
327:                    getGradientCaptions(null);
328:                    break;
329:                case WindowsDefs.SPI_SETDRAGFULLWINDOWS:
330:                    getFullWindowDrags(null);
331:                    break;
332:                case WindowsDefs.SPI_SETHIGHCONTRAST:
333:                    getHighContrast(null);
334:                    break;
335:                case WindowsDefs.SPI_SETHOTTRACKING:
336:                    getHotTracking(null);
337:                    break;
338:                case WindowsDefs.SPI_SETKEYBOARDCUES:
339:                    getKeyboardCues(null);
340:                    break;
341:                case WindowsDefs.SPI_SETFONTSMOOTHING:
342:                    getFontSmooth(null);
343:                    break;
344:                case SPI_SETFONTSMOOTHINGCONTRAST:
345:                    getFontSmoothContrast(null);
346:                    break;
347:                case SPI_SETFONTSMOOTHINGTYPE:
348:                    getFontSmoothType(null);
349:                    break;
350:                case WindowsDefs.SPI_SETDOUBLECLICKTIME:
351:                case WindowsDefs.SPI_SETWHEELSCROLLLINES:
352:                    getMouseProps(null);
353:                    break;
354:                }
355:
356:            }
357:
358:            private void getFullWindowDrags(Map<String, Object> props) {
359:                getBoolSPI("win.frame.fullWindowDragsOn", //$NON-NLS-1$
360:                        WindowsDefs.SPI_GETDRAGFULLWINDOWS, props);
361:
362:            }
363:
364:            private void getGradientCaptions(Map<String, Object> props) {
365:                getBoolSPI("win.frame.captionGradientsOn", //$NON-NLS-1$
366:                        WindowsDefs.SPI_GETGRADIENTCAPTIONS, props);
367:            }
368:
369:            private void getHotTracking(Map<String, Object> props) {
370:                getBoolSPI("win.item.hotTrackingOn", //$NON-NLS-1$
371:                        WindowsDefs.SPI_GETHOTTRACKING, props);
372:            }
373:
374:            private void getKeyboardCues(Map<String, Object> props) {
375:                getBoolSPI("win.menu.keyboardCuesOn", //$NON-NLS-1$
376:                        WindowsDefs.SPI_GETKEYBOARDCUES, props);
377:            }
378:
379:            private void getFontSmooth(Map<String, Object> props) {
380:                getBoolSPI("win.text.fontSmoothingOn", //$NON-NLS-1$
381:                        WindowsDefs.SPI_GETFONTSMOOTHING, props);
382:            }
383:
384:            private void getFontSmoothContrast(Map<String, Object> props) {
385:                getIntSPI("win.text.fontSmoothingContrast", //$NON-NLS-1$
386:                        SPI_GETFONTSMOOTHINGCONTRAST, props);
387:            }
388:
389:            private void getFontSmoothType(Map<String, Object> props) {
390:                getIntSPI(
391:                        "win.text.fontSmoothingType", SPI_GETFONTSMOOTHINGTYPE, props); //$NON-NLS-1$
392:            }
393:
394:            private void getDragSize(boolean cx, Map<String, Object> props) {
395:                int sm_idx = (cx ? WindowsDefs.SM_CXDRAG
396:                        : WindowsDefs.SM_CYDRAG);
397:                String propName = "win.drag"; //$NON-NLS-1$
398:                propName += (cx ? ".width" : ".height"); //$NON-NLS-1$ //$NON-NLS-2$
399:                getSM(propName, sm_idx, props);
400:            }
401:
402:            private void getNonClientMetrics(Map<String, Object> props) {
403:                Win32.NONCLIENTMETRICSW ncm = win32
404:                        .createNONCLIENTMETRICSW(false);
405:                ncm.set_cbSize(ncm.size());
406:                win32.SystemParametersInfoW(
407:                        WindowsDefs.SPI_GETNONCLIENTMETRICS, ncm.size(), ncm
408:                                .getElementPointer(0), 0);
409:                setFontProperty("win.frame.captionFont", //$NON-NLS-1$
410:                        getFont(ncm.get_lfCaptionFont()), props);
411:                setFontProperty("win.frame.smallCaptionFont", //$NON-NLS-1$
412:                        getFont(ncm.get_lfSmCaptionFont()), props);
413:                setFontProperty(
414:                        "win.menu.font", getFont(ncm.get_lfMenuFont()), props); //$NON-NLS-1$
415:                setFontProperty("win.messagebox.font", //$NON-NLS-1$
416:                        getFont(ncm.get_lfMessageFont()), props);
417:                setFontProperty(
418:                        "win.status.font", getFont(ncm.get_lfStatusFont()), //$NON-NLS-1$
419:                        props);
420:                setFontProperty(
421:                        "win.tooltip.font", getFont(ncm.get_lfStatusFont()), //$NON-NLS-1$
422:                        props);
423:                setIntProperty(
424:                        "win.frame.sizingBorderWidth", ncm.get_iBorderWidth(), //$NON-NLS-1$
425:                        props);
426:                setIntProperty("win.scrollbar.width", ncm.get_iScrollWidth(), //$NON-NLS-1$
427:                        props);
428:                setIntProperty("win.scrollbar.height", ncm.get_iScrollHeight(), //$NON-NLS-1$
429:                        props);
430:                setIntProperty(
431:                        "win.frame.captionButtonWidth", ncm.get_iCaptionWidth(), //$NON-NLS-1$
432:                        props);
433:                setIntProperty(
434:                        "win.frame.captionButtonHeight", ncm.get_iCaptionHeight(), //$NON-NLS-1$
435:                        props);
436:                setIntProperty(
437:                        "win.frame.captionHeight", ncm.get_iCaptionHeight(), //$NON-NLS-1$
438:                        props);
439:                setIntProperty(
440:                        "win.frame.smallCaptionButtonWidth", ncm.get_iSmCaptionWidth(), //$NON-NLS-1$
441:                        props);
442:                setIntProperty(
443:                        "win.frame.smallCaptionButtonHeight", ncm.get_iSmCaptionHeight(), //$NON-NLS-1$
444:                        props);
445:                setIntProperty(
446:                        "win.frame.smallCaptionHeight", ncm.get_iSmCaptionHeight(), //$NON-NLS-1$
447:                        props);
448:                setIntProperty(
449:                        "win.menu.buttonWidth", ncm.get_iMenuWidth(), props); //$NON-NLS-1$
450:                setIntProperty("win.menu.height", ncm.get_iMenuHeight(), props); //$NON-NLS-1$
451:            }
452:
453:            private void getIconMetrics(Map<String, Object> props) {
454:                Win32.ICONMETRICSW im = win32.createICONMETRICSW(false);
455:                im.set_cbSize(im.size());
456:                win32.SystemParametersInfoW(WindowsDefs.SPI_GETICONMETRICS, im
457:                        .size(), im.getElementPointer(0), 0);
458:                setFontProperty(
459:                        "win.icon.font", getFont(im.get_lfFont()), props); //$NON-NLS-1$
460:                setIntProperty(
461:                        "win.icon.hspacing", im.get_iHorzSpacing(), props); //$NON-NLS-1$
462:                setBoolProperty(
463:                        "win.icon.titleWrappingOn", im.get_iTitleWrap(), props); //$NON-NLS-1$
464:                setIntProperty(
465:                        "win.icon.vspacing", im.get_iVertSpacing(), props); //$NON-NLS-1$
466:            }
467:
468:            private void getHighContrast(Map<String, Object> props) {
469:                Win32.HIGHCONTRASTA hc = win32.createHIGHCONTRASTA(false);
470:                hc.set_cbSize(hc.size());
471:                win32.SystemParametersInfoW(WindowsDefs.SPI_GETHIGHCONTRAST, hc
472:                        .size(), hc.getElementPointer(0), 0);
473:                setBoolProperty(
474:                        "win.highContrast.on", //$NON-NLS-1$
475:                        hc.get_dwFlags() & WindowsDefs.HCF_HIGHCONTRASTON,
476:                        props);
477:            }
478:
479:            private void getSM(String propName, int idx,
480:                    Map<String, Object> props) {
481:                setIntProperty(propName, win32.GetSystemMetrics(idx), props);
482:            }
483:
484:            private int getIntSPI(int idx) {
485:                NativeBridge bridge = NativeBridge.getInstance();
486:                Int32Pointer ptr = bridge.createInt32Pointer(1, false);
487:                win32.SystemParametersInfoW(idx, 0, ptr, 0);
488:                return ptr.get(0);
489:            }
490:
491:            private void getBoolSPI(String propName, int idx,
492:                    Map<String, Object> props) {
493:                setBoolProperty(propName, getIntSPI(idx), props);
494:            }
495:
496:            private void getIntSPI(String propName, int idx,
497:                    Map<String, Object> props) {
498:                setIntProperty(propName, getIntSPI(idx), props);
499:            }
500:
501:            void getXPTheme(Map<String, Object> props) {
502:                String style = "win.xpstyle."; //$NON-NLS-1$
503:                String nm = "Name"; //$NON-NLS-1$
504:                setBoolProperty(
505:                        style + "themeActive", win32.IsThemeActive(), props);//$NON-NLS-1$
506:                int bufSize = 256;
507:                NativeBridge nb = NativeBridge.getInstance();
508:                Int16Pointer ptrs[] = new Int16Pointer[3];
509:                for (int i = 0; i < ptrs.length; i++) {
510:                    ptrs[i] = nb.createInt16Pointer(bufSize, false);
511:                }
512:                String[] names = new String[] { "dll", "color", "size" };//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
513:                int res = win32.GetCurrentThemeName(ptrs[0], bufSize, ptrs[1],
514:                        bufSize, ptrs[2], bufSize);
515:                boolean ok = (res == WindowsDefs.S_OK);
516:                for (int i = 0; i < ptrs.length; i++) {
517:                    String val = (ok ? ptrs[i].getString() : null);
518:                    setDesktopProperty(style + names[i] + nm, val, props);
519:                }
520:            }
521:
522:            private void getDnDProps(Map<String, Object> props) {
523:                String propName = "DnD"; //$NON-NLS-1$
524:                setIntProperty(propName + ".gestureMotionThreshold", //$NON-NLS-1$
525:                        WindowsDefs.DD_DEFDRAGMINDIST, props);
526:                propName += ".Autoscroll"; //$NON-NLS-1$
527:                setIntProperty(propName + ".initialDelay", //$NON-NLS-1$
528:                        WindowsDefs.DD_DEFSCROLLDELAY, props);
529:                setIntProperty(propName + ".interval", //$NON-NLS-1$
530:                        WindowsDefs.DD_DEFSCROLLINTERVAL, props);
531:
532:            }
533:
534:            private void getShellProps(Map<String, Object> props) {
535:                Win32.SHELLFLAGSTATE sfs = win32.createSHELLFLAGSTATE(false);
536:                int flags = (WindowsDefs.SSF_SHOWATTRIBCOL | WindowsDefs.SSF_SHOWALLOBJECTS);
537:                win32.SHGetSettings(sfs, flags);
538:                String propName = "awt.file"; //$NON-NLS-1$
539:                setBoolProperty(propName + ".showAttribCol", //$NON-NLS-1$
540:                        sfs.get_fShowAttribCol(), props);
541:                setBoolProperty(propName + ".showHiddenFiles", //$NON-NLS-1$
542:                        (sfs.get_fShowAllObjects()), props);
543:            }
544:
545:            private void getMouseProps(Map<String, Object> props) {
546:                String propName = "awt."; //$NON-NLS-1$
547:                getSM(
548:                        propName + "mouse.numButtons", WindowsDefs.SM_CMOUSEBUTTONS, props); //$NON-NLS-1$
549:                setIntProperty(propName + "multiClickInterval", //$NON-NLS-1$
550:                        win32.GetDoubleClickTime(), props);
551:                setBoolProperty(
552:                        propName + "wheelMousePresent", //$NON-NLS-1$
553:                        win32
554:                                .GetSystemMetrics(WindowsDefs.SM_MOUSEWHEELPRESENT),
555:                        props);
556:                getIntSPI(propName + "wheelScrollLines", //$NON-NLS-1$
557:                        WindowsDefs.SPI_GETWHEELSCROLLLINES, props);
558:
559:            }
560:
561:            private void setSoundProperty(String propName, String sndName,
562:                    Map<String, Object> props) {
563:                String base = "win.sound."; //$NON-NLS-1$
564:                setDesktopProperty(base + propName, new WinPlaySound(sndName),
565:                        props);
566:            }
567:
568:            private void initSoundProps(Map<String, Object> props) {
569:                setSoundProperty("asterisk", "SystemAsterisk", props); //$NON-NLS-1$ //$NON-NLS-2$
570:                setSoundProperty("close", "Close", props); //$NON-NLS-1$ //$NON-NLS-2$
571:                setSoundProperty("default", ".Default", props); //$NON-NLS-1$ //$NON-NLS-2$
572:                setSoundProperty("exclamation", "SystemExclamation", props); //$NON-NLS-1$ //$NON-NLS-2$
573:                setSoundProperty("exit", "SystemExit", props); //$NON-NLS-1$ //$NON-NLS-2$
574:                setSoundProperty("hand", "SystemHand", props); //$NON-NLS-1$ //$NON-NLS-2$
575:                setSoundProperty("maximize", "Maximize", props); //$NON-NLS-1$ //$NON-NLS-2$
576:                setSoundProperty("menuCommand", "MenuCommand", props); //$NON-NLS-1$ //$NON-NLS-2$
577:                setSoundProperty("menuPopup", "MenuPopup", props); //$NON-NLS-1$ //$NON-NLS-2$
578:                setSoundProperty("minimize", "Minimize", props); //$NON-NLS-1$ //$NON-NLS-2$
579:                setSoundProperty("open", "Open", props); //$NON-NLS-1$ //$NON-NLS-2$
580:                setSoundProperty("question", "SystemQuestion", props); //$NON-NLS-1$ //$NON-NLS-2$
581:                setSoundProperty("restoreDown", "RestoreDown", props); //$NON-NLS-1$ //$NON-NLS-2$
582:                setSoundProperty("restoreUp", "RestoreUp", props); //$NON-NLS-1$ //$NON-NLS-2$
583:                setSoundProperty("start", "SystemStart", props); //$NON-NLS-1$ //$NON-NLS-2$
584:
585:            }
586:
587:            @SuppressWarnings("unchecked")
588:            public void mapInputMethodHighlight(InputMethodHighlight highlight,
589:                    Map<TextAttribute, ?> map) {
590:                Map<TextAttribute, Object> _map = (Map<TextAttribute, Object>) map;
591:                TextAttribute key = TextAttribute.INPUT_METHOD_UNDERLINE;
592:                boolean selected = highlight.isSelected();
593:                switch (highlight.getState()) {
594:                case InputMethodHighlight.RAW_TEXT:
595:                    _map.put(key, selected ? TextAttribute.UNDERLINE_LOW_GRAY
596:                            : TextAttribute.UNDERLINE_LOW_DOTTED);
597:                    break;
598:                case InputMethodHighlight.CONVERTED_TEXT:
599:                    _map.put(key,
600:                            selected ? TextAttribute.UNDERLINE_LOW_ONE_PIXEL
601:                                    : TextAttribute.UNDERLINE_LOW_DOTTED);
602:                    if (selected) {
603:                        // maybe get colors from system properties?
604:                        key = TextAttribute.BACKGROUND;
605:                        _map.put(key, Color.white);
606:                        key = TextAttribute.FOREGROUND;
607:                        _map.put(key, new Color(0, 0, 128));
608:                        key = TextAttribute.SWAP_COLORS;
609:                        _map.put(key, TextAttribute.SWAP_COLORS_ON);
610:                    }
611:                    break;
612:                }
613:            }
614:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.