mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 08:37:25 -05:00
wip: alias multi-editor feature complete
This commit is contained in:
@@ -29,6 +29,7 @@ import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
import alias.action.AliasAction;
|
||||
import alias.id.AliasID;
|
||||
import alias.id.AliasIDType;
|
||||
import alias.id.nonrecordable.NonRecordable;
|
||||
import alias.id.priority.Priority;
|
||||
|
||||
@XmlSeeAlso( { AliasID.class, AliasAction.class } )
|
||||
@@ -190,7 +191,7 @@ public class Alias
|
||||
return Priority.DEFAULT_PRIORITY;
|
||||
}
|
||||
|
||||
public boolean hasPriority()
|
||||
public boolean hasCallPriority()
|
||||
{
|
||||
for( AliasID id: mAliasIDs )
|
||||
{
|
||||
@@ -202,6 +203,30 @@ public class Alias
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets or updates the call priority
|
||||
*/
|
||||
public void setCallPriority( int priority )
|
||||
{
|
||||
if( priority == Priority.DO_NOT_MONITOR ||
|
||||
( Priority.MIN_PRIORITY <= priority && priority <= Priority.MAX_PRIORITY ) )
|
||||
{
|
||||
for( AliasID id: mAliasIDs )
|
||||
{
|
||||
if( id.getType() == AliasIDType.Priority )
|
||||
{
|
||||
((Priority)id).setPriority( priority );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//If we don't find a priority id, create one
|
||||
Priority p = new Priority();
|
||||
p.setPriority( priority );
|
||||
addAliasID( p );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inspects the alias for a non-recordable alias id. Default is true;
|
||||
@@ -218,4 +243,41 @@ public class Alias
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets or removes the non-recordable alias ID for this alias.
|
||||
*/
|
||||
public void setRecordable( boolean recordable )
|
||||
{
|
||||
if( recordable )
|
||||
{
|
||||
AliasID toRemove = null;
|
||||
|
||||
for( AliasID id: getId() )
|
||||
{
|
||||
if( id.getType() == AliasIDType.NonRecordable )
|
||||
{
|
||||
toRemove = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( toRemove != null )
|
||||
{
|
||||
removeAliasID( toRemove );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( AliasID id: getId() )
|
||||
{
|
||||
if( id.getType() == AliasIDType.NonRecordable )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
addAliasID( new NonRecordable() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public class AliasController extends JPanel
|
||||
{
|
||||
if( selectedRow >= 0 )
|
||||
{
|
||||
int index = mAliasTable.convertRowIndexToModel( mAliasTable.getSelectedRow() );
|
||||
int index = mAliasTable.convertRowIndexToModel( selectedRow );
|
||||
|
||||
return mAliasModel.getAliasAtIndex( index );
|
||||
}
|
||||
@@ -207,10 +207,11 @@ public class AliasController extends JPanel
|
||||
|
||||
for( int selectedRow: selectedRows )
|
||||
{
|
||||
selectedAliases.add( getAlias( selectedRow ) );
|
||||
Alias alias = getAlias( selectedRow );
|
||||
|
||||
selectedAliases.add( alias );
|
||||
}
|
||||
|
||||
mLog.debug( "Selection changed - setting selected aliases" );
|
||||
mMultipleAliasEditor.setItem( selectedAliases );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,14 +266,14 @@ public class AliasModel extends AbstractTableModel
|
||||
|
||||
public void broadcast( AliasEvent event )
|
||||
{
|
||||
mAliasEventBroadcaster.broadcast( event );
|
||||
|
||||
if( event.getEvent() == Event.CHANGE )
|
||||
{
|
||||
int index = mAliases.indexOf( event.getAlias() );
|
||||
|
||||
fireTableRowsUpdated( index, index );
|
||||
}
|
||||
|
||||
mAliasEventBroadcaster.broadcast( event );
|
||||
}
|
||||
|
||||
public void addListener( Listener<AliasEvent> listener )
|
||||
|
||||
@@ -515,7 +515,7 @@ public class AliasNode extends ConfigurableNode
|
||||
retVal.addSeparator();
|
||||
}
|
||||
|
||||
if( !getAlias().hasPriority() )
|
||||
if( !getAlias().hasCallPriority() )
|
||||
{
|
||||
JMenuItem priorityItem = new JMenuItem( "Set Call Priority" );
|
||||
|
||||
|
||||
@@ -18,12 +18,16 @@ import javax.swing.JColorChooser;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import alias.AliasEvent.Event;
|
||||
import alias.id.priority.Priority;
|
||||
import map.IconManager;
|
||||
import map.MapIcon;
|
||||
import map.MapIconListCellRenderer;
|
||||
@@ -52,6 +56,11 @@ public class MultipleAliasEditor extends Editor<List<Alias>>
|
||||
private JCheckBox mColorCheckBox = new JCheckBox( "Color" );
|
||||
private JButton mButtonColor;
|
||||
private JButton mBtnIconManager;
|
||||
private JCheckBox mRecordCheckBox = new JCheckBox( "Record" );
|
||||
private JComboBox<Record> mRecordActionCombo = new JComboBox<>( Record.values() );
|
||||
private JCheckBox mPriorityCheckBox = new JCheckBox( "Priority" );
|
||||
private JSlider mPrioritySlider;
|
||||
private JLabel mPrioritySliderLabel;
|
||||
|
||||
private AliasModel mAliasModel;
|
||||
private SettingsManager mSettingsManager;
|
||||
@@ -79,7 +88,7 @@ public class MultipleAliasEditor extends Editor<List<Alias>>
|
||||
public void init()
|
||||
{
|
||||
setLayout( new MigLayout( "fill,wrap 2", "[grow,fill][grow,fill]",
|
||||
"[][][][][][][][][][grow,fill]" ) );
|
||||
"[][][][][][][][][][][][][grow,fill]" ) );
|
||||
|
||||
mAliasCountLabel = new JLabel( "Alias:" );
|
||||
add( mAliasCountLabel );
|
||||
@@ -94,27 +103,11 @@ public class MultipleAliasEditor extends Editor<List<Alias>>
|
||||
add( mListCheckBox );
|
||||
|
||||
mListCombo.setEditable( true );
|
||||
mListCombo.addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
setModified( true );
|
||||
}
|
||||
} );
|
||||
add( mListCombo, "wrap" );
|
||||
|
||||
add( mGroupCheckBox );
|
||||
|
||||
mGroupCombo.setEditable( true );
|
||||
mGroupCombo.addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
setModified( true );
|
||||
}
|
||||
} );
|
||||
add( mGroupCombo, "wrap" );
|
||||
|
||||
add( mColorCheckBox );
|
||||
@@ -133,8 +126,6 @@ public class MultipleAliasEditor extends Editor<List<Alias>>
|
||||
{
|
||||
mButtonColor.setForeground( newColor );
|
||||
mButtonColor.setBackground( newColor );
|
||||
|
||||
setModified( true );
|
||||
}
|
||||
}
|
||||
} );
|
||||
@@ -147,15 +138,6 @@ public class MultipleAliasEditor extends Editor<List<Alias>>
|
||||
MapIconListCellRenderer renderer = new MapIconListCellRenderer();
|
||||
renderer.setPreferredSize( new Dimension( 200, 30 ) );
|
||||
mMapIconCombo.setRenderer( renderer );
|
||||
mMapIconCombo.addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
setModified( true );
|
||||
}
|
||||
} );
|
||||
|
||||
add( mMapIconCombo, "wrap" );
|
||||
|
||||
//Dummy place holder
|
||||
@@ -183,6 +165,47 @@ public class MultipleAliasEditor extends Editor<List<Alias>>
|
||||
|
||||
add( mBtnIconManager, "span,wrap" );
|
||||
|
||||
add( mRecordCheckBox );
|
||||
add( mRecordActionCombo );
|
||||
|
||||
//Placeholder
|
||||
add( new JLabel( " " ) );
|
||||
mPrioritySliderLabel = new JLabel( "Priority: " + Priority.MIN_PRIORITY );
|
||||
add( mPrioritySliderLabel );
|
||||
|
||||
add( mPriorityCheckBox );
|
||||
|
||||
mPrioritySlider = new JSlider( JSlider.HORIZONTAL,
|
||||
Priority.MIN_PRIORITY,
|
||||
Priority.MAX_PRIORITY + 1,
|
||||
Priority.MIN_PRIORITY );
|
||||
|
||||
mPrioritySlider.setMajorTickSpacing( 20 );
|
||||
mPrioritySlider.setMinorTickSpacing( 5 );
|
||||
mPrioritySlider.setPaintTicks( true );
|
||||
mPrioritySlider.setLabelTable( mPrioritySlider.createStandardLabels( 20, 20 ) );
|
||||
mPrioritySlider.setPaintLabels( true );
|
||||
mPrioritySlider.addChangeListener( new ChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void stateChanged( ChangeEvent e )
|
||||
{
|
||||
int priority = mPrioritySlider.getValue();
|
||||
|
||||
if( priority > Priority.MAX_PRIORITY )
|
||||
{
|
||||
mPrioritySliderLabel.setText( "Priority: Do Not Monitor" );
|
||||
}
|
||||
else
|
||||
{
|
||||
mPrioritySliderLabel.setText( "Priority: " + mPrioritySlider.getValue() );
|
||||
}
|
||||
}
|
||||
} );
|
||||
mPrioritySlider.setToolTipText( HELP_TEXT );
|
||||
|
||||
add( mPrioritySlider );
|
||||
|
||||
JButton saveButton = new JButton( "Save" );
|
||||
saveButton.addActionListener( new ActionListener()
|
||||
{
|
||||
@@ -200,8 +223,7 @@ public class MultipleAliasEditor extends Editor<List<Alias>>
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
setModified( false );
|
||||
setItem( getAliases() );
|
||||
reset();
|
||||
}
|
||||
} );
|
||||
add( resetButton );
|
||||
@@ -212,45 +234,79 @@ public class MultipleAliasEditor extends Editor<List<Alias>>
|
||||
@Override
|
||||
public void setItem( List<Alias> item )
|
||||
{
|
||||
mLog.debug( "setItem invoked" );
|
||||
super.setItem( item );
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append( "Multiple [" );
|
||||
sb.append( "Multiple Selected [ " );
|
||||
|
||||
if( hasItem() )
|
||||
{
|
||||
sb.append( String.valueOf( getAliases().size() ) );
|
||||
|
||||
List<String> listNames = mAliasModel.getListNames();
|
||||
listNames.add( 0, "" );
|
||||
mListCombo.setModel( new DefaultComboBoxModel<String>(
|
||||
listNames.toArray( new String[ listNames.size() ] ) ) );
|
||||
|
||||
List<String> groupNames = mAliasModel.getGroupNames();
|
||||
groupNames.add( 0, "" );
|
||||
mGroupCombo.setModel( new DefaultComboBoxModel<String>(
|
||||
groupNames.toArray( new String[ groupNames.size() ] ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.append( "0" );
|
||||
}
|
||||
|
||||
sb.append( "]" );
|
||||
sb.append( " ]" );
|
||||
|
||||
mAliasCount.setText( sb.toString() );
|
||||
|
||||
List<String> listNames = mAliasModel.getListNames();
|
||||
listNames.add( 0, "" );
|
||||
mListCombo.setModel( new DefaultComboBoxModel<String>(
|
||||
listNames.toArray( new String[ listNames.size() ] ) ) );
|
||||
|
||||
List<String> groupNames = mAliasModel.getGroupNames();
|
||||
groupNames.add( 0, "" );
|
||||
mGroupCombo.setModel( new DefaultComboBoxModel<String>(
|
||||
groupNames.toArray( new String[ groupNames.size() ] ) ) );
|
||||
|
||||
setModified( false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset()
|
||||
{
|
||||
//Reset multi-editor controls
|
||||
mListCheckBox.setSelected( false );
|
||||
mGroupCheckBox.setSelected( false );
|
||||
mColorCheckBox.setSelected( false );
|
||||
mIconCheckBox.setSelected( false );
|
||||
mRecordCheckBox.setSelected( false );
|
||||
mPriorityCheckBox.setSelected( false );
|
||||
|
||||
List<String> listNames = mAliasModel.getListNames();
|
||||
listNames.add( 0, "" );
|
||||
mListCombo.setModel( new DefaultComboBoxModel<String>(
|
||||
listNames.toArray( new String[ listNames.size() ] ) ) );
|
||||
|
||||
List<String> groupNames = mAliasModel.getGroupNames();
|
||||
groupNames.add( 0, "" );
|
||||
mGroupCombo.setModel( new DefaultComboBoxModel<String>(
|
||||
groupNames.toArray( new String[ groupNames.size() ] ) ) );
|
||||
|
||||
mButtonColor.setForeground( getForeground() );
|
||||
mButtonColor.setBackground( getBackground() );
|
||||
|
||||
super.reset();
|
||||
}
|
||||
|
||||
private boolean hasRequestedChanges()
|
||||
{
|
||||
return mListCheckBox.isSelected() ||
|
||||
mGroupCheckBox.isSelected() ||
|
||||
mColorCheckBox.isSelected() ||
|
||||
mIconCheckBox.isSelected() ||
|
||||
mRecordCheckBox.isSelected() ||
|
||||
mPriorityCheckBox.isSelected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save()
|
||||
{
|
||||
if( isModified() && hasItem() )
|
||||
if( hasRequestedChanges() && hasItem() )
|
||||
{
|
||||
setModified( false );
|
||||
|
||||
List<Alias> aliases = getAliases();
|
||||
|
||||
for( Alias alias: aliases )
|
||||
@@ -276,7 +332,6 @@ public class MultipleAliasEditor extends Editor<List<Alias>>
|
||||
group = (String)mGroupCombo.getSelectedItem();
|
||||
}
|
||||
|
||||
mLog.debug( "Group is:" + group );
|
||||
alias.setGroup( group );
|
||||
}
|
||||
|
||||
@@ -296,21 +351,34 @@ public class MultipleAliasEditor extends Editor<List<Alias>>
|
||||
alias.setIconName( null );
|
||||
}
|
||||
}
|
||||
|
||||
if( mRecordCheckBox.isSelected() )
|
||||
{
|
||||
Record action =
|
||||
(Record)mRecordActionCombo.getSelectedItem();
|
||||
|
||||
alias.setRecordable( action == Record.RECORDABLE );
|
||||
}
|
||||
|
||||
if( mPriorityCheckBox.isSelected() )
|
||||
{
|
||||
int priority = mPrioritySlider.getValue();
|
||||
|
||||
//This is a work-around -- we use max priority + 1 in the
|
||||
//gui to indicate do not monitor, and change the value here
|
||||
if( priority == Priority.MAX_PRIORITY + 1 )
|
||||
{
|
||||
priority = Priority.DO_NOT_MONITOR;
|
||||
}
|
||||
|
||||
alias.setCallPriority( priority );
|
||||
}
|
||||
}
|
||||
|
||||
if( mListCheckBox.isSelected() ||
|
||||
mGroupCheckBox.isSelected() ||
|
||||
mColorCheckBox.isSelected() ||
|
||||
mIconCheckBox.isSelected() )
|
||||
for( Alias alias: aliases )
|
||||
{
|
||||
mLog.debug( "Broadcasting change event" );
|
||||
|
||||
for( Alias alias: aliases )
|
||||
{
|
||||
mLog.debug( "Group:" + alias.getGroup() );
|
||||
//Broadcast an alias change event to save the updates
|
||||
mAliasModel.broadcast( new AliasEvent( alias, Event.CHANGE ) );
|
||||
}
|
||||
//Broadcast an alias change event to save the updates
|
||||
mAliasModel.broadcast( new AliasEvent( alias, Event.CHANGE ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -326,4 +394,22 @@ public class MultipleAliasEditor extends Editor<List<Alias>>
|
||||
setItem( getAliases() );
|
||||
}
|
||||
}
|
||||
|
||||
public enum Record
|
||||
{
|
||||
NON_RECORDABLE( "Non-Recordable" ),
|
||||
RECORDABLE( "Recordable" );
|
||||
|
||||
private String mLabel;
|
||||
|
||||
private Record( String label )
|
||||
{
|
||||
mLabel = label;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return mLabel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ public class TrafficChannelManager extends Module
|
||||
Alias to = event.getToIDAlias();
|
||||
|
||||
if( to != null &&
|
||||
to.hasPriority() &&
|
||||
to.hasCallPriority() &&
|
||||
to.getCallPriority() == Priority.DO_NOT_MONITOR )
|
||||
{
|
||||
return true;
|
||||
@@ -326,7 +326,7 @@ public class TrafficChannelManager extends Module
|
||||
Alias from = event.getFromIDAlias();
|
||||
|
||||
if( from != null &&
|
||||
from.hasPriority() &&
|
||||
from.hasCallPriority() &&
|
||||
from.getCallPriority() == Priority.DO_NOT_MONITOR )
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -504,16 +504,17 @@ public class PlaylistManager implements ChannelEventListener, Listener<AliasEven
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the playlist and resets the playlist save pending flag to false
|
||||
* Resets the playlist save pending flag to false and proceeds to save the
|
||||
* playlist.
|
||||
*/
|
||||
public class PlaylistSaveTask implements Runnable
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
save();
|
||||
|
||||
mPlaylistSavePending.set( false );
|
||||
|
||||
save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user