mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
Work in progress - more updates to the alias controller and alias editor
panels.
This commit is contained in:
@@ -166,32 +166,6 @@ public class Alias
|
||||
return !mAliasActions.isEmpty();
|
||||
}
|
||||
|
||||
public boolean hasAudioType()
|
||||
{
|
||||
for( AliasID id: mAliasIDs )
|
||||
{
|
||||
if( id.hasAudioType() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public AudioType getAudioType()
|
||||
{
|
||||
for( AliasID id: mAliasIDs )
|
||||
{
|
||||
if( id.hasAudioType() )
|
||||
{
|
||||
return id.getAudioType();
|
||||
}
|
||||
}
|
||||
|
||||
return AudioType.NORMAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the priority level of this alias, if defined, or the default priority
|
||||
*/
|
||||
|
||||
@@ -206,7 +206,7 @@ public class AliasController extends JPanel
|
||||
|
||||
if( selected != null )
|
||||
{
|
||||
// addAlias( selected.copyOf() );
|
||||
addAlias( AliasFactory.copyOf( selected ) );
|
||||
}
|
||||
break;
|
||||
case DELETE_ALIAS:
|
||||
|
||||
@@ -43,6 +43,7 @@ public class AliasEditor extends JPanel implements ActionListener, Listener<Alia
|
||||
|
||||
private JLabel mAliasLabel;
|
||||
private AliasNameEditor mAliasNameEditor;
|
||||
private AliasIdentifierEditor mAliasIdentifierEditor;
|
||||
|
||||
private Alias mAlias;
|
||||
|
||||
@@ -51,6 +52,9 @@ public class AliasEditor extends JPanel implements ActionListener, Listener<Alia
|
||||
{
|
||||
mAliasModel = aliasModel;
|
||||
mAliasNameEditor = new AliasNameEditor( mAliasModel, settingsManager );
|
||||
mAliasIdentifierEditor = new AliasIdentifierEditor();
|
||||
|
||||
mAliasModel.addAliasEventListener( this );
|
||||
|
||||
initGUI();
|
||||
}
|
||||
@@ -69,16 +73,16 @@ public class AliasEditor extends JPanel implements ActionListener, Listener<Alia
|
||||
}
|
||||
|
||||
mAliasNameEditor.setAlias( alias );
|
||||
|
||||
mAliasIdentifierEditor.setAlias( alias );
|
||||
}
|
||||
|
||||
private void initGUI()
|
||||
{
|
||||
setLayout( new MigLayout( "fill,wrap 2", "[right][grow,fill]", "[][][][][grow,fill]" ) );
|
||||
setLayout( new MigLayout( "fill,wrap 2", "[grow,fill][grow,fill]", "[][][][][grow,fill]" ) );
|
||||
|
||||
add( new JLabel( "Alias:" ) );
|
||||
add( new JLabel( "Alias:" ), "align right" );
|
||||
mAliasLabel = new JLabel( DEFAULT_NAME );
|
||||
add( mAliasLabel );
|
||||
add( mAliasLabel, "align left" );
|
||||
|
||||
add( new JSeparator( JSeparator.HORIZONTAL ), "span,growx,push" );
|
||||
|
||||
@@ -87,6 +91,7 @@ public class AliasEditor extends JPanel implements ActionListener, Listener<Alia
|
||||
tabs.setForeground( Color.BLACK );
|
||||
|
||||
tabs.addTab( "Alias", mAliasNameEditor );
|
||||
tabs.addTab( "IDs", mAliasIdentifierEditor );
|
||||
add( tabs, "span,grow" );
|
||||
|
||||
JButton btnSave = new JButton( "Save" );
|
||||
@@ -116,6 +121,7 @@ public class AliasEditor extends JPanel implements ActionListener, Listener<Alia
|
||||
if( command.contentEquals( "Save" ) )
|
||||
{
|
||||
mAliasNameEditor.save();
|
||||
mAliasIdentifierEditor.save();
|
||||
|
||||
//Broadcast an alias change event to save the updates
|
||||
mAliasModel.broadcast( new AliasEvent( mAlias, Event.CHANGE ) );
|
||||
|
||||
138
src/alias/AliasFactory.java
Normal file
138
src/alias/AliasFactory.java
Normal file
@@ -0,0 +1,138 @@
|
||||
package alias;
|
||||
|
||||
import alias.action.AliasAction;
|
||||
import alias.action.beep.BeepAction;
|
||||
import alias.action.clip.ClipAction;
|
||||
import alias.action.script.ScriptAction;
|
||||
import alias.id.esn.Esn;
|
||||
import alias.id.fleetsync.FleetsyncID;
|
||||
import alias.id.lojack.LoJackFunctionAndID;
|
||||
import alias.id.mdc.MDC1200ID;
|
||||
import alias.id.mobileID.Min;
|
||||
import alias.id.mpt1327.MPT1327ID;
|
||||
import alias.id.siteID.SiteID;
|
||||
import alias.id.talkgroup.TalkgroupID;
|
||||
import alias.id.uniqueID.UniqueID;
|
||||
import alias.priority.Priority;
|
||||
import alias.record.NonRecordable;
|
||||
|
||||
public class AliasFactory
|
||||
{
|
||||
public static Alias copyOf( Alias original )
|
||||
{
|
||||
Alias copy = new Alias( original.getName() );
|
||||
copy.setList( original.getList() );
|
||||
copy.setGroup( original.getGroup() );
|
||||
copy.setColor( original.getColor() );
|
||||
copy.setIconName( original.getIconName() );
|
||||
|
||||
for( AliasID id: original.getId() )
|
||||
{
|
||||
switch( id.getType() )
|
||||
{
|
||||
case ESN:
|
||||
Esn originalESN = (Esn)id;
|
||||
Esn copyESN = new Esn();
|
||||
copyESN.setEsn( originalESN.getEsn() );
|
||||
copy.addAliasID( copyESN );
|
||||
break;
|
||||
case Fleetsync:
|
||||
FleetsyncID originalFleetsyncID = (FleetsyncID)id;
|
||||
FleetsyncID copyFleetsyncID = new FleetsyncID();
|
||||
copyFleetsyncID.setIdent( originalFleetsyncID.getIdent() );
|
||||
copy.addAliasID( copyFleetsyncID );
|
||||
break;
|
||||
case LTRNetUID:
|
||||
UniqueID originalUniqueID = (UniqueID)id;
|
||||
UniqueID copyUniqueID = new UniqueID();
|
||||
copyUniqueID.setUid( originalUniqueID.getUid() );
|
||||
copy.addAliasID( copyUniqueID );
|
||||
break;
|
||||
case LoJack:
|
||||
LoJackFunctionAndID originalLoJackFunctionAndID = (LoJackFunctionAndID)id;
|
||||
LoJackFunctionAndID copyLoJackFunctionAndID = new LoJackFunctionAndID();
|
||||
copyLoJackFunctionAndID.setFunction( originalLoJackFunctionAndID.getFunction() );
|
||||
copyLoJackFunctionAndID.setID( originalLoJackFunctionAndID.getID() );
|
||||
copy.addAliasID( copyLoJackFunctionAndID );
|
||||
break;
|
||||
case MDC1200:
|
||||
MDC1200ID originalMDC1200ID = (MDC1200ID)id;
|
||||
MDC1200ID copyMDC1200ID = new MDC1200ID();
|
||||
copyMDC1200ID.setIdent( originalMDC1200ID.getIdent() );
|
||||
copy.addAliasID( copyMDC1200ID );
|
||||
break;
|
||||
case MIN:
|
||||
Min originalMin = (Min)id;
|
||||
Min copyMin = new Min();
|
||||
copyMin.setMin( originalMin.getMin() );
|
||||
copy.addAliasID( copyMin );
|
||||
break;
|
||||
case MPT1327:
|
||||
MPT1327ID originalMPT1327ID = (MPT1327ID)id;
|
||||
MPT1327ID copyMPT1327ID = new MPT1327ID();
|
||||
copyMPT1327ID.setIdent( originalMPT1327ID.getIdent() );
|
||||
copy.addAliasID( copyMPT1327ID );
|
||||
break;
|
||||
case NonRecordable:
|
||||
copy.addAliasID( new NonRecordable() );
|
||||
break;
|
||||
case Priority:
|
||||
Priority originalPriority = (Priority)id;
|
||||
Priority copyPriority = new Priority();
|
||||
copyPriority.setPriority( originalPriority.getPriority() );
|
||||
copy.addAliasID( copyPriority );
|
||||
break;
|
||||
case Site:
|
||||
SiteID originalSiteID = (SiteID)id;
|
||||
SiteID copySiteID = new SiteID();
|
||||
copySiteID.setSite( originalSiteID.getSite() );
|
||||
copy.addAliasID( copySiteID );
|
||||
break;
|
||||
case Talkgroup:
|
||||
TalkgroupID originalTalkgroupID = (TalkgroupID)id;
|
||||
TalkgroupID copyTalkgroupID = new TalkgroupID();
|
||||
copyTalkgroupID.setTalkgroup( originalTalkgroupID.getTalkgroup() );
|
||||
copy.addAliasID( copyTalkgroupID );
|
||||
break;
|
||||
case Status:
|
||||
default:
|
||||
throw new IllegalArgumentException( "Unrecognized alias "
|
||||
+ "ID type: " + id.getType() );
|
||||
}
|
||||
}
|
||||
|
||||
for( AliasAction action: original.getAction() )
|
||||
{
|
||||
if( action instanceof BeepAction )
|
||||
{
|
||||
copy.addAliasAction( new BeepAction() );
|
||||
}
|
||||
else if( action instanceof ClipAction )
|
||||
{
|
||||
ClipAction originalClip = (ClipAction)action;
|
||||
ClipAction copyClip = new ClipAction();
|
||||
copyClip.setInterval( originalClip.getInterval() );
|
||||
copyClip.setPath( originalClip.getPath() );
|
||||
copyClip.setPeriod( originalClip.getPeriod() );
|
||||
copy.addAliasAction( copyClip );
|
||||
}
|
||||
else if( action instanceof ScriptAction )
|
||||
{
|
||||
ScriptAction originalScript = (ScriptAction)action;
|
||||
ScriptAction copyScript = new ScriptAction();
|
||||
copyScript.setInterval( originalScript.getInterval() );
|
||||
copyScript.setPeriod( originalScript.getPeriod() );
|
||||
copyScript.setScript( originalScript.getScript() );
|
||||
copy.addAliasAction( copyScript );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException( "Unrecognized alias "
|
||||
+ "action: " + action.getClass() );
|
||||
}
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,8 +17,6 @@
|
||||
******************************************************************************/
|
||||
package alias;
|
||||
|
||||
import audio.inverted.AudioType;
|
||||
|
||||
public abstract class AliasID
|
||||
{
|
||||
public AliasID()
|
||||
@@ -27,15 +25,5 @@ public abstract class AliasID
|
||||
|
||||
public abstract AliasIDType getType();
|
||||
|
||||
public boolean hasAudioType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public AudioType getAudioType()
|
||||
{
|
||||
return AudioType.NORMAL;
|
||||
}
|
||||
|
||||
public abstract boolean matches( AliasID id );
|
||||
}
|
||||
|
||||
86
src/alias/AliasIdentifierEditor.java
Normal file
86
src/alias/AliasIdentifierEditor.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package alias;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.ListModel;
|
||||
import javax.swing.ListSelectionModel;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
public class AliasIdentifierEditor extends AliasConfigurationEditor
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static ListModel<AliasID> EMPTY_MODEL = new DefaultListModel<>();
|
||||
private JList<AliasID> mAliasIDList = new JList<>( EMPTY_MODEL );
|
||||
|
||||
private Alias mAlias;
|
||||
|
||||
public AliasIdentifierEditor()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
setLayout( new MigLayout( "fill,wrap 3",
|
||||
"[grow,fill][grow,fill][grow,fill]", "[grow,fill][][grow,fill]" ) );
|
||||
|
||||
mAliasIDList.setVisibleRowCount( 6 );
|
||||
mAliasIDList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
|
||||
mAliasIDList.setLayoutOrientation( JList.VERTICAL );
|
||||
|
||||
JScrollPane scroller = new JScrollPane( mAliasIDList );
|
||||
add( scroller, "span,grow" );
|
||||
|
||||
add( new JButton( "New" ) );
|
||||
add( new JButton( "Copy" ) );
|
||||
add( new JButton( "Delete" ), "wrap" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlias( Alias alias )
|
||||
{
|
||||
mAlias = alias;
|
||||
|
||||
if( mAlias == null || mAlias.getId().isEmpty() )
|
||||
{
|
||||
mAliasIDList.setModel( EMPTY_MODEL );
|
||||
}
|
||||
else
|
||||
{
|
||||
DefaultListModel<AliasID> model = new DefaultListModel<AliasID>();
|
||||
|
||||
List<AliasID> ids = mAlias.getId();
|
||||
|
||||
Collections.sort( ids, new Comparator<AliasID>()
|
||||
{
|
||||
@Override
|
||||
public int compare( AliasID o1, AliasID o2 )
|
||||
{
|
||||
return o1.toString().compareTo( o2.toString() );
|
||||
}
|
||||
} );
|
||||
|
||||
for( AliasID id: ids )
|
||||
{
|
||||
model.addElement( id );
|
||||
}
|
||||
|
||||
mAliasIDList.setModel( model );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
@@ -270,6 +270,13 @@ public class AliasModel implements TableModel
|
||||
public void broadcast( AliasEvent event )
|
||||
{
|
||||
mAliasEventBroadcaster.broadcast( event );
|
||||
|
||||
if( event.getEvent() == Event.CHANGE )
|
||||
{
|
||||
int index = mAliases.indexOf( event.getAlias() );
|
||||
|
||||
broadcast( new TableModelEvent( this, index ) );
|
||||
}
|
||||
}
|
||||
|
||||
public void addAliasEventListener( Listener<AliasEvent> listener )
|
||||
|
||||
@@ -13,7 +13,6 @@ import javax.swing.JButton;
|
||||
import javax.swing.JColorChooser;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import map.IconManager;
|
||||
@@ -30,11 +29,9 @@ public class AliasNameEditor extends AliasConfigurationEditor
|
||||
|
||||
private JComboBox<String> mListCombo = new JComboBox<>( EMPTY_MODEL );
|
||||
private JComboBox<String> mGroupCombo = new JComboBox<>( EMPTY_MODEL );
|
||||
private JComboBox<MapIcon> mMapIconCombo;
|
||||
private JTextField mName;
|
||||
|
||||
private JLabel mLabelMapColor;
|
||||
private JButton mButtonColor;
|
||||
private JComboBox<MapIcon> mComboMapIcon;
|
||||
private JButton mBtnIconManager;
|
||||
|
||||
private Alias mAlias;
|
||||
@@ -50,10 +47,33 @@ public class AliasNameEditor extends AliasConfigurationEditor
|
||||
|
||||
private void init()
|
||||
{
|
||||
setLayout( new MigLayout( "fill,wrap 2", "[right][grow,fill]", "[][][][][][grow][]" ) );
|
||||
setLayout( new MigLayout( "fill,wrap 2", "[right][grow,fill]",
|
||||
"[][][][][][][grow]" ) );
|
||||
|
||||
add( new JLabel( "List:" ) );
|
||||
mListCombo.setEditable( true );
|
||||
mListCombo.addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
if( mListCombo.getSelectedItem() != null )
|
||||
{
|
||||
List<String> groups = mAliasModel
|
||||
.getGroupNames( (String)mListCombo.getSelectedItem() );
|
||||
|
||||
if( groups.isEmpty() )
|
||||
{
|
||||
mGroupCombo.setModel( EMPTY_MODEL );
|
||||
}
|
||||
else
|
||||
{
|
||||
mGroupCombo.setModel( new DefaultComboBoxModel<String>(
|
||||
groups.toArray( new String[ groups.size() ] ) ) );;
|
||||
}
|
||||
}
|
||||
}
|
||||
} );
|
||||
add( mListCombo, "wrap" );
|
||||
|
||||
add( new JLabel( "Group:" ) );
|
||||
@@ -88,13 +108,13 @@ public class AliasNameEditor extends AliasConfigurationEditor
|
||||
|
||||
add( new JLabel( "Icon:" ) );
|
||||
|
||||
mComboMapIcon = new JComboBox<MapIcon>( mSettingsManager.getMapIcons() );
|
||||
mMapIconCombo = new JComboBox<MapIcon>( mSettingsManager.getMapIcons() );
|
||||
|
||||
MapIconListCellRenderer renderer = new MapIconListCellRenderer();
|
||||
renderer.setPreferredSize( new Dimension( 200, 30 ) );
|
||||
mComboMapIcon.setRenderer( renderer );
|
||||
mMapIconCombo.setRenderer( renderer );
|
||||
|
||||
add( mComboMapIcon, "wrap" );
|
||||
add( mMapIconCombo, "wrap" );
|
||||
|
||||
//Dummy place holder
|
||||
add( new JLabel() );
|
||||
@@ -175,7 +195,7 @@ public class AliasNameEditor extends AliasConfigurationEditor
|
||||
|
||||
if( savedIcon != null )
|
||||
{
|
||||
mComboMapIcon.setSelectedItem( savedIcon );
|
||||
mMapIconCombo.setSelectedItem( savedIcon );
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -192,41 +212,26 @@ public class AliasNameEditor extends AliasConfigurationEditor
|
||||
@Override
|
||||
public void save()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
String alias = mName.getText();
|
||||
|
||||
if( alias != null )
|
||||
if( mAlias != null )
|
||||
{
|
||||
// boolean expanded = mAliasNode.getModel().getTree()
|
||||
// .isExpanded( new TreePath( mAliasNode ) );
|
||||
//
|
||||
// mAliasNode.getAlias().setName( alias );
|
||||
// ((ConfigurableNode)mAliasNode.getParent()).sort();
|
||||
//
|
||||
// mAliasNode.getAlias().setColor(
|
||||
// mButtonColor.getBackground().getRGB() );
|
||||
|
||||
MapIcon selectedIcon = (MapIcon)mComboMapIcon.getSelectedItem();
|
||||
if( mListCombo.getSelectedItem() != null )
|
||||
{
|
||||
mAlias.setList( (String)mListCombo.getSelectedItem() );
|
||||
}
|
||||
|
||||
// if( selectedIcon != null )
|
||||
// {
|
||||
// mAliasNode.getAlias().setIconName( selectedIcon.getName() );
|
||||
// }
|
||||
//
|
||||
// mAliasNode.save();
|
||||
//
|
||||
// mAliasNode.show();
|
||||
//
|
||||
// if( expanded )
|
||||
// {
|
||||
// mAliasNode.getModel().getTree()
|
||||
// .expandPath( new TreePath( mAliasNode ) );
|
||||
// }
|
||||
if( mGroupCombo.getSelectedItem() != null )
|
||||
{
|
||||
mAlias.setGroup( (String)mGroupCombo.getSelectedItem() );
|
||||
}
|
||||
|
||||
mAlias.setName( mName.getText() );
|
||||
|
||||
mAlias.setColor( mButtonColor.getBackground().getRGB() );
|
||||
|
||||
if( mMapIconCombo.getSelectedItem() != null )
|
||||
{
|
||||
mAlias.setIconName( ((MapIcon)mMapIconCombo.getSelectedItem()).getName() );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog( AliasNameEditor.this, "Please enter an alias name" );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user