Author: jerome
Date: 2008-08-17 14:52:05 +0200 (Sun, 17 Aug 2008)
New Revision: 1536

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:
* Started add ChatterTux parameters.

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 12:00:03 UTC (rev 1535)
+++ 
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/ConfInterface.java
        2008-08-17 12:52:05 UTC (rev 1536)
@@ -24,6 +24,7 @@
 import javax.swing.ButtonGroup;
 import javax.swing.JButton;
 import javax.swing.JFrame;
+import javax.swing.JLabel;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JRadioButton;
@@ -32,6 +33,7 @@
 import javax.swing.JTextArea;
 import javax.swing.JTextField;
 import javax.swing.SpinnerListModel;
+import javax.swing.SpinnerModel;
 
 import com.tuxisalive.api.TuxAPI;
 import com.tuxisalive.api.TuxAPIConst;
@@ -45,6 +47,7 @@
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Locale;
+import java.util.Vector;
 
 /**
  * Chatter Tux configuration Object.
@@ -68,21 +71,22 @@
        private JButton cancel;
        private JButton okEdition;
        private JButton deleteEdition;
-       private JButton okAdd; //TODO 
+       private JButton add; //TODO 
        
        /* Voice configuration */
        private JComboBox locutorSet;
        private JComboBox tuxBody;
        private JSpinner pitchSet;
+       private JLabel howManyTime = new JLabel("How many time:");
        
        /* Parametrized values */
        private JComboBox parametrized;
        private JComboBox actionType;
        private JTextArea parameters = new JTextArea();
        private JTextField ttsSet;
+       private JSpinner manyValue;
        
        private File iniFile = new 
File("c:\\tuxdroid\\bin\\chattertux\\ChatterTux.ini");
-       private String location;
        
        //Current tts parsed action.
        public static String action = "none";
@@ -190,14 +194,18 @@
                return jContentPane;
        }
        
+       public String getFromIni(String key){
+               Hashtable<String, String> stored = 
this.properties.getProperties("VOICE CONFIGURATION");
+               return stored.get(key);
+       }
        
        /*
         * Sets the stored locutor into locutor combobox.
         */
        public void setStoredLocutor(){
-               Hashtable<String, String> storedLocutor = 
this.properties.getProperties("VOICE CONFIGURATION");
-               String locutor = storedLocutor.get("locutor");
                
+               String locutor = this.getFromIni("locutor");
+               
                //Displaying registered locutor configuration.
                if(this.locutorSet.getItemCount() <= 0){
                        this.locutorSet.addItem(locutor);
@@ -213,7 +221,12 @@
                this.locutorSet.setSelectedItem(locutor);
        }
        
+       public void setStoredPitch(){
+               String pitch = this.getFromIni("pitch");
+               this.pitchSet.setValue(Integer.valueOf(pitch));
+       }
        
+       
        //Gets voice configuration panel.
        public JPanel getVoiceConfigurationPanel(){
                if(this.voiceConfigPanel == null){
@@ -244,10 +257,8 @@
                        this.pitchSet.setModel(new SpinnerListModel(values));
                        
                        this.setStoredLocutor(); //Sets the registered locutor 
as first.
-                       Hashtable<String, String> storedLocutor = 
this.properties.getProperties("VOICE CONFIGURATION");
-                       String pitch = storedLocutor.get("pitch");
+                       this.setStoredPitch();   //same as locutor.
                        //Displaying registered pitch configuration.
-                       this.pitchSet.setValue(Integer.valueOf(pitch));
                        this.pitchSet.setFocusable(false);
                        
                        //Getting server start / stop function buttons.
@@ -422,7 +433,7 @@
                        this.okEdition.setFocusPainted(false);
                        this.okEdition.addMouseListener(new 
java.awt.event.MouseAdapter(){
                                public void 
mousePressed(java.awt.event.MouseEvent event){
-                                       storeAsIni();
+                                       
storeModificationsToIni(ConfInterface.currentKey);
                                }
                        });
                        this.okEdition.setLocation(new Point(294, 100));
@@ -468,12 +479,30 @@
                        this.tuxBody.setFocusable(false);
                        this.tuxBody.setLocation(new 
Point(this.actionType.getX(), 60));
                        this.editPanel.add(this.tuxBody);
+                       
+                       Integer[] values = new Integer[10];
+                       for(int i=1; i < 11; i++){
+                               values[i-1] = Integer.valueOf(i);
+                       }
+                       this.manyValue = new JSpinner();
+                       this.manyValue.setModel(new SpinnerListModel(values));
+                       this.manyValue.setSize(this.pitchSet.getSize());
+                       
this.manyValue.setPreferredSize(this.manyValue.getSize());
+                       this.manyValue.setVisible(false);
+                       this.manyValue.setLocation(new Point(280, 
this.tuxBody.getY()));
+                       
+                       this.howManyTime.setSize(this.tuxBody.getSize());
+                       this.howManyTime.setLocation(180, this.tuxBody.getY());
+                       this.howManyTime.setVisible(false);
+                       
                        //Create tts modification gfx.
                        this.ttsSet = new JTextField();
                        this.ttsSet.setSize(this.actionType.getSize());
                        this.ttsSet.setPreferredSize(this.ttsSet.getSize());
                        this.ttsSet.setLocation(new 
Point(this.actionType.getX(), 60));
                        this.editPanel.add(this.ttsSet);
+                       this.editPanel.add(this.manyValue);
+                       this.editPanel.add(this.howManyTime);
                }
                return this.editPanel;
        }
@@ -493,8 +522,23 @@
        }
        
        //TODO store modifications.
