forked from dorkbox/SystemTray
API cleanup, WIP adding widgets to the menu (on pause because of
problems with the enter key not responding after this). Updated test examples.
This commit is contained in:
parent
84a7fb77af
commit
09143f7630
@ -16,9 +16,9 @@
|
||||
package dorkbox.systemTray;
|
||||
|
||||
public
|
||||
interface SystemTrayMenuAction {
|
||||
interface Action {
|
||||
/**
|
||||
* This method will ALWAYS be called in the swing EDT
|
||||
* This method will ALWAYS be called in the swing EDT. If there is work conducted in this method, it will slow-down the GUI.
|
||||
*
|
||||
* @param systemTray this is the parent, system tray object
|
||||
* @param parent this is the parent menu of this menu entry
|
@ -97,7 +97,7 @@ interface Entry {
|
||||
*
|
||||
* @param callback the callback to set. If null, the callback is safely removed.
|
||||
*/
|
||||
void setCallback(SystemTrayMenuAction callback);
|
||||
void setCallback(Action callback);
|
||||
|
||||
/**
|
||||
* Sets a menu entry shortcut key (Mnemonic) so that menu entry can be "selected" via the keyboard while the menu is displayed.
|
||||
|
@ -52,7 +52,7 @@ interface Menu extends Entry {
|
||||
/**
|
||||
* This removes al menu entries from this menu
|
||||
*/
|
||||
void clear();
|
||||
void removeAll();
|
||||
|
||||
/**
|
||||
* Gets the menu entry for a specified text
|
||||
@ -62,17 +62,17 @@ interface Menu extends Entry {
|
||||
Entry get(final String menuText);
|
||||
|
||||
/**
|
||||
* Gets the first menu entry or sub-menu, ignoring status and spacers
|
||||
* Gets the first menu entry or sub-menu, ignoring status and separators
|
||||
*/
|
||||
Entry getFirst();
|
||||
|
||||
/**
|
||||
* Gets the last menu entry or sub-menu, ignoring status and spacers
|
||||
* Gets the last menu entry or sub-menu, ignoring status and separators
|
||||
*/
|
||||
Entry getLast();
|
||||
|
||||
/**
|
||||
* Gets the menu entry or sub-menu for a specified index (zero-index), ignoring status and spacers
|
||||
* Gets the menu entry or sub-menu for a specified index (zero-index), ignoring status and separators
|
||||
*
|
||||
* @param menuIndex the menu entry index to use to retrieve the menu entry.
|
||||
*/
|
||||
@ -86,7 +86,7 @@ interface Menu extends Entry {
|
||||
* @param menuText string of the text you want to appear
|
||||
* @param callback callback that will be executed when this menu entry is clicked
|
||||
*/
|
||||
Entry addEntry(String menuText, SystemTrayMenuAction callback);
|
||||
Entry addEntry(String menuText, Action callback);
|
||||
|
||||
/**
|
||||
* Adds a menu entry with text + image
|
||||
@ -95,7 +95,7 @@ interface Menu extends Entry {
|
||||
* @param imagePath the image (full path required) to use. If null, no image will be used
|
||||
* @param callback callback that will be executed when this menu entry is clicked
|
||||
*/
|
||||
Entry addEntry(String menuText, String imagePath, SystemTrayMenuAction callback);
|
||||
Entry addEntry(String menuText, String imagePath, Action callback);
|
||||
|
||||
/**
|
||||
* Adds a menu entry with text + image
|
||||
@ -104,7 +104,7 @@ interface Menu extends Entry {
|
||||
* @param imageUrl the URL of the image to use. If null, no image will be used
|
||||
* @param callback callback that will be executed when this menu entry is clicked
|
||||
*/
|
||||
Entry addEntry(String menuText, URL imageUrl, SystemTrayMenuAction callback);
|
||||
Entry addEntry(String menuText, URL imageUrl, Action callback);
|
||||
|
||||
/**
|
||||
* Adds a menu entry with text + image
|
||||
@ -114,7 +114,7 @@ interface Menu extends Entry {
|
||||
* @param imageStream the InputStream of the image to use. If null, no image will be used
|
||||
* @param callback callback that will be executed when this menu entry is clicked
|
||||
*/
|
||||
Entry addEntry(String menuText, String cacheName, InputStream imageStream, SystemTrayMenuAction callback);
|
||||
Entry addEntry(String menuText, String cacheName, InputStream imageStream, Action callback);
|
||||
|
||||
/**
|
||||
* Adds a menu entry with text + image
|
||||
@ -123,7 +123,7 @@ interface Menu extends Entry {
|
||||
* @param imageStream the InputStream of the image to use. If null, no image will be used
|
||||
* @param callback callback that will be executed when this menu entry is clicked
|
||||
*/
|
||||
Entry addEntry(String menuText, InputStream imageStream, SystemTrayMenuAction callback);
|
||||
Entry addEntry(String menuText, InputStream imageStream, Action callback);
|
||||
|
||||
|
||||
|
||||
@ -168,6 +168,14 @@ interface Menu extends Entry {
|
||||
*/
|
||||
Menu addMenu(String menuText, InputStream imageStream);
|
||||
|
||||
/**
|
||||
* Adds a swing widget as a menu entry.
|
||||
*
|
||||
* @param widget the JComponent that is to be added as an entry
|
||||
*/
|
||||
// TODO: buggy. The menu will **sometimes** stop responding to the "enter" key after this. Mnemonics still work however.
|
||||
// Entry addWidget(JComponent widget);
|
||||
|
||||
|
||||
/**
|
||||
* This removes a menu entry from the dropdown menu.
|
||||
|
@ -562,10 +562,7 @@ class SystemTray implements Menu {
|
||||
/*
|
||||
* appIndicator/gtk require strings (which is the path)
|
||||
* swing version loads as an image (which can be stream or path, we use path)
|
||||
*
|
||||
* For KDE4, it must also be unique across runs
|
||||
*/
|
||||
CacheUtil.setUniqueCachePerRun = isKDE;
|
||||
CacheUtil.tempDir = "SysTray";
|
||||
|
||||
try {
|
||||
@ -883,7 +880,7 @@ class SystemTray implements Menu {
|
||||
*/
|
||||
@Override
|
||||
public
|
||||
void setCallback(final SystemTrayMenuAction callback) {
|
||||
void setCallback(final Action callback) {
|
||||
// NO OP.
|
||||
}
|
||||
|
||||
@ -951,7 +948,7 @@ class SystemTray implements Menu {
|
||||
* @param callback callback that will be executed when this menu entry is clicked
|
||||
*/
|
||||
public final
|
||||
Entry addEntry(String menuText, SystemTrayMenuAction callback) {
|
||||
Entry addEntry(String menuText, Action callback) {
|
||||
return addEntry(menuText, (String) null, callback);
|
||||
}
|
||||
|
||||
@ -963,7 +960,7 @@ class SystemTray implements Menu {
|
||||
* @param callback callback that will be executed when this menu entry is clicked
|
||||
*/
|
||||
public final
|
||||
Entry addEntry(String menuText, String imagePath, SystemTrayMenuAction callback) {
|
||||
Entry addEntry(String menuText, String imagePath, Action callback) {
|
||||
return systemTrayMenu.addEntry(menuText, imagePath, callback);
|
||||
}
|
||||
|
||||
@ -975,7 +972,7 @@ class SystemTray implements Menu {
|
||||
* @param callback callback that will be executed when this menu entry is clicked
|
||||
*/
|
||||
public final
|
||||
Entry addEntry(String menuText, URL imageUrl, SystemTrayMenuAction callback) {
|
||||
Entry addEntry(String menuText, URL imageUrl, Action callback) {
|
||||
return systemTrayMenu.addEntry(menuText, imageUrl, callback);
|
||||
}
|
||||
|
||||
@ -988,7 +985,7 @@ class SystemTray implements Menu {
|
||||
* @param callback callback that will be executed when this menu entry is clicked
|
||||
*/
|
||||
public
|
||||
Entry addEntry(String menuText, String cacheName, InputStream imageStream, SystemTrayMenuAction callback) {
|
||||
Entry addEntry(String menuText, String cacheName, InputStream imageStream, Action callback) {
|
||||
return systemTrayMenu.addEntry(menuText, cacheName, imageStream, callback);
|
||||
}
|
||||
|
||||
@ -1000,7 +997,7 @@ class SystemTray implements Menu {
|
||||
* @param callback callback that will be executed when this menu entry is clicked
|
||||
*/
|
||||
public final
|
||||
Entry addEntry(String menuText, InputStream imageStream, SystemTrayMenuAction callback) {
|
||||
Entry addEntry(String menuText, InputStream imageStream, Action callback) {
|
||||
return systemTrayMenu.addEntry(menuText, imageStream, callback);
|
||||
}
|
||||
|
||||
@ -1063,6 +1060,17 @@ class SystemTray implements Menu {
|
||||
return systemTrayMenu.addMenu(menuText, imageStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a swing widget as a menu entry.
|
||||
*
|
||||
* @param widget the JComponent that is to be added as an entry
|
||||
*/
|
||||
// TODO: buggy. The menu will **sometimes** stop responding to the "enter" key after this. Mnemonics still work however.
|
||||
// @Override
|
||||
// public
|
||||
// Entry addWidget(final JComponent widget) {
|
||||
// return systemTrayMenu.addWidget(widget);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
@ -1092,8 +1100,8 @@ class SystemTray implements Menu {
|
||||
*/
|
||||
@Override
|
||||
public final
|
||||
void clear() {
|
||||
systemTrayMenu.clear();
|
||||
void removeAll() {
|
||||
systemTrayMenu.removeAll();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,9 +25,7 @@ import javax.swing.JMenuItem;
|
||||
|
||||
import dorkbox.systemTray.Entry;
|
||||
import dorkbox.systemTray.Menu;
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.util.ImageUtils;
|
||||
import dorkbox.util.SwingUtil;
|
||||
|
||||
abstract
|
||||
class EntryImpl implements Entry {
|
||||
@ -102,7 +100,7 @@ class EntryImpl implements Entry {
|
||||
void setText(final String newText) {
|
||||
this.text = newText;
|
||||
|
||||
SwingUtil.invokeLater(new Runnable() {
|
||||
parent.dispatch(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
@ -169,18 +167,14 @@ class EntryImpl implements Entry {
|
||||
@Override
|
||||
public final
|
||||
void remove() {
|
||||
try {
|
||||
SwingUtil.invokeAndWait(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
removePrivate();
|
||||
parent._native.remove(_native);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
SystemTray.logger.error("Error processing event on the dispatch thread.", e);
|
||||
}
|
||||
parent.dispatchAndWait(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
removePrivate();
|
||||
parent._native.remove(_native);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// called when this item is removed. Necessary to cleanup/remove itself
|
||||
|
@ -22,7 +22,7 @@ import java.io.File;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
import dorkbox.systemTray.SystemTrayMenuAction;
|
||||
import dorkbox.systemTray.Action;
|
||||
import dorkbox.util.SwingUtil;
|
||||
|
||||
class EntryItem extends EntryImpl {
|
||||
@ -30,10 +30,10 @@ class EntryItem extends EntryImpl {
|
||||
private final ActionListener swingCallback;
|
||||
|
||||
private volatile boolean hasLegitIcon = false;
|
||||
private volatile SystemTrayMenuAction callback;
|
||||
private volatile Action callback;
|
||||
|
||||
// this is ALWAYS called on the EDT.
|
||||
EntryItem(final MenuImpl parent, final SystemTrayMenuAction callback) {
|
||||
EntryItem(final MenuImpl parent, final Action callback) {
|
||||
super(parent, new AdjustedJMenuItem());
|
||||
this.callback = callback;
|
||||
|
||||
@ -58,7 +58,7 @@ class EntryItem extends EntryImpl {
|
||||
|
||||
@Override
|
||||
public
|
||||
void setCallback(final SystemTrayMenuAction callback) {
|
||||
void setCallback(final Action callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ import java.io.File;
|
||||
|
||||
import javax.swing.JSeparator;
|
||||
|
||||
import dorkbox.systemTray.SystemTrayMenuAction;
|
||||
import dorkbox.systemTray.Action;
|
||||
|
||||
class EntrySeparator extends EntryImpl implements dorkbox.systemTray.Separator {
|
||||
|
||||
@ -54,6 +54,6 @@ class EntrySeparator extends EntryImpl implements dorkbox.systemTray.Separator {
|
||||
|
||||
@Override
|
||||
public
|
||||
void setCallback(final SystemTrayMenuAction callback) {
|
||||
void setCallback(final Action callback) {
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ import java.io.File;
|
||||
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
import dorkbox.systemTray.Action;
|
||||
import dorkbox.systemTray.Status;
|
||||
import dorkbox.systemTray.SystemTrayMenuAction;
|
||||
|
||||
class EntryStatus extends EntryImpl implements Status {
|
||||
|
||||
@ -64,7 +64,7 @@ class EntryStatus extends EntryImpl implements Status {
|
||||
|
||||
@Override
|
||||
public
|
||||
void setCallback(final SystemTrayMenuAction callback) {
|
||||
void setCallback(final Action callback) {
|
||||
|
||||
}
|
||||
}
|
||||
|
62
src/dorkbox/systemTray/swing/EntryWidget.java
Normal file
62
src/dorkbox/systemTray/swing/EntryWidget.java
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2016 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.swing;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import dorkbox.systemTray.Action;
|
||||
|
||||
// TODO: buggy. The menu will **sometimes** stop responding to the "enter" key after this. Mnemonics still work however.
|
||||
class EntryWidget extends EntryImpl implements dorkbox.systemTray.Separator {
|
||||
|
||||
// this is ALWAYS called on the EDT.
|
||||
EntryWidget(final MenuImpl parent, JComponent widget) {
|
||||
super(parent, widget);
|
||||
|
||||
_native.setEnabled(true);
|
||||
}
|
||||
|
||||
// called in the EDT thread
|
||||
@Override
|
||||
void renderText(final String text) {
|
||||
}
|
||||
|
||||
@Override
|
||||
void setImage_(final File imageFile) {
|
||||
}
|
||||
|
||||
@Override
|
||||
void removePrivate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public
|
||||
void setShortcut(final char key) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public
|
||||
boolean hasImage() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public
|
||||
void setCallback(final Action callback) {
|
||||
}
|
||||
}
|
@ -30,20 +30,21 @@ import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
import dorkbox.systemTray.Action;
|
||||
import dorkbox.systemTray.Entry;
|
||||
import dorkbox.systemTray.Menu;
|
||||
import dorkbox.systemTray.Status;
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.SystemTrayMenuAction;
|
||||
import dorkbox.systemTray.util.ImageUtils;
|
||||
import dorkbox.util.SwingUtil;
|
||||
|
||||
// this is a weird composite class, because it must be a Menu, but ALSO a Entry -- so it has both
|
||||
@SuppressWarnings("ForLoopReplaceableByForEach")
|
||||
class MenuImpl implements Menu {
|
||||
public static final AtomicInteger MENU_ID_COUNTER = new AtomicInteger();
|
||||
static final AtomicInteger MENU_ID_COUNTER = new AtomicInteger();
|
||||
private final int id = MenuImpl.MENU_ID_COUNTER.getAndIncrement();
|
||||
|
||||
protected final java.util.List<Entry> menuEntries = new ArrayList<Entry>();
|
||||
private final java.util.List<Entry> menuEntries = new ArrayList<Entry>();
|
||||
|
||||
private final SystemTray systemTray;
|
||||
private final Menu parent;
|
||||
@ -69,13 +70,11 @@ class MenuImpl implements Menu {
|
||||
this._native = _native;
|
||||
}
|
||||
|
||||
protected
|
||||
void dispatch(final Runnable runnable) {
|
||||
// this will properly check if we are running on the EDT
|
||||
SwingUtil.invokeLater(runnable);
|
||||
}
|
||||
|
||||
protected
|
||||
void dispatchAndWait(final Runnable runnable) {
|
||||
// this will properly check if we are running on the EDT
|
||||
try {
|
||||
@ -98,7 +97,7 @@ class MenuImpl implements Menu {
|
||||
* NOT ALWAYS CALLED ON EDT
|
||||
*/
|
||||
private
|
||||
Entry addEntry_(final String menuText, final File imagePath, final SystemTrayMenuAction callback) {
|
||||
Entry addEntry_(final String menuText, final File imagePath, final Action callback) {
|
||||
if (menuText == null) {
|
||||
throw new NullPointerException("Menu text cannot be null");
|
||||
}
|
||||
@ -154,7 +153,7 @@ class MenuImpl implements Menu {
|
||||
if (entry == null) {
|
||||
// must always be called on the EDT
|
||||
entry = new MenuImpl(getSystemTray(), MenuImpl.this, new AdjustedJMenu());
|
||||
_native.add(((MenuImpl) entry)._native);
|
||||
_native.add(((MenuImpl) entry)._native); // have to add it separately
|
||||
|
||||
entry.setText(menuText);
|
||||
entry.setImage(imagePath);
|
||||
@ -256,6 +255,31 @@ class MenuImpl implements Menu {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: buggy. The menu will **sometimes** stop responding to the "enter" key after this. Mnemonics still work however.
|
||||
// public
|
||||
// Entry addWidget(final JComponent widget) {
|
||||
// if (widget == null) {
|
||||
// throw new NullPointerException("Widget cannot be null");
|
||||
// }
|
||||
//
|
||||
// final AtomicReference<Entry> value = new AtomicReference<Entry>();
|
||||
//
|
||||
// dispatchAndWait(new Runnable() {
|
||||
// @Override
|
||||
// public
|
||||
// void run() {
|
||||
// synchronized (menuEntries) {
|
||||
// // must always be called on the EDT
|
||||
// Entry entry = new EntryWidget(MenuImpl.this, widget);
|
||||
// value.set(entry);
|
||||
// menuEntries.add(entry);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// return value.get();
|
||||
// }
|
||||
|
||||
|
||||
public
|
||||
Entry get(final String menuText) {
|
||||
@ -265,7 +289,8 @@ class MenuImpl implements Menu {
|
||||
|
||||
// Must be wrapped in a synchronized block for object visibility
|
||||
synchronized (menuEntries) {
|
||||
for (Entry entry : menuEntries) {
|
||||
for (int i = 0, menuEntriesSize = menuEntries.size(); i < menuEntriesSize; i++) {
|
||||
final Entry entry = menuEntries.get(i);
|
||||
String text = entry.getText();
|
||||
|
||||
// text can be null
|
||||
@ -278,23 +303,25 @@ class MenuImpl implements Menu {
|
||||
return null;
|
||||
}
|
||||
|
||||
// ignores status + separators
|
||||
public
|
||||
Entry getFirst() {
|
||||
return get(0);
|
||||
}
|
||||
|
||||
// ignores status + separators
|
||||
public
|
||||
Entry getLast() {
|
||||
// Must be wrapped in a synchronized block for object visibility
|
||||
synchronized (menuEntries) {
|
||||
if (!menuEntries.isEmpty()) {
|
||||
Entry entry = null;
|
||||
for (int i = 0, menuEntriesSize = menuEntries.size(); i < menuEntriesSize; i++) {
|
||||
Entry entry;
|
||||
for (int i = menuEntries.size()-1; i >= 0; i--) {
|
||||
entry = menuEntries.get(i);
|
||||
}
|
||||
|
||||
if (!(entry instanceof dorkbox.systemTray.Separator || entry instanceof Status)) {
|
||||
return entry;
|
||||
if (!(entry instanceof dorkbox.systemTray.Separator || entry instanceof Status)) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -302,6 +329,7 @@ class MenuImpl implements Menu {
|
||||
return null;
|
||||
}
|
||||
|
||||
// ignores status + separators
|
||||
public
|
||||
Entry get(final int menuIndex) {
|
||||
if (menuIndex < 0) {
|
||||
@ -331,12 +359,12 @@ class MenuImpl implements Menu {
|
||||
|
||||
|
||||
public
|
||||
Entry addEntry(String menuText, SystemTrayMenuAction callback) {
|
||||
Entry addEntry(String menuText, Action callback) {
|
||||
return addEntry(menuText, (String) null, callback);
|
||||
}
|
||||
|
||||
public
|
||||
Entry addEntry(String menuText, String imagePath, SystemTrayMenuAction callback) {
|
||||
Entry addEntry(String menuText, String imagePath, Action callback) {
|
||||
if (imagePath == null) {
|
||||
return addEntry_(menuText, null, callback);
|
||||
}
|
||||
@ -346,7 +374,7 @@ class MenuImpl implements Menu {
|
||||
}
|
||||
|
||||
public
|
||||
Entry addEntry(String menuText, URL imageUrl, SystemTrayMenuAction callback) {
|
||||
Entry addEntry(String menuText, URL imageUrl, Action callback) {
|
||||
if (imageUrl == null) {
|
||||
return addEntry_(menuText, null, callback);
|
||||
}
|
||||
@ -356,7 +384,7 @@ class MenuImpl implements Menu {
|
||||
}
|
||||
|
||||
public
|
||||
Entry addEntry(String menuText, String cacheName, InputStream imageStream, SystemTrayMenuAction callback) {
|
||||
Entry addEntry(String menuText, String cacheName, InputStream imageStream, Action callback) {
|
||||
if (imageStream == null) {
|
||||
return addEntry_(menuText, null, callback);
|
||||
}
|
||||
@ -366,7 +394,7 @@ class MenuImpl implements Menu {
|
||||
}
|
||||
|
||||
public
|
||||
Entry addEntry(String menuText, InputStream imageStream, SystemTrayMenuAction callback) {
|
||||
Entry addEntry(String menuText, InputStream imageStream, Action callback) {
|
||||
if (imageStream == null) {
|
||||
return addEntry_(menuText, null, callback);
|
||||
}
|
||||
@ -483,29 +511,54 @@ class MenuImpl implements Menu {
|
||||
}
|
||||
}
|
||||
|
||||
public
|
||||
String getStatus() {
|
||||
synchronized (menuEntries) {
|
||||
Entry entry = menuEntries.get(0);
|
||||
if (entry instanceof EntryStatus) {
|
||||
return entry.getText();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public
|
||||
void setStatus(final String statusText) {
|
||||
final MenuImpl _this = this;
|
||||
dispatchAndWait(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
void run() {
|
||||
synchronized (menuEntries) {
|
||||
// status is ALWAYS at 0 index...
|
||||
EntryImpl menuEntry = null;
|
||||
if (!menuEntries.isEmpty()) {
|
||||
menuEntry = (EntryImpl) menuEntries.get(0);
|
||||
}
|
||||
|
||||
if (menuEntry instanceof EntryStatus) {
|
||||
// set the text or delete...
|
||||
|
||||
if (statusText == null) {
|
||||
// delete
|
||||
remove(menuEntry);
|
||||
}
|
||||
else {
|
||||
// set text
|
||||
menuEntry.setText(statusText);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
// create a new one
|
||||
menuEntry = new EntryStatus(_this, statusText);
|
||||
// status is ALWAYS at 0 index...
|
||||
menuEntries.add(0, menuEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -531,7 +584,7 @@ class MenuImpl implements Menu {
|
||||
|
||||
@Override
|
||||
public
|
||||
void setCallback(final SystemTrayMenuAction callback) {
|
||||
void setCallback(final Action callback) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -702,7 +755,7 @@ class MenuImpl implements Menu {
|
||||
|
||||
@Override
|
||||
public
|
||||
void clear() {
|
||||
void removeAll() {
|
||||
dispatch(new Runnable() {
|
||||
@Override
|
||||
public
|
||||
@ -713,8 +766,33 @@ class MenuImpl implements Menu {
|
||||
for (Entry entry : menuEntriesCopy) {
|
||||
entry.remove();
|
||||
}
|
||||
menuEntries.clear();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public final
|
||||
int hashCode() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final
|
||||
boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MenuImpl other = (MenuImpl) obj;
|
||||
return this.id == other.id;
|
||||
}
|
||||
}
|
||||
|
@ -140,12 +140,7 @@ class TrayPopup extends JPopupMenu {
|
||||
hiddenDialog.dispatchEvent(new WindowEvent(hiddenDialog, WindowEvent.WINDOW_CLOSING));
|
||||
}
|
||||
|
||||
void doShow(final Point point, int offset) {
|
||||
// when the menu entries are changed, this makes sure to correctly show them
|
||||
invalidate();
|
||||
revalidate();
|
||||
doLayout();
|
||||
|
||||
void doShow(final MenuImpl systemTray, final Point point, int offset) {
|
||||
Dimension size = getPreferredSize();
|
||||
Rectangle bounds = ScreenUtil.getScreenBoundsAt(point);
|
||||
|
||||
@ -185,6 +180,13 @@ class TrayPopup extends JPopupMenu {
|
||||
setLocation(x, y);
|
||||
setVisible(true);
|
||||
|
||||
// when the menu entries are changed, this makes sure to correctly show them
|
||||
invalidate();
|
||||
revalidate();
|
||||
doLayout();
|
||||
|
||||
requestFocusInWindow();
|
||||
|
||||
((EntryImpl) systemTray.getFirst())._native.requestFocusInWindow();
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ class _AppIndicatorTray extends MenuImpl {
|
||||
.getLocation();
|
||||
|
||||
TrayPopup popupMenu = (TrayPopup) _native;
|
||||
popupMenu.doShow(point, SystemTray.DEFAULT_TRAY_SIZE);
|
||||
popupMenu.doShow(_AppIndicatorTray.this, point, SystemTray.DEFAULT_TRAY_SIZE);
|
||||
}
|
||||
};
|
||||
|
||||
@ -219,8 +219,8 @@ class _AppIndicatorTray extends MenuImpl {
|
||||
Gtk.shutdownGui();
|
||||
|
||||
// uses EDT
|
||||
clear();
|
||||
remove();
|
||||
removeAll();
|
||||
remove(); // remove ourselves from our parent
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ class _GtkStatusIconTray extends MenuImpl {
|
||||
.getLocation();
|
||||
|
||||
TrayPopup popupMenu = (TrayPopup) _native;
|
||||
popupMenu.doShow(point, 0);
|
||||
popupMenu.doShow(_GtkStatusIconTray.this, point, 0);
|
||||
}
|
||||
};
|
||||
|
||||
@ -171,8 +171,8 @@ class _GtkStatusIconTray extends MenuImpl {
|
||||
Gtk.shutdownGui();
|
||||
|
||||
// uses EDT
|
||||
clear();
|
||||
remove();
|
||||
removeAll();
|
||||
remove(); // remove ourselves from our parent
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ class _SwingTray extends MenuImpl {
|
||||
void run() {
|
||||
tray.remove(trayIcon);
|
||||
|
||||
clear();
|
||||
removeAll();
|
||||
remove();
|
||||
}
|
||||
});
|
||||
@ -100,7 +100,7 @@ class _SwingTray extends MenuImpl {
|
||||
public
|
||||
void mousePressed(MouseEvent e) {
|
||||
TrayPopup popupMenu = (TrayPopup) _native;
|
||||
popupMenu.doShow(e.getPoint(), 0);
|
||||
popupMenu.doShow(_SwingTray.this, e.getPoint(), 0);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -18,10 +18,10 @@ package dorkbox;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import dorkbox.systemTray.Action;
|
||||
import dorkbox.systemTray.Entry;
|
||||
import dorkbox.systemTray.Menu;
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.SystemTrayMenuAction;
|
||||
|
||||
/**
|
||||
* Icons from 'SJJB Icons', public domain/CC0 icon set
|
||||
@ -29,9 +29,18 @@ import dorkbox.systemTray.SystemTrayMenuAction;
|
||||
public
|
||||
class TestTray {
|
||||
|
||||
public static final URL BLACK_MAIL = TestTray.class.getResource("transport_bus_station.p.000000.32.png");
|
||||
public static final URL GREEN_MAIL = TestTray.class.getResource("transport_bus_station.p.39AC39.32.png");
|
||||
public static final URL LT_GRAY_MAIL = TestTray.class.getResource("transport_bus_station.p.999999.32.png");
|
||||
public static final URL BLUE_CAMPING = TestTray.class.getResource("accommodation_camping.glow.0092DA.32.png");
|
||||
public static final URL BLACK_FIRE = TestTray.class.getResource("amenity_firestation.p.000000.32.png");
|
||||
|
||||
public static final URL BLACK_MAIL = TestTray.class.getResource("amenity_post_box.p.000000.32.png");
|
||||
public static final URL GREEN_MAIL = TestTray.class.getResource("amenity_post_box.p.39AC39.32.png");
|
||||
|
||||
public static final URL BLACK_BUS = TestTray.class.getResource("transport_bus_station.p.000000.32.png");
|
||||
public static final URL LT_GRAY_BUS = TestTray.class.getResource("transport_bus_station.p.999999.32.png");
|
||||
|
||||
public static final URL BLACK_TRAIN = TestTray.class.getResource("transport_train_station.p.000000.32.png");
|
||||
public static final URL GREEN_TRAIN = TestTray.class.getResource("transport_train_station.p.39AC39.32.png");
|
||||
public static final URL LT_GRAY_TRAIN = TestTray.class.getResource("transport_train_station.p.666666.32.png");
|
||||
|
||||
public static
|
||||
void main(String[] args) {
|
||||
@ -40,8 +49,8 @@ class TestTray {
|
||||
}
|
||||
|
||||
private SystemTray systemTray;
|
||||
private SystemTrayMenuAction callbackGreen;
|
||||
private SystemTrayMenuAction callbackGray;
|
||||
private Action callbackGreen;
|
||||
private Action callbackGray;
|
||||
|
||||
public
|
||||
TestTray() {
|
||||
@ -50,15 +59,15 @@ class TestTray {
|
||||
throw new RuntimeException("Unable to load SystemTray!");
|
||||
}
|
||||
|
||||
systemTray.setImage(LT_GRAY_MAIL);
|
||||
systemTray.setImage(LT_GRAY_TRAIN);
|
||||
systemTray.setStatus("No Mail");
|
||||
|
||||
callbackGreen = new SystemTrayMenuAction() {
|
||||
callbackGreen = new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
systemTray.setStatus("Some Mail!");
|
||||
systemTray.setImage(GREEN_MAIL);
|
||||
systemTray.setImage(GREEN_TRAIN);
|
||||
|
||||
entry.setCallback(callbackGray);
|
||||
entry.setImage(BLACK_MAIL);
|
||||
@ -67,12 +76,12 @@ class TestTray {
|
||||
}
|
||||
};
|
||||
|
||||
callbackGray = new SystemTrayMenuAction() {
|
||||
callbackGray = new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
systemTray.setStatus(null);
|
||||
systemTray.setImage(BLACK_MAIL);
|
||||
systemTray.setImage(BLACK_TRAIN);
|
||||
|
||||
entry.setCallback(null);
|
||||
// systemTray.setStatus("Mail Empty");
|
||||
@ -87,23 +96,34 @@ class TestTray {
|
||||
|
||||
this.systemTray.addSeparator();
|
||||
|
||||
final Menu submenu = this.systemTray.addMenu("Options", BLACK_MAIL);
|
||||
submenu.addEntry("Disable menu", LT_GRAY_MAIL, new SystemTrayMenuAction() {
|
||||
final Menu submenu = this.systemTray.addMenu("Options", BLUE_CAMPING);
|
||||
submenu.setShortcut('t');
|
||||
submenu.addEntry("Disable menu", BLACK_BUS, new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
submenu.setEnabled(false);
|
||||
}
|
||||
});
|
||||
submenu.addEntry("Hide tray", BLACK_MAIL, new SystemTrayMenuAction() {
|
||||
// TODO: buggy. The menu will **sometimes** stop responding to the "enter" key after this. Mnemonics still work however.
|
||||
// submenu.addEntry("Add widget", GREEN_BUS, new Action() {
|
||||
// @Override
|
||||
// public
|
||||
// void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
// JProgressBar progressBar = new JProgressBar(0, 100);
|
||||
// progressBar.setValue(new Random().nextInt(101));
|
||||
// progressBar.setStringPainted(true);
|
||||
// systemTray.addWidget(progressBar);
|
||||
// }
|
||||
// });
|
||||
submenu.addEntry("Hide tray", LT_GRAY_BUS, new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
systemTray.setEnabled(false);
|
||||
}
|
||||
});
|
||||
|
||||
submenu.addEntry("Remove menu", GREEN_MAIL, new SystemTrayMenuAction() {
|
||||
submenu.addEntry("Remove menu", BLACK_FIRE, new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
@ -112,7 +132,7 @@ class TestTray {
|
||||
});
|
||||
|
||||
|
||||
systemTray.addEntry("Quit", new SystemTrayMenuAction() {
|
||||
systemTray.addEntry("Quit", new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
|
@ -18,10 +18,10 @@ package dorkbox;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import dorkbox.systemTray.Action;
|
||||
import dorkbox.systemTray.Entry;
|
||||
import dorkbox.systemTray.Menu;
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.SystemTrayMenuAction;
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
@ -39,9 +39,18 @@ import javafx.stage.Stage;
|
||||
public
|
||||
class TestTrayJavaFX extends Application {
|
||||
|
||||
public static final URL BLACK_MAIL = TestTray.class.getResource("transport_bus_station.p.000000.32.png");
|
||||
public static final URL GREEN_MAIL = TestTray.class.getResource("transport_bus_station.p.39AC39.32.png");
|
||||
public static final URL LT_GRAY_MAIL = TestTray.class.getResource("transport_bus_station.p.999999.32.png");
|
||||
public static final URL BLUE_CAMPING = TestTray.class.getResource("accommodation_camping.glow.0092DA.32.png");
|
||||
public static final URL BLACK_FIRE = TestTray.class.getResource("amenity_firestation.p.000000.32.png");
|
||||
|
||||
public static final URL BLACK_MAIL = TestTray.class.getResource("amenity_post_box.p.000000.32.png");
|
||||
public static final URL GREEN_MAIL = TestTray.class.getResource("amenity_post_box.p.39AC39.32.png");
|
||||
|
||||
public static final URL BLACK_BUS = TestTray.class.getResource("transport_bus_station.p.000000.32.png");
|
||||
public static final URL LT_GRAY_BUS = TestTray.class.getResource("transport_bus_station.p.999999.32.png");
|
||||
|
||||
public static final URL BLACK_TRAIN = TestTray.class.getResource("transport_train_station.p.000000.32.png");
|
||||
public static final URL GREEN_TRAIN = TestTray.class.getResource("transport_train_station.p.39AC39.32.png");
|
||||
public static final URL LT_GRAY_TRAIN = TestTray.class.getResource("transport_train_station.p.666666.32.png");
|
||||
|
||||
public static
|
||||
void main(String[] args) {
|
||||
@ -50,8 +59,8 @@ class TestTrayJavaFX extends Application {
|
||||
}
|
||||
|
||||
private SystemTray systemTray;
|
||||
private SystemTrayMenuAction callbackGreen;
|
||||
private SystemTrayMenuAction callbackGray;
|
||||
private Action callbackGreen;
|
||||
private Action callbackGray;
|
||||
|
||||
public
|
||||
TestTrayJavaFX() {
|
||||
@ -83,16 +92,15 @@ class TestTrayJavaFX extends Application {
|
||||
throw new RuntimeException("Unable to load SystemTray!");
|
||||
}
|
||||
|
||||
this.systemTray.setImage(LT_GRAY_MAIL);
|
||||
|
||||
systemTray.setImage(LT_GRAY_TRAIN);
|
||||
systemTray.setStatus("No Mail");
|
||||
|
||||
callbackGreen = new SystemTrayMenuAction() {
|
||||
callbackGreen = new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
systemTray.setImage(GREEN_MAIL);
|
||||
systemTray.setStatus("Some Mail!");
|
||||
systemTray.setImage(GREEN_TRAIN);
|
||||
|
||||
entry.setCallback(callbackGray);
|
||||
entry.setImage(BLACK_MAIL);
|
||||
@ -101,12 +109,12 @@ class TestTrayJavaFX extends Application {
|
||||
}
|
||||
};
|
||||
|
||||
callbackGray = new SystemTrayMenuAction() {
|
||||
callbackGray = new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
systemTray.setStatus(null);
|
||||
systemTray.setImage(BLACK_MAIL);
|
||||
systemTray.setImage(BLACK_TRAIN);
|
||||
|
||||
entry.setCallback(null);
|
||||
// systemTray.setStatus("Mail Empty");
|
||||
@ -121,22 +129,34 @@ class TestTrayJavaFX extends Application {
|
||||
|
||||
this.systemTray.addSeparator();
|
||||
|
||||
final Menu submenu = this.systemTray.addMenu("Options", BLACK_MAIL);
|
||||
submenu.addEntry("Disable menu", LT_GRAY_MAIL, new SystemTrayMenuAction() {
|
||||
final Menu submenu = this.systemTray.addMenu("Options", BLUE_CAMPING);
|
||||
submenu.setShortcut('t');
|
||||
submenu.addEntry("Disable menu", BLACK_BUS, new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
submenu.setEnabled(false);
|
||||
}
|
||||
});
|
||||
submenu.addEntry("Hide tray", BLACK_MAIL, new SystemTrayMenuAction() {
|
||||
// TODO: buggy. The menu will **sometimes** stop responding to the "enter" key after this. Mnemonics still work however.
|
||||
// submenu.addEntry("Add widget", GREEN_BUS, new Action() {
|
||||
// @Override
|
||||
// public
|
||||
// void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
// JProgressBar progressBar = new JProgressBar(0, 100);
|
||||
// progressBar.setValue(new Random().nextInt(101));
|
||||
// progressBar.setStringPainted(true);
|
||||
// systemTray.addWidget(progressBar);
|
||||
// }
|
||||
// });
|
||||
submenu.addEntry("Hide tray", LT_GRAY_BUS, new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
systemTray.setEnabled(false);
|
||||
}
|
||||
});
|
||||
submenu.addEntry("Remove menu", GREEN_MAIL, new SystemTrayMenuAction() {
|
||||
submenu.addEntry("Remove menu", BLACK_FIRE, new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
@ -144,7 +164,7 @@ class TestTrayJavaFX extends Application {
|
||||
}
|
||||
});
|
||||
|
||||
systemTray.addEntry("Quit", new SystemTrayMenuAction() {
|
||||
systemTray.addEntry("Quit", new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
|
@ -23,10 +23,10 @@ import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import dorkbox.systemTray.Action;
|
||||
import dorkbox.systemTray.Entry;
|
||||
import dorkbox.systemTray.Menu;
|
||||
import dorkbox.systemTray.SystemTray;
|
||||
import dorkbox.systemTray.SystemTrayMenuAction;
|
||||
|
||||
/**
|
||||
* Icons from 'SJJB Icons', public domain/CC0 icon set
|
||||
@ -36,9 +36,18 @@ import dorkbox.systemTray.SystemTrayMenuAction;
|
||||
public
|
||||
class TestTraySwt {
|
||||
|
||||
public static final URL BLACK_MAIL = TestTray.class.getResource("transport_bus_station.p.000000.32.png");
|
||||
public static final URL GREEN_MAIL = TestTray.class.getResource("transport_bus_station.p.39AC39.32.png");
|
||||
public static final URL LT_GRAY_MAIL = TestTray.class.getResource("transport_bus_station.p.999999.32.png");
|
||||
public static final URL BLUE_CAMPING = TestTray.class.getResource("accommodation_camping.glow.0092DA.32.png");
|
||||
public static final URL BLACK_FIRE = TestTray.class.getResource("amenity_firestation.p.000000.32.png");
|
||||
|
||||
public static final URL BLACK_MAIL = TestTray.class.getResource("amenity_post_box.p.000000.32.png");
|
||||
public static final URL GREEN_MAIL = TestTray.class.getResource("amenity_post_box.p.39AC39.32.png");
|
||||
|
||||
public static final URL BLACK_BUS = TestTray.class.getResource("transport_bus_station.p.000000.32.png");
|
||||
public static final URL LT_GRAY_BUS = TestTray.class.getResource("transport_bus_station.p.999999.32.png");
|
||||
|
||||
public static final URL BLACK_TRAIN = TestTray.class.getResource("transport_train_station.p.000000.32.png");
|
||||
public static final URL GREEN_TRAIN = TestTray.class.getResource("transport_train_station.p.39AC39.32.png");
|
||||
public static final URL LT_GRAY_TRAIN = TestTray.class.getResource("transport_train_station.p.666666.32.png");
|
||||
|
||||
public static
|
||||
void main(String[] args) {
|
||||
@ -49,8 +58,8 @@ class TestTraySwt {
|
||||
}
|
||||
|
||||
private SystemTray systemTray;
|
||||
private SystemTrayMenuAction callbackGreen;
|
||||
private SystemTrayMenuAction callbackGray;
|
||||
private Action callbackGreen;
|
||||
private Action callbackGray;
|
||||
|
||||
public
|
||||
TestTraySwt() {
|
||||
@ -67,16 +76,15 @@ class TestTraySwt {
|
||||
throw new RuntimeException("Unable to load SystemTray!");
|
||||
}
|
||||
|
||||
this.systemTray.setImage(LT_GRAY_MAIL);
|
||||
|
||||
systemTray.setImage(LT_GRAY_TRAIN);
|
||||
systemTray.setStatus("No Mail");
|
||||
|
||||
callbackGreen = new SystemTrayMenuAction() {
|
||||
callbackGreen = new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
systemTray.setStatus("Some Mail!");
|
||||
systemTray.setImage(GREEN_MAIL);
|
||||
systemTray.setImage(GREEN_TRAIN);
|
||||
|
||||
entry.setCallback(callbackGray);
|
||||
entry.setImage(BLACK_MAIL);
|
||||
@ -85,12 +93,12 @@ class TestTraySwt {
|
||||
}
|
||||
};
|
||||
|
||||
callbackGray = new SystemTrayMenuAction() {
|
||||
callbackGray = new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
systemTray.setStatus(null);
|
||||
systemTray.setImage(BLACK_MAIL);
|
||||
systemTray.setImage(BLACK_TRAIN);
|
||||
|
||||
entry.setCallback(null);
|
||||
// systemTray.setStatus("Mail Empty");
|
||||
@ -105,22 +113,34 @@ class TestTraySwt {
|
||||
|
||||
this.systemTray.addSeparator();
|
||||
|
||||
final Menu submenu = this.systemTray.addMenu("Options", BLACK_MAIL);
|
||||
submenu.addEntry("Disable menu", LT_GRAY_MAIL, new SystemTrayMenuAction() {
|
||||
final Menu submenu = this.systemTray.addMenu("Options", BLUE_CAMPING);
|
||||
submenu.setShortcut('t');
|
||||
submenu.addEntry("Disable menu", BLACK_BUS, new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
submenu.setEnabled(false);
|
||||
}
|
||||
});
|
||||
submenu.addEntry("Hide tray", BLACK_MAIL, new SystemTrayMenuAction() {
|
||||
// TODO: buggy. The menu will **sometimes** stop responding to the "enter" key after this. Mnemonics still work however.
|
||||
// submenu.addEntry("Add widget", GREEN_BUS, new Action() {
|
||||
// @Override
|
||||
// public
|
||||
// void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
// JProgressBar progressBar = new JProgressBar(0, 100);
|
||||
// progressBar.setValue(new Random().nextInt(101));
|
||||
// progressBar.setStringPainted(true);
|
||||
// systemTray.addWidget(progressBar);
|
||||
// }
|
||||
// });
|
||||
submenu.addEntry("Hide tray", LT_GRAY_BUS, new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
systemTray.setEnabled(false);
|
||||
}
|
||||
});
|
||||
submenu.addEntry("Remove menu", GREEN_MAIL, new SystemTrayMenuAction() {
|
||||
submenu.addEntry("Remove menu", BLACK_FIRE, new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
@ -128,7 +148,7 @@ class TestTraySwt {
|
||||
}
|
||||
});
|
||||
|
||||
systemTray.addEntry("Quit", new SystemTrayMenuAction() {
|
||||
systemTray.addEntry("Quit", new Action() {
|
||||
@Override
|
||||
public
|
||||
void onClick(final SystemTray systemTray, final Menu parent, final Entry entry) {
|
||||
|
BIN
test/dorkbox/accommodation_camping.glow.0092DA.32.png
Normal file
BIN
test/dorkbox/accommodation_camping.glow.0092DA.32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
test/dorkbox/amenity_firestation.p.000000.32.png
Normal file
BIN
test/dorkbox/amenity_firestation.p.000000.32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 636 B |
BIN
test/dorkbox/amenity_post_box.p.000000.32.png
Normal file
BIN
test/dorkbox/amenity_post_box.p.000000.32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 474 B |
BIN
test/dorkbox/amenity_post_box.p.39AC39.32.png
Normal file
BIN
test/dorkbox/amenity_post_box.p.39AC39.32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 669 B |
BIN
test/dorkbox/transport_train_station.p.000000.32.png
Normal file
BIN
test/dorkbox/transport_train_station.p.000000.32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 623 B |
BIN
test/dorkbox/transport_train_station.p.666666.32.png
Normal file
BIN
test/dorkbox/transport_train_station.p.666666.32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 937 B |
Loading…
Reference in New Issue
Block a user