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