move some functions from the swing version