1 /* 2 * aTunes 3 * Copyright (C) Alex Aranda, Sylvain Gaudard and contributors 4 * 5 * See http://www.atunes.org/wiki/index.php?title=Contributing for information about contributors 6 * 7 * http://www.atunes.org 8 * http://sourceforge.net/projects/atunes 9 * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public License 12 * as published by the Free Software Foundation; either version 2 13 * of the License, or (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 */ 20 21 package net.sourceforge.atunes.kernel.modules.tray; 22 23 import java.awt.TrayIcon; 24 25 import javax.swing.JCheckBoxMenuItem; 26 import javax.swing.JMenuItem; 27 import javax.swing.JPopupMenu; 28 import javax.swing.JSeparator; 29 30 import net.sourceforge.atunes.gui.views.controls.JTrayIcon; 31 import net.sourceforge.atunes.kernel.actions.ExitAction; 32 import net.sourceforge.atunes.kernel.actions.MuteAction; 33 import net.sourceforge.atunes.kernel.actions.PlayAction; 34 import net.sourceforge.atunes.kernel.actions.PlayNextAudioObjectAction; 35 import net.sourceforge.atunes.kernel.actions.PlayPreviousAudioObjectAction; 36 import net.sourceforge.atunes.kernel.actions.RepeatModeAction; 37 import net.sourceforge.atunes.kernel.actions.ShowAboutAction; 38 import net.sourceforge.atunes.kernel.actions.ShuffleModeAction; 39 import net.sourceforge.atunes.kernel.actions.StopCurrentAudioObjectAction; 40 import net.sourceforge.atunes.kernel.actions.ToggleOSDSettingAction; 41 import net.sourceforge.atunes.model.IBeanFactory; 42 import net.sourceforge.atunes.model.IControlsBuilder; 43 44 /** 45 * Responsible of filling tray menu with tray icons 46 * 47 * @author alex 48 * 49 */ 50 public class CommonTrayIconFiller implements ITrayIconFiller { 51 52 private JMenuItem playMenuItem; 53 54 private IBeanFactory beanFactory; 55 56 private IControlsBuilder controlsBuilder; 57 58 /** 59 * @param controlsBuilder 60 */ setControlsBuilder(final IControlsBuilder controlsBuilder)61 public void setControlsBuilder(final IControlsBuilder controlsBuilder) { 62 this.controlsBuilder = controlsBuilder; 63 } 64 65 /** 66 * @param beanFactory 67 */ setBeanFactory(final IBeanFactory beanFactory)68 public void setBeanFactory(final IBeanFactory beanFactory) { 69 this.beanFactory = beanFactory; 70 } 71 72 @Override fillTrayIcon(final TrayIcon trayIcon)73 public void fillTrayIcon(final TrayIcon trayIcon) { 74 if (trayIcon instanceof JTrayIcon) { 75 JPopupMenu popupmenu = ((JTrayIcon) trayIcon).getJTrayIconPopup(); 76 77 popupmenu.add(getPlayMenuItem()); 78 popupmenu.add(getStopMenuItem()); 79 popupmenu.add(getPreviousMenuItem()); 80 popupmenu.add(getNextMenuItem()); 81 popupmenu.add(new JSeparator()); 82 popupmenu.add(getMuteCheckBoxMenuItem()); 83 popupmenu.add(new JSeparator()); 84 popupmenu.add(getShuffleCheckBoxMenuItem()); 85 popupmenu.add(getRepeatCheckBoxMenuItem()); 86 popupmenu.add(new JSeparator()); 87 popupmenu.add(getShowOSDCheckBoxMenuItem()); 88 popupmenu.add(new JSeparator()); 89 popupmenu.add(getAboutMenuItem()); 90 popupmenu.add(new JSeparator()); 91 popupmenu.add(getExitMenuItem()); 92 93 this.controlsBuilder.applyComponentOrientation(popupmenu); 94 } 95 } 96 97 @Override setPlayMenuItemText(final String text)98 public void setPlayMenuItemText(final String text) { 99 getPlayMenuItem().setText(text); 100 } 101 102 /** 103 * Getter of play menu item 104 * 105 * @return 106 */ getPlayMenuItem()107 private JMenuItem getPlayMenuItem() { 108 if (this.playMenuItem == null) { 109 this.playMenuItem = new JMenuItem( 110 this.beanFactory.getBean(PlayAction.class)); 111 } 112 return this.playMenuItem; 113 } 114 115 /** 116 * Getter of stop menu item 117 * 118 * @return 119 */ getStopMenuItem()120 private JMenuItem getStopMenuItem() { 121 return new JMenuItem( 122 this.beanFactory.getBean(StopCurrentAudioObjectAction.class)); 123 } 124 125 /** 126 * Getter of previous menu item 127 * 128 * @return 129 */ getPreviousMenuItem()130 private JMenuItem getPreviousMenuItem() { 131 return new JMenuItem( 132 this.beanFactory.getBean(PlayPreviousAudioObjectAction.class)); 133 } 134 135 /** 136 * Getter for next menu item 137 * 138 * @return 139 */ getNextMenuItem()140 private JMenuItem getNextMenuItem() { 141 return new JMenuItem( 142 this.beanFactory.getBean(PlayNextAudioObjectAction.class)); 143 } 144 145 /** 146 * Getter for mute menu item 147 * 148 * @return 149 */ getMuteCheckBoxMenuItem()150 private JCheckBoxMenuItem getMuteCheckBoxMenuItem() { 151 JCheckBoxMenuItem mute = new JCheckBoxMenuItem( 152 this.beanFactory.getBean(MuteAction.class)); 153 mute.setIcon(null); 154 return mute; 155 } 156 157 /** 158 * Getter for shuffle menu item 159 * 160 * @return 161 */ getShuffleCheckBoxMenuItem()162 private JCheckBoxMenuItem getShuffleCheckBoxMenuItem() { 163 return new JCheckBoxMenuItem( 164 this.beanFactory.getBean(ShuffleModeAction.class)); 165 } 166 167 /** 168 * Getter for repeat menu item 169 */ getRepeatCheckBoxMenuItem()170 private JCheckBoxMenuItem getRepeatCheckBoxMenuItem() { 171 return new JCheckBoxMenuItem( 172 this.beanFactory.getBean(RepeatModeAction.class)); 173 } 174 175 /** 176 * Getter for showOSD menu item 177 * 178 * @return 179 */ getShowOSDCheckBoxMenuItem()180 private JCheckBoxMenuItem getShowOSDCheckBoxMenuItem() { 181 return new JCheckBoxMenuItem( 182 this.beanFactory.getBean(ToggleOSDSettingAction.class)); 183 } 184 185 /** 186 * Getter for about menu item 187 * 188 * @return 189 */ getAboutMenuItem()190 private JMenuItem getAboutMenuItem() { 191 return new JMenuItem(this.beanFactory.getBean(ShowAboutAction.class)); 192 } 193 194 /** 195 * Getter for exit menu item 196 * 197 * @return 198 */ getExitMenuItem()199 private JMenuItem getExitMenuItem() { 200 return new JMenuItem(this.beanFactory.getBean(ExitAction.class)); 201 } 202 } 203