How do we prevent stuff like that? It is a difficult question. Abstractly, we have three elements to work with: 1) The idea itself of committing public slaughter in a specific way; 2) The motive to do so; 3) The means to do so. A person needs all three of those--and only those--in order to be able to shoot up a group of people.
The first part of that lethal equation--the idea itself--is the hardest to prevent without either infringing upon people's core civil liberties, or consigning them to ignorance--or both. Frankly, I'm not even sure it's possible. Imagining slaughter is pretty easy, because images of it have abounded in our culture, in every culture, since the dawn of civilization. And, in a more philosophical sense, I think we would lose an important part of our humanity by not being able to envision acts of destruction--an ability that sits at the core of human ethics.
The second part--the motive--is probably the easiest to address on paper, because it requires only a single dictum--to be applied to all facets of our society, from parents to television show producers: "Raise good children." The problem is that we don't know how to do that at the collective level, and it has to be at the collective level. It won't matter how fine an individual child is raised to be if he or she is not compatible with society at large. Trouble would be inevitable. Only a society where the parts are raised in the context of the whole will people have a good chance of not becoming disgruntled, embittered, despondent, or even murderous. And here's a twist to thicken the stew: To get there, people would have to give up many liberties that we now take for granted (especially in the United States). To frame it outside of a conservative mindset, it would require a significant evolution in the fabric of our culture--and in the minds of individuals. But, short of accomplishing this lofty goal completely, I do believe we can make great strides toward accomplishing it partially. I don't want to get into the thick of that stuff here, because it'll inevitably cause political arguments, but you can imagine the sorts of things I'm talking about: Raise literacy, support troubled kids, discourage bigotry (sorry, fat-haters), reduce poverty, provide structure for kids to express their energies, increase state authority to override incompetent parents, and so on. Unfortunately, all of those things are either expensive, progressive, authoritarian, or even some combination of the three, and are certain to generate opposition.
Sadly, this means it is all but certain that some people--too many--will be able to envision mass slaughter, and will eventually, through life's experiences, develop the motive to commit such an act. All we have left is to ignore our instincts to nurture that person, and instead stop them from carrying out their scheme...the third part of our three-part equation to murder. Now this is simple: If you meant to kill a lot of people, what tools would you want to have? That's easy: Guns. They are widely available and deadly effective. They give you an almost absolute physical advantage over those who do not have them, and the rudiments of their use are easily learned. Other methods of mass murder--chlorine bleach, vehicles, bladed weapons--are much less likely to occur to a would-be killer because they are variously harder to get, harder to use, less effective, or low in utility. The single biggest thing we could do to prevent mass murder with a minimum abrogation of the liberties of the people, is to make guns much harder to bear, and harder still to keep.
Gun control. So it comes down to that. There is no single policy that would have a wider-reaching, more immediate, less costly effect.