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;
25
* TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
27
public abstract class TGConfigManager {
29
private Properties properties;
31
public TGConfigManager() {
36
this.properties = new Properties(getDefaults());
40
private String getProperty(String key) {
41
return this.properties.getProperty(key);
44
public String getStringConfigValue(String key,String defaultValue) {
46
String property = getProperty(key);
47
return (property == null)?defaultValue:property.trim();
48
}catch(Throwable throwable){
49
throwable.printStackTrace();
54
public String getStringConfigValue(String key) {
55
return this.getStringConfigValue(key,null);
58
public int getIntConfigValue(String key,int defaultValue) {
60
String value = getProperty(key);
61
return (value == null)?defaultValue:Integer.parseInt(value.trim());
62
}catch(Throwable throwable){
63
throwable.printStackTrace();
68
public int getIntConfigValue(String key) {
69
return this.getIntConfigValue(key,0);
72
public boolean getBooleanConfigValue(String key,boolean defaultValue) {
74
String value = getProperty(key);
75
return (value == null)?defaultValue:Boolean.valueOf(value.trim()).booleanValue();
76
}catch(Throwable throwable){
77
throwable.printStackTrace();
82
public boolean getBooleanConfigValue(String key) {
83
return this.getBooleanConfigValue(key,false);
86
public FontData getFontDataConfigValue(String key){
88
String value = getProperty(key);
90
String[] values = value.trim().split(",");
91
if(values != null && values.length == 3){
93
String name = values[0].trim();
94
int size = Integer.parseInt(values[1].trim());
95
int style = Integer.parseInt(values[2].trim());
96
return new FontData( (name == null ? "" : name),size,style);
97
}catch(NumberFormatException e){
102
}catch(Throwable throwable){
103
throwable.printStackTrace();
105
return new FontData();
108
public RGB getRGBConfigValue(String key){
110
String value = getProperty(key);
112
String[] values = value.trim().split(",");
113
if(values != null && values.length == 3){
115
int red = Integer.parseInt(values[0].trim());
116
int green = Integer.parseInt(values[1].trim());
117
int blue = Integer.parseInt(values[2].trim());
119
return new RGB(red,green,blue);
120
}catch(NumberFormatException e){
125
}catch(Throwable throwable){
126
throwable.printStackTrace();
131
public void setProperty(String key,String value){
132
this.properties.setProperty(key, (value != null ? value : new String()) );
135
public void setProperty(String key,int value){
136
this.setProperty(key,Integer.toString(value));
139
public void setProperty(String key,boolean value){
140
this.setProperty(key,Boolean.toString(value));
143
public void setProperty(String key,RGB rgb){
144
this.setProperty(key,(rgb.red + "," + rgb.green + "," + rgb.blue));
147
public void setProperty(String key,FontData fd){
148
this.setProperty(key,(fd.getName() + "," + fd.getHeight() + "," + fd.getStyle()));
151
public void setDefaults(){
152
Properties defaults = new TGConfigDefaults().getProperties();
153
Iterator it = defaults.entrySet().iterator();
155
Map.Entry property = (Map.Entry)it.next();
156
setProperty((String)property.getKey(),(String)property.getValue());
161
public void removeProperty(String key){
162
this.properties.remove(key);
166
this.properties.clear();
171
if(new File(getFileName()).exists()){
172
InputStream inputStream = new FileInputStream(getFileName());
173
this.properties.clear();
174
this.properties.load(inputStream);
178
} catch (Exception e) {
185
File file = new File(getFileName());
187
File folder = file.getParentFile();
188
if(folder != null && !folder.exists()){
192
this.properties.store(new FileOutputStream(file),getName());
193
} catch (FileNotFoundException e1) {
194
e1.printStackTrace();
195
} catch (IOException e1) {
196
e1.printStackTrace();
200
public abstract String getName();
202
public abstract String getFileName();
204
public abstract Properties getDefaults();
b'\\ No newline at end of file'