F:\java\knim-game\sources\ru\ifmo\knim\providers\InterfaceEventProvider.java

1    /** 
2     * @(#)GameEventProvider.java 
3     *  
4     *  Copyright Anthony Yakovlev <yakovlev@rain.ifmo.ru> and Michail Lukin <michail@users.msn.com> 
5     */ 
6     
7    package ru.ifmo.knim.providers; 
8     
9    import com.evelopers.unimod.runtime.EventProvider; 
10   import com.evelopers.unimod.runtime.ModelEngine; 
11    
12   import javax.swing.*; 
13    
14   import ru.ifmo.knim.screens.*; 
15    
16   /** 
17    * Events that are send by interface engine 
18    * @author Anthony Yakovlev    
19    */ 
20   public class InterfaceEventProvider implements EventProvider { 
21        
22       /** 
23       * @unimod.event.descr User selected difficulty 
24       */ 
25       public static final String E4 = "e4"; 
26       /** 
27       * @unimod.event.descr User pressed "About" button 
28       */ 
29       public static final String E5 = "e5"; 
30       /** 
31       * @unimod.event.descr User pressed "New game" button 
32       */ 
33       public static final String E2 = "e2"; 
34       /** 
35       * @unimod.event.descr User closed the window 
36       */ 
37       public static final String E6 = "e6"; 
38       /** 
39       * @unimod.event.descr User finished move 
40       */ 
41       public static final String E3 = "e3"; 
42       /** 
43       * @unimod.event.descr User selected stone layout 
44       */ 
45       public static final String E7 = "e7"; 
46        
47       /* (non-Javadoc) 
48        * @see com.evelopers.unimod.runtime.EventProvider#init(com.evelopers.unimod.runtime.EventHandler, com.evelopers.unimod.core.stateworks.StateMachine) 
49        */ 
50       public void init(ModelEngine engine) { 
51           GameScreen.getScreen().init(engine); 
52    
53           try { 
54               // invoke in Swing event thread 
55               SwingUtilities.invokeAndWait(new Runnable() { 
56                   public void run() { 
57                       GameScreen.getScreen().setVisible(true); 
58                   } 
59               }); 
60           } catch (Exception e) { 
61               throw new RuntimeException(e); 
62           } 
63       } 
64        
65       /* (non-Javadoc) 
66        * @see com.evelopers.unimod.runtime.EventProvider#dispose() 
67        */ 
68       public void dispose() { 
69           try { 
70               // invoke in Swing event thread 
71               SwingUtilities.invokeAndWait(new Runnable() { 
72                   public void run() { 
73                       GameScreen.getScreen().setVisible(false); 
74                       GameScreen.getScreen().dispose(); 
75                   } 
76               }); 
77           } catch (Exception e) { 
78               e.printStackTrace(); 
79           } 
80       } 
81    
82   } 
83