SystemTray/test/dorkbox/TestTray.java

114 lines
3.8 KiB
Java
Raw Normal View History

2015-11-09 16:21:15 +01:00
/*
* Copyright 2015 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;
2016-09-22 16:18:50 +02:00
import java.net.URL;
import dorkbox.systemTray.Menu;
import dorkbox.systemTray.MenuEntry;
import dorkbox.systemTray.SystemTray;
import dorkbox.systemTray.SystemTrayMenuAction;
2015-11-09 16:21:15 +01:00
/**
* Icons from 'SJJB Icons', public domain/CC0 icon set
*/
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");
2015-11-09 16:21:15 +01:00
public static
void main(String[] args) {
2016-04-05 14:05:53 +02:00
// make sure JNA jar is on the classpath!
2015-11-09 16:21:15 +01:00
new TestTray();
}
private SystemTray systemTray;
private SystemTrayMenuAction callbackGreen;
private SystemTrayMenuAction callbackGray;
2015-11-09 16:21:15 +01:00
public
TestTray() {
this.systemTray = SystemTray.get();
if (systemTray == null) {
throw new RuntimeException("Unable to load SystemTray!");
}
systemTray.setIcon(LT_GRAY_MAIL);
2015-11-09 16:21:15 +01:00
systemTray.setStatus("No Mail");
callbackGreen = new SystemTrayMenuAction() {
@Override
public
void onClick(final SystemTray systemTray, final Menu parent, final MenuEntry menuEntry) {
2015-11-09 16:21:15 +01:00
systemTray.setStatus("Some Mail!");
systemTray.setIcon(GREEN_MAIL);
2015-11-09 16:21:15 +01:00
menuEntry.setCallback(callbackGray);
menuEntry.setImage(BLACK_MAIL);
2015-11-09 16:21:15 +01:00
menuEntry.setText("Delete Mail");
// systemTray.remove(menuEntry);
2015-11-09 16:21:15 +01:00
}
};
callbackGray = new SystemTrayMenuAction() {
@Override
public
void onClick(final SystemTray systemTray, final Menu parent, final MenuEntry menuEntry) {
2015-11-09 16:21:15 +01:00
systemTray.setStatus(null);
systemTray.setIcon(BLACK_MAIL);
2015-11-09 16:21:15 +01:00
menuEntry.setCallback(null);
// systemTray.setStatus("Mail Empty");
systemTray.remove(menuEntry);
2015-11-09 16:21:15 +01:00
System.err.println("POW");
}
};
this.systemTray.addEntry("Green Mail", GREEN_MAIL, callbackGreen);
this.systemTray.addSeparator();
2015-11-09 16:21:15 +01:00
final Menu submenu = this.systemTray.addMenu("Options", BLACK_MAIL);
submenu.addEntry("Disable menu", LT_GRAY_MAIL, new SystemTrayMenuAction() {
2015-11-09 16:21:15 +01:00
@Override
public
void onClick(final SystemTray systemTray, final Menu parent, final MenuEntry entry) {
submenu.setEnabled(false);
}
});
submenu.addEntry("Remove menu", GREEN_MAIL, new SystemTrayMenuAction() {
@Override
public
void onClick(final SystemTray systemTray, final Menu parent, final MenuEntry entry) {
submenu.remove();
}
});
systemTray.addEntry("Quit", new SystemTrayMenuAction() {
@Override
public
void onClick(final SystemTray systemTray, final Menu parent, final MenuEntry menuEntry) {
systemTray.shutdown();
//System.exit(0); not necessary if all non-daemon threads have stopped.
2015-11-09 16:21:15 +01:00
}
});
}
}