001package jmri.jmrix.swing;
002
003import javax.swing.BorderFactory;
004import javax.swing.Box;
005import javax.swing.BoxLayout;
006import javax.swing.JButton;
007import javax.swing.JComboBox;
008import javax.swing.JLabel;
009import javax.swing.JPanel;
010
011/**
012 * Frame for user input of XpressNet messages
013 *
014 * @author Bob Jacobsen Copyright (C) 2001,2002
015 */
016public abstract class AbstractPacketGenFrame extends jmri.util.JmriJFrame {
017
018    // member declarations
019    protected JLabel jLabel1 = new JLabel();
020    protected JButton sendButton = new JButton();
021    protected JComboBox<String> packetTextField = new JComboBox<String>();
022
023    public AbstractPacketGenFrame() {
024        super();
025    }
026
027    /** 
028     * {@inheritDoc}
029     */
030    @Override
031    public void initComponents() {
032        // the following code sets the frame's initial state
033        setTitle("Send Packet"); // NOI18N
034
035        JPanel packetPane = new JPanel();
036        packetPane.setBorder(BorderFactory.createEtchedBorder());
037        jLabel1.setText(Bundle.getMessage("PacketLabel"));
038        packetPane.add(jLabel1);
039
040        sendButton.setText(Bundle.getMessage("SendPacketTitle"));
041        sendButton.setVisible(true);
042        sendButton.setToolTipText(Bundle.getMessage("SendToolTip"));
043
044        packetTextField.setPreferredSize(new JButton("XXXXXXXXXXXXXXXXXXXXXXXXX").getPreferredSize());
045        packetTextField.setToolTipText(Bundle.getMessage("EnterHexBytesToolTip"));
046        packetTextField.setMaximumRowCount(5); // set the maximum number of items in the history.
047        packetTextField.setEditable(true);
048        packetPane.add(packetTextField);
049  
050        getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
051        getContentPane().add(packetPane);
052        getContentPane().add(sendButton);
053        getContentPane().add(Box.createVerticalGlue());
054        
055        //set the Send Button as default for Enter press
056        this.getRootPane().setDefaultButton(sendButton);
057
058        sendButton.addActionListener(new java.awt.event.ActionListener() {
059            @Override
060            public void actionPerformed(java.awt.event.ActionEvent e) {
061                sendButtonActionPerformed(e);
062                packetTextField.addItem((String) packetTextField.getSelectedItem());
063                packetTextField.setSelectedItem("");
064            }
065        });
066
067        // pack to cause display
068        pack();
069    }
070
071    abstract public void sendButtonActionPerformed(java.awt.event.ActionEvent e);
072
073}