⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainwindow.java

📁 这是一个基于java编写的torrent的P2P源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			// table columns and other objects
			if (uiSWTInstanceImpl == null) {
				uiSWTInstanceImpl = new UISWTInstanceImpl(azureus_core);
				uiSWTInstanceImpl.init();
			}

			if (azureus_core.getTrackerHost().getTorrents().length > 0) {
				showMyTracker();
			}

			if (COConfigurationManager.getBooleanParameter("Open MyTorrents", true)) {
				showMyTorrents();
			}

			//  share progress window

			new ProgressWindow();

			if (COConfigurationManager.getBooleanParameter("Open Console", false)) {
				showConsole();
			}
			events = null;

			if (COConfigurationManager.getBooleanParameter("Open Config", false)) {
				showConfig();
			}

			if (COConfigurationManager.getBooleanParameter("Open Stats On Start",
					false)) {
				showStats();
			}

			COConfigurationManager.addParameterListener("GUI_SWT_bFancyTab", this);

			updater = new GUIUpdater(this);
			updater.start();

		} catch (Throwable e) {
			Debug.printStackTrace(e);
		}

    COConfigurationManager.addAndFireParameterListener("IconBar.enabled",
				new ParameterListener() {
					public void parameterChanged(String parameterName) {
						setIconBarEnabled(COConfigurationManager.getBooleanParameter(parameterName));
					}
				});

    showMainWindow();
}
	protected boolean getIconBarEnabled() {
		return bIconBarEnabled;
	}
  
	protected void setIconBarEnabled(boolean enabled) {
		if (enabled == bIconBarEnabled) {
			return;
		}
		bIconBarEnabled  = enabled;
		COConfigurationManager.setParameter("IconBar.enabled", bIconBarEnabled);
		if (bIconBarEnabled) {
	    try {
		    iconBar = new IconBar(parent);
		    iconBar.setCurrentEnabler(this);
				Composite cIconBar = iconBar.getComposite();
		    
		    FormData folderLayoutData = (FormData)folder.getLayoutData();
		    
		    FormData formData = new FormData();
		    if (folderLayoutData.top != null && folderLayoutData.top.control != null) {
		    	formData.top = new FormAttachment(folderLayoutData.top.control);
		    } else {
			    formData.top = new FormAttachment(0, 0);
		    }
		    folderLayoutData.top = new FormAttachment(cIconBar);
		    
		    formData.left = new FormAttachment(0, 0); // 2 params for Pre SWT 3.0
		    formData.right = new FormAttachment(100, 0); // 2 params for Pre SWT 3.0
		    this.iconBar.setLayoutData(formData);

	    } catch (Exception e) {
	    	Logger.log(new LogEvent(LOGID, "Creating Icon Bar", e));
	    }
		} else if (iconBar != null) {
	    try {
		    FormData folderLayoutData = (FormData)folder.getLayoutData();
		    FormData iconBarLayoutData = (FormData)iconBar.getComposite().getLayoutData();
		    
		    if (iconBarLayoutData.top != null && iconBarLayoutData.top.control != null) {
		    	folderLayoutData.top = new FormAttachment(iconBarLayoutData.top.control);
		    } else {
		    	folderLayoutData.top = new FormAttachment(0, 0);
		    }
		    
	    	iconBar.delete();
		    iconBar = null;
	    } catch (Exception e) {
	    	Logger.log(new LogEvent(LOGID, "Removing Icon Bar", e));
	    }
		}
		shell.layout(true, true);
	}

	private void showMainWindow() {
		if (!bShowMainWindow) {
			return;
		}

		// No tray access on OSX yet
		boolean bEnableTray = COConfigurationManager
				.getBooleanParameter("Enable System Tray")
				&& (!Constants.isOSX || SWT.getVersion() > 3300);
		boolean bPassworded = COConfigurationManager.getBooleanParameter(
				"Password enabled", false);
		boolean bStartMinimize = bEnableTray
				&& (bPassworded || COConfigurationManager.getBooleanParameter(
						"Start Minimized", false));

		if (!bStartMinimize) {
	    shell.layout();
	    shell.open();
			if (!Constants.isOSX) {
				shell.forceActive();
			}
		} else if (Constants.isOSX) {
			shell.setMinimized(true);
			shell.setVisible(true);
		}

		if (bEnableTray) {

			try {
				systemTraySWT = new SystemTraySWT();

			} catch (Throwable e) {

				Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR,
						"Upgrade to SWT3.0M8 or later for system tray support."));
			}

			if (bStartMinimize) {
				minimizeToTray(null);
			}
			//Only show the password if not started minimized
			//Correct bug #878227
			else {
				if (bPassworded) {
					minimizeToTray(null);
					setVisible(true); // invokes password
				}
			}
		}

		COConfigurationManager.addAndFireParameterListener("Show Download Basket",
				this);

		checkForWhatsNewWindow();

		// check file associations   
		AssociationChecker.checkAssociations();

    azureus_core.triggerLifeCycleComponentCreated(uiFunctions);
		azureus_core.getPluginManager().firePluginEvent(
				PluginEvent.PEV_INITIALISATION_UI_COMPLETES);
	}


  protected void showMyTracker() {
  	if (my_tracker_tab == null) {
  		my_tracker_tab = new Tab(new MyTrackerView(azureus_core));
  		my_tracker_tab.getView().getComposite().addDisposeListener(new DisposeListener() {
      	public void widgetDisposed(DisposeEvent e) {
      		my_tracker_tab = null;
      	}
      });
  	} else {
  		my_tracker_tab.setFocus();
  		refreshIconBar();
  	}
  }
  
  protected void 
  showMyShares() 
  {
  	if (my_shares_tab == null) {
  		my_shares_tab = new Tab(new MySharesView(azureus_core));
  		my_shares_tab.getView().getComposite().addDisposeListener(new DisposeListener() {
      	public void widgetDisposed(DisposeEvent e) {
      		my_shares_tab = null;
      	}
      });
  	} else {
  		my_shares_tab.setFocus();
  		refreshIconBar();
  	}
  }
  
  protected void showMyTorrents() {
    if (mytorrents == null) {
    	MyTorrentsSuperView view = new MyTorrentsSuperView(azureus_core);
      mytorrents = new Tab(view);
      mytorrents.getView().getComposite().addDisposeListener(new DisposeListener() {
      	public void widgetDisposed(DisposeEvent e) {
      		mytorrents = null;
      	}
      });
    } else {
      mytorrents.setFocus();
    }
    refreshIconBar();
  }
	
  private void minimizeToTray(ShellEvent event) {
    //Added this test so that we can call this method with null parameter.
    if (event != null)
      event.doit = false;
    if(Constants.isOSX) {
    	shell.setMinimized(true);
    } else {  
    	shell.setVisible(false);
    }
    if (downloadBasket != null)
      downloadBasket.setVisible(true);

    MinimizedWindow.setAllVisible(true);
  }
  
  private void
  updateComponents()
  {
  	if (mainStatusBar != null)
  		mainStatusBar.refreshStatusText();

  	if (folder != null) {
  		if(useCustomTab) {
  			((CTabFolder)folder).update();
  		} else {
  			((TabFolder)folder).update();
  		}
  	}
  }

  public boolean
  destroyRequest()
  {
	  Logger.log(new LogEvent(LOGID, "MainWindow::destroyRequest"));

	  if ( COConfigurationManager.getBooleanParameter("Password enabled", false )){
		  
	  	if (!PasswordWindow.showPasswordWindow(display)) {
		  	Logger.log(new LogEvent(LOGID, "    denied - password is enabled"));
	
			  return false;
	  	}
	  }
	  
	  Utils.execSWTThread(
			new Runnable()
			{
				public void
				run()
				{
					dispose( false, false );
				}
			});
	  return true;
  }

	// globalmanagerlistener
	
  public void
  destroyed()
  {
  }
  
  public void
  destroyInitiated()
  {
  }				
  
  public void seedingStatusChanged( boolean seeding_only_mode ){
  }       
  
  public void 
  downloadManagerAdded(
  	final DownloadManager created) 
  {
    created.addListener(this);
  }

  protected void openManagerView(DownloadManager downloadManager) {
    try{
    	downloadViews_mon.enter();
    
      if (downloadViews.containsKey(downloadManager)) {
        Tab tab = (Tab) downloadViews.get(downloadManager);
        tab.setFocus();
        refreshIconBar();
      }
      else {
        Tab tab = new Tab(new ManagerView(azureus_core, downloadManager));
        downloadViews.put(downloadManager, tab);
      }
    }finally{
    	
    	downloadViews_mon.exit();
    }
  }

  protected void removeManagerView(DownloadManager downloadManager) {
    try{
    	downloadViews_mon.enter();
      
    	downloadViews.remove(downloadManager);
    }finally{
    	
    	downloadViews_mon.exit();
    }
  }

   public void downloadManagerRemoved(DownloadManager removed) {
    try{
    	downloadViews_mon.enter();
    
      if (downloadViews.containsKey(removed)) {
        final Tab tab = (Tab) downloadViews.get(removed);
        Utils.execSWTThread(new AERunnable(){
          public void runSupport() {
            if (display == null || display.isDisposed())
              return;

            tab.dispose();
          }
        });

      }
    }finally{
    	
    	downloadViews_mon.exit();
    }
  }

  public Display getDisplay() {
    return this.display;
  }

  public Shell getShell() {
    return shell;
  }

  public void setVisible(final boolean visible) {
		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				if (visible && !shell.getVisible()) {
					if (COConfigurationManager.getBooleanParameter("Password enabled",
							false)) {
						if (!PasswordWindow.showPasswordWindow(display)) {
							shell.setVisible(false);
							return;
						}
					}
				}

				shell.setVisible(visible);
				if (visible) {
					if (downloadBasket != null) {
						downloadBasket.setVisible(false);
						downloadBasket.setMoving(false);
					}

					/*
					 if (trayIcon != null)
					 trayIcon.showIcon();
					 */
					shell.forceActive();
					shell.setMinimized(false);
				}

			}
		});
	}

  public boolean isVisible() {
    return shell.isVisible();
  }

  public boolean 
  dispose(
  	boolean	for_restart,
	boolean	close_already_in_progress ) 
  {
  	if (isAlreadyDead) {
  		return true;
  	}

		if (!UIExitUtilsSWT.canClose(globalManager, for_restart)) {
			return false;
		}
    
    if(systemTraySWT != null) {
      systemTraySWT.dispose();
    }
    
    // close all tabs
    Tab.closeAllTabs();

    isAlreadyDead = true; //NICO try to never die twice...
    /*
    if (this.trayIcon != null)
      SysTrayMenu.dispose();
    */

    if(updater != null){
    	
      updater.stopIt();
    }
    
    if (initializer != null) {
    	initializer.stopIt( for_restart, close_already_in_progress );
    }

    //NICO swt disposes the mainWindow all by itself (thanks... ;-( ) on macosx
    if(!shell.isDisposed() && !isDisposeFromListener) {
    	shell.dispose();
    }
      
    
    COConfigurationManager.removeParameterListener( "config.style.useSIUnits", this );
    COConfigurationManager.removeParameterListener( "Show Download Basket", this );
    COConfigurationManager.removeParameterListener( "GUI_SWT_bFancyTab", this );
    

    UIExitUtilsSWT.uiShutdown();
    
    return true;
  }

  public GlobalManager getGlobalManager() {
    return globalManager;
  }

  /**
	 * @return
	 */
  public static MainWindow getWindow() {
    return window;
  }

  /**
	 * @return
	 */
  public TrayWindow getTray() {
    return downloadBasket;
  }



  /**
   * @return Returns the useCustomTab.
   */
  public boolean isUseCustomTab() {
    return useCustomTab;
  }    
  
  
  
  
  Map pluginTabs = new HashMap();
  
  
  protected void openPluginView(String sParentID, String sViewID, UISWTViewEventListener l,
			Object dataSource, boolean bSetFocus) {
  	
  	UISWTViewImpl view = null;
  	try {
  		view = new UISWTViewImpl(sParentID, sViewID, l);
  	} catch (Exception e) {
  		Tab tab = (Tab) pluginTabs.get(sViewID);
  		if (tab != null) {
  			tab.setFocus();
  		}
			return;
  	}
		view.dataSourceChanged(dataSource);

		Tab tab = new Tab(view, bSetFocus);

 		pluginTabs.put(sViewID, tab);
	}
  
  /**
   * Close all plugin views with the specified ID
   * 
   * @param sViewID
   */
  protected void closePluginViews(String sViewID) {
  	Item[] items;

		if (folder instanceof CTabFolder)
			items = ((CTabFolder) folder).getItems();
		else if (folder instanceof TabFolder)
			items = ((TabFolder) folder).getItems();
		else
			return;

		for (int i = 0; i < items.length; i++) {
			IView view = Tab.getView(items[i]);
			if (view instanceof UISWTViewImpl) {
				String sID = ((UISWTViewImpl) view).getViewID();
				if (sID != null && sID.equals(sViewID)) {
					try {
						closePluginView(view);
					} catch (Exception e) {
						Debug.printStackTrace(e);
					}
				}
			}
		} // for
  }
  
  /**
   * Get all open Plugin Views
   * 
   * @return open plugin views
   */
  protected UISWTView[] getPluginViews() {
  	Item[] items;

		if (folder instanceof CTabFolder)
			items = ((CTabFolder) folder).getItems();
		else if (folder instanceof TabFolder)
			items = ((TabFolder) folder).getItems();
		else
			return new UISWTView[0];

		ArrayList views = new ArrayList();
		
		for (int i = 0; i < items.length; i++) {
			IView view = Tab.getView(items[i]);
			if (view instanceof UISWTViewImpl) {
				views.add(view);
			}
		} // for
		
		return (UISWTView[])views.toArray(new UISWTView[0]);
  }

  protected void openPluginView(final AbstractIView view, final String name) {
		Utils.execSWTThread(new AERunnable() {
			public void runSupport() {
				Tab tab = (Tab) pluginTabs.get(name);

⌨️ 快捷键说明

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