2
* Created on 09-ene-2006
4
* TODO To change the template for this generated file go to
5
* Window - Preferences - Java - Code Style - Code Templates
7
package org.herac.tuxguitar.gui.system.config;
10
import java.io.FileInputStream;
11
import java.io.FileNotFoundException;
12
import java.io.FileOutputStream;
13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.util.Iterator;
17
import java.util.Properties;
19
import org.eclipse.swt.graphics.FontData;
20
import org.eclipse.swt.graphics.RGB;
21
import org.herac.tuxguitar.gui.util.TuxGuitarFileUtils;
26
* TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
28
public class ConfigManager {
29
private Properties properties;
31
public ConfigManager() {
32
this.properties = new Properties(new ConfigDefaults().getProperties());
39
private String getProperty(String key) {
40
return this.properties.getProperty(key);
43
public String getStringConfigValue(String key,String defaultValue) {
44
String property = getProperty(key);
45
return (property == null)?defaultValue:property.trim();
48
public String getStringConfigValue(String key) {
49
return this.getStringConfigValue(key,null);
52
public int getIntConfigValue(String key,int defaultValue) {
53
String value = getProperty(key);
54
return (value == null)?defaultValue:Integer.parseInt(value.trim());
57
public int getIntConfigValue(String key) {
58
return this.getIntConfigValue(key,0);
61
public boolean getBooleanConfigValue(String key,boolean defaultValue) {
62
String value = getProperty(key);
63
return (value == null)?defaultValue:Boolean.valueOf(value.trim()).booleanValue();
66
public boolean getBooleanConfigValue(String key) {
67
return this.getBooleanConfigValue(key,false);
70
public FontData getFontDataConfigValue(String key){
71
String value = getProperty(key);
73
String[] values = value.trim().split(",");
74
if(values != null && values.length == 3){
76
String name = values[0].trim();
77
int size = Integer.parseInt(values[1].trim());
78
int style = Integer.parseInt(values[2].trim());
80
return new FontData(name,size,style);
81
}catch(NumberFormatException e){}
87
public RGB getRGBConfigValue(String key){
88
String value = getProperty(key);
90
String[] values = value.trim().split(",");
91
if(values != null && values.length == 3){
93
int red = Integer.parseInt(values[0].trim());
94
int green = Integer.parseInt(values[1].trim());
95
int blue = Integer.parseInt(values[2].trim());
97
return new RGB(red,green,blue);
98
}catch(NumberFormatException e){}
104
public void setProperty(String key,String value){
105
this.properties.setProperty(key,value);
108
public void setProperty(String key,int value){
109
setProperty(key,Integer.toString(value));
112
public void setProperty(String key,boolean value){
113
setProperty(key,Boolean.toString(value));
116
public void setDefaults(){
117
Properties defaults = new ConfigDefaults().getProperties();
118
Iterator it = defaults.entrySet().iterator();
120
Map.Entry property = (Map.Entry)it.next();
121
setProperty((String)property.getKey(),(String)property.getValue());
126
public void removeProperty(String key){
127
this.properties.remove(key);
131
this.properties.clear();
136
if(new File(getFileName()).exists()){
137
InputStream inputStream = new FileInputStream(getFileName());
138
this.properties.clear();
139
this.properties.load(inputStream);
143
} catch (Exception e) {
150
properties.store(new FileOutputStream(getFileName()),"System Configuration");
151
} catch (FileNotFoundException e1) {
152
e1.printStackTrace();
153
} catch (IOException e1) {
154
e1.printStackTrace();
158
private String getFileName(){
159
return TuxGuitarFileUtils.USER_CONFIG_PREFIX + File.separator + "config.properties";
b'\\ No newline at end of file'