001package jmri.jmrit.display.layoutEditor.blockRoutingTable;
002
003import java.awt.event.ActionEvent;
004import javax.swing.AbstractAction;
005import jmri.jmrit.display.layoutEditor.LayoutBlock;
006import jmri.util.JmriJFrame;
007
008/**
009 * Swing action to create and register a Block Routing Table.
010 *
011 * @author Kevin Dickerson Copyright (C) 2011
012 */
013public class LayoutBlockRouteTableAction extends AbstractAction {
014
015    /**
016     * Create an action with a specific title.
017     * <p>
018     * Note that the argument is the Action title, not the title of the
019     * resulting frame. Perhaps this should be changed?
020     * <p>
021     * @param name the action title
022     * @param layoutBlock the layout block
023     */
024    public LayoutBlockRouteTableAction(String name, LayoutBlock layoutBlock) {
025        super(name);
026        this.layoutBlock = layoutBlock;
027    }
028
029    private LayoutBlock layoutBlock = null;
030
031    private LayoutBlockRouteTable lbrTable;
032    private JmriJFrame frame = null;
033
034    private void createModel() {
035        lbrTable = new LayoutBlockRouteTable(false, layoutBlock);
036    }
037
038    public void actionPerformed() {
039        // create the JTable model, with changes for specific NamedBean
040        createModel();
041
042        // create the frame
043        frame = new JmriJFrame();
044        frame.add(lbrTable);
045        setTitle();
046        frame.pack();
047        frame.setVisible(true);
048    }
049
050    @Override
051    public void actionPerformed(ActionEvent e) {
052        actionPerformed();
053    }
054
055    void setTitle() {
056        if (layoutBlock != null) {
057            frame.setTitle(Bundle.getMessage("BlockRoutingTableTitle") + " " + layoutBlock.getDisplayName());
058        } else {
059            frame.setTitle(Bundle.getMessage("BlockRoutingTableTitleShort"));
060        }
061    }
062
063    String helpTarget() {
064        return "package.jmri.jmrit.display.layoutEditor";
065    }
066
067}