Removed a bunch of code duplication.

6 instances of the same pattern, replaced by a function call.

git-svn-id: https://valelab.ucsf.edu/svn/micromanager2/trunk@13945 d0ab736e-dc22-4aeb-8dc9-08def0aa14fd