Author: jerome
Date: 2008-08-17 09:53:03 +0200 (Sun, 17 Aug 2008)
New Revision: 1530
Added:
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniWriter.java
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
Log:
* Starting storing new datas into ini file.
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 06:39:36 UTC (rev 1529)
+++
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/ConfInterface.java
2008-08-17 07:53:03 UTC (rev 1530)
@@ -86,6 +86,7 @@
//Current tts parsed action.
public static String action = "none";
+ public static String currentKey = "None";
//** Configuration objects
Locale locale;
@@ -399,7 +400,7 @@
this.deleteEdition.setLocation(new Point(215, 100));
this.deleteEdition.addMouseListener(new
java.awt.event.MouseAdapter(){
public void
mousePressed(java.awt.event.MouseEvent event){
- removeFromIni();
+ removeFromIni(ConfInterface.currentKey);
}
});
this.okEdition = new JButton("Save");
@@ -462,12 +463,22 @@
// TODO Store to ini file.
public void storeAsIni(){
+
+ }
+
+ //TODO store modifications.
+ public void storeModificationsToIni(){
}
//TODO remove entry from ini.
- public void removeFromIni(){
-
+ public void removeFromIni(String key){
+ try {
+ this.ini.writer.delete(key);
+ } catch (Exception e) {
+ System.out.println(String.format("Problem deleting %s",
key));
+ e.printStackTrace();
+ }
}
/*****************************************************************************/
@@ -501,6 +512,7 @@
text = "Action: " + action + "\n" + title + value;
parameters.setText(text);
+ ConfInterface.currentKey = key;
}
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 06:39:36 UTC (rev 1529)
+++
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniFile.java
2008-08-17 07:53:03 UTC (rev 1530)
@@ -33,11 +33,13 @@
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.file = file;
try {
this.getKeys(this.file);
+ this.writer = new IniWriter(this.file);
} catch (Exception except){ except.printStackTrace(); }
}
@@ -110,7 +112,14 @@
return this.keys;
}
+ /*
+ * Sets new hashtable in case of deletion for example.
+ */
+ public void setHashtable(Hashtable<String, Vector<String>> table){
+ this.keys = table;
+ }
+
/*
* Return number of keys.
*/
Added:
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniWriter.java
===================================================================
---
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniWriter.java
(rev 0)
+++
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniWriter.java
2008-08-17 07:53:03 UTC (rev 1530)
@@ -0,0 +1,95 @@
+/* This file is part of "TuxDroid Chatter Tux tool".
+ * Copyright 2008, kysoh
+ * Author : Conan Jerome
+ * eMail : [EMAIL PROTECTED]
+ * Site : http://www.kysoh.com/
+ *
+ * "TuxDroid Chatter Tux tool" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "TuxDroid Chatter Tux tool" is distributed in the hope that it will be
useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "TuxDroid Control Center"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Vector;
+import java.io.FileWriter;
+
+public class IniWriter {
+
+ public static boolean isFile = false;
+ 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;
+ try {
+ writer = new FileWriter(this.iniFile);
+ ini = new IniFile(this.iniFile);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void delete(String key) throws Exception{
+ ini.getHashtable().remove(key);
+ this.write();
+ }
+
+ public void modify(String key){
+
+ }
+
+ public void add(String keyName, Vector<String> datas){
+
+ }
+
+
+ /*
+ * Private ini writer.
+ */
+ private boolean write(){
+
+ //this.iniFile.delete();
+
+ try {
+ this.iniFile.createNewFile();
+ } catch (IOException e) {
+ System.out.println("File error"); //TODO displaying
errorBox instead.
+ return false;
+ }
+
+ for(int i=0; i < this.ini.getHashtable().size(); i++){
+ try {
+ this.writer.write(String.format("\n[%s]",
this.ini.getKeyAtIndex(i)));
+ 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)));
+ this.writer.write("\n");
+ } catch (IOException e) {
+ 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.
+ }
+
+ 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