~ubuntu-branches/ubuntu/precise/triplea/precise

« back to all changes in this revision

Viewing changes to .pc/macwrappers.patch/src/games/strategy/common/ui/MacWrapper.java

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2011-11-11 21:40:11 UTC
  • Revision ID: package-import@ubuntu.com-20111111214011-5y05v7g6bgodm2uu
Tags: 1.3.2.2-1
Initial release. (Closes: #648444) (LP: #126069)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This program is free software; you can redistribute it and/or modify
 
3
 * it under the terms of the GNU General Public License as published by
 
4
 * the Free Software Foundation; either version 2 of the License, or
 
5
 * (at your option) any later version.
 
6
 * This program is distributed in the hope that it will be useful,
 
7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
8
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
9
 * GNU General Public License for more details.
 
10
 * You should have received a copy of the GNU General Public License
 
11
 * along with this program; if not, write to the Free Software
 
12
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
13
 */
 
14
 
 
15
package games.strategy.common.ui;
 
16
 
 
17
import com.apple.eawt.Application;
 
18
import com.apple.eawt.ApplicationAdapter;
 
19
import com.apple.eawt.ApplicationEvent;
 
20
 
 
21
 
 
22
/**
 
23
 * Utility class to wrap Mac OS X-specific shutdown handler.<p>
 
24
 * 
 
25
 * Based on TripleA code.<p>
 
26
 * 
 
27
 * Needs AppleJavaExtensions.jar to compile on non-Mac platform.
 
28
 * 
 
29
 * @author Lane Schwartz
 
30
 * @see http://developer.apple.com/samplecode/AppleJavaExtensions/index.html
 
31
 */
 
32
public class MacWrapper
 
33
{
 
34
    private static MainGameFrame s_shutdownFrame;
 
35
    private static Application application = new Application();     
 
36
        
 
37
    static
 
38
    {
 
39
        application.addApplicationListener(
 
40
                new ApplicationAdapter() {
 
41
                    public void handleQuit(ApplicationEvent event) 
 
42
                    {   
 
43
                        if(s_shutdownFrame != null)
 
44
                            s_shutdownFrame.shutdown();
 
45
                        else 
 
46
                            System.exit(0);   
 
47
                    }});
 
48
    }
 
49
    
 
50
    //keep this in its own class, otherwise we get a no class def error when 
 
51
    //we try to load the game and the stubs arent in the classpath
 
52
    //i think the java validator triggers this
 
53
    public static void registerMacShutdownHandler(final MainGameFrame frame)
 
54
    {
 
55
        s_shutdownFrame = frame;
 
56
    }
 
57
    
 
58
    
 
59
    public static void unregisterShutdownHandler()
 
60
    {
 
61
        s_shutdownFrame = null;       
 
62
    }
 
63
}