Source Code Cross Referenced for OperatingSystem.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » 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 » Swing Library » jEdit » org.gjt.sp.jedit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * OperatingSystem.java - OS detection
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 2002, 2005 Slava Pestov
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:
023:        package org.gjt.sp.jedit;
024:
025:        import java.awt.GraphicsConfiguration;
026:        import java.awt.GraphicsDevice;
027:        import java.awt.GraphicsEnvironment;
028:        import java.awt.Rectangle;
029:        import java.awt.Toolkit;
030:        import javax.swing.UIManager;
031:        import java.io.File;
032:        import java.util.Enumeration;
033:        import java.util.Vector;
034:        import org.gjt.sp.util.Log;
035:
036:        /**
037:         * Operating system detection routines.
038:         * @author Slava Pestov
039:         * @version $Id: OperatingSystem.java 5354 2006-03-03 16:18:06Z ezust $
040:         * @since jEdit 4.0pre4
041:         */
042:        public class OperatingSystem {
043:            //{{{ getScreenBounds() method
044:            /**
045:             * Returns the bounds of the default screen.
046:             */
047:            public static final Rectangle getScreenBounds() {
048:                int screenX = (int) Toolkit.getDefaultToolkit().getScreenSize()
049:                        .getWidth();
050:                int screenY = (int) Toolkit.getDefaultToolkit().getScreenSize()
051:                        .getHeight();
052:                int x, y, w, h;
053:
054:                if (isMacOS()) {
055:                    x = 0;
056:                    y = 22;
057:                    w = screenX;
058:                    h = screenY - y - 4;//shadow size
059:                } else if (isWindows()) {
060:                    x = -4;
061:                    y = -4;
062:                    w = screenX - 2 * x;
063:                    h = screenY - 2 * y;
064:                } else {
065:                    x = 0;
066:                    y = 0;
067:                    w = screenX;
068:                    h = screenY;
069:                }
070:
071:                return new Rectangle(x, y, w, h);
072:            } //}}}
073:
074:            //{{{ getScreenBounds() method
075:            /**
076:             * Returns the bounds of the (virtual) screen that the window should be in
077:             * @param window The bounds of the window to get the screen for
078:             */
079:            public static final Rectangle getScreenBounds(Rectangle window) {
080:                GraphicsDevice[] gd = GraphicsEnvironment
081:                        .getLocalGraphicsEnvironment().getScreenDevices();
082:                Vector intersects = new Vector();
083:
084:                // Get available screens
085:                // O(n^3), this is nasty, but since we aren't dealling with
086:                // many items it should be fine
087:                for (int i = 0; i < gd.length; i++) {
088:                    GraphicsConfiguration gc = gd[i].getDefaultConfiguration();
089:                    // Don't add duplicates
090:                    if (window.intersects(gc.getBounds())) {
091:                        for (Enumeration e = intersects.elements(); e
092:                                .hasMoreElements();) {
093:                            GraphicsConfiguration gcc = (GraphicsConfiguration) e
094:                                    .nextElement();
095:                            if (gcc.getBounds().equals(gc.getBounds()))
096:                                break;
097:                        }
098:                        intersects.add(gc);
099:                    }
100:                }
101:
102:                GraphicsConfiguration choice = null;
103:                if (intersects.size() > 0) {
104:                    // Pick screen with largest intersection
105:                    for (Enumeration e = intersects.elements(); e
106:                            .hasMoreElements();) {
107:                        GraphicsConfiguration gcc = (GraphicsConfiguration) e
108:                                .nextElement();
109:                        if (choice == null)
110:                            choice = gcc;
111:                        else {
112:                            Rectangle int1 = choice.getBounds().intersection(
113:                                    window);
114:                            Rectangle int2 = gcc.getBounds().intersection(
115:                                    window);
116:                            int area1 = int1.width * int1.height;
117:                            int area2 = int2.width * int2.height;
118:                            if (area2 > area1)
119:                                choice = gcc;
120:                        }
121:                    }
122:                } else
123:                    choice = GraphicsEnvironment.getLocalGraphicsEnvironment()
124:                            .getDefaultScreenDevice().getDefaultConfiguration();
125:
126:                // Make adjustments for some OS's
127:                int screenX = choice.getBounds().x;
128:                int screenY = choice.getBounds().y;
129:                int screenW = choice.getBounds().width;
130:                int screenH = choice.getBounds().height;
131:                int x, y, w, h;
132:
133:                if (isMacOS()) {
134:                    x = screenX;
135:                    y = screenY + 22;
136:                    w = screenW;
137:                    h = screenH - y - 4;//shadow size
138:                } else {
139:                    x = screenX;
140:                    y = screenY;
141:                    w = screenW;
142:                    h = screenH;
143:                }
144:
145:                // Yay, we're finally there
146:                return new Rectangle(x, y, w, h);
147:            } //}}}
148:
149:            //{{{ isDOSDerived() method
150:            /**
151:             * Returns if we're running Windows 95/98/ME/NT/2000/XP, or OS/2.
152:             */
153:            public static final boolean isDOSDerived() {
154:                return isWindows() || isOS2();
155:            } //}}}
156:
157:            //{{{ isWindows() method
158:            /**
159:             * Returns if we're running Windows 95/98/ME/NT/2000/XP.
160:             */
161:            public static final boolean isWindows() {
162:                return os == WINDOWS_9x || os == WINDOWS_NT;
163:            } //}}}
164:
165:            //{{{ isWindows9x() method
166:            /**
167:             * Returns if we're running Windows 95/98/ME.
168:             */
169:            public static final boolean isWindows9x() {
170:                return os == WINDOWS_9x;
171:            } //}}}
172:
173:            //{{{ isWindowsNT() method
174:            /**
175:             * Returns if we're running Windows NT/2000/XP.
176:             */
177:            public static final boolean isWindowsNT() {
178:                return os == WINDOWS_NT;
179:            } //}}}
180:
181:            //{{{ isOS2() method
182:            /**
183:             * Returns if we're running OS/2.
184:             */
185:            public static final boolean isOS2() {
186:                return os == OS2;
187:            } //}}}
188:
189:            //{{{ isUnix() method
190:            /**
191:             * Returns if we're running Unix (this includes MacOS X).
192:             */
193:            public static final boolean isUnix() {
194:                return os == UNIX || os == MAC_OS_X;
195:            } //}}}
196:
197:            //{{{ isMacOS() method
198:            /**
199:             * Returns if we're running MacOS X.
200:             */
201:            public static final boolean isMacOS() {
202:                return os == MAC_OS_X;
203:            } //}}}
204:
205:            //{{{ isX11() method
206:            /**
207:             * Returns if this OS is likely to be using X11 as the graphics
208:             * system.
209:             * @since jEdit 4.2pre3
210:             */
211:            public static boolean isX11() {
212:                return os == UNIX;
213:            } //}}}
214:
215:            //{{{ isVMS() method
216:            /**
217:             * Returns if we're running VMS.
218:             */
219:            public static final boolean isVMS() {
220:                return os == VMS;
221:            } //}}}
222:
223:            //{{{ isMacOSLF() method
224:            /**
225:             * Returns if we're running MacOS X and using the native look and feel.
226:             */
227:            public static final boolean isMacOSLF() {
228:                return (isMacOS() && UIManager.getLookAndFeel()
229:                        .isNativeLookAndFeel());
230:            } //}}}
231:
232:            //{{{ hasScreenMenuBar() method
233:            /**
234:             * Returns whether the screen menu bar on Mac OS X is in use.
235:             * @since jEdit 4.2pre1
236:             */
237:            public static final boolean hasScreenMenuBar() {
238:                if (!isMacOS())
239:                    return false;
240:                else if (hasScreenMenuBar == -1) {
241:                    String result = System
242:                            .getProperty("apple.laf.useScreenMenuBar");
243:                    if (result == null)
244:                        result = System
245:                                .getProperty("com.apple.macos.useScreenMenuBar");
246:                    hasScreenMenuBar = ("true".equals(result)) ? 1 : 0;
247:                }
248:
249:                return (hasScreenMenuBar == 1);
250:            } //}}}
251:
252:            //{{{ isJava14() method
253:            /**
254:             * Returns if Java 2 version 1.4, or Java 2 version 1.5 is in use.
255:             */
256:            public static final boolean hasJava14() {
257:                // jEdit 4.3 requires Java 1.4 or later. However, this method exists
258:                // for two reasons. Compatibility with plugins for jEdit 4.2, and
259:                // in case somebody wants to borrow this class for their app.
260:                return java14;
261:            } //}}}
262:
263:            //{{{ isJava15() method
264:            /**
265:             * Returns if Java 2 version 1.5 is in use.
266:             */
267:            public static final boolean hasJava15() {
268:                return java15;
269:            } //}}}
270:
271:            //{{{ isCaseInsensitiveFS() method
272:            /**
273:             * @since jEdit 4.3pre2
274:             */
275:            public static boolean isCaseInsensitiveFS() {
276:                return isDOSDerived() || isMacOS();
277:            } //}}}
278:
279:            //{{{ Private members
280:            private static final int UNIX = 0x31337;
281:            private static final int WINDOWS_9x = 0x640;
282:            private static final int WINDOWS_NT = 0x666;
283:            private static final int OS2 = 0xDEAD;
284:            private static final int MAC_OS_X = 0xABC;
285:            private static final int VMS = 0xDEAD2;
286:            private static final int UNKNOWN = 0xBAD;
287:
288:            private static int os;
289:            private static boolean java14;
290:            private static boolean java15;
291:            private static int hasScreenMenuBar = -1;
292:
293:            //{{{ Class initializer
294:            static {
295:                if (System.getProperty("mrj.version") != null) {
296:                    os = MAC_OS_X;
297:                } else {
298:                    String osName = System.getProperty("os.name");
299:                    if (osName.indexOf("Windows 9") != -1
300:                            || osName.indexOf("Windows M") != -1) {
301:                        os = WINDOWS_9x;
302:                    } else if (osName.indexOf("Windows") != -1) {
303:                        os = WINDOWS_NT;
304:                    } else if (osName.indexOf("OS/2") != -1) {
305:                        os = OS2;
306:                    } else if (osName.indexOf("VMS") != -1) {
307:                        os = VMS;
308:                    } else if (File.separatorChar == '/') {
309:                        os = UNIX;
310:                    } else {
311:                        os = UNKNOWN;
312:                        Log.log(Log.WARNING, OperatingSystem.class,
313:                                "Unknown operating system: " + osName);
314:                    }
315:                }
316:
317:                // for debugging, make jEdit think its using a different
318:                // version of Java than it really is.
319:                String javaVersion = System
320:                        .getProperty("jedit.force.java.version");
321:                if (javaVersion == null || javaVersion.equals(""))
322:                    javaVersion = System.getProperty("java.version");
323:                java14 = (javaVersion.compareTo("1.4") >= 0);
324:                java15 = (javaVersion.compareTo("1.5") >= 0);
325:            } //}}}
326:
327:            //}}}
328:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.