WIP #34: added channel map manager and new editor window. Removed a

number of unused classes.  Removed playlist manager from a number of
classes and replaced with the alias, channel and channel map models.
Updated playlist manager to no longer retain a playlist except for when
loading to models or when storing from models.  Extracted version 1 to
version 2 playlist conversion and changed playlist manager to keep the
original version 1 playlist and create a new version 2 (playlist_v2.xml)
file.  On startup, try to load a v2, and if not, look for a v1 to
convert.  Otherwise, don't create a playlist and one will be created
once the user adds items to the models.
This commit is contained in:
denny
2016-03-06 07:48:14 -05:00
parent 8aebdd1c26
commit 2394ac2fa9
75 changed files with 2154 additions and 5008 deletions

View File

@@ -18,7 +18,6 @@
package controller;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
@@ -29,21 +28,14 @@ import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreePath;
import module.decode.DecoderType;
import playlist.PlaylistManager;
import playlist.PlaylistNode;
import settings.SettingsManager;
import source.SourceManager;
import source.recording.RecordingGroupNode;
import source.tuner.Tuner;
import source.tuner.TunerGroupNode;
import source.tuner.TunerNode;
import source.tuner.TunerSelectionListener;
import controller.channel.Channel;
import controller.channel.ChannelModel;
import controller.channel.ChannelNode;
import controller.channel.ChannelProcessingManager;
public class ConfigurationControllerModel extends DefaultTreeModel
@@ -55,13 +47,10 @@ public class ConfigurationControllerModel extends DefaultTreeModel
private ArrayList<TunerSelectionListener> mTunerSelectionListeners =
new ArrayList<TunerSelectionListener>();
private PlaylistNode mPlaylistNode;
private TunerGroupNode mTunerGroupNode;
// private RecordingGroupNode mRecordingGroupNode;
private ChannelModel mChannelModel;
private ChannelProcessingManager mChannelProcessingManager;
private PlaylistManager mPlaylistManager;
private SettingsManager mSettingsManager;
private SourceManager mSourceManager;
@@ -73,7 +62,6 @@ public class ConfigurationControllerModel extends DefaultTreeModel
*/
public ConfigurationControllerModel( ChannelModel channelModel,
ChannelProcessingManager channelProcessingManager,
PlaylistManager playlistManager,
SettingsManager settingsManager,
SourceManager sourceManager )
{
@@ -81,7 +69,6 @@ public class ConfigurationControllerModel extends DefaultTreeModel
mChannelModel = channelModel;
mChannelProcessingManager = channelProcessingManager;
mPlaylistManager = playlistManager;
mSettingsManager = settingsManager;
mSourceManager = sourceManager;
@@ -117,13 +104,13 @@ public class ConfigurationControllerModel extends DefaultTreeModel
// insertNodeInto( mRecordingGroupNode, (MutableTreeNode)root, 1 );
// mRecordingGroupNode.loadRecordings();
/**
* Add the playlist node
*/
mPlaylistNode = new PlaylistNode( mChannelModel, mChannelProcessingManager,
mPlaylistManager, mSettingsManager, mSourceManager );
insertNodeInto( mPlaylistNode, (MutableTreeNode)root, 1 );
mPlaylistNode.loadPlaylist();
// /**
// * Add the playlist node
// */
// mPlaylistNode = new PlaylistNode( mChannelModel, mChannelProcessingManager,
// mPlaylistManager, mSettingsManager, mSourceManager );
// insertNodeInto( mPlaylistNode, (MutableTreeNode)root, 1 );
// mPlaylistNode.loadPlaylist();
}
public void showNode( DefaultMutableTreeNode node )
@@ -146,8 +133,7 @@ public class ConfigurationControllerModel extends DefaultTreeModel
for( Tuner tuner: tuners )
{
TunerNode child = new TunerNode( mChannelModel,
mChannelProcessingManager, mPlaylistManager, mSettingsManager,
tuner );
mChannelProcessingManager, mSettingsManager, tuner );
insertNodeInto( child, parent, parent.getChildCount() );
@@ -250,28 +236,11 @@ public class ConfigurationControllerModel extends DefaultTreeModel
public ArrayList<Channel> getCurrentChannelConfigs()
{
return getChannelConfigs( mPlaylistNode );
return null;
}
private ArrayList<Channel> getChannelConfigs( DefaultMutableTreeNode parent )
{
ArrayList<Channel> configs = new ArrayList<Channel>();
Enumeration<DefaultMutableTreeNode> nodes = parent.children();
while( nodes.hasMoreElements() )
{
DefaultMutableTreeNode node = nodes.nextElement();
if( node instanceof ChannelNode )
{
configs.add( ((ChannelNode)node).getChannel() );
}
//Recursive call
configs.addAll( getChannelConfigs( node ) );
}
return configs;
return null;
}
}

View File

@@ -33,7 +33,6 @@ import module.decode.event.CallEventPanel;
import module.decode.event.MessageActivityPanel;
import module.decode.state.ChannelList;
import net.miginfocom.swing.MigLayout;
import playlist.PlaylistManager;
import settings.SettingsManager;
import source.SourceManager;
import spectrum.ChannelSpectrumPanel;
@@ -48,6 +47,7 @@ import com.jidesoft.swing.JideTabbedPane;
import controller.channel.ChannelController;
import controller.channel.ChannelModel;
import controller.channel.ChannelProcessingManager;
import controller.channel.map.ChannelMapModel;
public class ControllerPanel extends JPanel
{
@@ -83,9 +83,9 @@ public class ControllerPanel extends JPanel
ConfigurationControllerModel controller,
AliasModel aliasModel,
ChannelModel channelModel,
ChannelMapModel channelMapModel,
ChannelProcessingManager channelProcessingManager,
MapService mapService,
PlaylistManager playlistManager,
SettingsManager settingsManager,
SourceManager sourceManager )
{
@@ -105,9 +105,10 @@ public class ControllerPanel extends JPanel
channelProcessingManager );
mChannelStateList = new ChannelList( channelModel, channelProcessingManager,
playlistManager, mSettingsManager );
mSettingsManager );
mChannelController = new ChannelController( channelModel, playlistManager, sourceManager );
mChannelController = new ChannelController( channelModel, channelMapModel,
sourceManager, aliasModel );
mAliasController = new AliasController( aliasModel, mSettingsManager );

View File

