changeset 3658:bfadff5e8544

RT-30544 Mac: clean up MacSystemClipboard and MacPasteboard classes Reviewed-by: anthony
author Petr Pchelko <petr.pchelko@oracle.com>
date Thu, 23 May 2013 11:27:54 +0400
parents 951b878804e0
children 26bdb2990130
files glass/glass-lib-macosx/src/GlassPasteboard.m glass/glass/src/com/sun/glass/ui/mac/MacDnDClipboard.java glass/glass/src/com/sun/glass/ui/mac/MacPasteboard.java glass/glass/src/com/sun/glass/ui/mac/MacSystemClipboard.java
diffstat 4 files changed, 200 insertions(+), 461 deletions(-) [+]
line wrap: on
line diff
--- a/glass/glass-lib-macosx/src/GlassPasteboard.m	Wed May 22 15:57:12 2013 -0700
+++ b/glass/glass-lib-macosx/src/GlassPasteboard.m	Thu May 23 11:27:54 2013 +0400
@@ -562,89 +562,6 @@
 
 /*
  * Class:     com_sun_glass_ui_mac_MacPasteboard
- * Method:    _getItemAsString
- * Signature: (JI)Ljava/lang/String;
- */
-JNIEXPORT jstring JNICALL Java_com_sun_glass_ui_mac_MacPasteboard__1getItemAsString
-(JNIEnv *env, jobject jPasteboard, jlong jPtr, jint jIndex)
-{
-    LOG("Java_com_sun_glass_ui_mac_MacPasteboard__1getItemAsString");
-    
-    jstring string = NULL;
-    
-    GLASS_ASSERT_MAIN_JAVA_THREAD(env);
-    GLASS_POOL_ENTER;
-    {
-        if (jIndex >= 0)
-        {
-            NSPasteboard *pasteboard = (NSPasteboard*)jlong_to_ptr(jPtr);
-            NSArray *items = [pasteboard pasteboardItems];
-            NSPasteboardItem *item = [items objectAtIndex:(NSUInteger)jIndex];
-            if (item != nil)
-            {
-                // since this is a convenience method we'll try to do our best to return a string for this item
-                // by trying all the following types if needed
-                NSArray *utfs = [NSArray arrayWithObjects:
-                                 NSPasteboardTypeString,
-                                 NSPasteboardTypeRTF,
-                                 NSPasteboardTypeMultipleTextSelection,
-                                 NSPasteboardTypeTabularText,
-                                 NSPasteboardTypeHTML,
-                                 NSPasteboardTypePDF,
-                                 NSPasteboardTypeRTFD,
-                                 nil];
-                
-                NSString *str = nil;
-                for (NSUInteger i=0; i<[utfs count]; i++)
-                {
-                    str = [item stringForType:[utfs objectAtIndex:i]];
-                    if (str != nil)
-                    {
-                        string = (jobject)(*env)->NewStringUTF(env, [str UTF8String]);
-                        break;
-                    }
-                }
-                
-                if (string == nil)
-                {
-                    // if no string yet, try by referencing the item's url (if it exists)
-                    NSString *file = [item stringForType:(NSString*)kUTTypeURL];
-                    if (file != nil)
-                    {
-                        NSURL *url = [NSURL URLWithString:file]; 
-                        str = [NSString stringWithContentsOfURL:url encoding:NSUnicodeStringEncoding error:nil];
-                        if (str != nil)
-                        {
-                            string = (jobject)(*env)->NewStringUTF(env, [str UTF8String]);
-                        }
-                    }
-                }
-                
-                if (string == nil)
-                {
-                    // if no string yet, try by referencing the item's url (if it exists)
-                    NSString *file = [item stringForType:(NSString*)kUTTypeFileURL];
-                    if (file != nil)
-                    {
-                        NSURL *url = [NSURL URLWithString:file]; 
-                        str = [NSString stringWithContentsOfURL:url encoding:NSUnicodeStringEncoding error:nil];
-                        if (str != nil)
-                        {
-                            string = (jobject)(*env)->NewStringUTF(env, [str UTF8String]);
-                        }
-                    }
-                }
-            }
-        }
-    }
-    GLASS_POOL_EXIT;
-    GLASS_CHECK_EXCEPTION(env);
-    
-    return string;
-}
-
-/*
- * Class:     com_sun_glass_ui_mac_MacPasteboard
  * Method:    _getItemStringForUTF
  * Signature: (JILjava/lang/String;)Ljava/lang/String;
  */
