View Javadoc

1   package com.melloware.jukes.gui.view;
2   
3   import java.awt.Component;
4   
5   import javax.swing.JMenu;
6   import javax.swing.JMenuBar;
7   import javax.swing.JPopupMenu;
8   
9   import com.jgoodies.looks.BorderStyle;
10  import com.jgoodies.looks.HeaderStyle;
11  import com.jgoodies.looks.Options;
12  import com.jgoodies.looks.plastic.PlasticLookAndFeel;
13  import com.jgoodies.looks.windows.WindowsLookAndFeel;
14  import com.jgoodies.uif.action.ActionManager;
15  import com.jgoodies.uif.builder.MenuBuilder;
16  import com.jgoodies.uif.builder.PopupMenuBuilder;
17  import com.jgoodies.uif.component.UIFMenuItem;
18  import com.jgoodies.uif.osx.OSXApplicationMenu;
19  import com.melloware.jukes.gui.tool.Actions;
20  import com.melloware.jukes.gui.tool.Resources;
21  
22  /**
23   * Builds the <code>JMenuBar</code> and pull-down menus in Jukes.
24   * <p>
25   * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
26   * @author Emil A. Lefkof III <info@melloware.com> 
27   * @version 4.0
28   * AZ - 2009, 2010 
29   */
30  public final class MainMenuBuilder {
31  
32  	public static final String CATALOG = Resources.getString("menu.catalog");
33  	private static final String PLAYER = Resources.getString("menu.player");
34      private static final String REPORTS = Resources.getString("menu.reports");
35  	private static final String TOOLS = Resources.getString("menu.tools");
36  	private static final String HELP = Resources.getString("menu.help");
37  	private static final String LANGUAGE = Resources.getString("menu.language");
38  	
39      
40      /**
41       * Builds and returns the Player.
42       */
43      public static JPopupMenu buildPlayerPopupMenu(Component aComponent) {
44          final PopupMenuBuilder popup = new PopupMenuBuilder("Player");
45          UIFMenuItem menuItem = null;
46          menuItem = new UIFMenuItem(ActionManager.get(Actions.PLAYER_QUEUE_ID));
47          menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
48          popup.add(menuItem);
49          menuItem = new UIFMenuItem(ActionManager.get(Actions.PLAYER_QUEUE_NEXT_ID));
50          menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
51          popup.add(menuItem);
52          menuItem = new UIFMenuItem(ActionManager.get(Actions.TRACK_PLAY_IMMEDIATE_ID));
53          menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
54          popup.add(menuItem);
55          //AZ
56          menuItem = new UIFMenuItem(ActionManager.get(Actions.DISCLIST_QUEUE_ID));
57          menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
58          popup.add(menuItem);
59          return popup.getPopupMenu();
60      }
61      
62      /**
63       * Builds and returns the Playlist Menu.
64       * <p>
65       * @param aComponent the panel that owns this menu
66       * @param aList a JList that this menu item is acting on.
67       */
68      public static JPopupMenu buildPlaylistPopupMenu(Component aComponent, Component aList) {
69          final PopupMenuBuilder popup = new PopupMenuBuilder("Playlist");
70          UIFMenuItem menuItem = null;
71          menuItem = new UIFMenuItem(ActionManager.get(Actions.TRACK_PLAY_IMMEDIATE_ID));
72          menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aList);
73          popup.add(menuItem);
74          menuItem = new UIFMenuItem(ActionManager.get(Actions.PLAYLIST_MOVEUP_ID));
75          menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
76          popup.add(menuItem);
77          menuItem = new UIFMenuItem(ActionManager.get(Actions.PLAYLIST_MOVEDOWN_ID));
78          menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
79          popup.add(menuItem);
80          menuItem = new UIFMenuItem(ActionManager.get(Actions.PLAYLIST_MOVEOVER_ID));
81          menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
82          popup.add(menuItem);
83          menuItem = new UIFMenuItem(ActionManager.get(Actions.PLAYLIST_REMOVE_TRACK_ID));
84          menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
85          popup.add(menuItem);
86          menuItem = new UIFMenuItem(ActionManager.get(Actions.PLAYLIST_CLEAR_ID));
87          menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
88          popup.add(menuItem);
89          menuItem = new UIFMenuItem(ActionManager.get(Actions.PLAYLIST_GOTO_ID));
90          menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aList);
91          popup.add(menuItem);
92            
93          return popup.getPopupMenu();
94      }
95  
96      /**
97       * Configures, composes, and returns the menu bar.
98       */
99      JMenuBar build() {
100         JMenuBar menuBar = new JMenuBar();
101 
102         // Set a hint so that JGoodies Looks will detect it as being in the header.
103         menuBar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
104         // Unlike the default, use a separator border.
105         menuBar.putClientProperty(WindowsLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR);
106         menuBar.putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.SEPARATOR);
107 
108         menuBar.add(buildCatalogMenu());
109         menuBar.add(buildPlayerMenu());
110         menuBar.add(buildReportsMenu());
111         menuBar.add(buildLanguageMenu());
112         menuBar.add(buildToolsMenu());
113         menuBar.add(buildHelpMenu());
114         return menuBar;
115     }
116 
117     /**
118      * Builds and returns the Catalog menu.
119      */
120     private JMenu buildCatalogMenu() {
121         MenuBuilder builder = new MenuBuilder(CATALOG, CATALOG.charAt(0));
122 
123         builder.add(ActionManager.get(Actions.TRACK_ADD_ID)); //AZ
124         builder.add(ActionManager.get(Actions.DISC_ADD_ID));
125         builder.add(ActionManager.get(Actions.DISC_FINDER_ID));
126         builder.add(ActionManager.get(Actions.DISC_REMOVER_ID));
127         builder.addSeparator();
128         builder.add(ActionManager.get(Actions.SEARCH_ID));
129         builder.add(ActionManager.get(Actions.PLAYLIST_SHOW_ID));
130         builder.add(ActionManager.get(Actions.DISCLIST_SHOW_ID)); //AZ
131         builder.add(ActionManager.get(Actions.FILTER_SHOW_ID));
132         builder.add(ActionManager.get(Actions.CATALOG_EXPORT_ID));
133         builder.addSeparator();
134         builder.add(ActionManager.get(Actions.CONNECT_ID));
135         builder.add(ActionManager.get(Actions.REFRESH_ID));
136         if (!OSXApplicationMenu.isRegisteredQuit()) {
137             builder.addSeparator();
138             builder.add(ActionManager.get(Actions.EXIT_ID));
139         }
140         return builder.getMenu();
141     }
142     
143     /**
144      * Builds and returns the Player menu.
145      */
146     private JMenu buildPlayerMenu() {
147         MenuBuilder builder = new MenuBuilder(PLAYER, PLAYER.charAt(0));
148         builder.add(ActionManager.get(Actions.PLAYER_PLAY_ID));
149         builder.add(ActionManager.get(Actions.PLAYER_PAUSE_ID));
150         builder.add(ActionManager.get(Actions.PLAYER_STOP_ID));
151         builder.add(ActionManager.get(Actions.PLAYER_PREVIOUS_ID));
152         builder.add(ActionManager.get(Actions.PLAYER_NEXT_ID));
153         return builder.getMenu();
154     }
155     
156     /**
157      * Builds and returns the Reports menu.
158      */
159     private JMenu buildReportsMenu() {
160         MenuBuilder builder = new MenuBuilder(REPORTS, REPORTS.charAt(0));
161         builder.add(ActionManager.get(Actions.REPORT_CATALOG_ID));
162         builder.add(ActionManager.get(Actions.REPORT_CATALOG_BY_GENRES_ID));//AZ
163         builder.add(ActionManager.get(Actions.REPORT_ALBUMS_FOR_ARTIST_ID));//AZ
164         builder.add(ActionManager.get(Actions.REPORT_NOCOVERART_ID));
165         builder.add(ActionManager.get(Actions.REPORT_BITRATE_ID));
166         builder.add(ActionManager.get(Actions.REPORT_GENRES_ID));//AZ
167         builder.addSeparator();
168         builder.add(ActionManager.get(Actions.CATALOG_EXPORT_ID));
169         return builder.getMenu();
170     }
171 
172     /**
173      * Builds and returns the Help menu.
174      */
175     private JMenu buildHelpMenu() {
176         MenuBuilder builder = new MenuBuilder(HELP, HELP.charAt(0));
177         builder.add(ActionManager.get(Actions.HELP_CONTENTS_ID));
178         builder.addSeparator();
179         builder.add(ActionManager.get(Actions.HELP_DONATE_ID));
180         builder.add(ActionManager.get(Actions.HELP_FORUMS_ID));
181         builder.add(ActionManager.get(Actions.HELP_CONTACT_ID));
182         builder.add(ActionManager.get(Actions.HELP_TIP_OF_THE_DAY_ID));
183         if (!OSXApplicationMenu.isRegisteredAbout()) {
184             builder.addSeparator();
185             builder.add(ActionManager.get(Actions.HELP_ABOUT_DIALOG_ID));
186         }
187         return builder.getMenu();
188     }
189 
190     /**
191      * Builds and returns the Component menu.
192      */
193     private JMenu buildToolsMenu() {
194         MenuBuilder builder = new MenuBuilder(TOOLS, TOOLS.charAt(0));
195         if (!OSXApplicationMenu.isRegisteredPreferences()) {
196             builder.add(ActionManager.get(Actions.PREFERENCES_ID));
197         }
198         builder.add(ActionManager.get(Actions.TOOL_BACKUP_ID));
199         builder.add(ActionManager.get(Actions.PREFERENCES_IMPORT_ID));
200         builder.add(ActionManager.get(Actions.PREFERENCES_EXPORT_ID));
201         builder.add(ActionManager.get(Actions.TOOL_DIFFERENCE_ID));
202         builder.add(ActionManager.get(Actions.TOOL_CHECK_GENRES_ID)); //AZ
203         builder.add(ActionManager.get(Actions.TOOL_LOCATION_ID));
204         builder.add(ActionManager.get(Actions.DB_XML_EXPORT_ID));//AZ
205         builder.add(ActionManager.get(Actions.DB_XML_IMPORT_ID));//AZ 
206         builder.addSeparator();
207         builder.add(ActionManager.get(Actions.TOOL_STATISTICS_ID));
208         builder.add(ActionManager.get(Actions.TOOL_MEMORY_ID));
209         return builder.getMenu();
210     }
211     
212     /**
213      * Builds and returns the Language menu.
214      */
215     private JMenu buildLanguageMenu() {
216         MenuBuilder builder = new MenuBuilder(LANGUAGE, LANGUAGE.charAt(0));
217         builder.add(ActionManager.get(Actions.LANG_ENGLISH_ID));
218         builder.add(ActionManager.get(Actions.LANG_SPANISH_ID));
219         builder.add(ActionManager.get(Actions.LANG_GERMAN_ID));
220         builder.add(ActionManager.get(Actions.LANG_INDONESIAN_ID));
221         builder.add(ActionManager.get(Actions.LANG_KOREAN_ID));
222         builder.add(ActionManager.get(Actions.LANG_NORWEGIAN_ID));
223         builder.add(ActionManager.get(Actions.LANG_DUTCH_ID));
224         builder.add(ActionManager.get(Actions.LANG_FRENCH_ID));
225         builder.add(ActionManager.get(Actions.LANG_PORTUGEUSE_ID));
226         builder.add(ActionManager.get(Actions.LANG_ITALIAN_ID));
227         builder.add(ActionManager.get(Actions.LANG_SWEDISH_ID));
228         builder.add(ActionManager.get(Actions.LANG_FINNISH_ID));
229         builder.add(ActionManager.get(Actions.LANG_RUSSIAN_ID));
230         builder.add(ActionManager.get(Actions.LANG_UKRAINIAN_ID));
231         builder.add(ActionManager.get(Actions.LANG_CHINESE_ID));
232         builder.add(ActionManager.get(Actions.LANG_HINDHI_ID));
233         //builder.add(ActionManager.get(Actions.LANG_TAMIL_ID));
234         //builder.add(ActionManager.get(Actions.LANG_TELEGU_ID));
235         return builder.getMenu();
236     }
237     
238      /**AZ
239      * Builds and returns the Disclist Menu.
240      * <p>
241      * @param aComponent the panel that owns this menu
242      * @param aList a JList that this menu item is acting on.
243      */
244     public static JPopupMenu buildDisclistPopupMenu(Component aComponent, Component aList) {
245         final PopupMenuBuilder popup = new PopupMenuBuilder("Disclist");
246         UIFMenuItem menuItem = null;
247         menuItem = new UIFMenuItem(ActionManager.get(Actions.DISCLIST_MOVEUP_ID));
248         menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
249         popup.add(menuItem);
250         menuItem = new UIFMenuItem(ActionManager.get(Actions.DISCLIST_MOVEDOWN_ID));
251         menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
252         popup.add(menuItem);
253         menuItem = new UIFMenuItem(ActionManager.get(Actions.DISCLIST_REMOVE_DISC_ID));
254         menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
255         popup.add(menuItem);
256         menuItem = new UIFMenuItem(ActionManager.get(Actions.DISCLIST_CLEAR_ID));
257         menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
258         popup.add(menuItem);
259         menuItem = new UIFMenuItem(ActionManager.get(Actions.DISCLIST_GOTO_ID));
260         menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aList);
261         popup.add(menuItem);
262           
263         return popup.getPopupMenu();
264     }
265 
266     /**AZ
267      * Builds and returns the DiscExportableTable PopUp Menu.
268      */
269     public static JPopupMenu buildDiscExportableTablePopupMenu(Component aComponent) {
270         final PopupMenuBuilder popup = new PopupMenuBuilder("DiscExportableTable");
271         UIFMenuItem menuItem = null;
272         menuItem = new UIFMenuItem(ActionManager.get(Actions.PLAYER_QUEUE_ID));
273         menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
274         popup.add(menuItem);
275         menuItem = new UIFMenuItem(ActionManager.get(Actions.PLAYER_QUEUE_NEXT_ID));
276         menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
277         popup.add(menuItem);
278         menuItem = new UIFMenuItem(ActionManager.get(Actions.DISCLIST_QUEUE_ID));
279         menuItem.putClientProperty(Resources.EDITOR_COMPONENT, aComponent);
280         popup.add(menuItem);
281         return popup.getPopupMenu();
282     }
283 }