FileDocCategorySizeDatePackage
TrayWindow.javaAPI DocAzureus 3.0.3.48974Fri Jul 20 11:36:50 BST 2007org.gudy.azureus2.ui.swt

TrayWindow

public class TrayWindow extends Object implements org.gudy.azureus2.core3.global.GlobalManagerListener
Download Basket
author
Olivier

Fields Summary
org.gudy.azureus2.core3.global.GlobalManager
globalManager
List
managers
protected org.gudy.azureus2.core3.util.AEMonitor
managers_mon
org.gudy.azureus2.ui.swt.mainwindow.MainWindow
main
Display
display
Shell
minimized
Label
label
private Menu
menu
private org.eclipse.swt.graphics.Rectangle
screen
private int
xPressed
private int
yPressed
private boolean
moving
Constructors Summary
public TrayWindow(org.gudy.azureus2.ui.swt.mainwindow.MainWindow _main)


     
    this.managers = new ArrayList();
    this.main = _main;
    this.display = main.getDisplay();
    minimized = org.gudy.azureus2.ui.swt.components.shell.ShellFactory.createShell(main.getShell(), SWT.ON_TOP);
    minimized.setText("Azureus"); //$NON-NLS-1$
    label = new Label(minimized, SWT.NULL);
    Image img = ImageRepository.getImage("tray");
    label.setImage(img); //$NON-NLS-1$
    final Rectangle bounds = img.getBounds();
    label.setSize(bounds.width, bounds.height);
    minimized.setSize(bounds.width + 2, bounds.height + 2);
    screen = display.getClientArea();
 //NICO handle macosx and multiple monitors
    if (!Constants.isOSX) {
    	minimized.setLocation(screen.x + screen.width - bounds.width - 2,
					screen.y + screen.height - bounds.height - 2);
    } else {
    	minimized.setLocation(20, 20);
    }
    minimized.layout();
    minimized.setVisible(false);
    //minimized.open();    

    MouseListener mListener = new MouseAdapter() {
      public void mouseDown(MouseEvent e) {
        xPressed = e.x;
        yPressed = e.y;
        moving = true;
        //System.out.println("Position : " + xPressed + " , " + yPressed);          
      }

      public void mouseUp(MouseEvent e) {
        moving = false;
      }

      public void mouseDoubleClick(MouseEvent e) {
        restore();
      }

    };
    MouseMoveListener mMoveListener = new MouseMoveListener() {
      public void mouseMove(MouseEvent e) {
        if (moving) {
          int dX = xPressed - e.x;
          int dY = yPressed - e.y;
          Point currentLoc = minimized.getLocation();
          int x = currentLoc.x - dX;
          int y = currentLoc.y - dY;
          if (x < 10)
            x = 0;
          if (x > screen.width - (bounds.width + 12))
            x = screen.width - (bounds.width + 2);
          if (y < 10)
            y = 0;
          if (y > screen.height - (bounds.height + 12))
            y = screen.height - (bounds.height + 2);
          minimized.setLocation(x, y);
        }
      }
    };

    label.addMouseListener(mListener);
    label.addMouseMoveListener(mMoveListener);

    menu = new Menu(minimized, SWT.CASCADE);
    label.setMenu(menu);

    MenuItem file_show = new MenuItem(menu, SWT.NULL);
    Messages.setLanguageText(file_show, "TrayWindow.menu.show"); //$NON-NLS-1$
    menu.setDefaultItem(file_show);
    file_show.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event e) {
        restore();
      }
    });

    new MenuItem(menu, SWT.SEPARATOR);
    
    main.getMenu().addCloseDownloadBarsToMenu(menu);
    
    new MenuItem(menu, SWT.SEPARATOR);

    MenuItem file_startalldownloads = new MenuItem(menu, SWT.NULL);
    Messages.setLanguageText(file_startalldownloads, "TrayWindow.menu.startalldownloads"); //$NON-NLS-1$
    file_startalldownloads.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event e) {
            globalManager.startAllDownloads();
        }
    });    
    
    MenuItem file_stopalldownloads = new MenuItem(menu, SWT.NULL);
    Messages.setLanguageText(file_stopalldownloads, "TrayWindow.menu.stopalldownloads"); //$NON-NLS-1$
    file_stopalldownloads.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event e) {
      	ManagerUtils.asyncStopAll();
      }
    });

    new MenuItem(menu, SWT.SEPARATOR);

    MenuItem file_close = new MenuItem(menu, SWT.NULL);
    Messages.setLanguageText(file_close, "TrayWindow.menu.close");
    file_close.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event e) {
        COConfigurationManager.setParameter("Show Download Basket", false);
      }
    });

    MenuItem file_exit = new MenuItem(menu, SWT.NULL);
    Messages.setLanguageText(file_exit, "TrayWindow.menu.exit"); //$NON-NLS-1$
    file_exit.addListener(SWT.Selection, new Listener() {
      public void handleEvent(Event e) {
        main.dispose(false,false);
      }
    });

    Utils.createTorrentDropTarget(minimized, false);
    globalManager = main.getGlobalManager();
    globalManager.addListener(this);
  
Methods Summary
public voiddestroyInitiated()

	
public voiddestroyed()

	
public voiddispose()

    minimized.dispose();
  
public voiddownloadManagerAdded(org.gudy.azureus2.core3.download.DownloadManager created)

     try{
     	managers_mon.enter();
     
     	managers.add(created);
     }finally{
     	
     	managers_mon.exit();
    }
  
public voiddownloadManagerRemoved(org.gudy.azureus2.core3.download.DownloadManager removed)

    try{
    	managers_mon.enter();
    	
    	managers.remove(removed);
    }finally{
    	managers_mon.exit();
    }
  
public voidrefresh()

    if (minimized.isDisposed() || !minimized.isVisible())
      return;

    StringBuffer toolTip = new StringBuffer();
    String separator = ""; //$NON-NLS-1$
    try{
      managers_mon.enter();
      for (int i = 0; i < managers.size(); i++) {
        DownloadManager manager = (DownloadManager) managers.get(i);
		DownloadManagerStats	stats = manager.getStats();
		
        String name = manager.getDisplayName();
        String completed = DisplayFormatters.formatPercentFromThousands(stats.getCompleted());
        toolTip.append(separator);
        toolTip.append(name);
        toolTip.append(" -- C: ");
        toolTip.append(completed);
        toolTip.append(", D : ");
				toolTip.append(DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(
						stats.getDataReceiveRate(), stats.getProtocolReceiveRate()));
				toolTip.append(", U : ");
				toolTip.append(DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(
						stats.getDataSendRate(), stats.getProtocolSendRate()));
        separator = "\n"; //$NON-NLS-1$
      }
    }finally{
    	managers_mon.exit();
    }
    //label.setToolTipText(toolTip.toString());
    //minimized.moveAbove(null);
  
public voidrestore()

    if(!COConfigurationManager.getBooleanParameter("Show Download Basket"))
      minimized.setVisible(false);
    main.setVisible(true);
    moving = false;
  
public voidseedingStatusChanged(boolean seeding_only_mode)

    
public voidsetMoving(boolean moving)

param
moving

    this.moving = moving;
  
public voidsetVisible(boolean visible)

    if(visible || !COConfigurationManager.getBooleanParameter("Show Download Basket")) {
      minimized.setVisible(visible);
      if (!visible)
        moving = false;
    }
  
public voidupdateLanguage()

    MainWindow.getWindow().getMenu().updateMenuText(menu);