client/ClientWindow.java
/**
		 * Refresh the current items of the basket
		 */
Refresh the current items of the basket
Refresh the current items of the basket
private void refreshBasket() {
			basketInner.removeAll();
			basketMap.clear();
			Map<Dish, Number> basketItems = client.getBasket(user);
			for (Entry<Dish, Number> basketItem : basketItems.entrySet()) {
				Dish basketDish = basketItem.getKey();
				Number basketQuantity = basketItem.getValue();
				JPanel basketPanel = new JPanel(new BorderLayout());
				basketPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE,50));
				SpinnerNumberModel minMax = new SpinnerNumberModel(0,0,100000,1);
				JSpinner basketQuantitySpinner = new JSpinner();
				basketQuantitySpinner.setModel(minMax);
				basketQuantitySpinner.setValue(basketQuantity);
				basketPanel.add(basketQuantitySpinner,BorderLayout.WEST);
				JLabel basketLabel = new JLabel(basketDish.getName());
				basketPanel.add(basketLabel,BorderLayout.CENTER);
				basketInner.add(basketPanel);
				basketMap.put(basketDish, basketQuantitySpinner);
			}
			Number cost = client.getBasketCost(user);
			basketCost.setText(moneyFormat.format(cost));
			if(basketItems.size() > 0) {
				checkoutBasket.setEnabled(true);
			} else {
				checkoutBasket.setEnabled(false);
			}
			basketInner.revalidate();
			basketInner.repaint();
		}
private void refreshBasket ( ) { basketInner . removeAll ( ) ; basketMap . clear ( ) ; Map < Dish , Number > basketItems = client . getBasket ( user ) ; for ( Entry < Dish , Number > basketItem : basketItems . entrySet ( ) ) { Dish basketDish = basketItem . getKey ( ) ; Number basketQuantity = basketItem . getValue ( ) ; JPanel basketPanel = new JPanel ( new BorderLayout ( ) ) ; basketPanel . setMaximumSize ( new Dimension ( Integer . MAX_VALUE , 50 ) ) ; SpinnerNumberModel minMax = new SpinnerNumberModel ( 0 , 0 , 100000 , 1 ) ; JSpinner basketQuantitySpinner = new JSpinner ( ) ; basketQuantitySpinner . setModel ( minMax ) ; basketQuantitySpinner . setValue ( basketQuantity ) ; basketPanel . add ( basketQuantitySpinner , BorderLayout . WEST ) ; JLabel basketLabel = new JLabel ( basketDish . getName ( ) ) ; basketPanel . add ( basketLabel , BorderLayout . CENTER ) ; basketInner . add ( basketPanel ) ; basketMap . put ( basketDish , basketQuantitySpinner ) ; } Number cost = client . getBasketCost ( user ) ; basketCost . setText ( moneyFormat . format ( cost ) ) ; if ( basketItems . size ( ) > 0 ) { checkoutBasket . setEnabled ( true ) ; } else { checkoutBasket . setEnabled ( false ) ; } basketInner . revalidate ( ) ; basketInner . repaint ( ) ; }
Refresh the current items of the basket
Refresh the current items of the basket
//Get all current items in the basket from the backend //Get the total cost of the basket //If there's at least 1 item, enable checkout //Redraw the basket