Commit e317ef47 authored by Michael Schwarz's avatar Michael Schwarz 🤔
Browse files

Separate closure from core (and in there finished from non-finished) in

tooltips for conflict trace
parent 9ad30549
......@@ -18,6 +18,7 @@ import org.eclipse.zest.core.widgets.GraphItem;
import de.in.tum.www2.cup.internal.lalr_state;
import de.tum.in.www2.cupplugin.views.CupConflictGraphView.ParserConflictNode;
import de.tum.in.www2.cupplugin.views.CupReduceGraphView.ParserReduceNode;
import de.tum.in.www2.cupplugin.widgets.ITooltip;
import de.tum.in.www2.cupplugin.widgets.StateTooltip;
public class CupGraphBase extends FailableView {
......@@ -67,7 +68,7 @@ public class CupGraphBase extends FailableView {
}
protected <T> void attachTooltip(GraphViewer graphViewer,
StateTooltip tooltip) {
ITooltip tooltip) {
// TODO: HACK!
List<Method> wrapper = new ArrayList<Method>();
try {
......
......@@ -15,42 +15,63 @@ import de.tum.in.www2.cupplugin.views.CupConflictGraphView;
import de.tum.in.www2.cupplugin.views.CupConflictGraphView.ParserConflictNode;
import de.tum.in.www2.cupplugin.views.CupGraphBase.CupGraphNode;
public class ConflictStateTooltip extends StateTooltip {
public class ConflictStateTooltip extends MultipleTextTooltipBase implements ITooltip {
private CupConflictState cState;
public ConflictStateTooltip(Display display) {
super(display);
super(display,3);
}
@Override
public void show(CupGraphNode node) {
if(!(node instanceof ParserConflictNode)) {
return;
}
ParserConflictNode cNode = (ParserConflictNode)node;
if (this.cState != cNode.getcState()) {
// This is what used to be here
// List<lalr_transition> goneTransitions = new LinkedList<lalr_transition>();
// CupConflictState current = cState;
// while(current.getPredecessor()!=null) {
// current = current.getPredecessor();
// goneTransitions.add(current.getTransition());
// }
// Collections.reverse(goneTransitions);
this.cState = cNode.getcState();
StringBuilder builder = new StringBuilder();
StringBuilder core = new StringBuilder();
StringBuilder closure = new StringBuilder();
StringBuilder finished = new StringBuilder();
for (Enumeration e = this.cState.getState().items().all(); e.hasMoreElements(); ) {
builder.append(((lalr_item)e.nextElement()).toString().replace("(*)", "\u2022"));
builder.append("\n");
lalr_item item = (lalr_item)e.nextElement();
if(item.dot_pos() == 0){
// Dot at the very beginning => Item from the closure
closure.append(item.toString().replace("(*)", "\u2022"));
closure.append("\n");
}
else if(item.dot_at_end()){
finished.append(item.toString().replace("(*)", "\u2022"));
finished.append("\n");
}
else {
core.append(item.toString().replace("(*)", "\u2022"));
core.append("\n");
}
}
List<lalr_transition> goneTransitions = new LinkedList<lalr_transition>();
CupConflictState current = cState;
while(current.getPredecessor()!=null) {
current = current.getPredecessor();
goneTransitions.add(current.getTransition());
}
Collections.reverse(goneTransitions);
// builder.append("Actual gone path:\n");
// for(lalr_transition trans : goneTransitions) {
// builder.append(trans.toString());
// builder.append("\n");
// }
setText(builder.toString());
setText(0,core.toString());
setText(1,closure.toString());
setText(2,finished.toString());
}
show();
}
......
package de.tum.in.www2.cupplugin.widgets;
import org.eclipse.swt.graphics.Point;
import de.tum.in.www2.cupplugin.views.CupGraphBase.CupGraphNode;
public interface ITooltip {
public void fix();
public void unfix();
public boolean isFixed();
public void show();
public void hide();
public boolean isVisible();
public void setLocation(Point target);
public void show(CupGraphNode node);
}
package de.tum.in.www2.cupplugin.widgets;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
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.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public class MultipleTextTooltipBase{
private static final int MARGIN = 3;
private static final int MAX_HEIGHT = 300;
private int offsetLeft;
private ScrolledComposite scrolled;
private Composite internal;
private Shell popup;
private boolean isOpen;
private boolean isVisible;
private Label[] labels;
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) {
correctWindowSize();
popup.setVisible(true);
isVisible = true;
}
}
public void hide() {
if (isVisible) {
popup.setVisible(false);
isVisible = false;
}
}
public boolean isVisible() {
return isVisible;
}
private void correctWindowSize() {
int maxWidth = Display.getCurrent().getPrimaryMonitor().getBounds().width
- 50 - offsetLeft;
// Get the desired size for each label
int desired = 0;
for(Label l : labels){
desired = Math.max(desired, l.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);
}
int width = Math.min(desired, maxWidth) + MARGIN*2;
popup.setSize(width, 10);
Rectangle r = scrolled.getClientArea();
scrolled.setMinSize(labels[0].computeSize(r.width, SWT.DEFAULT));
popup.layout(true, true);
int desiredHeight = 50;
for(Label l: labels){
desiredHeight += l.getBounds().height;
}
popup.setSize(width, Math.min(desiredHeight, MAX_HEIGHT) + MARGIN*2);
popup.layout(true, true);
}
public void setText(int label,String txt) {
labels[label].setText(txt);
correctWindowSize();
scrolled.layout(true, true);
}
public void setLocation(Point p) {
offsetLeft = p.x;
popup.setLocation(p);
}
//FIXME: in order to prevent a new icon in the tray for every popup, use an
// invisible Dialog
public MultipleTextTooltipBase(Display display,int labelCount) {
popup = new Shell(display, SWT.BALLOON);
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);
internal = new Composite(scrolled,SWT.NONE);
scrolled.setContent(internal);
GridLayout gl = new GridLayout();
gl.numColumns = 1;
gl.makeColumnsEqualWidth = false;
internal.setLayout(gl);
labels = new Label[labelCount];
Color background = display.getSystemColor (SWT.COLOR_INFO_BACKGROUND);
for(int i=0;i < labelCount;i++){
labels[i] = new Label(internal, SWT.WRAP);
labels[i].setBackground(background);
labels[i].setForeground(display.getSystemColor (SWT.COLOR_INFO_FOREGROUND));
}
popup.setBackground(background);
internal.setBackground(background);
this.scrolled.setBackground(background);
popup.setSize(10, 10);
}
}
......@@ -14,7 +14,7 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
public abstract class TooltipBase {
public abstract class TooltipBase implements ITooltip{
private static final int MARGIN = 3;
private static final int MAX_HEIGHT = 300;
......
Supports Markdown
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