Commit 56847b62 authored by Johannes Roith's avatar Johannes Roith

- Tooltips stay at a fixed position.

- Scrolling
- Minor changes.
parent 17347851
......@@ -99,6 +99,12 @@ public class CupReduceGraphView extends FailableView
IZoomableWorkbenchPart, ICupEditorPageVisibility,
IRegisterForControllerChanges {
// TODO: hack!
public static int xAtPopup = -1;
public static int yAtPopup = -1;
// Some Constants
private static final int BUTTON_WIDTH = 120;
private static final int LABEL_WIDTH = 40;
......@@ -208,12 +214,10 @@ public class CupReduceGraphView extends FailableView
}
graphViewer.getGraphControl().addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
tooltip.fix();
}
@Override
public void mouseUp(MouseEvent e) {
tooltip.unfix();
......@@ -240,10 +244,14 @@ public class CupReduceGraphView extends FailableView
if (gi.getData() instanceof ParserReduceNode) {
ParserReduceNode node = (ParserReduceNode) gi.getData();
Point target = new Point(p.x + 10, p.y + 10);
tooltip.setLocation(target);
tooltip.show(node.getState());
if (!tooltip.isVisible ()) {
tooltip.setLocation(target);
tooltip.show(node.getState());
xAtPopup = e.x;
yAtPopup = e.y;
}
}
} else {
} else if (Math.abs(xAtPopup-e.x) > 15 && Math.abs(yAtPopup-e.y) > 15) {
tooltip.hide();
}
}
......
package de.tum.in.www2.cupplugin.widgets;
import java.util.Enumeration;
import org.eclipse.swt.widgets.Display;
import de.in.tum.www2.cup.internal.lalr_item;
import de.in.tum.www2.cup.internal.lalr_state;
public class StateTooltip extends TooltipBase {
private lalr_state state;
public StateTooltip(Display display) {
super(display);
}
......@@ -15,9 +18,13 @@ public class StateTooltip extends TooltipBase {
public void show(lalr_state state) {
if (this.state != state) {
this.state = state;
String str = this.state.items().toString();
str = str.replace("(*)", "\u2022");
setText("TEST:\n" + str);
StringBuilder builder = new StringBuilder();
for (Enumeration e = this.state.items().all(); e.hasMoreElements(); ) {
builder.append(((lalr_item)e.nextElement()).toString().replace("(*)", "\u2022"));
builder.append("\n");
}
setText(builder.toString());
}
show();
}
......
package de.tum.in.www2.cupplugin.widgets;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import de.tum.in.www2.cupplugin.Colors;
public abstract class TooltipBase {
private static final int MARGIN = 3;
private static final int MAX_HEIGHT = 300;
private ScrolledComposite scrolled;
private Shell popup;
private boolean isOpen;
private boolean isVisible;
private Label label;
private boolean fixed;
public void fix() {
fixed = true;
}
......@@ -46,12 +51,19 @@ public abstract class TooltipBase {
isVisible = false;
}
}
public boolean isVisible() {
return isVisible;
}
public void setText(String txt) {
label.setText(txt);
label.pack();
Rectangle rect = label.getBounds();
popup.setSize(rect.width, rect.height);
Point labelSize = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
popup.setSize(labelSize.x + MARGIN*2, Math.min(labelSize.y, MAX_HEIGHT));
popup.layout();
scrolled.layout(true, true);
scrolled.setMinSize(labelSize);
}
public void setLocation(Point p) {
......@@ -60,12 +72,32 @@ public abstract class TooltipBase {
public TooltipBase(Display display) {
popup = new Shell(display, SWT.BALLOON | SWT.ON_TOP);
FillLayout fillLayout = new FillLayout();
fillLayout.marginWidth = MARGIN;
fillLayout.marginHeight = MARGIN;
popup.setLayout(fillLayout);
this.scrolled = new ScrolledComposite(popup, SWT.V_SCROLL);
this.scrolled.setExpandHorizontal(true);
this.scrolled.setExpandVertical(true);
label = new Label(scrolled, SWT.NONE);
scrolled.setContent(label);
Color background = display.getSystemColor (SWT.COLOR_INFO_BACKGROUND);
popup.setBackground(background);
label = new Label(popup, SWT.NONE);
this.scrolled.setBackground(background);
this.label.setBackground(background);
popup.setSize(200, 150);
this.label.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
System.out.println("clicked label!");
}
});
popup.setSize(10, 10);
}
}
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