001: /*
002: * MacOSPlugin.java
003: *
004: * Created on March 18, 2004, 11:17 AM
005: */
006:
007: package net.sourceforge.squirrel_sql.plugins.macosx;
008:
009: //import com.apple.eawt.ApplicationAdapter;
010: //import com.apple.eawt.ApplicationEvent;
011: //import com.apple.eawt.Application;
012:
013: import net.sourceforge.squirrel_sql.client.IApplication;
014: import net.sourceforge.squirrel_sql.client.plugin.PluginException;
015: import net.sourceforge.squirrel_sql.client.plugin.DefaultPlugin;
016: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
017: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
018:
019: import java.lang.reflect.Proxy;
020: import java.lang.reflect.Method;
021:
022: /**
023: *
024: * @author rowen
025: */
026: public class MacOSPlugin extends DefaultPlugin {
027:
028: private final static ILogger s_log = LoggerController
029: .createLogger(MacOSPlugin.class);
030:
031: public String getAuthor() {
032: return ("Neville Rowe");
033: }
034:
035: public String getDescriptiveName() {
036: return ("Mac OS User Interface");
037: }
038:
039: public String getInternalName() {
040: return ("macosx");
041: }
042:
043: public String getVersion() {
044: return ("0.1");
045: }
046:
047: public String getChangeLogFileName() {
048: return "changes.txt";
049: }
050:
051: public String getHelpFileName() {
052: return "readme.txt";
053: }
054:
055: public String getLicenceFileName() {
056: return "licence.txt";
057: }
058:
059: public synchronized void load(IApplication app)
060: throws PluginException {
061: super .load(app);
062: }
063:
064: public synchronized void initialize() throws PluginException {
065: try {
066: super .initialize();
067: final IApplication app = getApplication();
068:
069: Class<?> com_apple_eawt_Application;
070: try {
071: com_apple_eawt_Application = Class
072: .forName("com.apple.eawt.Application");
073: } catch (ClassNotFoundException e) {
074: return;
075: }
076:
077: Method getApplication = com_apple_eawt_Application
078: .getMethod("getApplication", new Class[0]);
079:
080: Object applicationInstance = getApplication.invoke(
081: com_apple_eawt_Application, new Object[0]);
082:
083: Class<?> com_apple_eawt_ApplicationListener = Class
084: .forName("com.apple.eawt.ApplicationListener");
085:
086: ApplicationListenerInvocationHandler handler = new ApplicationListenerInvocationHandler(
087: app);
088: Object proxy = Proxy.newProxyInstance(IApplication.class
089: .getClassLoader(),
090: new Class[] { com_apple_eawt_ApplicationListener },
091: handler);
092:
093: // com.apple.eawt.ApplicationAdapter applicationAdapter = new com.apple.eawt.ApplicationAdapter()
094: // {
095: // public void handleAbout(ApplicationEvent e)
096: // {
097: // e.setHandled(true);
098: // new AboutCommand(app).execute();
099: // }
100: //
101: // public void handleOpenApplication(ApplicationEvent e)
102: // {
103: // }
104: //
105: // public void handleOpenFile(ApplicationEvent e)
106: // {
107: // }
108: //
109: // public void handlePreferences(ApplicationEvent e)
110: // {
111: // e.setHandled(true);
112: // new GlobalPreferencesCommand(app).execute();
113: // }
114: //
115: // public void handlePrintFile(ApplicationEvent e)
116: // {
117: // }
118: //
119: // public void handleQuit(ApplicationEvent e)
120: // {
121: // e.setHandled(true);
122: // app.getMainFrame().dispose();
123: // }
124: // };
125:
126: Method addApplicationListener = com_apple_eawt_Application
127: .getMethod(
128: "addApplicationListener",
129: new Class[] { com_apple_eawt_ApplicationListener });
130: addApplicationListener.invoke(applicationInstance,
131: new Object[] { proxy });
132:
133: Method addPreferencesMenuItem = com_apple_eawt_Application
134: .getMethod("addPreferencesMenuItem", new Class[0]);
135: addPreferencesMenuItem.invoke(applicationInstance,
136: new Object[0]);
137:
138: Method setEnabledPreferencesMenu = com_apple_eawt_Application
139: .getMethod("setEnabledPreferencesMenu",
140: new Class[] { Boolean.TYPE });
141: setEnabledPreferencesMenu.invoke(applicationInstance,
142: new Object[] { Boolean.TRUE });
143:
144: // fApplication.addApplicationListener(applicationAdapter);
145: // fApplication.addPreferencesMenuItem();
146: // fApplication.setEnabledPreferencesMenu(true);
147: } catch (Exception e) {
148: s_log.error("initialize: encountered exception: "
149: + e.getMessage(), e);
150: throw new RuntimeException(e);
151: }
152: }
153: }
|