Fixed tooltip alignment on windows

This commit is contained in:
nathan 2015-01-23 00:25:35 +01:00
parent 0065cb259a
commit fda29df750

View File

@ -91,37 +91,46 @@ public class SwingSystemTray extends dorkbox.util.tray.SystemTray {
Point point = e.getPoint(); Point point = e.getPoint();
Rectangle bounds = SwingUtil.getScreenBoundsAt(point); Rectangle bounds = SwingUtil.getScreenBoundsAt(point);
// linux gtk was ICON_SIZE+4
int PADDING = ICON_SIZE/2;
int x = point.x; int x = point.x;
int y = point.y; int y = point.y;
if (y < bounds.y) { if (y < bounds.y) {
y = bounds.y; y = bounds.y;
} else if (y > bounds.y + bounds.height) { } else if (y + size.height > bounds.y + bounds.height) {
y = bounds.y + bounds.height + ICON_SIZE + 4; // 4 for padding // our menu cannot have the top-edge snap to the mouse
} // so we make the bottom-edge snap to the mouse
if (x < bounds.x) { y -= size.height; // snap to edge of mouse
x = bounds.x;
} else if (x > bounds.x + bounds.width) {
x = bounds.x + bounds.width;
} }
if (x + size.width > bounds.x + bounds.width) { if (x < bounds.x) {
// always put the menu in the middle x = bounds.x;
x = bounds.x + bounds.width - size.width; } else if (x + size.width > bounds.x + bounds.width) {
} // our menu cannot have the left-edge snap to the mouse
if (y + size.height > bounds.y + bounds.height) { // so we make the right-edge snap to the mouse
y = bounds.y + bounds.height - size.height - ICON_SIZE - 4; // 4 for padding x -= size.width; // snap to edge of mouse
} }
// if (x + size.width > bounds.x + bounds.width) {
// // always put the menu in the middle
// x = bounds.x + bounds.width - size.width;
// }
// if (y + size.height > bounds.y + bounds.height) {
// y = bounds.y + bounds.height - size.height - PADDING;
// }
// do we open at top-right or top-left? // do we open at top-right or top-left?
// we ASSUME monitor size is greater than 640x480 AND that our tray icon is IN THE CORNER SOMEWHERE // we ASSUME monitor size is greater than 640x480 AND that our tray icon is IN THE CORNER SOMEWHERE
// always put the menu in the middle // always put the menu in the horiz. middle
x -= size.width / 4; // x -= size.width / 4;
SwingSystemTray.this.jmenu.setInvoker(SwingSystemTray.this.jmenu); SwingSystemTray.this.jmenu.setInvoker(SwingSystemTray.this.jmenu);
SwingSystemTray.this.jmenu.setLocation(x, y); SwingSystemTray.this.jmenu.setLocation(x, y);
SwingSystemTray.this.jmenu.setVisible(true); SwingSystemTray.this.jmenu.setVisible(true);
SwingSystemTray.this.jmenu.requestFocus();
} }
}); });