Author: remi
Date: 2008-08-09 12:57:55 +0200 (Sat, 09 Aug 2008)
New Revision: 1451

Modified:
   software_suite_v2/software/tools/attitunesStudio/trunk/.classpath
   software_suite_v2/software/tools/attitunesStudio/trunk/images/Thumbs.db
   software_suite_v2/software/tools/attitunesStudio/trunk/src/MainFrame.java
   
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/ATTConfig.java
   
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/block/ATTBlock.java
   
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTBlockParams.java
   
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTFormatReadWrite.java
   
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTXmlParser.java
   
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/visual/ATTBlockViewer.java
   
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/visual/ATTSButton.java
Log:
* update

Modified: software_suite_v2/software/tools/attitunesStudio/trunk/.classpath
===================================================================
--- software_suite_v2/software/tools/attitunesStudio/trunk/.classpath   
2008-08-07 10:05:24 UTC (rev 1450)
+++ software_suite_v2/software/tools/attitunesStudio/trunk/.classpath   
2008-08-09 10:57:55 UTC (rev 1451)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
        <classpathentry kind="src" path="src"/>
-       <classpathentry kind="src" path="images"/>
+       <classpathentry including="*.PNG|*.att|*.png" kind="src" path="images"/>
        <classpathentry kind="con" 
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>

Modified: 
software_suite_v2/software/tools/attitunesStudio/trunk/images/Thumbs.db
===================================================================
(Binary files differ)

Modified: 
software_suite_v2/software/tools/attitunesStudio/trunk/src/MainFrame.java
===================================================================
--- software_suite_v2/software/tools/attitunesStudio/trunk/src/MainFrame.java   
2008-08-07 10:05:24 UTC (rev 1450)
+++ software_suite_v2/software/tools/attitunesStudio/trunk/src/MainFrame.java   
2008-08-09 10:57:55 UTC (rev 1451)
@@ -1,4 +1,6 @@
 
+import GUI.*;
+
 import com.cloudgarden.layout.AnchorConstraint;
 import com.cloudgarden.layout.AnchorLayout;
 import java.awt.event.MouseAdapter;
@@ -6,23 +8,33 @@
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.awt.Color;
-import javax.swing.BoxLayout;
-import javax.swing.WindowConstants;
+import java.awt.*;
+import java.util.Hashtable;
+
+import javax.swing.ImageIcon;
 import com.tuxisalive.attitunes.*;
+import com.tuxisalive.attitunes.format.*;
 import com.tuxisalive.attitunes.block.ATTBlock;
 import com.tuxisalive.attitunes.block.ATTBlockContainer;
 import com.tuxisalive.attitunes.visual.ATTBlockViewer;
 import com.tuxisalive.attitunes.visual.ATTSButton;
 
+//import javax.swing.JOptionPane;
+
 /**
  * 
  * @author R�mi Jocaille
  *
  */