@@ -25,9 +25,12 @@ import org.slf4j.LoggerFactory;
import playlist.PlaylistManager;
import source.SourceManager;
import alias.AliasModel;
import com.jidesoft.swing.JideSplitPane;
import controller.channel.map.ChannelMapModel;
public class ChannelController extends JPanel
implements ActionListener, ListSelectionListener
{
@@ -47,13 +50,15 @@ public class ChannelController extends JPanel
private JButton mCopyChannelButton = new JButton( COPY_CHANNEL );
private JButton mDeleteChannelButton = new JButton( DELETE_CHANNEL );
public ChannelController( ChannelModel channelModel,
PlaylistManager playlistManager,
SourceManager sourceManager )
public ChannelController( ChannelModel channelModel,
ChannelMapModel channelMapModel,
SourceManager sourceManager,
AliasModel aliasModel )
{
mChannelModel = channelModel;
mEditor = new ChannelEditor( channelModel, playlistManager, sourceManager );
mEditor = new ChannelEditor( channelModel, channelMapModel,
sourceManager, aliasModel );
mChannelModel.addListener( mEditor );
init();

View File

@@ -40,10 +40,12 @@ import playlist.PlaylistManager;
import record.RecordComponentEditor;
import source.SourceComponentEditor;
import source.SourceManager;
import alias.AliasModel;
import com.jidesoft.swing.JideTabbedPane;
import controller.channel.ChannelEvent.Event;
import controller.channel.map.ChannelMapModel;
public class ChannelEditor extends JPanel
implements ActionListener, ChannelEventListener
@@ -65,23 +67,24 @@ public class ChannelEditor extends JPanel
private JLabel mChannelName = new JLabel( "Channel:" );
private ChannelModel mChannelModel;
private PlaylistManager mPlaylistManager;
private ChannelMapModel mChannelMapModel;
private SourceManager mSourceManager;
private boolean mChannelEnableRequested = false;
public ChannelEditor( ChannelModel channelModel,
PlaylistManager playlistManager,
SourceManager sourceManager )
ChannelMapModel channelMapModel,
SourceManager sourceManager,
AliasModel aliasModel )
{
super();
mChannelModel = channelModel;
mPlaylistManager = playlistManager;
mChannelMapModel = channelMapModel;
mSourceManager = sourceManager;
mNameConfigurationEditor = new NameConfigurationEditor(
mChannelModel, mPlaylistManager );
mNameConfigurationEditor = new NameConfigurationEditor( aliasModel,
mChannelModel );
initGUI();
}
@@ -137,7 +140,7 @@ public class ChannelEditor extends JPanel
mSourceEditor = new SourceComponentEditor( mSourceManager );
tabs.addTab( "Source", mSourceEditor );
mDecodeEditor = new DecodeComponentEditor( mPlaylistManager );
mDecodeEditor = new DecodeComponentEditor( mChannelMapModel );
tabs.addTab( "Decoder", mDecodeEditor );
mAuxDecodeEditor = new AuxDecodeComponentEditor();

View File

@@ -1,190 +0,0 @@
/*******************************************************************************
* 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 controller.channel;
import java.awt.Color;
import java.text.DecimalFormat;
import javax.swing.JMenu;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import playlist.PlaylistManager;
import source.SourceManager;
import source.tuner.TunerChannel;
import controller.ConfigurableNode;
import controller.site.SiteNode;
import controller.system.SystemNode;
/**
* A channel has all of the pieces needed to wire together a source, decoder,
* event logger and recorder and be started and stopped.
*/
public class ChannelNode extends ConfigurableNode implements ChannelEventListener
{
private static final long serialVersionUID = 1L;
private final static Logger mLog = LoggerFactory.getLogger( ChannelNode.class );
private static DecimalFormat sFORMAT = new DecimalFormat( "0.0000" );
private ChannelModel mChannelModel;
private ChannelProcessingManager mChannelProcessingManager;
private SourceManager mSourceManager;
public ChannelNode( Channel channel,
ChannelModel channelModel,
ChannelProcessingManager channelProcessingManager,
PlaylistManager playlistManager,
SourceManager sourceManager )
{
super( playlistManager, channel );
mChannelModel = channelModel;
mChannelProcessingManager = channelProcessingManager;
mSourceManager = sourceManager;
}
public void init()
{
/* Set the owning system and site names for the channel */
SiteNode siteNode = (SiteNode)getParent();
if( siteNode != null )
{
getChannel().setSite( siteNode.getSite().getName() );
SystemNode systemNode = (SystemNode)siteNode.getParent();
if( systemNode != null )
{
getChannel().setSystem( systemNode.getSystem().getName() );
}
}
/* Add this node as listener to receive changes from underlying channel */
// getChannel().addListener( this );
}
/**
* Listener method to receive channel changes from the underlying chnannel
*/
@Override
public void channelChanged( ChannelEvent event )
{
switch( event.getEvent() )
{
/* Refresh the node for each of these events */
case NOTIFICATION_SELECTION_CHANGE:
case NOTIFICATION_PROCESSING_START:
case NOTIFICATION_PROCESSING_STOP:
this.refresh();
break;
/* We're being deleted, so cleanup */
case NOTIFICATION_DELETE:
delete();
break;
default:
break;
}
}
@Override
public String getIconPath()
{
return getChannel().getDecodeConfiguration().getDecoderType()
.getIconFilename();
}
@Override
public Color getBackgroundColor()
{
if( getChannel().getEnabled() )
{
if( getChannel().getEnabled() )
{
return Color.GREEN;
}
else
{
return Color.RED;
}
}
return null;
}
@Override
public JPanel getEditor()
{
return new OldChannelEditor( getChannel(), mChannelModel, getPlaylistManager(), mSourceManager );
}
public Channel getChannel()
{
return (Channel)this.getUserObject();
}
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append( getChannel().getName() );
TunerChannel channel = getChannel().getTunerChannel();
if( channel != null )
{
sb.append( " (" );
sb.append( sFORMAT.format( (double)channel.getFrequency() / 1000000.0d ) + " MHz" );
sb.append( ")" );
}
return sb.toString();
}
public JPopupMenu getContextMenu()
{
JPopupMenu popupMenu = new JPopupMenu();
JMenu channelMenu = ChannelUtils.getContextMenu( mChannelModel,
mChannelProcessingManager, getPlaylistManager(), getChannel(),
getModel().getTree() );
if( channelMenu != null )
{
popupMenu.add( channelMenu );
}
return popupMenu;
}
public void delete()
{
((SiteNode)getParent()).getSite().removeChannel( getChannel() );
save();
getModel().removeNodeFromParent( ChannelNode.this );
}
}

View File

@@ -40,12 +40,14 @@ import sample.Listener;
import source.Source;
import source.SourceException;
import source.SourceManager;
import alias.AliasModel;
import audio.AudioPacket;
import audio.metadata.Metadata;
import audio.metadata.MetadataType;
import controller.ThreadPoolManager;
import controller.channel.Channel.ChannelType;
import controller.channel.ChannelEvent.Event;
import controller.channel.map.ChannelMapModel;
import filter.FilterSet;
public class ChannelProcessingManager implements ChannelEventListener
@@ -58,22 +60,25 @@ public class ChannelProcessingManager implements ChannelEventListener
private List<Listener<Message>> mMessageListeners = new CopyOnWriteArrayList<>();
private ChannelModel mChannelModel;
private ChannelMapModel mChannelMapModel;
private AliasModel mAliasModel;
private EventLogManager mEventLogManager;
private PlaylistManager mPlaylistManager;
private RecorderManager mRecorderManager;
private SourceManager mSourceManager;
private ThreadPoolManager mThreadPoolManager;
public ChannelProcessingManager( ChannelModel channelModel,
ChannelMapModel channelMapModel,
AliasModel aliasModel,
EventLogManager eventLogManager,
PlaylistManager playlistManager,
RecorderManager recorderManager,
SourceManager sourceManager,
ThreadPoolManager threadPoolManager )
{
mChannelModel = channelModel;
mChannelMapModel = channelMapModel;
mAliasModel = aliasModel;
mEventLogManager = eventLogManager;
mPlaylistManager = playlistManager;
mRecorderManager = recorderManager;
mSourceManager = sourceManager;
mThreadPoolManager = threadPoolManager;
@@ -201,7 +206,7 @@ public class ChannelProcessingManager implements ChannelEventListener
/* Processing Modules */
List<Module> modules = DecoderFactory.getModules( mChannelModel,
this, mPlaylistManager, channel );
mChannelMapModel, this, mAliasModel, channel );
processingChain.addModules( modules );
/* Setup message activity model with filtering */

View File

