1 /*
   2  * Copyright (c) 2015, 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 java.awt;
  27 
  28 import java.awt.desktop.*;
  29 import java.io.File;
  30 import java.net.URI;
  31 import java.util.EventObject;
  32 import java.util.List;
  33 
  34 /**
  35  * AppEvents are sent to listeners and handlers installed on the {@link Desktop}.
  36  * 
  37  * @since 1.9
  38  */
  39 @SuppressWarnings("serial") // JDK implementation class
  40 public class AppEvent extends EventObject {
  41 
  42     AppEvent() {
  43         super(Desktop.getDesktop());
  44     }
  45 
  46     /**
  47      * Contains a list of files.
  48      */
  49     @SuppressWarnings("serial") // JDK implementation class
  50     public static class FilesEvent extends AppEvent {
  51         final List<File> files;
  52 
  53         FilesEvent(final List<File> files) {
  54             this.files = files;
  55         }
  56 
  57         /**
  58          * @return the list of files
  59          */
  60         public List<File> getFiles() {
  61             return files;
  62         }
  63     }
  64 
  65     /**
  66      * Event sent when the app is asked to open a list of files.
  67      *
  68      * @see OpenFilesHandler#openFiles
  69      */
  70     @SuppressWarnings("serial") // JDK implementation class
  71     public static class OpenFilesEvent extends FilesEvent {
  72         final String searchTerm;
  73 
  74         /**
  75          * @param files files
  76          * @param searchTerm searchTerm
  77          */
  78         public OpenFilesEvent(final List<File> files, final String searchTerm) {
  79             super(files);
  80             this.searchTerm = searchTerm;
  81         }
  82 
  83         /**
  84          * Gets the search term. The platform may additionally provide the search
  85          * term that was used to find the files. This is for example the case
  86          * on Mac OS X, when the files were opened using the Spotlight search
  87          * menu or a Finder search window.
  88          *
  89          * This is useful for highlighting the search term in the documents when
  90          * they are opened.
  91          * @return the search term used to find the files
  92          */
  93         public String getSearchTerm() {
  94             return searchTerm;
  95         }
  96     }
  97 
  98     /**
  99      * Event sent when the app is asked to print a list of files.
 100      *
 101      * @see PrintFilesHandler#printFiles(AppEvent.PrintFilesEvent)
 102      */
 103     @SuppressWarnings("serial") // JDK implementation class
 104     public static class PrintFilesEvent extends FilesEvent {
 105 
 106         /**
 107          * @param files files
 108          */
 109         public PrintFilesEvent(final List<File> files) {
 110             super(files);
 111         }
 112     }
 113 
 114     /**
 115      * Event sent when the app is asked to open a URI.
 116      *
 117      * @see OpenURIHandler#openURI(AppEvent.OpenURIEvent)
 118      */
 119     @SuppressWarnings("serial") // JDK implementation class
 120     public static class OpenURIEvent extends AppEvent {
 121         final URI uri;
 122 
 123         /**
 124          * @param uri uri
 125          */
 126         public OpenURIEvent(final URI uri) {
 127             this.uri = uri;
 128         }
 129 
 130         /**
 131          * @return the URI the app was asked to open
 132          */
 133         public URI getURI() {
 134             return uri;
 135         }
 136     }
 137 
 138     /**
 139      * Event sent when the application is asked to open its about window.
 140      *
 141      * @see AboutHandler#handleAbout
 142      */
 143     @SuppressWarnings("serial") // JDK implementation class
 144     public static class AboutEvent extends AppEvent {
 145 
 146         /**
 147          *
 148          */
 149         public AboutEvent() {}
 150     }
 151 
 152     /**
 153      * Event sent when the application is asked to open its preferences window.
 154      *
 155      * @see PreferencesHandler#handlePreferences
 156      */
 157     @SuppressWarnings("serial") // JDK implementation class
 158     public static class PreferencesEvent extends AppEvent {
 159 
 160         /**
 161          *
 162          */
 163         public PreferencesEvent() {}
 164     }
 165 
 166     /**
 167      * Event sent when the application is asked to quit.
 168      *
 169      * @see QuitHandler#handleQuitRequestWith(AppEvent.QuitEvent, QuitResponse)
 170      */
 171     @SuppressWarnings("serial") // JDK implementation class
 172     public static class QuitEvent extends AppEvent {
 173 
 174         /**
 175          *
 176          */
 177         public QuitEvent() {}
 178     }
 179 
 180     /**
 181      * Event sent when the application is asked to re-open itself.
 182      *
 183      * @see AppReopenedListener#appReopened(AppEvent.AppReopenedEvent)
 184      */
 185     @SuppressWarnings("serial") // JDK implementation class
 186     public static class AppReopenedEvent extends AppEvent {
 187 
 188         /**
 189          *
 190          */
 191         public AppReopenedEvent() { }
 192     }
 193 
 194     /**
 195      * Event sent when the application has become the foreground app, and when it has resigned being the foreground app.
 196      *
 197      * @see AppForegroundListener#appRaisedToForeground(AppEvent.AppForegroundEvent)
 198      * @see AppForegroundListener#appMovedToBackground(AppEvent.AppForegroundEvent)
 199      */
 200     @SuppressWarnings("serial") // JDK implementation class
 201     public static class AppForegroundEvent extends AppEvent {
 202 
 203         /**
 204          *
 205          */
 206         public AppForegroundEvent() { }
 207     }
 208 
 209     /**
 210      * Event sent when the application has been hidden or shown.
 211      *
 212      * @see AppHiddenListener#appHidden(AppEvent.AppHiddenEvent)
 213      * @see AppHiddenListener#appUnhidden(AppEvent.AppHiddenEvent)
 214      */
 215     @SuppressWarnings("serial") // JDK implementation class
 216     public static class AppHiddenEvent extends AppEvent {
 217 
 218         /**
 219          *
 220          */
 221         public AppHiddenEvent() { }
 222     }
 223 
 224     /**
 225      * Event sent when the user session has been changed via Fast User Switching.
 226      *
 227      * @see UserSessionListener#userSessionActivated(AppEvent.UserSessionEvent)
 228      * @see UserSessionListener#userSessionDeactivated(AppEvent.UserSessionEvent)
 229      */
 230     @SuppressWarnings("serial") // JDK implementation class
 231     public static class UserSessionEvent extends AppEvent {
 232 
 233         /**
 234          *
 235          */
 236         public UserSessionEvent() { }
 237     }
 238 
 239     /**
 240      * Event sent when the displays attached to the system enter and exit power save sleep.
 241      *
 242      * @see ScreenSleepListener#screenAboutToSleep(AppEvent.ScreenSleepEvent)
 243      * @see ScreenSleepListener#screenAwoke(AppEvent.ScreenSleepEvent)
 244      */
 245     @SuppressWarnings("serial") // JDK implementation class
 246     public static class ScreenSleepEvent extends AppEvent {
 247 
 248         /**
 249          *
 250          */
 251         public ScreenSleepEvent() { }
 252     }
 253 
 254     /**
 255      * Event sent when the system enters and exits power save sleep.
 256      *
 257      * @see SystemSleepListener#systemAboutToSleep(AppEvent.SystemSleepEvent)
 258      * @see SystemSleepListener#systemAwoke(AppEvent.SystemSleepEvent)
 259      */
 260     @SuppressWarnings("serial") // JDK implementation class
 261     public static class SystemSleepEvent extends AppEvent {
 262 
 263         /**
 264          *
 265          */
 266         public SystemSleepEvent() { }
 267     }
 268 
 269     /**
 270      * Event sent when a window is entering/exiting or has entered/exited full screen state.
 271      */
 272     @SuppressWarnings("serial") // JDK implementation class
 273     public static class FullScreenEvent extends AppEvent {
 274         final Window window;
 275 
 276         /**
 277          * @param window window
 278          */
 279         public FullScreenEvent(final Window window) {
 280             this.window = window;
 281         }
 282 
 283         /**
 284          * @return window transitioning between full screen states
 285          */
 286         public Window getWindow() {
 287             return window;
 288         }
 289     }
 290 }