KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > ajde > ui > internal > UserPreferencesStore


1
2 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3  *
4  * This file is part of the IDE support for the AspectJ(tm)
5  * programming language; see http://aspectj.org
6  *
7  * The contents of this file are subject to the Mozilla Public License
8  * Version 1.1 (the "License"); you may not use this file except in
9  * compliance with the License. You may obtain a copy of the License at
10  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * The Original Code is AspectJ.
18  *
19  * The Initial Developer of the Original Code is Xerox Corporation. Portions
20  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21  * All Rights Reserved.
22  *
23  * Contributor(s):
24  */

25  
26  
27 package org.aspectj.ajde.ui.internal;
28
29 import java.util.*;
30 import java.io.*;
31 import org.aspectj.ajde.*;
32 import org.aspectj.ajde.ui.UserPreferencesAdapter;
33
34 public class UserPreferencesStore implements UserPreferencesAdapter {
35     public static final String JavaDoc FILE_NAME = "/.ajbrowser";
36     private final String JavaDoc VALUE_SEP = ";";
37     private Properties properties = new Properties();
38     
39     public UserPreferencesStore() {
40         try {
41             if (new File(getPropertiesFilePath()).exists()) {
42                 properties.load(new FileInputStream(getPropertiesFilePath()));
43             }
44         } catch (IOException ioe) {
45             Ajde.getDefault().getErrorHandler().handleError("Could not read properties", ioe);
46         }
47     }
48     
49     public String JavaDoc getProjectPreference(String JavaDoc name) {
50         return properties.getProperty(name);
51     }
52
53     public List getProjectMultivalPreference(String JavaDoc name) {
54         List values = new ArrayList();
55         String JavaDoc valuesString = properties.getProperty(name);
56         if (valuesString != null && !valuesString.trim().equals("")) {
57             StringTokenizer st = new StringTokenizer(valuesString, VALUE_SEP);
58             while (st.hasMoreTokens()) {
59                 values.add(st.nextToken());
60             }
61         }
62         return values;
63     }
64
65     public void setProjectPreference(String JavaDoc name, String JavaDoc value) {
66         properties.setProperty(name, value);
67         saveProperties();
68     }
69
70     public void setProjectMultivalPreference(String JavaDoc name, List values) {
71         String JavaDoc valuesString = "";
72         for (Iterator it = values.iterator(); it.hasNext(); ) {
73             valuesString += (String JavaDoc)it.next() + ';';
74         }
75         properties.setProperty(name, valuesString);
76         saveProperties();
77     }
78
79     public String JavaDoc getPropertiesFilePath() {
80         String JavaDoc path = System.getProperty("user.home");
81         if (path == null) {
82             path = ".";
83         }
84         return path + FILE_NAME;
85     }
86     
87     public String JavaDoc getGlobalPreference(String JavaDoc name) {
88         return getProjectPreference(name);
89     }
90     
91     public List getGlobalMultivalPreference(String JavaDoc name) {
92         return getProjectMultivalPreference(name);
93     }
94     
95     public void setGlobalPreference(String JavaDoc name, String JavaDoc value) {
96         setProjectPreference(name, value);
97     }
98     
99     public void setGlobalMultivalPreference(String JavaDoc name, List values) {
100         setProjectMultivalPreference(name, values);
101     }
102     
103     public void saveProperties() {
104         try {
105             properties.store(new FileOutputStream(getPropertiesFilePath()), "AJDE Settings");
106         } catch (IOException ioe) {
107             Ajde.getDefault().getErrorHandler().handleError("Could not write properties", ioe);
108         }
109     }
110 }
111
Popular Tags