forked from dorkbox/SystemTray
UI components are now cached
This commit is contained in:
parent
08b86cf16f
commit
e1a191e155
@ -56,7 +56,6 @@ class LinuxSwingUI implements SwingUIFactory {
|
|||||||
public static class Metal_MenuItemBorder extends MetalBorders.MenuItemBorder {
|
public static class Metal_MenuItemBorder extends MetalBorders.MenuItemBorder {
|
||||||
private final int verticalPadding;
|
private final int verticalPadding;
|
||||||
|
|
||||||
public
|
|
||||||
Metal_MenuItemBorder(int verticalPadding) {
|
Metal_MenuItemBorder(int verticalPadding) {
|
||||||
this.verticalPadding = verticalPadding;
|
this.verticalPadding = verticalPadding;
|
||||||
}
|
}
|
||||||
@ -69,6 +68,10 @@ class LinuxSwingUI implements SwingUIFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static PopupMenuUI popupMenuUI = null;
|
||||||
|
private static MenuItemUI menuItemUI = null;
|
||||||
|
private static SeparatorUI separatorUI = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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)
|
||||||
*
|
*
|
||||||
@ -80,19 +83,23 @@ class LinuxSwingUI implements SwingUIFactory {
|
|||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
PopupMenuUI getMenuUI(final JPopupMenu jPopupMenu, final Menu entry) {
|
PopupMenuUI getMenuUI(final JPopupMenu jPopupMenu, final Menu entry) {
|
||||||
return new DefaultPopupMenuUI(jPopupMenu) {
|
if (popupMenuUI == null) {
|
||||||
@Override
|
popupMenuUI = new DefaultPopupMenuUI(jPopupMenu) {
|
||||||
public
|
@Override
|
||||||
void installUI(final JComponent c) {
|
public
|
||||||
super.installUI(c);
|
void installUI(final JComponent c) {
|
||||||
|
super.installUI(c);
|
||||||
|
|
||||||
JPopupMenu popupMenu = (JPopupMenu) c;
|
JPopupMenu popupMenu = (JPopupMenu) c;
|
||||||
|
|
||||||
// borderUI resource border type will get changed internally!
|
// borderUI resource border type will get changed internally!
|
||||||
// setBorder(new BorderUIResource.EmptyBorderUIResource(0, 0, 0, 0));
|
// setBorder(new BorderUIResource.EmptyBorderUIResource(0, 0, 0, 0));
|
||||||
popupMenu.setBorder(new EmptyBorder(1, 1, 1, 1));
|
popupMenu.setBorder(new EmptyBorder(1, 1, 1, 1));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return popupMenuUI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -106,19 +113,23 @@ class LinuxSwingUI implements SwingUIFactory {
|
|||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
MenuItemUI getItemUI(final JMenuItem jMenuItem, final Entry entry) {
|
MenuItemUI getItemUI(final JMenuItem jMenuItem, final Entry entry) {
|
||||||
return new DefaultMenuItemUI(jMenuItem) {
|
if (menuItemUI == null) {
|
||||||
@Override
|
menuItemUI = new DefaultMenuItemUI(jMenuItem) {
|
||||||
public
|
@Override
|
||||||
void installUI(final JComponent c) {
|
public
|
||||||
super.installUI(c);
|
void installUI(final JComponent c) {
|
||||||
|
super.installUI(c);
|
||||||
|
|
||||||
JMenuItem menuItem = (JMenuItem) c;
|
JMenuItem menuItem = (JMenuItem) c;
|
||||||
menuItem.setIconTextGap(8);
|
menuItem.setIconTextGap(8);
|
||||||
// the original is hardcoded to always be 2 (top/bottom). We want this to be larger, so the vertical spacing looks like
|
// the original is hardcoded to always be 2 (top/bottom). We want this to be larger, so the vertical spacing looks like
|
||||||
// other menus
|
// other menus
|
||||||
c.setBorder(new Metal_MenuItemBorder(4));
|
c.setBorder(new Metal_MenuItemBorder(4));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return menuItemUI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -131,9 +142,12 @@ class LinuxSwingUI implements SwingUIFactory {
|
|||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
SeparatorUI getSeparatorUI(final JSeparator jSeparator) {
|
SeparatorUI getSeparatorUI(final JSeparator jSeparator) {
|
||||||
return new DefaultSeparatorUI(jSeparator);
|
if (separatorUI == null) {
|
||||||
}
|
separatorUI = new DefaultSeparatorUI(jSeparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
return separatorUI;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This saves a vector CheckMark to a correctly sized PNG file. The checkmark image will ALWAYS be centered in the targetImageSize
|
* This saves a vector CheckMark to a correctly sized PNG file. The checkmark image will ALWAYS be centered in the targetImageSize
|
||||||
|
Loading…
Reference in New Issue
Block a user