How and why did Japan shift from a feudal society, in danger of colonization, to an industrialized and imperializing nation?