/** * This constructor creates an instance of the object. * * @param cctrl the TransactionController. */ public CoinInputBox(TransactionController cctrl) { this.txCtrl = cctrl; MainController mainCtrl = cctrl.getMainController(); StoreController storeCtrl = mainCtrl.getStoreController(); int cashStoreSize = storeCtrl.getStoreSize(Store.CASH); StoreItem[] cashStoreItems = storeCtrl.getStore(Store.CASH).getItems(); btnCoinButton = new CoinButton[cashStoreSize + 1]; CoinInputListener coinInputListener = new CoinInputListener(txCtrl.getCoinReceiver()); setLayout(new GridBagLayout()); for (int i = 0; i < cashStoreItems.length; i++) { StoreItem storeItem = cashStoreItems[i]; CashStoreItem cashStoreItem = (CashStoreItem) storeItem; StoreObject storeObject = cashStoreItem.getContent(); Coin coin = (Coin) storeObject; String coinName = coin.getName(); int coinValue = coin.getValue(); double coinWeight = coin.getWeight(); btnCoinButton[i] = new CoinButton(coinName, coinValue, coinWeight); btnCoinButton[i].addActionListener(coinInputListener); add( btnCoinButton[i], new GridBagConstraints( i, 1, 1, 1, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 10, 8)); } btnCoinButton[cashStoreSize] = new CoinButton("Invalid", -1, CashStore.INVALID_COIN_WEIGHT); btnCoinButton[cashStoreSize].addActionListener(coinInputListener); add( btnCoinButton[cashStoreSize], new GridBagConstraints( cashStoreSize, 1, 1, 1, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 10, 8)); }
/** setup the maintenance panel and display it. */ public void displayMaintenancePanel() { SimulatorControlPanel scp = mCtrl.getSimulatorControlPanel(); if (mpanel == null) mpanel = new MaintenancePanel((Frame) scp, this); mpanel.display(); mpanel.setActive(MaintenancePanel.DIALOG, true); // setActive of password, invalid and valid display. }
// TransferCashButtonListener // get all the cash from store and set store cash 0; public void transferAll() { StoreController sctrl = mCtrl.getStoreController(); MachineryController machctrl = mCtrl.getMachineryController(); int cc; // coin quantity; try { cc = sctrl.transferAll(); mpanel.displayCoins(cc); machctrl.displayCoinStock(); // the cash qty current is displayed in the Maintenance panel needs to be update to be 0; // not required. mpanel.updateCurrentQtyDisplay(Store.CASH, 0); } catch (VMCSException e) { System.out.println("MaintenanceController.transferAll:" + e); } }
// invoked in CoinDisplayListener public void displayCoin(int idx) { StoreController sctrl = mCtrl.getStoreController(); CashStoreItem item; try { item = (CashStoreItem) sctrl.getStoreItem(Store.CASH, idx); mpanel.getCoinDisplay().displayQty(idx, item.getQuantity()); } catch (VMCSException e) { System.out.println("MaintenanceController.displayCoin:" + e); } }
public void loginMaintainer(boolean st) { mpanel.displayPasswordState(st); mpanel.clearPassword(); if (st == true) { // login successful mpanel.setActive(MaintenancePanel.WORKING, true); mpanel.setActive(MaintenancePanel.PSWD, false); MachineryController machctrl = mCtrl.getMachineryController(); machctrl.setDoorState(false); } }
// StoreViewerListener public void changeStoreQty(char type, int idx, int qty) { StoreController sctrl = mCtrl.getStoreController(); try { mpanel.updateQtyDisplay(type, idx, qty); mpanel.initCollectCash(); mpanel.initTotalCash(); } catch (VMCSException e) { System.out.println("MaintenanceController.changeStoreQty:" + e); } }
// invoked in DrinkDisplayListener; public void displayDrinks(int idx) { StoreController sctrl = mCtrl.getStoreController(); DrinksStoreItem item; try { item = (DrinksStoreItem) sctrl.getStoreItem(Store.DRINK, idx); DrinksBrand db = (DrinksBrand) item.getContent(); mpanel.getDrinksDisplay().displayQty(idx, item.getQuantity()); mpanel.displayPrice(db.getPrice()); } catch (VMCSException e) { System.out.println("MaintenanceController.displayDrink:" + e); } }
// exit button listener; public void logoutMaintainer() { MachineryController machctrl = mCtrl.getMachineryController(); boolean ds = machctrl.isDoorClosed(); if (ds == false) { MessageDialog msg = new MessageDialog(mpanel, "Please Lock the Door before You Leave"); msg.setLocation(500, 500); return; } mpanel.setActive(MaintenancePanel.DIALOG, true); }
// TotalCashButtonListener public void getTotalCash() { StoreController sctrl = mCtrl.getStoreController(); int tc = sctrl.getTotalCash(); mpanel.displayTotalCash(tc); }
// invoked by PriceDisplayListener public void setPrice(int pr) { StoreController sctrl = mCtrl.getStoreController(); int curIdx = mpanel.getCurIdx(); sctrl.setPrice(curIdx, pr); mpanel.getDrinksDisplay().getPriceDisplay().setValue(pr + "C"); }