@@ -9,26 +9,20 @@ import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import controller.channel.ChannelEvent.Event;
import module.ProcessingChain;
import module.decode.event.ActivitySummaryFrame;
import module.decode.state.DecoderState;
import playlist.PlaylistManager;
import controller.channel.ChannelEvent.Event;
public class ChannelUtils
{
private static final boolean ENABLED = true;
private static final boolean DISABLED = false;
private static final boolean BROADCAST_CHANGE = true;
/**
* Creates a context menu for the channel argument
*/
public static JMenu getContextMenu( final ChannelModel channelModel,
final ChannelProcessingManager channelProcessingManager,
final PlaylistManager playlistManager,
final Channel channel,
final Component anchor )
final ChannelProcessingManager channelProcessingManager,
final Channel channel,
final Component anchor )
{
if( channel != null )
{

View File

@@ -27,12 +27,11 @@ import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import net.miginfocom.swing.MigLayout;
import playlist.PlaylistManager;
import alias.AliasList;
import alias.AliasModel;
public class NameConfigurationEditor extends ChannelConfigurationEditor
{
@@ -42,21 +41,20 @@ public class NameConfigurationEditor extends ChannelConfigurationEditor
private static ComboBoxModel<String> EMPTY_MODEL = new DefaultComboBoxModel<>();
private AliasModel mAliasModel;
private ChannelModel mChannelModel;
private PlaylistManager mPlaylistManager;
private JTextField mChannelName = new JTextField( DEFAULT_NAME );
private JComboBox<String> mSystemNameCombo = new JComboBox<>( EMPTY_MODEL );
private JComboBox<String> mSiteNameCombo = new JComboBox<>( EMPTY_MODEL );
private JComboBox<AliasList> mAliasListCombo;
private JComboBox<String> mAliasListCombo;
private Channel mChannel;
public NameConfigurationEditor( ChannelModel model,
PlaylistManager playlistManager )
public NameConfigurationEditor( AliasModel aliasModel, ChannelModel model )
{
mAliasModel = aliasModel;
mChannelModel = model;
mPlaylistManager = playlistManager;
setLayout( new MigLayout( "fill,wrap 2", "[right][]", "[][][][][][grow]" ) );
@@ -110,15 +108,14 @@ public class NameConfigurationEditor extends ChannelConfigurationEditor
*/
add( new JLabel( "Alias List:" ) );
mAliasListCombo = new JComboBox<AliasList>();
mAliasListCombo = new JComboBox<String>();
List<AliasList> lists = mPlaylistManager.getPlayist()
.getAliasDirectory().getAliasList();
List<String> lists = mAliasModel.getListNames();
Collections.sort( lists );
mAliasListCombo.setModel( new DefaultComboBoxModel<AliasList>(
lists.toArray( new AliasList[ lists.size() ] ) ) );
mAliasListCombo.setModel( new DefaultComboBoxModel<String>(
lists.toArray( new String[ lists.size() ] ) ) );
add( mAliasListCombo, "growx" );
@@ -126,35 +123,35 @@ public class NameConfigurationEditor extends ChannelConfigurationEditor
final JButton aliasListButton = new JButton( "New Alias List ..." );
aliasListButton.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
String name = JOptionPane.showInputDialog( aliasListButton,
"Please enter an Alias List name:" );
if( name != null && !name.isEmpty() )
{
AliasList aliasList = new AliasList( name );
mPlaylistManager.getPlayist().getAliasDirectory()
.addAliasList( aliasList );
mPlaylistManager.save();
List<AliasList> lists = mPlaylistManager.getPlayist()
.getAliasDirectory().getAliasList();
Collections.sort( lists );
mAliasListCombo.setModel( new DefaultComboBoxModel<AliasList>(
lists.toArray( new AliasList[ lists.size() ] ) ) );
mAliasListCombo.setSelectedItem( aliasList );
}
}
} );
// aliasListButton.addActionListener( new ActionListener()
// {
// @Override
// public void actionPerformed( ActionEvent e )
// {
// String name = JOptionPane.showInputDialog( aliasListButton,
// "Please enter an Alias List name:" );
//
// if( name != null && !name.isEmpty() )
// {
// AliasListOld aliasList = new AliasListOld( name );
//
// mPlaylistManager.getPlayist().getAliasDirectory()
// .addAliasList( aliasList );
//
// mPlaylistManager.save();
//
// List<AliasListOld> lists = mPlaylistManager.getPlayist()
// .getAliasDirectory().getAliasList();
//
// Collections.sort( lists );
//
// mAliasListCombo.setModel( new DefaultComboBoxModel<AliasListOld>(
// lists.toArray( new AliasListOld[ lists.size() ] ) ) );
//
// mAliasListCombo.setSelectedItem( aliasList );
// }
// }
// } );
add( aliasListButton, "growx" );
}
@@ -173,8 +170,7 @@ public class NameConfigurationEditor extends ChannelConfigurationEditor
mChannel.setSite( ( site == null ? null : (String)site ) );
Object aliasList = mAliasListCombo.getSelectedItem();
mChannel.setAliasListName( aliasList == null ? null :
((AliasList)aliasList).getName() );
mChannel.setAliasListName( aliasList == null ? null : (String)aliasList );
}
}
@@ -232,10 +228,7 @@ public class NameConfigurationEditor extends ChannelConfigurationEditor
if( aliasListName != null )
{
AliasList selected = mPlaylistManager.getPlayist().getAliasDirectory()
.getAliasList( aliasListName );
mAliasListCombo.setSelectedItem( selected );
mAliasListCombo.setSelectedItem( aliasListName );
}
}
else

View File

@@ -1,260 +0,0 @@
/*******************************************************************************
* 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 controller.channel;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collections;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextField;
import module.decode.AuxDecodeComponentEditor;
import module.decode.DecodeComponentEditor;
import module.log.EventLogComponentEditor;
import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import playlist.PlaylistManager;
import record.RecordComponentEditor;
import source.SourceComponentEditor;
import source.SourceManager;
import alias.AliasList;
import com.jidesoft.swing.JideTabbedPane;
public class OldChannelEditor extends ChannelConfigurationEditor implements ActionListener
{
private final static Logger mLog = LoggerFactory.getLogger( OldChannelEditor.class );
private static final long serialVersionUID = 1L;
private DecodeComponentEditor mDecodeEditor;
private AuxDecodeComponentEditor mAuxDecodeEditor;
private EventLogComponentEditor mEventLogEditor;
private RecordComponentEditor mRecordEditor;
private SourceComponentEditor mSourceEditor;
private JTextField mChannelName;
private JCheckBox mChannelEnabled = new JCheckBox();
private JComboBox<AliasList> mComboAliasLists;
private Channel mChannel;
private ChannelModel mChannelModel;
private PlaylistManager mPlaylistManager;
private SourceManager mSourceManager;
public OldChannelEditor( Channel channel,
ChannelModel channelModel,
PlaylistManager playlistManager,
SourceManager sourceManager )
{
super();
mChannel = channel;
mChannelModel = channelModel;
mPlaylistManager = playlistManager;
mSourceManager = sourceManager;
initGUI();
}
private void initGUI()
{
setLayout( new MigLayout( "fill,wrap 2", "[right,grow][grow]", "[][][][][grow][]" ) );
add( new JLabel( "Channel Configuration" ), "span, align center" );
add( new JLabel( "Enabled:" ) );
mChannelEnabled.setSelected( mChannel.getEnabled() );
mChannelEnabled.setComponentOrientation( ComponentOrientation.RIGHT_TO_LEFT );
add( mChannelEnabled );
add( new JLabel( "Name:" ) );
mChannelName = new JTextField( mChannel.getName() );
add( mChannelName, "growx,push" );
/**
* ComboBox: Alias Lists
*/
add( new JLabel( "Alias List:" ) );
mComboAliasLists = new JComboBox<AliasList>();
List<AliasList> lists = mPlaylistManager.getPlayist()
.getAliasDirectory().getAliasList();
Collections.sort( lists );
mComboAliasLists.setModel( new DefaultComboBoxModel<AliasList>(
lists.toArray( new AliasList[ lists.size() ] ) ) );
String aliasListName = mChannel.getAliasListName();
if( aliasListName != null )
{
AliasList selected = mPlaylistManager.getPlayist().getAliasDirectory()
.getAliasList( aliasListName );
mComboAliasLists.setSelectedItem( selected );
}
add( mComboAliasLists, "growx,push" );
JideTabbedPane tabs = new JideTabbedPane();
tabs.setFont( this.getFont() );
tabs.setForeground( Color.BLACK );
mSourceEditor = new SourceComponentEditor( mSourceManager );
tabs.addTab( "Source", mSourceEditor );
mDecodeEditor = new DecodeComponentEditor( mPlaylistManager );
tabs.addTab( "Decoder", mDecodeEditor );
mAuxDecodeEditor = new AuxDecodeComponentEditor();
tabs.addTab( "Aux", mAuxDecodeEditor );
mEventLogEditor = new EventLogComponentEditor();
tabs.addTab( "Event Log", mEventLogEditor );
mRecordEditor = new RecordComponentEditor();
tabs.addTab( "Record", mRecordEditor );
add( tabs, "span,grow,push" );
JButton btnSave = new JButton( "Save" );
btnSave.addActionListener( OldChannelEditor.this );
add( btnSave, "growx,push" );
JButton btnReset = new JButton( "Reset" );
btnReset.addActionListener( OldChannelEditor.this );
add( btnReset, "growx,push" );
}
@Override
public void actionPerformed( ActionEvent e )
{
String command = e.getActionCommand();
if( command.contentEquals( "Save" ) )
{
save();
}
else if( command.contentEquals( "Reset" ) )
{
// reset();
}
}
@Override
public void save()
{
// try
// {
// /**
// * Validate the source configuration against the other component
// * configuration editors
// */
// validate( mSourceEditor.getSourceEditor() );
//
// mSourceEditor.save();
// mDecodeEditor.save();
// mAuxDecodeEditor.save();
// mEventLogEditor.save();
// mRecordEditor.save();
//
// mChannel.setName( mChannelName.getText() );
// mChannel.setEnabled( mChannelEnabled.isSelected() );
//
// AliasList selected = mComboAliasLists.getItemAt(
// mComboAliasLists.getSelectedIndex() );
// if( selected != null )
// {
// mChannel.setAliasListName( selected.getName() );
// }
// }
// catch ( ConfigurationValidationException validationException )
// {
// /* ChannelValidationException can be thrown by any of the component
// * editors. Show the validation error text in a popup menu to the
// * user */
// JOptionPane.showMessageDialog( OldChannelEditor.this,
// validationException.getMessage(),
// "Channel Configuration Error",
// JOptionPane.ERROR_MESSAGE );
// }
}
// @Override
// public void reset()
// {
// mChannelName.setText( mChannel.getName() );
// mChannelName.requestFocus();
// mChannelName.requestFocusInWindow();
//
// mChannelEnabled.setSelected( mChannel.getEnabled() );
// mChannelEnabled.requestFocus();
// mChannelEnabled.requestFocusInWindow();
//
// String aliasListName = mChannel.getAliasListName();
//
// if( aliasListName != null )
// {
// AliasList selected = mPlaylistManager.getPlayist().getAliasDirectory()
// .getAliasList( aliasListName );
//
// mComboAliasLists.setSelectedItem( selected );
// }
//
//
// mSourceEditor.reset();
// mDecodeEditor.reset();
// mAuxDecodeEditor.reset();
// mEventLogEditor.reset();
// mRecordEditor.reset();
// }
@Override
public void setConfiguration( Channel channel )
{
}
@Override
public void validateConfiguration() throws ConfigurationValidationException
{
mSourceEditor.validate();
mDecodeEditor.validate();
mAuxDecodeEditor.validate();
mEventLogEditor.validate();
mRecordEditor.validate();
}
}

