diff options
Diffstat (limited to 'subsonic-booter/src/main/java/net/sourceforge/subsonic/booter/mac/SubsonicController.java')
-rw-r--r-- | subsonic-booter/src/main/java/net/sourceforge/subsonic/booter/mac/SubsonicController.java | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/subsonic-booter/src/main/java/net/sourceforge/subsonic/booter/mac/SubsonicController.java b/subsonic-booter/src/main/java/net/sourceforge/subsonic/booter/mac/SubsonicController.java new file mode 100644 index 00000000..65731f31 --- /dev/null +++ b/subsonic-booter/src/main/java/net/sourceforge/subsonic/booter/mac/SubsonicController.java @@ -0,0 +1,89 @@ +package net.sourceforge.subsonic.booter.mac; + +import net.sourceforge.subsonic.booter.deployer.SubsonicDeployerService; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.net.URL; +import java.net.URI; + +/** + * Controller for the Mac booter. + * + * @author Sindre Mehus + */ +public class SubsonicController { + + private final SubsonicDeployerService deployer; + private final SubsonicFrame frame; + private Action openAction; + private Action controlPanelAction; + private Action quitAction; + + public SubsonicController(SubsonicDeployerService deployer, SubsonicFrame frame) { + this.deployer = deployer; + this.frame = frame; + createActions(); + createComponents(); + } + + private void createActions() { + openAction = new AbstractAction("Open Subsonic Web Page") { + public void actionPerformed(ActionEvent e) { + openBrowser(); + } + }; + + controlPanelAction = new AbstractAction("Subsonic Control Panel") { + public void actionPerformed(ActionEvent e) { + frame.setActive(false); + frame.setActive(true); + } + }; + + quitAction = new AbstractAction("Quit Subsonic") { + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + }; + } + + private void createComponents() { + PopupMenu menu = new PopupMenu(); + menu.add(createMenuItem(openAction)); + menu.add(createMenuItem(controlPanelAction)); + menu.addSeparator(); + menu.add(createMenuItem(quitAction)); + + URL url = getClass().getResource("/images/subsonic-21.png"); + Image image = Toolkit.getDefaultToolkit().createImage(url); + TrayIcon trayIcon = new TrayIcon(image, "Subsonic Music Streamer", menu); + trayIcon.setImageAutoSize(false); + + try { + SystemTray.getSystemTray().add(trayIcon); + } catch (Throwable x) { + System.err.println("Failed to add tray icon."); + } + } + + private MenuItem createMenuItem(Action action) { + MenuItem menuItem = new MenuItem((String) action.getValue(Action.NAME)); + menuItem.addActionListener(action); + return menuItem; + } + + private void openBrowser() { + String url = deployer.getDeploymentInfo().getURL(); + if (url == null) { + return; + } + try { + Desktop.getDesktop().browse(new URI(url)); + } catch (Throwable x) { + x.printStackTrace(); + } + } + +}
\ No newline at end of file |