Source code: com/arranger/jarl/ui/PrefManager.java
1 package com.arranger.jarl.ui;
2
3 import com.arranger.jarl.util.IOUtil;
4 import com.arranger.jarl.util.StringTools;
5
6 import java.util.Properties;
7 import java.io.File;
8 import java.io.IOException;
9 import java.io.OutputStream;
10
11 /**
12 * PrefManager created on Apr 15, 2003
13 */
14 class PrefManager {
15
16 public Properties getPreferences() {
17 File prefFile = getPrefFile();
18 if (prefFile != null && prefFile.exists()) {
19 try {
20 return IOUtil.loadProperties(prefFile.getAbsolutePath());
21 } catch (IOException e) {
22 e.printStackTrace();
23 }
24 }
25 return new Properties();
26 }
27
28 public void storePreferences(Properties properties) {
29 File prefFile = getPrefFile();
30 if (prefFile != null) {
31 try {
32 OutputStream outputStream = IOUtil.getOutputStream(prefFile.getAbsolutePath());
33 properties.store(outputStream, "jarl properties");
34 outputStream.close();
35 } catch (IOException e) {
36 e.printStackTrace();
37 }
38 }
39 }
40
41 protected File getPrefFile() {
42 String userDir = System.getProperty("user.home");
43 File file = new File(userDir);
44 if (!file.exists()) {
45 return null;
46 }
47 String prefFile = StringTools.appendPath(userDir, "jarl.properties");
48 return new File(prefFile);
49 }
50 }