Commit 8f3d1e1f authored by Johannes Roith's avatar Johannes Roith

Tooltips can't exceed screen size.

parent 4c26a9a1
......@@ -15,7 +15,9 @@ public abstract class TooltipBase {
private static final int MARGIN = 3;
private static final int MAX_HEIGHT = 300;
private static final int MAX_WIDTH = 600;
private int offsetLeft;
private ScrolledComposite scrolled;
private Shell popup;
private boolean isOpen;
......@@ -38,8 +40,10 @@ public abstract class TooltipBase {
public void show() {
if (!isOpen) {
isOpen = true;
popup.open();}
popup.open();
}
if (!isVisible) {
correctWindowSize();
popup.setVisible(true);
isVisible = true;
}
......@@ -56,17 +60,23 @@ public abstract class TooltipBase {
return isVisible;
}
public void setText(String txt) {
label.setText(txt);
private void correctWindowSize() {
int maxWidth = Display.getCurrent().getPrimaryMonitor().getBounds().width
- 50 - offsetLeft;
Point labelSize = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
popup.setSize(labelSize.x + MARGIN*2, Math.min(labelSize.y, MAX_HEIGHT));
popup.setSize(Math.min(labelSize.x, maxWidth) + MARGIN*2, Math.min(labelSize.y, MAX_HEIGHT) + MARGIN*2);
popup.layout();
scrolled.layout(true, true);
scrolled.setMinSize(labelSize);
}
public void setText(String txt) {
label.setText(txt);
correctWindowSize();
scrolled.layout(true, true);
}
public void setLocation(Point p) {
offsetLeft = p.x;
popup.setLocation(p);
}
......@@ -82,7 +92,7 @@ public abstract class TooltipBase {
this.scrolled.setExpandHorizontal(true);
this.scrolled.setExpandVertical(true);
label = new Label(scrolled, SWT.NONE);
label = new Label(scrolled, SWT.WRAP);
scrolled.setContent(label);
Color background = display.getSystemColor (SWT.COLOR_INFO_BACKGROUND);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment