public int getGridX(int x, int y) 
	{
		Insets myInsets = getInsets();
		int x1 = myInsets.left;
		int y1 = myInsets.top;
		x = x - x1 - GRID_X;
		y = y - y1 - GRID_Y;
		if (x < 0) 
		{   //To the left of the grid
			return -1;
		}
		else if (y < 0) 
		{   //Above the grid
			return -1;
		}
		else if ((x % (INNER_CELL_SIZE + 1) == 0) || (y % (INNER_CELL_SIZE + 1) == 0)) 
		{   //Coordinate is at an edge; not inside a cell
			return -1;
		}
		
		x = x / (INNER_CELL_SIZE + 1);
		y = y / (INNER_CELL_SIZE + 1);

		if (x < 0 || x > getTotalColumns() - 1 || y < 0 || y > TOTAL_ROWS - 1) 
		{   //Outside the rest of the grid
			return -1;
		}
		return x;
	}