-       public void storeModificationsToIni(){
-               
+       public void storeModificationsToIni(String key){
+               String action = this.actionType.getSelectedItem().toString();
+               String command = "";
+               if(this.ttsSet.isVisible()){ //then tts parameter.
+                       command = this.ttsSet.getText();
+               }
+               else if(this.tuxBody.isVisible()){ //then it's an api command.
+                       command = this.tuxBody.getSelectedItem().toString();
+                       //then reverting command to be right with api.
+                       command = this.revertParsedCommand(command);
+               }
+               Vector<String> values = new Vector<String>();
+               values.add(action);
+               values.add(command);
+               this.writer.modify(key, values);
+               this.properties.updateHashTable(this.ini.getHashtable());
+               this.updateValues();
        }
        
        /*
@@ -561,6 +605,8 @@
        
        public void setTTSEditComponentsVivible(boolean arg0){
                this.tuxBody.setVisible(false);
+               this.howManyTime.setVisible(false);
+               this.manyValue.setVisible(false);
                this.ttsSet.setVisible(true);
        }
        
@@ -568,6 +614,8 @@
        public void setAPIEditComponentsVisible(boolean arg0){
                this.ttsSet.setVisible(false);
                this.tuxBody.setVisible(true);
+               this.howManyTime.setVisible(true);
+               this.manyValue.setVisible(true);
        }
        
        /*
@@ -608,11 +656,35 @@
                        ConfInterface.action = "Spin right";
                        returns.append("moves to the right");
                }
+               if(command.contains(".onAsync(")){
+                       int index = command.indexOf("(") + 1;
+                       int end = command.indexOf(", SSV_NDEF");
+                       Integer value = 
Integer.valueOf(command.substring(index, end));
+                       this.manyValue.setValue(value);
+               }
                
                return returns.toString();
        }
        
-       //TODO 
+       //Return reverted parsed command.
+       public String revertParsedCommand(String command){
+               StringBuffer result = new StringBuffer();
+               result.append("tux.");
+               if(command.contains("Spin right")) 
result.append("spinning.right");
+               else if(command.contains("Spin left")) 
result.append("spinning.left");
+               else if(command.contains("Right led")) 
result.append("led.right");
+               else if(command.contains("Left led")) result.append("led.left");
+               else if(command.contains("Both leds")) 
result.append("led.both");
+               else if(command.contains("Flippers")) result.append("flippers");
+               else if(command.contains("Mouth")) result.append("mouth");
+               else if(command.contains("Eyes")) result.append("eyes");
+               result.append(String.format(".onAsync(%s, SSV_NDEF)", 
this.manyValue.getValue().toString()));
+               return result.toString();
+       }
+       
+       /*
+        * Update components that deponds on Tchatter Tux ini file.
+        */
        public void updateValues(){
                this.onRadioConnected(null, null);
                this.parametrized.removeAllItems();
@@ -621,6 +693,7 @@
                }
                this.parametrized.setSelectedIndex(0);
                this.setStoredLocutor();
+               this.setStoredPitch();
        }
        
        

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 12:00:03 UTC (rev 1535)
+++ 
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniFile.java  
    2008-08-17 12:52:05 UTC (rev 1536)
@@ -133,7 +133,12 @@
                this.indexes = tmp;
        }
        
+       public void add(String key, Vector<String> values){
+               this.keys.put(key, values);
+               this.indexes.put(Integer.valueOf(this.keys.size()), key);
+       }
        
+       
        /*
         * 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 12:00:03 UTC (rev 1535)
+++ 
software_suite_v2/software/tools/chatterTux/trunk/Chatter_tux/src/IniWriter.java
    2008-08-17 12:52:05 UTC (rev 1536)
@@ -53,12 +53,18 @@
                this.write();
        }
        
-       public void modify(String key){
-               
+       public void modify(String key, Vector<String> datas){
+               try {
+                       this.delete(key);
+                       this.add(key, datas);
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
        }
        
        public void add(String keyName, Vector<String> datas){
-               
+               this.ini.add(keyName, datas);
+               this.write();
        }
        
        
@@ -77,7 +83,7 @@
                        return false;
                }
                
-               for(int i=0; i < this.ini.getHashtable().size(); i++){
+               for(int i=0; i < this.ini.getLength(); i++){
                        try {
                                this.writer.write("[" + 
this.ini.getKeyAtIndex(i) + "]\n");
                                Vector<String> dat = 
this.ini.getKeyPropertiesAtKey(this.ini.getKeyAtIndex(i));


-------------------------------------------------------------------------
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

Reply via email to