View File

@@ -1,6 +1,6 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
* Copyright (C) 2014-2016 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
@@ -17,22 +17,22 @@
******************************************************************************/
package controller.channel.map;
import gui.editor.DocumentListenerEditor;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableCellEditor;
import javax.swing.text.InternationalFormatter;
@@ -41,28 +41,45 @@ import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ChannelMapEditor extends JPanel implements ActionListener
public class ChannelMapEditor extends DocumentListenerEditor<ChannelMap>
implements ListSelectionListener
{
private static final long serialVersionUID = 1L;
private final static Logger mLog =
LoggerFactory.getLogger( ChannelMapEditor.class );
private ChannelMapNode mChannelMapNode;
private JLabel mNameLabel;
private JTextField mNameText;
private ChannelMapModel mRangeModel;
private ChannelRangeModel mRangeModel;
private JTable mRangeTable;
private JButton mDelete;
private ChannelMap mChannelMapCopy;
public ChannelMapEditor( ChannelMapNode ChannelMap )
public ChannelMapEditor()
{
mChannelMapNode = ChannelMap;
mChannelMapCopy = mChannelMapNode.getChannelMap().copyOf();
initGUI();
}
private ChannelMap getChannelMap()
{
if( hasItem() )
{
return (ChannelMap)getItem();
}
return null;
}
@Override
public void setItem( ChannelMap item )
{
super.setItem( item );
if( hasItem() )
{
}
}
private void initGUI()
{
setLayout( new MigLayout( "fill,wrap 2", "[right][grow]", "[][][grow][][]" ) );
@@ -72,20 +89,11 @@ public class ChannelMapEditor extends JPanel implements ActionListener
mNameLabel = new JLabel( "Name:" );
add( mNameLabel );
mNameText = new JTextField( mChannelMapCopy.getName() );
mNameText.addFocusListener( new FocusListener()
{
@Override public void focusGained( FocusEvent arg0 ) {}
@Override
public void focusLost( FocusEvent arg0 )
{
mChannelMapCopy.setName( mNameText.getText() );
}
} );
mNameText = new JTextField();
mNameText.getDocument().addDocumentListener( this );
add( mNameText, "growx, push" );
mRangeModel = new ChannelMapModel( mChannelMapCopy );
mRangeModel = new ChannelRangeModel();
mRangeTable = new JTable( mRangeModel );
mRangeTable.setPreferredScrollableViewportSize( new Dimension( 300, 150 ) );
@@ -101,88 +109,89 @@ public class ChannelMapEditor extends JPanel implements ActionListener
add( scrollPane, "span,grow,push");
JButton btnNew = new JButton( "New Range" );
btnNew.addActionListener( ChannelMapEditor.this );
// btnNew.addActionListener( ChannelMapEditor.this );
add( btnNew );
mDelete = new JButton( "Delete" );
mDelete.addActionListener( ChannelMapEditor.this );
// mDelete.addActionListener( ChannelMapEditor.this );
add( mDelete, "wrap" );
JButton btnSave = new JButton( "Save" );
btnSave.addActionListener( ChannelMapEditor.this );
// btnSave.addActionListener( ChannelMapEditor.this );
add( btnSave, "growx" );
JButton btnReset = new JButton( "Reset " );
btnReset.addActionListener( ChannelMapEditor.this );
// btnReset.addActionListener( ChannelMapEditor.this );
add( btnReset, "wrap" );
}
private boolean checkForValidRanges()
{
int invalidRow = mChannelMapCopy.getInvalidRange();
if( invalidRow != -1 && invalidRow <= mRangeTable.getRowCount() )
{
mRangeTable.setRowSelectionInterval( invalidRow, invalidRow );
JOptionPane.showMessageDialog( this,
"Starting channel number must be less than ending channel number",
"Channel number range error",
JOptionPane.WARNING_MESSAGE );
return false;
}
mLog.error( "Fix Me!" );
// int invalidRow = mChannelMapCopy.getInvalidRange();
//
// if( invalidRow != -1 && invalidRow <= mRangeTable.getRowCount() )
// {
// mRangeTable.setRowSelectionInterval( invalidRow, invalidRow );
//
// JOptionPane.showMessageDialog( this,
// "Starting channel number must be less than ending channel number",
// "Channel number range error",
// JOptionPane.WARNING_MESSAGE );
//
// return false;
// }
return true;
}
@Override
public void actionPerformed( ActionEvent e )
{
String command = e.getActionCommand();
switch( command )
{
case "New Range":
mRangeModel.addRange( new ChannelRange() );
break;
case "Save":
if( checkForValidRanges() )
{
mChannelMapNode.getChannelMap()
.setName( mChannelMapCopy.getName() );
mChannelMapNode.getChannelMap()
.setRanges( mChannelMapCopy.getRanges() );
mChannelMapNode.save();
mChannelMapNode.refresh();
mChannelMapNode.show();
}
case "Reset":
mChannelMapCopy = mChannelMapNode.getChannelMap();
mRangeModel.setChannelMap( mChannelMapCopy );
mNameText.setText( mChannelMapCopy.getName() );
break;
case "Delete":
int row = mRangeTable.getSelectedRow();
if( row < 0 )
{
JOptionPane.showMessageDialog( this,
"Please select a channel range to delete",
"Select a range",
JOptionPane.WARNING_MESSAGE );
}
else
{
mRangeModel.removeRange(
mRangeTable.convertRowIndexToModel( row ) );
}
break;
}
}
// @Override
// public void actionPerformed( ActionEvent e )
// {
// String command = e.getActionCommand();
//
// switch( command )
// {
// case "New Range":
// mRangeModel.addRange( new ChannelRange() );
// break;
// case "Save":
// if( checkForValidRanges() )
// {
// mChannelMapNode.getChannelMap()
// .setName( mChannelMapCopy.getName() );
// mChannelMapNode.getChannelMap()
// .setRanges( mChannelMapCopy.getRanges() );
//
// mChannelMapNode.save();
//
// mChannelMapNode.refresh();
//
// mChannelMapNode.show();
// }
// case "Reset":
// mChannelMapCopy = mChannelMapNode.getChannelMap();
// mRangeModel.setChannelMap( mChannelMapCopy );
// mNameText.setText( mChannelMapCopy.getName() );
// break;
// case "Delete":
// int row = mRangeTable.getSelectedRow();
//
// if( row < 0 )
// {
// JOptionPane.showMessageDialog( this,
// "Please select a channel range to delete",
// "Select a range",
// JOptionPane.WARNING_MESSAGE );
// }
// else
// {
// mRangeModel.removeRange(
// mRangeTable.convertRowIndexToModel( row ) );
// }
// break;
// }
// }
public class RangeTableEditor extends AbstractCellEditor
implements TableCellEditor, ActionListener
@@ -221,4 +230,17 @@ public class ChannelMapEditor extends JPanel implements ActionListener
return mEditor;
}
}
@Override
public void save()
{
// TODO Auto-generated method stub
}
@Override
public void valueChanged( ListSelectionEvent e )
{
mLog.debug( "List Select Event from: " + e.getSource().getClass() );
}
}

