jdk/src/share/classes/java/awt/Window.java

Print this page

        

@@ -439,11 +439,11 @@
     }
 
     transient Object anchor = new Object();
     static class WindowDisposerRecord implements sun.java2d.DisposerRecord {
         final WeakReference<Window> owner;
-        final WeakReference weakThis;
+        final WeakReference<Window> weakThis;
         final WeakReference<AppContext> context;
         WindowDisposerRecord(AppContext context, Window victim) {
             owner = new WeakReference<Window>(victim.getOwner());
             weakThis = victim.weakThis;
             this.context = new WeakReference<AppContext>(context);

@@ -1540,10 +1540,11 @@
     }
 
     private static Window[] getWindows(AppContext appContext) {
         synchronized (Window.class) {
             Window realCopy[];
+            @SuppressWarnings("unchecked")
             Vector<WeakReference<Window>> windowList =
                 (Vector<WeakReference<Window>>)appContext.get(Window.class);
             if (windowList != null) {
                 int fullSize = windowList.size();
                 int realSize = 0;

@@ -1864,11 +1865,11 @@
      * @see #addWindowListener
      * @see #removeWindowListener
      * @since 1.4
      */
     public synchronized WindowListener[] getWindowListeners() {
-        return (WindowListener[])(getListeners(WindowListener.class));
+        return getListeners(WindowListener.class);
     }
 
     /**
      * Returns an array of all the window focus listeners
      * registered on this window.

@@ -1880,11 +1881,11 @@
      * @see #addWindowFocusListener
      * @see #removeWindowFocusListener
      * @since 1.4
      */
     public synchronized WindowFocusListener[] getWindowFocusListeners() {
-        return (WindowFocusListener[])(getListeners(WindowFocusListener.class));
+        return getListeners(WindowFocusListener.class);
     }
 
     /**
      * Returns an array of all the window state listeners
      * registered on this window.

@@ -1896,11 +1897,11 @@
      * @see #addWindowStateListener
      * @see #removeWindowStateListener
      * @since 1.4
      */
     public synchronized WindowStateListener[] getWindowStateListeners() {
-        return (WindowStateListener[])(getListeners(WindowStateListener.class));
+        return getListeners(WindowStateListener.class);
     }
 
 
     /**
      * Returns an array of all the objects currently registered

@@ -2012,11 +2013,10 @@
                 case WindowEvent.WINDOW_LOST_FOCUS:
                     processWindowFocusEvent((WindowEvent)e);
                     break;
                 case WindowEvent.WINDOW_STATE_CHANGED:
                     processWindowStateEvent((WindowEvent)e);
-                default:
                     break;
             }
             return;
         }
         super.processEvent(e);

@@ -2380,16 +2380,18 @@
      *         KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
      *         KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS, or
      *         KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS
      * @since 1.4
      */
+    @SuppressWarnings("unchecked")
     public Set<AWTKeyStroke> getFocusTraversalKeys(int id) {
         if (id < 0 || id >= KeyboardFocusManager.TRAVERSAL_KEY_LENGTH) {
             throw new IllegalArgumentException("invalid focus traversal key identifier");
         }
 
         // Okay to return Set directly because it is an unmodifiable view
+        @SuppressWarnings("rawtypes")
         Set keystrokes = (focusTraversalKeys != null)
             ? focusTraversalKeys[id]
             : null;
 
         if (keystrokes != null) {

@@ -2763,11 +2765,11 @@
     }
 
    /*
     * Support for tracking all windows owned by this window
     */
-    void addOwnedWindow(WeakReference weakWindow) {
+    void addOwnedWindow(WeakReference<Window> weakWindow) {
         if (weakWindow != null) {
             synchronized(ownedWindowList) {
                 // this if statement should really be an assert, but we don't
                 // have asserts...
                 if (!ownedWindowList.contains(weakWindow)) {

@@ -2775,11 +2777,11 @@
                 }
             }
         }
     }
 
-    void removeOwnedWindow(WeakReference weakWindow) {
+    void removeOwnedWindow(WeakReference<Window> weakWindow) {
         if (weakWindow != null) {
             // synchronized block not required since removeElement is
             // already synchronized
             ownedWindowList.removeElement(weakWindow);
         }

@@ -2790,21 +2792,23 @@
         addOwnedWindow(child.weakThis);
     }
 
     private void addToWindowList() {
         synchronized (Window.class) {
+            @SuppressWarnings("unchecked")
             Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)appContext.get(Window.class);
             if (windowList == null) {
                 windowList = new Vector<WeakReference<Window>>();
                 appContext.put(Window.class, windowList);
             }
             windowList.add(weakThis);
         }
     }
 
-    private static void removeFromWindowList(AppContext context, WeakReference weakThis) {
+    private static void removeFromWindowList(AppContext context, WeakReference<Window> weakThis) {
         synchronized (Window.class) {
+            @SuppressWarnings("unchecked")
             Vector<WeakReference<Window>> windowList = (Vector<WeakReference<Window>>)context.get(Window.class);
             if (windowList != null) {
                 windowList.remove(weakThis);
             }
         }

@@ -2943,22 +2947,22 @@
         inputContextLock = new Object();
 
         // Deserialized Windows are not yet visible.
         visible = false;
 
-        weakThis = new WeakReference(this);
+        weakThis = new WeakReference<>(this);
 
         anchor = new Object();
         sun.java2d.Disposer.addRecord(anchor, new WindowDisposerRecord(appContext, this));
 
         addToWindowList();
         initGC(null);
     }
 
     private void deserializeResources(ObjectInputStream s)
         throws ClassNotFoundException, IOException, HeadlessException {
-            ownedWindowList = new Vector();
+            ownedWindowList = new Vector<>();
 
             if (windowSerializedDataVersion < 2) {
                 // Translate old-style focus tracking to new model. For 1.4 and
                 // later releases, we'll rely on the Window's initial focusable
                 // Component.