Riddle - Three Men and Five Hats

This is a fun riddle that appears to be impossible to explain at first.
It is a good mental exercise, even after knowing the thought process.

picture of 3 men in hats

Three men are blindfolded and each randomly selects a hat from a box and puts it on.
They know there are 2 white hats and 3 black hats in the box but they do not know the color of the hat they selected.
The 3 men are placed in a line, one behind another, facing a wall and their blindfolds are removed.
The man with hat # 1 can see the color of hat # 2 and hat # 3, but not his own.
The man with hat #2 can see the color of hat #3, but not his own. The man with hat #3 cannot see the color of any hats.
When the man with hat #1 is asked for the color of his own hat he responds, "I do not know", which the men with hats #2 and #3 hear.
When the man with hat #2 is asked for the color of his own hat he responds, "I do not know", which the man with hat #3 hears.
Then, when the man with hat #3 is asked for the color of his hat he responds "I know the color of my hat."
What is the color of his hat and how did he know?
Stuck?