001package jmri.jmrit.operations.rollingstock.cars.gui;
002
003import javax.swing.AbstractAction;
004import javax.swing.JMenu;
005
006import org.slf4j.Logger;
007import org.slf4j.LoggerFactory;
008
009import jmri.jmrit.operations.rollingstock.cars.tools.*;
010
011/**
012 * Provides a context-specific menu for handling the Roster.
013 *
014 * @author Bob Jacobsen Copyright (C) 2001, 2002
015 * @author Dennis Miller Copyright (C) 2005
016 * @author Daniel Boudreau Copyright (C) 2007, 2012, 2016
017 *
018 */
019public class CarRosterMenu extends JMenu {
020
021    /**
022     * Ctor argument defining that the menu object will be used as part of the
023     * main menu of the program, away from any GUI that can select or use a
024     * RosterEntry.
025     */
026    static public final int MAINMENU = 1;
027
028    /**
029     * Ctor argument defining that the menu object will be used as a menu on a
030     * GUI object that can select a RosterEntry.
031     */
032    static public final int SELECTMENU = 2;
033
034    /**
035     * Ctor argument defining that the menu object will be used as a menu on a
036     * GUI object that is dealing with a single RosterEntry.
037     */
038    static public final int ENTRYMENU = 3;
039
040    /**
041     * Create a
042     *
043     * @param pMenuName Name for the menu
044     * @param pMenuType Select where the menu will be used, hence the right set
045     *            of items to be enabled.
046     * @param carsTableFrame The Component using this menu, used to ensure that
047     *            dialog boxes will pop in the right place.
048     */
049    public CarRosterMenu(String pMenuName, int pMenuType, CarsTableFrame carsTableFrame) {
050        super(pMenuName);
051
052        // create the menu
053        AbstractAction importAction = new ImportCarRosterAction();
054        importAction.setEnabled(false);
055        AbstractAction exportAction = new ExportCarRosterAction(carsTableFrame);
056        exportAction.setEnabled(false);
057        AbstractAction deleteAction = new DeleteCarRosterAction(carsTableFrame);
058        deleteAction.setEnabled(false);
059        AbstractAction resetMovesAction = new ResetCarMovesAction(carsTableFrame);
060        resetMovesAction.setEnabled(false);
061
062        AbstractAction printAction = new PrintCarRosterAction(false, carsTableFrame);
063        printAction.setEnabled(false);
064        AbstractAction previewAction = new PrintCarRosterAction(true, carsTableFrame);
065        previewAction.setEnabled(false);
066        
067        add(importAction);
068        add(exportAction);
069        addSeparator();
070        add(deleteAction);
071        add(resetMovesAction);
072        addSeparator();
073        add(printAction);
074        add(previewAction);
075
076        // activate the right items
077        switch (pMenuType) {
078            case MAINMENU:
079                importAction.setEnabled(true);
080                exportAction.setEnabled(true);
081                deleteAction.setEnabled(true);
082                resetMovesAction.setEnabled(true);
083                printAction.setEnabled(true);
084                previewAction.setEnabled(true);
085                break;
086            case SELECTMENU:
087            case ENTRYMENU:
088                printAction.setEnabled(true);
089                previewAction.setEnabled(true);
090                break;
091            default:
092                log.error("RosterMenu constructed without a valid menuType parameter: {}", pMenuType);
093        }
094    }
095
096    // initialize logging
097    private final static Logger log = LoggerFactory.getLogger(CarRosterMenu.class
098            .getName());
099
100}