8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.lwawt.macosx; 27 28 import java.awt.Desktop.Action; 29 import java.awt.peer.DesktopPeer; 30 import java.io.File; 31 import java.io.IOException; 32 import java.net.URI; 33 34 35 /** 36 * Concrete implementation of the interface <code>DesktopPeer</code> for MacOS X 37 * 38 * @see DesktopPeer 39 */ 40 public class CDesktopPeer implements DesktopPeer { 41 42 public boolean isSupported(Action action) { 43 // OPEN, EDIT, PRINT, MAIL, BROWSE all supported. 44 // Though we don't really differentiate between OPEN / EDIT 45 return true; 46 } 47 48 public void open(File file) throws IOException { 49 this.lsOpenFile(file, false); 50 } 51 52 public void edit(File file) throws IOException { 53 this.lsOpenFile(file, false); 54 } 55 56 public void print(File file) throws IOException { 57 this.lsOpenFile(file, true); 58 } 59 60 public void mail(URI uri) throws IOException { 61 this.lsOpen(uri); 62 } 63 64 public void browse(URI uri) throws IOException { 65 this.lsOpen(uri); 66 } 67 68 private void lsOpen(URI uri) throws IOException { 69 int status = _lsOpenURI(uri.toString()); 70 71 if (status != 0 /* noErr */) { 72 throw new IOException("Failed to mail or browse " + uri + ". Error code: " + status); 73 } 74 } 75 76 private void lsOpenFile(File file, boolean print) throws IOException { 77 int status = _lsOpenFile(file.getCanonicalPath(), print); 78 79 if (status != 0 /* noErr */) { 80 throw new IOException("Failed to open, edit or print " + file + ". Error code: " + status); 81 } 82 } 83 84 private static native int _lsOpenURI(String uri); 85 | 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package sun.lwawt.macosx; 27 28 import com.apple.eawt.Application; 29 import com.apple.eawt.FullScreenUtilities; 30 import sun.awt.AWTAccessor; 31 import sun.lwawt.LWWindowPeer; 32 33 import javax.swing.*; 34 import java.awt.*; 35 import java.awt.Desktop.Action; 36 import java.awt.desktop.*; 37 import java.awt.peer.ComponentPeer; 38 import java.awt.peer.DesktopPeer; 39 import java.io.File; 40 import java.io.FileNotFoundException; 41 import java.io.IOException; 42 import java.net.URI; 43 44 45 /** 46 * Concrete implementation of the interface <code>DesktopPeer</code> for MacOS X 47 * 48 * @see DesktopPeer 49 */ 50 final public class CDesktopPeer implements DesktopPeer { 51 52 private static final CFileManager fileManager = new CFileManager(); 53 54 @Override 55 public boolean isSupported(Action action) { 56 return true; 57 } 58 59 @Override 60 public void open(File file) throws IOException { 61 this.lsOpenFile(file, false); 62 } 63 64 @Override 65 public void edit(File file) throws IOException { 66 this.lsOpenFile(file, false); 67 } 68 69 @Override 70 public void print(File file) throws IOException { 71 this.lsOpenFile(file, true); 72 } 73 74 @Override 75 public void mail(URI uri) throws IOException { 76 this.lsOpen(uri); 77 } 78 79 @Override 80 public void browse(URI uri) throws IOException { 81 this.lsOpen(uri); 82 } 83 84 @Override 85 public void addAppEventListener(SystemEventListener listener) { 86 Application.getApplication().addAppEventListener(listener); 87 } 88 89 @Override 90 public void removeAppEventListener(SystemEventListener listener) { 91 Application.getApplication().removeAppEventListener(listener); 92 } 93 94 @Override 95 public void setAboutHandler(AboutHandler aboutHandler) { 96 Application.getApplication().setAboutHandler(aboutHandler); 97 } 98 99 @Override 100 public void setPreferencesHandler(PreferencesHandler preferencesHandler) { 101 Application.getApplication().setPreferencesHandler(preferencesHandler); 102 } 103 104 @Override 105 public void setOpenFileHandler(OpenFilesHandler openFileHandler) { 106 Application.getApplication().setOpenFileHandler(openFileHandler); 107 } 108 109 @Override 110 public void setPrintFileHandler(PrintFilesHandler printFileHandler) { 111 Application.getApplication().setPrintFileHandler(printFileHandler); 112 } 113 114 @Override 115 public void setOpenURIHandler(OpenURIHandler openURIHandler) { 116 Application.getApplication().setOpenURIHandler(openURIHandler); 117 } 118 119 @Override 120 public void setQuitHandler(QuitHandler quitHandler) { 121 Application.getApplication().setQuitHandler(quitHandler); 122 } 123 124 @Override 125 public void setQuitStrategy(QuitStrategy strategy) { 126 Application.getApplication().setQuitStrategy(strategy); 127 } 128 129 @Override 130 public void enableSuddenTermination() { 131 Application.getApplication().enableSuddenTermination(); 132 } 133 134 @Override 135 public void disableSuddenTermination() { 136 Application.getApplication().disableSuddenTermination(); 137 } 138 139 @Override 140 public void requestForeground(boolean allWindows) { 141 Application.getApplication().requestForeground(allWindows); 142 } 143 144 @Override 145 public void openHelpViewer() { 146 Application.getApplication().openHelpViewer(); 147 } 148 149 @Override 150 public void setDefaultMenuBar(JMenuBar menuBar) { 151 Application.getApplication().setDefaultMenuBar(menuBar); 152 } 153 154 @Override 155 public void addWindowFullScreenListener(final Window window, 156 final FullScreenListener listener) { 157 FullScreenUtilities.addFullScreenListenerTo(window, listener); 158 } 159 160 @Override 161 public void removeWindowFullScreenListener(final Window window, 162 final FullScreenListener listener) { 163 FullScreenUtilities.removeFullScreenListenerFrom(window, listener); 164 } 165 166 @Override 167 public void setWindowCanFullScreen(Window window, boolean canFullScreen) { 168 FullScreenUtilities.setWindowCanFullScreen(window, canFullScreen); 169 } 170 171 @Override 172 public void requestToggleFullScreen(Window window) { 173 final ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(window); 174 175 if (!(peer instanceof LWWindowPeer)) { 176 return; 177 } 178 Object platformWindow = ((LWWindowPeer) peer).getPlatformWindow(); 179 if (!(platformWindow instanceof CPlatformWindow)) { 180 return; 181 } 182 ((CPlatformWindow) platformWindow).toggleFullScreen(); 183 } 184 185 @Override 186 public FileManager getFileManager() { 187 return fileManager; 188 } 189 190 private static class CFileManager extends FileManager { 191 192 @Override 193 public int OSTypeToInt(String type) { 194 return com.apple.eio.FileManager.OSTypeToInt(type); 195 } 196 197 @Override 198 public void setFileTypeAndCreator(String filename, int type, int creator) 199 throws IOException { 200 com.apple.eio.FileManager.setFileTypeAndCreator(filename, type, creator); 201 } 202 203 @Override 204 public void setFileType(String filename, int type) throws IOException { 205 com.apple.eio.FileManager.setFileType(filename, type); 206 } 207 208 @Override 209 public void setFileCreator(String filename, int creator) throws IOException { 210 com.apple.eio.FileManager.setFileCreator(filename, creator); 211 } 212 213 @Override 214 public int getFileType(String filename) throws IOException { 215 return com.apple.eio.FileManager.getFileType(filename); 216 } 217 218 @Override 219 public int getFileCreator(String filename) throws IOException { 220 return com.apple.eio.FileManager.getFileCreator(filename); 221 } 222 223 @Override 224 public String findFolder(int folderType) throws FileNotFoundException { 225 return com.apple.eio.FileManager.findFolder(folderType); 226 } 227 228 @Override 229 public String findFolder(short domain, int folderType) 230 throws FileNotFoundException { 231 return com.apple.eio.FileManager.findFolder(domain, folderType); 232 } 233 234 @Override 235 public String findFolder(short domain, int folderType, boolean createIfNeeded) 236 throws FileNotFoundException { 237 return com.apple.eio.FileManager.findFolder(domain, folderType, createIfNeeded); 238 } 239 240 @Override 241 public String getResource(String resourceName) throws FileNotFoundException { 242 return com.apple.eio.FileManager.getResource(resourceName); 243 } 244 245 @Override 246 public String getResource(String resourceName, String subDirName) 247 throws FileNotFoundException { 248 return com.apple.eio.FileManager.getResource(resourceName, subDirName); 249 } 250 251 @Override 252 public String getResource(String resourceName, String subDirName, String type) 253 throws FileNotFoundException { 254 return com.apple.eio.FileManager.getResource(resourceName, subDirName, type); 255 } 256 257 @Override 258 public String getPathToApplicationBundle() { 259 return com.apple.eio.FileManager.getPathToApplicationBundle(); 260 } 261 262 @Override 263 public boolean moveToTrash(File file) throws FileNotFoundException { 264 return com.apple.eio.FileManager.moveToTrash(file); 265 } 266 267 @Override 268 public boolean revealInFinder(File file) throws FileNotFoundException { 269 return com.apple.eio.FileManager.revealInFinder(file); 270 } 271 272 } 273 274 private void lsOpen(URI uri) throws IOException { 275 int status = _lsOpenURI(uri.toString()); 276 277 if (status != 0 /* noErr */) { 278 throw new IOException("Failed to mail or browse " + uri + ". Error code: " + status); 279 } 280 } 281 282 private void lsOpenFile(File file, boolean print) throws IOException { 283 int status = _lsOpenFile(file.getCanonicalPath(), print); 284 285 if (status != 0 /* noErr */) { 286 throw new IOException("Failed to open, edit or print " + file + ". Error code: " + status); 287 } 288 } 289 290 private static native int _lsOpenURI(String uri); 291 |