< prev index next >

src/java.desktop/macosx/classes/sun/lwawt/macosx/CDesktopPeer.java

Print this page

        

*** 23,72 **** * questions. */ package sun.lwawt.macosx; import java.awt.Desktop.Action; import java.awt.peer.DesktopPeer; import java.io.File; import java.io.IOException; import java.net.URI; /** * Concrete implementation of the interface <code>DesktopPeer</code> for MacOS X * * @see DesktopPeer */ ! public class CDesktopPeer implements DesktopPeer { public boolean isSupported(Action action) { - // OPEN, EDIT, PRINT, MAIL, BROWSE all supported. - // Though we don't really differentiate between OPEN / EDIT return true; } public void open(File file) throws IOException { this.lsOpenFile(file, false); } public void edit(File file) throws IOException { this.lsOpenFile(file, false); } public void print(File file) throws IOException { this.lsOpenFile(file, true); } public void mail(URI uri) throws IOException { this.lsOpen(uri); } public void browse(URI uri) throws IOException { this.lsOpen(uri); } private void lsOpen(URI uri) throws IOException { int status = _lsOpenURI(uri.toString()); if (status != 0 /* noErr */) { throw new IOException("Failed to mail or browse " + uri + ". Error code: " + status); --- 23,278 ---- * questions. */ package sun.lwawt.macosx; + import com.apple.eawt.Application; + import com.apple.eawt.FullScreenUtilities; + import sun.awt.AWTAccessor; + import sun.lwawt.LWWindowPeer; + + import javax.swing.*; + import java.awt.*; import java.awt.Desktop.Action; + import java.awt.desktop.*; + import java.awt.peer.ComponentPeer; import java.awt.peer.DesktopPeer; import java.io.File; + import java.io.FileNotFoundException; import java.io.IOException; import java.net.URI; /** * Concrete implementation of the interface <code>DesktopPeer</code> for MacOS X * * @see DesktopPeer */ ! final public class CDesktopPeer implements DesktopPeer { ! ! private static final CFileManager fileManager = new CFileManager(); + @Override public boolean isSupported(Action action) { return true; } + @Override public void open(File file) throws IOException { this.lsOpenFile(file, false); } + @Override public void edit(File file) throws IOException { this.lsOpenFile(file, false); } + @Override public void print(File file) throws IOException { this.lsOpenFile(file, true); } + @Override public void mail(URI uri) throws IOException { this.lsOpen(uri); } + @Override public void browse(URI uri) throws IOException { this.lsOpen(uri); } + @Override + public void addAppEventListener(SystemEventListener listener) { + Application.getApplication().addAppEventListener(listener); + } + + @Override + public void removeAppEventListener(SystemEventListener listener) { + Application.getApplication().removeAppEventListener(listener); + } + + @Override + public void setAboutHandler(AboutHandler aboutHandler) { + Application.getApplication().setAboutHandler(aboutHandler); + } + + @Override + public void setPreferencesHandler(PreferencesHandler preferencesHandler) { + Application.getApplication().setPreferencesHandler(preferencesHandler); + } + + @Override + public void setOpenFileHandler(OpenFilesHandler openFileHandler) { + Application.getApplication().setOpenFileHandler(openFileHandler); + } + + @Override + public void setPrintFileHandler(PrintFilesHandler printFileHandler) { + Application.getApplication().setPrintFileHandler(printFileHandler); + } + + @Override + public void setOpenURIHandler(OpenURIHandler openURIHandler) { + Application.getApplication().setOpenURIHandler(openURIHandler); + } + + @Override + public void setQuitHandler(QuitHandler quitHandler) { + Application.getApplication().setQuitHandler(quitHandler); + } + + @Override + public void setQuitStrategy(QuitStrategy strategy) { + Application.getApplication().setQuitStrategy(strategy); + } + + @Override + public void enableSuddenTermination() { + Application.getApplication().enableSuddenTermination(); + } + + @Override + public void disableSuddenTermination() { + Application.getApplication().disableSuddenTermination(); + } + + @Override + public void requestForeground(boolean allWindows) { + Application.getApplication().requestForeground(allWindows); + } + + @Override + public void openHelpViewer() { + Application.getApplication().openHelpViewer(); + } + + @Override + public void setDefaultMenuBar(JMenuBar menuBar) { + Application.getApplication().setDefaultMenuBar(menuBar); + } + + @Override + public void addWindowFullScreenListener(final Window window, + final FullScreenListener listener) { + FullScreenUtilities.addFullScreenListenerTo(window, listener); + } + + @Override + public void removeWindowFullScreenListener(final Window window, + final FullScreenListener listener) { + FullScreenUtilities.removeFullScreenListenerFrom(window, listener); + } + + @Override + public void setWindowCanFullScreen(Window window, boolean canFullScreen) { + FullScreenUtilities.setWindowCanFullScreen(window, canFullScreen); + } + + @Override + public void requestToggleFullScreen(Window window) { + final ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(window); + + if (!(peer instanceof LWWindowPeer)) { + return; + } + Object platformWindow = ((LWWindowPeer) peer).getPlatformWindow(); + if (!(platformWindow instanceof CPlatformWindow)) { + return; + } + ((CPlatformWindow) platformWindow).toggleFullScreen(); + } + + @Override + public FileManager getFileManager() { + return fileManager; + } + + private static class CFileManager extends FileManager { + + @Override + public int OSTypeToInt(String type) { + return com.apple.eio.FileManager.OSTypeToInt(type); + } + + @Override + public void setFileTypeAndCreator(String filename, int type, int creator) + throws IOException { + com.apple.eio.FileManager.setFileTypeAndCreator(filename, type, creator); + } + + @Override + public void setFileType(String filename, int type) throws IOException { + com.apple.eio.FileManager.setFileType(filename, type); + } + + @Override + public void setFileCreator(String filename, int creator) throws IOException { + com.apple.eio.FileManager.setFileCreator(filename, creator); + } + + @Override + public int getFileType(String filename) throws IOException { + return com.apple.eio.FileManager.getFileType(filename); + } + + @Override + public int getFileCreator(String filename) throws IOException { + return com.apple.eio.FileManager.getFileCreator(filename); + } + + @Override + public String findFolder(int folderType) throws FileNotFoundException { + return com.apple.eio.FileManager.findFolder(folderType); + } + + @Override + public String findFolder(short domain, int folderType) + throws FileNotFoundException { + return com.apple.eio.FileManager.findFolder(domain, folderType); + } + + @Override + public String findFolder(short domain, int folderType, boolean createIfNeeded) + throws FileNotFoundException { + return com.apple.eio.FileManager.findFolder(domain, folderType, createIfNeeded); + } + + @Override + public String getResource(String resourceName) throws FileNotFoundException { + return com.apple.eio.FileManager.getResource(resourceName); + } + + @Override + public String getResource(String resourceName, String subDirName) + throws FileNotFoundException { + return com.apple.eio.FileManager.getResource(resourceName, subDirName); + } + + @Override + public String getResource(String resourceName, String subDirName, String type) + throws FileNotFoundException { + return com.apple.eio.FileManager.getResource(resourceName, subDirName, type); + } + + @Override + public String getPathToApplicationBundle() { + return com.apple.eio.FileManager.getPathToApplicationBundle(); + } + + @Override + public boolean moveToTrash(File file) throws FileNotFoundException { + return com.apple.eio.FileManager.moveToTrash(file); + } + + @Override + public boolean revealInFinder(File file) throws FileNotFoundException { + return com.apple.eio.FileManager.revealInFinder(file); + } + + } + private void lsOpen(URI uri) throws IOException { int status = _lsOpenURI(uri.toString()); if (status != 0 /* noErr */) { throw new IOException("Failed to mail or browse " + uri + ". Error code: " + status);
< prev index next >