Commit d3d9926e authored by Benedikt Engeser's avatar Benedikt Engeser

Merge branch 'master' of git@github.com:jroith/cup-eclipse.git

parents 328fe3d0 103d8f37
......@@ -90,7 +90,7 @@ import de.tum.in.www2.cupplugin.editors.Jumper;
import de.tum.in.www2.cupplugin.model.ICupParserLaLrChangeObserver;
import de.tum.in.www2.cupplugin.model.Model;
public class CupConflictGraphView extends FailableView implements
public class CupConflictGraphView extends CupGraphBase implements
ICupParserLaLrChangeObserver, IZoomableWorkbenchPart,
ICupEditorPageVisibility, IRegisterForControllerChanges {
......@@ -163,6 +163,8 @@ public class CupConflictGraphView extends FailableView implements
graphViewer.setNodeStyle(ZestStyles.NODES_NO_ANIMATION);
graphViewer.setInput(nodeModel.getNodes());
attachTooltip(graphViewer);
// Setup search Result Label
scroll = new ScrolledComposite(this.parentComposite, SWT.BORDER
......@@ -550,19 +552,14 @@ public class CupConflictGraphView extends FailableView implements
setModelForDFSAfterState(stateHashMap.get(index));
}
static class ParserConflictNode {
private final int id;
private final String name;
static class ParserConflictNode extends CupGraphNode {
private List<ParserConflictNode> connections;
private String description;
private boolean isNonTerm = false;
private String transitionSymbol;
public ParserConflictNode(int id, String name) {
this.id = id;
this.name = name;
public ParserConflictNode(lalr_state state, int id, String name) {
super(state, id, name, "");
this.connections = new ArrayList<ParserConflictNode>();
this.description = "";
}
public int getId() {
......@@ -671,7 +668,7 @@ public class CupConflictGraphView extends FailableView implements
ParserConflictNode oldNode = null;
int counter = 0;
for (CupConflictState state : resultList) {
ParserConflictNode newNode = new ParserConflictNode(state
ParserConflictNode newNode = new ParserConflictNode(state.getState(), state
.getState().index(), "State "
+ state.getState().index());
newNode.setDescription(state.getState().toString());
......@@ -793,6 +790,8 @@ public class CupConflictGraphView extends FailableView implements
@Override
public IFigure getTooltip(Object entity) {
return null;
/*
org.eclipse.draw2d.Label description = null;
if (entity instanceof ParserConflictNode) {
ParserConflictNode n = (ParserConflictNode) entity;
......@@ -802,6 +801,7 @@ public class CupConflictGraphView extends FailableView implements
}
description = new org.eclipse.draw2d.Label("");
return description;
*/
}
@Override
......
......@@ -13,6 +13,7 @@ import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
......@@ -62,10 +63,9 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
class ConflictPanel extends Composite {
private static final int BASE_HEIGHT = 90;
private static final int BASE_HEIGHT = 60;
private static final int COLUMNS = 3;
private static final int HEADING_FONT_SIZE = 14;
private static final int SIZE_INCREASE_PER_LINE = 11;
private Conflict conflict;
......@@ -200,6 +200,7 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
public void update(ConflictResolutionManager crm, Conflict conflict) {
this.conflict = conflict;
gridData.heightHint = BASE_HEIGHT;
links.clear();
int linkCounter = 0;
......@@ -207,7 +208,9 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
lalr_state state = conflict.getState();
Pair<String,Integer> hint = makeConflictResolutionHint(crm, state);
resolutionHint.setText(hint.getFirst());
gridData.heightHint = BASE_HEIGHT + hint.getSecond() * SIZE_INCREASE_PER_LINE;
gridData.heightHint += resolutionHint.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
System.err.println(gridData.heightHint);
int cindex = state.index();
stateLabel.setText("<a href=\"" + cindex + "\">State: " + cindex + "</a>");
......@@ -310,11 +313,14 @@ public class CupConflictsView extends FailableView implements ICupEditorPageVisi
builder.append("</a>");
if (i != size - 1)
builder.append(", ");
gridData.heightHint += SIZE_INCREASE_PER_LINE;
// gridData.heightHint += SIZE_INCREASE_PER_LINE;
}
detailText.setText(builder.toString());
gridData.heightHint += detailText.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
} else {
throw new RuntimeException("unexpected conflict type.");
}
......
package de.tum.in.www2.cupplugin.views;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.draw2d.IFigure;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.zest.core.viewers.GraphViewer;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphItem;
import de.in.tum.www2.cup.internal.lalr_state;
import de.tum.in.www2.cupplugin.views.CupReduceGraphView.ParserReduceNode;
import de.tum.in.www2.cupplugin.widgets.StateTooltip;
public class CupGraphBase extends FailableView {
public static class CupGraphNode {
protected int id;
protected String name;
protected String description;
protected lalr_state state;
public lalr_state getState() {
return this.state;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public CupGraphNode(lalr_state state, int id, String name, String description) {
this.state = state;
this.id = id;
this.name = name;
this.description = "";
}
}
// TODO: hack!
public static GraphItem giAtPopup;
public static int xAtPopup = -1;
public static int yAtPopup = -1;
public CupGraphBase(Composite parent) {
super(parent);
}
protected <T> void attachTooltip(GraphViewer graphViewer) {
StateTooltip tooltip = new StateTooltip(graphViewer.getGraphControl().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 CupGraphNode) {
CupGraphNode node = (CupGraphNode) gi.getData();
Point target = new Point(p.x + 10, p.y + 10);
if (giAtPopup != gi || !tooltip.isVisible ()) {
tooltip.setLocation(target);
tooltip.show(node.getState());
giAtPopup = gi;
xAtPopup = e.x;
yAtPopup = e.y;
}
}
} else if (Math.abs(xAtPopup-e.x) > 15 && Math.abs(yAtPopup-e.y) > 15) {
tooltip.hide();
}
}
});
}
}
......@@ -94,17 +94,11 @@ 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
public class CupReduceGraphView extends CupGraphBase
implements ICupParserLaLrChangeObserver,
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;
......@@ -199,65 +193,7 @@ 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);
if (!tooltip.isVisible ()) {
tooltip.setLocation(target);
tooltip.show(node.getState());
xAtPopup = e.x;
yAtPopup = e.y;
}
}
} else if (Math.abs(xAtPopup-e.x) > 15 && Math.abs(yAtPopup-e.y) > 15) {
tooltip.hide();
}
}
});
attachTooltip(graphViewer);
graphViewer.getGraphControl().addMouseListener(new MouseAdapter() {
......@@ -487,44 +423,17 @@ public class CupReduceGraphView extends FailableView
* ContentProviderStuff for Zest
*/
static class ParserReduceNode {
private final int id;
private final String name;
static class ParserReduceNode extends CupGraphNode {
private List<ParserReduceNode> connections;
private String description;
private lalr_state state;
public ParserReduceNode(lalr_state state, int id, String name) {
this.state = state;
this.id = id;
this.name = name;
super(state, id, name, "");
this.connections = new ArrayList<ParserReduceNode>();
this.description = "";
}
public lalr_state getState() {
return this.state;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public List<ParserReduceNode> getConnectedTo() {
return connections;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
static class ParserReduceConnection {
......
......@@ -71,7 +71,7 @@ public abstract class TooltipBase {
}
public TooltipBase(Display display) {
popup = new Shell(display, SWT.BALLOON | SWT.ON_TOP);
popup = new Shell(display, SWT.BALLOON);
FillLayout fillLayout = new FillLayout();
fillLayout.marginWidth = MARGIN;
......
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