Commit 988c4162 authored by Johannes Roith's avatar Johannes Roith

- Experimental custom tooltip in automaton view.

- Removed pointless visitors.
parent 25f7a8e8
package de.in.tum.www2.cup.analysis;
public class CupGenVisitor<T> extends Visitor<T>
{
}
package de.in.tum.www2.cup.analysis;
public class ParseJavaVisitor<T> extends Visitor<T>
{
}
......@@ -31,6 +31,7 @@ import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
......@@ -60,6 +61,7 @@ import org.eclipse.zest.core.viewers.ZoomContributionViewItem;
import org.eclipse.zest.core.viewers.internal.ZoomManager;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphItem;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.core.widgets.ZestStyles;
import org.eclipse.zest.layouts.LayoutAlgorithm;
......@@ -80,6 +82,7 @@ import de.in.tum.www2.cup.internal.lalr_transition;
import de.in.tum.www2.cup.internal.parse_reduce_row;
import de.in.tum.www2.cup.internal.parse_reduce_table;
import de.tum.in.www2.cupplugin.Colors;
import de.tum.in.www2.cupplugin.Pair;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.controller.IRegisterForControllerChanges;
......@@ -89,6 +92,7 @@ import de.tum.in.www2.cupplugin.editors.CupTextEditor;
import de.tum.in.www2.cupplugin.editors.Jumper;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
import de.tum.in.www2.cupplugin.widgets.StateTooltip;
public class CupReduceGraphView extends FailableView
implements ICupParserLaLrChangeObserver,
......@@ -189,6 +193,64 @@ public class CupReduceGraphView extends FailableView
new HorizontalShift(
LayoutStyles.NO_LAYOUT_NODE_RESIZING) });
StateTooltip tooltip = new StateTooltip(parent.getDisplay());
// TODO: HACK!
List<Method> wrapper = new ArrayList<Method>();
try {
Method m = Graph.class.getDeclaredMethod("getGraphItem", new Class[] { IFigure.class });
m.setAccessible(true);
wrapper.add(m);
} catch (NoSuchMethodException | SecurityException | IllegalArgumentException e) {
e.printStackTrace();
}
graphViewer.getGraphControl().addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
tooltip.fix();
}
@Override
public void mouseUp(MouseEvent e) {
tooltip.unfix();
}
});
graphViewer.getGraphControl().addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
if (tooltip.isFixed())
return;
Graph g = (Graph) graphViewer.getControl();
Point p = e.display.getCursorLocation();
IFigure figure = g.getFigureAt(e.x, e.y);
if (figure != null) {
GraphItem gi = null;
try {
gi = (GraphItem) wrapper.get(0).invoke(g, figure);
} catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException e1) {
e1.printStackTrace();
}
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());
}
} else {
tooltip.hide();
}
}
});
graphViewer.getGraphControl().addMouseListener(new MouseAdapter() {
@Override
......@@ -422,13 +484,19 @@ public class CupReduceGraphView extends FailableView
private final String name;
private List<ParserReduceNode> connections;
private String description;
private lalr_state state;
public ParserReduceNode(int id, String name) {
public ParserReduceNode(lalr_state state, int id, String name) {
this.state = state;
this.id = id;
this.name = name;
this.connections = new ArrayList<ParserReduceNode>();
this.description = "";
}
public lalr_state getState() {
return this.state;
}
public int getId() {
return id;
......@@ -638,7 +706,7 @@ public class CupReduceGraphView extends FailableView
}
for (lalr_state state : allStates) {
ParserReduceNode n = new ParserReduceNode(state.index(),
ParserReduceNode n = new ParserReduceNode(state, state.index(),
"State: " + state.index());
n.setDescription(state.toString());
nodes.add(n);
......@@ -785,6 +853,8 @@ public class CupReduceGraphView extends FailableView
@Override
public IFigure getTooltip(Object entity) {
return null;
/*
Label description = null;
if (entity instanceof ParserReduceNode) {
ParserReduceNode n = (ParserReduceNode) entity;
......@@ -793,6 +863,7 @@ public class CupReduceGraphView extends FailableView
}
description = new Label("");
return description;
*/
}
@Override
......@@ -821,30 +892,18 @@ public class CupReduceGraphView extends FailableView
}
}
/*
static class CupToolTipHelper extends PopUpHelper {
private Timer timer;
private IFigure currentTipSource;
/**
* Constructs a ToolTipHelper to be associated with Control <i>c</i>.
*
* @param c
* the control
* @since 2.0
*/
public CupToolTipHelper(org.eclipse.swt.widgets.Control c) {
super(c, SWT.TOOL | SWT.ON_TOP);
getShell().setBackground(ColorConstants.tooltipBackground);
getShell().setForeground(ColorConstants.tooltipForeground);
}
/*
* Calculates the location where the tooltip will be painted. Returns
* this as a Point. Tooltip will be painted directly below the cursor if
* possible, otherwise it will be painted directly above cursor.
*/
private Point computeWindowLocation(IFigure tip, int eventX, int eventY) {
org.eclipse.swt.graphics.Rectangle clientArea = control
.getDisplay().getClientArea();
......@@ -863,26 +922,7 @@ public class CupReduceGraphView extends FailableView
return preferredLocation;
}
/**
* Sets the LightWeightSystem's contents to the passed tooltip, and
* displays the tip. The tip will be displayed only if the tip source is
* different than the previously viewed tip source. (i.e. The cursor has
* moved off of the previous tooltip source figure.)
* <p>
* The tooltip will be painted directly below the cursor if possible,
* otherwise it will be painted directly above cursor.
*
* @param hoverSource
* the figure over which the hover event was fired
* @param tip
* the tooltip to be displayed
* @param eventX
* the x coordinate of the hover event
* @param eventY
* the y coordinate of the hover event
* @since 2.0
*/
public void displayToolTipNear(IFigure hoverSource, IFigure tip,
int eventX, int eventY) {
if (tip != null && hoverSource != currentTipSource) {
......@@ -908,11 +948,6 @@ public class CupReduceGraphView extends FailableView
}
}
/**
* Disposes of the tooltip's shell and kills the timer.
*
* @see PopUpHelper#dispose()
*/
public void dispose() {
if (isShowing()) {
timer.cancel();
......@@ -921,9 +956,6 @@ public class CupReduceGraphView extends FailableView
getShell().dispose();
}
/**
* @see PopUpHelper#hookShellListeners()
*/
protected void hookShellListeners() {
// Close the tooltip window if the mouse enters the tooltip
getShell().addMouseTrackListener(new MouseTrackAdapter() {
......@@ -937,26 +969,9 @@ public class CupReduceGraphView extends FailableView
});
}
/**
* Displays the hover source's tooltip if a tooltip of another source is
* currently being displayed.
*
* @param figureUnderMouse
* the figure over which the cursor was when called
* @param tip
* the tooltip to be displayed
* @param eventX
* the x coordinate of the cursor
* @param eventY
* the y coordinate of the cursor
* @since 2.0
*/
public void updateToolTip(IFigure figureUnderMouse, IFigure tip,
int eventX, int eventY) {
/*
* If the cursor is not on any Figures, it has been moved off of the
* control. Hide the tool tip.
*/
if (figureUnderMouse == null) {
if (isShowing()) {
hide();
......@@ -974,7 +989,7 @@ public class CupReduceGraphView extends FailableView
}
}
*/
static class BuildUpNodeFilter extends ViewerFilter {
private List<ParserReduceNode> nodeList;
......
package de.tum.in.www2.cupplugin.widgets;
import org.eclipse.swt.widgets.Display;
import de.in.tum.www2.cup.internal.lalr_state;
public class StateTooltip extends TooltipBase {
private lalr_state state;
public StateTooltip(Display display) {
super(display);
}
public void show(lalr_state state) {
if (this.state != state) {
this.state = state;
setText(this.state.toString());
}
show();
}
}
package de.tum.in.www2.cupplugin.widgets;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
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 Shell popup;
private boolean isOpen;
private boolean isVisible;
private Label label;
private boolean fixed;
public void fix() {
fixed = true;
}
public void unfix() {
fixed = false;
}
public boolean isFixed() {
return fixed;
}
public void show() {
if (!isOpen) {
isOpen = true;
popup.open();}
if (!isVisible) {
popup.setVisible(true);
isVisible = true;
}
}
public void hide() {
if (isVisible) {
popup.setVisible(false);
isVisible = false;
}
}
public void setText(String txt) {
label.setText(txt);
label.pack();
Rectangle rect = label.getBounds();
popup.setSize(rect.width, rect.height);
}
public void setLocation(Point p) {
popup.setLocation(p);
}
public TooltipBase(Display display) {
popup = new Shell(display, SWT.BALLOON | SWT.ON_TOP);
Color background = display.getSystemColor (SWT.COLOR_INFO_BACKGROUND);
popup.setBackground(background);
label = new Label(popup, SWT.NONE);
popup.setSize(200, 150);
}
}
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