Work in progress - updates to alias and alias ID editors.

This commit is contained in:
denny
2016-02-21 20:02:27 -05:00
parent bd09911e68
commit e5004f9fa6
44 changed files with 1331 additions and 945 deletions

View File

@@ -0,0 +1,69 @@
/*******************************************************************************
* 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 alias.id.status;
import javax.xml.bind.annotation.XmlAttribute;
import alias.AliasID;
import alias.AliasIDType;
public class StatusID extends AliasID
{
private int mStatus;
public StatusID()
{
}
@XmlAttribute
public int getStatus()
{
return mStatus;
}
public void setStatus( int status )
{
this.mStatus = status;
}
public String toString()
{
return "Status: " + mStatus;
}
@Override
public boolean matches( AliasID id )
{
boolean retVal = false;
if( id instanceof StatusID )
{
StatusID statusId = (StatusID)id;
retVal = ( mStatus == statusId.getStatus() );
}
return retVal;
}
@Override
public AliasIDType getType()
{
return AliasIDType.Status;
}
}

View File

@@ -0,0 +1,128 @@
/*******************************************************************************
* 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 alias.id.status;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.text.MaskFormatter;
import net.miginfocom.swing.MigLayout;
import alias.AliasID;
import alias.ComponentEditor;
public class StatusIDEditor extends ComponentEditor<AliasID>
{
private static final long serialVersionUID = 1L;
private static final String HELP_TEXT = "Status numbers are used in some"
+ " protocols like Fleetsync. The status number is assigned a meaning"
+ " in the radio. You can assign a 3 digit status code (use leading zeros) to an"
+ " alias where the alias contains the status meaning.";
private JTextField mTextField;
public StatusIDEditor( AliasID aliasID )
{
super( aliasID );
initGUI();
setComponent( aliasID );
}
private void initGUI()
{
setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][grow]" ) );
add( new JLabel( "Status:" ) );
MaskFormatter formatter = null;
try
{
//Mask: 3 digits
formatter = new MaskFormatter( "###" );
}
catch( Exception e )
{
//Do nothing, the mask was invalid
}
mTextField = new JFormattedTextField( formatter );
mTextField.getDocument().addDocumentListener( this );
add( mTextField, "growx,push" );
JTextArea helpText = new JTextArea( HELP_TEXT );
helpText.setLineWrap( true );
helpText.setBackground( getBackground() );
add( helpText, "span,grow,push" );
}
public StatusID getStatusID()
{
if( getComponent() instanceof StatusID )
{
return (StatusID)getComponent();
}
return null;
}
@Override
public void setComponent( AliasID aliasID )
{
mComponent = aliasID;
StatusID statusID = getStatusID();
if( statusID != null )
{
mTextField.setText( String.valueOf( statusID.getStatus() ) );
}
setModified( false );
repaint();
}
@Override
public void save()
{
StatusID statusID = getStatusID();
if( statusID != null )
{
int status = 0;
try
{
status = Integer.valueOf( mTextField.getText() );
}
catch( Exception e )
{
//Do nothing, we couldn't parse the value
}
statusID.setStatus( status );
}
setModified( false );
}
}

View File

@@ -0,0 +1,87 @@
/*******************************************************************************
* 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 alias.id.status;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import playlist.PlaylistManager;
import alias.AliasIDNode;
import alias.AliasNode;
public class StatusIDNode extends AliasIDNode
{
private static final long serialVersionUID = 1L;
public StatusIDNode( PlaylistManager playlistManager, StatusID id )
{
super( playlistManager, id );
}
@Override
public JPanel getEditor()
{
return null;
}
public StatusID getStatusID()
{
return (StatusID)getUserObject();
}
public String toString()
{
return "Status Code " + getStatusID().getStatus();
}
public JPopupMenu getContextMenu()
{
JPopupMenu retVal = new JPopupMenu();
JMenuItem addSystemItem = new JMenuItem( "Delete" );
addSystemItem.addActionListener( new ActionListener()
{
@Override
public void actionPerformed( ActionEvent e )
{
int n = JOptionPane.showConfirmDialog( getModel().getTree(),
"Are you sure you want to permanently delete this node?" );
if( n == JOptionPane.YES_OPTION )
{
AliasNode parent = (AliasNode)getParent();
parent.getAlias().removeAliasID( getStatusID() );
save();
getModel().removeNodeFromParent( StatusIDNode.this );
}
}
} );
retVal.add( addSystemItem );
return retVal;
}
}