@@ -738,50 +655,6 @@
 
 /*
  * Class:     com_sun_glass_ui_mac_MacPasteboard
- * Method:    _getItemForUTF
- * Signature: (JILjava/lang/String;)J
- */
-JNIEXPORT jlong JNICALL Java_com_sun_glass_ui_mac_MacPasteboard__1getItemForUTF
-(JNIEnv *env, jobject jPasteboard, jlong jPtr, jint jIndex, jstring jUtf)
-{
-    LOG("Java_com_sun_glass_ui_mac_MacPasteboard__1getItemForUTF");
-    
-    jlong ptr = 0L;
-    
-    GLASS_ASSERT_MAIN_JAVA_THREAD(env);
-    GLASS_POOL_ENTER;
-    {
-        if (jIndex >= 0)
-        {
-            NSString *utf = nil;
-            {
-                const jchar *chars = (*env)->GetStringChars(env, jUtf, NULL);
-                jsize length = (*env)->GetStringLength(env, jUtf);
-                if (length > 0)
-                {
-                    utf = [NSString stringWithCharacters:(UniChar *)chars length:(NSUInteger)length];
-                }
-                (*env)->ReleaseStringChars(env, jUtf, chars);
-            }
-            if (utf != nil)
-            {
-                NSPasteboard *pasteboard = (NSPasteboard*)jlong_to_ptr(jPtr);
-                NSArray *items = [pasteboard pasteboardItems];
-                NSPasteboardItem *item = [items objectAtIndex:(NSUInteger)jIndex];
-                
-                id property = [[item propertyListForType:utf] retain]; // notice we retain
-                ptr = ptr_to_jlong(property);
-            }
-        }
-    }
-    GLASS_POOL_EXIT;
-    GLASS_CHECK_EXCEPTION(env);
-    
-    return ptr;
-}
-
-/*
- * Class:     com_sun_glass_ui_mac_MacPasteboard
  * Method:    _putItemsFromArray
  * Signature: (J[Ljava/lang/Object;I)J
  */
--- a/glass/glass/src/com/sun/glass/ui/mac/MacDnDClipboard.java	Wed May 22 15:57:12 2013 -0700
+++ b/glass/glass/src/com/sun/glass/ui/mac/MacDnDClipboard.java	Thu May 23 11:27:54 2013 +0400
@@ -24,38 +24,13 @@
  */
 package com.sun.glass.ui.mac;
 
-import com.sun.glass.events.MouseEvent;
-
 final class MacDnDClipboard extends MacSystemClipboard {
 
     public MacDnDClipboard(String name) {
         super(name);
     }
 
-    /*
-     * called from native
-     */
-    static MacDnDClipboard getInstance() {
-        return (MacDnDClipboard)get(DND);
-    }
-
     @Override public String toString() {
         return "Mac DnD Clipboard";
     }
-
-    /*
-     * The MouseEvent.BUTTON_XXXX const if Java is DnD source.
-     */
-    protected int dragButton = 0;
-
-    public int getDragButton() {
-        return dragButton;
-    }
-
-    /*
-     * Called from native code
-     */
-    private void setDragButton(int dragButton) {
-        this.dragButton = dragButton;
-    }
 }
--- a/glass/glass/src/com/sun/glass/ui/mac/MacPasteboard.java	Wed May 22 15:57:12 2013 -0700
+++ b/glass/glass/src/com/sun/glass/ui/mac/MacPasteboard.java	Thu May 23 11:27:54 2013 +0400
@@ -24,10 +24,6 @@
  */
 package com.sun.glass.ui.mac;
 
-import com.sun.glass.ui.Application;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
 import java.util.HashMap;
 
 final class MacPasteboard {
@@ -113,14 +109,6 @@
         return _getItemAsRawImage(this.ptr, index);
     }
     
-    // get the item representation for the given index as String
-    // the platform will try to find the best representation
-    private native String _getItemAsString(long ptr, int index);
-    public String getItemAsString(int index) {
-        assertValid();
-        return _getItemAsString(this.ptr, index);
-    }
-    
     // get the item representation for the given utf type as String
     private native String _getItemStringForUTF(long ptr, int index, String utf);
     public String getItemStringForUTF(int index, String utf) {
@@ -135,15 +123,6 @@
         return _getItemBytesForUTF(this.ptr, index, utf);
     }
     
