src/solaris/classes/sun/awt/X11/XToolkit.java

Print this page
rev 9717 : 8039642: Fix raw and unchecked warnings in sun.awt.*
Reviewed-by:

@@ -34,10 +34,11 @@
 import java.awt.dnd.DragGestureEvent;
 import java.awt.dnd.DragGestureRecognizer;
 import java.awt.dnd.MouseDragGestureRecognizer;
 import java.awt.dnd.InvalidDnDOperationException;
 import java.awt.dnd.peer.DragSourceContextPeer;
+import java.awt.font.TextAttribute;
 import java.awt.im.InputMethodHighlight;
 import java.awt.im.spi.InputMethodDescriptor;
 import java.awt.image.ColorModel;
 import java.awt.peer.*;
 import java.beans.PropertyChangeListener;

@@ -96,13 +97,13 @@
     private XSettings xs;
 
     private FontConfigManager fcManager = new FontConfigManager();
 
     static int arrowCursor;
-    static TreeMap winMap = new TreeMap();
-    static HashMap specialPeerMap = new HashMap();
-    static HashMap winToDispatcher = new HashMap();
+    static TreeMap<Long, XBaseWindow> winMap = new TreeMap<>();
+    static HashMap<Object, Object> specialPeerMap = new HashMap<>();
+    static HashMap<Long, Collection<XEventDispatcher>> winToDispatcher = new HashMap<>();
     private static long _display;
     static UIDefaults uidefaults;
     static X11GraphicsEnvironment localEnv;
     static X11GraphicsDevice device;
     static final X11GraphicsConfig config;

@@ -320,11 +321,11 @@
             awtAppClassName = getCorrectXIDString(mainClassName);
 
             init();
             XWM.init();
 
-            PrivilegedAction<Thread> action = new PrivilegedAction() {
+            PrivilegedAction<Thread> action = new PrivilegedAction<Thread>() {
                 public Thread run() {
                     ThreadGroup currentTG = Thread.currentThread().getThreadGroup();
                     ThreadGroup parentTG = currentTG.getParent();
                     while (parentTG != null) {
                         currentTG = parentTG;

@@ -371,29 +372,29 @@
             winMap.remove(Long.valueOf(window));
         }
     }
     static XBaseWindow windowToXWindow(long window) {
         synchronized(winMap) {
-            return (XBaseWindow) winMap.get(Long.valueOf(window));
+            return winMap.get(Long.valueOf(window));
         }
     }
 
     static void addEventDispatcher(long window, XEventDispatcher dispatcher) {
         synchronized(winToDispatcher) {
             Long key = Long.valueOf(window);
-            Collection dispatchers = (Collection)winToDispatcher.get(key);
+            Collection<XEventDispatcher> dispatchers = winToDispatcher.get(key);
             if (dispatchers == null) {
-                dispatchers = new Vector();
+                dispatchers = new Vector<>();
                 winToDispatcher.put(key, dispatchers);
             }
             dispatchers.add(dispatcher);
         }
     }
     static void removeEventDispatcher(long window, XEventDispatcher dispatcher) {
         synchronized(winToDispatcher) {
             Long key = Long.valueOf(window);
-            Collection dispatchers = (Collection)winToDispatcher.get(key);
+            Collection<XEventDispatcher> dispatchers = winToDispatcher.get(key);
             if (dispatchers != null) {
                 dispatchers.remove(dispatcher);
             }
         }
     }

@@ -506,22 +507,22 @@
             resetKeyboardSniffer();
             setupModifierMap();
         }
         XBaseWindow.dispatchToWindow(ev);
 
-        Collection dispatchers = null;
+        Collection<XEventDispatcher> dispatchers = null;
         synchronized(winToDispatcher) {
             Long key = Long.valueOf(xany.get_window());
-            dispatchers = (Collection)winToDispatcher.get(key);
+            dispatchers = winToDispatcher.get(key);
             if (dispatchers != null) { // Clone it to avoid synchronization during dispatching
-                dispatchers = new Vector(dispatchers);
+                dispatchers = new Vector<>(dispatchers);
             }
         }
         if (dispatchers != null) {
-            Iterator iter = dispatchers.iterator();
+            Iterator<XEventDispatcher> iter = dispatchers.iterator();
             while (iter.hasNext()) {
-                XEventDispatcher disp = (XEventDispatcher)iter.next();
+                XEventDispatcher disp = iter.next();
                 disp.dispatchEvent(ev);
             }
         }
         notifyListeners(ev);
     }

