use of com.intellij.ui.mac.foundation.ID in project intellij-community by JetBrains.
the class MacColorPipette method captureScreen.
@Nullable
static BufferedImage captureScreen(@Nullable Window belowWindow, @NotNull Rectangle rect) {
ID pool = Foundation.invoke("NSAutoreleasePool", "new");
try {
ID windowId = belowWindow != null ? MacUtil.findWindowFromJavaWindow(belowWindow) : null;
Foundation.NSRect nsRect = new Foundation.NSRect(rect.x, rect.y, rect.width, rect.height);
ID cgWindowId = windowId != null ? Foundation.invoke(windowId, "windowNumber") : ID.NIL;
int windowListOptions = cgWindowId != null ? FoundationLibrary.kCGWindowListOptionOnScreenBelowWindow : FoundationLibrary.kCGWindowListOptionAll;
int windowImageOptions = FoundationLibrary.kCGWindowImageNominalResolution;
ID cgImageRef = Foundation.cgWindowListCreateImage(nsRect, windowListOptions, cgWindowId, windowImageOptions);
ID bitmapRep = Foundation.invoke(Foundation.invoke("NSBitmapImageRep", "alloc"), "initWithCGImage:", cgImageRef);
ID nsImage = Foundation.invoke(Foundation.invoke("NSImage", "alloc"), "init");
Foundation.invoke(nsImage, "addRepresentation:", bitmapRep);
ID data = Foundation.invoke(nsImage, "TIFFRepresentation");
ID bytes = Foundation.invoke(data, "bytes");
ID length = Foundation.invoke(data, "length");
ByteBuffer byteBuffer = Native.getDirectByteBuffer(bytes.longValue(), length.longValue());
Foundation.invoke(nsImage, "release");
byte[] b = new byte[byteBuffer.remaining()];
byteBuffer.get(b);
BufferedImage result = ImageIO.read(new ByteArrayInputStream(b));
if (result != null) {
ColorSpace ics = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorConvertOp cco = new ColorConvertOp(ics, null);
return cco.filter(result, null);
}
return null;
} catch (Throwable t) {
LOG.error(t);
return null;
} finally {
Foundation.invoke(pool, "release");
}
}
use of com.intellij.ui.mac.foundation.ID in project intellij-community by JetBrains.
the class NSScrollerHelper method initNotificationObserver.
private static void initNotificationObserver() {
Foundation.NSAutoreleasePool pool = new Foundation.NSAutoreleasePool();
ID delegateClass = Foundation.allocateObjcClassPair(Foundation.getObjcClass("NSObject"), "NSScrollerChangesObserver");
if (!ID.NIL.equals(delegateClass)) {
// already exists.
if (!Foundation.addMethod(delegateClass, Foundation.createSelector("handleScrollerStyleChanged:"), APPEARANCE_CALLBACK, "v@")) {
throw new RuntimeException("Cannot add observer method");
}
if (!Foundation.addMethod(delegateClass, Foundation.createSelector("handleBehaviorChanged:"), BEHAVIOR_CALLBACK, "v@")) {
throw new RuntimeException("Cannot add observer method");
}
Foundation.registerObjcClassPair(delegateClass);
}
ID delegate = invoke("NSScrollerChangesObserver", "new");
try {
ID center;
center = invoke("NSNotificationCenter", "defaultCenter");
invoke(center, "addObserver:selector:name:object:", delegate, Foundation.createSelector("handleScrollerStyleChanged:"), Foundation.nsString("NSPreferredScrollerStyleDidChangeNotification"), ID.NIL);
center = invoke("NSDistributedNotificationCenter", "defaultCenter");
invoke(center, "addObserver:selector:name:object:", delegate, Foundation.createSelector("handleBehaviorChanged:"), Foundation.nsString("AppleNoRedisplayAppearancePreferenceChanged"), ID.NIL, // NSNotificationSuspensionBehaviorCoalesce
2);
} finally {
pool.drain();
}
}
use of com.intellij.ui.mac.foundation.ID in project intellij-community by JetBrains.
the class DateFormatUtil method getMacFormats.
private static boolean getMacFormats(DateFormat[] formats) {
final int MacFormatterNoStyle = 0;
final int MacFormatterShortStyle = 1;
final int MacFormatterMediumStyle = 2;
final int MacFormatterBehavior_10_4 = 1040;
ID autoReleasePool = Foundation.invoke("NSAutoreleasePool", "new");
try {
ID dateFormatter = Foundation.invoke("NSDateFormatter", "new");
Foundation.invoke(dateFormatter, Foundation.createSelector("setFormatterBehavior:"), MacFormatterBehavior_10_4);
// short date
formats[0] = invokeFormatter(dateFormatter, MacFormatterNoStyle, MacFormatterShortStyle);
// short time
formats[1] = invokeFormatter(dateFormatter, MacFormatterShortStyle, MacFormatterNoStyle);
// medium time
formats[2] = invokeFormatter(dateFormatter, MacFormatterMediumStyle, MacFormatterNoStyle);
// short date/time
formats[3] = invokeFormatter(dateFormatter, MacFormatterShortStyle, MacFormatterShortStyle);
return true;
} finally {
Foundation.invoke(autoReleasePool, Foundation.createSelector("release"));
}
}
Aggregations