View File

@@ -0,0 +1,76 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014-2016 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 controller.channel.map;
public class ChannelMapEvent
{
private ChannelMap mChannelMap;
private Event mEvent;
private String mPreviousChannelMapName;
/**
* ChannelMapEvent - event describing any changes to a channel map
*
* @param channelMap that changed
* @param event describing the change
*/
public ChannelMapEvent( ChannelMap channelMap, Event event )
{
mChannelMap = channelMap;
mEvent = event;
}
/**
* ChannelMapEvent - channel map renaming event.
*
* @param channelMap that changed
* @param previousName of the channel map
*/
public ChannelMapEvent( ChannelMap channelMap, String previousName )
{
this( channelMap, Event.RENAME );
mPreviousChannelMapName = previousName;
}
public ChannelMap getChannelMap()
{
return mChannelMap;
}
public String getPreviousChannelMapName()
{
return mPreviousChannelMapName;
}
public Event getEvent()
{
return mEvent;
}
/**
* Events
*/
public enum Event
{
ADD,
CHANGE,
RENAME,
DELETE;
}
}

View File

@@ -1,76 +0,0 @@
/*******************************************************************************
* 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 controller.channel.map;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSeeAlso;
@XmlSeeAlso( ChannelMap.class )
public class ChannelMapList
{
private ArrayList<ChannelMap> mChannelMap = new ArrayList<ChannelMap>();
public ChannelMapList()
{
/* Empty constructor for JAXB */
}
@XmlElement( name = "channel_map" )
public ArrayList<ChannelMap> getChannelMap()
{
return mChannelMap;
}
public void setChannelMap( ArrayList<ChannelMap> ChannelMaps )
{
mChannelMap = ChannelMaps;
}
public void addChannelMap( ChannelMap ChannelMap )
{
mChannelMap.add( ChannelMap );
}
public void removeChannelMap( ChannelMap ChannelMap )
{
mChannelMap.remove( ChannelMap );
}
public void clearChannelMaps()
{
mChannelMap.clear();
}
/**
* Gets the named channel map, or returns an empty map
*/
public ChannelMap getChannelMap( String name )
{
for( ChannelMap map: mChannelMap )
{
if( map.getName().equalsIgnoreCase( name ) )
{
return map;
}
}
return new ChannelMap();
}
}

View File

