DefaultLegacyHooks: make open window test a method

We are going to make it more complicated, so let's keep things DRY.
DefaultLegacyHooks: also skip closed ImageWindows

When ImageJ1 is quitting, the WindowManager.closeAllWindows() method
marks each ImageWindow as closed, but does not actually hide it. So the
ImageJ2 heuristic of checking whether the window is still visible after
it receives a windowClosing event fails. The workaround is to check, in
the case of ImageWindows, whether their isClosed() method returns true,
and if so, continue.

This change results in ImageJ1 shutting down successfully again when
image windows are still open.