Add ProjectorUtils to jbr-api (#181)

* Add ProjectorUtils to jbr-api

Co-authored-by: Sviatoslav Vlasov <Sviatoslav.Vlasov@jetbrains.com>
This commit is contained in:
Svyatoslav Vlasov
2022-10-20 13:46:38 +02:00
committed by jbrbot
parent b67ca5a155
commit fe0fe95b91
4 changed files with 58 additions and 3 deletions

View File

@@ -46,6 +46,9 @@ public class JBRApiModule {
"sun.awt.windows.WWindowPeer")
.service("com.jetbrains.DesktopActions")
.withStatic("setHandler", "setDesktopActionsHandler", "java.awt.Desktop")
.clientProxy("java.awt.Desktop$DesktopActionsHandler", "com.jetbrains.DesktopActions$Handler");
.clientProxy("java.awt.Desktop$DesktopActionsHandler", "com.jetbrains.DesktopActions$Handler")
.service("com.jetbrains.ProjectorUtils")
.withStatic("overrideGraphicsEnvironment", "overrideLocalGraphicsEnvironment", "java.awt.GraphicsEnvironment")
.withStatic("setLocalGraphicsEnvironmentProvider", "setLocalGraphicsEnvironmentProvider", "java.awt.GraphicsEnvironment");
}
}

View File

@@ -30,6 +30,7 @@ import java.awt.image.BufferedImage;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Locale;
import java.util.function.Supplier;
import sun.awt.PlatformGraphicsInfo;
import sun.font.FontManager;
@@ -73,6 +74,9 @@ public abstract class GraphicsEnvironment {
protected GraphicsEnvironment() {
}
// JBR API internals
private static Supplier<GraphicsEnvironment> graphicsEnvironmentProvider = null;
/**
* Lazy initialization of local graphics environment using holder idiom.
*/
@@ -90,6 +94,12 @@ public abstract class GraphicsEnvironment {
* @return the graphics environment
*/
private static GraphicsEnvironment createGE() {
if (graphicsEnvironmentProvider != null) {
GraphicsEnvironment overriddenGE = graphicsEnvironmentProvider.get();
if (overriddenGE != null)
return overriddenGE;
}
GraphicsEnvironment ge = PlatformGraphicsInfo.createGE();
if (isHeadless()) {
ge = new HeadlessGraphicsEnvironment(ge);
@@ -106,6 +116,16 @@ public abstract class GraphicsEnvironment {
return LocalGE.INSTANCE;
}
// JBR API internals
private static void setLocalGraphicsEnvironmentProvider(Supplier<GraphicsEnvironment> geProvider) {
graphicsEnvironmentProvider = geProvider;
}
// JBR API internals
private static void overrideLocalGraphicsEnvironment(GraphicsEnvironment overriddenGE) {
setLocalGraphicsEnvironmentProvider(() -> overriddenGE);
}
/**
* Tests whether or not a display, keyboard, and mouse can be
* supported in this environment. If this method returns true,

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2022 JetBrains s.r.o.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.jetbrains;
import java.awt.*;
import java.util.function.Supplier;
public interface ProjectorUtils {
void setLocalGraphicsEnvironmentProvider(Supplier<GraphicsEnvironment> geProvider);
void overrideGraphicsEnvironment(GraphicsEnvironment overriddenGE);
}

View File

@@ -6,9 +6,9 @@
# 2. When only new API is added, or some existing API was @Deprecated - increment MINOR, reset PATCH to 0
# 3. For major backwards incompatible API changes - increment MAJOR, reset MINOR and PATCH to 0
VERSION = 0.0.5
VERSION = 0.0.7
# Hash is used to track changes to jetbrains.api, so you would not forget to update version when needed.
# When you make any changes, "make jbr-api" will fail and ask you to update hash and version number here.
HASH = 7AA8AF5DDF8293EF33786DF3B91F3B0
HASH = 50DD43AD1517742CC33F31C7E5098