< prev index next >

src/java.desktop/share/classes/java/awt/Taskbar.java

Print this page




 162     public boolean isSupported(Feature feature) {
 163         return peer.isSupported(feature);
 164     }
 165 
 166     /**
 167      * Checks if the feature type is supported.
 168      *
 169      * @param featureType the action type in question
 170      * @throws UnsupportedOperationException if the specified action type is not
 171      *         supported on the current platform
 172      */
 173     private void checkFeatureSupport(Feature featureType){
 174         if (!isSupported(featureType)) {
 175             throw new UnsupportedOperationException("The " + featureType.name()
 176                     + " feature is not supported on the current platform!");
 177         }
 178     }
 179 
 180     /**
 181      *  Calls to the security manager's {@code checkPermission} method with
 182      *  an {@code AWTPermission("showWindowWithoutWarningBanner")}
 183      *  permission.

 184      */
 185     private void checkAWTPermission(){
 186         SecurityManager sm = System.getSecurityManager();
 187         if (sm != null) {
 188             sm.checkPermission(new AWTPermission(


 189                     "showWindowWithoutWarningBanner"));
 190         }
 191     }
 192 
 193     private Taskbar() {
 194         Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
 195         if (defaultToolkit instanceof SunToolkit) {
 196             peer = ((SunToolkit) defaultToolkit).createTaskbarPeer(this);
 197         }
 198     }
 199 
 200     /**
 201      * Returns the {@code Taskbar} instance of the current
 202      * taskbar context.  On some platforms the Taskbar API may not be
 203      * supported; use the {@link #isTaskbarSupported} method to
 204      * determine if the current taskbar is supported.
 205      * @return the Taskbar instance
 206      * @throws HeadlessException if {@link
 207      * GraphicsEnvironment#isHeadless()} returns {@code true}
 208      * @throws UnsupportedOperationException if this class is not


 245         }
 246         return false;
 247     }
 248 
 249     /**
 250      * Requests user attention to this application.
 251      *
 252      * Depending on the platform, this may be visually indicated by a bouncing
 253      * or flashing icon in the task area. It may have no effect on an already active
 254      * application.
 255      *
 256      * On some platforms (e.g. Mac OS) this effect may disappear upon app activation
 257      * and cannot be dismissed by setting {@code enabled} to false.
 258      * Other platforms may require an additional call
 259      * {@link #requestUserAttention} to dismiss this request
 260      * with {@code enabled} parameter set to false.
 261      *
 262      * @param enabled disables this request if false
 263      * @param critical if this is an important request
 264      * @throws SecurityException if a security manager exists and it denies the
 265      * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.

 266      * @throws UnsupportedOperationException if the current platform
 267      * does not support the {@link Taskbar.Feature#USER_ATTENTION} feature
 268      */
 269     public void requestUserAttention(final boolean enabled, final boolean critical) {
 270         checkAWTPermission();
 271         checkFeatureSupport(Feature.USER_ATTENTION);
 272         peer.requestUserAttention(enabled, critical);
 273     }
 274 
 275     /**
 276      * Requests user attention to the specified window until it is activated.
 277      *
 278      * On an already active window requesting attention does nothing.
 279      *
 280      * @param w window
 281      * @throws SecurityException if a security manager exists and it denies the
 282      * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.

 283      * @throws UnsupportedOperationException if the current platform
 284      * does not support the {@link Taskbar.Feature#USER_ATTENTION_WINDOW} feature
 285      */
 286     public void requestWindowUserAttention(Window w) {
 287         checkAWTPermission();
 288         checkFeatureSupport(Feature.USER_ATTENTION_WINDOW);
 289         peer.requestWindowUserAttention(w);
 290     }
 291 
 292     /**
 293      * Attaches the contents of the provided PopupMenu to the application icon
 294      * in the task area.
 295      *
 296      * @param menu the PopupMenu to attach to this application
 297      * @throws SecurityException if a security manager exists and it denies the
 298      * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.

 299      * @throws UnsupportedOperationException if the current platform
 300      * does not support the {@link Taskbar.Feature#MENU} feature
 301      */
 302     public void setMenu(final PopupMenu menu) {
 303         checkAWTPermission();
 304         checkFeatureSupport(Feature.MENU);
 305         peer.setMenu(menu);
 306     }
 307 
 308     /**
 309      * Gets PopupMenu used to add items to this application's icon in system task area.
 310      *
 311      * @return the PopupMenu
 312      * @throws SecurityException if a security manager exists and it denies the
 313      * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.

 314      * @throws UnsupportedOperationException if the current platform
 315      * does not support the {@link Taskbar.Feature#MENU} feature
 316      */
 317     public PopupMenu getMenu() {
 318         checkAWTPermission();
 319         checkFeatureSupport(Feature.MENU);
 320         return peer.getMenu();
 321     }
 322 
 323     /**
 324      * Changes this application's icon to the provided image.
 325      *
 326      * @param image to change
 327      * @throws SecurityException if a security manager exists and it denies the
 328      * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.

 329      * @throws UnsupportedOperationException if the current platform
 330      * does not support the {@link Taskbar.Feature#ICON_IMAGE} feature
 331      */
 332     public void setIconImage(final Image image) {
 333         checkAWTPermission();
 334         checkFeatureSupport(Feature.ICON_IMAGE);
 335         peer.setIconImage(image);
 336     }
 337 
 338     /**
 339      * Obtains an image of this application's icon.
 340      *
 341      * @return an image of this application's icon
 342      * @throws SecurityException if a security manager exists and it denies the
 343      * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.

 344      * @throws UnsupportedOperationException if the current platform
 345      * does not support the {@link Taskbar.Feature#ICON_IMAGE} feature
 346      */
 347     public Image getIconImage() {
 348         checkAWTPermission();
 349         checkFeatureSupport(Feature.ICON_IMAGE);
 350         return peer.getIconImage();
 351     }
 352 
 353     /**
 354      * Affixes a small system-provided badge to this application's icon.
 355      * Usually a number.
 356      *
 357      * Some platforms do not support string values and accept only integer
 358      * values. In this case, pass an integer represented as a string as parameter.
 359      * This can be tested by {@code Feature.ICON_BADGE_TEXT} and
 360      * {@code Feature.ICON_BADGE_NUMBER}.
 361      *
 362      * Passing {@code null} as parameter hides the badge.
 363      * @param badge label to affix to the icon
 364      * @throws SecurityException if a security manager exists and it denies the
 365      * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.

 366      * @throws UnsupportedOperationException if the current platform
 367      * does not support the {@link Taskbar.Feature#ICON_BADGE_NUMBER}
 368      * or {@link Taskbar.Feature#ICON_BADGE_TEXT} feature
 369      */
 370     public void setIconBadge(final String badge) {
 371         checkAWTPermission();
 372         checkFeatureSupport(Feature.ICON_BADGE_NUMBER);
 373         peer.setIconBadge(badge);
 374     }
 375 
 376     /**
 377      * Affixes a small badge to this application's icon in the task area
 378      * for the specified window.
 379      * It may be disabled by system settings.
 380      *
 381      * @param w window to update
 382      * @param badge image to affix to the icon
 383      * @throws SecurityException if a security manager exists and it denies the
 384      * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.

 385      * @throws UnsupportedOperationException if the current platform
 386      * does not support the {@link Taskbar.Feature#ICON_BADGE_IMAGE_WINDOW} feature
 387      */
 388     public void setWindowIconBadge(Window w, final Image badge) {
 389         checkAWTPermission();
 390         checkFeatureSupport(Feature.ICON_BADGE_IMAGE_WINDOW);
 391         if (w != null) {
 392             peer.setWindowIconBadge(w, badge);
 393         }
 394     }
 395 
 396 
 397     /**
 398      * Affixes a small system-provided progress bar to this application's icon.
 399      *
 400      * @param value from 0 to 100, other to disable progress indication



 401      * @throws UnsupportedOperationException if the current platform
 402      * does not support the {@link Taskbar.Feature#PROGRESS_VALUE} feature
 403      */
 404     public void setProgressValue(int value) {
 405         checkAWTPermission();
 406         checkFeatureSupport(Feature.PROGRESS_VALUE);
 407         peer.setProgressValue(value);
 408     }
 409 
 410     /**
 411      * Displays progress for specified window.
 412      *
 413      * @param w window to update
 414      * @param value from 0 to 100, other to disable progress indication
 415      * @throws SecurityException if a security manager exists and it denies the
 416      * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.

 417      * @throws UnsupportedOperationException if the current platform
 418      * does not support the {@link Taskbar.Feature#PROGRESS_VALUE_WINDOW} feature
 419      */
 420     public void setWindowProgressValue(Window w, int value) {
 421         checkAWTPermission();
 422         checkFeatureSupport(Feature.PROGRESS_VALUE_WINDOW);
 423         if (w != null) {
 424             peer.setWindowProgressValue(w, value);
 425         }
 426     }
 427 
 428     /**
 429      * Sets a progress state for a specified window.
 430      *
 431      * @param w window
 432      * @param state to change to
 433      * @see State#OFF
 434      * @see State#NORMAL
 435      * @see State#PAUSED
 436      * @see State#INDETERMINATE
 437      * @see State#ERROR
 438      * @throws SecurityException if a security manager exists and it denies the
 439      * {@code AWTPermission("showWindowWithoutWarningBanner")} permission.

 440      * @throws UnsupportedOperationException if the current platform
 441      * does not support the {@link Taskbar.Feature#PROGRESS_STATE_WINDOW} feature
 442      */
 443     public void setWindowProgressState(Window w, State state) {
 444         checkAWTPermission();
 445         checkFeatureSupport(Feature.PROGRESS_STATE_WINDOW);
 446         if (w != null) {
 447             peer.setWindowProgressState(w, state);
 448         }
 449     }
 450 }


 162     public boolean isSupported(Feature feature) {
 163         return peer.isSupported(feature);
 164     }
 165 
 166     /**
 167      * Checks if the feature type is supported.
 168      *
 169      * @param featureType the action type in question
 170      * @throws UnsupportedOperationException if the specified action type is not
 171      *         supported on the current platform
 172      */
 173     private void checkFeatureSupport(Feature featureType){
 174         if (!isSupported(featureType)) {
 175             throw new UnsupportedOperationException("The " + featureType.name()
 176                     + " feature is not supported on the current platform!");
 177         }
 178     }
 179 
 180     /**
 181      *  Calls to the security manager's {@code checkPermission} method with
 182      *  an {@code AWTPermission("showWindowWithoutWarningBanner")} and an
 183      *  {@code AWTPermission("canProcessApplicationEvents")}
 184      *  permissions.
 185      */
 186     private void checkPermissions(){
 187         SecurityManager sm = System.getSecurityManager();
 188         if (sm != null) {
 189             sm.checkPermission(new AWTPermission(
 190                     "canProcessApplicationEvents"));
 191             sm.checkPermission(new AWTPermission(
 192                     "showWindowWithoutWarningBanner"));
 193         }
 194     }
 195     
 196     private Taskbar() {
 197         Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
 198         if (defaultToolkit instanceof SunToolkit) {
 199             peer = ((SunToolkit) defaultToolkit).createTaskbarPeer(this);
 200         }
 201     }
 202 
 203     /**
 204      * Returns the {@code Taskbar} instance of the current
 205      * taskbar context.  On some platforms the Taskbar API may not be
 206      * supported; use the {@link #isTaskbarSupported} method to
 207      * determine if the current taskbar is supported.
 208      * @return the Taskbar instance
 209      * @throws HeadlessException if {@link
 210      * GraphicsEnvironment#isHeadless()} returns {@code true}
 211      * @throws UnsupportedOperationException if this class is not


 248         }
 249         return false;
 250     }
 251 
 252     /**
 253      * Requests user attention to this application.
 254      *
 255      * Depending on the platform, this may be visually indicated by a bouncing
 256      * or flashing icon in the task area. It may have no effect on an already active
 257      * application.
 258      *
 259      * On some platforms (e.g. Mac OS) this effect may disappear upon app activation
 260      * and cannot be dismissed by setting {@code enabled} to false.
 261      * Other platforms may require an additional call
 262      * {@link #requestUserAttention} to dismiss this request
 263      * with {@code enabled} parameter set to false.
 264      *
 265      * @param enabled disables this request if false
 266      * @param critical if this is an important request
 267      * @throws SecurityException if a security manager exists and it denies the
 268      * {@code AWTPermission("showWindowWithoutWarningBanner")} or the
 269      * {@code RuntimePermission("canProcessApplicationEvents")} permission.
 270      * @throws UnsupportedOperationException if the current platform
 271      * does not support the {@link Taskbar.Feature#USER_ATTENTION} feature
 272      */
 273     public void requestUserAttention(final boolean enabled, final boolean critical) {
 274         checkPermissions();
 275         checkFeatureSupport(Feature.USER_ATTENTION);
 276         peer.requestUserAttention(enabled, critical);
 277     }
 278 
 279     /**
 280      * Requests user attention to the specified window until it is activated.
 281      *
 282      * On an already active window requesting attention does nothing.
 283      *
 284      * @param w window
 285      * @throws SecurityException if a security manager exists and it denies the
 286      * {@code AWTPermission("showWindowWithoutWarningBanner")} or the
 287      * {@code RuntimePermission("canProcessApplicationEvents")} permission.
 288      * @throws UnsupportedOperationException if the current platform
 289      * does not support the {@link Taskbar.Feature#USER_ATTENTION_WINDOW} feature
 290      */
 291     public void requestWindowUserAttention(Window w) {
 292         checkPermissions();
 293         checkFeatureSupport(Feature.USER_ATTENTION_WINDOW);
 294         peer.requestWindowUserAttention(w);
 295     }
 296 
 297     /**
 298      * Attaches the contents of the provided PopupMenu to the application icon
 299      * in the task area.
 300      *
 301      * @param menu the PopupMenu to attach to this application
 302      * @throws SecurityException if a security manager exists and it denies the
 303      * {@code AWTPermission("showWindowWithoutWarningBanner")} or the
 304      * {@code RuntimePermission("canProcessApplicationEvents")} permission.
 305      * @throws UnsupportedOperationException if the current platform
 306      * does not support the {@link Taskbar.Feature#MENU} feature
 307      */
 308     public void setMenu(final PopupMenu menu) {
 309         checkPermissions();
 310         checkFeatureSupport(Feature.MENU);
 311         peer.setMenu(menu);
 312     }
 313 
 314     /**
 315      * Gets PopupMenu used to add items to this application's icon in system task area.
 316      *
 317      * @return the PopupMenu
 318      * @throws SecurityException if a security manager exists and it denies the
 319      * {@code AWTPermission("showWindowWithoutWarningBanner")} or the
 320      * {@code RuntimePermission("canProcessApplicationEvents")} permission.
 321      * @throws UnsupportedOperationException if the current platform
 322      * does not support the {@link Taskbar.Feature#MENU} feature
 323      */
 324     public PopupMenu getMenu() {
 325         checkPermissions();
 326         checkFeatureSupport(Feature.MENU);
 327         return peer.getMenu();
 328     }
 329 
 330     /**
 331      * Changes this application's icon to the provided image.
 332      *
 333      * @param image to change
 334      * @throws SecurityException if a security manager exists and it denies the
 335      * {@code AWTPermission("showWindowWithoutWarningBanner")} or the
 336      * {@code RuntimePermission("canProcessApplicationEvents")} permission.
 337      * @throws UnsupportedOperationException if the current platform
 338      * does not support the {@link Taskbar.Feature#ICON_IMAGE} feature
 339      */
 340     public void setIconImage(final Image image) {
 341         checkPermissions();
 342         checkFeatureSupport(Feature.ICON_IMAGE);
 343         peer.setIconImage(image);
 344     }
 345 
 346     /**
 347      * Obtains an image of this application's icon.
 348      *
 349      * @return an image of this application's icon
 350      * @throws SecurityException if a security manager exists and it denies the
 351      * {@code AWTPermission("showWindowWithoutWarningBanner")} or the
 352      * {@code RuntimePermission("canProcessApplicationEvents")} permission.
 353      * @throws UnsupportedOperationException if the current platform
 354      * does not support the {@link Taskbar.Feature#ICON_IMAGE} feature
 355      */
 356     public Image getIconImage() {
 357         checkPermissions();
 358         checkFeatureSupport(Feature.ICON_IMAGE);
 359         return peer.getIconImage();
 360     }
 361 
 362     /**
 363      * Affixes a small system-provided badge to this application's icon.
 364      * Usually a number.
 365      *
 366      * Some platforms do not support string values and accept only integer
 367      * values. In this case, pass an integer represented as a string as parameter.
 368      * This can be tested by {@code Feature.ICON_BADGE_TEXT} and
 369      * {@code Feature.ICON_BADGE_NUMBER}.
 370      *
 371      * Passing {@code null} as parameter hides the badge.
 372      * @param badge label to affix to the icon
 373      * @throws SecurityException if a security manager exists and it denies the
 374      * {@code AWTPermission("showWindowWithoutWarningBanner")} or the
 375      * {@code RuntimePermission("canProcessApplicationEvents")} permission.
 376      * @throws UnsupportedOperationException if the current platform
 377      * does not support the {@link Taskbar.Feature#ICON_BADGE_NUMBER}
 378      * or {@link Taskbar.Feature#ICON_BADGE_TEXT} feature
 379      */
 380     public void setIconBadge(final String badge) {
 381         checkPermissions();
 382         checkFeatureSupport(Feature.ICON_BADGE_NUMBER);
 383         peer.setIconBadge(badge);
 384     }
 385 
 386     /**
 387      * Affixes a small badge to this application's icon in the task area
 388      * for the specified window.
 389      * It may be disabled by system settings.
 390      *
 391      * @param w window to update
 392      * @param badge image to affix to the icon
 393      * @throws SecurityException if a security manager exists and it denies the
 394      * {@code AWTPermission("showWindowWithoutWarningBanner")} or the
 395      * {@code RuntimePermission("canProcessApplicationEvents")} permission.
 396      * @throws UnsupportedOperationException if the current platform
 397      * does not support the {@link Taskbar.Feature#ICON_BADGE_IMAGE_WINDOW} feature
 398      */
 399     public void setWindowIconBadge(Window w, final Image badge) {
 400         checkPermissions();
 401         checkFeatureSupport(Feature.ICON_BADGE_IMAGE_WINDOW);
 402         if (w != null) {
 403             peer.setWindowIconBadge(w, badge);
 404         }
 405     }
 406 
 407 
 408     /**
 409      * Affixes a small system-provided progress bar to this application's icon.
 410      *
 411      * @param value from 0 to 100, other to disable progress indication
 412      * @throws SecurityException if a security manager exists and it denies the
 413      * {@code AWTPermission("showWindowWithoutWarningBanner")} or the
 414      * {@code RuntimePermission("canProcessApplicationEvents")} permission.
 415      * @throws UnsupportedOperationException if the current platform
 416      * does not support the {@link Taskbar.Feature#PROGRESS_VALUE} feature
 417      */
 418     public void setProgressValue(int value) {
 419         checkPermissions();
 420         checkFeatureSupport(Feature.PROGRESS_VALUE);
 421         peer.setProgressValue(value);
 422     }
 423 
 424     /**
 425      * Displays progress for specified window.
 426      *
 427      * @param w window to update
 428      * @param value from 0 to 100, other to disable progress indication
 429      * @throws SecurityException if a security manager exists and it denies the
 430      * {@code AWTPermission("showWindowWithoutWarningBanner")} or the
 431      * {@code RuntimePermission("canProcessApplicationEvents")} permission.
 432      * @throws UnsupportedOperationException if the current platform
 433      * does not support the {@link Taskbar.Feature#PROGRESS_VALUE_WINDOW} feature
 434      */
 435     public void setWindowProgressValue(Window w, int value) {
 436         checkPermissions();
 437         checkFeatureSupport(Feature.PROGRESS_VALUE_WINDOW);
 438         if (w != null) {
 439             peer.setWindowProgressValue(w, value);
 440         }
 441     }
 442 
 443     /**
 444      * Sets a progress state for a specified window.
 445      *
 446      * @param w window
 447      * @param state to change to
 448      * @see State#OFF
 449      * @see State#NORMAL
 450      * @see State#PAUSED
 451      * @see State#INDETERMINATE
 452      * @see State#ERROR
 453      * @throws SecurityException if a security manager exists and it denies the
 454      * {@code AWTPermission("showWindowWithoutWarningBanner")} or the
 455      * {@code RuntimePermission("canProcessApplicationEvents")} permission.
 456      * @throws UnsupportedOperationException if the current platform
 457      * does not support the {@link Taskbar.Feature#PROGRESS_STATE_WINDOW} feature
 458      */
 459     public void setWindowProgressState(Window w, State state) {
 460         checkPermissions();
 461         checkFeatureSupport(Feature.PROGRESS_STATE_WINDOW);
 462         if (w != null) {
 463             peer.setWindowProgressState(w, state);
 464         }
 465     }
 466 }
< prev index next >