MenuItem mDownload = new MenuItem(mSettings, SWT.CASCADE); skinManager.addItem(mDownload, "toolbar.menu_item.auto_download");   mDownload.addArmListener(new ToolTipArmListener(Resources.getString("toolbar.menu_item.tooltip.auto_download")));   Menu menu2 = new Menu(mDownload); mDownload.setMenu(menu2);  int[] counts = new int[] { 0, 5, 11, 17, 23, 29, 37 }; int autoDownload = trackDatabase.getAutoDownload(); for (int i = 0; i < counts.length; i++) { MenuItem mTimes = new MenuItem(menu2, SWT.CHECK, i); final Integer acount = new Integer(counts[i]); final int dummy = 0; mTimes.setText(i == 0 ? Resources.getString("toolbar.sub_menu_item.auto_download.disabled") : "< " + acount + " " + Resources.getString("toolbar.sub_menu_item.auto_download.unrated_tracks")); mTimes.setSelection(acount.intValue() == autoDownload); mTimes.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) {  MenuItem self = (MenuItem) e.getSource(); uncheckSiblingMenuItems(self); self.setSelection(true); trackDatabase.setAutoDownload(acount.intValue()); downloadThread.checkAutoDownload(); } });   mTimes.addArmListener( new ToolTipArmListener( Resources.getString("toolbar.sub_menu_item.auto_download.tooltip.unrated_tracks") + " " + acount));   }  MenuItem mPlayList = new MenuItem(mSettings, SWT.CASCADE); skinManager.addItem(mPlayList, "toolbar.menu_item.play_list");   mPlayList.addArmListener(new ToolTipArmListener(Resources.getString("toolbar.menu_item.tooltip.play_list")));   Menu menuPlayList = new Menu(mPlayList); mPlayList.setMenu(menuPlayList);  counts = new int[] { 13, 19, 31, 49 }; int playListLength = trackDatabase.getPlayListLength(); for (int i = 0; i < counts.length; i++) { MenuItem mTimes = new MenuItem(menuPlayList, SWT.CHECK, i); final int dummy = 0; final Integer pcount = new Integer(counts[i]); mTimes.setText(pcount + " " + Resources.getString("toolbar.sub_menu_item.play_list.tracks")); mTimes.setSelection(pcount.intValue() == playListLength); mTimes.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { MenuItem self = (MenuItem) e.getSource(); uncheckSiblingMenuItems(self); self.setSelection(true); trackDatabase.setPlayListLength(pcount.intValue()); } });   mTimes.addArmListener( new ToolTipArmListener(Resources.getString("toolbar.sub_menu_item.play_list.tooltip.tracks") + " " + pcount));   }
  public void createMenu() {    // Needed to clean up on Mac regular quit event    display.addListener(SWT.Close, new Listener() {      public void handleEvent(Event e) {        quit();      }    });        Menu menubar = new Menu(shell, SWT.BAR);    shell.setMenuBar(menubar);        // Declare this as our main menu bar to prettify things on Mac OS X    MacMenuFixer.setMenuBar(menubar);        final int accel=(isMac() ? SWT.COMMAND : SWT.CTRL);    MenuItem item1 = new MenuItem(menubar, SWT.CASCADE);    skinManager.addItem(item1, "toolbar.menu_title.action");    Menu menu1 = new Menu(item1);    //Added for a nicer UI by Allen Tipper 14.9.03    menu1.addMenuListener(new MenuAdapter() {      public void menuHidden(MenuEvent e) {        update();      }    });    //end add    item1.setMenu(menu1);    MenuItem item_undo = new MenuItem(menu1, SWT.PUSH);    item_undo.addSelectionListener(new SelectionAdapter() {      public void widgetSelected(SelectionEvent e) {        undoLastRating();      }    });    item_undo.addArmListener(new ToolTipArmListener(Resources.getString("toolbar.menu_item.tooltip.undo")));    skinManager.addItem(item_undo, "toolbar.menu_item.undo");    item_undo.setAccelerator('Z' + accel);    // Disable the undo menu item if it's not available    final MenuItem item_undoX=item_undo;    menu1.addMenuListener(new MenuAdapter() {      public void menuShown(MenuEvent e) {        item_undoX.setEnabled(canUndoLastRating());      }    });        MenuItem sep = new MenuItem(menu1, SWT.SEPARATOR);        MenuItem play = new MenuItem(menu1, SWT.PUSH);    skinManager.addItem(play, "toolbar.menu_item.play");    play.setAccelerator(' ');    play.addSelectionListener(new SelectionAdapter() {      public void widgetSelected(SelectionEvent e) {        setPaused(!isPaused());      }    });        MenuItem next = new MenuItem(menu1, SWT.PUSH);    skinManager.addItem(next, "toolbar.menu_item.next");    next.setAccelerator(SWT.ARROW_RIGHT + accel);    next.addSelectionListener(new SelectionAdapter() {      public void widgetSelected(SelectionEvent e) {        skip(false);      }    });    MenuItem prev = new MenuItem(menu1, SWT.PUSH);    skinManager.addItem(prev, "toolbar.menu_item.prev");    prev.setAccelerator(SWT.ARROW_LEFT + accel);    prev.addSelectionListener(new SelectionAdapter() {      public void widgetSelected(SelectionEvent e) {        skip(true);      }    });    MenuItem sep2 = new MenuItem(menu1, SWT.SEPARATOR);       if (isMac()) {      // Drag-n-drop is broken on SWT/Carbon; need another way to      // let users get at the files behind their tracks.      MenuItem mShowFile = new MenuItem(menu1, SWT.PUSH);      mShowFile.addSelectionListener(new SelectionAdapter() {        public void widgetSelected(SelectionEvent e) {          Track track = trackTable.getSelectedTrack();          File trackfile = track.getFile();          if (trackfile.exists()) {            System.out.println("Show track file: " + trackfile);            String macpath = "file \"" + trackfile.getName() + "\" of ";            while ((trackfile = trackfile.getParentFile()) != null) {              if (!trackfile.getName().equals(""))                macpath = macpath + "folder \"" + trackfile.getName() + "\" of ";            }            macpath = macpath + "startup disk";            System.out.println("Mac path: " + macpath);            try {              Process script = Runtime.getRuntime().exec("/usr/bin/osascript");              PrintStream out = new PrintStream(script.getOutputStream());              out.println("tell application \"Finder\"");              out.println("    activate");              out.println("    select " + macpath);              out.println("end tell");              out.close();              script.waitFor();            } catch (Exception ex) {              ex.printStackTrace();            }          }        }      });      skinManager.addItem(mShowFile, "toolbar.menu_item.showfile");    } else {      // Mac OS X already has Quit in the app menu      MenuItem item1_4 = new MenuItem(menu1, SWT.PUSH);      item1_4.addSelectionListener(new SelectionAdapter() {        public void widgetSelected(SelectionEvent e) {          quit();        }      });      skinManager.addItem(item1_4, "toolbar.menu_item.quit");      //Added for a nicer UI by Allen Tipper 14.9.03      item1_4.addArmListener(new ToolTipArmListener(Resources.getString("toolbar.menu_item.tooltip.quit")));      //end add    }    MenuItem item2 = new MenuItem(menubar, SWT.CASCADE);    skinManager.addItem(item2, "toolbar.menu_title.settings");    Menu mSettings = new Menu(item2);    //Added for a nicer UI by Allen Tipper 14.9.03    mSettings.addMenuListener(new MenuAdapter() {      public void menuHidden(MenuEvent e) {        update();      }    });    //end add    item2.setMenu(mSettings);    MenuItem mDownload = new MenuItem(mSettings, SWT.CASCADE);    skinManager.addItem(mDownload, "toolbar.menu_item.auto_download");    //Added for a nicer UI by Allen Tipper 14.9.03    mDownload.addArmListener(new ToolTipArmListener(Resources.getString("toolbar.menu_item.tooltip.auto_download")));    //end add    Menu menu2 = new Menu(mDownload);    mDownload.setMenu(menu2);    int[] counts = new int[] { 0, 5, 11, 17, 23, 29, 37 };    int autoDownload = trackDatabase.getAutoDownload();    for (int i = 0; i < counts.length; i++) {      MenuItem mTimes = new MenuItem(menu2, SWT.CHECK, i);      final Integer acount = new Integer(counts[i]);      final int dummy = 0; // workaround for gcj-3.0.4 bug      mTimes.setText(i == 0 ? Resources.getString("toolbar.sub_menu_item.auto_download.disabled") : "< " + acount + " " + Resources.getString("toolbar.sub_menu_item.auto_download.unrated_tracks"));      mTimes.setSelection(acount.intValue() == autoDownload);      mTimes.addSelectionListener(new SelectionAdapter() {        public void widgetSelected(SelectionEvent e) {          //stupid trick to make self the only selected item          MenuItem self = (MenuItem) e.getSource();          uncheckSiblingMenuItems(self);          self.setSelection(true);          trackDatabase.setAutoDownload(acount.intValue());          downloadThread.checkAutoDownload();        }      });      //Added for a nicer UI by Allen Tipper 14.9.03      mTimes.addArmListener(        new ToolTipArmListener(          Resources.getString("toolbar.sub_menu_item.auto_download.tooltip.unrated_tracks")          + " " + acount));      //end add    }    MenuItem mPlayList = new MenuItem(mSettings, SWT.CASCADE);    skinManager.addItem(mPlayList, "toolbar.menu_item.play_list");    //Added for a nicer UI by Allen Tipper 14.9.03    mPlayList.addArmListener(new ToolTipArmListener(Resources.getString("toolbar.menu_item.tooltip.play_list")));    //end add    Menu menuPlayList = new Menu(mPlayList);    mPlayList.setMenu(menuPlayList);    counts = new int[] { 13, 19, 31, 49 };    int playListLength = trackDatabase.getPlayListLength();    for (int i = 0; i < counts.length; i++) {      MenuItem mTimes = new MenuItem(menuPlayList, SWT.CHECK, i);      final int dummy = 0; // workaround for gcj-3.0.4 bug      final Integer pcount = new Integer(counts[i]);      mTimes.setText(pcount + " " + Resources.getString("toolbar.sub_menu_item.play_list.tracks"));      mTimes.setSelection(pcount.intValue() == playListLength);      mTimes.addSelectionListener(new SelectionAdapter() {        public void widgetSelected(SelectionEvent e) {          MenuItem self = (MenuItem) e.getSource();          uncheckSiblingMenuItems(self);          self.setSelection(true);          trackDatabase.setPlayListLength(pcount.intValue());        }      });      //Added for a nicer UI by Allen Tipper 14.9.03      mTimes.addArmListener(        new ToolTipArmListener(Resources.getString("toolbar.sub_menu_item.play_list.tooltip.tracks") + " " + pcount));      //end add    }    /**     * Added by Eric Dalquist - 11.09.2003     *     * Allows the user to select the number of unrated tracks to add to each playlist generation     */    MenuItem mNewUnrated = new MenuItem(mSettings, SWT.CASCADE);    skinManager.addItem(mNewUnrated, "toolbar.menu_item.unrated");    mNewUnrated.addArmListener(new ToolTipArmListener(Resources.getString("toolbar.menu_item.tooltip.unrated")));    Menu menuNewUnrated = new Menu(mNewUnrated);    mNewUnrated.setMenu(menuNewUnrated);    int unratedPlayListRatio = trackDatabase.getUnratedPlayListRatio();    counts = new int[] { 0, 13, 29, 47, 63, 79, 97 };    for (int i = 0; i < counts.length; i++) {      final Integer ratio = new Integer(counts[i]);      MenuItem mRatio = new MenuItem(menuNewUnrated, SWT.CHECK, i);      mRatio.setText(ratio + "%");      mRatio.setSelection(ratio.intValue() == unratedPlayListRatio);      mRatio.addSelectionListener(new SelectionAdapter() {        public void widgetSelected(SelectionEvent e) {          MenuItem self = (MenuItem) e.getSource();          uncheckSiblingMenuItems(self);          self.setSelection(true);          trackDatabase.setUnratedPlayListRatio(ratio.intValue());        }      });      //Added for a nicer UI by Allen Tipper 14.9.03      mRatio.addArmListener(        new ToolTipArmListener(          Resources.getString("toolbar.submenu_item.tooltip.unrated") +          " " + ratio + "%."));      //end add    }    /****/    MenuItem mPlayers = new MenuItem(mSettings, SWT.CASCADE);    skinManager.addItem(mPlayers, "toolbar.menu_item.player");    menu2 = new Menu(mPlayers);    mPlayers.setMenu(menu2);    //Added for a nicer UI by Allen Tipper 14.9.03    mPlayers.addArmListener(new ToolTipArmListener(Resources.getString("toolbar.menu_item.tooltip.player")));    //end add    Player players[] = playerList.getPlayers();    for (int i = 0; i < players.length; i++) {      final String player = players[i].getName();      MenuItem mPlayer = new MenuItem(menu2, SWT.CHECK, i);      mPlayer.setText(player);      if (trackDatabase.getPlayer().equals(player))        mPlayer.setSelection(true);      mPlayer.addSelectionListener(new SelectionAdapter() {        public void widgetSelected(SelectionEvent e) {          //stupid trick to make self the only selected item          MenuItem self = (MenuItem) e.getSource();          uncheckSiblingMenuItems(self);          self.setSelection(true);          trackDatabase.setPlayer(player);          downloadThread.checkAutoDownload();        }      });      mPlayer.addArmListener(        new ToolTipArmListener(Resources.getString("toolbar.sub_menu_item.tooltip.player") + " " + player));    }        Menu hidden;    if (isMac()) {      // On the Mac, we put some items in the application menu.      // We use a hidden popup Menu to stick the MenuItems with      // the selection listeners.      hidden = new Menu(shell, SWT.POP_UP);    } else {      hidden = null;    }    MenuItem item2_1 = new MenuItem(isMac() ? hidden : mSettings, SWT.PUSH);    skinManager.addItem(item2_1, "toolbar.menu_item.advanced");    item2_1.addSelectionListener(new SelectionAdapter() {      public void widgetSelected(SelectionEvent e) {        showSettingDialog(SettingDialog.PLUGIN_PAGE);      }    });    //Added for a nicer UI by Allen Tipper 14.9.03    item2_1.addArmListener(new ToolTipArmListener(Resources.getString("toolbar.menu_item.tooltip.advanced")));    //end add    MenuItem item3 = new MenuItem(menubar, SWT.CASCADE);    skinManager.addItem(item3, "toolbar.menu_title.info");    Menu menu3 = new Menu(item3);    menu3.addMenuListener(new MenuAdapter() {      public void menuHidden(MenuEvent e) {        update();      }    });    item3.setMenu(menu3);    MenuItem helpItem = new MenuItem(menu3, SWT.PUSH);    if (isMac()) {      helpItem.setAccelerator('?' | SWT.COMMAND);      skinManager.addItem(helpItem, "toolbar.menu_item.help_mac");	} else {      helpItem.setAccelerator(SWT.F1);      skinManager.addItem(helpItem, "toolbar.menu_item.help");    }    helpItem.addSelectionListener(new SelectionAdapter() {      public void widgetSelected(SelectionEvent e) {        try {          // Might be nice to have more thorough docs stored locally.          // For the mac app bundle version, they can be stored in the          // app bundle and accessed through Help Viewer.          showURL(new URL("http://irate.sourceforge.net/documentation.gettingstarted.html"));        } catch (MalformedURLException ex) {          ex.printStackTrace();        }      }    });        if(System.getProperty("os.name").toLowerCase().startsWith("win")) {      MenuItem helpSep = new MenuItem(menu3, SWT.SEPARATOR);    }        MenuItem item3_1 = new MenuItem(isMac() ? hidden : menu3, SWT.PUSH);    skinManager.addItem(item3_1, "toolbar.menu_item.credits");    item3_1.addSelectionListener(new SelectionAdapter() {      public void widgetSelected(SelectionEvent e) {        actionAbout();      }    });    item3_1.addArmListener(new ToolTipArmListener(Resources.getString("toolbar.menu_item.tooltip.credits")));        if (isMac()) {      try {        /* Touch up the application menu on Mac OS X         * I apologize for the reflection ugliness! --brion         */        Class appMenuClass = Class.forName("com.leuksman.swtdock.ApplicationMenu");        Method enablePreferences = appMenuClass.getMethod(          "enablePreferences", new Class[] {});        Method insertMenuItem = appMenuClass.getMethod("insertMenuItem",          new Class[] {String.class, java.lang.Integer.TYPE, String.class});        Method insertSeparator = appMenuClass.getMethod(          "insertSeparator", new Class[] {java.lang.Integer.TYPE});                Class commandHandlerClass = Class.forName("com.leuksman.swtdock.CommandHandler");        Method setAndListenFor = commandHandlerClass.getMethod("setAndListenFor",          new Class[] {String.class, MenuItem.class});                /* Add the 'About' item and enable 'Preferences' */        Object appmenu = appMenuClass.newInstance();        enablePreferences.invoke(appmenu, new Object[] {});        insertMenuItem.invoke(appmenu, new Object[] {          Resources.getString("toolbar.menu_item.about"),          new Integer(0), "abou" });        insertSeparator.invoke(appmenu, new Object[] {new Integer(1)});                /* Attach these commands to the existing MenuItems */        Object handler = commandHandlerClass.newInstance();        setAndListenFor.invoke(handler, new Object[] {"abou", item3_1});        setAndListenFor.invoke(handler, new Object[] {"pref", item2_1});      } catch (Exception e) {        e.printStackTrace();      }    }  }