001package jmri.jmrit.vsdecoder.swing;
002
003import javax.swing.BoxLayout;
004import javax.swing.JButton;
005import javax.swing.JComboBox;
006import javax.swing.JDialog;
007import javax.swing.JLabel;
008import javax.swing.JPanel;
009import javax.swing.SwingUtilities;
010import jmri.InstanceManager;
011import jmri.jmrit.operations.trains.Train;
012import jmri.jmrit.operations.trains.TrainManager;
013
014/**
015 * Options dialog to add a Train to a VSDecoder.
016 *
017 * <hr>
018 * This file is part of JMRI.
019 * <p>
020 * JMRI is free software; you can redistribute it and/or modify it under
021 * the terms of version 2 of the GNU General Public License as published
022 * by the Free Software Foundation. See the "COPYING" file for a copy
023 * of this license.
024 * <p>
025 * JMRI is distributed in the hope that it will be useful, but WITHOUT
026 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
027 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
028 * for more details.
029 *
030 * @author Mark Underwood Copyright (C) 2011
031 */
032public class VSDOptionsDialog extends JDialog {
033
034    public static final String OPTIONS_PROPERTY = "Options"; // NOI18N
035
036    private JComboBox<Train> opsTrainComboBox;
037
038    public VSDOptionsDialog(JPanel parent, String title) {
039        super(SwingUtilities.getWindowAncestor(parent), title);
040        initComponents();
041        setLocationRelativeTo(parent);
042    }
043
044    public void initComponents() {
045        this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.PAGE_AXIS));
046
047        JLabel x = new JLabel();
048        x.setText(Bundle.getMessage("FieldSelectTrain"));
049        this.add(x);
050        opsTrainComboBox = InstanceManager.getDefault(TrainManager.class).getTrainComboBox();
051        this.add(opsTrainComboBox);
052
053        JButton closeButton = new JButton(Bundle.getMessage("ButtonOK"));
054        closeButton.setEnabled(true);
055        closeButton.setToolTipText(Bundle.getMessage("ToolTipCloseDialog"));
056        closeButton.addActionListener(new java.awt.event.ActionListener() {
057            @Override
058            public void actionPerformed(java.awt.event.ActionEvent e) {
059                closeButtonActionPerformed(e);
060            }
061        });
062        this.add(closeButton);
063        this.pack();
064        this.setVisible(true);
065    }
066
067    private void closeButtonActionPerformed(java.awt.event.ActionEvent ae) {
068        if (opsTrainComboBox.getSelectedItem() != null) {
069            firePropertyChange(OPTIONS_PROPERTY, null, opsTrainComboBox.getSelectedItem().toString());
070        }
071        dispose();
072    }
073
074}