copied from timetool (swing/awt)