diff --git a/CHANGELOG.md b/CHANGELOG.md index 11448483f..29444812e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ All notable changes to this project will be documented in this file. - Hiding selection after raw editation save - Proper disabling switching items or other actions on editation - Raw editor item count and edit display +- Warnings about invalid reflective access in color dialog on Java 9+ ### Changed - Quick search needs minimum of 3 characters diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java index eb839e481..eb48234e2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java @@ -648,12 +648,12 @@ public class Helper { public static E deepCopy(E o) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + try ( ObjectOutputStream oos = new ObjectOutputStream(baos)) { oos.writeObject(o); oos.flush(); } E copy; - try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + try ( ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { copy = (E) ois.readObject(); } return copy; @@ -694,7 +694,7 @@ public class Helper { public static byte[] readFile(String... file) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); for (String f : file) { - try (FileInputStream fis = new FileInputStream(f)) { + try ( FileInputStream fis = new FileInputStream(f)) { byte[] buf = new byte[4096]; int cnt; while ((cnt = fis.read(buf)) > 0) { @@ -798,7 +798,7 @@ public class Helper { } public static void appendFile(String file, byte[]... data) { - try (FileOutputStream fos = new FileOutputStream(file, true)) { + try ( FileOutputStream fos = new FileOutputStream(file, true)) { for (byte[] d : data) { fos.write(d); } @@ -808,7 +808,7 @@ public class Helper { } public static void writeFile(String file, byte[]... data) { - try (FileOutputStream fos = new FileOutputStream(file)) { + try ( FileOutputStream fos = new FileOutputStream(file)) { for (byte[] d : data) { fos.write(d); } @@ -818,7 +818,7 @@ public class Helper { } public static void writeFile(String file, InputStream stream) { - try (FileOutputStream fos = new FileOutputStream(file)) { + try ( FileOutputStream fos = new FileOutputStream(file)) { copyStream(stream, fos); } catch (IOException ex) { // ignore @@ -938,7 +938,7 @@ public class Helper { } try { f.setAccessible(true); - + Object v = f.get(obj); if (v != null) { try { @@ -1167,7 +1167,7 @@ public class Helper { public static void saveStream(InputStream is, File output) throws IOException { byte[] buf = new byte[4096]; int cnt; - try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(output))) { + try ( OutputStream fos = new BufferedOutputStream(new FileOutputStream(output))) { while ((cnt = is.read(buf)) > 0) { fos.write(buf, 0, cnt); fos.flush(); @@ -1581,4 +1581,16 @@ public class Helper { String text = new String(data, Utf8Helper.charset); return text; } + + public static int getJavaVersion() { + String version = System.getProperty("java.version"); + if (version.startsWith("1.")) { + version = version.substring(2, 3); + } + int dot = version.indexOf("."); + if (dot != -1) { + version = version.substring(0, dot); + } + return Integer.parseInt(version); + } } diff --git a/src/com/jpexs/decompiler/flash/gui/generictageditors/ColorEditor.java b/src/com/jpexs/decompiler/flash/gui/generictageditors/ColorEditor.java index e6bfd0bf8..eca941a6d 100644 --- a/src/com/jpexs/decompiler/flash/gui/generictageditors/ColorEditor.java +++ b/src/com/jpexs/decompiler/flash/gui/generictageditors/ColorEditor.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.gui.AppStrings; import com.jpexs.decompiler.flash.types.ARGB; import com.jpexs.decompiler.flash.types.RGB; import com.jpexs.decompiler.flash.types.RGBA; +import com.jpexs.helpers.Helper; import com.jpexs.helpers.ReflectionTools; import java.awt.Color; import java.awt.Component; @@ -193,47 +194,55 @@ public class ColorEditor extends JPanel implements GenericTagEditor, ActionListe } private static Color noTransparencyColorChooser(Component component, String title, Color initialColor) throws Exception { - final JColorChooser pane = new JColorChooser(initialColor != null - ? initialColor : Color.white); - AbstractColorChooserPanel[] colorPanels = pane.getChooserPanels(); - for (int i = 1; i < colorPanels.length; i++) { - AbstractColorChooserPanel cp = colorPanels[i]; - - Field f = cp.getClass().getDeclaredField("panel"); - f.setAccessible(true); - - Object colorPanel = f.get(cp); - Field f2 = colorPanel.getClass().getDeclaredField("spinners"); - f2.setAccessible(true); - Object spinners = f2.get(colorPanel); - - Object transpSlispinner = Array.get(spinners, 3); - if (i == colorPanels.length - 1) { - transpSlispinner = Array.get(spinners, 4); - } - Field f3 = transpSlispinner.getClass().getDeclaredField("slider"); - f3.setAccessible(true); - JSlider slider = (JSlider) f3.get(transpSlispinner); - slider.setEnabled(false); - Field f4 = transpSlispinner.getClass().getDeclaredField("spinner"); - f4.setAccessible(true); - JSpinner spinner = (JSpinner) f4.get(transpSlispinner); - spinner.setEnabled(false); - } final Color[] col = new Color[]{initialColor}; - JDialog dialog = JColorChooser.createDialog(component, title, true, pane, new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - col[0] = pane.getColor(); + if (Helper.getJavaVersion() >= 9) { + Color c = JColorChooser.showDialog(component, title, initialColor, false); + if (c != null) { + col[0] = c; } - }, null); + } else { + final JColorChooser pane = new JColorChooser(initialColor != null + ? initialColor : Color.white); - dialog.setVisible(true); + AbstractColorChooserPanel[] colorPanels = pane.getChooserPanels(); + for (int i = 1; i < colorPanels.length; i++) { + AbstractColorChooserPanel cp = colorPanels[i]; + + Field f = cp.getClass().getDeclaredField("panel"); + f.setAccessible(true); + + Object colorPanel = f.get(cp); + Field f2 = colorPanel.getClass().getDeclaredField("spinners"); + f2.setAccessible(true); + Object spinners = f2.get(colorPanel); + + Object transpSlispinner = Array.get(spinners, 3); + if (i == colorPanels.length - 1) { + transpSlispinner = Array.get(spinners, 4); + } + Field f3 = transpSlispinner.getClass().getDeclaredField("slider"); + f3.setAccessible(true); + JSlider slider = (JSlider) f3.get(transpSlispinner); + slider.setEnabled(false); + Field f4 = transpSlispinner.getClass().getDeclaredField("spinner"); + f4.setAccessible(true); + JSpinner spinner = (JSpinner) f4.get(transpSlispinner); + spinner.setEnabled(false); + } + + JDialog dialog = JColorChooser.createDialog(component, title, true, pane, new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + col[0] = pane.getColor(); + } + }, null); + dialog.setVisible(true); + } + return col[0]; - } @Override