mainmenu.java

来自「Azureus is a powerful, full-featured, cr」· Java 代码 · 共 609 行 · 第 1/2 页

JAVA
609
字号
/*
 * Created on 4 mai 2004
 * Created by Olivier Chalouhi
 * 
 * Copyright (C) 2004 Aelitis SARL, All rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details ( see the LICENSE file ).
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 * AELITIS, SARL au capital de 30,000 euros,
 * 8 Alle Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
 */
package org.gudy.azureus2.ui.swt.mainwindow;

import java.util.Locale;

import org.eclipse.swt.SWT;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.logging.LGLogger;
import org.gudy.azureus2.core3.util.AERunnable;
import org.gudy.azureus2.core3.util.Constants;
import org.gudy.azureus2.core3.util.Debug;
import org.gudy.azureus2.core3.util.SystemProperties;
import org.gudy.azureus2.plugins.PluginView;
import org.gudy.azureus2.ui.swt.Messages;
import org.gudy.azureus2.ui.swt.Tab;
import org.gudy.azureus2.ui.swt.config.wizard.ConfigureWizard;
import org.gudy.azureus2.ui.swt.donations.DonationWindow2;
import org.gudy.azureus2.ui.swt.exporttorrent.wizard.ExportTorrentWizard;
import org.gudy.azureus2.ui.swt.help.AboutWindow;
import org.gudy.azureus2.ui.swt.help.HealthHelpWindow;
import org.gudy.azureus2.ui.swt.importtorrent.wizard.ImportTorrentWizard;
import org.gudy.azureus2.ui.swt.maketorrent.NewTorrentWizard;
import org.gudy.azureus2.ui.swt.pluginsinstaller.InstallPluginWizard;
import org.gudy.azureus2.ui.swt.pluginsuninstaller.UnInstallPluginWizard;
import org.gudy.azureus2.ui.swt.sharing.ShareUtils;
import org.gudy.azureus2.ui.swt.update.UpdateMonitor;
import com.aelitis.azureus.core.AzureusCoreFactory;

/**
 * @author Olivier Chalouhi
 *
 */
public class MainMenu {

  private Display display;
  private MainWindow mainWindow;
    
  private Menu menuBar;
  
  private MenuItem menu_tools;
  private Menu toolsMenu;
  
  private MenuItem menu_plugin;
  private Menu pluginMenu;
  
  
  public MainMenu(MainWindow mainWindow) {
    this.mainWindow = mainWindow;
    this.display = SWTThread.getInstance().getDisplay();
  }

  /**
   * @param locales
   */
  public void buildMenu(Locale[] locales) {
    try {
      
      //The Main Menu
      menuBar = new Menu(mainWindow.getShell(), SWT.BAR);
      mainWindow.getShell().setMenuBar(menuBar);
      
      
      //The File Menu
      MenuItem fileItem = new MenuItem(menuBar, SWT.CASCADE);
      Messages.setLanguageText(fileItem, "MainWindow.menu.file"); //$NON-NLS-1$
      Menu fileMenu = new Menu(mainWindow.getShell(), SWT.DROP_DOWN);
      fileItem.setMenu(fileMenu);
      
      MenuItem file_new = new MenuItem(fileMenu, SWT.CASCADE);
      Messages.setLanguageText(file_new, "MainWindow.menu.file.open"); //$NON-NLS-1$
      
      MenuItem file_share= new MenuItem(fileMenu, SWT.CASCADE);
      Messages.setLanguageText(file_share, "MainWindow.menu.file.share"); //$NON-NLS-1$
      
      MenuItem file_create = new MenuItem(fileMenu, SWT.NULL);
      Messages.setLanguageText(file_create, "MainWindow.menu.file.create"); //$NON-NLS-1$
  
      new MenuItem(fileMenu, SWT.SEPARATOR);
  
      MenuItem file_export = new MenuItem(fileMenu, SWT.NULL);
      Messages.setLanguageText(file_export, "MainWindow.menu.file.export"); //$NON-NLS-1$
  
      MenuItem file_import = new MenuItem(fileMenu, SWT.NULL);
      Messages.setLanguageText(file_import, "MainWindow.menu.file.import"); //$NON-NLS-1$
       
      new MenuItem(fileMenu, SWT.SEPARATOR);
      
      MenuItem file_restart = new MenuItem(fileMenu, SWT.NULL);
      Messages.setLanguageText(file_restart, "MainWindow.menu.file.restart"); //$NON-NLS-1$
      
      file_restart.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {

        	MainWindow.getWindow().dispose(true,false);
         }
      });
      
      
      //No need for exit on OS X
      if(! Constants.isOSX) {

        MenuItem file_exit = new MenuItem(fileMenu, SWT.NULL);
        Messages.setLanguageText(file_exit, "MainWindow.menu.file.exit"); //$NON-NLS-1$
        
        file_exit.addListener(SWT.Selection, new Listener() {
          public void handleEvent(Event e) {
            mainWindow.dispose(false,false);
          }
        });
      }
      
      // file->open submenus
      
      Menu newMenu = new Menu(mainWindow.getShell(), SWT.DROP_DOWN);
      file_new.setMenu(newMenu);
  
      MenuItem file_new_torrent = new MenuItem(newMenu, SWT.NULL);
      Messages.setLanguageText(file_new_torrent, "MainWindow.menu.file.open.torrent"); //$NON-NLS-1$
      file_new_torrent.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
          TorrentOpener.openTorrent();
        }
      });
      