-public class MainFrame extends javax.swing.JFrame
+public class MainFrame extends Frame
 {
        private static final long serialVersionUID = 724080299924475945L;
        
+       private GridBagLayout frameLayout;
+       
+       private AttituneMenuBar menuBar;
+       private AttituneStatusBar statusBar;
+       
        private ATTBlockViewer attBlockViewer;
        
        private ATTSButton zoomPlusButton;
@@ -52,12 +64,35 @@
        {
                try
                {
+                       /* Create the menu bar */
+                       menuBar = new AttituneMenuBar();
+                       this.setMenuBar(menuBar);
+                       menuBar.events.register("onMenuItemNew", this, 
"onMenuItemNew");
+                       menuBar.events.register("onMenuItemLoad", this, 
"onMenuItemLoad");
+                       menuBar.events.register("onMenuItemSave", this, 
"onMenuItemSave");
+                       menuBar.events.register("onMenuItemSaveAs", this, 
"onMenuItemSaveAs");
+                       menuBar.events.register("onMenuItemProperties", this, 
"onMenuItemProperties");
+                       menuBar.events.register("onMenuItemQuit", this, 
"onMenuItemQuit");
+                       menuBar.events.register("onMenuItemCreate", this, 
"onMenuItemCreate");
+                       menuBar.events.register("onMenuItemDelete", this, 
"onMenuItemDelete");
+                       menuBar.events.register("onMenuItemCopy", this, 
"onMenuItemCopy");
+                       menuBar.events.register("onMenuItemPast", this, 
"onMenuItemPast");
+                       menuBar.events.register("onMenuItemOnline", this, 
"onMenuItemOnline");
+                       menuBar.events.register("onMenuItemAbout", this, 
"onMenuItemAbout");
+                       
                        /* Add a layout to the frame */
-                       BoxLayout thisLayout = new BoxLayout(getContentPane(), 
javax.swing.BoxLayout.Y_AXIS);
-                       getContentPane().setLayout(thisLayout);
+                       frameLayout = new GridBagLayout();
+                       setLayout(frameLayout);
+                       
+                       /* Create the layout constraint */
+                       GridBagConstraints c = new GridBagConstraints();
+                       c.fill = GridBagConstraints.BOTH;
+               c.weightx = 1.0;
+               c.weighty = 1.0;
+               c.gridwidth = GridBagConstraints.REMAINDER;;
+               c.gridheight = 1;
 
                        /* Close window */
-                       
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                        this.addWindowListener(new WindowAdapter() {
                                public void windowClosing(WindowEvent evt) {
                                        thisWindowClosing(evt);
@@ -66,9 +101,22 @@
 
                        /* Main viewer */
                        attBlockViewer = new ATTBlockViewer(640, 300);
+                       attBlockViewer.setPreferredSize(new 
java.awt.Dimension(640, 300));
                        AnchorLayout mainViewerLayout = new AnchorLayout();
                        attBlockViewer.setLayout(mainViewerLayout);
-                       getContentPane().add(attBlockViewer);
+               frameLayout.setConstraints(attBlockViewer, c);
+                       this.add(attBlockViewer);
+                       
+                       Button test = new Button("Hello");
+                       test.setPreferredSize(new java.awt.Dimension(640, 200));
+                       frameLayout.setConstraints(test, c);
+                       this.add(test);
+                       
+                       /* Status bar */
+                       statusBar = new AttituneStatusBar("Hello", "world", 
"coucou");
+                       frameLayout.setConstraints(statusBar, c);
+                       this.add(statusBar);
+                       
                        attBlockViewer.loadImages("/");
                        
attBlockViewer.events.register(ATTConfig.EVENT_POSITION_CHANGED, this, 
"onPositionChanged");
                        
attBlockViewer.events.register(ATTConfig.EVENT_LENGTH_CHANGED, this, 
"onLengthChanged");
@@ -81,13 +129,15 @@
                        
attBlockViewer.events.register(ATTConfig.EVENT_BLOCK_DRAG_STARTED, this, 
"onBlockDragStarted");
                        
attBlockViewer.events.register(ATTConfig.EVENT_BLOCK_DRAGGING, this, 
"onBlockDragging");
                        
attBlockViewer.events.register(ATTConfig.EVENT_BLOCK_DRAG_STOPPED, this, 
"onBlockDragStopped");
+                       
attBlockViewer.events.register(ATTConfig.EVENT_ATTITUNE_LOADED, this, 
"onAttituneLoaded");
+                       
attBlockViewer.events.register(ATTConfig.EVENT_ATTITUNE_SAVED, this, 
"onAttituneSaved");
                        
                        /* Load a file */
-                       
attBlockViewer.loadAttitune(getClass().getResource("aero.att").getPath());
+                       
attBlockViewer.loadAttitune(ATTResources.getRealPath("aero.att"));
                        
                        /* Zoom plus button */
                        zoomPlusButton = new ATTSButton("/zoomPlusButton.png");
-                       zoomPlusButton.setPressedIcon("/zoomPressedButton.png");
+                       zoomPlusButton.setPressedIcon(new 
ImageIcon(getClass().getResource("/zoomPressedButton.png")));
                        zoomPlusButton.addMouseListener(new MouseAdapter() {
                                public void mousePressed(MouseEvent evt) 
                                { 
@@ -98,7 +148,7 @@
                        
                        /* Zoom minus button */
                        zoomMinusButton = new 
ATTSButton("/zoomMinusButton.png");
-                       
zoomMinusButton.setPressedIcon("/zoomPressedButton.png");
+                       zoomMinusButton.setPressedIcon(new 
ImageIcon(getClass().getResource("/zoomPressedButton.png")));
                        zoomMinusButton.addMouseListener(new MouseAdapter() {
                                public void mousePressed(MouseEvent evt) 
                                { 
@@ -109,7 +159,7 @@
                        
                        /* Zoom full button */
                        zoomFullButton = new ATTSButton("/zoomFullButton.png");
-                       zoomFullButton.setPressedIcon("/zoomPressedButton.png");
+                       zoomFullButton.setPressedIcon(new 
ImageIcon(getClass().getResource("/zoomPressedButton.png")));
                        zoomFullButton.addMouseListener(new MouseAdapter() {
                                public void mousePressed(MouseEvent evt) 
                                { 
@@ -120,7 +170,7 @@
                        
                        /* Create button */
                        createButton = new ATTSButton("Create", Color.WHITE, 
"/actionButton1Enable.png");
-                       
createButton.setPressedIcon("/actionButton1Pressed.png");
+                       createButton.setPressedIcon(new 
ImageIcon(getClass().getResource("/actionButton1Pressed.png")));
                        createButton.addMouseListener(new MouseAdapter() {
                                public void mousePressed(MouseEvent evt) 
                                { 
@@ -131,7 +181,7 @@
                        
                        /* Delete button */
                        deleteButton = new ATTSButton("Delete", Color.WHITE, 
"/actionButton1Enable.png");
-                       
deleteButton.setPressedIcon("/actionButton1Pressed.png");
+                       deleteButton.setPressedIcon(new 
ImageIcon(getClass().getResource("/actionButton1Pressed.png")));
                        deleteButton.addMouseListener(new MouseAdapter() {
                                public void mousePressed(MouseEvent evt) 
                                { 
@@ -142,7 +192,7 @@
                        
                        /* Copy button */
                        copyButton = new ATTSButton("Copy", Color.WHITE, 
"/actionButton1Enable.png");
-                       copyButton.setPressedIcon("/actionButton1Pressed.png");
+                       copyButton.setPressedIcon(new 
ImageIcon(getClass().getResource("/actionButton1Pressed.png")));
                        copyButton.addMouseListener(new MouseAdapter() {
                                public void mousePressed(MouseEvent evt) 
                                { 
@@ -153,7 +203,7 @@
                        
                        /* Past button */
                        pastButton = new ATTSButton("Past", Color.WHITE, 
"/actionButton1Enable.png");
-                       pastButton.setPressedIcon("/actionButton1Pressed.png");
+                       pastButton.setPressedIcon(new 
ImageIcon(getClass().getResource("/actionButton1Pressed.png")));
                        pastButton.addMouseListener(new MouseAdapter() {
                                public void mousePressed(MouseEvent evt) 
                                { 
@@ -164,7 +214,7 @@
                        
                        /* Play button */
                        playButton = new ATTSButton("Play", Color.BLACK, 
"/actionButton2Enable.png");
-                       playButton.setPressedIcon("/actionButton2Pressed.png");
+                       playButton.setPressedIcon(new 
ImageIcon(getClass().getResource("/actionButton2Pressed.png")));
                        playButton.addMouseListener(new MouseAdapter() {
                                public void mousePressed(MouseEvent evt) 
                                { 
@@ -175,7 +225,7 @@
                        
                        /* Stop button */
                        stopButton = new ATTSButton("Stop", Color.BLACK, 
"/actionButton2Enable.png");
-                       stopButton.setPressedIcon("/actionButton2Pressed.png");
+                       stopButton.setPressedIcon(new 
ImageIcon(getClass().getResource("/actionButton2Pressed.png")));
                        stopButton.addMouseListener(new MouseAdapter() {
                                public void mousePressed(MouseEvent evt) 
                                { 
@@ -183,7 +233,8 @@
                                }
                        });
                        attBlockViewer.add(stopButton, new AnchorConstraint(10, 
273));
-
+                       attBlockViewer.repaint();
+                       
                        /* Pack the components and set the frame size */
                        pack();
                        setSize(648, 400);
@@ -204,9 +255,122 @@
        private void thisWindowClosing(WindowEvent evt)
        {
                attBlockViewer.destroy();
+               System.exit(0);
        }
        
        /* 
------------------------------------------------------------------------
+        * Menu events
+        * 
--------------------------------------------------------------------- */
+       
+       /*
+        * Event on menu New
+        */
+       public void onMenuItemNew(MenuItem menuItem)
+       {
+               System.out.println("New");
+       }
+       
+       /*
+        * Event on menu Load
+        */
+       public void onMenuItemLoad(MenuItem menuItem)
+       {
+               /* Check if the current scene need to be saved */
+               if (attBlockViewer.getSceneHaveChanged())
+               {
+                       /* Save the changes first */
+                       /* if not changed exit the function */
+               }
+               /* Load a file viewer to select an attitune */
+       }
+       
+       /*
+        * Event on menu Save
+        */
+       public void onMenuItemSave(MenuItem menuItem)
+       {
+               /* Check if the current scene if the template */
+               if (attBlockViewer.getAttituneIsTemplate())
+               {
+                       onMenuItemSaveAs(menuItem);
+               }
+               /* Save the attitune */
+               //attBlockViewer
+       }
+
+       /*
+        * Event on menu Save as
+        */
+       public void onMenuItemSaveAs(MenuItem menuItem)
+       {
+               System.out.println("Save as");
+       }
+       
+       /*
+        * Event on menu Properties
+        */
+       public void onMenuItemProperties(MenuItem menuItem)
+       {
+               System.out.println("Properties");
+       }
+       
+       /*
+        * Event on menu Quit
+        */
+       public void onMenuItemQuit(MenuItem menuItem)
+       {
+               System.out.println("Quit");
+       }
+       
+       /*
+        * Event on menu Create
+        */
+       public void onMenuItemCreate(MenuItem menuItem)
+       {
+               System.out.println("Create");
+       }
+       
+       /*
+        * Event on menu Delete
+        */
+       public void onMenuItemDelete(MenuItem menuItem)
+       {
+               System.out.println("Delete");
+       }
+       
+       /*
+        * Event on menu Copy
+        */
+       public void onMenuItemCopy(MenuItem menuItem)
+       {
+               System.out.println("Copy");
+       }
+       
+       /*
+        * Event on menu Past
+        */
+       public void onMenuItemPast(MenuItem menuItem)
+       {
+               System.out.println("Past");
+       }
+       
+       /*
+        * Event on menu Online
+        */
+       public void onMenuItemOnline(MenuItem menuItem)
+       {
+               System.out.println("Online");
+       }
+       
+       /*
+        * Event on menu About
+        */
+       public void onMenuItemAbout(MenuItem menuItem)
+       {
+               System.out.println("About");
+       }
+       
+       /* 
------------------------------------------------------------------------
         * Blocks viewer events
         * 
--------------------------------------------------------------------- */
        
@@ -215,6 +379,7 @@
         */
        public void onPositionChanged(Double newPosition)
        {
+               statusBar.setLabel1("Position : " + 
ATTMisc.timeToString(newPosition));
        }
        
        /*
@@ -222,6 +387,7 @@
         */
        public void onLengthChanged(Double newLength)
        {
+               statusBar.setLabel2("Duration : " + 
ATTMisc.timeToString(newLength));
        }
        
        /*
@@ -264,6 +430,7 @@
         */
        public void onBlockSelected(ATTBlock block)
        {
+               statusBar.setLabel3("Block start : " + 
ATTMisc.timeToString(block.getPosition()));
        }
        
        /*
@@ -278,6 +445,7 @@
         */
        public void onBlockDragging(ATTBlock block, Double timeIdx)
        {
+               statusBar.setLabel3("Block start : " + 
ATTMisc.timeToString(timeIdx));
        }
        
        /*
@@ -287,6 +455,22 @@
        {
        }
        
+       /*
+        * Event when an attitune is loaded
+        */
+       public void onAttituneLoaded(ATTBlockViewer bv)
+       {
+               statusBar.setLabel1("Position : " + 
ATTMisc.timeToString(attBlockViewer.getCurrentPosition()));
+               statusBar.setLabel2("Duration : " + 
ATTMisc.timeToString(attBlockViewer.getLength()));
+       }
+       
+       /*
+        * Event when an attitune is saved
+        */
+       public void onAttituneSaved(ATTBlockViewer bv)
+       {
+       }
+       
        /* 
------------------------------------------------------------------------
         * Blocks buttons events
         * 
--------------------------------------------------------------------- */
@@ -320,6 +504,13 @@
         */
        public void onCreateButtonPressed(MouseEvent evt)
        {
+               Hashtable<String,Object> params = 
ATTBlockParams.getDefaultBlock(attBlockViewer.getFocusedRow());
+
+               attBlockViewer.createBlock(
+                               attBlockViewer.getFocusedRow(), 
+                               params, 
+                               attBlockViewer.getCurrentPosition(), 
+                               (Double)params.get("duration"));
        }
        
        /*
@@ -327,6 +518,7 @@
         */
        public void onDeleteButtonPressed(MouseEvent evt)
        {
+               attBlockViewer.deleteBlock(attBlockViewer.getFocusedBlock());
        }
        
        /*
@@ -334,6 +526,7 @@
         */
        public void onCopyButtonPressed(MouseEvent evt)
        {
+               attBlockViewer.copyBlock();
        }
        
        /*
@@ -341,6 +534,7 @@
         */
        public void onPastButtonPressed(MouseEvent evt)
        {
+               attBlockViewer.pastBlock(attBlockViewer.getCurrentPosition());
        }
        
        /*
@@ -349,6 +543,7 @@
        public void onPlayButtonPressed(MouseEvent evt)
        {
                attBlockViewer.playScene(attBlockViewer.getCurrentPosition());
+               attBlockViewer.saveAttitune("c:\\aero3.att");
        }
        
        /*

Modified: 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/ATTConfig.java
===================================================================
--- 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/ATTConfig.java
  2008-08-07 10:05:24 UTC (rev 1450)
+++ 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/ATTConfig.java
  2008-08-09 10:57:55 UTC (rev 1451)
@@ -79,6 +79,8 @@
        public static String EVENT_SCROLLBAR_DRAG_STARTED       = 
"scrollbar_drag_started";
        public static String EVENT_SCROLLBAR_DRAG_STOPPED       = 
"scrollbar_drag_stopped";
        public static String EVENT_SCROLLBAR_DRAGGING           = 
"scrollbar_dragging";
+       public static String EVENT_ATTITUNE_LOADED                      = 
"attitune_loaded";
+       public static String EVENT_ATTITUNE_SAVED                       = 
"attitune_saved";
        
        public static String[] EVENT_LIST = {
                EVENT_POSITION_CHANGED,
@@ -92,5 +94,7 @@
                EVENT_SCROLLBAR_DRAG_STARTED,
                EVENT_SCROLLBAR_DRAG_STOPPED,
                EVENT_SCROLLBAR_DRAGGING,
+               EVENT_ATTITUNE_LOADED,
+               EVENT_ATTITUNE_SAVED,
        };
 }
\ No newline at end of file

Modified: 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/block/ATTBlock.java
===================================================================
--- 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/block/ATTBlock.java
     2008-08-07 10:05:24 UTC (rev 1450)
+++ 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/block/ATTBlock.java
     2008-08-09 10:57:55 UTC (rev 1451)
@@ -142,6 +142,7 @@
                if ((value >= 0.0) && (value <= 600. - length))
                {
                        timeBegin = value;
+                       function.put("start_time", (Double)value);
                }               
        }
        

Modified: 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTBlockParams.java
===================================================================
--- 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTBlockParams.java
      2008-08-07 10:05:24 UTC (rev 1450)
+++ 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTBlockParams.java
      2008-08-09 10:57:55 UTC (rev 1451)
@@ -21,16 +21,16 @@
        public static Hashtable<String,Object> LEDS_BLINK_CANVAS = new 
Hashtable<String,Object>();
                static {
                        LEDS_BLINK_CANVAS.put("cmd", "leds_blink");
-                       LEDS_BLINK_CANVAS.put("count", 1.0);
+                       LEDS_BLINK_CANVAS.put("count", 1);
                        LEDS_BLINK_CANVAS.put("speed", 1);
                        LEDS_BLINK_CANVAS.put("duration", 0.0);
                }
        private static String[] ledsBlinkTmc(Hashtable<String,Object> struct)
        {
                String[] result = new String[1];
-               double duration = (Double)struct.get("speed") * 0.008;
+               double duration = (Double)((Integer)struct.get("speed") * 
0.008);
                String cmd = String.format("TUX_CMD:LED:BLINK:LED_BOTH,%d,%g", 
-                               struct.get("count"), duration);
+                               (Integer)struct.get("count"), duration);
                result[0] = cmd;
                return result;
        }

Modified: 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTFormatReadWrite.java
===================================================================
--- 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTFormatReadWrite.java
  2008-08-07 10:05:24 UTC (rev 1450)
+++ 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTFormatReadWrite.java
  2008-08-09 10:57:55 UTC (rev 1451)
@@ -1,12 +1,6 @@
 package com.tuxisalive.attitunes.format;
 
-import java.io.File;
-import java.io.IOException;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.BufferedOutputStream;
-import java.io.BufferedInputStream;
-import java.util.zip.*;
+import java.io.*;
 import java.util.Hashtable;
 
 /**
@@ -24,7 +18,7 @@
        static {
                try
                {
-                       createTmpAttDir();
+                       tmpAttDir = ATTFormatMisc.createTmpAttDir();
                        tmpDirFound = true;
                }
                catch (Exception e)
@@ -37,6 +31,7 @@
         * Attitune file fields
         */
        @SuppressWarnings("unused")
+       private String attFileName = "";
        private String attFilePath = "";
        private String attWorkPath = "";
        private String xmlPath = "";
@@ -44,58 +39,56 @@
        private Hashtable<String,Object> xmlStruct;
        private Hashtable<String,Object> blocksStruct;
        private Hashtable<String,Object> headerStruct;
+       private Hashtable<String,Object> wavStruct;
+       private boolean attituneLoaded = false;
        
-       /*
-        * 
-        */
-       public static void createTmpAttDir() throws IOException
-       {
-               File tempFile = File.createTempFile("attitunesF", "", null);
-               
-        if (!tempFile.delete())
-        {
-            throw new IOException();
-        }
-        
-        if (!tempFile.mkdir())
-        {
-            throw new IOException();
-        }
-        
-        tempFile.deleteOnExit();
-        tmpAttDir = tempFile;
-       }
-       
        /**
         * 
         */
        @SuppressWarnings("unchecked")
        public boolean openAttituneFile(String attFilePath)
        {
+               attFilePath = ATTFormatMisc.regularizePath(attFilePath);
+               
                File attFile = new File(attFilePath);
                
                /* Check if the temp dir exists */
                if (!tmpDirFound)
                {
+                       attituneLoaded = false;
                        return false;
                }
                
                /* Check if the attitune file exists */
                if (!attFile.exists())
                {
+                       attituneLoaded = false;
                        return false;
                }
                
+               /* Get the attitune file name */
+               attFileName = 
attFilePath.substring(attFilePath.lastIndexOf(File.separator) + 
File.separator.length(), attFilePath.lastIndexOf("."));
+               
+               /* Get the destination path */
+               attWorkPath = tmpAttDir.getPath() + File.separator + 
attFileName + File.separator;
+               
                /* Uncompress the attitune file */
-               if (!uncompressAttFile(attFilePath))
+               if (!ATTFormatCompressor.uncompressAttitune(attFilePath, 
attWorkPath))
                {
+                       attituneLoaded = false;
                        return false;
                }
                
+               /* Get some paths */
+               this.attFilePath = attFilePath;
+               xmlPath = attWorkPath + attFileName + File.separator + 
"scene.xml";
+               wavsPath = attWorkPath + attFileName + File.separator + "wavs" 
+ File.separator;
+               
                /* Parse the xml structure */
                xmlStruct = ATTXmlParser.xmlToStruct(xmlPath);
                if (xmlStruct.isEmpty())
                {
+                       attituneLoaded = false;
                        return false;
                }
                
@@ -106,95 +99,463 @@
                
                /* Get the header structure */
                headerStruct = (Hashtable)xmlStruct.get("header");
+               if (!headerStruct.containsKey("language"))
+               {
+                       headerStruct.put("language", "en");
+               }
                
+               /* Get the wav structure */
+               wavStruct = (Hashtable)xmlStruct.get("wavs");
+               
+               attituneLoaded = true;
                return true;
        }
        
-       /*
+       /**
         * 
+        * @param newAttFilePath
+        * @return
         */
-       private static void prepareFileDirectories(String destination, String 
entryName)
+       public boolean saveAttituneFile(String newAttFilePath)
        {
-               String outputFileName = destination + entryName;
-               new File(outputFileName.substring(0, 
outputFileName.lastIndexOf("/"))).mkdirs();
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return false;
+               }
+               
+               newAttFilePath = ATTFormatMisc.regularizePath(newAttFilePath);
+               
+               /* Reconstruction of the xml file */
+               Hashtable<String,Object> newXmlStruct = new 
Hashtable<String,Object>();
+               Hashtable<String,Object> nodeScript = new 
Hashtable<String,Object>();
+               Hashtable<String,Object> nodeBody = new 
Hashtable<String,Object>();
+               
+               nodeScript.put("timeline", blocksStruct);
+               nodeBody.put("script", nodeScript);
+               newXmlStruct.put("body", nodeBody);
+               newXmlStruct.put("wavs", wavStruct);
+               newXmlStruct.put("header", headerStruct);
+               
+               ATTXmlParser.structToXml(newXmlStruct, xmlPath);
+               
+               /* Get the new uncompressed attitune directory path and name */
+               String newFileName = 
newAttFilePath.substring(newAttFilePath.lastIndexOf(File.separator) + 
File.separator.length(), 
+                               newAttFilePath.lastIndexOf("."));
+               String newWorkPath = tmpAttDir.getPath() + File.separator + 
newFileName + File.separator;
+               
+               /* Copy the new directory if != of the current one */
+               if (newFileName != attFileName)
+               {
+                       String destDir = newWorkPath + newFileName + 
File.separator;
+                       String srcDir = attWorkPath + attFileName + 
File.separator;
+                       
+                       if (!ATTFormatMisc.copyDir(srcDir, destDir))
+                       {
+                               return false;
+                       }
+               }
+               
+               /* Compress the attitune directory to the destination *.att 
file */
+               if (!ATTFormatCompressor.compressAttitune(newAttFilePath, 
newWorkPath))
+               {
+                       return false;
+               }
+               
+               return true;
        }
        
-       /*
+       /**
         * 
+        * @return
         */
-       private boolean uncompressAttFile(String attFilePath)
+       public String getAttFilePath()
        {
-               BufferedOutputStream dest = null;
-               FileInputStream fis;
-               ZipInputStream zis;
-               ZipEntry entry;
-               int count;
-               byte data[] = new byte[8192];
-               String fwext = 
attFilePath.substring(attFilePath.lastIndexOf("/") + 1, 
attFilePath.lastIndexOf("."));
-               String destination = tmpAttDir.getPath() + File.separator + 
fwext + File.separator;
+               return attFilePath;
+       }
+       
+       
+       /**
+        * 
+        * @return
+        */
+       public Hashtable<String,Object> getBocksStruct()
+       {
+               return blocksStruct;
+       }
+       
+       /**
+        * 
+        * @param struct
+        */
+       public void setBlockStruct(Hashtable<String,Object> struct)
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return;
+               }
                
-               try
+               blocksStruct = struct;
+       }
+       
+       /**
+        * 
+        * @param waveName
+        * @return
+        */
+       public String getWaveFile(String waveName)
+       {
+               return wavsPath + waveName;
+       }
+       
+       /**
+        * 
+        * @param wavePath
+        */
+       public boolean insertWaveFile(String wavePath)
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
                {
-                       fis = new FileInputStream(attFilePath);
-                       zis = new ZipInputStream(new BufferedInputStream(fis));
-
-               while ((entry = zis.getNextEntry()) != null)
-               {
-                       if (!entry.isDirectory())
-                       {
-                               prepareFileDirectories(destination, 
entry.getName());
-                               String destFileName = destination + 
File.separator + entry.getName();
-                               FileOutputStream fos = new 
FileOutputStream(destFileName);
-                       dest = new BufferedOutputStream(fos, 8192);
-                       while((count = zis.read(data, 0, 8192)) != -1)
-                       {
-                         dest.write(data, 0, count);
-                       }
-                       dest.flush();
-                       dest.close();
-                       }
-               }
-               zis.close();
+                       return false;
                }
-               catch (Exception e)
+               
+               String waveName = 
wavePath.substring(wavePath.lastIndexOf(File.separator) + 
File.separator.length(), 
+                               wavePath.length());
+               String destWavePath = wavsPath + waveName;
+               
+               if (ATTFormatMisc.copyfile(wavePath, destWavePath))
                {
-                       e.printStackTrace();
+                       Integer wavCount = (Integer)wavStruct.get("count");
+                       wavStruct.put(String.format("wav%d", wavCount), 
waveName);
+                       wavCount++;
+                       wavStruct.put("count", wavCount);
+               }
+               else
+               {
                        return false;
                }
                
-               this.attFilePath = attFilePath;
-               attWorkPath = destination;
-               xmlPath = attWorkPath + fwext + File.separator + "scene.xml";
-               wavsPath = attWorkPath + fwext + File.separator + "wavs" + 
File.separator;
-               
                return true;
        }
        
        /**
         * 
+        * @param waveName
+        */
+       public boolean deleteWaveFile(String waveName)
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return false;
+               }
+               
+               Hashtable<String,Object> newWavStruct = new 
Hashtable<String,Object>();
+               Integer count = 0;
+               
+               if (ATTFormatMisc.deleteFile(wavsPath + waveName))
+               {
+                       for (int i = 0; i < (Integer)wavStruct.get("count"); 
i++)
+                       {
+                               String tmpWavName = 
(String)wavStruct.get(String.format("wav%d", i));
+                               if (!tmpWavName.equals(waveName))
+                               {
+                                       newWavStruct.put(String.format("wav%d", 
count), tmpWavName);
+                                       count++;
+                               }
+                       }
+                       newWavStruct.put("count", count);
+                       wavStruct = newWavStruct;
+                       return true;
+               }
+               
+               return false;
+       }
+       
+       /**
+        * 
         * @return
         */
-       public Hashtable<String,Object> getBocksStruct()
+       public Hashtable<String,Object> getWavsStruct()
        {
-               return blocksStruct;
+               return wavStruct;
        }
        
        /**
         * 
+        * @param struct
+        */
+       public void setWavsStruct(Hashtable<String,Object> struct)
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return;
+               }
+               
+               wavStruct = struct;
+       }
+
+       /**
+        * 
+        */
+       public void setHeaderAuthor(String value)
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return;
+               }
+               
+               headerStruct.put("author", value);
+       }
+       
+       /**
+        * 
         * @return
         */
-       public Hashtable<String,Object> getHeaderStruct()
+       public String getHeaderAuthor()
        {
-               return headerStruct;
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return "";
+               }
+               
+               return (String)headerStruct.get("author");
        }
        
        /**
         * 
-        * @param waveName
+        */
+       public void setHeaderCategory(String value)
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return;
+               }
+               
+               headerStruct.put("category", value);
+       }
+       
+       /**
+        * 
         * @return
         */
-       public String getWaveFile(String waveName)
+       public String getHeaderCategory()
        {
-               return wavsPath + waveName;
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return "";
+               }
+               
+               return (String)headerStruct.get("category");
        }
+       
+       /**
+        * 
+        */
+       public void setHeaderDescription(String value)
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return;
+               }
+               
+               headerStruct.put("description", value);
+       }
+       
+       /**
+        * 
+        * @return
+        */
+       public String getHeaderDescription()
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return "";
+               }
+               
+               return (String)headerStruct.get("description");
+       }
+       
+       /**
+        * 
+        */
+       public void setHeaderName(String value)
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return;
+               }
+               
+               headerStruct.put("name", value);
+       }
+       
+       /**
+        * 
+        * @return
+        */
+       public String getHeaderName()
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return "";
+               }
+               
+               return (String)headerStruct.get("name");
+       }
+       
+       /**
+        * 
+        */
+       public void setHeaderSubCategory(String value)
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return;
+               }
+               
+               headerStruct.put("sub_category", value);
+       }
+       
+       /**
+        * 
+        * @return
+        */
+       public String getHeaderSubCategory()
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return "";
+               }
+               
+               return (String)headerStruct.get("sub_category");
+       }
+       
+       /**
+        * 
+        */
+       public void setHeaderVersion(String value)
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return;
+               }
+               
+               headerStruct.put("version", value);
+       }
+       
+       /**
+        * 
+        * @return
+        */
+       public String getHeaderVersion()
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return "";
+               }
+               
+               return (String)headerStruct.get("version");
+       }
+       
+       /**
+        * 
+        */
+       public void setHeaderLanguage(String value)
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return;
+               }
+               
+               headerStruct.put("language", value);
+       }
+       
+       /**
+        * 
+        * @return
+        */
+       public String getHeaderLanguage()
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return "";
+               }
+               
+               return (String)headerStruct.get("language");
+       }
+       
+       /**
+        * 
+        */
+       public void setHeaderLength(Double value)
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return;
+               }
+               
+               headerStruct.put("length", value);
+       }
+       
+       /**
+        * 
+        * @return
+        */
+       public Double getHeaderLength()
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return 0.;
+               }
+               
+               return (Double)headerStruct.get("length");
+       }
+       
+       /**
+        * 
+        */
+       public void setHeaderKeywords(String value)
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return;
+               }
+               
+               headerStruct.put("keywords", value);
+       }
+       
+       /**
+        * 
+        * @return
+        */
+       public String getHeaderKeywords()
+       {
+               /* Check if an attitune has been loaded before */
+               if (!attituneLoaded)
+               {
+                       return "";
+               }
+               
+               return (String)headerStruct.get("keywords");
+       }
 }

