|
3 | 3 | /* |
4 | 4 | Part of the Processing project - http://processing.org |
5 | 5 |
|
6 | | - Copyright (c) 2012-2013 The Processing Foundation |
| 6 | + Copyright (c) 2012-2014 The Processing Foundation |
7 | 7 | Copyright (c) 2007-2012 Ben Fry and Casey Reas |
8 | 8 |
|
9 | 9 | This program is free software; you can redistribute it and/or |
|
23 | 23 | package processing.app.platform; |
24 | 24 |
|
25 | 25 | import java.awt.event.*; |
| 26 | +import java.io.File; |
26 | 27 |
|
27 | 28 | import javax.swing.*; |
28 | 29 |
|
29 | | -import processing.app.About; |
30 | | -import processing.app.Base; |
31 | | -import processing.app.Toolkit; |
32 | | -import processing.app.Language; |
33 | | - |
34 | 30 | import com.apple.eawt.*; |
| 31 | +import com.apple.eawt.AppEvent.*; |
| 32 | + |
| 33 | +import processing.app.*; |
35 | 34 |
|
36 | 35 |
|
37 | 36 | /** |
38 | 37 | * Deal with issues related to thinking differently. This handles the basic |
39 | 38 | * Mac OS X menu commands (and apple events) for open, about, prefs, etc. |
40 | 39 | * |
41 | | - * Based on OSXAdapter.java from Apple DTS. |
42 | | - * |
43 | 40 | * As of 0140, this code need not be built on platforms other than OS X, |
44 | 41 | * because of the new platform structure which isolates through reflection. |
45 | 42 | * |
46 | | - * This suppresses deprecation warnings because to use the new code, all users |
47 | | - * would be forced to use Java Update 3 on OS X 10.6, and Java Update 8 on |
48 | | - * OS X 10.5, which doesn't seem likely at the moment. |
| 43 | + * Rewritten for 0232 to remove deprecation issues, per the message |
| 44 | + * <a href="http://lists.apple.com/archives/java-dev/2012/Jan/msg00101.html">here</a>. |
| 45 | + * (We're able to do this now because we're dropping older Java versions.) |
49 | 46 | */ |
50 | | -@SuppressWarnings("deprecation") |
51 | | -public class ThinkDifferent implements ApplicationListener { |
| 47 | +public class ThinkDifferent { |
52 | 48 |
|
53 | 49 | // pseudo-singleton model; no point in making multiple instances |
54 | 50 | // of the EAWT application or our adapter |
@@ -57,26 +53,54 @@ public class ThinkDifferent implements ApplicationListener { |
57 | 53 | private static Application application; |
58 | 54 |
|
59 | 55 | // reference to the app where the existing quit, about, prefs code is |
60 | | - private Base base; |
| 56 | + //private Base base; |
61 | 57 |
|
62 | 58 |
|
63 | | - static protected void init(Base base) { |
| 59 | + static protected void init(final Base base) { |
64 | 60 | if (application == null) { |
65 | | - //application = new com.apple.eawt.Application(); |
66 | 61 | application = Application.getApplication(); |
67 | 62 | } |
68 | 63 | if (adapter == null) { |
69 | | - adapter = new ThinkDifferent(base); |
| 64 | + adapter = new ThinkDifferent(); //base); |
70 | 65 | } |
71 | | - application.addApplicationListener(adapter); |
72 | | - application.setEnabledAboutMenu(true); |
73 | | - application.setEnabledPreferencesMenu(true); |
74 | | - |
75 | | - // Set the menubar to be used when nothing else is open. http://j.mp/dkZmka |
76 | | - // Only available since Java for Mac OS X 10.6 Update 1, but removed |
77 | | - // dynamic loading code because that should be installed in 10.6.8, and |
78 | | - // we may be dropped 10.6 really soon anyway |
79 | 66 |
|
| 67 | + application.setAboutHandler(new AboutHandler() { |
| 68 | + public void handleAbout(AboutEvent ae) { |
| 69 | + new About(null); |
| 70 | + } |
| 71 | + }); |
| 72 | + |
| 73 | + application.setPreferencesHandler(new PreferencesHandler() { |
| 74 | + public void handlePreferences(PreferencesEvent arg0) { |
| 75 | + base.handlePrefs(); |
| 76 | + } |
| 77 | + }); |
| 78 | + |
| 79 | + application.setOpenFileHandler(new OpenFilesHandler() { |
| 80 | + public void openFiles(OpenFilesEvent event) { |
| 81 | + for (File file : event.getFiles()) { |
| 82 | + base.handleOpen(file.getAbsolutePath()); |
| 83 | + } |
| 84 | + } |
| 85 | + }); |
| 86 | + |
| 87 | + application.setPrintFileHandler(new PrintFilesHandler() { |
| 88 | + public void printFiles(PrintFilesEvent event) { |
| 89 | + // TODO not yet implemented |
| 90 | + } |
| 91 | + }); |
| 92 | + |
| 93 | + application.setQuitHandler(new QuitHandler() { |
| 94 | + public void handleQuitRequestWith(QuitEvent event, QuitResponse response) { |
| 95 | + if (base.handleQuit()) { |
| 96 | + response.performQuit(); |
| 97 | + } else { |
| 98 | + response.cancelQuit(); |
| 99 | + } |
| 100 | + } |
| 101 | + }); |
| 102 | + |
| 103 | + // Set the menubar to be used when nothing else is open. |
80 | 104 | JMenuBar defaultMenuBar = new JMenuBar(); |
81 | 105 | JMenu fileMenu = buildFileMenu(base); |
82 | 106 | defaultMenuBar.add(fileMenu); |
@@ -107,9 +131,9 @@ static protected void init(Base base) { |
107 | 131 | } |
108 | 132 |
|
109 | 133 |
|
110 | | - public ThinkDifferent(Base base) { |
111 | | - this.base = base; |
112 | | - } |
| 134 | +// public ThinkDifferent(Base base) { |
| 135 | +// this.base = base; |
| 136 | +// } |
113 | 137 |
|
114 | 138 |
|
115 | 139 | /** |
@@ -154,64 +178,4 @@ public void actionPerformed(ActionEvent e) { |
154 | 178 |
|
155 | 179 | return fileMenu; |
156 | 180 | } |
157 | | - |
158 | | - |
159 | | - // implemented handler methods. These are basically hooks into existing |
160 | | - // functionality from the main app, as if it came over from another platform. |
161 | | - public void handleAbout(ApplicationEvent ae) { |
162 | | - if (base != null) { |
163 | | - ae.setHandled(true); |
164 | | - new About(null); |
165 | | - } else { |
166 | | - throw new IllegalStateException("handleAbout: Base instance detached from listener"); |
167 | | - } |
168 | | - } |
169 | | - |
170 | | - |
171 | | - public void handlePreferences(ApplicationEvent ae) { |
172 | | - if (base != null) { |
173 | | - base.handlePrefs(); |
174 | | - ae.setHandled(true); |
175 | | - } else { |
176 | | - throw new IllegalStateException("handlePreferences: Base instance detached from listener"); |
177 | | - } |
178 | | - } |
179 | | - |
180 | | - |
181 | | - public void handleOpenApplication(ApplicationEvent ae) { |
182 | | - } |
183 | | - |
184 | | - |
185 | | - public void handleOpenFile(ApplicationEvent ae) { |
186 | | -// System.out.println("got open file event " + ae.getFilename()); |
187 | | - String filename = ae.getFilename(); |
188 | | - base.handleOpen(filename); |
189 | | - ae.setHandled(true); |
190 | | - } |
191 | | - |
192 | | - |
193 | | - public void handlePrintFile(ApplicationEvent ae) { |
194 | | - // TODO implement os x print handler here (open app, call handlePrint, quit) |
195 | | - } |
196 | | - |
197 | | - |
198 | | - public void handleQuit(ApplicationEvent ae) { |
199 | | - if (base != null) { |
200 | | - /* |
201 | | - / You MUST setHandled(false) if you want to delay or cancel the quit. |
202 | | - / This is important for cross-platform development -- have a universal quit |
203 | | - / routine that chooses whether or not to quit, so the functionality is identical |
204 | | - / on all platforms. This example simply cancels the AppleEvent-based quit and |
205 | | - / defers to that universal method. |
206 | | - */ |
207 | | - boolean result = base.handleQuit(); |
208 | | - ae.setHandled(result); |
209 | | - } else { |
210 | | - throw new IllegalStateException("handleQuit: Base instance detached from listener"); |
211 | | - } |
212 | | - } |
213 | | - |
214 | | - |
215 | | - public void handleReOpenApplication(ApplicationEvent arg0) { |
216 | | - } |
217 | 181 | } |