From 2b32762482309867d625fed1d9e001627dd824d8 Mon Sep 17 00:00:00 2001 From: hades Date: Fri, 29 May 2020 11:23:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?KERNEL-4069=20=E9=85=8D=E5=90=88=E5=AE=8C?= =?UTF-8?q?=E6=88=90JDK11=E6=9E=84=E5=BB=BA=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E7=9A=84=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/gui/frpane/UIBubbleFloatPane.java | 2 +- .../ui/rsyntaxtextarea/RSyntaxTextArea.java | 13 +- .../com/fr/design/utils/AWTUtilities.java | 200 ++++++++++++++++++ .../main/java/com/fr/start/SplashWindow.java | 3 +- 4 files changed, 204 insertions(+), 14 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/utils/AWTUtilities.java diff --git a/designer-base/src/main/java/com/fr/design/gui/frpane/UIBubbleFloatPane.java b/designer-base/src/main/java/com/fr/design/gui/frpane/UIBubbleFloatPane.java index c41cc9f7a..0297353ee 100644 --- a/designer-base/src/main/java/com/fr/design/gui/frpane/UIBubbleFloatPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/frpane/UIBubbleFloatPane.java @@ -2,9 +2,9 @@ package com.fr.design.gui.frpane; import com.fr.design.beans.BasicBeanPane; import com.fr.design.dialog.UIDialog; +import com.fr.design.utils.AWTUtilities; import com.fr.log.FineLoggerFactory; import com.fr.stable.Constants; -import com.sun.awt.AWTUtilities; import javax.swing.JComponent; import javax.swing.JPanel; diff --git a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxTextArea.java b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxTextArea.java index 30fc7b871..9cdc3b0ef 100644 --- a/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxTextArea.java +++ b/designer-base/src/main/java/com/fr/design/gui/syntax/ui/rsyntaxtextarea/RSyntaxTextArea.java @@ -9,16 +9,7 @@ */ package com.fr.design.gui.syntax.ui.rsyntaxtextarea; -import java.awt.Color; -import java.awt.Cursor; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Insets; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.RenderingHints; +import java.awt.*; import java.awt.datatransfer.Clipboard; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -604,7 +595,7 @@ private boolean fractionalFontMetricsEnabled; SecurityManager sm = System.getSecurityManager(); if (sm!=null) { try { - sm.checkSystemClipboardAccess(); + sm.checkPermission(new AWTPermission("accessClipboard")); } catch (SecurityException se) { UIManager.getLookAndFeel().provideErrorFeedback(null); return; diff --git a/designer-base/src/main/java/com/fr/design/utils/AWTUtilities.java b/designer-base/src/main/java/com/fr/design/utils/AWTUtilities.java new file mode 100644 index 000000000..12bf2ac4d --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/utils/AWTUtilities.java @@ -0,0 +1,200 @@ +package com.fr.design.utils; + +import sun.awt.SunToolkit; + +import java.awt.*; + +/** + * 适配jdk10之后被移除的 com.sun.awt.AWTUtilities + * 参照 https://github.com/frohoff/jdk8u-dev-jdk/blob/master/src/share/classes/com/sun/awt/AWTUtilities.java中实现 + * + * @author hades + * @version 10.0 + * Created by hades on 2020/5/29 + */ +public class AWTUtilities { + + /** + * @param window the window to set the shape to + * @param shape the shape to set to the window + * + */ + public static void setWindowShape(Window window, Shape shape) { + if (window == null) { + throw new NullPointerException("The window argument should not be null."); + } + window.setShape(shape); + } + + /** + * + * + * @param window the window to set the shape to + * @param opaque whether the window must be opaque (true), + * or translucent (false) + * + */ + public static void setWindowOpaque(Window window, boolean opaque) { + if (window == null) { + throw new NullPointerException("The window argument should not be null."); + } + if (!opaque && !isTranslucencySupported(Translucency.PERPIXEL_TRANSLUCENT)) { + throw new UnsupportedOperationException("The PERPIXEL_TRANSLUCENT translucency kind is not supported"); + } + Color color = window.getBackground(); + if (color == null) { + color = new Color(0, 0, 0, 0); + } + window.setBackground(new Color(color.getRed(), color.getGreen(), color.getBlue(), opaque ? 255 : 0)); + } + + + public static enum Translucency { + /** + * Represents support in the underlying system for windows each pixel + * of which is guaranteed to be either completely opaque, with + * an alpha value of 1.0, or completely transparent, with an alpha + * value of 0.0. + */ + PERPIXEL_TRANSPARENT, + + /** + * Represents support in the underlying system for windows all of + * the pixels of which have the same alpha value between or including + * 0.0 and 1.0. + */ + TRANSLUCENT, + + /** + * Represents support in the underlying system for windows that + * contain or might contain pixels with arbitrary alpha values + * between and including 0.0 and 1.0. + */ + PERPIXEL_TRANSLUCENT; + } + + + /** + * Returns whether the given level of translucency is supported by + * the underlying system. + * + * Note that this method may sometimes return the value + * indicating that the particular level is supported, but + * the native windowing system may still not support the + * given level of translucency (due to the bugs in + * the windowing system). + * + * @param translucencyKind a kind of translucency support + * (either PERPIXEL_TRANSPARENT, + * TRANSLUCENT, or PERPIXEL_TRANSLUCENT) + * @return whether the given translucency kind is supported + */ + private static boolean isTranslucencySupported(Translucency translucencyKind) { + switch (translucencyKind) { + case PERPIXEL_TRANSPARENT: + return isWindowShapingSupported(); + case TRANSLUCENT: + return isWindowOpacitySupported(); + case PERPIXEL_TRANSLUCENT: + return isWindowTranslucencySupported(); + } + return false; + } + + /** + * Returns whether the windowing system supports changing the opacity + * value of top-level windows. + * Note that this method may sometimes return true, but the native + * windowing system may still not support the concept of + * translucency (due to the bugs in the windowing system). + */ + private static boolean isWindowOpacitySupported() { + Toolkit curToolkit = Toolkit.getDefaultToolkit(); + if (!(curToolkit instanceof SunToolkit)) { + return false; + } + return ((SunToolkit)curToolkit).isWindowOpacitySupported(); + } + + /** + * Returns whether the windowing system supports changing the shape + * of top-level windows. + * Note that this method may sometimes return true, but the native + * windowing system may still not support the concept of + * shaping (due to the bugs in the windowing system). + */ + private static boolean isWindowShapingSupported() { + Toolkit curToolkit = Toolkit.getDefaultToolkit(); + if (!(curToolkit instanceof SunToolkit)) { + return false; + } + return ((SunToolkit)curToolkit).isWindowShapingSupported(); + } + + private static boolean isWindowTranslucencySupported() { + /* + * Per-pixel alpha is supported if all the conditions are TRUE: + * 1. The toolkit is a sort of SunToolkit + * 2. The toolkit supports translucency in general + * (isWindowTranslucencySupported()) + * 3. There's at least one translucency-capable + * GraphicsConfiguration + */ + + Toolkit curToolkit = Toolkit.getDefaultToolkit(); + if (!(curToolkit instanceof SunToolkit)) { + return false; + } + + if (!((SunToolkit)curToolkit).isWindowTranslucencySupported()) { + return false; + } + + GraphicsEnvironment env = + GraphicsEnvironment.getLocalGraphicsEnvironment(); + + // If the default GC supports translucency return true. + // It is important to optimize the verification this way, + // see CR 6661196 for more details. + if (isTranslucencyCapable(env.getDefaultScreenDevice() + .getDefaultConfiguration())) + { + return true; + } + + // ... otherwise iterate through all the GCs. + GraphicsDevice[] devices = env.getScreenDevices(); + + for (int i = 0; i < devices.length; i++) { + GraphicsConfiguration[] configs = devices[i].getConfigurations(); + for (int j = 0; j < configs.length; j++) { + if (isTranslucencyCapable(configs[j])) { + return true; + } + } + } + + return false; + } + + private static boolean isTranslucencyCapable(GraphicsConfiguration gc) { + if (gc == null) { + throw new NullPointerException("The gc argument should not be null"); + } + /* + return gc.isTranslucencyCapable(); + */ + Toolkit curToolkit = Toolkit.getDefaultToolkit(); + if (!(curToolkit instanceof SunToolkit)) { + return false; + } + return ((SunToolkit)curToolkit).isTranslucencyCapable(gc); + } + + + + + + + +} diff --git a/designer-base/src/main/java/com/fr/start/SplashWindow.java b/designer-base/src/main/java/com/fr/start/SplashWindow.java index 0176883f5..b6a012f95 100644 --- a/designer-base/src/main/java/com/fr/start/SplashWindow.java +++ b/designer-base/src/main/java/com/fr/start/SplashWindow.java @@ -2,9 +2,9 @@ package com.fr.start; import com.fr.base.BaseUtils; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.utils.AWTUtilities; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.stable.OperatingSystem; -import com.sun.awt.AWTUtilities; import javax.swing.ImageIcon; import javax.swing.JFrame; @@ -41,7 +41,6 @@ public class SplashWindow extends JFrame { this.setAlwaysOnTop(false); this.setUndecorated(true); AWTUtilities.setWindowOpaque(this, false); - //使窗体背景透明 if (OperatingSystem.isWindows()) { this.setBackground(new Color(0, 0, 0, 0)); From 974e6d677ad2b7715014161851b5a8f391537dc9 Mon Sep 17 00:00:00 2001 From: hades Date: Fri, 29 May 2020 11:25:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?KERNEL-4069=20fix=20=E6=BC=8F=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/mainframe/alphafine/listener/ComponentHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/listener/ComponentHandler.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/listener/ComponentHandler.java index 1294fd7d0..17f12f9dd 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/listener/ComponentHandler.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/listener/ComponentHandler.java @@ -1,6 +1,6 @@ package com.fr.design.mainframe.alphafine.listener; -import com.sun.awt.AWTUtilities; +import com.fr.design.utils.AWTUtilities; import java.awt.*; import java.awt.event.ComponentAdapter;