1 /* 2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 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 com.apple.eawt; 27 28 import java.io.File; 29 import java.net.URI; 30 import java.util.*; 31 import java.awt.Window; 32 33 /** 34 * AppEvents are sent to listeners and handlers installed on the {@link Application}. 35 * 36 * @since Java for Mac OS X 10.6 Update 3 37 * @since Java for Mac OS X 10.5 Update 8 38 */ 39 public abstract class AppEvent extends EventObject { 40 AppEvent() { 41 super(Application.getApplication()); 42 } 43 44 /** 45 * Contains a list of files. 46 */ 47 public abstract static class FilesEvent extends AppEvent { 48 final List<File> files; 49 50 FilesEvent(final List<File> files) { 51 this.files = files; 52 } 53 54 /** 55 * @return the list of files 56 */ 57 public List<File> getFiles() { 58 return files; 59 } 60 } 61 62 /** 63 * Event sent when the app is asked to open a list of files. 64 * 65 * @see OpenFilesHandler#openFiles(OpenFilesEvent) 66 */ 67 public static class OpenFilesEvent extends FilesEvent { 68 final String searchTerm; 69 70 OpenFilesEvent(final List<File> files, final String searchTerm) { 71 super(files); 72 this.searchTerm = searchTerm; 73 } 74 75 /** 76 * If the files were opened using the Spotlight search menu or a Finder search window, this method obtains the search term used to find the files. 77 * This is useful for highlighting the search term in the documents when they are opened. 78 * @return the search term used to find the files 79 */ 80 public String getSearchTerm() { 81 return searchTerm; 82 } 83 } 84 85 /** 86 * Event sent when the app is asked to print a list of files. 87 * 88 * @see PrintFilesHandler#printFiles(PrintFilesEvent) 89 */ 90 public static class PrintFilesEvent extends FilesEvent { 91 PrintFilesEvent(final List<File> files) { 92 super(files); 93 } 94 } 95 96 /** 97 * Event sent when the app is asked to open a URI. 98 * 99 * @see OpenURIHandler#openURI(OpenURIEvent) 100 */ 101 public static class OpenURIEvent extends AppEvent { 102 final URI uri; 103 104 OpenURIEvent(final URI uri) { 105 this.uri = uri; 106 } 107 108 /** 109 * @return the URI the app was asked to open 110 */ 111 public URI getURI() { 112 return uri; 113 } 114 } 115 116 /** 117 * Event sent when the application is asked to open it's about window. 118 * 119 * @see AboutHandler#handleAbout() 120 */ 121 public static class AboutEvent extends AppEvent { AboutEvent() { } } 122 123 /** 124 * Event sent when the application is asked to open it's preferences window. 125 * 126 * @see PreferencesHandler#handlePreferences() 127 */ 128 public static class PreferencesEvent extends AppEvent { PreferencesEvent() { } } 129 130 /** 131 * Event sent when the application is asked to quit. 132 * 133 * @see QuitHandler#handleQuitRequestWith(QuitEvent, QuitResponse) 134 */ 135 public static class QuitEvent extends AppEvent { QuitEvent() { } } 136 137 /** 138 * Event sent when the application is asked to re-open itself. 139 * 140 * @see AppReOpenedListener#appReOpened(AppReOpenedEvent) 141 */ 142 public static class AppReOpenedEvent extends AppEvent { AppReOpenedEvent() { } } 143 144 /** 145 * Event sent when the application has become the foreground app, and when it has resigned being the foreground app. 146 * 147 * @see AppForegroundListener#appRaisedToForeground(AppForegroundEvent) 148 * @see AppForegroundListener#appMovedToBackground(AppForegroundEvent) 149 */ 150 public static class AppForegroundEvent extends AppEvent { AppForegroundEvent() { } } 151 152 /** 153 * Event sent when the application has been hidden or shown. 154 * 155 * @see AppHiddenListener#appHidden(AppHiddenEvent) 156 * @see AppHiddenListener#appUnhidden(AppHiddenEvent) 157 */ 158 public static class AppHiddenEvent extends AppEvent { AppHiddenEvent() { } } 159 160 /** 161 * Event sent when the user session has been changed via Fast User Switching. 162 * 163 * @see UserSessionListener#userSessionActivated(UserSessionEvent) 164 * @see UserSessionListener#userSessionDeactivated(UserSessionEvent) 165 */ 166 public static class UserSessionEvent extends AppEvent { UserSessionEvent() { } } 167 168 /** 169 * Event sent when the displays attached to the system enter and exit power save sleep. 170 * 171 * @see ScreenSleepListener#screenAboutToSleep(ScreenSleepEvent) 172 * @see ScreenSleepListener#screenAwoke(ScreenSleepEvent) 173 */ 174 public static class ScreenSleepEvent extends AppEvent { ScreenSleepEvent() { } } 175 176 /** 177 * Event sent when the system enters and exits power save sleep. 178 * 179 * @see SystemSleepListener#systemAboutToSleep(SystemSleepEvent) 180 * @see SystemSleepListener#systemAwoke(SystemSleepEvent) 181 */ 182 public static class SystemSleepEvent extends AppEvent { SystemSleepEvent() { } } 183 184 /** 185 * Event sent when a window is entering/exiting or has entered/exited full screen state. 186 * 187 * @see FullScreenUtilities 188 * 189 * @since Java for Mac OS X 10.7 Update 1 190 */ 191 public static class FullScreenEvent extends AppEvent { 192 final Window window; 193 194 FullScreenEvent(final Window window) { 195 this.window = window; 196 } 197 198 /** 199 * @return window transitioning between full screen states 200 */ 201 public Window getWindow() { 202 return window; 203 } 204 } 205 }