Modified: 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTXmlParser.java
===================================================================
--- 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTXmlParser.java
        2008-08-07 10:05:24 UTC (rev 1450)
+++ 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/format/ATTXmlParser.java
        2008-08-09 10:57:55 UTC (rev 1451)
@@ -192,6 +192,10 @@
                                {
                                        nodeStruct.put(childName, childValue);
                                }
+                               else if (childType.equals("list"))
+                               {
+                                       nodeStruct.put(childName, childValue);
+                               }
                                else if (childType.equals("int"))
                                {
                                        nodeStruct.put(childName, 
Integer.parseInt(childValue));

Modified: 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/visual/ATTBlockViewer.java
===================================================================
--- 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/visual/ATTBlockViewer.java
      2008-08-07 10:05:24 UTC (rev 1450)
+++ 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/visual/ATTBlockViewer.java
      2008-08-09 10:57:55 UTC (rev 1451)
@@ -86,6 +86,10 @@
        
        public TuxAPI tux = new TuxAPI("localhost", 270);
        
+       private boolean sceneHaveChanged = false;
+       
+       private boolean attituneIsTemplate = false;
+       
        /**
         * Constructor of the class.
         * @param width width of the viewer
@@ -184,6 +188,8 @@
                this.setVisible(true);
                /* Connect the tuxdroid api */
                tux.server.autoConnect(TuxAPIConst.CLIENT_LEVEL_RESTRICTED, 
"AttitunesStudio", "attscene");
+               /* Refresh the viewer */
+               this.setZoomFactor(1);
        }
        
        /**
@@ -237,6 +243,24 @@
        
        /**
         * 
+        * @return
+        */
+       public Boolean getSceneHaveChanged()
+       {
+               return sceneHaveChanged;
+       }
+       
+       /**
+        * 
+        * @return
+        */
+       public boolean getAttituneIsTemplate()
+       {
+               return attituneIsTemplate;
+       }
+       
+       /**
+        * 
         * @param path
         * @return
         */
