com.sun.jna.IntegerType Java Examples

The following examples show how to use com.sun.jna.IntegerType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClipboardSynchronizer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static Transferable getClipboardContentNatively() {
  String plainText = "public.utf8-plain-text";

  ID pasteboard = Foundation.invoke("NSPasteboard", "generalPasteboard");
  ID types = Foundation.invoke(pasteboard, "types");
  IntegerType count = Foundation.invoke(types, "count");

  ID plainTextType = null;

  for (int i = 0; i < count.intValue(); i++) {
    ID each = Foundation.invoke(types, "objectAtIndex:", i);
    String eachType = Foundation.toStringViaUTF8(each);
    if (plainText.equals(eachType)) {
      plainTextType = each;
      break;
    }
  }

  // will put string value even if we doesn't found java object. this is needed because java caches clipboard value internally and
  // will reset it ONLY IF we'll put jvm-object into clipboard (see our setContent optimizations which avoids putting jvm-objects
  // into clipboard)

  Transferable result = null;
  if (plainTextType != null) {
    ID text = Foundation.invoke(pasteboard, "stringForType:", plainTextType);
    String value = Foundation.toStringViaUTF8(text);
    if (value == null) {
      LOG.info(String.format("[Clipboard] Strange string value (null?) for type: %s", plainTextType));
    }
    else {
      result = new StringSelection(value);
    }
  }

  return result;
}