diff --git a/build.gradle b/build.gradle index 6ec448d..46487ed 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ plugins { } group = 'com.josdem.jmetadata' -version = '1.3.5' +version = '1.3.6' java { toolchain { diff --git a/src/main/java/com/josdem/jmetadata/dnd/DragTooltipDialog.java b/src/main/java/com/josdem/jmetadata/dnd/DragTooltipDialog.java index 39eed40..002b98b 100644 --- a/src/main/java/com/josdem/jmetadata/dnd/DragTooltipDialog.java +++ b/src/main/java/com/josdem/jmetadata/dnd/DragTooltipDialog.java @@ -107,13 +107,8 @@ public boolean matches(Object o) { private boolean allowed; public DragTooltipDialog(Window owner) { - super( - (owner instanceof Frame) ? (JFrame) owner : null, - null, - false, - TransparencyManagerFactory.getManager().getTranslucencyCapableGC()); + super((owner instanceof Frame) ? (JFrame) owner : null, null, false); initialize(); - TransparencyManagerFactory.getManager().setWindowOpaque(this, false); } private void initialize() { @@ -144,7 +139,6 @@ public void setAllowed(boolean allowed) { log.debug("Drag tootltip display error."); } } - TransparencyManagerFactory.getManager().setWindowOpaque(this, false); } private void setFullSize(Dimension contentSize) { @@ -174,7 +168,6 @@ public void setContent(FileSystemValidatorLight validator) { int width = 0; Dimension contentSize = new Dimension(width, height); this.setFullSize(contentSize); - TransparencyManagerFactory.getManager().setWindowOpaque(this, false); } public void setContent(String... message) { @@ -200,7 +193,6 @@ protected void paintComponent(Graphics g) { descriptionPanel.setBounds(7, 20, width, height); descriptionPanel.add(imagePanel); this.setFullSize(width + 14, height + dragIcon.getHeight() + 7); - TransparencyManagerFactory.getManager().setWindowOpaque(this, false); } private Dimension fillContent(List... stuff) { @@ -216,7 +208,6 @@ private Dimension fillContent(List... stuff) { descriptionPanel.setBounds(21, 3, width, height); descriptionPanel.add(dynamicPanel.getPanel()); } - TransparencyManagerFactory.getManager().setWindowOpaque(this, false); return new Dimension(width, height); } diff --git a/src/main/java/com/josdem/jmetadata/dnd/Jdk6u10TransparencyManager.java b/src/main/java/com/josdem/jmetadata/dnd/Jdk6u10TransparencyManager.java deleted file mode 100644 index f69288d..0000000 --- a/src/main/java/com/josdem/jmetadata/dnd/Jdk6u10TransparencyManager.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - Copyright 2025 Jose Morales contact@josdem.io - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package com.josdem.jmetadata.dnd; - -import com.josdem.jmetadata.util.MethodWrapper; -import java.awt.Component; -import java.awt.Container; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; -import java.awt.Shape; -import java.awt.Window; -import javax.swing.JComponent; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class Jdk6u10TransparencyManager implements TransparencyManager { - - private MethodWrapper setWindowShapeMethod; - private MethodWrapper setWindowOpacityMethod; - private MethodWrapper setWindowOpaqueMethod; - private MethodWrapper isTranslucencyCapableMethod; - private MethodWrapper isTranslucencySupportedMethod; - - public Jdk6u10TransparencyManager() { - Class translucencyClass = MethodWrapper.getClass("com.sun.awt.AWTUtilities$Translucency"); - isTranslucencySupportedMethod = - MethodWrapper.forClass("com.sun.awt.AWTUtilities") - .method("isTranslucencySupported") - .withParameters(translucencyClass) - .andReturnType(boolean.class); - isTranslucencyCapableMethod = - MethodWrapper.forClass("com.sun.awt.AWTUtilities") - .method("isTranslucencyCapable") - .withParameters(GraphicsConfiguration.class) - .andReturnType(boolean.class); - setWindowShapeMethod = - MethodWrapper.forClass("com.sun.awt.AWTUtilities") - .method("setWindowShape") - .withParameters(Window.class, Shape.class) - .andReturnType(null); - setWindowOpacityMethod = - MethodWrapper.forClass("com.sun.awt.AWTUtilities") - .method("setWindowOpacity") - .withParameters(Window.class, float.class) - .andReturnType(null); - setWindowOpaqueMethod = - MethodWrapper.forClass("com.sun.awt.AWTUtilities") - .method("setWindowOpaque") - .withParameters(Window.class, boolean.class) - .andReturnType(null); - } - - @Override - public boolean isTranslucencySupported(Object kind) { - return isTranslucencySupportedMethod.invoke(kind); - } - - @Override - public boolean isTranslucencyCapable(GraphicsConfiguration gc) { - return isTranslucencyCapableMethod.invoke(gc); - } - - @Override - public void setWindowShape(Window window, Shape shape) { - setWindowShapeMethod.invoke(window, shape); - } - - @Override - public void setWindowOpacity(Window window, float opacity) { - setWindowOpacityMethod.invoke(window, opacity); - } - - @Override - public void setWindowOpaque(Window window, boolean opaque) { - setWindowOpaqueMethod.invoke(window, opaque); - doTheDoubleBuffer(window); - } - - private void doTheDoubleBuffer(Component c) { - if (c instanceof JComponent) { - JComponent comp = (JComponent) c; - comp.setDoubleBuffered(false); - } - if (c instanceof Container) { - Container container = (Container) c; - for (Component c2 : container.getComponents()) { - doTheDoubleBuffer(c2); - } - } - } - - @Override - public GraphicsConfiguration getTranslucencyCapableGC() { - GraphicsEnvironment localGraphicsEnvironment = - GraphicsEnvironment.getLocalGraphicsEnvironment(); - GraphicsDevice defaultScreenDevice = localGraphicsEnvironment.getDefaultScreenDevice(); - GraphicsConfiguration translucencyCapableGC = defaultScreenDevice.getDefaultConfiguration(); - - if (!isTranslucencyCapable(translucencyCapableGC)) { - translucencyCapableGC = null; - - log.info("Default graphics configuration does not support translucency"); - - GraphicsEnvironment env = localGraphicsEnvironment; - GraphicsDevice[] devices = env.getScreenDevices(); - - for (int i = 0; i < devices.length && translucencyCapableGC == null; i++) { - GraphicsConfiguration[] configs = devices[i].getConfigurations(); - - for (int j = 0; j < configs.length && translucencyCapableGC == null; j++) { - if (isTranslucencyCapable(configs[j])) { - translucencyCapableGC = configs[j]; - } - } - } - } - - if (translucencyCapableGC == null) { - log.warn("Translucency capable graphics configuration not found"); - } - return translucencyCapableGC; - } -} diff --git a/src/main/java/com/josdem/jmetadata/dnd/NullTransparencyManager.java b/src/main/java/com/josdem/jmetadata/dnd/NullTransparencyManager.java deleted file mode 100644 index 326bbee..0000000 --- a/src/main/java/com/josdem/jmetadata/dnd/NullTransparencyManager.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright 2025 Jose Morales contact@josdem.io - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package com.josdem.jmetadata.dnd; - -import java.awt.GraphicsConfiguration; -import java.awt.Shape; -import java.awt.Window; - -public class NullTransparencyManager implements TransparencyManager { - - @Override - public boolean isTranslucencySupported(Object kind) { - return false; - } - - @Override - public boolean isTranslucencyCapable(GraphicsConfiguration gc) { - return false; - } - - @Override - public void setWindowShape(Window window, Shape shape) {} - - @Override - public void setWindowOpacity(Window window, float opacity) {} - - @Override - public void setWindowOpaque(Window window, boolean opaque) {} - - @Override - public GraphicsConfiguration getTranslucencyCapableGC() { - return null; - } -} diff --git a/src/main/java/com/josdem/jmetadata/dnd/TransparencyManager.java b/src/main/java/com/josdem/jmetadata/dnd/TransparencyManager.java deleted file mode 100644 index 8cde1b2..0000000 --- a/src/main/java/com/josdem/jmetadata/dnd/TransparencyManager.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright 2025 Jose Morales contact@josdem.io - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package com.josdem.jmetadata.dnd; - -import java.awt.GraphicsConfiguration; -import java.awt.Shape; -import java.awt.Window; - -public interface TransparencyManager { - public boolean isTranslucencySupported(Object kind); - - public boolean isTranslucencyCapable(GraphicsConfiguration gc); - - public void setWindowShape(Window window, Shape shape); - - public void setWindowOpacity(Window window, float opacity); - - public void setWindowOpaque(Window window, boolean opaque); - - public GraphicsConfiguration getTranslucencyCapableGC(); -} diff --git a/src/main/java/com/josdem/jmetadata/dnd/TransparencyManagerFactory.java b/src/main/java/com/josdem/jmetadata/dnd/TransparencyManagerFactory.java deleted file mode 100644 index 97ed0d3..0000000 --- a/src/main/java/com/josdem/jmetadata/dnd/TransparencyManagerFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - Copyright 2025 Jose Morales contact@josdem.io - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package com.josdem.jmetadata.dnd; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class TransparencyManagerFactory { - private static TransparencyManager manager; - - public static TransparencyManager getManager() { - if (manager != null) { - return manager; - } - try { - manager = new Jdk6u10TransparencyManager(); - return manager; - } catch (Throwable t) { - log.error("Unexpected exception during TransparencyManager instantiation.", t); - } - manager = new NullTransparencyManager(); - return manager; - } -} diff --git a/src/test/java/com/josdem/jmetadata/util/ImageIconBaseTests.java b/src/test/java/com/josdem/jmetadata/util/ImageIconBaseTests.java index 31c85b7..4b23398 100644 --- a/src/test/java/com/josdem/jmetadata/util/ImageIconBaseTests.java +++ b/src/test/java/com/josdem/jmetadata/util/ImageIconBaseTests.java @@ -1,36 +1,35 @@ package com.josdem.jmetadata.util; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import javax.swing.ImageIcon; - import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; class ImageIconBaseTests { - private static ImageIconBase imageIconBase; + private static ImageIconBase imageIconBase; - @BeforeAll - static void init() { - imageIconBase = mock(ImageIconBase.class); - } + @BeforeAll + static void init() { + imageIconBase = mock(ImageIconBase.class); + } - @Test - void testGetImageIcon() { - // Given - String imagePath = "path/to/image.png"; - var expectedImageIcon = new ImageIcon(imagePath); - when(imageIconBase.getImageIcon()).thenReturn(expectedImageIcon); + @Test + void testGetImageIcon() { + // Given + String imagePath = "path/to/image.png"; + var expectedImageIcon = new ImageIcon(imagePath); + when(imageIconBase.getImageIcon()).thenReturn(expectedImageIcon); - // When - ImageIcon result = imageIconBase.getImageIcon(); + // When + ImageIcon result = imageIconBase.getImageIcon(); - // Then - assertNotNull(result); - assertEquals(expectedImageIcon.getDescription(), result.getDescription()); - } + // Then + assertNotNull(result); + assertEquals(expectedImageIcon.getDescription(), result.getDescription()); + } }