001: package visualdebugger.draw2d;
002:
003: import org.eclipse.draw2d.*;
004: import org.eclipse.draw2d.geometry.Insets;
005: import org.eclipse.jdt.core.ICompilationUnit;
006: import org.eclipse.jdt.core.dom.ASTNode;
007: import org.eclipse.jdt.core.dom.Expression;
008: import org.eclipse.jdt.core.dom.Statement;
009: import org.eclipse.swt.graphics.Color;
010: import org.eclipse.swt.widgets.Display;
011:
012: import de.uka.ilkd.key.visualdebugger.VisualDebugger;
013: import de.uka.ilkd.key.visualdebugger.executiontree.ETNode;
014: import de.uka.ilkd.key.visualdebugger.executiontree.ETStatementNode;
015:
016: public class SourceElementFigure extends Figure {
017:
018: private boolean selected;
019:
020: static final Color gradient1 = new Color(null, 232, 232, 240);
021:
022: static final Color gradient2 = new Color(null, 176, 184, 216);
023:
024: static final Color gradient12 = new Color(null, 236, 152, 188);
025:
026: static final Color gradient22 = new Color(null, 236, 196, 213);
027:
028: static final Color corner1 = new Color(null, 200, 208, 223);
029:
030: static final Color corner2 = new Color(null, 160, 172, 200);
031:
032: static final Color blue = new Color(null, 152, 168, 200);
033:
034: static final Color shadow = new Color(null, 202, 202, 202);
035:
036: static final int CORNER_SIZE = 00;
037:
038: ETNode etNode = null;
039:
040: final ETStatementNode sNode;
041:
042: Statement statement;
043:
044: Expression expression;
045:
046: ICompilationUnit unit;
047:
048: // static final Border BORDER = new CompoundBorder(new FoldedPageBorder(),
049: // new MarginBorder(4, 4, 8, 3));
050: static final Border BORDER = new LineBorder(ColorConstants.black, 1);
051:
052: static final Border BREAKMODEBORDER = new LineBorder(
053: ColorConstants.red, 2);
054:
055: static final Border ROUNDEDBORDER = new RoundedBorder(
056: ColorConstants.black, 1);
057:
058: public static class RoundedBorder extends LineBorder {
059:
060: public RoundedBorder(Color color, int width) {
061: super (color, width);
062: }
063:
064: public void paint(IFigure figure, Graphics graphics,
065: Insets insets) {
066: tempRect.setBounds(getPaintRectangle(figure, insets));
067: if (getWidth() % 2 == 1) {
068: tempRect.width--;
069: tempRect.height--;
070: }
071: tempRect.shrink(getWidth() / 2, getWidth() / 2);
072: graphics.setLineWidth(getWidth());
073: if (getColor() != null)
074: graphics.setForegroundColor(getColor());
075: graphics.drawRoundRectangle(tempRect, 12, 12);
076: }
077: }
078:
079: private Label label = new Label();
080:
081: public SourceElementFigure(String text) {
082: this ();
083: if (text.length() > 20)
084: text = text.substring(0, 20);
085: label.setFont(Display.getCurrent().getSystemFont());
086: label.setText(text);
087: }
088:
089: public SourceElementFigure() {
090: setBorder(BORDER);
091: setLayoutManager(new StackLayout());
092: add(label);
093: sNode = null;
094: statement = null;
095: unit = null;
096: }
097:
098: public SourceElementFigure(ETStatementNode etNode) {
099: // this();
100:
101: setLayoutManager(new StackLayout());
102: add(label);
103: String labelText = "";
104: String st = "";
105: boolean breakpoint = false;
106: // if (etNode.getStatementId()!=null){
107: if (etNode.getStatementId().isStatement()) {
108:
109: if (VisualDebugger.getVisualDebugger().getBpManager()
110: .suspendByBreakpoint(etNode.getStatementId())) {
111: breakpoint = true;
112: setBorder(BREAKMODEBORDER);
113: } else
114: setBorder(BORDER);
115: statement = (Statement) visualdebugger.Activator
116: .getDefault().getASTNodeForStatementId(
117: etNode.getStatementId());
118:
119: unit = visualdebugger.Activator.getDefault()
120: .getCompilationUnit(etNode.getStatementId());
121: st = statement.toString();
122: } else {
123: expression = visualdebugger.Activator.getDefault()
124: .getExpression(etNode.getStatementId());
125: setBorder(ROUNDEDBORDER);
126: unit = visualdebugger.Activator.getDefault()
127: .getCompilationUnit(etNode.getStatementId());
128: st = expression.toString();
129: }
130:
131: labelText = st;
132: int i = st.indexOf("\n");
133: if (i > -1)
134: labelText = st.substring(0, i);
135: label.setText(labelText);
136: // }
137:
138: sNode = etNode;
139: if (breakpoint)
140: st = "Statement Breakpoint is reached...\n" + st;
141: this .setToolTip(new Label(st));
142: }
143:
144: /**
145: * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
146: */
147: protected void paintFigure(Graphics g) {
148: super .paintFigure(g);
149: if (selected) {
150: g.setForegroundColor(ColorConstants.menuBackgroundSelected);
151: g.setBackgroundColor(ColorConstants.titleGradient);
152: } else {
153: if (statement != null || label.getText().equals("Start")) {
154: g.setForegroundColor(gradient1);
155: g.setBackgroundColor(gradient2);
156: } else {
157: g.setForegroundColor(gradient12);
158: g.setBackgroundColor(gradient22);
159:
160: }
161: }
162: g.fillGradient(getBounds().getResized(-1, -1), true);
163:
164: }
165:
166: public void setSelected(boolean value) {
167: this .selected = value;
168: if (selected)
169: label.setForegroundColor(ColorConstants.white);
170: else
171: label.setForegroundColor(null);
172: repaint();
173: }
174:
175: /**
176: * @see java.lang.Object#toString()
177: */
178: public String toString() {
179: // return ((Label) getChildren().get(0)).getText();
180: if (getETNode() != null)
181: if (getETNode().getITNodesArray()[0] != null)
182: return getETNode().getITNodesArray()[0].getId() + "";
183:
184: return "nullds";
185: }
186:
187: public void validate() {
188: repaint();
189: super .validate();
190: }
191:
192: public ETNode getETNode() {
193: return sNode;
194: }
195:
196: public Statement getStatement() {
197: return statement;
198: }
199:
200: public ICompilationUnit getUnit() {
201: return unit;
202: }
203:
204: public ASTNode getASTNode() {
205: if (statement != null)
206: return statement;
207: else
208: return expression;
209: }
210:
211: }
|