Changeset 108

Show
Ignore:
Timestamp:
03/02/07 20:14:46 (2 years ago)
Author:
bfitzpa2
Message:

Refactored to use Maps instead of String arrays for songs.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dmp/trunk/XmLRpcBridgeServer/BridgeXmlRpcServer.cs

    r107 r108  
    152152                        while(reader.Read()) 
    153153                        { 
    154                                 Object[] values = new Object[reader.FieldCount]; 
    155                                 reader.GetValues(values); 
    156                                 ArrayList song = new ArrayList(); 
    157                                 foreach(Object obj in values) 
     154                                Hashtable song = new Hashtable(); 
     155                                for (int i = 0; i < reader.FieldCount; i++) 
    158156                                { 
    159                                         song.Add(obj.ToString()); 
     157                                        String columnName = reader.GetName(i); 
     158                                        song.Add(columnName, reader.GetValue(i).ToString()); 
    160159                                } 
    161160                                collection.Add(song); 
  • dmp/trunk/gwt-windows-1.3.3/src/DMP/DMPXmlRpcClient.java

    r107 r108  
    1010import java.net.URL; 
    1111import java.util.Vector; 
     12import java.util.HashMap; 
    1213import java.util.ArrayList; 
    1314 
     
    8788         
    8889        /** 
    89          * Gets a Vector<Vector<String>> of the songs in the collection. 
    90          * @return a Vector<Vector<String>
     90         * Gets a Vector<HashMap> of the songs in the collection. 
     91         * @return a Vector<HashMap
    9192         */ 
    9293        public Vector getSongsFromCollection() 
     
    99100                }  
    100101                catch (XmlRpcException e) { 
    101                         // TODO Auto-generated catch block 
    102102                        e.printStackTrace(); 
    103103                } 
    104104                 
    105                 // formats the returned response into a Vector<Vector<String>> 
    106                 Vector<Vector<String>> response = new Vector<Vector<String>>(); 
    107                 Vector<String> songVector = new Vector<String>(); 
     105                Vector<HashMap> collection = new Vector<HashMap>(); 
    108106                if (resp != null) { 
    109107                        for (Object o : resp) { 
    110                                 Object[] song = (Object[]) o; 
    111                                 songVector = new Vector<String>(); 
    112                                 for (Object obj : song) { 
    113                                         songVector.add((String) obj); 
    114                                 } 
    115                                 response.add(songVector); 
     108                                HashMap song = (HashMap) o; 
     109                                collection.add(song); 
    116110                        } 
    117111                } 
    118                  
    119                 return response; 
     112                return collection; 
    120113        } 
    121114} 
  • dmp/trunk/gwt-windows-1.3.3/src/DMP/client/DMPWebsite.java

    r99 r108  
    77import com.google.gwt.user.client.Timer; 
    88import java.util.Vector; 
     9import java.util.HashMap; 
    910 
    1011/** 
     
    3031                } 
    3132                Widget parent = w.getParent(); 
    32                 Vector song = collection.getSong(clickText); 
     33                HashMap song = collection.getSong(clickText); 
    3334                if(song != null && parent == collection) 
    3435                { 
     
    6768                getSongsFromCollection(); 
    6869 
    69                 Vector tags = new Vector(); 
    70                 tags.add("title"); 
    71                 tags.add("artist"); 
    72                 tags.add("comment"); 
    73                 for(int i = 5; i > 0; i--) 
    74                 { 
    75                         tags.add("test" + i); 
    76                 } 
    77                 collection.setTagList(tags); 
     70                Vector collectionTags = new Vector(); 
     71                collectionTags.add("id"); 
     72                collectionTags.add("Title"); 
     73                collectionTags.add("Artist"); 
     74                collectionTags.add("Size"); 
     75                collectionTags.add("Duration"); 
     76                collection.setTagList(collectionTags); 
    7877                collection.setTitle("Song Collection"); 
     78                 
    7979                playing.setTitle("Now Playing"); 
    80                 playing.setTagList(tags); 
     80                playing.setTagList(collectionTags); //just use the same tags as the collection for now 
    8181                 
    8282                FlowPanel topPanel = new FlowPanel(); 
     
    130130                        } 
    131131                }; 
    132                 testPlay.schedule(60000); 
     132                //testPlay.schedule(60000); 
    133133        } 
    134134         
     
    171171                }); 
    172172        } 
    173  
    174         private FlexTable makeSongTable(int[] songs) 
    175         { 
    176                 FlexTable songTable = new FlexTable(); 
    177                 songTable.setTitle("Collection"); 
    178                 songTable.setCellPadding(5); 
    179                 songTable.setCellSpacing(3); 
    180                 songTable.setBorderWidth(2); 
    181                 songTable.setText(0,0,"Song"); 
    182                 songTable.setText(0, 1, "Album"); 
    183                 songTable.setText(0, 2, "Artist"); 
    184                 return songTable; 
    185         } 
    186173} 
  • dmp/trunk/gwt-windows-1.3.3/src/DMP/client/MusicServ.java

    r78 r108  
    22 
    33import java.util.Vector; 
     4import java.util.HashMap; 
    45import com.google.gwt.user.client.rpc.RemoteService; 
    56 
    67public interface MusicServ extends RemoteService { 
    78        public Vector getSongsFromCollection(); 
    8         public void addSongToPlaying(Vector song); 
    9         public void removeSongFromPlaying(Vector song); 
     9        public void addSongToPlaying(HashMap song); 
     10        public void removeSongFromPlaying(HashMap song); 
    1011        public String getNextSong(); 
    1112} 
  • dmp/trunk/gwt-windows-1.3.3/src/DMP/client/MusicServAsync.java

    r78 r108  
    22 
    33import com.google.gwt.user.client.rpc.*; 
    4 import java.util.Vector
     4import java.util.HashMap
    55 
    66public interface MusicServAsync { 
    77        public void getSongsFromCollection(AsyncCallback callback); 
    8         public void addSongToPlaying(Vector song, AsyncCallback callback); 
    9         public void removeSongFromPlaying(Vector song, AsyncCallback callback); 
     8        public void addSongToPlaying(HashMap song, AsyncCallback callback); 
     9        public void removeSongFromPlaying(HashMap song, AsyncCallback callback); 
    1010        public void getNextSong(AsyncCallback callback); 
    1111} 
  • dmp/trunk/gwt-windows-1.3.3/src/DMP/client/SongTable.java

    r78 r108  
    88import java.util.Vector; 
    99import java.util.Iterator; 
     10import java.util.HashMap; 
    1011 
    1112/** 
     
    7071         * @param song song to add 
    7172         */ 
    72         public void addSong(Vector song) 
     73        public void addSong(HashMap song) 
    7374        { 
    7475                if(!songList.contains(song)) 
     
    8384         * @param song song to remove 
    8485         */ 
    85         public void removeSong(Vector song) 
     86        public void removeSong(HashMap song) 
    8687        { 
    8788                if(songList.contains(song)) 
     
    99100        { 
    100101                Iterator it = songs.iterator(); 
    101                 Vector song = null; 
     102                HashMap song = null; 
    102103                while(it.hasNext()) 
    103104                { 
    104                         song = (Vector) it.next(); 
     105                        song = (HashMap) it.next(); 
    105106                        if(!songList.contains(song)) 
    106107                        { 
     
    112113         
    113114        /** 
     115         * Broken, will fix later. 
    114116         * Sorts the songs in this table by the specified tag 
    115117         * @param tag tag for the songs to be sorted by 
     
    160162        } 
    161163         
    162         /** 
    163          * Emptys and refills the table using the song and tag lists. 
    164          */ 
    165164        protected void refillTable() 
    166165        { 
    167166                emptyTable(); 
    168                 int i = 0; 
    169                 int j = 0; 
    170                 while(i < songList.size()) 
    171                 { 
    172                         j = 0; 
    173                         Vector song = (Vector) songList.get(i); 
    174                         while(j < song.size() && j < tagList.size()) 
    175                         { 
    176                                 if(j == 0) 
    177                                 { 
    178                                         String songTitle = (String) song.get(j); 
     167                for(int row = 0; row < songList.size(); row++) 
     168                { 
     169                        HashMap song = (HashMap) songList.get(row); 
     170                        for(int column = 0; column < tagList.size(); column++) 
     171                        { 
     172                                if(column == 0) 
     173                                { 
     174                                        String songTitle = (String) song.get(((String)tagList.get(column)).toLowerCase()); 
    179175                                        Button songButton = new Button(songTitle); 
    180176                                        songButton.setTitle(songTitle); 
    181177                                        songButton.addClickListener(listener); 
    182                                         this.setWidget(i, j, songButton); 
     178                                        this.setWidget(row, column, songButton); 
    183179                                } 
    184180                                else 
    185181                                { 
    186                                         setText(i,j,(String)song.get(j)); 
    187                                 } 
    188                                 j++; 
    189                         } 
    190                         i++; 
     182                                        setText(row, column, (String) song.get(((String)tagList.get(column)).toLowerCase())); 
     183                                } 
     184                        } 
    191185                } 
    192186                // sets up the top label bar 
    193187                insertRow(0); 
    194                 i = 0; 
     188                int i = 0; 
    195189                while(i < tagList.size()) 
    196190                { 
     
    204198        } 
    205199         
     200        /**  Old method, kept for reference. 
     201         * Emptys and refills the table using the song and tag lists. 
     202         */ 
     203        protected void refillTable2() 
     204        { 
     205                emptyTable(); 
     206                int i = 0; 
     207                int j = 0; 
     208                while(i < songList.size()) 
     209                { 
     210                        j = 0; 
     211                        Vector song = (Vector) songList.get(i); 
     212                        while(j < song.size() && j < tagList.size()) 
     213                        { 
     214                                if(j == 0) 
     215                                { 
     216                                        String songTitle = (String) song.get(j); 
     217                                        Button songButton = new Button(songTitle); 
     218                                        songButton.setTitle(songTitle); 
     219                                        songButton.addClickListener(listener); 
     220                                        this.setWidget(i, j, songButton); 
     221                                } 
     222                                else 
     223                                { 
     224                                        setText(i,j,(String)song.get(j)); 
     225                                } 
     226                                j++; 
     227                        } 
     228                        i++; 
     229                } 
     230                // sets up the top label bar 
     231                insertRow(0); 
     232                i = 0; 
     233                while(i < tagList.size()) 
     234                { 
     235                        String tagTitle = (String) tagList.get(i); 
     236                        Button tagButton = new Button(tagTitle); 
     237                        tagButton.setTitle("Sort by " + tagTitle); 
     238                        tagButton.addClickListener(listener); 
     239                        this.setWidget(0, i, tagButton); 
     240                        i++; 
     241                } 
     242        } 
     243         
    206244        /** 
    207245         * Gets the song in this table with the specified string identifier. 
     
    210248         * @return the song Vector of the found song or null if the song is not found 
    211249         */ 
    212         public Vector getSong(String songIdentifier) 
     250        public HashMap getSong(String songIdentifier) 
    213251        { 
    214252                Iterator it = songList.iterator(); 
    215                 Vector song = new Vector(); 
     253                HashMap song = new HashMap(); 
    216254                while(it.hasNext()) 
    217255                { 
    218                         song = (Vector) it.next(); 
    219                         if(song.contains(songIdentifier)) 
     256                        song = (HashMap) it.next(); 
     257                        if(song.containsValue(songIdentifier)) 
    220258                        { 
    221259                                return song; 
  • dmp/trunk/gwt-windows-1.3.3/src/DMP/server/MusicServImpl.java

    r107 r108  
    2525         
    2626        private static final long serialVersionUID = 02; 
    27         private LinkedList<Vector> playing; 
     27        private LinkedList<HashMap> playing; 
    2828        private DMPXmlRpcClient client; 
    29         private HashMap<Vector,File> flashFileHandles = new HashMap<Vector,File>(); 
     29        private HashMap<HashMap,File> flashFileHandles = new HashMap<HashMap,File>(); 
    3030         
    3131        // testing method 
     
    4141        public MusicServImpl() 
    4242        { 
    43                 playing = new LinkedList<Vector>(); 
     43                playing = new LinkedList<HashMap>(); 
    4444                client = new DMPXmlRpcClient();          
    4545        } 
     
    4848        public String getNextSong() 
    4949        { 
    50                 Vector song = playing.poll(); 
     50                HashMap song = playing.poll(); 
    5151                File songHandle = flashFileHandles.get(song); 
    5252                return songHandle.getPath(); 
    5353        } 
    5454         
    55         public void addSongToPlaying(Vector song) 
     55        public void addSongToPlaying(HashMap song) 
    5656        { 
    5757                playing.add(song); 
     
    5959        } 
    6060         
    61         public void removeSongFromPlaying(Vector song) 
     61        public void removeSongFromPlaying(HashMap song) 
    6262        { 
    6363                if(playing.contains(song)) 
     
    107107         * @return the path of the flash file created 
    108108         */ 
    109         public void makeFlash(Vector song) 
    110         { 
    111                 Integer songID = Integer.parseInt((song.get(0).toString())); 
     109        public void makeFlash(HashMap song) 
     110        { 
     111                Integer songID = Integer.parseInt((song.get("id").toString())); 
    112112                byte[] musicBytes = client.getSong(songID.intValue()); 
    113113                if(musicBytes == null) 
     
    143143                } 
    144144                // use temp files to create flash movie 
    145                 createFlashMovie(tempMusicFile.getPath(),tempFlashFile.getPath()); 
    146                 tempMusicFile.delete(); 
     145                boolean created = createFlashMovie(tempMusicFile.getPath(),tempFlashFile.getPath()); 
     146                System.out.println("" + tempFlashFile.getPath() + " is " + created); 
     147                tempMusicFile.delete(); //always delete the temp music file 
     148                if(!created) //if the flash isn't created, end 
     149                { 
     150                        return; 
     151                } 
    147152                tempFlashFile.deleteOnExit(); 
    148153                flashFileHandles.put(song, tempFlashFile); 
     
    177182                } 
    178183                //System.out.println(makeFlash(musicBytes)); 
    179                 int breakpoint = 0; 
    180184        } 
    181185         
     
    209213                        return false; 
    210214                } 
    211  
    212                 int samplesPerBlock = soundGenerator.getSampleRate() / framesPerSecond; 
    213                 int numberOfBlocks = soundGenerator.getSamplesPerChannel() / samplesPerBlock; 
     215                 
     216                int samplesPerBlock; 
     217                int numberOfBlocks; 
     218                try { 
     219                        samplesPerBlock = soundGenerator.getSampleRate() / framesPerSecond; 
     220                        numberOfBlocks = soundGenerator.getSamplesPerChannel() / samplesPerBlock; 
     221                } catch (ArithmeticException e1) { 
     222                        e1.printStackTrace(); 
     223                        return false; 
     224                } 
    214225                 
    215226                musicMov.add(soundGenerator.streamHeader(samplesPerBlock));