From 277a84702ae2a8de27c47412ea3e0cceb68c3c96 Mon Sep 17 00:00:00 2001 From: Denny Sheirer Date: Sat, 28 Mar 2020 15:52:39 +0000 Subject: [PATCH] Resolves #580 channel map selection and editing (#711) Co-authored-by: Denny --- .../decode/mpt1327/MPT1327DecoderEditor.java | 47 ++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/dsheirer/module/decode/mpt1327/MPT1327DecoderEditor.java b/src/main/java/io/github/dsheirer/module/decode/mpt1327/MPT1327DecoderEditor.java index b58c3897..49a935f6 100644 --- a/src/main/java/io/github/dsheirer/module/decode/mpt1327/MPT1327DecoderEditor.java +++ b/src/main/java/io/github/dsheirer/module/decode/mpt1327/MPT1327DecoderEditor.java @@ -30,6 +30,8 @@ import io.github.dsheirer.gui.editor.EditorValidationException; import io.github.dsheirer.gui.editor.ValidatingEditor; import io.github.dsheirer.module.decode.config.DecodeConfiguration; import net.miginfocom.swing.MigLayout; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; @@ -41,10 +43,13 @@ import javax.swing.event.ChangeListener; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.util.List; public class MPT1327DecoderEditor extends ValidatingEditor { + private final static Logger mLog = LoggerFactory.getLogger(MPT1327DecoderEditor.class); private static final long serialVersionUID = 1L; private JComboBox mComboChannelMaps; @@ -65,12 +70,17 @@ public class MPT1327DecoderEditor extends ValidatingEditor { setLayout(new MigLayout("insets 0 0 0 0,wrap 4", "[right][grow,fill][right][grow,fill]", "")); - List maps = mChannelMapModel.getChannelMaps(); - ChannelMap[] mapArray = maps.toArray(new ChannelMap[maps.size()]); - mComboChannelMaps = new JComboBox(); - mComboChannelMaps.setModel(new DefaultComboBoxModel(mapArray)); + refreshChannelMaps(); mComboChannelMaps.setEnabled(false); + mComboChannelMaps.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + setModified(true); + } + }); add(new JLabel("Channel Map:")); add(mComboChannelMaps); @@ -80,8 +90,17 @@ public class MPT1327DecoderEditor extends ValidatingEditor @Override public void actionPerformed(ActionEvent e) { - final ChannelMapManagerFrame manager = - new ChannelMapManagerFrame(mChannelMapModel); + final ChannelMapManagerFrame manager = new ChannelMapManagerFrame(mChannelMapModel); + manager.addWindowListener(new WindowAdapter() + { + @Override + public void windowClosed(WindowEvent e) + { + super.windowClosed(e); + mLog.debug("Refreshing channel maps combo box"); + refreshChannelMaps(); + } + }); EventQueue.invokeLater(new Runnable() { @@ -139,6 +158,22 @@ public class MPT1327DecoderEditor extends ValidatingEditor add(mCallTimeout); } + private void refreshChannelMaps() + { + List maps = mChannelMapModel.getChannelMaps(); + + ChannelMap[] mapArray = new ChannelMap[maps.size() + 1]; + + int index = 1; + + for(ChannelMap channelMap: maps) + { + mapArray[index++] = channelMap; + } + + mComboChannelMaps.setModel(new DefaultComboBoxModel(mapArray)); + } + @Override public void save() {