001package jmri.jmrit.operations.rollingstock.cars; 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 add(deleteAction); 070 add(resetMovesAction); 071 addSeparator(); 072 add(printAction); 073 add(previewAction); 074 075 // activate the right items 076 switch (pMenuType) { 077 case MAINMENU: 078 importAction.setEnabled(true); 079 exportAction.setEnabled(true); 080 deleteAction.setEnabled(true); 081 resetMovesAction.setEnabled(true); 082 printAction.setEnabled(true); 083 previewAction.setEnabled(true); 084 break; 085 case SELECTMENU: 086 case ENTRYMENU: 087 printAction.setEnabled(true); 088 previewAction.setEnabled(true); 089 break; 090 default: 091 log.error("RosterMenu constructed without a valid menuType parameter: {}", pMenuType); 092 } 093 } 094 095 // initialize logging 096 private final static Logger log = LoggerFactory.getLogger(CarRosterMenu.class 097 .getName()); 098 099}