001package jmri.jmrit.entryexit; 002 003import java.awt.BorderLayout; 004import java.awt.event.ActionEvent; 005import java.awt.event.ActionListener; 006import java.util.Hashtable; 007 008import javax.swing.BoxLayout; 009import javax.swing.DefaultListModel; 010import javax.swing.JButton; 011import javax.swing.JList; 012import javax.swing.JPanel; 013import javax.swing.JScrollPane; 014 015import jmri.util.swing.JmriJOptionPane; 016 017public class StackNXPanel extends JPanel { 018 019 transient EntryExitPairs manager = jmri.InstanceManager.getDefault(jmri.jmrit.entryexit.EntryExitPairs.class); 020 021 private JPanel entryExitPanel; 022 023 private DefaultListModel<String> listModel; 024 private JList<String> list = new JList<String>(); 025 JScrollPane listScrollPane = new JScrollPane(list); 026 027 public StackNXPanel() { 028 super(); 029 initGUI(); 030 } 031 032 private void initGUI() { 033 listModel = new DefaultListModel<String>(); 034 setLayout(new BorderLayout()); 035 entryExitPanel = new JPanel(); 036 entryExitPanel.setDoubleBuffered(true); 037 entryExitPanel.setLayout(new BoxLayout(entryExitPanel, BoxLayout.Y_AXIS)); 038 entryExitPanel.add(listScrollPane); 039 JButton cancelButton = new JButton(Bundle.getMessage("ButtonCancel")); // NOI18N 040 cancelButton.addActionListener(new ActionListener() { 041 @Override 042 public void actionPerformed(ActionEvent e) { 043 //This method can be called only if 044 //there's a valid selection 045 //so go ahead and remove whatever's selected. 046 if (list.getSelectedValue() != null) { 047 // basic check to see if anything was selected 048 manager.cancelStackedRoute(listToDest.get(list.getSelectedValue()), false); 049 } else { 050 JmriJOptionPane.showMessageDialog(entryExitPanel, 051 Bundle.getMessage("Error1", Bundle.getMessage("ButtonCancel")), 052 Bundle.getMessage("WarningTitle"), JmriJOptionPane.WARNING_MESSAGE); 053 // Keep Panel open 054 } 055 } 056 057 }); 058 add(cancelButton, BorderLayout.SOUTH); 059 add(entryExitPanel, BorderLayout.CENTER); 060 061 updateGUI(); 062 } 063 064 Hashtable<String, DestinationPoints> listToDest = new Hashtable<String, DestinationPoints>(); 065 066 public void updateGUI() { 067 listModel.clear(); 068 listToDest = new Hashtable<String, DestinationPoints>(); 069 for (DestinationPoints dp : manager.getStackedInterlocks()) { 070 listToDest.put(dp.getDisplayName(), dp); 071 listModel.addElement(dp.getDisplayName()); 072 } 073 list.setModel(listModel); 074 list.setVisibleRowCount(10); 075 } 076}