@@ -1,88 +0,0 @@
/*******************************************************************************
* 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 controller.channel.map;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import playlist.PlaylistManager;
import controller.ConfigurableNode;
public class ChannelMapListNode extends ConfigurableNode
{
private static final long serialVersionUID = 1L;
public ChannelMapListNode( PlaylistManager playlistManager, ChannelMapList list )
{
super( playlistManager, list );
}
public ChannelMapList getChannelMapList()
{
return (ChannelMapList)getUserObject();
}
public void init()
{
for( ChannelMap channelMap: getChannelMapList().getChannelMap() )
{
ChannelMapNode node = new ChannelMapNode( getPlaylistManager(), channelMap );
getModel().addNode( node, ChannelMapListNode.this, getChildCount() );
node.init();
}
sort();
}
public String toString()
{
return "Channel Maps [" + this.getChildCount() + "]";
}
public JPopupMenu getContextMenu()
{
JPopupMenu retVal = new JPopupMenu();
JMenuItem addSystemItem = new JMenuItem( "Add Channel Map" );
addSystemItem.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
ChannelMap channelMap = new ChannelMap();
getChannelMapList().addChannelMap( channelMap );
getModel().addNode( new ChannelMapNode( getPlaylistManager(), channelMap ),
ChannelMapListNode.this,
ChannelMapListNode.this.getChildCount() );
save();
}
} );
retVal.add( addSystemItem );
return retVal;
}
}

View File

@@ -0,0 +1,47 @@
package controller.channel.map;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import net.miginfocom.swing.MigLayout;
import com.jidesoft.swing.JideSplitPane;
public class ChannelMapManager extends JPanel
{
private static final long serialVersionUID = 1L;
private ChannelMapModel mChannelMapModel;
private JList<ChannelMap> mChannelMapList;
private ChannelMapEditor mChannelMapEditor;
public ChannelMapManager( ChannelMapModel channelMapModel )
{
mChannelMapModel = channelMapModel;
mChannelMapList = new JList( mChannelMapModel );
mChannelMapEditor = new ChannelMapEditor();
init();
}
private void init()
{
setLayout( new MigLayout( "", "[fill,grow]", "[fill,grow]" ) );
mChannelMapList.addListSelectionListener( mChannelMapEditor );
mChannelMapList.setLayoutOrientation( JList.VERTICAL );
mChannelMapList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
JScrollPane listScroller = new JScrollPane( mChannelMapList );
JScrollPane editorScroller = new JScrollPane( mChannelMapEditor );
JideSplitPane splitPane = new JideSplitPane();
splitPane.setOrientation( JideSplitPane.HORIZONTAL_SPLIT );
splitPane.add( listScroller );
splitPane.add( editorScroller );
add( splitPane );
}
}

View File

@@ -1,6 +1,6 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
* Copyright (C) 2014-2016 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
@@ -15,46 +15,28 @@
* 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 controller.system;
package controller.channel.map;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import net.miginfocom.swing.MigLayout;
@XmlSeeAlso( { controller.system.System.class } )
@XmlRootElement( name = "system_list" )
public class SystemList
public class ChannelMapManagerFrame extends JFrame
{
private ArrayList<System> mSystem = new ArrayList<System>();
private static final long serialVersionUID = 1L;
public SystemList()
{
}
public ArrayList<System> getSystem()
{
return mSystem;
}
public void setSystem( ArrayList<System> systems )
{
mSystem = systems;
}
public void addSystem( System system )
{
mSystem.add( system );
}
public void removeSystem( System system )
{
mSystem.remove( system );
}
public void clearSystems()
{
mSystem.clear();
}
public ChannelMapManagerFrame( ChannelMapModel channelMapModel )
{
init( new ChannelMapManager( channelMapModel ) );
}
private void init( ChannelMapManager channelMapManager )
{
setTitle( "Channel Map Manager" );
setSize( 800, 400 );
setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
setLayout( new MigLayout( "", "[grow,fill]", "[grow,fill]" ) );
add( channelMapManager );
setLocationRelativeTo( null );
}
}

View File

@@ -1,171 +1,155 @@
/*******************************************************************************
* 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 controller.channel.map;
import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.swing.AbstractListModel;
public class ChannelMapModel extends AbstractTableModel
import controller.channel.map.ChannelMapEvent.Event;
import sample.Broadcaster;
import sample.Listener;
public class ChannelMapModel extends AbstractListModel<ChannelMap>
{
private static final long serialVersionUID = 1L;
private final static Logger mLog =
LoggerFactory.getLogger( ChannelMapModel.class );
private static final long serialVersionUID = 1L;
private List<ChannelMap> mChannelMaps = new ArrayList<>();
private Broadcaster<ChannelMapEvent> mEventBroadcaster = new Broadcaster<>();
private static final int sSTART = 0;
private static final int sSTOP = 1;
private static final int sBASE = 2;
private static final int sSIZE = 3;
public ChannelMapModel()
{
}
protected int[] mColumnWidths = { 110, 110, 110, -1 };
/**
* Returns an unmodifiable list of channel maps currently in the model
*/
public List<ChannelMap> getChannelMaps()
{
return Collections.unmodifiableList( mChannelMaps );
}
protected String[] mHeaders = new String[] { "Begin",
"End",
"Base",
"Size" };
private ChannelMap mChannelMap;
public ChannelMapModel( ChannelMap map )
/**
* Returns the channel map with a matching name or null
*/
public ChannelMap getChannelMap( String name )
{
mChannelMap = map;
}
public ChannelMap getChannelMap()
{
return mChannelMap;
}
public void setChannelMap( ChannelMap map )
{
mChannelMap = map;
fireTableDataChanged();
}
public void addRange( ChannelRange range )
{
mChannelMap.addRange( range );
int index = mChannelMap.getRanges().size() - 1;
fireTableRowsInserted( index, index );
}
public void removeRange( int rangeIndex )
{
if( rangeIndex < mChannelMap.getRanges().size() )
for( ChannelMap channelMap: mChannelMaps )
{
mChannelMap.getRanges().remove( rangeIndex );
}
fireTableRowsDeleted( rangeIndex, rangeIndex );
}
public int[] getColumnWidths()
{
return mColumnWidths;
}
public void setColumnWidths( int[] widths )
{
if( widths.length != 4 )
{
throw new IllegalArgumentException( "ChannelMapRangeModel - "
+ "column widths array should have 5 elements" );
}
else
{
mColumnWidths = widths;
}
}
@Override
public int getRowCount()
{
return mChannelMap.getRanges().size();
}
@Override
public int getColumnCount()
{
return mHeaders.length;
}
public String getColumnName( int column )
{
return mHeaders[ column ];
}
@Override
public Object getValueAt( int rowIndex, int columnIndex )
{
ChannelRange range = mChannelMap.getRanges().get( rowIndex );
switch( columnIndex )
{
case sSTART:
return range.getFirstChannelNumber();
case sSTOP:
return range.getLastChannelNumber();
case sBASE:
return range.getBase();
case sSIZE:
return range.getSize();
if( channelMap.getName().equalsIgnoreCase( name ) )
{
return channelMap;
}
}
return null;
}
public boolean isCellEditable( int row, int column )
{
return true;
}
public void setValueAt( Object value, int row, int column )
/**
* Adds a listener to receive notifications when channel map updates occur
*/
public void addListener( Listener<ChannelMapEvent> listener )
{
try
mEventBroadcaster.addListener( listener );
}
/**
* Removes the channel map update notification listener
*/
public void removeListener( Listener<ChannelMapEvent> listener )
{
mEventBroadcaster.removeListener( listener );
}
/**
* Broadcasts a channel map change.
*
* Note: use the add/remove methods to add or remove channel maps from this
* model. When using those methods, an add or delete event will automatically
* be generated.
*/
public void broadcast( ChannelMapEvent event )
{
if( event.getEvent() == ChannelMapEvent.Event.CHANGE ||
event.getEvent() == ChannelMapEvent.Event.RENAME )
{
int parsedValue = Integer.parseInt( (String)value );
int index = mChannelMaps.indexOf( event.getChannelMap() );
ChannelRange range = mChannelMap.getRanges().get( row );
switch( column )
if( index >= 0 )
{
case sSTART:
range.setFirstChannelNumber( parsedValue );
break;
case sSTOP:
range.setLastChannelNumber( parsedValue );
break;
case sBASE:
range.setBase( parsedValue );
break;
case sSIZE:
range.setSize( parsedValue );
break;
fireContentsChanged( this, index, index );
}
}
catch( Exception e )
mEventBroadcaster.broadcast( event );
}
/**
* Adds a list of channel maps to this model
*/
public void addChannelMaps( List<ChannelMap> channelMaps )
{
for( ChannelMap channelMap: channelMaps )
{
mLog.error( "ChannelMapModel - couldn't parse integer value "
+ "for [" + value + "]", e );
addChannelMap( channelMap );
}
}
/**
* Adds the channel map to this model
*/
public void addChannelMap( ChannelMap channelMap )
{
if( !mChannelMaps.contains( channelMap ) )
{
mChannelMaps.add( channelMap );
int index = mChannelMaps.indexOf( channelMap );
fireIntervalAdded( this, index, index );
broadcast( new ChannelMapEvent( channelMap, Event.ADD ) );
}
}
/**
* Removes the channel map from this model
*/
public void removeChannelMap( ChannelMap channelMap )
{
if( mChannelMaps.contains( channelMap ) )
{
int index = mChannelMaps.indexOf( channelMap );
mChannelMaps.remove( channelMap );
fireIntervalRemoved( this, index, index );
broadcast( new ChannelMapEvent( channelMap, Event.DELETE ) );
}
}
/**
* Size/Number of channel maps in this model
*/
@Override
public int getSize()
{
return mChannelMaps.size();
}
/**
* Returns the channel map at the specified index
*/
@Override
public ChannelMap getElementAt( int index )
{
if( index <= mChannelMaps.size() )
{
return mChannelMaps.get( index );
}
return null;
}
}

View File

@@ -1,103 +0,0 @@
/*******************************************************************************
* 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 controller.channel.map;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import playlist.PlaylistManager;
import controller.ConfigurableNode;
public class ChannelMapNode extends ConfigurableNode
{
private static final long serialVersionUID = 1L;
public ChannelMapNode( PlaylistManager playlistManager, ChannelMap ChannelMap )
{
super( playlistManager, ChannelMap );
}
public void init()
{
//For consistency, but not used
}
@Override
public String getIconPath()
{
return "images/ChannelMap.png";
}
@Override
public JPanel getEditor()
{
return new ChannelMapEditor( this );
}
public ChannelMap getChannelMap()
{
return (ChannelMap)getUserObject();
}
public String toString()
{
return getChannelMap().getName();
}
public void delete()
{
ChannelMapListNode parent = (ChannelMapListNode)getParent();
parent.getChannelMapList().removeChannelMap( getChannelMap() );
save();
getModel().removeNodeFromParent( ChannelMapNode.this );
/* Show the first child, if one exists so that we don't have a
* collapsed list */
if( parent.getChildCount() > 0 )
{
((ConfigurableNode)parent.getFirstChild()).show();
}
}
public JPopupMenu getContextMenu()
{
JPopupMenu retVal = new JPopupMenu();
JMenuItem deleteItem = new JMenuItem( "Delete" );
deleteItem.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
delete();
}
} );
retVal.add( deleteItem );
return retVal;
}
}

View File

@@ -1,6 +1,6 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
* Copyright (C) 2014-2016 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

View File

