mirror of
https://github.com/DSheirer/sdrtrunk.git
synced 2026-11-12 16:47:31 -05:00
Work in progress - updates to alias and alias ID editors.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
* SDR Trunk
|
||||
* Copyright (C) 2015 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
|
||||
@@ -20,109 +20,125 @@ package alias.id.lojack;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JFormattedTextField;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.text.MaskFormatter;
|
||||
|
||||
import module.decode.lj1200.LJ1200Message;
|
||||
import module.decode.lj1200.LJ1200Message.Function;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import controller.ConfigurableNode;
|
||||
import alias.AliasID;
|
||||
import alias.ComponentEditor;
|
||||
|
||||
public class LoJackIDEditor extends JPanel implements ActionListener
|
||||
public class LoJackIDEditor extends ComponentEditor<AliasID>
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private LoJackIDNode mLoJackIDNode;
|
||||
|
||||
|
||||
private JTextField mTextField;
|
||||
|
||||
private JComboBox<LJ1200Message.Function> mFunctionCombo;
|
||||
private JTextField mTextIdent;
|
||||
|
||||
private String mHelpText = "Select a LoJack message function code and enter"
|
||||
+ " a five character reply code/identifier in the ID field.\n\n"
|
||||
+ "Wildcard: use an asterisk (*) to wildcard any character in the "
|
||||
+ "five character reply code (e.g. AB*CD or ***12 or *****)\n\n"
|
||||
+ "Reply codes are five characters where the middle character"
|
||||
+ " identifies the entity (tower/site or transponder) as follows:\n"
|
||||
+ "X,Y\t\tTower\n"
|
||||
+ "0-9,A,C-H,J-N,P-W\tTransponder\n"
|
||||
+ "B,I,O,Z\t\tNot Used";
|
||||
private static final String HELP_TEXT = "LoJack function code and five character ID."
|
||||
+ " The middle character in a reply ID code identifies the entity:"
|
||||
+ " Tower[X,Y] Transponder[0-9,A,C-H,J-N,P-W] Not Used[B,I,O,Z]."
|
||||
+ " Use an asterisk (*) to wildcard ID characters (e.g. AB*CD or ***12 or *****)";
|
||||
|
||||
public LoJackIDEditor( LoJackIDNode lojackNode )
|
||||
public LoJackIDEditor( AliasID aliasID )
|
||||
{
|
||||
mLoJackIDNode = lojackNode;
|
||||
super( aliasID );
|
||||
|
||||
initGUI();
|
||||
|
||||
setComponent( aliasID );
|
||||
}
|
||||
|
||||
private void initGUI()
|
||||
{
|
||||
setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][grow]" ) );
|
||||
|
||||
add( new JLabel( "LoJack Function and ID" ), "span,align center" );
|
||||
|
||||
LoJackFunctionAndID lojack = mLoJackIDNode.getLoJackID();
|
||||
|
||||
add( new JLabel( "Function:" ) );
|
||||
mFunctionCombo = new JComboBox<LJ1200Message.Function>( Function.values() );
|
||||
mFunctionCombo.setSelectedItem( lojack.getFunction() );
|
||||
add( mFunctionCombo, "grow, wrap" );
|
||||
mFunctionCombo.addActionListener( new ActionListener()
|
||||
{
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
setModified( true );
|
||||
}
|
||||
} );
|
||||
add( mFunctionCombo, "growx, push" );
|
||||
|
||||
add( new JLabel( "ID:" ) );
|
||||
mTextIdent = new JTextField( lojack.getID() );
|
||||
|
||||
add( mTextIdent, "grow, wrap" );
|
||||
|
||||
JButton btnSave = new JButton( "Save" );
|
||||
btnSave.addActionListener( LoJackIDEditor.this );
|
||||
add( btnSave, "growx,push" );
|
||||
MaskFormatter formatter = null;
|
||||
|
||||
JButton btnReset = new JButton( "Reset" );
|
||||
btnReset.addActionListener( LoJackIDEditor.this );
|
||||
add( btnReset, "growx,push" );
|
||||
try
|
||||
{
|
||||
//Mask: any character or number, 5 places
|
||||
formatter = new MaskFormatter( "AAAAA" );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
//Do nothing, the mask was invalid
|
||||
}
|
||||
|
||||
JTextArea helpText = new JTextArea( mHelpText );
|
||||
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 LoJackFunctionAndID getLoJackID()
|
||||
{
|
||||
if( getComponent() instanceof LoJackFunctionAndID )
|
||||
{
|
||||
return (LoJackFunctionAndID)getComponent();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed( ActionEvent e )
|
||||
{
|
||||
String command = e.getActionCommand();
|
||||
public void setComponent( AliasID aliasID )
|
||||
{
|
||||
mComponent = aliasID;
|
||||
|
||||
final LoJackFunctionAndID lojack = mLoJackIDNode.getLoJackID();
|
||||
|
||||
if( command.contentEquals( "Save" ) )
|
||||
{
|
||||
String id = mTextIdent.getText();
|
||||
|
||||
if( id != null )
|
||||
{
|
||||
|
||||
lojack.setID( id );
|
||||
lojack.setFunction( (Function)mFunctionCombo.getSelectedItem() );
|
||||
|
||||
((ConfigurableNode)mLoJackIDNode.getParent()).sort();
|
||||
|
||||
mLoJackIDNode.save();
|
||||
|
||||
mLoJackIDNode.show();
|
||||
}
|
||||
else
|
||||
{
|
||||
JOptionPane.showMessageDialog( LoJackIDEditor.this, "Please enter an ident" );
|
||||
}
|
||||
}
|
||||
else if( command.contentEquals( "Reset" ) )
|
||||
LoJackFunctionAndID lojack = getLoJackID();
|
||||
|
||||
if( lojack != null )
|
||||
{
|
||||
mFunctionCombo.setSelectedItem( lojack.getFunction() );
|
||||
mTextIdent.setText( lojack.getID() );
|
||||
mTextField.setText( lojack.getID() );
|
||||
}
|
||||
else
|
||||
{
|
||||
mFunctionCombo.setSelectedItem( null );
|
||||
mTextField.setText( null );
|
||||
}
|
||||
|
||||
mLoJackIDNode.refresh();
|
||||
}
|
||||
setModified( false );
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save()
|
||||
{
|
||||
LoJackFunctionAndID lojack = getLoJackID();
|
||||
|
||||
if( lojack != null )
|
||||
{
|
||||
lojack.setID( mTextField.getText() );
|
||||
lojack.setFunction( (Function)mFunctionCombo.getSelectedItem() );
|
||||
}
|
||||
|
||||
setModified( false );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user