Author: jerome
Date: 2008-08-17 11:11:26 +0200 (Sun, 17 Aug 2008)
New Revision: 1531
Modified:
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/ConfInterface.java
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniFile.java
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniWriter.java
Log:
* Completed deletion function, users can now delete a ChatterTux action.
Modified:
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/ConfInterface.java
===================================================================
---
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/ConfInterface.java
2008-08-17 07:53:03 UTC (rev 1530)
+++
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/ConfInterface.java
2008-08-17 09:11:26 UTC (rev 1531)
@@ -94,6 +94,7 @@
List<String> availableLocutors;
int currentPitch = 120;
IniFile ini;
+ IniWriter writer;
Properties properties;
//** Tux Object.
@@ -106,6 +107,7 @@
//Getting ini file.
this.ini = new IniFile(this.iniFile);
this.properties = new
Properties(this.ini.getHashtable());
+ this.writer = new IniWriter(this.iniFile, this.ini);
this.getFrame();
locale = Locale.getDefault(); //Getting language.
@@ -474,7 +476,7 @@
//TODO remove entry from ini.
public void removeFromIni(String key){
try {
- this.ini.writer.delete(key);
+ this.writer.delete(key);
} catch (Exception e) {
System.out.println(String.format("Problem deleting %s",
key));
e.printStackTrace();
Modified:
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniFile.java
===================================================================
---
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniFile.java
2008-08-17 07:53:03 UTC (rev 1530)
+++
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniFile.java
2008-08-17 09:11:26 UTC (rev 1531)
@@ -33,17 +33,18 @@
private File file;
private Hashtable<String, Vector<String>> keys = new Hashtable<String,
Vector<String>>();
private Hashtable<Integer, String> indexes = new Hashtable<Integer,
String>();
- public IniWriter writer;
public IniFile(File file){
+ this.create(file);
+ }
+
+ private void create(File file){
this.file = file;
try {
this.getKeys(this.file);
- this.writer = new IniWriter(this.file);
} catch (Exception except){ except.printStackTrace(); }
}
-
/**
* This function gets keys into .ini file and store an index to each
key.
* @param file
@@ -119,7 +120,20 @@
this.keys = table;
}
+ public void remove(String key){
+ this.keys.remove(key);
+ int y = 0;
+ Hashtable<Integer, String> tmp = new Hashtable<Integer,
String>();
+ for(int i= 0; i < this.indexes.size(); i++){
+ if(!this.indexes.get(i).equals(key)){
+ tmp.put(y, this.indexes.get(i));
+ y++;
+ }
+ }
+ this.indexes = tmp;
+ }
+
/*
* Return number of keys.
*/
Modified:
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniWriter.java
===================================================================
---
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniWriter.java
2008-08-17 07:53:03 UTC (rev 1530)
+++
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniWriter.java
2008-08-17 09:11:26 UTC (rev 1531)
@@ -31,24 +31,25 @@
private File iniFile;
private FileWriter writer;
private IniFile ini;
- private String path;
- public IniWriter(File iniFile){
- this.iniFile = new File(iniFile.getAbsolutePath()+".tmp");
- String path = iniFile.getAbsolutePath();
- if(this.iniFile.isFile()){
- IniWriter.isFile = true;
+ public IniWriter(File iniFile, IniFile inif){
+ this.iniFile = new File(iniFile.getAbsolutePath());
+ if(!this.iniFile.isFile()){
try {
- writer = new FileWriter(this.iniFile);
- ini = new IniFile(this.iniFile);
+ this.iniFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
+
+ if(this.iniFile.isFile()){
+ IniWriter.isFile = true;
+ ini = inif;
+ }
}
public void delete(String key) throws Exception{
- ini.getHashtable().remove(key);
+ ini.remove(key);
this.write();
}
@@ -69,6 +70,7 @@
//this.iniFile.delete();
try {
+ writer = new FileWriter(this.iniFile);
this.iniFile.createNewFile();
} catch (IOException e) {
System.out.println("File error"); //TODO displaying
errorBox instead.
@@ -77,18 +79,33 @@
for(int i=0; i < this.ini.getHashtable().size(); i++){
try {
- this.writer.write(String.format("\n[%s]",
this.ini.getKeyAtIndex(i)));
+ this.writer.write("[" +
this.ini.getKeyAtIndex(i) + "]\n");
Vector<String> dat =
this.ini.getKeyPropertiesAtKey(this.ini.getKeyAtIndex(i));
- this.writer.write(String.format("action = %s",
dat.get(0)));
- this.writer.write(String.format("command = %s",
dat.get(1)));
+ System.out.println(dat);
+
+ this.writer.write(dat.firstElement() + "\n");
+ this.writer.write(dat.lastElement() + "\n");
this.writer.write("\n");
+
+
} catch (IOException e) {
+ try {
+ this.writer.close();
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
System.out.println("Error writing file");
//TODO displaying errorBox instead.
e.printStackTrace();
}
//TODO make a copy to be able to restore values in case
of error writing file.
}
+ try {
+ this.writer.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
return true;
}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn