1 53 package org.swixml; 54 55 import com.apple.eawt.*; 56 import javax.swing.*; 57 58 import java.awt.event.ActionEvent ; 59 import java.util.Map ; 60 61 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 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 (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 (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 (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 (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 (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 (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 (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 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 |