Initial code check in continued

This commit is contained in:
dennis.sheirer
2014-04-26 19:48:24 +00:00
parent 960a6f9952
commit 3dfedcf8d1
474 changed files with 76613 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>
******************************************************************************/
package playlist;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import alias.AliasDirectory;
import controller.channel.ChannelMapList;
import controller.system.SystemList;
@XmlSeeAlso( { AliasDirectory.class,
ChannelMapList.class,
SystemList.class } )
@XmlRootElement( name = "playlist" )
public class Playlist
{
private AliasDirectory mAliasDirectory = new AliasDirectory();
private ChannelMapList mChannelMapList = new ChannelMapList();
private SystemList mSystemList = new SystemList();
public Playlist()
{
}
@XmlElement( name = "alias_directory" )
public AliasDirectory getAliasDirectory()
{
mAliasDirectory.refresh();
return mAliasDirectory;
}
public void setAliasDirectory( AliasDirectory directory )
{
mAliasDirectory = directory;
}
@XmlElement( name = "system_list" )
public SystemList getSystemList()
{
return mSystemList;
}
public void setSystemList( SystemList list )
{
mSystemList = list;
}
@XmlElement( name = "channel_maps" )
public ChannelMapList getChannelMapList()
{
return mChannelMapList;
}
public void setChannelMapList( ChannelMapList list )
{
mChannelMapList = list;
}
}

View File

@@ -0,0 +1,214 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>
******************************************************************************/
package playlist;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import log.Log;
import properties.SystemProperties;
public class PlaylistManager
{
private Playlist mPlaylist = new Playlist();
public PlaylistManager()
{
init();
}
public Playlist getPlayist()
{
return mPlaylist;
}
/**
* Loads playlist from the current playlist file, or the default playlist file,
* as specified in the current SDRTRunk system settings
*/
private void init()
{
SystemProperties props = SystemProperties.getInstance();
Path playlistFolder = props.getApplicationFolder( "playlist" );
String defaultPlaylistFile =
props.get( "playlist.defaultfilename", "playlist.xml" );
String playlistFile =
props.get( "playlist.currentfilename", defaultPlaylistFile );
load( playlistFolder.resolve( playlistFile ) );
}
public void save()
{
JAXBContext context = null;
SystemProperties props = SystemProperties.getInstance();
Path playlistPath = props.getApplicationFolder( "playlist" );
String playlistDefault = props.get( "playlist.defaultfilename",
"playlist.xml" );
String playlistCurrent = props.get( "playlist.currentfilename",
playlistDefault );
Path filePath = playlistPath.resolve( playlistCurrent );
File outputFile = new File( filePath.toString() );
try
{
if( !outputFile.exists() )
{
outputFile.createNewFile();
}
}
catch( Exception e )
{
Log.error( "PlaylistManager - couldn't create file to save playlist [" + filePath.toString() + "]" );
}
OutputStream out = null;
try
{
out = new FileOutputStream( outputFile );
try
{
context = JAXBContext.newInstance( Playlist.class );
Marshaller m = context.createMarshaller();
m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true );
m.marshal( mPlaylist, out );
}
catch ( JAXBException e )
{
Log.error( "PlaylistManager - jaxb exception while saving " +
"playlist: " + e.getLocalizedMessage() );
e.printStackTrace();
}
}
catch ( Exception e )
{
Log.error( "PlaylistManager - coulcn't open outputstream to " +
"save playlist [" + filePath.toString() + "]" );
}
finally
{
if( out != null )
{
try
{
out.close();
}
catch ( IOException e )
{
e.printStackTrace();
}
}
}
}
/**
* Erases current playlist and loads playlist from the playlistPath filename,
* if it exists.
*/
public void load( Path playlistPath )
{
if( Files.exists( playlistPath ) )
{
Log.info( "PlaylistManager - loading playlist file [" +
playlistPath.toString() + "]" );
JAXBContext context = null;
InputStream in = null;
try
{
in = new FileInputStream( playlistPath.toString() );
try
{
context = JAXBContext.newInstance( Playlist.class );
Unmarshaller m = context.createUnmarshaller();
mPlaylist = (Playlist)m.unmarshal( in );
}
catch ( JAXBException e )
{
Log.error( "PlaylistManager - jaxb exception while loading " +
"playlist: " + e.getLocalizedMessage() );
e.printStackTrace();
}
}
catch ( Exception e )
{
e.printStackTrace();
Log.error( "PlaylistManager - coulcn't open inputstream to " +
"load playlist [" + playlistPath.toString() + "]" );
}
finally
{
if( in != null )
{
try
{
in.close();
}
catch ( IOException e )
{
Log.error( "PlaylistManager - exception while closing " +
"the playlist file inputstream reader - " +
e.getLocalizedMessage() );
}
}
}
}
else
{
Log.info( "PlaylistManager - playlist does not exist [" +
playlistPath.toString() + "]" );
}
if( mPlaylist == null )
{
mPlaylist = new Playlist();
}
}
}

View File

@@ -0,0 +1,147 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>
******************************************************************************/
package playlist;
import javax.swing.JPanel;
import alias.AliasDirectory;
import alias.AliasDirectoryNode;
import controller.BaseNode;
import controller.EmptyEditor;
import controller.channel.ChannelMapList;
import controller.channel.ChannelMapListNode;
import controller.system.SystemList;
import controller.system.SystemListNode;
public class PlaylistNode extends BaseNode
{
private static final long serialVersionUID = 1L;
private AliasDirectoryNode mAliasDirectoryNode;
private ChannelMapListNode mChannelMapListNode;
private SystemListNode mSystemListNode;
public PlaylistNode()
{
super( null );
}
private void init()
{
/**
* Delete any existing children
*/
delete();
/**
* Load the AliasDirectory
*/
AliasDirectory directory = getPlaylist().getAliasDirectory();
if( directory == null )
{
directory = new AliasDirectory();
getPlaylist().setAliasDirectory( directory );
}
mAliasDirectoryNode = new AliasDirectoryNode( directory );
getModel().insertNodeInto( mAliasDirectoryNode, this, 0 );
mAliasDirectoryNode.init();
/**
* Load the Channel Map List
*/
ChannelMapList channelMapList = getPlaylist().getChannelMapList();
if( channelMapList == null )
{
channelMapList = new ChannelMapList();
}
mChannelMapListNode = new ChannelMapListNode( channelMapList );
getModel().insertNodeInto( mChannelMapListNode, this, 1 );
mChannelMapListNode.init();
/**
* Load the SystemList
*/
SystemList list = getPlaylist().getSystemList();
if( list == null )
{
list = new SystemList();
getPlaylist().setSystemList( list );
}
mSystemListNode = new SystemListNode( list );
getModel().insertNodeInto( mSystemListNode, this, 2 );
mSystemListNode.init();
mSystemListNode.show();
}
public SystemListNode getSystemListNode()
{
return mSystemListNode;
}
public AliasDirectoryNode getAliasDirectoryNode()
{
return mAliasDirectoryNode;
}
public void loadPlaylist()
{
Playlist playlist =
getModel().getResourceManager().getPlaylistManager().getPlayist();
setUserObject( playlist );
init();
}
public Playlist getPlaylist()
{
Playlist retVal = null;
Object userObject = getUserObject();
if( userObject != null )
{
retVal = (Playlist)userObject;
}
return retVal;
}
public String toString()
{
return "Playlist";
}
public JPanel getEditor()
{
return new EmptyEditor();
}
}