public JPopupMenu generatePopUp(Location l) {
		orderItems.clear();
		shipItems.clear();
		upgradeItems.clear();
		locSpecificItems.clear();
		planetItem = null;
		JMenuItem menuItem;
		popup = new JPopupMenu();
		Ship[] s = l.getOccupants();

		/*** AVAILABLE ORDERS FOR SELECTED SHIPS ***/
		if(GameManager.getSelectedObj() instanceof Location && !((Location)(GameManager.getSelectedObj())).isEmptyOrInvisible()) {
			Ship[] ships = ((Location)(GameManager.getSelectedObj())).getOccupants();
			boolean upgradeMenuCreated = false;
			Orders[] orders;
			for(int i = 0; i < ships.length; i++) {
				if(ships[i].getLoyalty() != TurnManager.currentPlayer)
					continue;
				orders = ships[i].getOrders();
				for(int j = 0; j < orders.length; j++) {
					if(!orderItems.containsValue(orders[j]) && (orders[j] != Orders.UPGRADE || !upgradeMenuCreated)) {
						if(orders[j] == Orders.UPGRADE ) {
							// Add a submenu with a list of ships to upgrade
							JMenu upgradeMenu = new JMenu(Orders.OrderToString(orders[j]));
							if(!l.isEmptyOrInvisible())
							{
								for(int si = 0; si < s.length; si++) {
									if(s[si].canUpgrade() && s[si].getLoyalty() == TurnManager.currentPlayer) {
										menuItem = new JMenuItem(s[si].getName());
										menuItem.addActionListener(this);
										upgradeMenu.add(menuItem);
										upgradeItems.put(menuItem, s[si]);
									}
								}
							}
							popup.add(upgradeMenu);
							upgradeMenuCreated = true;
						} else {
							menuItem = new JMenuItem(Orders.OrderToString(orders[j]));
							menuItem.addActionListener(this);
							popup.add(menuItem);
							orderItems.put(menuItem, orders[j]);
						}
					}
				}
			}
			popup.addSeparator();
		} /*** AVAILABLE ORDERS FOR SELECTED LOCATION ***/
		else if(GameManager.getSelectedObj() instanceof Ship) {
			if(((Ship)GameManager.getSelectedObj()).getLoyalty() == TurnManager.currentPlayer) {
				// Should we only show upgrade order if only the capital ship is selected, and not if an entire location is selected?
				Orders[] orders = ((Ship)(GameManager.getSelectedObj())).getOrders();
				for(int i = 0; i < orders.length; i++) {
					if(orders[i] == Orders.UPGRADE) {
						JMenu upgradeMenu = new JMenu(Orders.OrderToString(orders[i]));
						if(!l.isEmptyOrInvisible()) {
							for(int si = 0; si < s.length; si++) { 
								if(s[si].canUpgrade() && s[si].getLoyalty() == TurnManager.currentPlayer) { // Change this to checking if ship is upgradeable. 
									menuItem = new JMenuItem(s[si].getName());
									menuItem.addActionListener(this);
									upgradeMenu.add(menuItem);
									upgradeItems.put(menuItem, s[si]);
								}
							}
						}
						popup.add(upgradeMenu);
					} else {
						menuItem = new JMenuItem(Orders.OrderToString(orders[i]));
						menuItem.addActionListener(this);
						popup.add(menuItem);
						orderItems.put(menuItem, orders[i]);
					}
				}
				popup.addSeparator();
			}
		}
		else if(GameManager.getSelectedObj() instanceof Planet) {
			if(((Planet)GameManager.getSelectedObj()).canBeOrdered() && (((Planet)GameManager.getSelectedObj()).getAlliance() == TurnManager.currentPlayer)) {
				Orders[] orders = ((Planet)(GameManager.getSelectedObj())).getOrders();
				for (int i = 0; i < orders.length; i++) {
					if(orders[i] == Orders.UPGRADE) {
						JMenu upgradeMenu = new JMenu(Orders.OrderToString(orders[i]));
						if(!l.isEmptyOrInvisible()) {
							for(int si = 0; si < s.length; si++) {
								if(s[si].canUpgrade() && s[si].getLoyalty() == TurnManager.currentPlayer) {
									menuItem = new JMenuItem(s[si].getName());
									menuItem.addActionListener(this);
									upgradeMenu.add(menuItem);
									upgradeItems.put(menuItem, s[si]);
								}
							}
						}
						popup.add(upgradeMenu);
					} else {
						menuItem = new JMenuItem(Orders.OrderToString(orders[i]));
						menuItem.addActionListener(this);
						popup.add(menuItem);
						orderItems.put(menuItem, orders[i]);
					}
				}
			}
			popup.addSeparator();
		}
		
		//Ships at location
		if(s != null && s.length > 0) {
			for(int i = 0; i < s.length; i++) {
				menuItem = new JMenuItem(s[i].getName());
				// Maybe show player colors instead of just red?
				if(s[i].getLoyalty() != TurnManager.currentPlayer) {
					menuItem.setForeground(Color.red);
				}
				menuItem.addActionListener(this);
				popup.add(menuItem);
				shipItems.put(menuItem, s[i]);
			}
			popup.addSeparator();
		}
		
		//Planets at location
		if(l.getPlanet() != null) {
			if(l.getPlanet().getAlliance() == TurnManager.currentPlayer) {
				JMenu planetMenu = new JMenu(l.getPlanet().getName());
				planetMenu.setForeground(TurnManager.getPlayerColor(l.getPlanet().getAlliance()));
				Orders[] orders = l.getPlanet().getOrders();
				for(int i = 0; i < orders.length; i++) {
					if(orders[i] == Orders.UPGRADE) {
						JMenu upgradeMenu = new JMenu(Orders.OrderToString(orders[i]));
						if(!l.isEmptyOrInvisible()) {
							for(int si = 0; si < s.length; si++) {
								if(s[si].canUpgrade() && s[si].getLoyalty() == TurnManager.currentPlayer) {
									menuItem = new JMenuItem(s[si].getName());
									menuItem.addActionListener(this);
									upgradeMenu.add(menuItem);
									locSpecificItems.put(menuItem, s[si]);
								}
							}
						}
						planetMenu.add(upgradeMenu);
					} else {
						menuItem = new JMenuItem(Orders.OrderToString(orders[i]));
						menuItem.addActionListener(this);
						planetMenu.add(menuItem);
						locSpecificItems.put(menuItem, orders[i]);
					}
				}
				popup.add(planetMenu);
			} else if(l.getPlanet().getAlliance() != Planet.UNOWNED) {
				menuItem = new JMenuItem(l.getPlanet().getName());
				menuItem.setForeground(TurnManager.getPlayerColor(l.getPlanet().getAlliance()));
				menuItem.addActionListener(this);
				popup.add(menuItem);
				planetItem = menuItem;
				popup.addSeparator();
			} else {
				menuItem = new JMenuItem(l.getPlanet().getName());
				menuItem.addActionListener(this);
				popup.add(menuItem);
				planetItem = menuItem;
				popup.addSeparator();
			}
		}
		
		//Location Information
		menuItem = new JMenuItem("Location " + l.toString());
		menuItem.addActionListener(this);
		popup.add(menuItem);
		locItem = menuItem;
		associatedLoc = l;
		return popup;
	}