From e5004f9fa6009d7b4e76186997e2b1477355eb14 Mon Sep 17 00:00:00 2001 From: denny Date: Sun, 21 Feb 2016 20:02:27 -0500 Subject: [PATCH] Work in progress - updates to alias and alias ID editors. --- src/alias/Alias.java | 2 +- src/alias/AliasEditor.java | 2 +- src/alias/AliasFactory.java | 74 ++++++- src/alias/AliasID.java | 6 +- src/alias/AliasIdentifierEditor.java | 80 +++++++- src/alias/AliasList.java | 6 +- src/alias/AliasNameEditor.java | 8 +- src/alias/AliasNode.java | 12 +- src/alias/ComponentEditor.java | 137 +++++++++++++ src/alias/ComponentValidationException.java | 14 ++ src/alias/EmptyAliasActionEditor.java | 32 +++ src/alias/EmptyAliasIDEditor.java | 31 +++ src/alias/id/esn/ESNEditor.java | 106 +++++----- src/alias/id/esn/ESNNode.java | 2 +- src/alias/id/fleetsync/FleetsyncIDEditor.java | 124 +++++++----- src/alias/id/fleetsync/FleetsyncIDNode.java | 2 +- src/alias/id/fleetsync/StatusIDEditor.java | 120 ----------- src/alias/id/lojack/LoJackIDEditor.java | 148 ++++++++------ src/alias/id/lojack/LoJackIDNode.java | 2 +- src/alias/id/mdc/MDC1200IDEditor.java | 121 ++++++----- src/alias/id/mdc/MDC1200IDNode.java | 2 +- src/alias/id/mobileID/MINEditor.java | 122 ++++++----- src/alias/id/mobileID/MINNode.java | 2 +- src/alias/id/mpt1327/MPT1327IDEditor.java | 123 ++++++----- src/alias/id/mpt1327/MPT1327IDNode.java | 2 +- .../nonrecordable}/NonRecordable.java | 8 +- .../id/nonrecordable/NonRecordableEditor.java | 62 ++++++ .../nonrecordable}/NonRecordableNode.java | 4 +- src/alias/{ => id}/priority/Priority.java | 2 +- src/alias/id/priority/PriorityEditor.java | 137 +++++++++++++ src/alias/{ => id}/priority/PriorityNode.java | 4 +- src/alias/id/siteID/SiteIDEditor.java | 119 +++++------ src/alias/id/siteID/SiteIDNode.java | 2 +- .../id/{fleetsync => status}/StatusID.java | 2 +- src/alias/id/status/StatusIDEditor.java | 128 ++++++++++++ .../{fleetsync => status}/StatusIDNode.java | 4 +- src/alias/id/talkgroup/TalkgroupIDEditor.java | 120 +++++------ src/alias/id/talkgroup/TalkgroupIDNode.java | 2 +- src/alias/id/uniqueID/UniqueIDEditor.java | 130 ++++++------ src/alias/id/uniqueID/UniqueIDNode.java | 2 +- src/alias/priority/PriorityEditor.java | 191 ------------------ src/alias/record/NonRecordableEditor.java | 75 ------- src/audio/metadata/AudioMetadata.java | 2 +- .../decode/state/TrafficChannelManager.java | 2 +- 44 files changed, 1331 insertions(+), 945 deletions(-) create mode 100644 src/alias/ComponentEditor.java create mode 100644 src/alias/ComponentValidationException.java create mode 100644 src/alias/EmptyAliasActionEditor.java create mode 100644 src/alias/EmptyAliasIDEditor.java delete mode 100644 src/alias/id/fleetsync/StatusIDEditor.java rename src/alias/{record => id/nonrecordable}/NonRecordable.java (70%) create mode 100644 src/alias/id/nonrecordable/NonRecordableEditor.java rename src/alias/{record => id/nonrecordable}/NonRecordableNode.java (97%) rename src/alias/{ => id}/priority/Priority.java (98%) create mode 100644 src/alias/id/priority/PriorityEditor.java rename src/alias/{ => id}/priority/PriorityNode.java (97%) rename src/alias/id/{fleetsync => status}/StatusID.java (98%) create mode 100644 src/alias/id/status/StatusIDEditor.java rename src/alias/id/{fleetsync => status}/StatusIDNode.java (97%) delete mode 100644 src/alias/priority/PriorityEditor.java delete mode 100644 src/alias/record/NonRecordableEditor.java diff --git a/src/alias/Alias.java b/src/alias/Alias.java index d455b2de..1f29d060 100644 --- a/src/alias/Alias.java +++ b/src/alias/Alias.java @@ -27,7 +27,7 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSeeAlso; import alias.action.AliasAction; -import alias.priority.Priority; +import alias.id.priority.Priority; @XmlSeeAlso( { AliasID.class, AliasAction.class } ) @XmlRootElement( name = "alias" ) diff --git a/src/alias/AliasEditor.java b/src/alias/AliasEditor.java index 28e6ecb6..95d43e44 100644 --- a/src/alias/AliasEditor.java +++ b/src/alias/AliasEditor.java @@ -91,7 +91,7 @@ public class AliasEditor extends JPanel implements ActionListener, Listener getEditor( AliasID aliasID ) + { + if( aliasID != null ) + { + switch( aliasID.getType() ) + { + case ESN: + return new ESNEditor( aliasID ); + case Fleetsync: + return new FleetsyncIDEditor( aliasID ); + case LTRNetUID: + return new UniqueIDEditor( aliasID ); + case LoJack: + return new LoJackIDEditor( aliasID ); + case MDC1200: + return new MDC1200IDEditor( aliasID ); + case MIN: + return new MINEditor( aliasID ); + case MPT1327: + return new MPT1327IDEditor( aliasID ); + case NonRecordable: + return new NonRecordableEditor( aliasID ); + case Priority: + return new PriorityEditor( aliasID ); + case Site: + return new SiteIDEditor( aliasID ); + case Status: + return new StatusIDEditor( aliasID ); + case Talkgroup: + return new TalkgroupIDEditor( aliasID ); + default: + break; + } + } + + return new EmptyAliasIDEditor(); + } + + public static ComponentEditor getEditor( AliasAction aliasAction ) + { + if( aliasAction != null ) + { + if( aliasAction instanceof BeepAction ) + { + + } + else if( aliasAction instanceof ClipAction ) + { + + } + else if( aliasAction instanceof ScriptAction ) + { + + } + } + + return new EmptyAliasActionEditor(); + } } diff --git a/src/alias/AliasID.java b/src/alias/AliasID.java index 83a6c360..a4a8ec7f 100644 --- a/src/alias/AliasID.java +++ b/src/alias/AliasID.java @@ -22,16 +22,16 @@ import javax.xml.bind.annotation.XmlSeeAlso; import alias.id.esn.Esn; import alias.id.fleetsync.FleetsyncID; -import alias.id.fleetsync.StatusID; import alias.id.lojack.LoJackFunctionAndID; import alias.id.mdc.MDC1200ID; import alias.id.mobileID.Min; import alias.id.mpt1327.MPT1327ID; +import alias.id.nonrecordable.NonRecordable; +import alias.id.priority.Priority; import alias.id.siteID.SiteID; +import alias.id.status.StatusID; import alias.id.talkgroup.TalkgroupID; import alias.id.uniqueID.UniqueID; -import alias.priority.Priority; -import alias.record.NonRecordable; @XmlSeeAlso( { Esn.class, FleetsyncID.class, Group.class, LoJackFunctionAndID.class, MDC1200ID.class, Min.class, MPT1327ID.class, NonRecordable.class, diff --git a/src/alias/AliasIdentifierEditor.java b/src/alias/AliasIdentifierEditor.java index a240e364..297ff4f3 100644 --- a/src/alias/AliasIdentifierEditor.java +++ b/src/alias/AliasIdentifierEditor.java @@ -7,18 +7,28 @@ import java.util.List; import javax.swing.DefaultListModel; import javax.swing.JButton; import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.ListModel; import javax.swing.ListSelectionModel; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; import net.miginfocom.swing.MigLayout; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class AliasIdentifierEditor extends AliasConfigurationEditor { private static final long serialVersionUID = 1L; + private final static Logger mLog = LoggerFactory.getLogger( AliasIdentifierEditor.class ); + private static ListModel EMPTY_MODEL = new DefaultListModel<>(); private JList mAliasIDList = new JList<>( EMPTY_MODEL ); + private EditorContainer mEditorContainer = new EditorContainer(); private Alias mAlias; @@ -30,14 +40,36 @@ public class AliasIdentifierEditor extends AliasConfigurationEditor private void init() { setLayout( new MigLayout( "fill,wrap 3", - "[grow,fill][grow,fill][grow,fill]", "[grow,fill][][grow,fill]" ) ); + "[grow,fill][grow,fill][grow,fill]", "[][grow,fill][]" ) ); - mAliasIDList.setVisibleRowCount( 6 ); + mAliasIDList.setVisibleRowCount( 4 ); mAliasIDList.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); mAliasIDList.setLayoutOrientation( JList.VERTICAL ); + mAliasIDList.addListSelectionListener( new ListSelectionListener() + { + @Override + public void valueChanged( ListSelectionEvent event ) + { + if( !event.getValueIsAdjusting() ) + { + JList list = (JList)event.getSource(); + + Object selectedItem = list.getSelectedValue(); + + if( selectedItem != null && selectedItem instanceof AliasID ) + { + AliasID selected = (AliasID)selectedItem; + + mEditorContainer.setAliasID( selected ); + } + } + } + } ); JScrollPane scroller = new JScrollPane( mAliasIDList ); add( scroller, "span,grow" ); + + add( mEditorContainer, "span,grow" ); add( new JButton( "New" ) ); add( new JButton( "Copy" ) ); @@ -75,6 +107,8 @@ public class AliasIdentifierEditor extends AliasConfigurationEditor mAliasIDList.setModel( model ); } + + mEditorContainer.setAliasID( null ); } @Override @@ -83,4 +117,46 @@ public class AliasIdentifierEditor extends AliasConfigurationEditor // TODO Auto-generated method stub } + + public class EditorContainer extends JPanel + { + private static final long serialVersionUID = 1L; + + private ComponentEditor mEditor = new EmptyAliasIDEditor(); + + public EditorContainer() + { + setLayout( new MigLayout( "","[grow,fill]", "[grow,fill]" ) ); + + add( mEditor ); + } + + public void setAliasID( AliasID aliasID ) + { + if( mEditor != null ) + { + if( mEditor.isModified() ) + { + int option = JOptionPane.showConfirmDialog( + EditorContainer.this, + "Identifier settings have changed. Do you want to save these changes?", + "Save Changes?", + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE ); + + if( option == JOptionPane.YES_OPTION ) + { + mEditor.save(); + } + } + } + removeAll(); + + mEditor = AliasFactory.getEditor( aliasID ); + + add( mEditor ); + + revalidate(); + } + } } diff --git a/src/alias/AliasList.java b/src/alias/AliasList.java index 312e9d6f..52eb6efe 100644 --- a/src/alias/AliasList.java +++ b/src/alias/AliasList.java @@ -36,16 +36,16 @@ import alias.action.clip.ClipAction; import alias.action.script.ScriptAction; import alias.id.esn.Esn; import alias.id.fleetsync.FleetsyncID; -import alias.id.fleetsync.StatusID; import alias.id.lojack.LoJackFunctionAndID; import alias.id.mdc.MDC1200ID; import alias.id.mobileID.Min; import alias.id.mpt1327.MPT1327ID; +import alias.id.nonrecordable.NonRecordable; +import alias.id.priority.Priority; import alias.id.siteID.SiteID; +import alias.id.status.StatusID; import alias.id.talkgroup.TalkgroupID; import alias.id.uniqueID.UniqueID; -import alias.priority.Priority; -import alias.record.NonRecordable; import audio.metadata.MetadataType; @XmlSeeAlso( { Alias.class, diff --git a/src/alias/AliasNameEditor.java b/src/alias/AliasNameEditor.java index 69768e3a..8455f836 100644 --- a/src/alias/AliasNameEditor.java +++ b/src/alias/AliasNameEditor.java @@ -50,6 +50,10 @@ public class AliasNameEditor extends AliasConfigurationEditor setLayout( new MigLayout( "fill,wrap 2", "[right][grow,fill]", "[][][][][][][grow]" ) ); + add( new JLabel( "Name:" ) ); + mName = new JTextField(); + add( mName, "wrap" ); + add( new JLabel( "List:" ) ); mListCombo.setEditable( true ); mListCombo.addActionListener( new ActionListener() @@ -80,10 +84,6 @@ public class AliasNameEditor extends AliasConfigurationEditor mGroupCombo.setEditable( true ); add( mGroupCombo, "wrap" ); - add( new JLabel( "Name:" ) ); - mName = new JTextField(); - add( mName, "wrap" ); - add( new JLabel( "Color:" ) ); mButtonColor = new JButton( "Select ..." ); diff --git a/src/alias/AliasNode.java b/src/alias/AliasNode.java index 7346bb4c..ca120982 100644 --- a/src/alias/AliasNode.java +++ b/src/alias/AliasNode.java @@ -40,8 +40,6 @@ import alias.id.esn.ESNNode; import alias.id.esn.Esn; import alias.id.fleetsync.FleetsyncID; import alias.id.fleetsync.FleetsyncIDNode; -import alias.id.fleetsync.StatusID; -import alias.id.fleetsync.StatusIDNode; import alias.id.lojack.LoJackFunctionAndID; import alias.id.lojack.LoJackIDNode; import alias.id.mdc.MDC1200ID; @@ -50,16 +48,18 @@ import alias.id.mobileID.MINNode; import alias.id.mobileID.Min; import alias.id.mpt1327.MPT1327ID; import alias.id.mpt1327.MPT1327IDNode; +import alias.id.nonrecordable.NonRecordable; +import alias.id.nonrecordable.NonRecordableNode; +import alias.id.priority.Priority; +import alias.id.priority.PriorityNode; import alias.id.siteID.SiteID; import alias.id.siteID.SiteIDNode; +import alias.id.status.StatusID; +import alias.id.status.StatusIDNode; import alias.id.talkgroup.TalkgroupID; import alias.id.talkgroup.TalkgroupIDNode; import alias.id.uniqueID.UniqueID; import alias.id.uniqueID.UniqueIDNode; -import alias.priority.Priority; -import alias.priority.PriorityNode; -import alias.record.NonRecordable; -import alias.record.NonRecordableNode; import controller.ConfigurableNode; public class AliasNode extends ConfigurableNode diff --git a/src/alias/ComponentEditor.java b/src/alias/ComponentEditor.java new file mode 100644 index 00000000..3de3d30c --- /dev/null +++ b/src/alias/ComponentEditor.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +package alias; + +import javax.swing.JPanel; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +public abstract class ComponentEditor extends JPanel implements DocumentListener +{ + private static final long serialVersionUID = 1L; + private boolean mModified; + private ComponentModificationListener mListener; + protected T mComponent; + + /** + * Abstract class for editor with notifications when contents are modified + * and methods for saving or resetting the component values with the + * contents of the editor. + */ + public ComponentEditor( T component ) + { + mComponent = component; + } + + public ComponentEditor() + { + } + + public void dispose() + { + mComponent = null; + mListener = null; + } + + public T getComponent() + { + return mComponent; + } + + protected void setModified( boolean modified ) + { + mModified = modified; + + if( modified && mListener != null ) + { + mListener.componentModified(); + } + } + + /** + * Indicates if the contents of the editor have been modified + */ + public boolean isModified() + { + return mModified; + } + + @Override + public void insertUpdate( DocumentEvent e ) + { + setModified( true ); + } + + @Override + public void removeUpdate( DocumentEvent e ) + { + setModified( true ); + } + + @Override + public void changedUpdate( DocumentEvent e ) { } + + public void setComponentModificationListener( ComponentModificationListener listener ) + { + mListener = listener; + } + + /** + * Sets or resets the editable component + */ + public abstract void setComponent( T t ); + + /** + * Saves changed editor values to the component + */ + public abstract void save(); + + /** + * Reloads the editor contents from the source component and resets the + * modified flag + */ + public void reset() + { + setComponent( getComponent() ); + } + + /** + * Validate contents of other editors against this component editor before + * saving. Override this method to allow controller to pass other editors + * to this editor for content inspection/validation before indicating that + * this editor passes validation. This allows for validating editor contents + * that are contingent on settings in other editors. + * + * @throws ComponentValidationException if the contents of the editor + * argument cannot be validated, with the exception containing a detailed + * description of the issue. + */ + public void validate( ComponentEditor editor ) throws ComponentValidationException + { + } + + /** + * Listener interface to receive notification that the contents of the + * editor have been modified from the original component value and either + * need to be saved or reset + */ + public interface ComponentModificationListener + { + public void componentModified(); + } +} diff --git a/src/alias/ComponentValidationException.java b/src/alias/ComponentValidationException.java new file mode 100644 index 00000000..bfa8d925 --- /dev/null +++ b/src/alias/ComponentValidationException.java @@ -0,0 +1,14 @@ +package alias; + +public class ComponentValidationException extends Exception +{ + private static final long serialVersionUID = 1L; + + /** + * Component editor contents validation error + */ + public ComponentValidationException( String message ) + { + super( message ); + } +} diff --git a/src/alias/EmptyAliasActionEditor.java b/src/alias/EmptyAliasActionEditor.java new file mode 100644 index 00000000..d00dfaa7 --- /dev/null +++ b/src/alias/EmptyAliasActionEditor.java @@ -0,0 +1,32 @@ +package alias; + +import javax.swing.JLabel; + +import net.miginfocom.swing.MigLayout; +import alias.action.AliasAction; + +public class EmptyAliasActionEditor extends ComponentEditor +{ + private static final long serialVersionUID = 1L; + + public EmptyAliasActionEditor() + { + setLayout( new MigLayout( "", "[center]", "[][grow]" ) ); + add( new JLabel( "Please select an alias action" ), "wrap" ); + } + + @Override + public void setComponent( AliasAction t ) + { + } + + @Override + public void save() + { + } + + @Override + public void reset() + { + } +} diff --git a/src/alias/EmptyAliasIDEditor.java b/src/alias/EmptyAliasIDEditor.java new file mode 100644 index 00000000..3c7908f6 --- /dev/null +++ b/src/alias/EmptyAliasIDEditor.java @@ -0,0 +1,31 @@ +package alias; + +import javax.swing.JLabel; + +import net.miginfocom.swing.MigLayout; + +public class EmptyAliasIDEditor extends ComponentEditor +{ + private static final long serialVersionUID = 1L; + + public EmptyAliasIDEditor() + { + setLayout( new MigLayout( "", "[center]", "[][grow]" ) ); + add( new JLabel( "Please select an identifier" ), "wrap" ); + } + + @Override + public void setComponent( AliasID t ) + { + } + + @Override + public void save() + { + } + + @Override + public void reset() + { + } +} diff --git a/src/alias/id/esn/ESNEditor.java b/src/alias/id/esn/ESNEditor.java index e2a55f2b..1ace4da8 100644 --- a/src/alias/id/esn/ESNEditor.java +++ b/src/alias/id/esn/ESNEditor.java @@ -1,6 +1,6 @@ /******************************************************************************* * SDR Trunk - * Copyright (C) 2014 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,76 +20,86 @@ package alias.id.esn; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import javax.swing.JButton; import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; +import javax.swing.JTextArea; import javax.swing.JTextField; import net.miginfocom.swing.MigLayout; -import controller.ConfigurableNode; +import alias.AliasID; +import alias.ComponentEditor; -public class ESNEditor extends JPanel implements ActionListener +public class ESNEditor extends ComponentEditor { private static final long serialVersionUID = 1L; - private ESNNode mESNNode; - private JTextField mTextESN; - public ESNEditor( ESNNode esnNode ) + private static final String HELP_TEXT = "An Electronic Serial Number (ESN)" + + " is a unique radio hardware identifier normally composed of" + + " hexadecimal (0-9,A-F) characters. Use an asterisk (*) to wildcard" + + " individual digits (e.g. ABCD123* or AB**1**4)"; + + private JTextField mTextField; + + public ESNEditor( AliasID aliasID ) { - mESNNode = esnNode; + super( aliasID ); initGUI(); + + setComponent( aliasID ); } private void initGUI() { - setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][grow]" ) ); - - add( new JLabel( "Electronic Serial Number ID" ), "span,align center" ); + setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][grow]" ) ); add( new JLabel( "ESN:" ) ); - mTextESN = new JTextField( mESNNode.getESN().getEsn() ); - add( mTextESN, "growx,push" ); - - JButton btnSave = new JButton( "Save" ); - btnSave.addActionListener( ESNEditor.this ); - add( btnSave, "growx,push" ); + mTextField = new JTextField(); + mTextField.getDocument().addDocumentListener( this ); + add( mTextField, "growx,push" ); - JButton btnReset = new JButton( "Reset" ); - btnReset.addActionListener( ESNEditor.this ); - add( btnReset, "growx,push" ); + JTextArea helpText = new JTextArea( HELP_TEXT ); + helpText.setLineWrap( true ); + helpText.setBackground( getBackground() ); + add( helpText, "span,grow,push" ); + } + + public Esn getEsn() + { + if( getComponent() instanceof Esn ) + { + return (Esn)getComponent(); + } + + return null; } @Override - public void actionPerformed( ActionEvent e ) - { - String command = e.getActionCommand(); + public void setComponent( AliasID aliasID ) + { + mComponent = aliasID; - if( command.contentEquals( "Save" ) ) + Esn esn = getEsn(); + + if( esn != null ) { - String esn = mTextESN.getText(); - - if( esn != null ) - { - mESNNode.getESN().setEsn( esn ); - - ((ConfigurableNode)mESNNode.getParent()).sort(); - - mESNNode.save(); - - mESNNode.show(); - } - else - { - JOptionPane.showMessageDialog( ESNEditor.this, "Please enter an ESN" ); - } - } - else if( command.contentEquals( "Reset" ) ) - { - mTextESN.setText( mESNNode.getESN().getEsn() ); + mTextField.setText( esn.getEsn() ); } - mESNNode.refresh(); - } + setModified( false ); + + repaint(); + } + + @Override + public void save() + { + Esn esn = getEsn(); + + if( esn != null ) + { + esn.setEsn( mTextField.getText() ); + } + + setModified( false ); + } } diff --git a/src/alias/id/esn/ESNNode.java b/src/alias/id/esn/ESNNode.java index ecdd33e8..a814811e 100644 --- a/src/alias/id/esn/ESNNode.java +++ b/src/alias/id/esn/ESNNode.java @@ -41,7 +41,7 @@ public class ESNNode extends AliasIDNode @Override public JPanel getEditor() { - return new ESNEditor( this ); + return null; } public Esn getESN() diff --git a/src/alias/id/fleetsync/FleetsyncIDEditor.java b/src/alias/id/fleetsync/FleetsyncIDEditor.java index 03b36c81..9075ee7f 100644 --- a/src/alias/id/fleetsync/FleetsyncIDEditor.java +++ b/src/alias/id/fleetsync/FleetsyncIDEditor.java @@ -1,6 +1,6 @@ /******************************************************************************* * SDR Trunk - * Copyright (C) 2014 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,89 +20,107 @@ package alias.id.fleetsync; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import javax.swing.JButton; +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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import controller.channel.Channel; import net.miginfocom.swing.MigLayout; -import controller.ConfigurableNode; +import alias.AliasID; +import alias.ComponentEditor; -public class FleetsyncIDEditor extends JPanel implements ActionListener +public class FleetsyncIDEditor extends ComponentEditor { - private static final long serialVersionUID = 1L; - private FleetsyncIDNode mFleetsyncIDNode; - - private JLabel mLabelName; - private JTextField mTextIdent; + private final static Logger mLog = LoggerFactory.getLogger( FleetsyncIDEditor.class ); - private String mHelpText = "Enter a formatted fleetsync identifier.\n\n" - + "Format: PPP-IIII (P=Prefix, I=Identifier)\n\n" - + "Wildcard: use one or more asterisks (*) for any talkgroup " - + "digits.\n\n"; + private static final long serialVersionUID = 1L; - public FleetsyncIDEditor( FleetsyncIDNode fsNode ) + private static final String HELP_TEXT = "A Fleetsync identifier is a" + + " composite decimal [0-9] value formatted as ggg-uuuu where" + + " g=Group and u=Unit."; + + private JTextField mTextField; + + public FleetsyncIDEditor( AliasID aliasID ) { - mFleetsyncIDNode = fsNode; + super( aliasID ); + initGUI(); + + setComponent( aliasID ); } private void initGUI() { - setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][grow]" ) ); + setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][grow]" ) ); - add( new JLabel( "Fleetsync ID" ), "span,align center" ); + add( new JLabel( "Fleetsync ID:" ) ); - add( new JLabel( "Ident:" ) ); - mTextIdent = new JTextField( mFleetsyncIDNode.getFleetsyncID().getIdent() ); + MaskFormatter formatter = null; - add( mTextIdent, "grow, wrap" ); + try + { + //Mask: 3 digits - 4 digits + formatter = new MaskFormatter( "###-####" ); + } + catch( Exception e ) + { + //Do nothing, the mask was invalid + } - JButton btnSave = new JButton( "Save" ); - btnSave.addActionListener( FleetsyncIDEditor.this ); - add( btnSave, "growx,push" ); + mTextField = new JFormattedTextField( formatter ); + mTextField.getDocument().addDocumentListener( this ); - JButton btnReset = new JButton( "Reset" ); - btnReset.addActionListener( FleetsyncIDEditor.this ); - add( btnReset, "growx,push" ); + add( mTextField, "growx,push" ); - JTextArea helpText = new JTextArea( mHelpText ); + JTextArea helpText = new JTextArea( HELP_TEXT ); helpText.setLineWrap( true ); helpText.setBackground( getBackground() ); add( helpText, "span,grow,push" ); } + + public FleetsyncID getFleetsyncID() + { + if( getComponent() instanceof FleetsyncID ) + { + return (FleetsyncID)getComponent(); + } + + return null; + } @Override - public void actionPerformed( ActionEvent e ) - { - String command = e.getActionCommand(); + public void setComponent( AliasID aliasID ) + { + mComponent = aliasID; - if( command.contentEquals( "Save" ) ) + FleetsyncID fleetsync = getFleetsyncID(); + + if( fleetsync != null ) { - String ident = mTextIdent.getText(); - - if( ident != null ) - { - mFleetsyncIDNode.getFleetsyncID().setIdent( ident ); + mTextField.setText( fleetsync.getIdent() ); + } + + setModified( false ); + + repaint(); + } - ((ConfigurableNode)mFleetsyncIDNode.getParent()).sort(); - - mFleetsyncIDNode.save(); - - mFleetsyncIDNode.show(); - } - else - { - JOptionPane.showMessageDialog( FleetsyncIDEditor.this, "Please enter an ident" ); - } - } - else if( command.contentEquals( "Reset" ) ) + @Override + public void save() + { + FleetsyncID fleetsync = getFleetsyncID(); + + if( fleetsync != null ) { - mTextIdent.setText( mFleetsyncIDNode.getFleetsyncID().getIdent() ); + fleetsync.setIdent( mTextField.getText() ); } - mFleetsyncIDNode.refresh(); - } + setModified( false ); + } } diff --git a/src/alias/id/fleetsync/FleetsyncIDNode.java b/src/alias/id/fleetsync/FleetsyncIDNode.java index 4d0e09f1..280c44a8 100644 --- a/src/alias/id/fleetsync/FleetsyncIDNode.java +++ b/src/alias/id/fleetsync/FleetsyncIDNode.java @@ -41,7 +41,7 @@ public class FleetsyncIDNode extends AliasIDNode @Override public JPanel getEditor() { - return new FleetsyncIDEditor( this ); + return null; } public FleetsyncID getFleetsyncID() diff --git a/src/alias/id/fleetsync/StatusIDEditor.java b/src/alias/id/fleetsync/StatusIDEditor.java deleted file mode 100644 index fe3a6348..00000000 --- a/src/alias/id/fleetsync/StatusIDEditor.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * 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 - ******************************************************************************/ -package alias.id.fleetsync; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; - -import net.miginfocom.swing.MigLayout; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import controller.ConfigurableNode; - -public class StatusIDEditor extends JPanel implements ActionListener -{ - private static final long serialVersionUID = 1L; - private final static Logger mLog = - LoggerFactory.getLogger( StatusIDEditor.class ); - - private StatusIDNode mStatusIDNode; - - private JLabel mLabelName; - private JTextField mTextStatusID; - - public StatusIDEditor( StatusIDNode statusIDNode ) - { - mStatusIDNode = statusIDNode; - - initGUI(); - } - - private void initGUI() - { - setLayout( new MigLayout() ); - - setBorder( BorderFactory.createTitledBorder( "Status Code" ) ); - - mLabelName = new JLabel( "Status Code:" ); - add( mLabelName, "align right" ); - - mTextStatusID = new JTextField( - String.valueOf( mStatusIDNode.getStatusID().getStatus() ) ); - add( mTextStatusID, "grow, wrap" ); - - JButton btnSave = new JButton( "Save" ); - btnSave.addActionListener( StatusIDEditor.this ); - add( btnSave ); - - JButton btnReset = new JButton( "Reset" ); - btnReset.addActionListener( StatusIDEditor.this ); - add( btnReset, "wrap" ); - } - - @Override - public void actionPerformed( ActionEvent e ) - { - String command = e.getActionCommand(); - - if( command.contentEquals( "Save" ) ) - { - String statusIDString = mTextStatusID.getText(); - - if( statusIDString != null ) - { - try - { - int id = Integer.parseInt( statusIDString ); - - mStatusIDNode.getStatusID().setStatus( id ); - - ((ConfigurableNode)mStatusIDNode.getParent()).sort(); - - mStatusIDNode.save(); - - mStatusIDNode.show(); - } - catch( Exception ex ) - { - mLog.error( "StatusIDEditor - error parsing int status " + - "id from [" + statusIDString + "]" ); - } - } - else - { - JOptionPane.showMessageDialog( StatusIDEditor.this, - "Please enter a status ID code" ); - } - } - else if( command.contentEquals( "Reset" ) ) - { - mTextStatusID.setText( - String.valueOf( mStatusIDNode.getStatusID().getStatus() ) ); - } - - mStatusIDNode.refresh(); - } -} diff --git a/src/alias/id/lojack/LoJackIDEditor.java b/src/alias/id/lojack/LoJackIDEditor.java index 9cc121da..551dc82d 100644 --- a/src/alias/id/lojack/LoJackIDEditor.java +++ b/src/alias/id/lojack/LoJackIDEditor.java @@ -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 { private static final long serialVersionUID = 1L; - private LoJackIDNode mLoJackIDNode; - + + private JTextField mTextField; + private JComboBox 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( 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 ); + } } diff --git a/src/alias/id/lojack/LoJackIDNode.java b/src/alias/id/lojack/LoJackIDNode.java index fcda77bd..b5e65b7f 100644 --- a/src/alias/id/lojack/LoJackIDNode.java +++ b/src/alias/id/lojack/LoJackIDNode.java @@ -41,7 +41,7 @@ public class LoJackIDNode extends AliasIDNode @Override public JPanel getEditor() { - return new LoJackIDEditor( this ); + return null; } public LoJackFunctionAndID getLoJackID() diff --git a/src/alias/id/mdc/MDC1200IDEditor.java b/src/alias/id/mdc/MDC1200IDEditor.java index 6003fd56..2f23bacb 100644 --- a/src/alias/id/mdc/MDC1200IDEditor.java +++ b/src/alias/id/mdc/MDC1200IDEditor.java @@ -1,6 +1,6 @@ /******************************************************************************* * SDR Trunk - * Copyright (C) 2014 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 @@ -17,79 +17,100 @@ ******************************************************************************/ package alias.id.mdc; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; +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 net.miginfocom.swing.MigLayout; -import controller.ConfigurableNode; +import alias.AliasID; +import alias.ComponentEditor; -public class MDC1200IDEditor extends JPanel implements ActionListener +public class MDC1200IDEditor extends ComponentEditor { private static final long serialVersionUID = 1L; - private MDC1200IDNode mMDC1200IDNode; - - private JTextField mTextIdent; - public MDC1200IDEditor( MDC1200IDNode fsNode ) + private static final String HELP_TEXT = "An MDC-1200 identifier is a" + + " four digit [0-9] value. Use an asterisk (*) to wildcard" + + " individual digits (e.g. 123* or **34)"; + + private JTextField mTextField; + + public MDC1200IDEditor( AliasID aliasID ) { - mMDC1200IDNode = fsNode; + super( aliasID ); + initGUI(); + + setComponent( aliasID ); } private void initGUI() { - setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][grow]" ) ); + setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][grow]" ) ); - add( new JLabel( "MDC-1200 " ), "span,align center" ); + add( new JLabel( "MDC-1200 ID:" ) ); - add( new JLabel( "Unit ID:" ) ); - mTextIdent = new JTextField( mMDC1200IDNode.getMDC1200ID().getIdent() ); - add( mTextIdent, "growx,push" ); + MaskFormatter formatter = null; + + try + { + //Mask: 4 digits + formatter = new MaskFormatter( "####" ); + } + catch( Exception e ) + { + //Do nothing, the mask was invalid + } - JButton btnSave = new JButton( "Save" ); - btnSave.addActionListener( MDC1200IDEditor.this ); - add( btnSave, "growx,push" ); - - JButton btnReset = new JButton( "Reset" ); - btnReset.addActionListener( MDC1200IDEditor.this ); - add( btnReset, "growx,push" ); + 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 MDC1200ID getMDC1200ID() + { + if( getComponent() instanceof MDC1200ID ) + { + return (MDC1200ID)getComponent(); + } + + return null; } @Override - public void actionPerformed( ActionEvent e ) - { - String command = e.getActionCommand(); + public void setComponent( AliasID aliasID ) + { + mComponent = aliasID; - if( command.contentEquals( "Save" ) ) + MDC1200ID mdc = getMDC1200ID(); + + if( mdc != null ) { - String ident = mTextIdent.getText(); - - if( ident != null ) - { - mMDC1200IDNode.getMDC1200ID().setIdent( ident ); + mTextField.setText( mdc.getIdent() ); + } + + setModified( false ); + + repaint(); + } - ((ConfigurableNode)mMDC1200IDNode.getParent()).sort(); - - mMDC1200IDNode.save(); - - mMDC1200IDNode.show(); - } - else - { - JOptionPane.showMessageDialog( MDC1200IDEditor.this, "Please enter a unit ID" ); - } - } - else if( command.contentEquals( "Reset" ) ) + @Override + public void save() + { + MDC1200ID mdc = getMDC1200ID(); + + if( mdc != null ) { - mTextIdent.setText( mMDC1200IDNode.getMDC1200ID().getIdent() ); + mdc.setIdent( mTextField.getText() ); } - mMDC1200IDNode.refresh(); - } + setModified( false ); + } } diff --git a/src/alias/id/mdc/MDC1200IDNode.java b/src/alias/id/mdc/MDC1200IDNode.java index 9c315a49..0af5fae0 100644 --- a/src/alias/id/mdc/MDC1200IDNode.java +++ b/src/alias/id/mdc/MDC1200IDNode.java @@ -41,7 +41,7 @@ public class MDC1200IDNode extends AliasIDNode @Override public JPanel getEditor() { - return new MDC1200IDEditor( this ); + return null; } public MDC1200ID getMDC1200ID() diff --git a/src/alias/id/mobileID/MINEditor.java b/src/alias/id/mobileID/MINEditor.java index 8b0f982a..aaac927d 100644 --- a/src/alias/id/mobileID/MINEditor.java +++ b/src/alias/id/mobileID/MINEditor.java @@ -1,6 +1,6 @@ /******************************************************************************* * SDR Trunk - * Copyright (C) 2014 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,79 +20,99 @@ package alias.id.mobileID; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import javax.swing.JButton; +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 net.miginfocom.swing.MigLayout; -import controller.ConfigurableNode; +import alias.AliasID; +import alias.ComponentEditor; -public class MINEditor extends JPanel implements ActionListener +public class MINEditor extends ComponentEditor { private static final long serialVersionUID = 1L; - private MINNode mMINNode; - - private JLabel mLabelName; - private JTextField mTextMIN; - public MINEditor( MINNode minNode ) + private static final String HELP_TEXT = "A Passport Mobile Identifier (MIN) is a" + + " six character hexadecimal value"; + + private JTextField mTextField; + + public MINEditor( AliasID aliasID ) { - mMINNode = minNode; + super( aliasID ); initGUI(); + + setComponent( aliasID ); } private void initGUI() { - setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][grow]" ) ); - - add( new JLabel( "Mobile ID Number (MIN)" ), "span,align center" ); + setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][grow]" ) ); add( new JLabel( "MIN:" ) ); - - mTextMIN = new JTextField( mMINNode.getMIN().getMin() ); - add( mTextMIN, "growx,push" ); - - JButton btnSave = new JButton( "Save" ); - btnSave.addActionListener( MINEditor.this ); - add( btnSave, "growx,push" ); - JButton btnReset = new JButton( "Reset" ); - btnReset.addActionListener( MINEditor.this ); - add( btnReset, "growx,push" ); + MaskFormatter formatter = null; + + try + { + //Mask: 6 hex characters + formatter = new MaskFormatter( "HHHHHH" ); + } + 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 Min getMin() + { + if( getComponent() instanceof Min ) + { + return (Min)getComponent(); + } + + return null; } @Override - public void actionPerformed( ActionEvent e ) - { - String command = e.getActionCommand(); + public void setComponent( AliasID aliasID ) + { + mComponent = aliasID; - if( command.contentEquals( "Save" ) ) + Min min = getMin(); + + if( min != null ) { - String esn = mTextMIN.getText(); - - if( esn != null ) - { - mMINNode.getMIN().setMin( esn ); - - ((ConfigurableNode)mMINNode.getParent()).sort(); - - mMINNode.save(); - - mMINNode.show(); - } - else - { - JOptionPane.showMessageDialog( MINEditor.this, "Please enter an ESN" ); - } - } - else if( command.contentEquals( "Reset" ) ) - { - mTextMIN.setText( mMINNode.getMIN().getMin() ); + mTextField.setText( min.getMin() ); } - mMINNode.refresh(); - } + setModified( false ); + + repaint(); + } + + @Override + public void save() + { + Min min = getMin(); + + if( min != null ) + { + min.setMin( mTextField.getText() ); + } + + setModified( false ); + } } diff --git a/src/alias/id/mobileID/MINNode.java b/src/alias/id/mobileID/MINNode.java index be0b7e83..3f43fca2 100644 --- a/src/alias/id/mobileID/MINNode.java +++ b/src/alias/id/mobileID/MINNode.java @@ -41,7 +41,7 @@ public class MINNode extends AliasIDNode @Override public JPanel getEditor() { - return new MINEditor( this ); + return null; } public Min getMIN() diff --git a/src/alias/id/mpt1327/MPT1327IDEditor.java b/src/alias/id/mpt1327/MPT1327IDEditor.java index ab6dcdb6..c1e7e674 100644 --- a/src/alias/id/mpt1327/MPT1327IDEditor.java +++ b/src/alias/id/mpt1327/MPT1327IDEditor.java @@ -1,6 +1,6 @@ /******************************************************************************* * SDR Trunk - * Copyright (C) 2014 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 @@ -17,80 +17,101 @@ ******************************************************************************/ package alias.id.mpt1327; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; +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 net.miginfocom.swing.MigLayout; -import controller.ConfigurableNode; +import alias.AliasID; +import alias.ComponentEditor; -public class MPT1327IDEditor extends JPanel implements ActionListener +public class MPT1327IDEditor extends ComponentEditor { - private static final long serialVersionUID = 1L; - private MPT1327IDNode mMPT1327IDNode; - - private JTextField mTextIdent; + private static final long serialVersionUID = 1L; - public MPT1327IDEditor( MPT1327IDNode fsNode ) + private static final String HELP_TEXT = "An MPT-1327 identifier is a" + + " composite decimal [0-9] value formatted as ppp-iiii where" + + " p=Prefix and i=Ident."; + + private JTextField mTextField; + + public MPT1327IDEditor( AliasID aliasID ) { - mMPT1327IDNode = fsNode; + super( aliasID ); + initGUI(); + + setComponent( aliasID ); } private void initGUI() { - setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][grow]" ) ); + setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][grow]" ) ); - add( new JLabel( "MPT-1327 Radio or Group ID" ), "span,align center" ); + add( new JLabel( "MPT-1327 ID:" ) ); - add( new JLabel( "ID:" ) ); + MaskFormatter formatter = null; + + try + { + //Mask: 3 digits - 4 digits + formatter = new MaskFormatter( "###-####" ); + } + catch( Exception e ) + { + //Do nothing, the mask was invalid + } - mTextIdent = new JTextField( mMPT1327IDNode.getMPT1327ID().getIdent() ); - add( mTextIdent, "growx,push" ); - - JButton btnSave = new JButton( "Save" ); - btnSave.addActionListener( MPT1327IDEditor.this ); - add( btnSave, "growx,push" ); + mTextField = new JFormattedTextField( formatter ); + mTextField.getDocument().addDocumentListener( this ); - JButton btnReset = new JButton( "Reset" ); - btnReset.addActionListener( MPT1327IDEditor.this ); - add( btnReset, "growx,push" ); + add( mTextField, "growx,push" ); + + JTextArea helpText = new JTextArea( HELP_TEXT ); + helpText.setLineWrap( true ); + helpText.setBackground( getBackground() ); + add( helpText, "span,grow,push" ); + } + + public MPT1327ID getMPT1327ID() + { + if( getComponent() instanceof MPT1327ID ) + { + return (MPT1327ID)getComponent(); + } + + return null; } @Override - public void actionPerformed( ActionEvent e ) - { - String command = e.getActionCommand(); + public void setComponent( AliasID aliasID ) + { + mComponent = aliasID; - if( command.contentEquals( "Save" ) ) + MPT1327ID mpt = getMPT1327ID(); + + if( mpt != null ) { - String ident = mTextIdent.getText(); - - if( ident != null ) - { - mMPT1327IDNode.getMPT1327ID().setIdent( ident ); + mTextField.setText( mpt.getIdent() ); + } + + setModified( false ); + + repaint(); + } - ((ConfigurableNode)mMPT1327IDNode.getParent()).sort(); - - mMPT1327IDNode.save(); - - mMPT1327IDNode.show(); - } - else - { - JOptionPane.showMessageDialog( MPT1327IDEditor.this, "Please enter a MPT1327 unit ID" ); - } - } - else if( command.contentEquals( "Reset" ) ) + @Override + public void save() + { + MPT1327ID mpt = getMPT1327ID(); + + if( mpt != null ) { - mTextIdent.setText( mMPT1327IDNode.getMPT1327ID().getIdent() ); + mpt.setIdent( mTextField.getText() ); } - mMPT1327IDNode.refresh(); - } + setModified( false ); + } } diff --git a/src/alias/id/mpt1327/MPT1327IDNode.java b/src/alias/id/mpt1327/MPT1327IDNode.java index a5937cee..04cda43a 100644 --- a/src/alias/id/mpt1327/MPT1327IDNode.java +++ b/src/alias/id/mpt1327/MPT1327IDNode.java @@ -41,7 +41,7 @@ public class MPT1327IDNode extends AliasIDNode @Override public JPanel getEditor() { - return new MPT1327IDEditor( this ); + return null; } public MPT1327ID getMPT1327ID() diff --git a/src/alias/record/NonRecordable.java b/src/alias/id/nonrecordable/NonRecordable.java similarity index 70% rename from src/alias/record/NonRecordable.java rename to src/alias/id/nonrecordable/NonRecordable.java index 00c69482..423ccd56 100644 --- a/src/alias/record/NonRecordable.java +++ b/src/alias/id/nonrecordable/NonRecordable.java @@ -1,4 +1,4 @@ -package alias.record; +package alias.id.nonrecordable; import alias.AliasID; import alias.AliasIDType; @@ -16,4 +16,10 @@ public class NonRecordable extends AliasID { return false; } + + @Override + public String toString() + { + return "Non-Recordable"; + } } diff --git a/src/alias/id/nonrecordable/NonRecordableEditor.java b/src/alias/id/nonrecordable/NonRecordableEditor.java new file mode 100644 index 00000000..220a9d5d --- /dev/null +++ b/src/alias/id/nonrecordable/NonRecordableEditor.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +package alias.id.nonrecordable; + +import javax.swing.JTextArea; + +import net.miginfocom.swing.MigLayout; +import alias.AliasID; +import alias.ComponentEditor; + +public class NonRecordableEditor extends ComponentEditor +{ + private static final long serialVersionUID = 1L; + + private static final String HELP_TEXT = "This identifies an alias as " + + "non-recordable. The alias can still be monitored but it will " + + "not be recorded when recording is enabled for the decoding channel."; + + public NonRecordableEditor( AliasID aliasID ) + { + super( aliasID ); + + initGUI(); + + setComponent( aliasID ); + } + + private void initGUI() + { + setLayout( new MigLayout( "fill,wrap 1", "[]", "[][grow]" ) ); + + JTextArea helpText = new JTextArea( HELP_TEXT ); + helpText.setLineWrap( true ); + helpText.setBackground( getBackground() ); + add( helpText, "span,grow,push" ); + } + + @Override + public void setComponent( AliasID aliasID ) + { + } + + @Override + public void save() + { + } +} diff --git a/src/alias/record/NonRecordableNode.java b/src/alias/id/nonrecordable/NonRecordableNode.java similarity index 97% rename from src/alias/record/NonRecordableNode.java rename to src/alias/id/nonrecordable/NonRecordableNode.java index 082238df..2a9a2fa4 100644 --- a/src/alias/record/NonRecordableNode.java +++ b/src/alias/id/nonrecordable/NonRecordableNode.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see ******************************************************************************/ -package alias.record; +package alias.id.nonrecordable; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -42,7 +42,7 @@ public class NonRecordableNode extends AliasIDNode @Override public JPanel getEditor() { - return new NonRecordableEditor( this ); + return null; } @Override diff --git a/src/alias/priority/Priority.java b/src/alias/id/priority/Priority.java similarity index 98% rename from src/alias/priority/Priority.java rename to src/alias/id/priority/Priority.java index 6a9aa177..d15a75f0 100644 --- a/src/alias/priority/Priority.java +++ b/src/alias/id/priority/Priority.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see ******************************************************************************/ -package alias.priority; +package alias.id.priority; import javax.xml.bind.annotation.XmlAttribute; diff --git a/src/alias/id/priority/PriorityEditor.java b/src/alias/id/priority/PriorityEditor.java new file mode 100644 index 00000000..ccdbb36a --- /dev/null +++ b/src/alias/id/priority/PriorityEditor.java @@ -0,0 +1,137 @@ +/******************************************************************************* + * 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 + ******************************************************************************/ +package alias.id.priority; + +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JSlider; +import javax.swing.JTextArea; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; + +import net.miginfocom.swing.MigLayout; +import alias.AliasID; +import alias.ComponentEditor; + +public class PriorityEditor extends ComponentEditor +{ + private static final long serialVersionUID = 1L; + + public static final String DO_NOT_MONITOR = "Do Not Monitor"; + + private static final String HELP_TEXT = "Priority determines which calls" + + " have priority for playback over your computer speakers, or designates" + + " an alias for non-monitoring if you don't want to hear calls" + + " from an alias. Lower values indicate higher priority levels."; + + private JCheckBox mDoNotMonitorCheckBox = new JCheckBox( DO_NOT_MONITOR ); + private JSlider mPrioritySlider; + private JLabel mPrioritySliderLabel; + + public PriorityEditor( AliasID aliasID ) + { + super( aliasID ); + + initGUI(); + + setComponent( aliasID ); + } + + private void initGUI() + { + setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][grow]" ) ); + + add( mDoNotMonitorCheckBox, "span,align center" ); + + mPrioritySlider = new JSlider( JSlider.HORIZONTAL, + Priority.MIN_PRIORITY, + Priority.MAX_PRIORITY, + 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 ) + { + mPrioritySliderLabel.setText( "Priority: " + mPrioritySlider.getValue() ); + } + } ); + + mPrioritySliderLabel = new JLabel( "Priority: " + mPrioritySlider.getValue() + " " ); + add( mPrioritySliderLabel ); + add( mPrioritySlider, "wrap,grow" ); + + JTextArea helpText = new JTextArea( HELP_TEXT ); + helpText.setLineWrap( true ); + helpText.setBackground( getBackground() ); + add( helpText, "span,grow,push" ); + } + + public Priority getPriority() + { + if( getComponent() instanceof Priority ) + { + return (Priority)getComponent(); + } + + return null; + } + + @Override + public void setComponent( AliasID aliasID ) + { + mComponent = aliasID; + + Priority priority = getPriority(); + + if( priority != null ) + { + mPrioritySlider.setValue( priority.getPriority() ); + mDoNotMonitorCheckBox.setSelected( priority.isDoNotMonitor() ); + } + + setModified( false ); + + repaint(); + } + + @Override + public void save() + { + Priority priority = getPriority(); + + if( priority != null ) + { + if( mDoNotMonitorCheckBox.isSelected() ) + { + priority.setPriority( Priority.DO_NOT_MONITOR ); + } + else + { + priority.setPriority( mPrioritySlider.getValue() ); + } + } + + setModified( false ); + } +} diff --git a/src/alias/priority/PriorityNode.java b/src/alias/id/priority/PriorityNode.java similarity index 97% rename from src/alias/priority/PriorityNode.java rename to src/alias/id/priority/PriorityNode.java index 707ae0f7..2a448d48 100644 --- a/src/alias/priority/PriorityNode.java +++ b/src/alias/id/priority/PriorityNode.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see ******************************************************************************/ -package alias.priority; +package alias.id.priority; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -41,7 +41,7 @@ public class PriorityNode extends AliasIDNode @Override public JPanel getEditor() { - return new PriorityEditor( this ); + return null; } public Priority getPriority() diff --git a/src/alias/id/siteID/SiteIDEditor.java b/src/alias/id/siteID/SiteIDEditor.java index 526e89c2..a352fd94 100644 --- a/src/alias/id/siteID/SiteIDEditor.java +++ b/src/alias/id/siteID/SiteIDEditor.java @@ -1,6 +1,6 @@ /******************************************************************************* * SDR Trunk - * Copyright (C) 2014 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 @@ -17,95 +17,86 @@ ******************************************************************************/ package alias.id.siteID; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; import net.miginfocom.swing.MigLayout; +import alias.AliasID; +import alias.ComponentEditor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SiteIDEditor extends JPanel implements ActionListener +public class SiteIDEditor extends ComponentEditor { private static final long serialVersionUID = 1L; - private final static Logger mLog = - LoggerFactory.getLogger( SiteIDEditor.class ); - private SiteIDNode mSiteIDNode; - private JTextField mTextSiteID; - public SiteIDEditor( SiteIDNode siteIDNode ) + private static final String HELP_TEXT = "Site number for P25 systems uses" + + " the format RR-SS, where RR = RF Subsystem and SS = Site Number. " + + " (e.g. RFSS 1 Site 3: 01-03). For other protocols, simply use" + + " a decimal value for the site ID"; + + private JTextField mTextField; + + public SiteIDEditor( AliasID aliasID ) { - mSiteIDNode = siteIDNode; + super( aliasID ); initGUI(); + + setComponent( aliasID ); } private void initGUI() { - setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][][grow]" ) ); + setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][grow]" ) ); - add( new JLabel( "Site ID" ), "span,align center" ); + add( new JLabel( "Site ID:" ) ); + mTextField = new JTextField(); + mTextField.getDocument().addDocumentListener( this ); + add( mTextField, "growx,push" ); - add( new JLabel( "Site:" ) ); + JTextArea helpText = new JTextArea( HELP_TEXT ); + helpText.setLineWrap( true ); + helpText.setBackground( getBackground() ); + add( helpText, "span,grow,push" ); + } + + public SiteID getSiteID() + { + if( getComponent() instanceof SiteID ) + { + return (SiteID)getComponent(); + } - mTextSiteID = new JTextField( - String.valueOf( mSiteIDNode.getSiteID().getSite() ) ); - add( mTextSiteID, "growx,push" ); - - JTextArea description = new JTextArea( "Enter a site number. " - + "For P25 systems, use the format RR-SS, where RR = RF " - + "Subsystem and SS = Site Number. For example, RFSS 1 and " - + "Site 3 would be: 01-03"); - - description.setLineWrap( true ); - description.setBackground( getBackground() ); - - add( description, "growx,span" ); - - JButton btnSave = new JButton( "Save" ); - btnSave.addActionListener( SiteIDEditor.this ); - add( btnSave, "growx,push" ); - - JButton btnReset = new JButton( "Reset" ); - btnReset.addActionListener( SiteIDEditor.this ); - add( btnReset, "growx,push" ); + return null; } @Override - public void actionPerformed( ActionEvent e ) - { - String command = e.getActionCommand(); + public void setComponent( AliasID aliasID ) + { + mComponent = aliasID; - if( command.contentEquals( "Save" ) ) + SiteID siteID = getSiteID(); + + if( siteID != null ) { - String siteIDString = mTextSiteID.getText(); - - if( siteIDString != null ) - { - mSiteIDNode.getSiteID().setSite( siteIDString ); + mTextField.setText( siteID.getSite() ); + } + + setModified( false ); + + repaint(); + } - mSiteIDNode.save(); - - mSiteIDNode.show(); - } - else - { - JOptionPane.showMessageDialog( SiteIDEditor.this, - "Please enter a site ID" ); - } - } - else if( command.contentEquals( "Reset" ) ) + @Override + public void save() + { + SiteID siteID = getSiteID(); + + if( siteID != null ) { - mTextSiteID.setText( mSiteIDNode.getSiteID().getSite() ); + siteID.setSite( mTextField.getText() ); } - mSiteIDNode.refresh(); - } + setModified( false ); + } } diff --git a/src/alias/id/siteID/SiteIDNode.java b/src/alias/id/siteID/SiteIDNode.java index e9e2a4b4..52cc308b 100644 --- a/src/alias/id/siteID/SiteIDNode.java +++ b/src/alias/id/siteID/SiteIDNode.java @@ -41,7 +41,7 @@ public class SiteIDNode extends AliasIDNode @Override public JPanel getEditor() { - return new SiteIDEditor( this ); + return null; } public SiteID getSiteID() diff --git a/src/alias/id/fleetsync/StatusID.java b/src/alias/id/status/StatusID.java similarity index 98% rename from src/alias/id/fleetsync/StatusID.java rename to src/alias/id/status/StatusID.java index bbcd694c..40ae82b8 100644 --- a/src/alias/id/fleetsync/StatusID.java +++ b/src/alias/id/status/StatusID.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see ******************************************************************************/ -package alias.id.fleetsync; +package alias.id.status; import javax.xml.bind.annotation.XmlAttribute; diff --git a/src/alias/id/status/StatusIDEditor.java b/src/alias/id/status/StatusIDEditor.java new file mode 100644 index 00000000..d0575e2c --- /dev/null +++ b/src/alias/id/status/StatusIDEditor.java @@ -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 + ******************************************************************************/ +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 +{ + 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 ); + } +} diff --git a/src/alias/id/fleetsync/StatusIDNode.java b/src/alias/id/status/StatusIDNode.java similarity index 97% rename from src/alias/id/fleetsync/StatusIDNode.java rename to src/alias/id/status/StatusIDNode.java index 49aaeb83..19586a5f 100644 --- a/src/alias/id/fleetsync/StatusIDNode.java +++ b/src/alias/id/status/StatusIDNode.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see ******************************************************************************/ -package alias.id.fleetsync; +package alias.id.status; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -41,7 +41,7 @@ public class StatusIDNode extends AliasIDNode @Override public JPanel getEditor() { - return new StatusIDEditor( this ); + return null; } public StatusID getStatusID() diff --git a/src/alias/id/talkgroup/TalkgroupIDEditor.java b/src/alias/id/talkgroup/TalkgroupIDEditor.java index 1feda866..4bae20ac 100644 --- a/src/alias/id/talkgroup/TalkgroupIDEditor.java +++ b/src/alias/id/talkgroup/TalkgroupIDEditor.java @@ -17,99 +17,87 @@ ******************************************************************************/ package alias.id.talkgroup; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; import net.miginfocom.swing.MigLayout; -import controller.ConfigurableNode; +import alias.AliasID; +import alias.ComponentEditor; -public class TalkgroupIDEditor extends JPanel implements ActionListener +public class TalkgroupIDEditor extends ComponentEditor { private static final long serialVersionUID = 1L; - private TalkgroupIDNode mTalkgroupIDNode; - - private JTextField mTextTalkgroupID; - - private String mHelpText = "Enter a formatted talkgroup identifier.\n\n" - + "P25 Talkgroup Format: hexadecimal value, 4 characters for " - + "talkgroup or 6 characters for a mobile radio\n\n" - + "LTR Talkgroup Format: A-HH-TTT (A=Area, H=Home Repeater, " - + "T=Talkgroup)\n\n" - + "Passport Talkgroup Format: xxxxx (up to 5-digit number)\n\n" - + "Wildcard: use one or more asterisks (*) for any talkgroup digits."; - public TalkgroupIDEditor( TalkgroupIDNode talkgroupIDNode ) + private static final String HELP_TEXT = "Enter a formatted talkgroup identifier.\n" + + "P25: 4 or 6 hex characters (e.g. AB12 or ABC123)\n" + + "LTR: A-HH-TTT (A=Area H=Home T=Talkgroup)\n" + + "Passport: xxxxx (up to 5-digit number)\n\n" + + "Wildcard: use an asterisk (*) in place of each talkgroup digit"; + + private JTextField mTextField; + + public TalkgroupIDEditor( AliasID aliasID ) { - mTalkgroupIDNode = talkgroupIDNode; + super( aliasID ); initGUI(); + + setComponent( aliasID ); } private void initGUI() { - setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][][grow]" ) ); - - add( new JLabel( "Talkgroup ID" ), "span,align center" ); - - add( new JLabel( "TGID:" ) ); - mTextTalkgroupID = new JTextField(); + setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][grow]" ) ); - mTextTalkgroupID.setText( mTalkgroupIDNode.getTalkgroupID().getTalkgroup() ); + add( new JLabel( "Talkgroup:" ) ); + mTextField = new JTextField(); + mTextField.getDocument().addDocumentListener( this ); + add( mTextField, "growx,push" ); - add( mTextTalkgroupID, "growx,push" ); - - JButton btnSave = new JButton( "Save" ); - btnSave.addActionListener( TalkgroupIDEditor.this ); - add( btnSave, "growx,push" ); - - JButton btnReset = new JButton( "Reset" ); - btnReset.addActionListener( TalkgroupIDEditor.this ); - add( btnReset, "growx,push" ); - - JTextArea helpText = new JTextArea( mHelpText ); - helpText.setBackground( getBackground() ); + JTextArea helpText = new JTextArea( HELP_TEXT ); helpText.setLineWrap( true ); + helpText.setBackground( getBackground() ); add( helpText, "span,grow,push" ); } + + public TalkgroupID getTalkgroupID() + { + if( getComponent() instanceof TalkgroupID ) + { + return (TalkgroupID)getComponent(); + } + + return null; + } @Override - public void actionPerformed( ActionEvent e ) - { - String command = e.getActionCommand(); + public void setComponent( AliasID aliasID ) + { + mComponent = aliasID; - if( command.contentEquals( "Save" ) ) + TalkgroupID talkgroup = getTalkgroupID(); + + if( talkgroup != null ) { - String tgid = mTextTalkgroupID.getText(); - - if( tgid != null ) - { - mTalkgroupIDNode.getTalkgroupID().setTalkgroup( tgid ); - - ((ConfigurableNode)mTalkgroupIDNode.getParent()).sort(); + mTextField.setText( talkgroup.getTalkgroup() ); + } + + setModified( false ); + + repaint(); + } - mTalkgroupIDNode.save(); - - mTalkgroupIDNode.show(); - } - else - { - JOptionPane.showMessageDialog( TalkgroupIDEditor.this, - "Please enter a talkgroup ID" ); - } - } - else if( command.contentEquals( "Reset" ) ) + @Override + public void save() + { + TalkgroupID talkgroup = getTalkgroupID(); + + if( talkgroup != null ) { - mTextTalkgroupID.setText( - mTalkgroupIDNode.getTalkgroupID().getTalkgroup() ); + talkgroup.setTalkgroup( mTextField.getText() ); } - mTalkgroupIDNode.refresh(); - } + setModified( false ); + } } diff --git a/src/alias/id/talkgroup/TalkgroupIDNode.java b/src/alias/id/talkgroup/TalkgroupIDNode.java index 261adc75..1a11cd08 100644 --- a/src/alias/id/talkgroup/TalkgroupIDNode.java +++ b/src/alias/id/talkgroup/TalkgroupIDNode.java @@ -41,7 +41,7 @@ public class TalkgroupIDNode extends AliasIDNode @Override public JPanel getEditor() { - return new TalkgroupIDEditor( this ); + return null; } public TalkgroupID getTalkgroupID() diff --git a/src/alias/id/uniqueID/UniqueIDEditor.java b/src/alias/id/uniqueID/UniqueIDEditor.java index 7b46f176..349f66b6 100644 --- a/src/alias/id/uniqueID/UniqueIDEditor.java +++ b/src/alias/id/uniqueID/UniqueIDEditor.java @@ -1,6 +1,6 @@ /******************************************************************************* * SDR Trunk - * Copyright (C) 2014 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 @@ -17,101 +17,95 @@ ******************************************************************************/ package alias.id.uniqueID; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; +import javax.swing.JTextArea; import javax.swing.JTextField; import net.miginfocom.swing.MigLayout; +import alias.AliasID; +import alias.ComponentEditor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import controller.ConfigurableNode; - -public class UniqueIDEditor extends JPanel implements ActionListener +public class UniqueIDEditor extends ComponentEditor { private static final long serialVersionUID = 1L; - private final static Logger mLog = - LoggerFactory.getLogger( UniqueIDEditor.class ); - private UniqueIDNode mUniqueIDNode; - - private JLabel mLabelUniqueID; - private JTextField mTextUniqueID; - public UniqueIDEditor( UniqueIDNode uniqueIDNode ) + private static final String HELP_TEXT = "LTR-Net Unique ID (UID) is a system" + + " identifier assigned to each radio in the range 1 - 2097152"; + + private JTextField mTextField; + + public UniqueIDEditor( AliasID aliasID ) { - mUniqueIDNode = uniqueIDNode; + super( aliasID ); initGUI(); + + setComponent( aliasID ); } private void initGUI() { - setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][grow]" ) ); - - add( new JLabel( "LTR-Net Radio Unique ID" ), "span,align center" ); + setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][grow]" ) ); add( new JLabel( "Unique ID:" ) ); - - mTextUniqueID = new JTextField( - String.valueOf( mUniqueIDNode.getUniqueID().getUid() ) ); - add( mTextUniqueID, "growx,push" ); - - JButton btnSave = new JButton( "Save" ); - btnSave.addActionListener( UniqueIDEditor.this ); - add( btnSave, "growx,push" ); + mTextField = new JTextField(); + mTextField.getDocument().addDocumentListener( this ); + add( mTextField, "growx,push" ); - JButton btnReset = new JButton( "Reset" ); - btnReset.addActionListener( UniqueIDEditor.this ); - add( btnReset, "growx,push" ); + JTextArea helpText = new JTextArea( HELP_TEXT ); + helpText.setLineWrap( true ); + helpText.setBackground( getBackground() ); + add( helpText, "span,grow,push" ); + } + + public UniqueID getUniqueID() + { + if( getComponent() instanceof UniqueID ) + { + return (UniqueID)getComponent(); + } + + return null; } @Override - public void actionPerformed( ActionEvent e ) - { - String command = e.getActionCommand(); + public void setComponent( AliasID aliasID ) + { + mComponent = aliasID; - if( command.contentEquals( "Save" ) ) + UniqueID uid = getUniqueID(); + + if( uid != null ) { - String uid = mTextUniqueID.getText(); + mTextField.setText( String.valueOf( uid.getUid() ) ); + } + + setModified( false ); + + repaint(); + } + + @Override + public void save() + { + UniqueID uid = getUniqueID(); + + if( uid != null ) + { + int id = 0; - if( uid != null ) + try { - try - { - int uidInt = Integer.parseInt( uid ); - - mUniqueIDNode.getUniqueID().setUid( uidInt ); - - ((ConfigurableNode)mUniqueIDNode.getParent()).sort(); - - mUniqueIDNode.save(); - - mUniqueIDNode.show(); - } - catch( Exception ex ) - { - mLog.error( "UniqueIDEditor - exception trying to parse " + - "int from uid [" + uid + "]", ex ); - } + id = Integer.parseInt( mTextField.getText() ); } - else + catch( Exception e ) { - JOptionPane.showMessageDialog( UniqueIDEditor.this, - "Please enter a site number and unique ID" ); + //Do nothing, we couldn't parse the value } - } - else if( command.contentEquals( "Reset" ) ) - { - mTextUniqueID.setText( - String.valueOf( mUniqueIDNode.getUniqueID().getUid() ) ); + + uid.setUid( id ); } - mUniqueIDNode.refresh(); - } + setModified( false ); + } } diff --git a/src/alias/id/uniqueID/UniqueIDNode.java b/src/alias/id/uniqueID/UniqueIDNode.java index ebb92f4f..bdf43be9 100644 --- a/src/alias/id/uniqueID/UniqueIDNode.java +++ b/src/alias/id/uniqueID/UniqueIDNode.java @@ -41,7 +41,7 @@ public class UniqueIDNode extends AliasIDNode @Override public JPanel getEditor() { - return new UniqueIDEditor( this ); + return null; } public UniqueID getUniqueID() diff --git a/src/alias/priority/PriorityEditor.java b/src/alias/priority/PriorityEditor.java deleted file mode 100644 index 1028ae74..00000000 --- a/src/alias/priority/PriorityEditor.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * SDR Trunk - * Copyright (C) 2015 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 - ******************************************************************************/ -package alias.priority; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JSlider; -import javax.swing.JTextArea; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -import net.miginfocom.swing.MigLayout; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import controller.ConfigurableNode; - -public class PriorityEditor extends JPanel implements ActionListener -{ - private final static Logger mLog = LoggerFactory.getLogger( PriorityEditor.class ); - - public static final String DO_NOT_MONITOR = "Do Not Monitor"; - public static final String SAVE = "Save"; - public static final String RESET = "Reset"; - - private static final long serialVersionUID = 1L; - private PriorityNode mPriorityNode; - private JCheckBox mDoNotMonitorCheckBox = new JCheckBox( DO_NOT_MONITOR ); - private JSlider mPrioritySlider; - private JLabel mPrioritySliderLabel; - - public PriorityEditor( PriorityNode priorityNode ) - { - mPriorityNode = priorityNode; - - initGUI(); - } - - private void initGUI() - { - setLayout( new MigLayout( "fill,wrap 2", "[right][left]", "[][][][grow]" ) ); - - add( new JLabel( "Priority" ), "span,align center" ); - - boolean doNotMonitor = mPriorityNode.getPriority().isDoNotMonitor(); - - mDoNotMonitorCheckBox.addActionListener( this ); - - if( doNotMonitor ) - { - mDoNotMonitorCheckBox.setSelected( true ); - } - - add( mDoNotMonitorCheckBox, "span,align center" ); - - int priority = mPriorityNode.getPriority().getPriority(); - - /* Adjust the displayable priority value to within the min/max bounds - * so we don't get an error in the jslider control. If the actual - * priority is -1 (ie do not follow), the controls will be updated - * to reflect that state */ - if( priority < Priority.MIN_PRIORITY ) - { - priority = Priority.DEFAULT_PRIORITY; - } - else if( priority > Priority.MAX_PRIORITY ) - { - priority = Priority.DEFAULT_PRIORITY; - } - - mPrioritySlider = new JSlider( JSlider.HORIZONTAL, - Priority.MIN_PRIORITY, - Priority.MAX_PRIORITY, - priority ); - - mPrioritySlider.setMajorTickSpacing( 20 ); - mPrioritySlider.setMinorTickSpacing( 5 ); - mPrioritySlider.setPaintTicks( true ); - - mPrioritySlider.setLabelTable( mPrioritySlider.createStandardLabels( 20, 20 ) ); - mPrioritySlider.setPaintLabels( true ); - - mPrioritySliderLabel = new JLabel( "Priority: " + mPrioritySlider.getValue() + " " ); - - mPrioritySlider.addChangeListener( new ChangeListener() - { - @Override - public void stateChanged( ChangeEvent e ) - { - mPrioritySliderLabel.setText( "Priority: " + mPrioritySlider.getValue() ); - } - } ); - - if( doNotMonitor ) - { - mPrioritySlider.setEnabled( false ); - mPrioritySliderLabel.setEnabled( false ); - } - - add( mPrioritySliderLabel ); - add( mPrioritySlider, "wrap,grow" ); - - JButton btnSave = new JButton( SAVE ); - btnSave.addActionListener( PriorityEditor.this ); - add( btnSave, "growx,push" ); - - JButton btnReset = new JButton( RESET ); - btnReset.addActionListener( PriorityEditor.this ); - add( btnReset, "growx,push" ); - - StringBuilder sb = new StringBuilder(); - sb.append( "Select a value for audio priority within the range " ); - sb.append( Priority.MIN_PRIORITY ); - sb.append( " and " ); - sb.append( Priority.MAX_PRIORITY ); - sb.append( ". Lower values indicate higher priority levels." ); - - JTextArea helpText = new JTextArea( sb.toString() ); - helpText.setLineWrap( true ); - add( helpText, "span,grow,push" ); - } - - @Override - public void actionPerformed( ActionEvent e ) - { - String command = e.getActionCommand(); - - if( command.contentEquals( SAVE ) ) - { - if( mDoNotMonitorCheckBox.isSelected() ) - { - mPriorityNode.getPriority().setPriority( Priority.DO_NOT_MONITOR ); - } - else - { - mPriorityNode.getPriority().setPriority( mPrioritySlider.getValue() ); - } - - ((ConfigurableNode)mPriorityNode.getParent()).sort(); - - mPriorityNode.save(); - - mPriorityNode.show(); - } - else if( command.contentEquals( RESET ) ) - { - mPrioritySlider.setValue( mPriorityNode.getPriority().getPriority() ); - } - else if( command.contentEquals( DO_NOT_MONITOR ) ) - { - if( mDoNotMonitorCheckBox.isSelected() ) - { - mPriorityNode.getPriority().setPriority( Priority.DO_NOT_MONITOR ); - mPrioritySlider.setEnabled( false ); - mPrioritySliderLabel.setEnabled( false ); - } - else - { - mPriorityNode.getPriority().setPriority( Priority.DEFAULT_PRIORITY ); - mPrioritySlider.setEnabled( true ); - mPrioritySliderLabel.setEnabled( true ); - } - - mPriorityNode.save(); - mPriorityNode.show(); - } - - mPriorityNode.refresh(); - } -} diff --git a/src/alias/record/NonRecordableEditor.java b/src/alias/record/NonRecordableEditor.java deleted file mode 100644 index e9ab06e3..00000000 --- a/src/alias/record/NonRecordableEditor.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * 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 - ******************************************************************************/ -package alias.record; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; -import javax.swing.JPanel; -import javax.swing.JTextArea; - -import net.miginfocom.swing.MigLayout; - -public class NonRecordableEditor extends JPanel implements ActionListener -{ - private static final long serialVersionUID = 1L; - - private NonRecordableNode mNode; - - public NonRecordableEditor( NonRecordableNode node ) - { - mNode = node; - initGUI(); - } - - private void initGUI() - { - setLayout( new MigLayout( "fill", "[left]", "[grow]" ) ); - - JTextArea description = new JTextArea( "Non-Recordable. Any audio where" - + " this alias is a participant in the call will not be recorded." ); - - description.setLineWrap( true ); - description.setBackground( getBackground() ); - - add( description, "growx,span" ); - - JButton btnSave = new JButton( "Save" ); - btnSave.addActionListener( NonRecordableEditor.this ); - add( btnSave, "growx,push" ); - - JButton btnReset = new JButton( "Reset" ); - btnReset.addActionListener( NonRecordableEditor.this ); - add( btnReset, "growx,push" ); - } - - @Override - public void actionPerformed( ActionEvent e ) - { - String command = e.getActionCommand(); - - if( command.contentEquals( "Save" ) ) - { - mNode.save(); - mNode.show(); - } - - mNode.refresh(); - } -} diff --git a/src/audio/metadata/AudioMetadata.java b/src/audio/metadata/AudioMetadata.java index ad498288..d4b8cae0 100644 --- a/src/audio/metadata/AudioMetadata.java +++ b/src/audio/metadata/AudioMetadata.java @@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory; import sample.Listener; import alias.Alias; -import alias.priority.Priority; +import alias.id.priority.Priority; public class AudioMetadata implements Listener { diff --git a/src/module/decode/state/TrafficChannelManager.java b/src/module/decode/state/TrafficChannelManager.java index 5455d7d5..ff4eae65 100644 --- a/src/module/decode/state/TrafficChannelManager.java +++ b/src/module/decode/state/TrafficChannelManager.java @@ -22,7 +22,7 @@ import source.config.SourceConfigTuner; import source.tuner.TunerChannel; import source.tuner.TunerChannel.Type; import alias.Alias; -import alias.priority.Priority; +import alias.id.priority.Priority; import controller.channel.Channel; import controller.channel.Channel.ChannelType; import controller.channel.ChannelEvent;