001package jmri.jmrix.nce.consist;
002
003import java.awt.Component;
004import java.awt.Frame;
005import javax.swing.AbstractAction;
006import javax.swing.JMenu;
007import org.slf4j.Logger;
008import org.slf4j.LoggerFactory;
009
010/**
011 * Provides a context-specific menu for handling the Roster.
012 *
013 * @author Bob Jacobsen Copyright (C) 2001, 2002
014 * @author Dennis Miller Copyright (C) 2005
015 * @author Daniel Boudreau Copyright (C) 2007
016 * @see NceConsistRosterEntry
017 * @see NceConsistRoster
018 */
019public class NceConsistRosterMenu 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 pWho      The Component using this menu, used to ensure that
047     *                  dialog boxes will pop in the right place.
048     */
049    public NceConsistRosterMenu(String pMenuName, int pMenuType, Component pWho) {
050        super(pMenuName);
051
052        // create the menu
053        //       AbstractAction importAction = new ImportRosterItemAction(Bundle.getMessage("MenuItemImport"), pWho);
054        //       importAction.setEnabled(false);
055        //       AbstractAction exportAction = new ExportRosterItemAction(Bundle.getMessage("MenuItemExport"), pWho);
056        //       exportAction.setEnabled(false);
057        //       AbstractAction copyAction = new CopyRosterItemAction(Bundle.getMessage("MenuItemCopy"), pWho);
058        //       copyAction.setEnabled(false);
059        //       AbstractAction deleteAction = new DeleteRosterItemAction(Bundle.getMessage("MenuItemDelete"), pWho);
060        //       deleteAction.setEnabled(false);
061        // Need a frame here, but are not passed one
062        Frame newFrame = new Frame();
063        AbstractAction printAction = new PrintNceConsistRosterAction(Bundle.getMessage("MenuItemPrintSummary"), newFrame, false);
064        printAction.setEnabled(false);
065        AbstractAction previewAction = new PrintNceConsistRosterAction(Bundle.getMessage("MenuItemPreviewSummary"), newFrame, true);
066        printAction.setEnabled(false);
067//        add(copyAction);
068//        add(importAction);
069//        add(exportAction);
070//        add(deleteAction);
071        add(printAction);
072        add(previewAction);
073
074        // activate the correct items (currently all identical)
075        switch (pMenuType) {
076            case MAINMENU:
077//                deleteAction.setEnabled(true);
078//                importAction.setEnabled(true);
079//                exportAction.setEnabled(true);
080//                copyAction.setEnabled(true);
081            case SELECTMENU:
082            case ENTRYMENU:
083                printAction.setEnabled(true);
084                previewAction.setEnabled(true);
085                break;
086            default:
087                log.error("RosterMenu constructed without a valid menuType parameter: {}", pMenuType);
088        }
089    }
090
091    // initialize logging
092    private final static Logger log = LoggerFactory.getLogger(NceConsistRosterMenu.class);
093
094}