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);