mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
Work in progress - added ability to add new alias identifiers and to
auto save alias/identifier changes.
This commit is contained in:
@@ -55,7 +55,7 @@ public class AliasController extends JPanel
|
||||
mAliasModel = aliasModel;
|
||||
|
||||
mEditor = new AliasEditor( mAliasModel, settingsManager );
|
||||
mAliasModel.addAliasEventListener( mEditor );
|
||||
mAliasModel.addListener( mEditor );
|
||||
|
||||
mIconCellRenderer = new IconCellRenderer( settingsManager );
|
||||
|
||||
|
||||
@@ -52,9 +52,9 @@ public class AliasEditor extends JPanel implements ActionListener, Listener<Alia
|
||||
{
|
||||
mAliasModel = aliasModel;
|
||||
mAliasNameEditor = new AliasNameEditor( mAliasModel, settingsManager );
|
||||
mAliasIdentifierEditor = new AliasIdentifierEditor();
|
||||
mAliasIdentifierEditor = new AliasIdentifierEditor( aliasModel );
|
||||
|
||||
mAliasModel.addAliasEventListener( this );
|
||||
mAliasModel.addListener( this );
|
||||
|
||||
initGUI();
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import alias.id.priority.Priority;
|
||||
import alias.id.priority.PriorityEditor;
|
||||
import alias.id.siteID.SiteIDEditor;
|
||||
import alias.id.siteID.SiteID;
|
||||
import alias.id.status.StatusID;
|
||||
import alias.id.status.StatusIDEditor;
|
||||
import alias.id.talkgroup.TalkgroupID;
|
||||
import alias.id.talkgroup.TalkgroupIDEditor;
|
||||
@@ -205,4 +206,37 @@ public class AliasFactory
|
||||
|
||||
return new EmptyAliasActionEditor();
|
||||
}
|
||||
|
||||
public static AliasID getAliasID( AliasIDType type )
|
||||
{
|
||||
switch( type )
|
||||
{
|
||||
case ESN:
|
||||
return new Esn();
|
||||
case Fleetsync:
|
||||
return new FleetsyncID();
|
||||
case LTRNetUID:
|
||||
return new UniqueID();
|
||||
case LoJack:
|
||||
return new LoJackFunctionAndID();
|
||||
case MDC1200:
|
||||
return new MDC1200ID();
|
||||
case MIN:
|
||||
return new Min();
|
||||
case MPT1327:
|
||||
return new MPT1327ID();
|
||||
case NonRecordable:
|
||||
return new NonRecordable();
|
||||
case Priority:
|
||||
return new Priority();
|
||||
case Site:
|
||||
return new SiteID();
|
||||
case Status:
|
||||
return new StatusID();
|
||||
case Talkgroup:
|
||||
return new TalkgroupID();
|
||||
default:
|
||||
throw new IllegalArgumentException( "Unrecognized Alias ID type: " + type );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,16 +19,28 @@ package alias;
|
||||
|
||||
public enum AliasIDType
|
||||
{
|
||||
ESN,
|
||||
Fleetsync,
|
||||
LoJack,
|
||||
LTRNetUID,
|
||||
MDC1200,
|
||||
MIN,
|
||||
MPT1327,
|
||||
NonRecordable,
|
||||
Priority,
|
||||
Site,
|
||||
Status,
|
||||
Talkgroup;
|
||||
ESN( "ESN" ),
|
||||
Fleetsync( "Fleetsync" ),
|
||||
LoJack( "LoJack" ),
|
||||
LTRNetUID( "LTR-Net UID" ),
|
||||
MDC1200( "MDC-1200" ),
|
||||
MIN( "Passport MIN" ),
|
||||
MPT1327( "MPT-1327" ),
|
||||
NonRecordable( "Non-Recordable" ),
|
||||
Priority( "Audio Priority" ),
|
||||
Site( "Site" ),
|
||||
Status( "Status" ),
|
||||
Talkgroup( "Talkgroup" );
|
||||
|
||||
private String mLabel;
|
||||
|
||||
private AliasIDType( String label )
|
||||
{
|
||||
mLabel = label;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return mLabel;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package alias;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
@@ -7,8 +12,10 @@ import java.util.List;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.ListModel;
|
||||
import javax.swing.ListSelectionModel;
|
||||
@@ -20,6 +27,9 @@ import net.miginfocom.swing.MigLayout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sample.Listener;
|
||||
import alias.AliasEvent.Event;
|
||||
|
||||
public class AliasIdentifierEditor extends AliasConfigurationEditor
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -31,9 +41,11 @@ public class AliasIdentifierEditor extends AliasConfigurationEditor
|
||||
private EditorContainer mEditorContainer = new EditorContainer();
|
||||
|
||||
private Alias mAlias;
|
||||
private AliasModel mAliasModel;
|
||||
|
||||
public AliasIdentifierEditor()
|
||||
public AliasIdentifierEditor( AliasModel model )
|
||||
{
|
||||
mAliasModel = model;
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -71,7 +83,35 @@ public class AliasIdentifierEditor extends AliasConfigurationEditor
|
||||
|
||||
add( mEditorContainer, "span,grow" );
|
||||
|
||||
add( new JButton( "New" ) );
|
||||
final JButton newButton = new JButton( "New ..." );
|
||||
|
||||
newButton.addMouseListener( new MouseAdapter()
|
||||
{
|
||||
@Override
|
||||
public void mouseClicked( MouseEvent e )
|
||||
{
|
||||
JPopupMenu menu = new JPopupMenu();
|
||||
|
||||
menu.add( new AddAliasIdentifierItem( AliasIDType.ESN ) );
|
||||
menu.add( new AddAliasIdentifierItem( AliasIDType.Fleetsync ) );
|
||||
menu.add( new AddAliasIdentifierItem( AliasIDType.LoJack ) );
|
||||
menu.add( new AddAliasIdentifierItem( AliasIDType.LTRNetUID ) );
|
||||
menu.add( new AddAliasIdentifierItem( AliasIDType.MDC1200 ) );
|
||||
menu.add( new AddAliasIdentifierItem( AliasIDType.MPT1327 ) );
|
||||
menu.add( new AddAliasIdentifierItem( AliasIDType.MIN ) );
|
||||
menu.add( new AddAliasIdentifierItem( AliasIDType.Site ) );
|
||||
menu.add( new AddAliasIdentifierItem( AliasIDType.Status ) );
|
||||
menu.add( new AddAliasIdentifierItem( AliasIDType.Talkgroup ) );
|
||||
menu.addSeparator();
|
||||
menu.add( new AddAliasIdentifierItem( AliasIDType.Priority ) );
|
||||
menu.addSeparator();
|
||||
menu.add( new AddAliasIdentifierItem( AliasIDType.NonRecordable ) );
|
||||
|
||||
menu.show( e.getComponent(), e.getX(), e.getY() );
|
||||
}
|
||||
} );
|
||||
|
||||
add( newButton );
|
||||
add( new JButton( "Copy" ) );
|
||||
add( new JButton( "Delete" ), "wrap" );
|
||||
}
|
||||
@@ -110,12 +150,11 @@ public class AliasIdentifierEditor extends AliasConfigurationEditor
|
||||
|
||||
mEditorContainer.setAliasID( null );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void save()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
mAliasModel.broadcast( new AliasEvent( mAlias, Event.CHANGE ) );
|
||||
}
|
||||
|
||||
public class EditorContainer extends JPanel
|
||||
@@ -159,4 +198,43 @@ public class AliasIdentifierEditor extends AliasConfigurationEditor
|
||||
revalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public class AddAliasIdentifierItem extends JMenuItem
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private AliasIDType mAliasIDType;
|
||||
|
||||
public AddAliasIdentifierItem( AliasIDType type )
|
||||
{
|
||||
super( type.toString() );
|
||||
|
||||
mAliasIDType = type;
|
||||
|
||||
addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
final AliasID id = AliasFactory.getAliasID( mAliasIDType );
|
||||
|
||||
if( id != null && mAlias != null )
|
||||
{
|
||||
mAlias.addAliasID( id );
|
||||
|
||||
EventQueue.invokeLater( new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
setAlias( mAlias );
|
||||
|
||||
mAliasIDList.setSelectedValue( id, true );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,12 +258,12 @@ public class AliasModel extends AbstractTableModel
|
||||
}
|
||||
}
|
||||
|
||||
public void addAliasEventListener( Listener<AliasEvent> listener )
|
||||
public void addListener( Listener<AliasEvent> listener )
|
||||
{
|
||||
mAliasEventBroadcaster.addListener( listener );
|
||||
}
|
||||
|
||||
public void removeAliasEventListener( Listener<AliasEvent> listener )
|
||||
public void removeListener( Listener<AliasEvent> listener )
|
||||
{
|
||||
mAliasEventBroadcaster.removeListener( listener );
|
||||
}
|
||||
|
||||
@@ -37,8 +37,10 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import properties.SystemProperties;
|
||||
import sample.Listener;
|
||||
import alias.Alias;
|
||||
import alias.AliasDirectory;
|
||||
import alias.AliasEvent;
|
||||
import alias.AliasList;
|
||||
import alias.AliasModel;
|
||||
import alias.Group;
|
||||
@@ -51,7 +53,7 @@ import controller.channel.ChannelModel;
|
||||
import controller.site.Site;
|
||||
import controller.system.SystemList;
|
||||
|
||||
public class PlaylistManager implements ChannelEventListener
|
||||
public class PlaylistManager implements ChannelEventListener, Listener<AliasEvent>
|
||||
{
|
||||
private final static Logger mLog =
|
||||
LoggerFactory.getLogger( PlaylistManager.class );
|
||||
@@ -83,8 +85,9 @@ public class PlaylistManager implements ChannelEventListener
|
||||
mAliasModel = aliasModel;
|
||||
mChannelModel = channelModel;
|
||||
|
||||
//Register for channel events so that we can save the playlist when
|
||||
//any channels change
|
||||
//Register for alias and channel events so that we can save the
|
||||
//playlist with changes
|
||||
mAliasModel.addListener( this );
|
||||
mChannelModel.addListener( this );
|
||||
}
|
||||
|
||||
@@ -128,6 +131,33 @@ public class PlaylistManager implements ChannelEventListener
|
||||
load( playlistFolder.resolve( playlistFile ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias event listener method. Monitors alias events for events that
|
||||
* indicate that the playlist has changed and queues automatic playlist
|
||||
* saving.
|
||||
*/
|
||||
@Override
|
||||
public void receive( AliasEvent event )
|
||||
{
|
||||
if( !mPlaylistLoading )
|
||||
{
|
||||
switch( event.getEvent() )
|
||||
{
|
||||
case ADD:
|
||||
case DELETE:
|
||||
case CHANGE:
|
||||
schedulePlaylistSave();
|
||||
break;
|
||||
default:
|
||||
//When a new event enum entry is added and received, throw an
|
||||
//exception here to ensure developer adds support for the
|
||||
//use case
|
||||
throw new IllegalArgumentException( "Unrecognized Alias "
|
||||
+ "Event [" + event.getEvent().toString() + "]" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel event listener method. Monitors channel events for events that
|
||||
* indicate that the playlist has changed and queues automatic playlist
|
||||
|
||||
Reference in New Issue
Block a user