Added better safety checks and errors when running under WindowsXP with Java9+
This commit is contained in:
parent
d1682a17f0
commit
f86a2f7e40
@ -16,10 +16,7 @@
|
|||||||
package dorkbox.systemTray.util;
|
package dorkbox.systemTray.util;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Graphics;
|
|
||||||
|
|
||||||
import javax.swing.Icon;
|
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JMenu;
|
import javax.swing.JMenu;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
@ -29,12 +26,11 @@ import javax.swing.plaf.MenuItemUI;
|
|||||||
import javax.swing.plaf.PopupMenuUI;
|
import javax.swing.plaf.PopupMenuUI;
|
||||||
import javax.swing.plaf.SeparatorUI;
|
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.Entry;
|
||||||
import dorkbox.systemTray.Menu;
|
import dorkbox.systemTray.Menu;
|
||||||
|
import dorkbox.systemTray.SystemTray;
|
||||||
import dorkbox.systemTray.ui.swing.SwingUIFactory;
|
import dorkbox.systemTray.ui.swing.SwingUIFactory;
|
||||||
|
import dorkbox.util.OS;
|
||||||
import dorkbox.util.OSUtil;
|
import dorkbox.util.OSUtil;
|
||||||
import dorkbox.util.swing.DefaultMenuItemUI;
|
import dorkbox.util.swing.DefaultMenuItemUI;
|
||||||
import dorkbox.util.swing.DefaultPopupMenuUI;
|
import dorkbox.util.swing.DefaultPopupMenuUI;
|
||||||
@ -57,7 +53,18 @@ import dorkbox.util.swing.DefaultSeparatorUI;
|
|||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public
|
public
|
||||||
class WindowsSwingUI implements SwingUIFactory {
|
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)
|
* 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
|
// 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.
|
// basically, override everything to have a 'null' checkbox, so the graphics system thinks it's not there.
|
||||||
if (jMenuItem instanceof JMenu) {
|
if (jMenuItem instanceof JMenu) {
|
||||||
return new WindowsMenuUI() {
|
return new WindowsXpMenuUI();
|
||||||
@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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
return new WindowsMenuItemUI() {
|
return new WindowsXpMenuItemUI();
|
||||||
@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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
51
src/dorkbox/systemTray/util/WindowsXpMenuItemUI.java
Normal file
51
src/dorkbox/systemTray/util/WindowsXpMenuItemUI.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
57
src/dorkbox/systemTray/util/WindowsXpMenuUI.java
Normal file
57
src/dorkbox/systemTray/util/WindowsXpMenuUI.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user