@@ -438,6 +462,7 @@
                        if (scrollbarIsFocused)
                        {
                                scrollbarIsFocused = false;
+                               sceneHaveChanged = true;
                                
events.emit(ATTConfig.EVENT_SCROLLBAR_DRAG_STOPPED);
                        }
                        if (draggingBlock)
@@ -1076,16 +1101,73 @@
        public ATTBlock createBlock(int rowIdx, Hashtable<String,Object> 
fctParams, double timeBegin, double timeLength)
        {
                ATTBlock resBlock = blockContainers[rowIdx].newBlock();
+               resBlock.setFunctionParams(fctParams);
                resBlock.setPosition(timeBegin);
-               resBlock.setFunctionParams(fctParams);
                resBlock.setLength(timeLength);
                recalcFullTime();
                setFocusedBlock(resBlock);
                this.repaint();
+               sceneHaveChanged = true;
                return resBlock;
        }
        
        /**
+        * 
+        * @param block
+        * @param fctParams
+        */
+       public void updateBlock(ATTBlock block, Hashtable<String,Object> 
fctParams)
+       {
+               block.setFunctionParams(fctParams);
+               recalcFullTime();
+               this.repaint();
+               sceneHaveChanged = true;
+       }
+       
+       /**
+        * 
+        */
+       public boolean insertWaveFile(String wavePath)
+       {
+               if (attituneFile.insertWaveFile(wavePath))
+               {
+                       sceneHaveChanged = true;
+                       return true;
+               }
+               
+               return false;
+       }
+       
+       /**
+        * 
+        * @param waveName
+        * @return
+        */
+       public boolean deleteWaveFile(String waveName)
+       {
+               if (attituneFile.deleteWaveFile(waveName))
+               {
+                       sceneHaveChanged = true;
+                       return true;
+               }
+               
+               return false;
+       }
+       
+       /**
+        * Handle new attitune file
+        */
+       public void createAttitune()
+       {
+               if (!loadAttitune("c:/template.att"))
+               {
+                       return;
+               }
+               attituneIsTemplate = true;
+               sceneHaveChanged = true;
+       }
+       
+       /**
         * Delete a block from the scene
         * @param block
         */
