mirror of https://github.com/zlatinb/muwire
try to get a tray icon working
parent
770396ba41
commit
ff50a84a48
|
@ -10,7 +10,9 @@ import com.muwire.gui.UISettings
|
||||||
|
|
||||||
import javax.annotation.Nonnull
|
import javax.annotation.Nonnull
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
import javax.swing.ImageIcon
|
||||||
import javax.swing.JLabel
|
import javax.swing.JLabel
|
||||||
|
import javax.swing.JPopupMenu
|
||||||
import javax.swing.JTable
|
import javax.swing.JTable
|
||||||
import javax.swing.LookAndFeel
|
import javax.swing.LookAndFeel
|
||||||
import javax.swing.UIManager
|
import javax.swing.UIManager
|
||||||
|
@ -20,7 +22,11 @@ import static griffon.util.GriffonApplicationUtils.isMacOSX
|
||||||
import static groovy.swing.SwingBuilder.lookAndFeel
|
import static groovy.swing.SwingBuilder.lookAndFeel
|
||||||
|
|
||||||
import java.awt.Font
|
import java.awt.Font
|
||||||
|
import java.awt.MenuItem
|
||||||
|
import java.awt.PopupMenu
|
||||||
|
import java.awt.SystemTray
|
||||||
import java.awt.Toolkit
|
import java.awt.Toolkit
|
||||||
|
import java.awt.TrayIcon
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
import java.util.logging.LogManager
|
import java.util.logging.LogManager
|
||||||
|
|
||||||
|
@ -43,6 +49,39 @@ class Initialize extends AbstractLifecycleHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SystemTray.isSupported()) {
|
||||||
|
try {
|
||||||
|
def tray = SystemTray.getSystemTray()
|
||||||
|
def url = Initialize.class.getResource("/MuWire-32x32.png")
|
||||||
|
def image = new ImageIcon(url, "tray icon").getImage()
|
||||||
|
def popupMenu = new PopupMenu()
|
||||||
|
def trayIcon = new TrayIcon(image, "MuWire", popupMenu)
|
||||||
|
|
||||||
|
|
||||||
|
def exit = new MenuItem("Exit")
|
||||||
|
exit.addActionListener({
|
||||||
|
Core core = application.getContext().get("core")
|
||||||
|
if (core != null)
|
||||||
|
core.shutdown()
|
||||||
|
tray.remove(trayIcon)
|
||||||
|
System.exit(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
popupMenu.add(exit)
|
||||||
|
tray.add(trayIcon)
|
||||||
|
|
||||||
|
|
||||||
|
trayIcon.addActionListener({ e ->
|
||||||
|
def mainFrame = application.getWindowManager().findWindow("main-frame")
|
||||||
|
if (mainFrame != null)
|
||||||
|
mainFrame.setVisible(true)
|
||||||
|
})
|
||||||
|
application.getContext().put("tray-icon", true)
|
||||||
|
} catch (Exception bad) {
|
||||||
|
log.log(Level.WARNING,"couldn't set tray icon",bad)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.info "Loading home dir"
|
log.info "Loading home dir"
|
||||||
def portableHome = System.getProperty("portable.home")
|
def portableHome = System.getProperty("portable.home")
|
||||||
def home = portableHome == null ?
|
def home = portableHome == null ?
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.muwire.gui
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import griffon.core.GriffonApplication
|
||||||
import griffon.core.artifact.GriffonView
|
import griffon.core.artifact.GriffonView
|
||||||
import griffon.core.env.Metadata
|
import griffon.core.env.Metadata
|
||||||
import griffon.inject.MVCMember
|
import griffon.inject.MVCMember
|
||||||
|
@ -11,6 +12,7 @@ import javax.swing.BorderFactory
|
||||||
import javax.swing.Box
|
import javax.swing.Box
|
||||||
import javax.swing.BoxLayout
|
import javax.swing.BoxLayout
|
||||||
import javax.swing.JFileChooser
|
import javax.swing.JFileChooser
|
||||||
|
import javax.swing.JFrame
|
||||||
import javax.swing.JLabel
|
import javax.swing.JLabel
|
||||||
import javax.swing.JMenuItem
|
import javax.swing.JMenuItem
|
||||||
import javax.swing.JPopupMenu
|
import javax.swing.JPopupMenu
|
||||||
|
@ -54,6 +56,7 @@ class MainFrameView {
|
||||||
@MVCMember @Nonnull
|
@MVCMember @Nonnull
|
||||||
MainFrameModel model
|
MainFrameModel model
|
||||||
|
|
||||||
|
@Inject @Nonnull GriffonApplication application
|
||||||
@Inject Metadata metadata
|
@Inject Metadata metadata
|
||||||
|
|
||||||
def downloadsTable
|
def downloadsTable
|
||||||
|
@ -64,10 +67,13 @@ class MainFrameView {
|
||||||
UISettings settings
|
UISettings settings
|
||||||
|
|
||||||
void initUI() {
|
void initUI() {
|
||||||
|
int closeOperation = application.getContext().get("tray-icon") ? JFrame.HIDE_ON_CLOSE : JFrame.EXIT_ON_CLOSE
|
||||||
|
|
||||||
settings = application.context.get("ui-settings")
|
settings = application.context.get("ui-settings")
|
||||||
builder.with {
|
builder.with {
|
||||||
application(size : [1024,768], id: 'main-frame',
|
application(size : [1024,768], id: 'main-frame',
|
||||||
locationRelativeTo : null,
|
locationRelativeTo : null,
|
||||||
|
defaultCloseOperation : closeOperation,
|
||||||
title: application.configuration['application.title'] + " " +
|
title: application.configuration['application.title'] + " " +
|
||||||
metadata["application.version"] + " revision " + metadata["build.revision"],
|
metadata["application.version"] + " revision " + metadata["build.revision"],
|
||||||
iconImage: imageIcon('/MuWire-48x48.png').image,
|
iconImage: imageIcon('/MuWire-48x48.png').image,
|
||||||
|
|
Loading…
Reference in New Issue