KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > platform > PlatformSettings


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.java.platform;
20
21 import java.io.File JavaDoc;
22 import java.util.prefs.Preferences JavaDoc;
23 import org.openide.util.NbBundle;
24 import org.openide.util.NbPreferences;
25 import org.openide.util.Utilities;
26
27
28
29 /**
30  *
31  * @author Tomas Zezula
32  */

33 public class PlatformSettings {
34     private static final PlatformSettings INSTANCE = new PlatformSettings();
35     private static final String JavaDoc PROP_PLATFORMS_FOLDER = "platformsFolder"; //NOI18N
36
private static final String JavaDoc APPLE_JAVAVM_FRAMEWORK_PATH = "/System/Library/Frameworks/JavaVM.framework/Versions/";//NOI18N
37

38     public PlatformSettings () {
39
40     }
41
42     public String JavaDoc displayName() {
43         return NbBundle.getMessage(PlatformSettings.class,"TXT_PlatformSettings");
44     }
45     
46     private static Preferences JavaDoc getPreferences() {
47         return NbPreferences.forModule(PlatformSettings.class);
48     }
49
50     public File JavaDoc getPlatformsFolder () {
51         String JavaDoc folderName = getPreferences().get(PROP_PLATFORMS_FOLDER, null);
52         if (folderName == null) {
53             File JavaDoc f;
54             if (Utilities.isMac()) {
55                 f = new File JavaDoc (APPLE_JAVAVM_FRAMEWORK_PATH);
56             }
57             else {
58                 f = new File JavaDoc(System.getProperty("user.home")); //NOI18N
59
File JavaDoc tmp;
60                 while ((tmp = f.getParentFile())!=null) {
61                     f = tmp;
62                 }
63             }
64             return f;
65         }
66         else {
67             return new File JavaDoc (folderName);
68         }
69     }
70
71     public void setPlatformsFolder (File JavaDoc file) {
72         getPreferences().put(PROP_PLATFORMS_FOLDER, file.getAbsolutePath());
73     }
74
75
76     public synchronized static PlatformSettings getDefault () {
77         return INSTANCE;
78     }
79 }
80
Popular Tags