Cleaned heirarchy, fixed shutdown methods
This commit is contained in:
parent
85f47eee6a
commit
89405a6cd1
@ -80,7 +80,7 @@ import dorkbox.util.SwingUtil;
|
|||||||
* http://bazaar.launchpad.net/~ubuntu-desktop/ido/gtk3/files
|
* http://bazaar.launchpad.net/~ubuntu-desktop/ido/gtk3/files
|
||||||
*/
|
*/
|
||||||
public
|
public
|
||||||
class _AppIndicatorTray extends _Tray {
|
class _AppIndicatorTray extends MenuImpl {
|
||||||
private volatile AppIndicatorInstanceStruct appIndicator;
|
private volatile AppIndicatorInstanceStruct appIndicator;
|
||||||
private boolean isActive = false;
|
private boolean isActive = false;
|
||||||
private final Runnable popupRunnable;
|
private final Runnable popupRunnable;
|
||||||
@ -107,11 +107,12 @@ class _AppIndicatorTray extends _Tray {
|
|||||||
_AppIndicatorTray(final SystemTray systemTray) {
|
_AppIndicatorTray(final SystemTray systemTray) {
|
||||||
super(systemTray,null, new TrayPopup());
|
super(systemTray,null, new TrayPopup());
|
||||||
|
|
||||||
if (SystemTray.FORCE_TRAY_TYPE == SystemTray.TYPE_GTK_STATUSICON) {
|
if (SystemTray.FORCE_TRAY_TYPE != 0 && SystemTray.FORCE_TRAY_TYPE != SystemTray.TYPE_APP_INDICATOR) {
|
||||||
// if we force GTK type system tray, don't attempt to load AppIndicator libs
|
throw new IllegalArgumentException("Unable to start AppIndicator Tray if 'SystemTray.FORCE_TRAY_TYPE' does not match");
|
||||||
throw new IllegalArgumentException("Unable to start AppIndicator Tray if 'SystemTray.FORCE_TRAY_TYPE' is set to GtkStatusIcon");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImageUtils.determineIconSize();
|
||||||
|
|
||||||
TrayPopup popupMenu = (TrayPopup) _native;
|
TrayPopup popupMenu = (TrayPopup) _native;
|
||||||
popupMenu.pack();
|
popupMenu.pack();
|
||||||
popupMenu.setFocusable(true);
|
popupMenu.setFocusable(true);
|
||||||
@ -218,7 +219,8 @@ class _AppIndicatorTray extends _Tray {
|
|||||||
Gtk.shutdownGui();
|
Gtk.shutdownGui();
|
||||||
|
|
||||||
// uses EDT
|
// uses EDT
|
||||||
super.remove();
|
clear();
|
||||||
|
remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ import dorkbox.systemTray.linux.jna.GEventCallback;
|
|||||||
import dorkbox.systemTray.linux.jna.GdkEventButton;
|
import dorkbox.systemTray.linux.jna.GdkEventButton;
|
||||||
import dorkbox.systemTray.linux.jna.Gobject;
|
import dorkbox.systemTray.linux.jna.Gobject;
|
||||||
import dorkbox.systemTray.linux.jna.Gtk;
|
import dorkbox.systemTray.linux.jna.Gtk;
|
||||||
|
import dorkbox.systemTray.util.ImageUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for handling all system tray interactions via GTK.
|
* Class for handling all system tray interactions via GTK.
|
||||||
@ -40,7 +41,7 @@ import dorkbox.systemTray.linux.jna.Gtk;
|
|||||||
* swing menu popup INSTEAD of GTK menu popups. The "golden standard" is our swing menu popup, since we have 100% control over it.
|
* swing menu popup INSTEAD of GTK menu popups. The "golden standard" is our swing menu popup, since we have 100% control over it.
|
||||||
*/
|
*/
|
||||||
public
|
public
|
||||||
class _GtkStatusIconTray extends _Tray {
|
class _GtkStatusIconTray extends MenuImpl {
|
||||||
private volatile Pointer trayIcon;
|
private volatile Pointer trayIcon;
|
||||||
|
|
||||||
// http://code.metager.de/source/xref/gnome/Platform/gtk%2B/gtk/deprecated/gtkstatusicon.c
|
// http://code.metager.de/source/xref/gnome/Platform/gtk%2B/gtk/deprecated/gtkstatusicon.c
|
||||||
@ -62,11 +63,12 @@ class _GtkStatusIconTray extends _Tray {
|
|||||||
_GtkStatusIconTray(final SystemTray systemTray) {
|
_GtkStatusIconTray(final SystemTray systemTray) {
|
||||||
super(systemTray, null, new TrayPopup());
|
super(systemTray, null, new TrayPopup());
|
||||||
|
|
||||||
if (SystemTray.FORCE_TRAY_TYPE == SystemTray.TYPE_APP_INDICATOR) {
|
if (SystemTray.FORCE_TRAY_TYPE != 0 && SystemTray.FORCE_TRAY_TYPE != SystemTray.TYPE_GTK_STATUSICON) {
|
||||||
// if we force GTK type system tray, don't attempt to load AppIndicator libs
|
throw new IllegalArgumentException("Unable to start GtkStatusIcon if 'SystemTray.FORCE_TRAY_TYPE' does not match");
|
||||||
throw new IllegalArgumentException("Unable to start GtkStatusIcon if 'SystemTray.FORCE_TRAY_TYPE' is set to AppIndicator");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImageUtils.determineIconSize();
|
||||||
|
|
||||||
JPopupMenu popupMenu = (JPopupMenu) _native;
|
JPopupMenu popupMenu = (JPopupMenu) _native;
|
||||||
popupMenu.pack();
|
popupMenu.pack();
|
||||||
popupMenu.setFocusable(true);
|
popupMenu.setFocusable(true);
|
||||||
@ -169,7 +171,8 @@ class _GtkStatusIconTray extends _Tray {
|
|||||||
Gtk.shutdownGui();
|
Gtk.shutdownGui();
|
||||||
|
|
||||||
// uses EDT
|
// uses EDT
|
||||||
super.remove();
|
clear();
|
||||||
|
remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import java.io.File;
|
|||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
|
|
||||||
import dorkbox.systemTray.Entry;
|
import dorkbox.systemTray.util.ImageUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for handling all system tray interaction, via SWING.
|
* Class for handling all system tray interaction, via SWING.
|
||||||
@ -38,7 +38,7 @@ import dorkbox.systemTray.Entry;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings({"SynchronizationOnLocalVariableOrMethodParameter", "WeakerAccess"})
|
@SuppressWarnings({"SynchronizationOnLocalVariableOrMethodParameter", "WeakerAccess"})
|
||||||
public
|
public
|
||||||
class _SwingTray extends _Tray {
|
class _SwingTray extends MenuImpl {
|
||||||
private volatile SystemTray tray;
|
private volatile SystemTray tray;
|
||||||
private volatile TrayIcon trayIcon;
|
private volatile TrayIcon trayIcon;
|
||||||
|
|
||||||
@ -50,6 +50,12 @@ class _SwingTray extends _Tray {
|
|||||||
_SwingTray(final dorkbox.systemTray.SystemTray systemTray) {
|
_SwingTray(final dorkbox.systemTray.SystemTray systemTray) {
|
||||||
super(systemTray, null, new TrayPopup());
|
super(systemTray, null, new TrayPopup());
|
||||||
|
|
||||||
|
if (dorkbox.systemTray.SystemTray.FORCE_TRAY_TYPE != 0 && dorkbox.systemTray.SystemTray.FORCE_TRAY_TYPE != dorkbox.systemTray.SystemTray.TYPE_SWING) {
|
||||||
|
throw new IllegalArgumentException("Unable to start Swing SystemTray if 'SystemTray.FORCE_TRAY_TYPE' does not match");
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageUtils.determineIconSize();
|
||||||
|
|
||||||
_SwingTray.this.tray = SystemTray.getSystemTray();
|
_SwingTray.this.tray = SystemTray.getSystemTray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,13 +67,7 @@ class _SwingTray extends _Tray {
|
|||||||
void run() {
|
void run() {
|
||||||
tray.remove(trayIcon);
|
tray.remove(trayIcon);
|
||||||
|
|
||||||
synchronized (menuEntries) {
|
clear();
|
||||||
for (Entry entry : menuEntries) {
|
|
||||||
entry.remove();
|
|
||||||
}
|
|
||||||
menuEntries.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
remove();
|
remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 javax.swing.JComponent;
|
|
||||||
|
|
||||||
import dorkbox.systemTray.Entry;
|
|
||||||
import dorkbox.systemTray.Menu;
|
|
||||||
import dorkbox.systemTray.SystemTray;
|
|
||||||
import dorkbox.systemTray.util.ImageUtils;
|
|
||||||
|
|
||||||
public abstract
|
|
||||||
class _Tray extends MenuImpl {
|
|
||||||
/**
|
|
||||||
* Called in the EDT
|
|
||||||
*/
|
|
||||||
_Tray(final SystemTray systemTray, final Menu parent, final JComponent _native) {
|
|
||||||
super(systemTray, parent, _native);
|
|
||||||
|
|
||||||
ImageUtils.determineIconSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user