< prev index next >

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

Print this page




 179 
 180     /**
 181      *  Calls to the security manager's {@code checkPermission} method with
 182      *  an {@code RuntimePermission("canProcessApplicationEvents")} permissions.
 183      */
 184     private void checkEventsProcessingPermission(){
 185         SecurityManager sm = System.getSecurityManager();
 186         if (sm != null) {
 187             sm.checkPermission(new RuntimePermission(
 188                     "canProcessApplicationEvents"));
 189         }
 190     }
 191 
 192     private Taskbar() {
 193         Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
 194         if (defaultToolkit instanceof SunToolkit) {
 195             peer = ((SunToolkit) defaultToolkit).createTaskbarPeer(this);
 196         }
 197     }
 198 


 199     /**
 200      * Returns the {@code Taskbar} instance of the current
 201      * taskbar context.  On some platforms the Taskbar API may not be
 202      * supported; use the {@link #isTaskbarSupported} method to
 203      * determine if the current taskbar is supported.
 204      * @return the Taskbar instance
 205      * @throws HeadlessException if {@link
 206      * GraphicsEnvironment#isHeadless()} returns {@code true}
 207      * @throws UnsupportedOperationException if this class is not
 208      * supported on the current platform
 209      * @see #isTaskbarSupported()
 210      * @see java.awt.GraphicsEnvironment#isHeadless
 211      */
 212     public static synchronized Taskbar getTaskbar(){
 213         if (GraphicsEnvironment.isHeadless()) throw new HeadlessException();
 214 
 215         if (!Taskbar.isTaskbarSupported()) {
 216             throw new UnsupportedOperationException("Taskbar API is not " +
 217                                                     "supported on the current platform");
 218         }
 219 

 220         sun.awt.AppContext context = sun.awt.AppContext.getAppContext();
 221         Taskbar taskbar = (Taskbar)context.get(Taskbar.class);



 222 
 223         if (taskbar == null) {
 224             taskbar = new Taskbar();

 225             context.put(Taskbar.class, taskbar);



 226         }
 227 
 228         return taskbar;
 229     }
 230 
 231     /**
 232      * Tests whether this class is supported on the current platform.
 233      * If it's supported, use {@link #getTaskbar()} to retrieve an
 234      * instance.
 235      *
 236      * @return {@code true} if this class is supported on the
 237      *         current platform; {@code false} otherwise
 238      * @see #getTaskbar()
 239      */
 240     public static boolean isTaskbarSupported(){
 241         Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
 242         if (defaultToolkit instanceof SunToolkit) {
 243             return ((SunToolkit)defaultToolkit).isTaskbarSupported();
 244         }
 245         return false;




 179 
 180     /**
 181      *  Calls to the security manager's {@code checkPermission} method with
 182      *  an {@code RuntimePermission("canProcessApplicationEvents")} permissions.
 183      */
 184     private void checkEventsProcessingPermission(){
 185         SecurityManager sm = System.getSecurityManager();
 186         if (sm != null) {
 187             sm.checkPermission(new RuntimePermission(
 188                     "canProcessApplicationEvents"));
 189         }
 190     }
 191 
 192     private Taskbar() {
 193         Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
 194         if (defaultToolkit instanceof SunToolkit) {
 195             peer = ((SunToolkit) defaultToolkit).createTaskbarPeer(this);
 196         }
 197     }
 198 
 199     private static Taskbar taskbar;
 200 
 201     /**
 202      * Returns the {@code Taskbar} instance of the current
 203      * taskbar context.  On some platforms the Taskbar API may not be
 204      * supported; use the {@link #isTaskbarSupported} method to
 205      * determine if the current taskbar is supported.
 206      * @return the Taskbar instance
 207      * @throws HeadlessException if {@link
 208      * GraphicsEnvironment#isHeadless()} returns {@code true}
 209      * @throws UnsupportedOperationException if this class is not
 210      * supported on the current platform
 211      * @see #isTaskbarSupported()
 212      * @see java.awt.GraphicsEnvironment#isHeadless
 213      */
 214     public static synchronized Taskbar getTaskbar(){
 215         if (GraphicsEnvironment.isHeadless()) throw new HeadlessException();
 216 
 217         if (!Taskbar.isTaskbarSupported()) {
 218             throw new UnsupportedOperationException("Taskbar API is not " +
 219                                                     "supported on the current platform");
 220         }
 221 
 222         Taskbar taskbar = null;
 223         sun.awt.AppContext context = sun.awt.AppContext.getAppContext();
 224 
 225         taskbar = (context == null)
 226                 ? Taskbar.taskbar
 227                 : (Taskbar)context.get(Taskbar.class);
 228 
 229         if (taskbar == null) {
 230             taskbar = new Taskbar();
 231             if (context != null) {
 232                 context.put(Taskbar.class, taskbar);
 233             } else {
 234                 Taskbar.taskbar = taskbar;
 235             }
 236         }
 237 
 238         return taskbar;
 239     }
 240 
 241     /**
 242      * Tests whether this class is supported on the current platform.
 243      * If it's supported, use {@link #getTaskbar()} to retrieve an
 244      * instance.
 245      *
 246      * @return {@code true} if this class is supported on the
 247      *         current platform; {@code false} otherwise
 248      * @see #getTaskbar()
 249      */
 250     public static boolean isTaskbarSupported(){
 251         Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
 252         if (defaultToolkit instanceof SunToolkit) {
 253             return ((SunToolkit)defaultToolkit).isTaskbarSupported();
 254         }
 255         return false;


< prev index next >