001package jmri.jmrix.ieee802154.swing.nodeconfig; 002 003import java.awt.Container; 004import java.awt.FlowLayout; 005import java.awt.event.WindowEvent; 006import javax.swing.BoxLayout; 007import javax.swing.JLabel; 008import javax.swing.JPanel; 009import jmri.jmrix.ieee802154.IEEE802154Node; 010import jmri.jmrix.ieee802154.IEEE802154TrafficController; 011 012/** 013 * Frame for Editing Nodes 014 * 015 * @author Bob Jacobsen Copyright (C) 2004 016 * @author Dave Duchamp Copyright (C) 2004 017 * @author Paul Bender Copyright (C) 2013,2016 018 */ 019public class EditNodeFrame extends jmri.util.JmriJFrame { 020 021 protected javax.swing.JTextField nodeAddrField = new javax.swing.JTextField(); 022 protected javax.swing.JTextField nodeAddr64Field = new javax.swing.JTextField(); 023 protected javax.swing.JButton editButton = new javax.swing.JButton(Bundle.getMessage("ButtonEdit")); 024 protected javax.swing.JButton cancelButton = new javax.swing.JButton(Bundle.getMessage("ButtonCancel")); 025 026 protected javax.swing.JPanel panel = new JPanel(); 027 028 protected IEEE802154Node curNode = null; // IEEE802154 Node being editted 029 030 /** 031 * Constructor method 032 * @param tc traffic controller 033 * @param node node to edit 034 */ 035 public EditNodeFrame(IEEE802154TrafficController tc, IEEE802154Node node) { 036 super(); 037 addHelpMenu("package.jmri.jmrix.ieee802154.swing.nodeconfig.EditNodeFrame", true); 038 curNode = node; 039 } 040 041 /** 042 * Initialize the config window 043 */ 044 @Override 045 public void initComponents() { 046 setTitle(Bundle.getMessage("EditNodeWindowTitle")); 047 Container contentPane = getContentPane(); 048 contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); 049 050 // Set up node address and node type 051 JPanel panel = new JPanel(); 052 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); 053 panel.add(new JLabel(Bundle.getMessage("LabelNodeAddress") + " ")); 054 panel.add(nodeAddrField); 055 nodeAddrField.setToolTipText(Bundle.getMessage("TipNodeAddress")); 056 panel.add(new JLabel(Bundle.getMessage("LabelNodeAddress64") + " ")); 057 panel.add(nodeAddr64Field); 058 nodeAddr64Field.setToolTipText(Bundle.getMessage("TipNodeAddress64")); 059 060 initAddressBoxes(); 061 contentPane.add(panel); 062 063 // Set up buttons 064 JPanel panel4 = new JPanel(); 065 panel4.setLayout(new FlowLayout()); 066 editButton.setText(Bundle.getMessage("ButtonEdit")); 067 editButton.setVisible(true); 068 editButton.setToolTipText(Bundle.getMessage("TipEditButton")); 069 editButton.addActionListener(new java.awt.event.ActionListener() { 070 @Override 071 public void actionPerformed(java.awt.event.ActionEvent e) { 072 editButtonActionPerformed(); 073 } 074 }); 075 panel4.add(editButton); 076 panel4.add(cancelButton); 077 cancelButton.setText(Bundle.getMessage("ButtonCancel")); 078 cancelButton.setVisible(true); 079 cancelButton.setToolTipText(Bundle.getMessage("TipCancelButton")); 080 panel4.add(cancelButton); 081 cancelButton.addActionListener(new java.awt.event.ActionListener() { 082 @Override 083 public void actionPerformed(java.awt.event.ActionEvent e) { 084 cancelButtonActionPerformed(); 085 } 086 }); 087 contentPane.add(panel4); 088 089 // pack for display 090 pack(); 091 } 092 093 /** 094 * Method to handle edit button 095 */ 096 public void editButtonActionPerformed() { 097 // get node information from window 098 // all ready, update the node 099 curNode.setUserAddress(jmri.util.StringUtil.bytesFromHexString(nodeAddrField.getText())); 100 curNode.setGlobalAddress(jmri.util.StringUtil.bytesFromHexString(nodeAddr64Field.getText())); 101 this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); 102 } 103 104 /** 105 * Method to handle cancel button 106 */ 107 public void cancelButtonActionPerformed() { 108 // Reset 109 curNode = null; 110 // Switch buttons 111 editButton.setVisible(true); 112 cancelButton.setVisible(false); 113 this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); 114 } 115 116 // Initilize the text boxes for the addresses. 117 protected void initAddressBoxes() { 118 nodeAddrField.setText(jmri.util.StringUtil.hexStringFromBytes(curNode.getUserAddress())); 119 nodeAddr64Field.setText(jmri.util.StringUtil.hexStringFromBytes(curNode.getGlobalAddress())); 120 } 121 122 // private final static Logger log = LoggerFactory.getLogger(EditNodeFrame.class); 123 124}