@@ -0,0 +1,181 @@
/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014-2016 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 controller.channel.map;
import javax.swing.table.AbstractTableModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ChannelRangeModel extends AbstractTableModel
{
private static final long serialVersionUID = 1L;
private final static Logger mLog =
LoggerFactory.getLogger( ChannelRangeModel.class );
private static final int START = 0;
private static final int STOP = 1;
private static final int BASE = 2;
private static final int SIZE = 3;
protected int[] mColumnWidths = { 110, 110, 110, -1 };
protected String[] mHeaders = new String[] { "Begin",
"End",
"Base",
"Size" };
private ChannelMap mChannelMap;
public ChannelRangeModel()
{
}
public void setChannelMap( ChannelMap channelMap )
{
mChannelMap = channelMap;
fireTableDataChanged();
}
public void addRange( ChannelRange range )
{
if( mChannelMap != null )
{
mChannelMap.addRange( range );
int index = mChannelMap.getRanges().size() - 1;
fireTableRowsInserted( index, index );
}
}
public void removeRange( int rangeIndex )
{
if( mChannelMap != null )
{
if( rangeIndex < mChannelMap.getRanges().size() )
{
mChannelMap.getRanges().remove( rangeIndex );
}
fireTableRowsDeleted( rangeIndex, rangeIndex );
}
}
public int[] getColumnWidths()
{
return mColumnWidths;
}
public void setColumnWidths( int[] widths )
{
if( widths.length != 4 )
{
throw new IllegalArgumentException( "ChannelMapRangeModel - "
+ "column widths array should have 5 elements" );
}
else
{
mColumnWidths = widths;
}
}
@Override
public int getRowCount()
{
if( mChannelMap != null )
{
return mChannelMap.getRanges().size();
}
return 0;
}
@Override
public int getColumnCount()
{
return mHeaders.length;
}
public String getColumnName( int column )
{
return mHeaders[ column ];
}
@Override
public Object getValueAt( int rowIndex, int columnIndex )
{
if( mChannelMap != null )
{
ChannelRange range = mChannelMap.getRanges().get( rowIndex );
switch( columnIndex )
{
case START:
return range.getFirstChannelNumber();
case STOP:
return range.getLastChannelNumber();
case BASE:
return range.getBase();
case SIZE:
return range.getSize();
}
}
return null;
}
public boolean isCellEditable( int row, int column )
{
return mChannelMap != null;
}
public void setValueAt( Object value, int row, int column )
{
if( mChannelMap != null )
{
try
{
int parsedValue = Integer.parseInt( (String)value );
ChannelRange range = mChannelMap.getRanges().get( row );
switch( column )
{
case START:
range.setFirstChannelNumber( parsedValue );
break;
case STOP:
range.setLastChannelNumber( parsedValue );
break;
case BASE:
range.setBase( parsedValue );
break;
case SIZE:
range.setSize( parsedValue );
break;
}
}
catch( Exception e )
{
mLog.error( "ChannelMapModel - couldn't parse integer value "
+ "for [" + value + "]", e );
}
}
}
}

View File

