Source Code Cross Referenced for DefaultPlatform.java in  » IDE » DrJava » edu » rice » cs » drjava » platform » 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 » IDE » DrJava » edu.rice.cs.drjava.platform 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*BEGIN_COPYRIGHT_BLOCK
002:         *
003:         * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004:         * All rights reserved.
005:         * 
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions are met:
008:         *    * Redistributions of source code must retain the above copyright
009:         *      notice, this list of conditions and the following disclaimer.
010:         *    * Redistributions in binary form must reproduce the above copyright
011:         *      notice, this list of conditions and the following disclaimer in the
012:         *      documentation and/or other materials provided with the distribution.
013:         *    * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014:         *      names of its contributors may be used to endorse or promote products
015:         *      derived from this software without specific prior written permission.
016:         * 
017:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018:         * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020:         * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024:         * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025:         * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026:         * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027:         * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028:         *
029:         * This software is Open Source Initiative approved Open Source Software.
030:         * Open Source Initative Approved is a trademark of the Open Source Initiative.
031:         * 
032:         * This file is part of DrJava.  Download the current version of this project
033:         * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034:         * 
035:         * END_COPYRIGHT_BLOCK*/
036:
037:        package edu.rice.cs.drjava.platform;
038:
039:        import edu.rice.cs.drjava.DrJava;
040:        import edu.rice.cs.drjava.config.Configuration;
041:        import edu.rice.cs.drjava.config.FileOption;
042:        import edu.rice.cs.drjava.config.OptionConstants;
043:        import edu.rice.cs.util.ArgumentTokenizer;
044:        import edu.rice.cs.util.StringOps;
045:
046:        import javax.swing.*;
047:        import java.io.File;
048:        import java.lang.reflect.Method;
049:        import java.net.URL;
050:        import java.util.List;
051:
052:        /** Default platform-neutral implementation of PlatformSupport.  Most implementations
053:         * will extend this class to inherit default behaviors.
054:         * @version $Id: DefaultPlatform.java 4255 2007-08-28 19:17:37Z mgricken $
055:         */
056:        class DefaultPlatform implements  PlatformSupport {
057:            /** Singleton instance. */
058:            public static DefaultPlatform ONLY = new DefaultPlatform();
059:
060:            /** Private constructor for singleton pattern. */
061:            protected DefaultPlatform() {
062:            }
063:
064:            /** Utility method to determine if the current Swing look and feel is the platform-specific look and feel for the
065:             * client platform.
066:             * @return true if current Swing look and feel is the system look and feel
067:             */
068:            public boolean isUsingSystemLAF() {
069:                String sysLAF = UIManager.getSystemLookAndFeelClassName();
070:                String curLAF = UIManager.getLookAndFeel().getClass().getName();
071:                return (sysLAF.equals(curLAF));
072:            }
073:
074:            /** Hook for performing general UI setup.  Called before all other UI setup is done. The default implementation 
075:             * does nothing.
076:             */
077:            public void beforeUISetup() {
078:            }
079:
080:            /** Hook for performing general UI setup.  Called after all other UI setup is done. The default implementation 
081:             * does nothing.
082:             *
083:             * @param about the Action associated with openning the About dialog
084:             * @param prefs the Action associated with openning the Preferences dialog
085:             * @param quit  the Action associated with quitting the DrJava application
086:             */
087:            public void afterUISetup(Action about, Action prefs, Action quit) {
088:            }
089:
090:            /** Returns whether this is a Mac OS X platform. */
091:            public boolean isMacPlatform() {
092:                return false;
093:            }
094:
095:            /** Returns whether this is a Windows platform. */
096:            public boolean isWindowsPlatform() {
097:                return false;
098:            }
099:
100:            /** Returns the current Java specification version. */
101:            public String getJavaSpecVersion() {
102:                return System.getProperty("java.specification.version");
103:            }
104:
105:            /** Returns true if the classpath's tools.jar is from version 1.3. */
106:            public boolean has13ToolsJar() {
107:                // Javadoc's Main class should not have an execute(String[]) method.
108:                try {
109:                    Class<?> main = Class.forName("com.sun.tools.javadoc.Main");
110:                    return !_javadocMainHasExecuteMethod(main);
111:                } catch (Throwable t) {
112:                    return false;
113:                }
114:            }
115:
116:            /** Returns true if the classpath's tools.jar is from version 1.4. */
117:            public boolean has14ToolsJar() {
118:                // Javadoc's Main class should have an execute(String[]) method.
119:                try {
120:                    Class<?> main = Class.forName("com.sun.tools.javadoc.Main");
121:                    return _javadocMainHasExecuteMethod(main);
122:                } catch (Throwable t) {
123:                    return false;
124:                }
125:            }
126:
127:            /** Returns true if the given class object for com.sun.tools.javadoc.Main
128:             *  has an execute(String[]) method.  If so, that means we have a 1.4
129:             *  version of tools.jar.
130:             *
131:             * @param main Class object for com.sun.tools.javadoc.Main
132:             */
133:            @SuppressWarnings("unchecked")
134:            private boolean _javadocMainHasExecuteMethod(Class main) {
135:                try {
136:                    Class<String[]>[] arr = new Class[] { String[].class };
137:                    main.getMethod("execute", arr);
138:                    return true;
139:                } catch (Throwable t) {
140:                    return false;
141:                }
142:            }
143:
144:            /** Utility method for opening a URL in a browser in a platform-specific way.
145:             * The default implementation uses Runtime.exec to execute a command specified
146:             * in Preferences.  Platform implementations should attempt the default method
147:             * first, then try to use a "default browser", if such a thing exists on the
148:             * specific platform.
149:             *
150:             * @param address the URL to open
151:             * @return true if the URL was successfully handled, false otherwise
152:             */
153:            public boolean openURL(URL address) {
154:                // Get the two config options.
155:                Configuration config = DrJava.getConfig();
156:                File exe = config.getSetting(OptionConstants.BROWSER_FILE);
157:                String command = config
158:                        .getSetting(OptionConstants.BROWSER_STRING);
159:
160:                // Check for empty settings.
161:                if ((exe == FileOption.NULL_FILE) && (command.equals(""))) {
162:                    // If the user hasn't specified anything, don't try to run it.
163:                    return false;
164:                } else {
165:                    String addr = address.toString();
166:                    if (command.equals("")) {
167:                        // If there is no command, simply use the URL.
168:                        command = addr;
169:                    } else {
170:                        // Otherwise, replace any <URL> tags in the command with the address.
171:                        String tag = "<URL>";
172:                        if (command.indexOf(tag) != -1) {
173:                            command = StringOps.replace(command, tag, addr);
174:                        } else {
175:                            // No <URL> specified, so tack it onto the end.
176:                            command = command + " " + addr;
177:                        }
178:                    }
179:
180:                    // Build a string array of command and arguments.
181:                    List<String> args = ArgumentTokenizer.tokenize(command);
182:
183:                    // Prepend the file only if it exists.
184:                    if (exe != FileOption.NULL_FILE)
185:                        args.add(0, exe.getAbsolutePath());
186:
187:                    // Call the command.
188:                    try {
189:                        // Process proc =
190:                        Runtime.getRuntime().exec(
191:                                args.toArray(new String[args.size()]));
192:                    } catch (Throwable t) {
193:                        // If there was any kind of problem, ignore it and report failure.
194:                        return false;
195:                    }
196:                }
197:
198:                // Otherwise, trust that it worked.
199:                return true;
200:            }
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.