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