Getting the Checkmark file name can now be overridden by the

SWING_UI paramater.
This commit is contained in:
nathan 2017-07-01 16:23:51 +02:00
parent fd492a74e9
commit c989de8cd8
3 changed files with 27 additions and 3 deletions

View File

@ -60,8 +60,14 @@ class SwingMenuItemCheckbox extends SwingMenuItem implements CheckboxPeer {
int sizePadding = (menuImageSize - size) / 2; int sizePadding = (menuImageSize - size) / 2;
checkedIcon = new ImageIcon(HeavyCheckMark.get(jMenuItem.getForeground(), size, String checkmarkPath;
0, sizePadding, 0, sizePadding)); if (SystemTray.SWING_UI != null) {
checkmarkPath = SystemTray.SWING_UI.getCheckMarkIcon(jMenuItem.getForeground(), size, 0, sizePadding, 0, sizePadding);
} else {
checkmarkPath = HeavyCheckMark.get(jMenuItem.getForeground(), size, 0, sizePadding, 0, sizePadding);
}
checkedIcon = new ImageIcon(checkmarkPath);
} catch(Exception e) { } catch(Exception e) {
SystemTray.logger.error("Error creating check-mark image.", e); SystemTray.logger.error("Error creating check-mark image.", e);
} }

View File

@ -15,6 +15,8 @@
*/ */
package dorkbox.systemTray.swingUI; package dorkbox.systemTray.swingUI;
import java.awt.Color;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.JPopupMenu; import javax.swing.JPopupMenu;
import javax.swing.JSeparator; import javax.swing.JSeparator;
@ -67,4 +69,20 @@ interface SwingUIFactory {
* @return the UI used to customize the Look & Feel of a menu separator entry * @return the UI used to customize the Look & Feel of a menu separator entry
*/ */
SeparatorUI getSeparatorUI(JSeparator jSeparator); SeparatorUI getSeparatorUI(JSeparator jSeparator);
/**
* Get the path to a CheckMark image for a specified color, size, and padding.
* <p>
* This is necessary because Swing does not have correct spacing when rendering CheckMark menu items next to
* normal menu menu items (with, or without, images attached).
*
* @param color the color of the CheckMark
* @param checkMarkSize the size of the CheckMark inside the image. (does not include padding)
*
* @param paddingTop amount of padding to apply to the top edge of the icon.
* @param paddingLeft amount of padding to apply to the left edge of the icon.
* @param paddingBottom amount of padding to apply to the bottom edge of the icon.
* @param paddingRight amount of padding to apply to the right edge of the icon.
*/
String getCheckMarkIcon(Color color, int checkMarkSize, int paddingTop, int paddingLeft , int paddingBottom, int paddingRight);
} }

View File

@ -21,7 +21,7 @@ public class HeavyCheckMark {
private static final int VERSION = 1; private static final int VERSION = 1;
/** /**
* This saves a scalable CheckMark to a correctly sized PNG file. * This saves a vector CheckMark to a correctly sized PNG file.
* *
* @param color the color of the CheckMark * @param color the color of the CheckMark
* @param checkMarkSize the size of the CheckMark inside the image. (does not include padding) * @param checkMarkSize the size of the CheckMark inside the image. (does not include padding)