first version of code for checkIn

port algorithm from jdk AWT package.