@@ -777,11 +778,11 @@
         XAtom XA_NET_WM_STRUT = XAtom.get("_NET_WM_STRUT");
         XAtom XA_NET_WM_STRUT_PARTIAL = XAtom.get("_NET_WM_STRUT_PARTIAL");
 
         Insets insets = new Insets(0, 0, 0, 0);
 
-        java.util.List search = new LinkedList();
+        java.util.List<Object> search = new LinkedList<>();
         search.add(root);
         search.add(0);
         while (!search.isEmpty())
         {
             long window = (Long)search.remove(0);

@@ -942,10 +943,11 @@
 
     public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException {
         return XDragSourceContextPeer.createDragSourceContextPeer(dge);
     }
 
+    @SuppressWarnings("unchecked")
     public <T extends DragGestureRecognizer> T
     createDragGestureRecognizer(Class<T> recognizerClass,
                     DragSource ds,
                     Component c,
                     int srcActions,

@@ -1160,11 +1162,11 @@
 
     public int getMaximumCursorColors() {
         return 2;  // Black and white.
     }
 
-    public Map mapInputMethodHighlight(InputMethodHighlight highlight)     {
+    public Map<TextAttribute, ?> mapInputMethodHighlight( InputMethodHighlight highlight) {
         return XInputMethod.mapInputMethodHighlight(highlight);
     }
     @Override
     public boolean getLockingKeyState(int key) {
         if (! (key == KeyEvent.VK_CAPS_LOCK || key == KeyEvent.VK_NUM_LOCK ||

@@ -1351,35 +1353,29 @@
     }
 
     static void dumpPeers() {
         if (log.isLoggable(PlatformLogger.Level.FINE)) {
             log.fine("Mapped windows:");
-            Iterator iter = winMap.entrySet().iterator();
-            while (iter.hasNext()) {
-                Map.Entry entry = (Map.Entry)iter.next();
-                log.fine(entry.getKey() + "->" + entry.getValue());
-                if (entry.getValue() instanceof XComponentPeer) {
-                    Component target = (Component)((XComponentPeer)entry.getValue()).getTarget();
+            winMap.forEach((k, v) -> {
+                log.fine(k + "->" + v);
+                if (v instanceof XComponentPeer) {
+                    Component target = (Component)((XComponentPeer)v).getTarget();
                     log.fine("\ttarget: " + target);
                 }
-            }
+            });
 
             SunToolkit.dumpPeers(log);
 
             log.fine("Mapped special peers:");
-            iter = specialPeerMap.entrySet().iterator();
-            while (iter.hasNext()) {
-                Map.Entry entry = (Map.Entry)iter.next();
-                log.fine(entry.getKey() + "->" + entry.getValue());
-            }
+            specialPeerMap.forEach((k, v) -> {
+                log.fine(k + "->" + v);
+            });
 
             log.fine("Mapped dispatchers:");
-            iter = winToDispatcher.entrySet().iterator();
-            while (iter.hasNext()) {
-                Map.Entry entry = (Map.Entry)iter.next();
-                log.fine(entry.getKey() + "->" + entry.getValue());
-            }
+            winToDispatcher.forEach((k, v) -> {
+                log.fine(k + "->" + v);
+            });
         }
     }
 
     /* Protected with awt_lock. */
     private static boolean initialized;

@@ -1599,20 +1595,20 @@
      * <p>
      * NB: This could be called from any thread if triggered by
      * <code>loadXSettings</code>.  It is called from the System EDT
      * if triggered by an XSETTINGS change.
      */
-    void parseXSettings(int screen_XXX_ignored,Map updatedSettings) {
+    void parseXSettings(int screen_XXX_ignored,Map<String, Object> updatedSettings) {
 
         if (updatedSettings == null || updatedSettings.isEmpty()) {
             return;
         }
 
-        Iterator i = updatedSettings.entrySet().iterator();
+        Iterator<Map.Entry<String, Object>> i = updatedSettings.entrySet().iterator();
         while (i.hasNext()) {
-            Map.Entry e = (Map.Entry)i.next();
-            String name = (String)e.getKey();
+            Map.Entry<String, Object> e = i.next();
+            String name = e.getKey();
 
             name = "gnome." + name;
             setDesktopProperty(name, e.getValue());
             if (log.isLoggable(PlatformLogger.Level.FINE)) {
                 log.fine("name = " + name + " value = " + e.getValue());

@@ -1705,11 +1701,11 @@
             // keycode. We are going to check a state of this modifier.
             // If a modifier is a weird one, we cannot help it.
             long window = 0;
             try{
                 // get any application window
-                window = ((Long)(winMap.firstKey())).longValue();
+                window = winMap.firstKey().longValue();
             }catch(NoSuchElementException nex) {
                 // get root window
                 window = getDefaultRootWindow();
             }
             boolean res = XlibWrapper.XQueryPointer(getDisplay(), window,

@@ -1811,11 +1807,11 @@
             log.fine("modLockIsShiftLock = " + modLockIsShiftLock);
         }
     }
 
 
-    private static SortedMap timeoutTasks;
+    private static SortedMap<Long, java.util.List<Runnable>> timeoutTasks;
 
     /**
      * Removed the task from the list of waiting-to-be called tasks.
      * If the task has been scheduled several times removes only first one.
      */

@@ -1832,14 +1828,14 @@
                 if (timeoutTaskLog.isLoggable(PlatformLogger.Level.FINER)) {
                     timeoutTaskLog.finer("Task is not scheduled");
                 }
                 return;
             }
-            Collection values = timeoutTasks.values();
-            Iterator iter = values.iterator();
+            Collection<java.util.List<Runnable>> values = timeoutTasks.values();
+            Iterator<java.util.List<Runnable>> iter = values.iterator();
             while (iter.hasNext()) {
-                java.util.List list = (java.util.List)iter.next();
+                java.util.List<Runnable> list = iter.next();
                 boolean removed = false;
                 if (list.contains(task)) {
                     list.remove(task);
                     if (list.isEmpty()) {
                         iter.remove();

@@ -1882,17 +1878,17 @@
                                      ";  task being added={2}" + ";  tasks before addition={3}",
                                      Long.valueOf(System.currentTimeMillis()), Long.valueOf(interval), task, timeoutTasks);
             }
 
             if (timeoutTasks == null) {
-                timeoutTasks = new TreeMap();
+                timeoutTasks = new TreeMap<>();
             }
 
             Long time = Long.valueOf(System.currentTimeMillis() + interval);
-            java.util.List tasks = (java.util.List)timeoutTasks.get(time);
+            java.util.List<Runnable> tasks = timeoutTasks.get(time);
             if (tasks == null) {
-                tasks = new ArrayList(1);
+                tasks = new ArrayList<>(1);
                 timeoutTasks.put(time, tasks);
             }
             tasks.add(task);
 
 

@@ -1910,11 +1906,11 @@
         awtLock();
         try {
             if (timeoutTasks == null || timeoutTasks.isEmpty()) {
                 return -1L;
             }
-            return (Long)timeoutTasks.firstKey();
+            return timeoutTasks.firstKey();
         } finally {
             awtUnlock();
         }
     }
 

@@ -1931,17 +1927,17 @@
         if (timeoutTasks == null || timeoutTasks.isEmpty()) {
             return;
         }
 
         Long currentTime = Long.valueOf(System.currentTimeMillis());
-        Long time = (Long)timeoutTasks.firstKey();
+        Long time = timeoutTasks.firstKey();
 
         while (time.compareTo(currentTime) <= 0) {
-            java.util.List tasks = (java.util.List)timeoutTasks.remove(time);
+            java.util.List<Runnable> tasks = timeoutTasks.remove(time);
 
-            for (Iterator iter = tasks.iterator(); iter.hasNext();) {
-                Runnable task = (Runnable)iter.next();
+            for (Iterator<Runnable> iter = tasks.iterator(); iter.hasNext();) {
+                Runnable task = iter.next();
 
                 if (timeoutTaskLog.isLoggable(PlatformLogger.Level.FINER)) {
                     timeoutTaskLog.finer("XToolkit.callTimeoutTasks(): current time={0}" +
                                          ";  about to run task={1}", Long.valueOf(currentTime), task);
                 }

@@ -1956,11 +1952,11 @@
             }
 
             if (timeoutTasks.isEmpty()) {
                 break;
             }
-            time = (Long)timeoutTasks.firstKey();
+            time = timeoutTasks.firstKey();
         }
     }
 
     static long getAwtDefaultFg() {
         return awt_defaultFg;