Added tooltips (if possible) to checkbox menu items
This commit is contained in:
parent
4a6881df4a
commit
077a53d30e
@ -32,6 +32,7 @@ class Checkbox extends Entry {
|
|||||||
|
|
||||||
private volatile boolean enabled = true;
|
private volatile boolean enabled = true;
|
||||||
private volatile char mnemonicKey;
|
private volatile char mnemonicKey;
|
||||||
|
private volatile String tooltip;
|
||||||
|
|
||||||
public
|
public
|
||||||
Checkbox() {
|
Checkbox() {
|
||||||
@ -195,4 +196,45 @@ class Checkbox extends Entry {
|
|||||||
((CheckboxPeer) peer).setShortcut(this);
|
((CheckboxPeer) peer).setShortcut(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the tooltip text, usually this is used to brand the SystemTray icon with your product's name, or to provide extra
|
||||||
|
* information during mouse-over for menu entries.
|
||||||
|
* <p>
|
||||||
|
* NOTE: Maximum length is 64 characters long, and it is not supported on all Operating Systems and Desktop Environments.
|
||||||
|
* <p>
|
||||||
|
* For more details on Linux see https://bugs.launchpad.net/indicator-application/+bug/527458/comments/12.
|
||||||
|
*
|
||||||
|
* @param tooltipText the text to use as a mouse-over tooltip for the tray icon or menu entry, null to remove.
|
||||||
|
*/
|
||||||
|
public
|
||||||
|
void setTooltip(final String tooltipText) {
|
||||||
|
if (tooltipText != null) {
|
||||||
|
// this is a safety precaution, since the behavior of really long text is undefined.
|
||||||
|
if (tooltipText.length() > 64) {
|
||||||
|
throw new RuntimeException("Tooltip text cannot be longer than 64 characters.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!MenuItem.alreadyEmittedTooltipWarning) {
|
||||||
|
MenuItem.alreadyEmittedTooltipWarning = true;
|
||||||
|
SystemTray.logger.warn("Please disable tooltips, as they are not consistent across all platforms and tray types.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.tooltip = tooltipText;
|
||||||
|
|
||||||
|
if (peer != null) {
|
||||||
|
((CheckboxPeer) peer).setTooltip(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the mouse-over tooltip for the meme entry.
|
||||||
|
*
|
||||||
|
* NOTE: This is not consistent across all platforms and tray types.
|
||||||
|
*/
|
||||||
|
public
|
||||||
|
String getTooltip() {
|
||||||
|
return this.tooltip;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ import dorkbox.util.SwingUtil;
|
|||||||
@SuppressWarnings({"unused", "SameParameterValue", "WeakerAccess"})
|
@SuppressWarnings({"unused", "SameParameterValue", "WeakerAccess"})
|
||||||
public
|
public
|
||||||
class MenuItem extends Entry {
|
class MenuItem extends Entry {
|
||||||
private static boolean alreadyEmittedTooltipWarning = false;
|
static boolean alreadyEmittedTooltipWarning = false;
|
||||||
|
|
||||||
private volatile String text;
|
private volatile String text;
|
||||||
private volatile File imageFile;
|
private volatile File imageFile;
|
||||||
|
@ -31,5 +31,7 @@ interface CheckboxPeer extends EntryPeer {
|
|||||||
|
|
||||||
void setShortcut(Checkbox menuItem);
|
void setShortcut(Checkbox menuItem);
|
||||||
|
|
||||||
|
void setTooltip(Checkbox menuItem);
|
||||||
|
|
||||||
void setChecked(Checkbox menuItem);
|
void setChecked(Checkbox menuItem);
|
||||||
}
|
}
|
||||||
|
@ -122,6 +122,12 @@ class AwtMenuItemCheckbox implements CheckboxPeer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public
|
||||||
|
void setTooltip(final Checkbox menuItem) {
|
||||||
|
// no op. (awt menus cannot show tooltips)
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
void setChecked(final Checkbox menuItem) {
|
void setChecked(final Checkbox menuItem) {
|
||||||
|
@ -268,6 +268,20 @@ class GtkMenuItemCheckbox extends GtkBaseMenuItem implements CheckboxPeer, GCall
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public
|
||||||
|
void setTooltip(final Checkbox menuItem) {
|
||||||
|
GtkEventDispatch.dispatch(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public
|
||||||
|
void run() {
|
||||||
|
// NOTE: this will not work for AppIndicator tray types!
|
||||||
|
// null will remove the tooltip
|
||||||
|
Gtk2.gtk_widget_set_tooltip_text(_native, menuItem.getTooltip());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// this is pretty much ONLY for Ubuntu AppIndicators
|
// this is pretty much ONLY for Ubuntu AppIndicators
|
||||||
private
|
private
|
||||||
void setCheckedIconForFakeCheckMarks() {
|
void setCheckedIconForFakeCheckMarks() {
|
||||||
|
@ -173,4 +173,16 @@ class SwingMenuItemCheckbox extends SwingMenuItem implements CheckboxPeer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public
|
||||||
|
void setTooltip(final Checkbox menuItem) {
|
||||||
|
SwingUtil.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public
|
||||||
|
void run() {
|
||||||
|
_native.setToolTipText(menuItem.getTooltip());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user