-    // get the item representation for the given utf type as native Objective-C object id
-    // the item retain count will increase by 1
-    // requires client to drop into Obj-C to do anything useful with the item
-    private native long _getItemForUTF(long ptr, int index, String utf);
-    public long getItemForUTF(int index, String utf) {
-        assertValid();
-        return _getItemForUTF(this.ptr, index, utf);
-    }
-    
     // paste the items with their corresponding representations
     // returns seed
     // 
@@ -163,16 +142,13 @@
     public long putItemsFromArray(Object[] items, int supportedActions) {
         return _putItemsFromArray(this.ptr, items, supportedActions);
     }
-    private Object[] hashMapToArray(HashMap hashmap) {
+    private Object[] hashMapToArray(HashMap<String, Object> hashmap) {
         Object[] array = null;
         if ((hashmap != null) && (hashmap.size() > 0)) {
             array = new Object[hashmap.size()];
-            java.util.Set keys = hashmap.keySet();
-            java.util.Iterator iterator = keys.iterator();
             int index = 0;
-            while (iterator.hasNext() == true) {
+            for (String utf : hashmap.keySet()) {
                 Object item[] = new Object[2];
-                String utf = (String)iterator.next();
                 item[MacPasteboard.UtfIndex] = utf;
                 item[MacPasteboard.ObjectIndex] = hashmap.get(utf);
                 array[index++] = item;
@@ -217,7 +193,7 @@
     private native void _release(long ptr);
     public void release() {
         assertValid();
-        if ((this.ptr != 0L) && (this.user == true)) {
+        if ((this.ptr != 0L) && (this.user)) {
             _release(ptr);
         }
         this.ptr = 0L;
--- a/glass/glass/src/com/sun/glass/ui/mac/MacSystemClipboard.java	Wed May 22 15:57:12 2013 -0700
+++ b/glass/glass/src/com/sun/glass/ui/mac/MacSystemClipboard.java	Thu May 23 11:27:54 2013 +0400
@@ -24,19 +24,21 @@
  */
 package com.sun.glass.ui.mac;
 
-import com.sun.glass.ui.Application;
-import com.sun.glass.ui.Clipboard;
-import com.sun.glass.ui.SystemClipboard;
-import com.sun.glass.ui.Pixels;
-
-import java.nio.IntBuffer;
-import java.util.HashMap;
-import java.net.URL;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.net.URL;
 import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import com.sun.glass.ui.Application;
+import com.sun.glass.ui.Clipboard;
+import com.sun.glass.ui.Pixels;
+import com.sun.glass.ui.SystemClipboard;
 
 class MacSystemClipboard extends SystemClipboard {
 
@@ -60,12 +62,16 @@
     final MacPasteboard pasteboard;
     public MacSystemClipboard(String name) {
         super(name);
-        if (name.equals(Clipboard.DND) == true) {
-            this.pasteboard = new MacPasteboard(MacPasteboard.DragAndDrop);
-        } else if (name.equals(Clipboard.SYSTEM) == true) {
-            this.pasteboard = new MacPasteboard(MacPasteboard.General);
-        } else {
-            this.pasteboard = new MacPasteboard(name);
+        switch (name) {
+            case Clipboard.DND:
+                this.pasteboard = new MacPasteboard(MacPasteboard.DragAndDrop);
+                break;
+            case Clipboard.SYSTEM:
+                this.pasteboard = new MacPasteboard(MacPasteboard.General);
+                break;
+            default:
+                this.pasteboard = new MacPasteboard(name);
+                break;
         }
     }
     
@@ -86,211 +92,164 @@
     
     @Override
     protected void pushToSystem(HashMap<String, Object> data, int supportedActions) {
-        //System.out.println("MacSystemClipboard pushToSystem, supportedActions: "+supportedActions);
         HashMap<String,Object> itemFirst = null; // used to handle paste as one item if we can
         HashMap<String,Object> itemList[] = null; // special case: multiple items for handling urls 10.6 style
-        
-        java.util.Set keys = data.keySet();
-        //System.out.println("keys:"+keys);
-        //System.out.println("values:"+data.values());
-        java.util.Iterator iterator = keys.iterator();
-        while (iterator.hasNext() == true) {
-            String mime = (String)iterator.next();
+
+        for (String mime  : data.keySet()) {
             Object object = data.get(mime);
-            //System.out.println("    ["+mime+"] : ["+object+"]");
             if (object != null) {
-                if (mime.equals(URI_TYPE) == true) {
-                    // synthesize list of urls as seperate pasteboard items (Mac OS 10.6 style)
-                    String list = (String)object;
-                    String split[] = list.split("\n");
-                    int count = 0;
-                    for (int i=0; i<split.length; i++) {
-                        String string = split[i];
-                        if (string.startsWith("#") == false) {
-                            // exclude comments: http://www.ietf.org/rfc/rfc2483.txt
-                            count++;
+                switch (mime) {
+                    case URI_TYPE:
+                    {
+                        // synthesize list of urls as seperate pasteboard items (Mac OS 10.6 style)
+                        String split[] = ((String) object).split("\n");
+                        int count = 0;
+                        for (String string : split) {
+                            if (!string.startsWith("#")) {
+                                // exclude comments: http://www.ietf.org/rfc/rfc2483.txt
+                                count++;
+                            }
                         }
+                        if (count > 0) {
+                            itemList = new HashMap[count];
+                            count = 0;
+                            for (String file : split) {
+                                if (!file.startsWith("#")) {
+                                    // exclude comments: http://www.ietf.org/rfc/rfc2483.txt
+                                    URI uri = createUri(file, MacSystemClipboard.BAD_URI_MSG);
+                                    String utf = MacPasteboard.UtfUrl;
+                                    if (uri.getScheme() == null) {
+                                        utf = MacPasteboard.UtfFileUrl;
+                                        uri = createUri(MacSystemClipboard.FILE_SCHEME, uri.getPath(), MacSystemClipboard.BAD_URI_MSG);
+                                    }
+                                    itemList[count] = new HashMap<>();
+                                    itemList[count].put(utf, uri.toASCIIString());
+                                    count++;
+                                }
+                            }
+                        }
+                        break;
                     }
-                    //System.out.println("        count:"+count);
-                    if (count > 0) {
-                        itemList = new HashMap[count];
-                        count = 0;
-                        for (int i=0; i<split.length; i++) {
-                            String file = split[i];
-                            if (file.startsWith("#") == false) {
-                                // exclude comments: http://www.ietf.org/rfc/rfc2483.txt
-                                //System.out.println("            utf:"+MacPasteboard.UtfFileUrl);
-                                //System.out.println("            string:"+string);
+                    case RAW_IMAGE_TYPE:
+                    case DRAG_IMAGE:
+                    {
+                        Pixels pixels = null;
+                        if (object instanceof Pixels) {
+                            pixels = (Pixels) object;
+                        } else if (object instanceof ByteBuffer) {
+                            try {
+                                ByteBuffer bb = (ByteBuffer) object;
+                                bb.rewind();
+                                pixels = Application.GetApplication().createPixels(bb.getInt(), bb.getInt(), bb.slice());
+                            } catch (Exception ex) {
+                                //Ignore all ill-sized arrays. Not a client problem.
+                            }
+                        } else if (object instanceof IntBuffer) {
+                            try {
+                                IntBuffer ib = (IntBuffer) object;
+                                ib.rewind();
+                                pixels = Application.GetApplication().createPixels(ib.get(), ib.get(), ib.slice());
+                            } catch (Exception ex) {
+                                //Ignore all ill-sized arrays. Not a client problem.
+                            }
+                        } else {
+                            throw new RuntimeException(object.getClass().getName() + " cannot be converted to Pixels");
+                        }
+                        if (pixels != null) {
+                            if (itemFirst == null) {
+                                itemFirst = new HashMap<>();
+                            }
+                            itemFirst.put(FormatEncoder.mimeToUtf(mime), pixels);
+                        }
+                        break;
+                    }
+                    case TEXT_TYPE:
+                    case HTML_TYPE:
+                    case RTF_TYPE:
+                    {
+                        if (object instanceof String) {
+                            String string = (String)object;
+                            if (itemFirst == null) {
+                                itemFirst = new HashMap<>();
+                            }
+                            itemFirst.put(FormatEncoder.mimeToUtf(mime), string);
+                        } else {
+                            // http://javafx-jira.kenai.com/browse/RT-14593
+                            // temporary code, DelayedCallback trips over this
+                            // by reusing (incorrectly) text mime type
+                            System.err.println("DelayedCallback not implemented yet: RT-14593");
+                            Thread.dumpStack();
+                        }
+                        break;
+                    }
+                    case FILE_LIST_TYPE:
+                    {
+                        // handle FILE_LIST_TYPE last to know whether to handle it as urls (10.6) or file list (10.5)
+                        // depending on whether urls have been already explicitly set or not
+                        String files[] = (String[]) object;
+                        if (data.get(URI_TYPE) == null) {
+                            // special case no explicit urls found - synthesize urls (Mac OS 10.6 style)
+                            itemList = new HashMap[files.length];
+                            for (int i = 0; i < files.length; i++) {
+                                String file = files[i];
                                 URI uri = createUri(file, MacSystemClipboard.BAD_URI_MSG);
                                 String utf = MacPasteboard.UtfUrl;
-                                if (uri.getScheme() == null)
-                                {
+                                if (uri.getScheme() == null) {
                                     utf = MacPasteboard.UtfFileUrl;
                                     uri = createUri(MacSystemClipboard.FILE_SCHEME, uri.getPath(), MacSystemClipboard.BAD_URI_MSG);
                                 }
-                                itemList[count] = new HashMap();
-                                itemList[count].put(utf, uri.toASCIIString());
-                                count++;
+                                itemList[i] = new HashMap<>();
+                                itemList[i].put(utf, uri.toASCIIString());
+                            }
+                        } else if (MacSystemClipboard.SUPPORT_10_5_API) {
+                            // special case urls already exist - synthesize file list (Mac OS 10.5 API compatible)
+                            if (itemFirst == null) {
+                                itemFirst = new HashMap<>();
+                            }
+                            StringBuilder string = null;
+                            for (int i = 0; i < files.length; i++) {
+                                String file = files[i];
+                                URI uri = createUri(file, MacSystemClipboard.BAD_URI_MSG);
+                                if (string == null) {
+                                    string = new StringBuilder();
+                                }
+                                string.append(uri.getPath());
+                                if (i < (files.length - 1)) {
+                                    string.append("\n");
+                                }
+                            }
+                            if (string != null) {
+                                if ((itemFirst.get(MacPasteboard.UtfString) == null) || MacSystemClipboard.SUPPORT_10_5_API_FORCE) {
+                                    itemFirst.remove(MacPasteboard.UtfString);
+                                    itemFirst.put(MacPasteboard.UtfString, string.toString());
+                                }
                             }
                         }
+                        break;
                     }
-                } else if ((mime.equals(RAW_IMAGE_TYPE) == true) ||
-                                (mime.equals(DRAG_IMAGE) == true)) {
-                    Pixels pixels = null;
-                    if (object instanceof Pixels) {
-                        pixels = (Pixels) object;
-                    } else if (object instanceof ByteBuffer) {
-                        try {
-                            ByteBuffer bb = (ByteBuffer) object;
-                            bb.rewind();
-                            pixels = Application.GetApplication().createPixels(bb.getInt(), bb.getInt(), bb.slice());
-                        } catch (Exception ex) {
-                            //Ignore all ill-sized arrays. Not a client problem.
+                    default:
+                    {
+                        // http://javafx-jira.kenai.com/browse/RT-14592
+                        // custom client mime type - pass through
+                        if (itemFirst == null) {
+                            itemFirst = new HashMap<>();
                         }
-                    } else if (object instanceof IntBuffer) {
-                        try {
-                            IntBuffer ib = (IntBuffer) object;
-                            ib.rewind();
-                            pixels = Application.GetApplication().createPixels(ib.get(), ib.get(), ib.slice());
-                        } catch (Exception ex) {
-                            //Ignore all ill-sized arrays. Not a client problem.
-                        }
-                    } else {
-                        throw new RuntimeException(object.getClass().getName() + " cannot be converted to Pixels");
+                        itemFirst.put(FormatEncoder.mimeToUtf(mime), serialize(object));
+                        break;
                     }
-                    if (pixels != null) {
-                        if (itemFirst == null) {
-                            itemFirst = new HashMap();
-                        }
-                        itemFirst.put(FormatEncoder.mimeToUtf(mime), pixels);
-                    }
-                } else if ((mime.equals(TEXT_TYPE) == true) ||
-                                (mime.equals(HTML_TYPE) == true) ||
-                                    (mime.equals(RTF_TYPE) == true)) {
-                    if (object instanceof String) {
-                        String string = (String)object;
-                        if (itemFirst == null) {
-                            itemFirst = new HashMap();
-                        }
-                        itemFirst.put(FormatEncoder.mimeToUtf(mime), string);
-                    } else {
-                        // http://javafx-jira.kenai.com/browse/RT-14593
-                        // temporary code, DelayedCallback trips over this
-                        // by reusing (incorrectly) text mime type
-                        System.err.println("DelayedCallback not implemented yet: RT-14593");
-                        Thread.dumpStack();
-                    }
-                } else if (mime.equals(FILE_LIST_TYPE)) {
-                    // handle FILE_LIST_TYPE last to know whether to handle it as urls (10.6) or file list (10.5)
-                    // depending on whether urls have been already explicitly set or not
-                    String files[] = (String[])object;
-                    if (data.get(URI_TYPE) == null) {
-                        // special case no explicit urls found - synthesize urls (Mac OS 10.6 style)
-                        itemList = new HashMap[files.length];
-                        for (int i=0; i<files.length; i++) {
-                            String file = files[i];
-                            URI uri = createUri(file, MacSystemClipboard.BAD_URI_MSG);
-                            String utf = MacPasteboard.UtfUrl;
-                            if (uri.getScheme() == null)
-                            {
-                                utf = MacPasteboard.UtfFileUrl;
-                                uri = createUri(MacSystemClipboard.FILE_SCHEME, uri.getPath(), MacSystemClipboard.BAD_URI_MSG);
-                            }
-                            itemList[i] = new HashMap();
-                            itemList[i].put(utf, uri.toASCIIString());
-                        }
-                    } else if (MacSystemClipboard.SUPPORT_10_5_API == true) {
-                        // special case urls already exist - synthesize file list (Mac OS 10.5 API compatible)
-                        if (itemFirst == null) {
-                            itemFirst = new HashMap();
-                        }
-                        StringBuilder string = null;
-                        for (int i=0; i<files.length; i++) {
-                            String file = files[i];
-                            URI uri = createUri(file, MacSystemClipboard.BAD_URI_MSG);
-                            if (string == null) {
-                                string = new StringBuilder();
-                            }
-                            string.append(uri.getPath());
-                            if (i < (files.length-1)) {
-                                string.append("\n");
-                            }
-                        }
-                        if (string != null) {
-                            if ((itemFirst.get(MacPasteboard.UtfString) == null) || (MacSystemClipboard.SUPPORT_10_5_API_FORCE == true)) {
-                                itemFirst.remove(MacPasteboard.UtfString);
-                                itemFirst.put(MacPasteboard.UtfString, string.toString());
-                            }
-                        }
-                    }
-                } else {
-                    // http://javafx-jira.kenai.com/browse/RT-14592
-                    // custom client mime type - pass through
-                    if (itemFirst == null) {
-                        itemFirst = new HashMap();
-                    }
-                    itemFirst.put(FormatEncoder.mimeToUtf(mime), serialize(object));
                 }
             }
         }
         
-//        System.out.println("    itemFirst:"+itemFirst);
-//        if (itemFirst != null) {
-//            iterator = itemFirst.keySet().iterator();
-//            while (iterator.hasNext() == true) {
-//                String utf = (String)iterator.next();
-//                Object object = itemFirst.get(utf);
-//                System.out.println("        "+utf+" : "+object);
-//                itemList[0].put(utf, object);
-//            }
-//        }
-            
-//        System.out.println("    itemList:"+itemList);
-//        if (itemList != null) {
-//            for (int i=0; i<itemList.length; i++) {
-//                System.out.println("        item["+i+"]");
-//                HashMap item = itemList[i];
-//                iterator = item.keySet().iterator();
-//                while (iterator.hasNext() == true) {
-//                    String utf = (String)iterator.next();
-//                    Object object = item.get(utf);
-//                    System.out.println("            "+utf+" : "+object);
-//                    itemList[0].put(utf, object);
-//                }
-//            }
-//        }
-        
         if (itemFirst != null) {
             if (itemList == null) {
                 itemList = new HashMap[1];
                 itemList[0] = itemFirst;
             } else {
-                HashMap temp = itemList[0];
-                itemList[0] = itemFirst;
-                iterator = temp.keySet().iterator();
-                while (iterator.hasNext() == true) {
-                    String utf = (String)iterator.next();
-                    Object object = temp.get(utf);
-                    itemList[0].put(utf, object);
-                }
+                itemList[0].putAll(itemFirst);
             }
         }
         
-//        System.out.println("pushToSystem final items:"+itemList);
-//        if (itemList != null) {
-//            for (int i=0; i<itemList.length; i++) {
-//                System.out.println("        item["+i+"]");
-//                HashMap item = itemList[i];
-//                iterator = item.keySet().iterator();
-//                while (iterator.hasNext() == true) {
-//                    String utf = (String)iterator.next();
-//                    Object object = item.get(utf);
-//                    System.out.println("            "+utf+" : "+object);
-//                    itemList[0].put(utf, object);
-//                }
-//            }
-//        }
-        
         if (itemList != null) {
             this.seed = this.pasteboard.putItems(itemList, supportedActions);
         }
@@ -298,58 +257,34 @@
     
     @Override
     protected Object popFromSystem(String mime) {
-        //System.err.println("popFromSystem: ["+mime+"]");
-        Object object = null;
+        String[][] utfs = this.pasteboard.getUTFs();
 
-        String[][] utfs = this.pasteboard.getUTFs();
-        if (mime.equals(URI_TYPE) == true) {
-            if (utfs != null) {
-                java.util.ArrayList<String> list = new java.util.ArrayList<String>();
-                for (int i=0; i<utfs.length; i++) {
-                    String url = this.pasteboard.getItemStringForUTF(i, FormatEncoder.mimeToUtf(URI_TYPE));
-                    //System.out.println("    url: "+url);
-                    if (url != null) {
-                        list.add(url);
-                        if (SUPPORT_10_6_API == false) {
-                            break;
-                        }
-                    }
-                }
-                if (list.size() > 0) {
-                    if (SUPPORT_10_6_API == false) {
-                        object = list.get(0);
-                    } else {
-                        object = list;
-                    }
-                }
-            }
-        } else if (mime.equals(RAW_IMAGE_TYPE) == true) {
-            if (utfs != null) {
-                java.util.ArrayList<Pixels> list = new java.util.ArrayList<Pixels>();
-                for (int i=0; i<utfs.length; i++) {
+        if (utfs == null) {
+            return null;
+        }
+        switch (mime) {
+            case RAW_IMAGE_TYPE:
+            {
+                List<Pixels> list = new ArrayList<>();
+                for (int i = 0; i < utfs.length; i++) {
                     Object data = this.pasteboard.getItemAsRawImage(i);
                     if (data != null) {
-                        Pixels pixels = getPixelsForRawImage((byte[])data);
+                        Pixels pixels = getPixelsForRawImage((byte[]) data);
                         list.add(pixels);
                         if (SUPPORT_10_6_API == false) {
                             break;
                         }
                     }
                 }
-                if (list.size() > 0) {
-                    if (SUPPORT_10_6_API == false) {
-                        object = list.get(0);
-                    } else {
-                        object = list;
-                    }
-                }
+                return getObjectFromList(list);
             }
-        } else if ((mime.equals(TEXT_TYPE) == true) ||
-                        (mime.equals(HTML_TYPE) == true) ||
-                            (mime.equals(RTF_TYPE) == true)) {
-            if (utfs != null) {
-                java.util.ArrayList<String> list = new java.util.ArrayList<String>();
-                for (int i=0; i<utfs.length; i++) {
+            case TEXT_TYPE:
+            case HTML_TYPE:
+            case RTF_TYPE:
+            case URI_TYPE:
+            {
+                List<String> list = new ArrayList<>();
+                for (int i = 0; i < utfs.length; i++) {
                     String item = this.pasteboard.getItemStringForUTF(i, FormatEncoder.mimeToUtf(mime));
                     if (item != null) {
                         list.add(item);
@@ -358,35 +293,30 @@
                         }
                     }
                 }
-                if (list.size() > 0) {
-                    if (SUPPORT_10_6_API == false) {
-                        object = list.get(0);
-                    } else {
-                        object = list;
-                    }
-                }
+                return getObjectFromList(list);
             }
-        } else if (mime.equals(FILE_LIST_TYPE) == true) {
-            // synthesize the list from individual URLs
-            if (utfs != null) {
-                java.util.ArrayList<String> list = new java.util.ArrayList<String>();
-                for (int i=0; i<utfs.length; i++) {
+            case FILE_LIST_TYPE:
+            {
+                // synthesize the list from individual URLs
+                List<String> list = new ArrayList<>();
+                for (int i = 0; i < utfs.length; i++) {
                     String file = this.pasteboard.getItemStringForUTF(i, MacPasteboard.UtfFileUrl); // explicitly ask for urls
                     if (file != null) {
                         URL url = createUrl(file, MacSystemClipboard.BAD_URL_MSG);
                         list.add(url.getPath());
-                        //System.out.println("    url: "+url.getPath());
                     }
                 }
+                String[] object = null;
                 if (list.size() > 0) {
                     object = new String[list.size()];
-                    list.toArray((String[])object);
+                    list.toArray(object);
                 }
+                return object;
             }
-        } else {
-            if (utfs != null) {
-                java.util.ArrayList<ByteBuffer> list = new java.util.ArrayList<ByteBuffer>();
-                for (int i=0; i<utfs.length; i++) {
+            default:
+            {
+                List<ByteBuffer> list = new ArrayList<>();
+                for (int i = 0; i < utfs.length; i++) {
                     byte data[] = this.pasteboard.getItemBytesForUTF(i, FormatEncoder.mimeToUtf(mime));
                     if (data != null) {
                         // http://javafx-jira.kenai.com/browse/RT-14592
@@ -398,53 +328,41 @@
                         }
                     }
                 }
-                if (list.size() > 0) {
-                    if (SUPPORT_10_6_API == false) {
-                        object = list.get(0);
-                    } else {
-                        object = list;
-                    }
-                }
+                return getObjectFromList(list);
             }
         }
-        
-        //System.out.println("    object: "+object);
-        return object;
+    }
+
+    private Object getObjectFromList(List<?> list) {
+        if (list.size() > 0) {
+            if (SUPPORT_10_6_API == false) {
+                return list.get(0);
+            } else {
+                return list;
+            }
+        }
+        return null;
     }
     
     @Override
     protected String[] mimesFromSystem() {
         String[][] all = this.pasteboard.getUTFs();
+        List<String> mimes = new ArrayList<>();
 
-        java.util.ArrayList<String> mimes = new java.util.ArrayList<String>();
-
-        //System.out.println("mimesFromSystem");
-        //System.out.println("    utfs:");
         if (all != null) {
-            for (int i=0; i<all.length; i++) {
-                String[] utfs = all[i];
+            for (String[] utfs : all) {
                 if (utfs != null) {
-                    for (int j=0; j<utfs.length; j++) {
-                        String utf = utfs[j];
-                        //System.out.println("        utfs["+i+"]:["+j+"]:"+utf);
+                    for (String utf : utfs) {
                         String mime = FormatEncoder.utfToMime(utf);
-                        //System.out.println("        mime:"+mime);
-                        if ((mime != null) && (mimes.contains(mime) == false)) {
+                        if ((mime != null) && (!mimes.contains(mime))) {
                             mimes.add(mime);
                         }
                     }
                 }
             }
         }
-        
         String[] strings = new String[mimes.size()];
         mimes.toArray(strings);
-        
-        //System.err.println("MacSystemClipboard mimesFromSystem:");
-        //for (int i=0; i<strings.length; i++) {
-        //    System.err.println("    mime["+i+"]:"+strings[i]);
-        //}
-        
         return strings;
     }
     
@@ -515,7 +433,6 @@
         } catch (URISyntaxException ex) {
             System.err.println(message+path);
             Thread.dumpStack();
-            //throw new RuntimeException(ex);
         }
         return uri;
     }
@@ -527,7 +444,6 @@
         } catch (URISyntaxException ex) {
             System.err.println(message+path);
             Thread.dumpStack();
-            //throw new RuntimeException(ex);
         }
         return uri;
     }
@@ -539,7 +455,6 @@
         } catch (MalformedURLException ex) {
             System.err.println(message+path);
             Thread.dumpStack();
-            //throw new RuntimeException(ex);
         }
         return url;
     }