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

📄 minimizedwindow.java

📁 这是一个基于java编写的torrent的P2P源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        close();
      }
    });
    
    splash.setMenu(menu);
    lDrag.setMenu(menu);
    l1.setMenu(menu);
    l3.setMenu(menu);
    l4.setMenu(menu);
    l5.setMenu(menu);
    pb1.setMenu(menu);
    splashDown.setMenu(menu);
    splashFile.setMenu(menu);
    splashUp.setMenu(menu);
    splashTime.setMenu(menu);
    

    try {
    	downloadBars_mon.enter();

      downloadBars.add(this);
    } finally {
    	downloadBars_mon.exit();
    }
    refresh();
    splash.setVisible(true);
    
    
  }

  public static ShellManager getShellManager() {
      return shellManager;
  }

  private void setSnapLocation(Point currentLoc) {
    /*
    if (downloadBars.size() > 1) {
      Rectangle snap = splash.getBounds();
      snap.x -= 10;
      snap.y -= 10;
      snap.height += 20;
      snap.width += 20;
      Point cursor = splash.getDisplay().getCursorLocation();
      if (!(cursor.x < snap.x || cursor.x > snap.x + snap.width || cursor.y < snap.y || cursor.y > snap.y + snap.height)) {
        if(snapped)
          return;
        for (int i = 0; i < downloadBars.size(); i++) {
          Shell downloadBar = (Shell) downloadBars.get(i);
          if (downloadBar != splash && !downloadBar.isDisposed()) {
            Rectangle rectangle = downloadBar.getBounds();
            if (snap.intersects(rectangle)) {
              currentLoc.x = rectangle.x;
              currentLoc.y = currentLoc.y > rectangle.y ? rectangle.y + rectangle.height : rectangle.y - rectangle.height;
              snapped = true;
            }
          }
        }
      } else {
        snapped = false;
      }
    }
    */
    if (currentLoc.x < 10)
      currentLoc.x = 0;
    else if (currentLoc.x > screen.width - splash.getBounds().width - 10)
      currentLoc.x = screen.width - splash.getBounds().width;
    if (currentLoc.y < 10)
      currentLoc.y = 0;
    MinimizedWindow mw = this;
    int height = 0;
    while (mw != null) {
      Shell s = mw.getShell();
      if (s.isDisposed())
        mw = null;
      else {
        height += s.getBounds().height - 1;
        mw = mw.getStucked();
        if (mw == this)
          mw = null;
      }
    }
    if (currentLoc.y > screen.height - height - 10)
      currentLoc.y = screen.height - height;

    try {
    	downloadBars_mon.enter();

    if (downloadBars.size() > 1) {
      for (int i = 0; i < downloadBars.size(); i++) {
        MinimizedWindow downloadBar = (MinimizedWindow) downloadBars.get(i);
        Point location = downloadBar.getShell().getLocation();
        // isn't the height always 10?
        // Gudy : No it depends on your system font.
        location.y += downloadBar.getShell().getBounds().height;
        //Stucking to someone else
        if (downloadBar != this && downloadBar.getStucked() == null || downloadBar.getStucked() == this) {
          if (Math.abs(location.x - currentLoc.x) < 10 && location.y - currentLoc.y < 10 && location.y - currentLoc.y > 0) {
            downloadBar.setStucked(this);
            currentLoc.x = location.x;
            currentLoc.y = location.y - 1;
          }
        }
        //Un-stucking from someone
        if (downloadBar != this && downloadBar.getStucked() == this) {
          if (Math.abs(location.x - currentLoc.x) > 10 || Math.abs(location.y - currentLoc.y) > 10)
            downloadBar.setStucked(null);
        }
      }
    }
    } finally {
    	downloadBars_mon.exit();
    }

    splash.setLocation(currentLoc);
    MinimizedWindow mwCurrent = this;
    while (mwCurrent != null) {
      currentLoc.y += mwCurrent.getShell().getBounds().height - 1;
      MinimizedWindow mwChild = mwCurrent.getStucked();
      if (mwChild != null && mwChild != this) {
        Shell s = mwChild.getShell();
        if (s.isDisposed()) {
          mwCurrent.setStucked(null);
          mwCurrent = null;
        }
        else {
          mwCurrent = mwChild;
          mwCurrent.getShell().setLocation(currentLoc);
        }
      }
      else
        mwCurrent = null;
    }
  }

  public void close() {
    if(!splash.isDisposed()) {
      Display display = splash.getDisplay();
      if(display != null && ! display.isDisposed()) {
       display.asyncExec(new AERunnable() {
        public void runSupport() {
          if(!splash.isDisposed()) {
            splash.dispose();
          }
        }
       }); 
      }
    }
    try {
    	downloadBars_mon.enter();

    	downloadBars.remove(this);
    } finally {
    	downloadBars_mon.exit();
    }
  }


  public void refresh() {
    if (splash.isDisposed())
      return;
    splashFile.setText(manager.getDisplayName());
    final int percent = manager.getStats().getCompleted();
    splashDown.setText(DisplayFormatters.formatByteCountToKiBEtcPerSec(manager.getStats().getDataReceiveRate()));
    splashUp.setText(DisplayFormatters.formatByteCountToKiBEtcPerSec(manager.getStats().getDataSendRate()));
    splashTime.setText(DisplayFormatters.formatETA(manager.getStats().getETA()));
    
    if ( pb1.getSelection() != percent ){
    	
    	pb1.setSelection(percent);
    
    	pb1.redraw();
    }
  }

  public void setVisible(boolean visible) {
    splash.setVisible(visible);
  }

  public Shell getShell() {
    return this.splash;
  }

  public MinimizedWindow getStucked() {
    return this.stucked;
  }

  public void setStucked(MinimizedWindow mw) {
    this.stucked = mw;
  }
  
  public static void close(MinimizedWindow downloadBar) {
  	if (downloadBar != null) {
  		downloadBar.close();
  	}
  }

  public static void close(DownloadManager dm) {
		Object[] bars = downloadBars.toArray();
		for (int i = 0; i < bars.length; i++) {
			MinimizedWindow bar = (MinimizedWindow) bars[i];
			if (bar.manager.equals(dm)) {
				bar.close();
			}
		}
	}

	public static void closeAll() {
		Object[] bars = downloadBars.toArray();
		for (int i = 0; i < bars.length; i++) {
			MinimizedWindow bar = (MinimizedWindow) bars[i];
			bar.close();
		}
	}

	public static boolean isOpen(DownloadManager dm) {
		try {
			downloadBars_mon.enter();

			for (Iterator iter = downloadBars.iterator(); iter.hasNext();) {
				MinimizedWindow bar = (MinimizedWindow) iter.next();
				if (bar.manager.equals(dm)) {
					return true;
				}
			}
		} finally {
			downloadBars_mon.exit();
		}
		return false;
	}

	public static MinimizedWindow get(DownloadManager dm) {
		try {
			downloadBars_mon.enter();

			for (Iterator iter = downloadBars.iterator(); iter.hasNext();) {
				MinimizedWindow bar = (MinimizedWindow) iter.next();
				if (bar.manager.equals(dm)) {
					return bar;
				}
			}
		} finally {
			downloadBars_mon.exit();
		}
		return null;
	}

	public static boolean refreshAll() {
		try {
			downloadBars_mon.enter();

			for (Iterator iter = downloadBars.iterator(); iter.hasNext();) {
				MinimizedWindow bar = (MinimizedWindow) iter.next();
				bar.refresh();
			}
		} finally {
			downloadBars_mon.exit();
		}
		return false;
	}

	public static boolean setAllVisible(boolean visible) {
		try {
			downloadBars_mon.enter();

			for (Iterator iter = downloadBars.iterator(); iter.hasNext();) {
				MinimizedWindow bar = (MinimizedWindow) iter.next();
				bar.setVisible(visible);
			}
		} finally {
			downloadBars_mon.exit();
		}
		return false;
	}
}

⌨️ 快捷键说明

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