KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > swixml > MacApp


1 /*--
2  $Id: MacApp.java,v 1.2 2004/10/05 21:32:35 tichy Exp $
3
4  Copyright (C) 2003-2004 Wolf Paulus.
5  All rights reserved.
6
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions
9  are met:
10
11  1. Redistributions of source code must retain the above copyright
12  notice, this list of conditions, and the following disclaimer.
13
14  2. Redistributions in binary form must reproduce the above copyright
15  notice, this list of conditions, and the disclaimer that follows
16  these conditions in the documentation and/or other materials provided
17  with the distribution.
18
19  3. The end-user documentation included with the redistribution,
20  if any, must include the following acknowledgment:
21         "This product includes software developed by the
22          SWIXML Project (http://www.swixml.org/)."
23  Alternately, this acknowledgment may appear in the software itself,
24  if and wherever such third-party acknowledgments normally appear.
25
26  4. The name "Swixml" must not be used to endorse or promote products
27  derived from this software without prior written permission. For
28  written permission, please contact <info_AT_swixml_DOT_org>
29
30  5. Products derived from this software may not be called "Swixml",
31  nor may "Swixml" appear in their name, without prior written
32  permission from the Swixml Project Management.
33
34  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37  DISCLAIMED. IN NO EVENT SHALL THE SWIXML PROJECT OR ITS
38  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
41  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
42  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
43  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
44  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45  SUCH DAMAGE.
46  ====================================================================
47
48  This software consists of voluntary contributions made by many
49  individuals on behalf of the Swixml Project and was originally
50  created by Wolf Paulus <wolf_AT_swixml_DOT_org>. For more information
51  on the Swixml Project, please see <http://www.swixml.org/>.
52 */

53 package org.swixml;
54
55 import com.apple.eawt.*;
56 import javax.swing.*;
57
58 import java.awt.event.ActionEvent JavaDoc;
59 import java.util.Map JavaDoc;
60
61 /**
62  * A MacApp object acompanies a SwingEngine generated UI, when run on a Mac.
63  * The MacApp dispatches MacMenu requests to the registered actions.<BR>
64  * It remains in the responsibility of the main application that the registered
65  * Action are available and fully funtional (loaded).
66  */

67 public class MacApp extends Application {
68   private static MacApp INSTANCE = null;
69
70   public synchronized static MacApp getInstance() {
71     if (INSTANCE == null) {
72       INSTANCE = new MacApp();
73     }
74     return INSTANCE;
75   }
76
77   //////////////////////////////////////////////////
78

79   Action aboutAction = null;
80   Action fileAction = null;
81   Action appAction = null;
82   Action prefAction = null;
83   Action printAction = null;
84   Action reopenAction = null;
85   Action quitAction = null;
86 int sequence;
87
88
89   private MacApp() {
90       this.sequence = 0;
91     addApplicationListener( new ApplicationAdapter() {
92
93       public void handleAbout( ApplicationEvent event ) {
94         if (aboutAction != null) {
95           event.setHandled( true );
96           aboutAction.actionPerformed( new ActionEvent JavaDoc(event.getSource(),
97                   MacApp.this.sequence++,
98                   Parser.ATTR_MACOS_ABOUT ));
99         } else {
100           super.handleAbout( event );
101         }
102       }
103
104       public void handleOpenApplication( ApplicationEvent event ) {
105         if (appAction != null) {
106           appAction.actionPerformed( new ActionEvent JavaDoc(event.getSource(),
107                   MacApp.this.sequence++,
108                   Parser.ATTR_MACOS_OPENAPP) );
109           event.setHandled( true );
110         } else {
111           super.handleOpenApplication( event );
112         }
113       }
114
115       public void handleOpenFile( ApplicationEvent event ) {
116         if (fileAction != null) {
117           fileAction.actionPerformed( new ActionEvent JavaDoc(event.getSource(),
118                   MacApp.this.sequence++,
119                   Parser.ATTR_MACOS_OPENFILE) );
120           event.setHandled( true );
121         } else {
122           super.handleOpenFile( event );
123         }
124       }
125
126       public void handlePreferences( ApplicationEvent event ) {
127         if (prefAction != null) {
128           prefAction.actionPerformed( new ActionEvent JavaDoc(event.getSource(),
129                   MacApp.this.sequence++,
130                   Parser.ATTR_MACOS_PREF) );
131           event.setHandled( true );
132         } else {
133           super.handlePreferences( event );
134         }
135       }
136
137       public void handlePrintFile( ApplicationEvent event ) {
138         if (printAction != null) {
139           printAction.actionPerformed( new ActionEvent JavaDoc(event.getSource(),
140                   MacApp.this.sequence++,
141                   Parser.ATTR_MACOS_PRINT) );
142           event.setHandled( true );
143         } else {
144           super.handlePrintFile( event );
145         }
146       }
147
148       public void handleQuit( ApplicationEvent event ) {
149         if (quitAction != null) {
150           quitAction.actionPerformed( new ActionEvent JavaDoc(event.getSource(),
151                   MacApp.this.sequence++,
152                   Parser.ATTR_MACOS_QUIT) );
153           event.setHandled( true );
154         } else {
155           super.handleQuit( event );
156         }
157       }
158
159       public void handleReOpenApplication( ApplicationEvent event ) {
160         if (reopenAction != null) {
161           reopenAction.actionPerformed( new ActionEvent JavaDoc(event.getSource(),
162                   MacApp.this.sequence++,
163                   Parser.ATTR_MACOS_OPENAPP) );
164           event.setHandled( true );
165         } else {
166           super.handleReOpenApplication( event );
167         }
168       }
169
170     } );
171   }
172
173
174   public void update( Map JavaDoc action_map ) {
175
176     if (action_map.containsKey( Parser.ATTR_MACOS_ABOUT )) {
177       aboutAction = (Action) action_map.get( Parser.ATTR_MACOS_ABOUT );
178       this.setEnabledAboutMenu( aboutAction != null );
179     }
180     if (action_map.containsKey( Parser.ATTR_MACOS_PREF )) {
181       prefAction = (Action) action_map.get( Parser.ATTR_MACOS_PREF );
182       this.setEnabledPreferencesMenu( prefAction != null );
183     }
184     if (action_map.containsKey( Parser.ATTR_MACOS_OPENAPP )) {
185       appAction = (Action) action_map.get( Parser.ATTR_MACOS_OPENAPP );
186     }
187     if (action_map.containsKey( Parser.ATTR_MACOS_REOPEN )) {
188       reopenAction = (Action) action_map.get( Parser.ATTR_MACOS_REOPEN );
189     }
190     if (action_map.containsKey( Parser.ATTR_MACOS_OPENFILE )) {
191       fileAction = (Action) action_map.get( Parser.ATTR_MACOS_OPENFILE );
192     }
193     if (action_map.containsKey( Parser.ATTR_MACOS_PRINT )) {
194       printAction = (Action) action_map.get( Parser.ATTR_MACOS_PRINT );
195     }
196     if (action_map.containsKey( Parser.ATTR_MACOS_QUIT )) {
197       quitAction = (Action) action_map.get( Parser.ATTR_MACOS_QUIT );
198     }
199   }
200 }
201
202
Popular Tags