@@ -1109,6 +1191,7 @@
                                                
blockContainers[i].deleteBlock(j);
                                                recalcFullTime();
                                                this.repaint();
+                                               sceneHaveChanged = true;
                                        }
                                        
                                        return;
@@ -1174,14 +1257,45 @@
                }
                
                this.repaint();
+               attituneIsTemplate = false;
+               events.emit(ATTConfig.EVENT_ATTITUNE_LOADED, this);
+               return true;
+       }
+       
+       /**
+        * 
+        * @param attFilePath
+        * @return
+        */
+       public boolean saveAttitune(String attFilePath)
+       {
+               /* Refresh the blocks structure in the attitune object */
+               attituneFile.setBlockStruct(getBlocksStruct());
                
+               /* Save the attitune file */
+               if (!attituneFile.saveAttituneFile(attFilePath))
+               {
+                       return false;
+               }
+               sceneHaveChanged = true;
+               events.emit(ATTConfig.EVENT_ATTITUNE_SAVED, this);
+               
+               /* Reload the attitune */
+               if (attFilePath != attituneFile.getAttFilePath())
+               {
+                       if (!loadAttitune(attFilePath))
+                       {
+                               return false;
+                       }
+               }
+               
                return true;
        }
        
        /*
         * 
         */
-       private Hashtable<String,Object> getBlocksStruct()
+       public Hashtable<String,Object> getBlocksStruct()
        {
                Hashtable<String,Object> result = new 
Hashtable<String,Object>();
                int count = 0;
@@ -1368,6 +1482,8 @@
                                        getFunctionParams().get("wav_name")));
                }
                
+               sceneHaveChanged = true;
+               
                return newBlock;
        }
 }

Modified: 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/visual/ATTSButton.java
===================================================================
--- 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/visual/ATTSButton.java
  2008-08-07 10:05:24 UTC (rev 1450)
+++ 
software_suite_v2/software/tools/attitunesStudio/trunk/src/com/tuxisalive/attitunes/visual/ATTSButton.java
  2008-08-09 10:57:55 UTC (rev 1451)
@@ -23,7 +23,7 @@
                
                try
                {
-                       enabledIcon = new 
ImageIcon(getClass().getResource(baseIcon).getPath());
+                       enabledIcon = new 
ImageIcon(getClass().getResource(baseIcon));
                } catch(Exception e) {}
                
                this.setIcon(enabledIcon);


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