@@ -1,86 +0,0 @@
/*******************************************************************************
* 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 controller.site;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import controller.channel.Channel;
@XmlSeeAlso( { Channel.class } )
@XmlRootElement( name = "site" )
public class Site
{
private String mName;
private ArrayList<Channel> mChannel = new ArrayList<Channel>();
public Site()
{
this( "New Site" );
}
public Site( String name )
{
mName = name;
}
public String toString()
{
return mName;
}
@XmlAttribute
public String getName()
{
return mName;
}
public void setName( String name )
{
mName = name;
}
public ArrayList<Channel> getChannel()
{
return mChannel;
}
public void setChannel( ArrayList<Channel> configs )
{
mChannel = configs;
}
public void addChannel( Channel channel )
{
mChannel.add( channel );
}
public void removeChannel( Channel channel )
{
mChannel.remove( channel );
}
public void removeAllChannels()
{
mChannel.clear();
}
}

View File

@@ -1,101 +0,0 @@
/*******************************************************************************
* 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 controller.site;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.tree.TreePath;
import net.miginfocom.swing.MigLayout;
public class SiteEditor extends JPanel implements ActionListener
{
private static final long serialVersionUID = 1L;
private SiteNode mSiteNode;
private JLabel mLabelName;
private JTextField mTextSite;
public SiteEditor( SiteNode site )
{
mSiteNode = site;
initGUI();
}
private void initGUI()
{
setLayout( new MigLayout() );
setBorder( BorderFactory.createTitledBorder( "Site" ) );
mLabelName = new JLabel( "Name:" );
add( mLabelName, "align right" );
mTextSite = new JTextField( mSiteNode.getSite().getName() );
add( mTextSite, "grow, wrap" );
JButton btnSave = new JButton( "Save" );
btnSave.addActionListener( SiteEditor.this );
add( btnSave );
JButton btnReset = new JButton( "Reset" );
btnReset.addActionListener( SiteEditor.this );
add( btnReset, "wrap" );
}
@Override
public void actionPerformed( ActionEvent e )
{
String command = e.getActionCommand();
if( command.contentEquals( "Save" ) )
{
boolean expanded = mSiteNode.getModel().getTree()
.isExpanded( new TreePath( mSiteNode ) );
String name = mTextSite.getText();
if( name != null )
{
mSiteNode.getSite().setName( name );
mSiteNode.save();
mSiteNode.show();
if( expanded )
{
mSiteNode.getModel().getTree().expandPath( new TreePath( mSiteNode ) );
}
}
else
{
JOptionPane.showMessageDialog( SiteEditor.this, "Please enter a site name" );
}
}
else if( command.contentEquals( "Reset" ) )
{
mTextSite.setText( mSiteNode.getSite().getName() );
}
}
}

View File

@@ -1,181 +0,0 @@
/*******************************************************************************
* 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 controller.site;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;
import javax.swing.tree.DefaultMutableTreeNode;
import playlist.PlaylistManager;
import source.SourceManager;
import controller.ConfigurableNode;
import controller.channel.Channel;
import controller.channel.ChannelModel;
import controller.channel.ChannelNode;
import controller.channel.ChannelProcessingManager;
import controller.system.System;
import controller.system.SystemNode;
public class SiteNode extends ConfigurableNode
{
private static final long serialVersionUID = 1L;
private ChannelModel mChannelModel;
private ChannelProcessingManager mChannelProcessingManager;
private SourceManager mSourceManager;
public SiteNode( Site site,
ChannelModel channelModel,
ChannelProcessingManager channelProcessingManager,
PlaylistManager playlistManager,
SourceManager sourceManager )
{
super( playlistManager, site );
mChannelModel = channelModel;
mChannelProcessingManager = channelProcessingManager;
mSourceManager = sourceManager;
}
public void init()
{
for( Channel channel: getSite().getChannel() )
{
ChannelNode node = new ChannelNode( channel, mChannelModel,
mChannelProcessingManager, getPlaylistManager(), mSourceManager );
getModel().insertNodeInto( node, SiteNode.this, getChildCount() );
node.init();
}
sort();
}
public String getIconPath()
{
return "images/site.png";
}
@Override
public Color getBackgroundColor()
{
@SuppressWarnings( "unchecked" )
Enumeration<DefaultMutableTreeNode> nodes = children();
while( nodes.hasMoreElements() )
{
ChannelNode child = (ChannelNode)nodes.nextElement();
if( child.getBackgroundColor() != null )
{
return Color.CYAN;
}
}
return null;
}
@Override
public JPanel getEditor()
{
return new SiteEditor( this );
}
public Site getSite()
{
return (Site)getUserObject();
}
public String toString()
{
return getSite().getName();
}
public void delete()
{
for( int x = 0; x < getChildCount(); x++ )
{
((ChannelNode)getChildAt( x )).delete();
}
((SystemNode)getParent()).getSystem().removeSite( getSite() );
save();
getModel().removeNodeFromParent( SiteNode.this );
}
public JPopupMenu getContextMenu()
{
JPopupMenu retVal = new JPopupMenu();
JMenuItem addChannelItem = new JMenuItem( "Add Channel" );
addChannelItem.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
System system = ((SystemNode)getParent()).getSystem();
Channel channel = new Channel();
channel.setSystem( system.getName() );
channel.setSite( getSite().getName() );
getSite().addChannel( channel );
ChannelNode node = new ChannelNode( channel, mChannelModel,
mChannelProcessingManager, getPlaylistManager(), mSourceManager );
getModel().addNode( node,
SiteNode.this,
SiteNode.this.getChildCount() );
sort();
save();
node.show();
}
} );
retVal.add( addChannelItem );
retVal.add( new JSeparator() );
JMenuItem deleteItem = new JMenuItem( "Delete" );
deleteItem.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
delete();
}
} );
retVal.add( deleteItem );
return retVal;
}
}

View File

@@ -1,85 +0,0 @@
/*******************************************************************************
* 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 controller.system;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import controller.site.Site;
@XmlSeeAlso( { Site.class } )
@XmlRootElement( name = "system" )
public class System
{
private String mName;
private ArrayList<Site> mSite = new ArrayList<Site>();
public System()
{
this( "New System" );
}
public System( String name )
{
mName = name;
}
@XmlAttribute
public String getName()
{
return mName;
}
public void setName( String name )
{
mName = name;
}
public ArrayList<Site> getSite()
{
return mSite;
}
public void setSite( ArrayList<Site> sites )
{
mSite = sites;
}
public void addSite( Site site )
{
mSite.add( site );
}
public void removeSite( Site site )
{
mSite.remove( site );
}
public void clearSites()
{
mSite.clear();
}
public String toString()
{
return mName;
}
}

View File

@@ -1,101 +0,0 @@
/*******************************************************************************
* 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 controller.system;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.tree.TreePath;
import net.miginfocom.swing.MigLayout;
public class SystemEditor extends JPanel implements ActionListener
{
private static final long serialVersionUID = 1L;
private SystemNode mSystemNode;
private JLabel mLabelSystem;
private JTextField mTextSystem;
public SystemEditor( SystemNode system )
{
mSystemNode = system;
initGUI();
}
private void initGUI()
{
setLayout( new MigLayout() );
setBorder( BorderFactory.createTitledBorder( "System" ) );
mLabelSystem = new JLabel( "Name:" );
add( mLabelSystem, "align right" );
mTextSystem = new JTextField( mSystemNode.getSystem().getName() );
add( mTextSystem, "grow, wrap" );
JButton btnSave = new JButton( "Save" );
btnSave.addActionListener( SystemEditor.this );
add( btnSave );
JButton btnReset = new JButton( "Reset" );
btnReset.addActionListener( SystemEditor.this );
add( btnReset, "wrap" );
}
@Override
public void actionPerformed( ActionEvent e )
{
String command = e.getActionCommand();
if( command.contentEquals( "Save" ) )
{
boolean expanded = mSystemNode.getModel().getTree()
.isExpanded( new TreePath( mSystemNode ) );
String name = mTextSystem.getText();
if( name != null )
{
mSystemNode.getSystem().setName( name );
mSystemNode.save();
mSystemNode.show();
if( expanded )
{
mSystemNode.getModel().getTree().expandPath( new TreePath( mSystemNode ) );
}
}
else
{
JOptionPane.showMessageDialog( SystemEditor.this, "Please enter a system name" );
}
}
else if( command.contentEquals( "Reset" ) )
{
mTextSystem.setText( mSystemNode.getSystem().getName() );
}
}
}

View File

@@ -1,102 +0,0 @@
/*******************************************************************************
* 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 controller.system;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import playlist.PlaylistManager;
import source.SourceManager;
import controller.ConfigurableNode;
import controller.channel.ChannelModel;
import controller.channel.ChannelProcessingManager;
public class SystemListNode extends ConfigurableNode
{
private static final long serialVersionUID = 1L;
private ChannelModel mChannelModel;
private ChannelProcessingManager mChannelProcessingManager;
private SourceManager mSourceManager;
public SystemListNode( SystemList list,
ChannelModel channelModel,
ChannelProcessingManager channelProcessingManager,
PlaylistManager playlistManager,
SourceManager sourceManager )
{
super( playlistManager, list );
mChannelModel = channelModel;
mChannelProcessingManager = channelProcessingManager;
mSourceManager = sourceManager;
}
public SystemList getSystemList()
{
return (SystemList)getUserObject();
}
public void init()
{
for( System system: getSystemList().getSystem() )
{
SystemNode node = new SystemNode( system, mChannelModel,
mChannelProcessingManager, getPlaylistManager(), mSourceManager );
getModel().addNode( node, SystemListNode.this, getChildCount() );
node.init();
}
sort();
}
public String toString()
{
return "Systems [" + this.getChildCount() + "]";
}
public JPopupMenu getContextMenu()
{
JPopupMenu retVal = new JPopupMenu();
JMenuItem addSystemItem = new JMenuItem( "Add System" );
addSystemItem.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
System system = new System();
getSystemList().addSystem( system );
getModel().addNode( new SystemNode( system, mChannelModel,
mChannelProcessingManager, getPlaylistManager(), mSourceManager ),
SystemListNode.this, SystemListNode.this.getChildCount() );
}
} );
retVal.add( addSystemItem );
return retVal;
}
}

View File

@@ -1,184 +0,0 @@
/*******************************************************************************
* 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 controller.system;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;
import javax.swing.tree.DefaultMutableTreeNode;
import playlist.PlaylistManager;
import source.SourceManager;
import controller.ConfigurableNode;
import controller.channel.ChannelModel;
import controller.channel.ChannelProcessingManager;
import controller.site.Site;
import controller.site.SiteNode;
public class SystemNode extends ConfigurableNode
{
private static final long serialVersionUID = 1L;
private ChannelModel mChannelModel;
private ChannelProcessingManager mChannelProcessingManager;
private SourceManager mSourceManager;
public SystemNode( System system,
ChannelModel channelModel,
ChannelProcessingManager channelProcessingManager,
PlaylistManager playlistManager,
SourceManager sourceManager )
{
super( playlistManager, system );
mChannelModel = channelModel;
mChannelProcessingManager = channelProcessingManager;
mSourceManager = sourceManager;
}
public void init()
{
for( Site site: getSystem().getSite() )
{
SiteNode node = new SiteNode( site, mChannelModel,
mChannelProcessingManager, getPlaylistManager(), mSourceManager );
getModel().insertNodeInto( node, SystemNode.this, getChildCount() );
node.init();
}
sort();
}
@Override
public String getIconPath()
{
return "images/system.png";
}
@Override
public Color getBackgroundColor()
{
@SuppressWarnings( "unchecked" )
Enumeration<DefaultMutableTreeNode> nodes = children();
while( nodes.hasMoreElements() )
{
SiteNode child = (SiteNode)nodes.nextElement();
if( child.getBackgroundColor() != null )
{
return Color.CYAN;
}
}
return null;
}
@Override
public JPanel getEditor()
{
return new SystemEditor( this );
}
public System getSystem()
{
return (System)getUserObject();
}
public String toString()
{
return getSystem().getName();
}
public void delete()
{
for( int x = 0; x < getChildCount(); x++ )
{
((SiteNode)getChildAt( x )).delete();
}
SystemListNode parent = (SystemListNode)getParent();
parent.getSystemList().removeSystem( getSystem() );
save();
getModel().removeNodeFromParent( SystemNode.this );
/* Show the first child, if one exists so that we don't have a
* collapsed list */
if( parent.getChildCount() > 0 )
{
((ConfigurableNode)parent.getFirstChild()).show();
}
}
public JPopupMenu getContextMenu()
{
JPopupMenu retVal = new JPopupMenu();
JMenuItem addSiteItem = new JMenuItem( "Add Site" );
addSiteItem.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
Site site = new Site();
getSystem().addSite( site );
SiteNode node = new SiteNode( site, mChannelModel,
mChannelProcessingManager, getPlaylistManager(), mSourceManager );
getModel().addNode( node,
SystemNode.this,
SystemNode.this.getChildCount() );
sort();
node.show();
}
} );
retVal.add( addSiteItem );
retVal.add( new JSeparator() );
JMenuItem deleteItem = new JMenuItem( "Delete" );
deleteItem.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
delete();
}
} );
retVal.add( deleteItem );
return retVal;
}
}