public void mouseClicked(MouseEvent e) {
	if (e.getButton() == e.BUTTON1) {
	    // left click
	    RRBEElementFactory f = window.getElementFactory();
	    if (f != null) {
			//addElement(f.createElement());
		f.activate(this);
		window.repaint(0);
	    }
	} else if (e.getButton() == e.BUTTON2) {
	    // middle-click
	    
	} else if (e.getButton() == e.BUTTON3) {
	    // right-click
	    rightMenu = new JPopupMenu();
	    rightMenu.add(wallSelect);

	    for (int i = 0; i < eh.size() + beamHeap.size(); i++) {
		RRBEElement ehget;
		if (i <eh.size())
		    ehget = eh.get(i);
		else
		    ehget = beamHeap.get(i - eh.size());
		if (ehget != null) {
		    String s = ehget.getName();
		    JMenu t = new JMenu(s);
		    t.setIcon(ehget.getSmallIcon());
		    		    
		    JMenuItem remove = 
			new JMenuItem("Remove " + s);
		    remove.addActionListener(new 
			rightMenuHandler(window,
					 this,
					 ehget,
					 RRBESquare.REMOVE));
		    t.add(remove);

		    if (ehget instanceof RRBETimedElement) {
			JMenu phaseMenu = new JMenu("Active phases");
			JCheckBoxMenuItem phases[] = 
			    new JCheckBoxMenuItem[RRBEGlobal.phaseCount];

			for (int j = 0; j < RRBEGlobal.phaseCount; j++) {
			    phases[j] = 
				new JCheckBoxMenuItem((new 
				    Integer(j+1)).toString());
			    phases[j].setState(ehget.getActivePhase(j));
			    phaseMenu.add(phases[j]);
			    phases[j].addActionListener(new 
				rightMenuHandler(window,
						 this,
						 ehget,
						 RRBESquare
						 .TOGGLEACTIVEPHASE+j));
			}
			t.add(phaseMenu);
		    }

		    JMenuItem edit = new JMenuItem("Edit " + s);
		    edit.addActionListener(new 
			rightMenuHandler(window,
					 this,
					 ehget,
					 RRBESquare.EDIT));
		    //t.add(edit);
		    JMenuItem rotatel = new JMenuItem("Rotate " + s + " left");
		    rotatel.addActionListener(new 
			rightMenuHandler(window,
					 this,
					 ehget,
					 RRBESquare.ROTATELEFT));
		    t.add(rotatel);
		    JMenuItem rotater = new 
			JMenuItem("Rotate " + s + " right");
		    rotater.addActionListener(new 
			rightMenuHandler(window,
					 this,
					 ehget,
					 RRBESquare.ROTATERIGHT));
		    t.add(rotater);
		    rightMenu.add(t);
		}
	    }
	    rightMenu.show(e.getComponent(), e.getX(), e.getY());
	}
    }