diff --git a/src/dorkbox/systemTray/util/WindowsSwingUI.java b/src/dorkbox/systemTray/util/WindowsSwingUI.java index cde539d..1ff27a1 100644 --- a/src/dorkbox/systemTray/util/WindowsSwingUI.java +++ b/src/dorkbox/systemTray/util/WindowsSwingUI.java @@ -16,10 +16,7 @@ package dorkbox.systemTray.util; import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JMenu; import javax.swing.JMenuItem; @@ -29,12 +26,11 @@ import javax.swing.plaf.MenuItemUI; import javax.swing.plaf.PopupMenuUI; import javax.swing.plaf.SeparatorUI; -import com.sun.java.swing.plaf.windows.WindowsMenuItemUI; -import com.sun.java.swing.plaf.windows.WindowsMenuUI; - import dorkbox.systemTray.Entry; import dorkbox.systemTray.Menu; +import dorkbox.systemTray.SystemTray; import dorkbox.systemTray.ui.swing.SwingUIFactory; +import dorkbox.util.OS; import dorkbox.util.OSUtil; import dorkbox.util.swing.DefaultMenuItemUI; import dorkbox.util.swing.DefaultPopupMenuUI; @@ -57,7 +53,18 @@ import dorkbox.util.swing.DefaultSeparatorUI; @SuppressWarnings("Duplicates") public class WindowsSwingUI implements SwingUIFactory { - private static final boolean isWindowsXP = OSUtil.Windows.isWindowsXP(); + private static final boolean isWindowsXP; + + static { + boolean _isWindowsXP = OSUtil.Windows.isWindowsXP(); + + if (_isWindowsXP && OS.javaVersion > 8) { + SystemTray.logger.error("Java9+ is not supported with WindowsXP. It will not work"); + _isWindowsXP = false; + } + + isWindowsXP = _isWindowsXP; + } /** * Allows one to specify the Look & Feel of the menus (The main SystemTray and sub-menus) @@ -95,72 +102,9 @@ class WindowsSwingUI implements SwingUIFactory { // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4199382 // basically, override everything to have a 'null' checkbox, so the graphics system thinks it's not there. if (jMenuItem instanceof JMenu) { - return new WindowsMenuUI() { - @Override - public - void installUI(final JComponent c) { - super.installUI(c); - } - - @Override - protected - void paintMenuItem(Graphics g, - JComponent c, - Icon checkIcon, - Icon arrowIcon, - Color background, - Color foreground, - int defaultTextIconGap) { - super.paintMenuItem(g, c, null, arrowIcon, background, foreground, defaultTextIconGap); - } - - - @Override - public Dimension getPreferredSize(JComponent c) { - return getPreferredMenuItemSize(c, - null, - arrowIcon, - defaultTextIconGap); - } - - @Override - protected - Dimension getPreferredMenuItemSize(final JComponent c, - final Icon checkIcon, - final Icon arrowIcon, - final int defaultTextIconGap) { - return super.getPreferredMenuItemSize(c, null, arrowIcon, defaultTextIconGap); - } - }; + return new WindowsXpMenuUI(); } else { - return new WindowsMenuItemUI() { - @Override - public - void installUI(final JComponent c) { - super.installUI(c); - } - - @Override - protected - void paintMenuItem(Graphics g, - JComponent c, - Icon checkIcon, - Icon arrowIcon, - Color background, - Color foreground, - int defaultTextIconGap) { - // we don't use checkboxes, we draw our own as an image. -OFFSET is to offset insanely large margins - super.paintMenuItem(g, c, null, arrowIcon, background, foreground, defaultTextIconGap); - } - - @Override - public Dimension getPreferredSize(JComponent c) { - return getPreferredMenuItemSize(c, - null, - arrowIcon, - defaultTextIconGap); - } - }; + return new WindowsXpMenuItemUI(); } } else { diff --git a/src/dorkbox/systemTray/util/WindowsXpMenuItemUI.java b/src/dorkbox/systemTray/util/WindowsXpMenuItemUI.java new file mode 100644 index 0000000..34f2cc3 --- /dev/null +++ b/src/dorkbox/systemTray/util/WindowsXpMenuItemUI.java @@ -0,0 +1,51 @@ +/* + * Copyright 2017 dorkbox, llc + * + * 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 dorkbox.systemTray.util; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; + +import javax.swing.Icon; +import javax.swing.JComponent; + +import com.sun.java.swing.plaf.windows.WindowsMenuItemUI; + +/** + * The LAST version of the JVM this will compile with is Java8 and it will not compile on anything higher. + * + * WindowsXP with Java8+ is ALSO no longer supported by Oracle or anyone else. + */ +class WindowsXpMenuItemUI extends WindowsMenuItemUI { + @Override + public + void installUI(final JComponent c) { + super.installUI(c); + } + + @Override + protected + void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) { + // we don't use checkboxes, we draw our own as an image. -OFFSET is to offset insanely large margins + super.paintMenuItem(g, c, null, arrowIcon, background, foreground, defaultTextIconGap); + } + + @Override + public + Dimension getPreferredSize(JComponent c) { + return getPreferredMenuItemSize(c, null, arrowIcon, defaultTextIconGap); + } +} diff --git a/src/dorkbox/systemTray/util/WindowsXpMenuUI.java b/src/dorkbox/systemTray/util/WindowsXpMenuUI.java new file mode 100644 index 0000000..eb986a0 --- /dev/null +++ b/src/dorkbox/systemTray/util/WindowsXpMenuUI.java @@ -0,0 +1,57 @@ +/* + * Copyright 2017 dorkbox, llc + * + * 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 dorkbox.systemTray.util; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; + +import javax.swing.Icon; +import javax.swing.JComponent; + +import com.sun.java.swing.plaf.windows.WindowsMenuUI; + +/** + * The LAST version of the JVM this will compile with is Java8 and it will not compile on anything higher. + * + * WindowsXP with Java8+ is ALSO no longer supported by Oracle or anyone else. + */ +class WindowsXpMenuUI extends WindowsMenuUI { + @Override + public + void installUI(final JComponent c) { + super.installUI(c); + } + + @Override + protected + void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) { + super.paintMenuItem(g, c, null, arrowIcon, background, foreground, defaultTextIconGap); + } + + + @Override + public + Dimension getPreferredSize(JComponent c) { + return getPreferredMenuItemSize(c, null, arrowIcon, defaultTextIconGap); + } + + @Override + protected + Dimension getPreferredMenuItemSize(final JComponent c, final Icon checkIcon, final Icon arrowIcon, final int defaultTextIconGap) { + return super.getPreferredMenuItemSize(c, null, arrowIcon, defaultTextIconGap); + } +}