\ru\ifmo\alarm\event\HitSensor.java

package ru.ifmo.alarm.event; 
 
import java.awt.event.MouseEvent; 
import java.awt.event.MouseListener; 
 
import com.evelopers.common.exception.CommonException; 
import com.evelopers.unimod.core.stateworks.Event; 
import com.evelopers.unimod.runtime.EventProvider; 
import com.evelopers.unimod.runtime.ModelEngine; 
import com.evelopers.unimod.runtime.context.StateMachineContextImpl; 
 
import ru.ifmo.alarm.gui.AlarmFrame; 
 
public class HitSensor implements EventProvider { 
     
    private ModelEngine engine;     //global so that ActionListener could access it 
     
    /** 
     * @unimod.event.descr easy hitted 
     */ 
    public static final String E21 = "e21"; 
    /** 
     * @unimod.event.descr hardly hitted 
     */ 
    public static final String E22 = "e22"; 
 
    public void init(ModelEngine engine) throws CommonException { 
        this.engine = engine;       //for actionPerformed method to access engine 
         
        AlarmFrame.alarmFrame.getCarPanel().addMouseListener(new MouseListener() { 
            public void mouseClicked(MouseEvent e) { 
                if (e.getButton() == MouseEvent.BUTTON1) { 
                    HitSensor.this.engine.getEventManager().handle( 
                            new Event(E21), StateMachineContextImpl.create()); 
                } else if (e.getButton() == MouseEvent.BUTTON3) { 
                    HitSensor.this.engine.getEventManager().handle( 
                            new Event(E22), StateMachineContextImpl.create()); 
                } 
            } 
            public void mouseEntered(MouseEvent e) {} 
            public void mouseExited(MouseEvent e) {} 
            public void mousePressed(MouseEvent e) {} 
            public void mouseReleased(MouseEvent e) {} 
        }); 
    } 
 
    public void dispose() { 
        AlarmFrame.alarmFrame.dispose();    //close window when the state machine stops 
    } 
 
}