/* Not working.. Hide for release
      MenuItem file_new_torrentwindow = new MenuItem(newMenu, SWT.NULL);
      file_new_torrentwindow.setText(MessageText.getString("MainWindow.menu.file.open.torrent") + " (Experimental)");
      file_new_torrentwindow.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
          TorrentOpener.openTorrentWindow();
        }
      });
*/
  
      MenuItem file_new_torrent_no_default = new MenuItem(newMenu, SWT.NULL);
      Messages.setLanguageText(file_new_torrent_no_default, "MainWindow.menu.file.open.torrentnodefault"); //$NON-NLS-1$
      file_new_torrent_no_default.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
          TorrentOpener.openTorrentNoDefaultSave(false);
        }      
      });
  
      MenuItem file_new_torrent_for_seeding = new MenuItem(newMenu, SWT.NULL);
      Messages.setLanguageText(file_new_torrent_for_seeding, "MainWindow.menu.file.open.torrentforseeding"); //$NON-NLS-1$
      file_new_torrent_for_seeding.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
          TorrentOpener.openTorrentNoDefaultSave(true);
        }      
      });
  
      MenuItem file_new_url = new MenuItem(newMenu,SWT.NULL);
      Messages.setLanguageText(file_new_url, "MainWindow.menu.file.open.url"); //$NON-NLS-1$
      file_new_url.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
          TorrentOpener.openUrl(mainWindow.getAzureusCore());
        }
      });
      MenuItem file_new_folder = new MenuItem(newMenu, SWT.NULL);
      Messages.setLanguageText(file_new_folder, "MainWindow.menu.file.folder"); //$NON-NLS-1$
      file_new_folder.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
          TorrentOpener.openDirectory();
        }
      });
  
      	// file->share submenus
      
      Menu shareMenu = new Menu(mainWindow.getShell(), SWT.DROP_DOWN);
      file_share.setMenu(shareMenu);
  
      MenuItem file_share_file = new MenuItem(shareMenu, SWT.NULL);
      Messages.setLanguageText(file_share_file, "MainWindow.menu.file.share.file");
      file_share_file.addListener(SWT.Selection, new Listener() {
      	public void handleEvent(Event e) {
      		ShareUtils.shareFile( mainWindow.getAzureusCore(),mainWindow.getShell() );
      	}
      });
      
      MenuItem file_share_dir = new MenuItem(shareMenu, SWT.NULL);
      Messages.setLanguageText(file_share_dir, "MainWindow.menu.file.share.dir");
      file_share_dir.addListener(SWT.Selection, new Listener() {
      	public void handleEvent(Event e) {
      		ShareUtils.shareDir( mainWindow.getAzureusCore(), mainWindow.getShell() );
      	}
      });
      
      MenuItem file_share_dircontents = new MenuItem(shareMenu, SWT.NULL);
      Messages.setLanguageText(file_share_dircontents, "MainWindow.menu.file.share.dircontents");
      file_share_dircontents.addListener(SWT.Selection, new Listener() {
      	public void handleEvent(Event e) {
      		ShareUtils.shareDirContents( mainWindow.getAzureusCore(),mainWindow.getShell(), false );
      	}
      });
      MenuItem file_share_dircontents_rec = new MenuItem(shareMenu, SWT.NULL);
      Messages.setLanguageText(file_share_dircontents_rec, "MainWindow.menu.file.share.dircontentsrecursive");
      file_share_dircontents_rec.addListener(SWT.Selection, new Listener() {
      	public void handleEvent(Event e) {
      		ShareUtils.shareDirContents( mainWindow.getAzureusCore(),mainWindow.getShell(), true );
      	}
      });
         	// file->create
      
      file_create.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
          new NewTorrentWizard(mainWindow.getAzureusCore(), display);
        }
      });
      
      file_export.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
          new ExportTorrentWizard(mainWindow.getAzureusCore(), display);
        }
      });
  
      file_import.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
          new ImportTorrentWizard(mainWindow.getAzureusCore(),display);
        }
      });
  
     
      	// ******** The Download Menu
      
      MenuItem downloadItem = new MenuItem(menuBar, SWT.CASCADE);
      Messages.setLanguageText(downloadItem, "MainWindow.menu.transfers"); //$NON-NLS-1$
      Menu downloadMenu = new Menu(mainWindow.getShell(), SWT.DROP_DOWN);
      downloadItem.setMenu(downloadMenu);

  
      
      // new MenuItem(fileMenu,SWT.SEPARATOR);
      
      final MenuItem itemStartAll = new MenuItem(downloadMenu,SWT.NULL);
      Messages.setLanguageText(itemStartAll,"MainWindow.menu.transfers.startalltransfers");
      
      final MenuItem itemStopAll = new MenuItem(downloadMenu,SWT.NULL); 
      Messages.setLanguageText(itemStopAll,"MainWindow.menu.transfers.stopalltransfers");

      final MenuItem itemPause = new MenuItem(downloadMenu,SWT.NULL);
      Messages.setLanguageText(itemPause,"MainWindow.menu.transfers.pausetransfers");
      
      final MenuItem itemResume = new MenuItem(downloadMenu,SWT.NULL); 
      Messages.setLanguageText(itemResume,"MainWindow.menu.transfers.resumetransfers");

      itemStartAll.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event arg0) {
        	mainWindow.getGlobalManager().startAllDownloads();
        }
      });
      
      itemStopAll.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event arg0) {
        	mainWindow.getGlobalManager().stopAllDownloads();
        }
      });

      itemPause.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event arg0) 
        {
        	mainWindow.getGlobalManager().pauseDownloads();
        }
      });
      
      itemResume.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event arg0) 
        {
          mainWindow.getGlobalManager().resumeDownloads();
        }
      });
      
      downloadMenu.addMenuListener(
          	new MenuListener()
    		{
          		public void
    			menuShown(

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?