Merge lp:~danilovesky/workcraft/trunk-bug-1288772 into lp:workcraft
- trunk-bug-1288772
- Merge into trunk
Proposed by
Danil Sokolov
Status: | Merged |
---|---|
Merged at revision: | 497 |
Proposed branch: | lp:~danilovesky/workcraft/trunk-bug-1288772 |
Merge into: | lp:workcraft |
Diff against target: |
1050 lines (+311/-258) 16 files modified
CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuitComponent.java (+5/-20) CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionContact.java (+2/-3) CpogsPlugin/src/org/workcraft/plugins/cpog/RenderedFormula.java (+77/-0) CpogsPlugin/src/org/workcraft/plugins/cpog/VisualArc.java (+3/-2) CpogsPlugin/src/org/workcraft/plugins/cpog/VisualRhoClause.java (+2/-2) CpogsPlugin/src/org/workcraft/plugins/cpog/VisualScenario.java (+28/-36) CpogsPlugin/src/org/workcraft/plugins/cpog/VisualVariable.java (+69/-80) CpogsPlugin/src/org/workcraft/plugins/cpog/VisualVertex.java (+49/-67) CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/booleanvisitors/FormulaRenderingResult.java (+1/-4) SONPlugin/src/org/workcraft/plugins/son/elements/VisualCondition.java (+13/-3) STGPlugin/src/org/workcraft/plugins/stg/VisualNamedTransition.java (+12/-7) WorkcraftCore/src/org/workcraft/dom/visual/Positioning.java (+8/-8) WorkcraftCore/src/org/workcraft/dom/visual/RenderedText.java (+14/-9) WorkcraftCore/src/org/workcraft/dom/visual/VisualComment.java (+4/-4) WorkcraftCore/src/org/workcraft/dom/visual/VisualComponent.java (+23/-12) WorkcraftCore/src/org/workcraft/dom/visual/VisualTransformableNode.java (+1/-1) |
To merge this branch: | bzr merge lp:~danilovesky/workcraft/trunk-bug-1288772 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Danil Sokolov | Approve | ||
Review via email:
|
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Danil Sokolov (danilovesky) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuitComponent.java' |
2 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuitComponent.java 2014-01-15 13:37:34 +0000 |
3 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualCircuitComponent.java 2014-04-09 17:15:15 +0000 |
4 | @@ -414,27 +414,12 @@ |
5 | } |
6 | |
7 | @Override |
8 | - public double getLabelOffset() { |
9 | - double result = size / 2; |
10 | - if (totalBB != null) { |
11 | - switch (getLabelPositioning()) { |
12 | - case CENTER: |
13 | - result = 0.0; |
14 | - break; |
15 | - case TOP: |
16 | - case BOTTOM: |
17 | - result = totalBB.getHeight() / 2; |
18 | - break; |
19 | - case LEFT: |
20 | - case RIGHT: |
21 | - result = totalBB.getWidth() / 2; |
22 | - break; |
23 | - default: |
24 | - result = Math.min(totalBB.getHeight(), totalBB.getWidth()) / 2; |
25 | - } |
26 | + public Rectangle2D getInternalBoundingBoxInLocalSpace() { |
27 | + if (groupImpl == null) { |
28 | + return super.getInternalBoundingBoxInLocalSpace(); |
29 | } |
30 | - return result; |
31 | - } |
32 | + return BoundingBoxHelper.union(totalBB, BoundingBoxHelper.mergeBoundingBoxes(Hierarchy.getChildrenOfType(this, Touchable.class))); |
33 | + } |
34 | |
35 | @Override |
36 | public void draw(DrawRequest r) { |
37 | |
38 | === modified file 'CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionContact.java' |
39 | --- CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionContact.java 2014-01-15 14:11:43 +0000 |
40 | +++ CircuitPlugin/src/org/workcraft/plugins/circuit/VisualFunctionContact.java 2014-04-09 17:15:15 +0000 |
41 | @@ -224,11 +224,11 @@ |
42 | g.draw(line); |
43 | } |
44 | g.translate(textX, textY); |
45 | - result.draw(g, foreground); |
46 | + g.setColor(foreground); |
47 | + result.draw(g); |
48 | g.setTransform(transform); |
49 | } |
50 | |
51 | - |
52 | @Override |
53 | public void draw(DrawRequest r) { |
54 | Graphics2D g = r.getGraphics(); |
55 | @@ -257,7 +257,6 @@ |
56 | super.draw(r); |
57 | } |
58 | |
59 | - |
60 | @Override |
61 | public void notify(StateEvent e) { |
62 | // renderedFormula = null; |
63 | |
64 | === added file 'CpogsPlugin/src/org/workcraft/plugins/cpog/RenderedFormula.java' |
65 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/RenderedFormula.java 1970-01-01 00:00:00 +0000 |
66 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/RenderedFormula.java 2014-04-09 17:15:15 +0000 |
67 | @@ -0,0 +1,77 @@ |
68 | +package org.workcraft.plugins.cpog; |
69 | + |
70 | +import java.awt.Font; |
71 | +import java.awt.Graphics2D; |
72 | +import java.awt.font.FontRenderContext; |
73 | +import java.awt.geom.AffineTransform; |
74 | +import java.awt.geom.Point2D; |
75 | +import java.awt.geom.Rectangle2D; |
76 | + |
77 | +import org.workcraft.dom.visual.BoundingBoxHelper; |
78 | +import org.workcraft.dom.visual.Positioning; |
79 | +import org.workcraft.dom.visual.Touchable; |
80 | +import org.workcraft.plugins.cpog.optimisation.BooleanFormula; |
81 | +import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaRenderingResult; |
82 | +import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToGraphics; |
83 | +import org.workcraft.plugins.cpog.optimisation.expressions.One; |
84 | + |
85 | +public class RenderedFormula implements Touchable { |
86 | + final public String text; |
87 | + final public BooleanFormula formula; |
88 | + final public Font font; |
89 | + final public Positioning positioning; |
90 | + final public double xOffset; |
91 | + final public double yOffset; |
92 | + final private FormulaRenderingResult renderingResult; |
93 | + private Rectangle2D boundingBox; |
94 | + |
95 | + public RenderedFormula(String text, BooleanFormula formula, Font font, Positioning positioning, Point2D offset) { |
96 | + this.text = text; |
97 | + this.formula = formula; |
98 | + this.font = font; |
99 | + this.positioning = positioning; |
100 | + this.xOffset = offset.getX(); |
101 | + this.yOffset = offset.getY(); |
102 | + final FontRenderContext context = new FontRenderContext(AffineTransform.getScaleInstance(1000, 1000), true, true); |
103 | + renderingResult = FormulaToGraphics.print(text, font, context); |
104 | + if (formula != One.instance()) { |
105 | + renderingResult.add(FormulaToGraphics.render(formula, context, font)); |
106 | + } |
107 | + Rectangle2D bb = renderingResult.boundingBox; |
108 | + double x = offset.getX() + positioning.xOffset + 0.5 * positioning.xSign * bb.getWidth(); |
109 | + double y = offset.getY() + 0.5 * positioning.ySign * bb.getHeight(); |
110 | + boundingBox = BoundingBoxHelper.move(bb, x - bb.getCenterX(), y - bb.getCenterY()); |
111 | + } |
112 | + |
113 | + public boolean isDifferent(String text, BooleanFormula formula, Font font, Positioning positioning, Point2D offset) { |
114 | + if (text == null) { |
115 | + text = ""; |
116 | + } |
117 | + return (!text.equals(this.text) || !formula.equals(this.formula) || !font.equals(this.font) |
118 | + || positioning != this.positioning || offset.getX() != this.xOffset || offset.getY() != this.yOffset); |
119 | + } |
120 | + |
121 | + public void draw (Graphics2D g) { |
122 | + g.setFont(font); |
123 | + AffineTransform oldTransform = g.getTransform(); |
124 | + g.translate(boundingBox.getX(), boundingBox.getCenterY()); |
125 | + renderingResult.draw(g); |
126 | + g.setTransform(oldTransform); |
127 | + } |
128 | + |
129 | + @Override |
130 | + public boolean hitTest(Point2D point) { |
131 | + return boundingBox.contains(point); |
132 | + } |
133 | + |
134 | + @Override |
135 | + public Rectangle2D getBoundingBox() { |
136 | + return boundingBox; |
137 | + } |
138 | + |
139 | + @Override |
140 | + public Point2D getCenter() { |
141 | + return new Point2D.Double(boundingBox.getCenterX(), boundingBox.getCenterY()); |
142 | + } |
143 | + |
144 | +} |
145 | |
146 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/VisualArc.java' |
147 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/VisualArc.java 2010-10-19 20:13:26 +0000 |
148 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/VisualArc.java 2014-04-09 17:15:15 +0000 |
149 | @@ -171,8 +171,9 @@ |
150 | AffineTransform transform = AffineTransform.getTranslateInstance(p.getX() - labelPosition.getX(), p.getY() - labelPosition.getY()); |
151 | transform.concatenate(AffineTransform.getRotateInstance(d.getX(), d.getY(), labelPosition.getX(), labelPosition.getY())); |
152 | |
153 | - g.transform(transform); |
154 | - result.draw(g, Coloriser.colorise(Color.BLACK, r.getDecoration().getColorisation())); |
155 | + g.transform(transform); |
156 | + g.setColor(Coloriser.colorise(Color.BLACK, r.getDecoration().getColorisation())); |
157 | + result.draw(g); |
158 | g.setTransform(oldTransform); |
159 | |
160 | labelBB = BoundingBoxHelper.transform(labelBB, transform); |
161 | |
162 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/VisualRhoClause.java' |
163 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/VisualRhoClause.java 2014-01-02 14:47:00 +0000 |
164 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/VisualRhoClause.java 2014-04-09 17:15:15 +0000 |
165 | @@ -98,8 +98,8 @@ |
166 | |
167 | AffineTransform transform = g.getTransform(); |
168 | g.translate(textX, textY); |
169 | - |
170 | - result.draw(g, Coloriser.colorise(getColor(), colorisation)); |
171 | + g.setColor(Coloriser.colorise(getColor(), colorisation)); |
172 | + result.draw(g); |
173 | |
174 | g.setTransform(transform); |
175 | } |
176 | |
177 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/VisualScenario.java' |
178 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/VisualScenario.java 2013-12-27 12:29:16 +0000 |
179 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/VisualScenario.java 2014-04-09 17:15:15 +0000 |
180 | @@ -62,7 +62,6 @@ |
181 | e.printStackTrace(); |
182 | } |
183 | } |
184 | - |
185 | |
186 | public VisualScenario() { |
187 | addPropertyDeclaration(new PropertyDeclaration<VisualScenario, String>( |
188 | @@ -87,17 +86,17 @@ |
189 | } |
190 | |
191 | @Override |
192 | - public Rectangle2D getBoundingBoxInLocalSpace() |
193 | - { |
194 | + public Rectangle2D getBoundingBoxInLocalSpace() { |
195 | Rectangle2D bb = getContentsBoundingBox(); |
196 | |
197 | // Increase bb by the label height (to include the latter into the bb) |
198 | - if(labelBB != null) |
199 | + if(labelBB != null) { |
200 | bb.add(bb.getMinX(), bb.getMinY() - labelBB.getHeight()); |
201 | - |
202 | + } |
203 | // Increase bb by the encoding height (to include the latter into the bb) |
204 | - if(encodingBB != null) |
205 | + if(encodingBB != null) { |
206 | bb.add(bb.getMinX(), bb.getMaxY() + encodingBB.getHeight()); |
207 | + } |
208 | |
209 | return bb; |
210 | } |
211 | @@ -105,15 +104,15 @@ |
212 | private Rectangle2D getContentsBoundingBox() { |
213 | Rectangle2D bb = null; |
214 | |
215 | - for(VisualVertex v : Hierarchy.getChildrenOfType(this, VisualVertex.class)) |
216 | - bb = BoundingBoxHelper.union(bb, v.getBoundingBox()); |
217 | - |
218 | - for(VisualVariable v : Hierarchy.getChildrenOfType(this, VisualVariable.class)) |
219 | - bb = BoundingBoxHelper.union(bb, v.getBoundingBox()); |
220 | - |
221 | - for(VisualArc a : Hierarchy.getChildrenOfType(this, VisualArc.class)) |
222 | + for(VisualVertex v : Hierarchy.getChildrenOfType(this, VisualVertex.class)) { |
223 | + bb = BoundingBoxHelper.union(bb, v.getBoundingBox()); |
224 | + } |
225 | + for(VisualVariable v : Hierarchy.getChildrenOfType(this, VisualVariable.class)) { |
226 | + bb = BoundingBoxHelper.union(bb, v.getBoundingBox()); |
227 | + } |
228 | + for(VisualArc a : Hierarchy.getChildrenOfType(this, VisualArc.class)) { |
229 | bb = BoundingBoxHelper.union(bb, a.getLabelBoundingBox()); |
230 | - |
231 | + } |
232 | if (bb == null) bb = contentsBB; |
233 | else |
234 | bb.setRect(bb.getMinX() - frameDepth, bb.getMinY() - frameDepth, |
235 | @@ -127,8 +126,7 @@ |
236 | } |
237 | |
238 | @Override |
239 | - public void draw(DrawRequest r) |
240 | - { |
241 | + public void draw(DrawRequest r) { |
242 | Graphics2D g = r.getGraphics(); |
243 | Color colorisation = r.getDecoration().getColorisation(); |
244 | Color background = r.getDecoration().getBackground(); |
245 | @@ -159,8 +157,8 @@ |
246 | |
247 | AffineTransform transform = g.getTransform(); |
248 | g.translate(labelPosition.getX(), labelPosition.getY()); |
249 | - |
250 | - result.draw(g, Coloriser.colorise(Color.BLACK, colorisation)); |
251 | + g.setColor(Coloriser.colorise(Color.BLACK, colorisation)); |
252 | + result.draw(g); |
253 | |
254 | g.setTransform(transform); |
255 | |
256 | @@ -209,8 +207,8 @@ |
257 | |
258 | transform = g.getTransform(); |
259 | g.translate(labelPosition.getX(), labelPosition.getY()); |
260 | - |
261 | - result.draw(g, Coloriser.colorise(Color.BLACK, colorisation)); |
262 | + g.setColor(Coloriser.colorise(Color.BLACK, colorisation)); |
263 | + result.draw(g); |
264 | |
265 | g.setTransform(transform); |
266 | |
267 | @@ -242,8 +240,8 @@ |
268 | Color color = Color.BLACK; |
269 | if (!var.getState().matches(encoding.getState(var))) color = Color.RED; |
270 | if (perfectMatch) color = Color.GREEN; |
271 | - |
272 | - result.draw(g, Coloriser.colorise(color, colorisation)); |
273 | + g.setColor(Coloriser.colorise(color, colorisation)); |
274 | + result.draw(g); |
275 | |
276 | g.setTransform(transform); |
277 | |
278 | @@ -254,19 +252,17 @@ |
279 | } |
280 | } |
281 | |
282 | - public Variable getVariableAt(Point2D p) |
283 | - { |
284 | + public Variable getVariableAt(Point2D p) { |
285 | Point2D q = new Point2D.Double(); |
286 | getParentToLocalTransform().transform(p, q); |
287 | - for(Rectangle2D rect : variableBBs.keySet()) |
288 | + for(Rectangle2D rect : variableBBs.keySet()) { |
289 | if (rect.contains(q)) return variableBBs.get(rect); |
290 | - |
291 | + } |
292 | return null; |
293 | } |
294 | |
295 | @Override |
296 | - public boolean hitTestInLocalSpace(Point2D p) |
297 | - { |
298 | + public boolean hitTestInLocalSpace(Point2D p) { |
299 | return |
300 | getContentsBoundingBox().contains(p) || |
301 | getLabelBB().contains(p) || |
302 | @@ -278,25 +274,21 @@ |
303 | return new Rectangle2D.Double(bb.getMaxX() - labelBB.getWidth(), bb.getMinY() - labelBB.getHeight(), labelBB.getWidth(), labelBB.getHeight()); |
304 | } |
305 | |
306 | - public void setLabel(String label) |
307 | - { |
308 | + public void setLabel(String label) { |
309 | this.label = label; |
310 | sendNotification(new PropertyChangedEvent(this, "label")); |
311 | } |
312 | |
313 | - public String getLabel() |
314 | - { |
315 | + public String getLabel() { |
316 | return label; |
317 | } |
318 | |
319 | - public void setEncoding(Encoding encoding) |
320 | - { |
321 | + public void setEncoding(Encoding encoding) { |
322 | this.encoding = encoding; |
323 | sendNotification(new PropertyChangedEvent(this, "encoding")); |
324 | } |
325 | |
326 | - public Encoding getEncoding() |
327 | - { |
328 | + public Encoding getEncoding() { |
329 | return encoding; |
330 | } |
331 | } |
332 | |
333 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/VisualVariable.java' |
334 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/VisualVariable.java 2014-04-08 12:03:26 +0000 |
335 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/VisualVariable.java 2014-04-09 17:15:15 +0000 |
336 | @@ -28,7 +28,6 @@ |
337 | import java.awt.Graphics2D; |
338 | import java.awt.Shape; |
339 | import java.awt.event.KeyEvent; |
340 | -import java.awt.geom.AffineTransform; |
341 | import java.awt.geom.Point2D; |
342 | import java.awt.geom.Rectangle2D; |
343 | import java.io.IOException; |
344 | @@ -37,29 +36,36 @@ |
345 | import org.workcraft.annotations.SVGIcon; |
346 | import org.workcraft.dom.visual.BoundingBoxHelper; |
347 | import org.workcraft.dom.visual.DrawRequest; |
348 | +import org.workcraft.dom.visual.Positioning; |
349 | import org.workcraft.dom.visual.VisualComponent; |
350 | import org.workcraft.gui.Coloriser; |
351 | +import org.workcraft.gui.graph.tools.Decoration; |
352 | import org.workcraft.gui.propertyeditor.PropertyDeclaration; |
353 | import org.workcraft.observation.PropertyChangedEvent; |
354 | -import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaRenderingResult; |
355 | -import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToGraphics; |
356 | +import org.workcraft.plugins.cpog.optimisation.expressions.One; |
357 | import org.workcraft.serialisation.xml.NoAutoSerialisation; |
358 | |
359 | @Hotkey(KeyEvent.VK_X) |
360 | @SVGIcon("images/icons/svg/variable.svg") |
361 | -public class VisualVariable extends VisualComponent |
362 | -{ |
363 | - private final static double size = 1.0; |
364 | - private final static float strokeWidth = 0.08f; |
365 | +public class VisualVariable extends VisualComponent { |
366 | + private static Font variableFont; |
367 | private static Font valueFont; |
368 | - private static Font labelFont; |
369 | - private Point2D labelPosition = null; |
370 | - private Rectangle2D labelBoundingBox = null; |
371 | - |
372 | + |
373 | + private final RenderedFormula valueFalseRenderedFormula = new RenderedFormula( |
374 | + VariableState.FALSE.toString(), One.instance(), valueFont, Positioning.CENTER, new Point2D.Double(0.0, 0.2)); |
375 | + |
376 | + private final RenderedFormula valueTrueRenderedFormula = new RenderedFormula( |
377 | + VariableState.TRUE.toString(), One.instance(), valueFont, Positioning.CENTER, new Point2D.Double(0.0, 0.2)); |
378 | + |
379 | + private final RenderedFormula valueUndefinedRenderedFormula = new RenderedFormula( |
380 | + VariableState.UNDEFINED.toString(), One.instance(), valueFont, Positioning.CENTER, new Point2D.Double(0.0, 0.2)); |
381 | + |
382 | + private RenderedFormula variableRenderedFormula = new RenderedFormula("", One.instance(), variableFont, getLabelPositioning(), getLabelOffset()); |
383 | + |
384 | static { |
385 | try { |
386 | Font font = Font.createFont(Font.TYPE1_FONT, ClassLoader.getSystemResourceAsStream("fonts/eurm10.pfb")); |
387 | - labelFont = font.deriveFont(0.5f); |
388 | + variableFont = font.deriveFont(0.5f); |
389 | valueFont = font.deriveFont(0.75f); |
390 | } catch (FontFormatException e) { |
391 | e.printStackTrace(); |
392 | @@ -68,10 +74,8 @@ |
393 | } |
394 | } |
395 | |
396 | - public VisualVariable(Variable variable) |
397 | - { |
398 | + public VisualVariable(Variable variable) { |
399 | super(variable); |
400 | - |
401 | addPropertyDeclaration(new PropertyDeclaration<VisualVariable, VariableState>( |
402 | this, "State", VariableState.class, VariableState.getChoice()) { |
403 | public void setter(VisualVariable object, VariableState value) { |
404 | @@ -84,8 +88,7 @@ |
405 | } |
406 | |
407 | @Override |
408 | - public void draw(DrawRequest r) |
409 | - { |
410 | + public void draw(DrawRequest r) { |
411 | Graphics2D g = r.getGraphics(); |
412 | Color colorisation = r.getDecoration().getColorisation(); |
413 | Color background = r.getDecoration().getBackground(); |
414 | @@ -93,95 +96,81 @@ |
415 | Shape shape = new Rectangle2D.Double(-size / 2 + strokeWidth / 2, -size / 2 + strokeWidth / 2, |
416 | size - strokeWidth, size - strokeWidth); |
417 | |
418 | - g.setStroke(new BasicStroke(strokeWidth)); |
419 | + g.setStroke(new BasicStroke((float)strokeWidth)); |
420 | g.setColor(Coloriser.colorise(getFillColor(), background)); |
421 | g.fill(shape); |
422 | g.setColor(Coloriser.colorise(getForegroundColor(), colorisation)); |
423 | g.draw(shape); |
424 | - |
425 | - String text = getState().toString(); |
426 | - FormulaRenderingResult result = FormulaToGraphics.print(text, valueFont, g.getFontRenderContext()); |
427 | - Rectangle2D textBB = result.boundingBox; |
428 | - |
429 | - float textX = (float)-textBB.getCenterX(); |
430 | - float textY = (float)-textBB.getCenterY() + 0.1f; |
431 | - if (getState() == VariableState.UNDEFINED) { |
432 | - // FIXMI: A hack to draw "?" symbol a bit higher, otherwise it shows too low, not sure why) |
433 | - textY -= 0.3f; |
434 | - } |
435 | - |
436 | - AffineTransform transform = g.getTransform(); |
437 | - g.translate(textX, textY); |
438 | - result.draw(g, Coloriser.colorise(getForegroundColor(), colorisation)); |
439 | - g.setTransform(transform); |
440 | - drawLabelInLocalSpace(r); |
441 | + |
442 | + g.setColor(Coloriser.colorise(getForegroundColor(), colorisation)); |
443 | + switch (getState()) { |
444 | + case FALSE: |
445 | + valueFalseRenderedFormula.draw(g); |
446 | + break; |
447 | + case TRUE: |
448 | + valueTrueRenderedFormula.draw(g); |
449 | + break; |
450 | + case UNDEFINED: |
451 | + valueUndefinedRenderedFormula.draw(g); |
452 | + break; |
453 | + default: |
454 | + break; |
455 | + } |
456 | + drawVariableInLocalSpace(r); |
457 | + } |
458 | + |
459 | + |
460 | + protected void cacheVariableRenderedFormula(DrawRequest r) { |
461 | + if (variableRenderedFormula.isDifferent(getLabel(), One.instance(), variableFont, getLabelPositioning(), getLabelOffset())) { |
462 | + variableRenderedFormula = new RenderedFormula(getLabel(), One.instance(), variableFont, getLabelPositioning(), getLabelOffset()); |
463 | + } |
464 | + } |
465 | + |
466 | + protected void drawVariableInLocalSpace(DrawRequest r) { |
467 | + if (getLabelVisibility()) { |
468 | + Graphics2D g = r.getGraphics(); |
469 | + Decoration d = r.getDecoration(); |
470 | + cacheVariableRenderedFormula(r); |
471 | + g.setColor(Coloriser.colorise(getLabelColor(), d.getColorisation())); |
472 | + variableRenderedFormula.draw(g); |
473 | + } |
474 | } |
475 | |
476 | @NoAutoSerialisation |
477 | @Override |
478 | - public String getLabel() |
479 | - { |
480 | + public String getLabel() { |
481 | return getMathVariable().getLabel(); |
482 | } |
483 | |
484 | @NoAutoSerialisation |
485 | @Override |
486 | - public void setLabel(String label) |
487 | - { |
488 | + public void setLabel(String label) { |
489 | getMathVariable().setLabel(label); |
490 | sendNotification(new PropertyChangedEvent(this, "label")); |
491 | } |
492 | |
493 | - protected void drawLabelInLocalSpace(DrawRequest r) |
494 | - { |
495 | - Graphics2D g = r.getGraphics(); |
496 | - Color colorisation = r.getDecoration().getColorisation(); |
497 | - Rectangle2D bb = new Rectangle2D.Double(-size / 2, -size / 2, size, size); |
498 | - |
499 | - FormulaRenderingResult result = FormulaToGraphics.print(getLabel(), labelFont, g.getFontRenderContext()); |
500 | - Rectangle2D gbb = result.boundingBox; |
501 | - |
502 | - labelPosition = new Point2D.Double( |
503 | - bb.getCenterX() - gbb.getCenterX() + 0.5 * getLabelPositioning().xOffset * (bb.getWidth() + gbb.getWidth() + 0.2), |
504 | - bb.getCenterY() - gbb.getCenterY() + 0.5 * getLabelPositioning().yOffset * (bb.getHeight() + gbb.getHeight() + 0.2)); |
505 | - labelBoundingBox = new Rectangle2D.Double(gbb.getX() + labelPosition.getX(), gbb.getY() + labelPosition.getY(), |
506 | - gbb.getWidth(), gbb.getHeight()); |
507 | - |
508 | - AffineTransform oldTransform = g.getTransform(); |
509 | - g.translate(labelPosition.getX(), labelPosition.getY()); |
510 | - result.draw(g, Coloriser.colorise(getLabelColor(), colorisation)); |
511 | - g.setTransform(oldTransform); |
512 | - } |
513 | - |
514 | - public Rectangle2D getBoundingBoxInLocalSpace() |
515 | - { |
516 | - Rectangle2D bb = new Rectangle2D.Double(-size / 2, -size / 2, size, size); |
517 | - return BoundingBoxHelper.union(bb, labelBoundingBox); |
518 | - } |
519 | - |
520 | - public boolean hitTestInLocalSpace(Point2D pointInLocalSpace) |
521 | - { |
522 | - if (labelBoundingBox != null && labelBoundingBox.contains(pointInLocalSpace)) return true; |
523 | - return Math.abs(pointInLocalSpace.getX()) <= size / 2 && Math.abs(pointInLocalSpace.getY()) <= size / 2; |
524 | - } |
525 | - |
526 | - public Variable getMathVariable() |
527 | - { |
528 | + @Override |
529 | + public Rectangle2D getBoundingBoxInLocalSpace() { |
530 | + Rectangle2D bb = super.getBoundingBoxInLocalSpace(); |
531 | + if (getLabelVisibility()) { |
532 | + bb = BoundingBoxHelper.union(bb, variableRenderedFormula.getBoundingBox()); |
533 | + } |
534 | + return bb; |
535 | + } |
536 | + |
537 | + public Variable getMathVariable() { |
538 | return (Variable)getReferencedComponent(); |
539 | } |
540 | |
541 | - public VariableState getState() |
542 | - { |
543 | + public VariableState getState() { |
544 | return getMathVariable().getState(); |
545 | } |
546 | |
547 | - public void setState(VariableState state) |
548 | - { |
549 | + public void setState(VariableState state) { |
550 | getMathVariable().setState(state); |
551 | } |
552 | |
553 | - public void toggle() |
554 | - { |
555 | + public void toggle() { |
556 | setState(getState().toggle()); |
557 | } |
558 | |
559 | |
560 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/VisualVertex.java' |
561 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/VisualVertex.java 2013-10-21 17:36:57 +0000 |
562 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/VisualVertex.java 2014-04-09 17:15:15 +0000 |
563 | @@ -28,9 +28,7 @@ |
564 | import java.awt.Graphics2D; |
565 | import java.awt.Shape; |
566 | import java.awt.event.KeyEvent; |
567 | -import java.awt.geom.AffineTransform; |
568 | import java.awt.geom.Ellipse2D; |
569 | -import java.awt.geom.Point2D; |
570 | import java.awt.geom.Rectangle2D; |
571 | import java.io.IOException; |
572 | import java.util.HashMap; |
573 | @@ -41,31 +39,26 @@ |
574 | import org.workcraft.dom.visual.DrawRequest; |
575 | import org.workcraft.dom.visual.VisualComponent; |
576 | import org.workcraft.gui.Coloriser; |
577 | +import org.workcraft.gui.graph.tools.Decoration; |
578 | import org.workcraft.observation.PropertyChangedEvent; |
579 | import org.workcraft.plugins.cpog.expressions.CpogFormulaVariable; |
580 | import org.workcraft.plugins.cpog.expressions.CpogVisitor; |
581 | import org.workcraft.plugins.cpog.optimisation.BooleanFormula; |
582 | import org.workcraft.plugins.cpog.optimisation.BooleanVariable; |
583 | import org.workcraft.plugins.cpog.optimisation.booleanvisitors.BooleanReplacer; |
584 | -import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaRenderingResult; |
585 | -import org.workcraft.plugins.cpog.optimisation.booleanvisitors.FormulaToGraphics; |
586 | import org.workcraft.plugins.cpog.optimisation.expressions.One; |
587 | import org.workcraft.plugins.cpog.optimisation.expressions.Zero; |
588 | |
589 | @Hotkey(KeyEvent.VK_V) |
590 | @SVGIcon("images/icons/svg/vertex.svg") |
591 | -public class VisualVertex extends VisualComponent implements CpogFormulaVariable |
592 | -{ |
593 | - private final static double size = 1; |
594 | - private final static float strokeWidth = 0.1f; |
595 | - private static Font labelFont; |
596 | - private Point2D labelPosition = null; |
597 | - private Rectangle2D labelBoundingBox = null; |
598 | +public class VisualVertex extends VisualComponent implements CpogFormulaVariable { |
599 | + public static Font conditionFont; |
600 | + private RenderedFormula conditionRenderedFormula = new RenderedFormula("", One.instance(), conditionFont, getLabelPositioning(), getLabelOffset()); |
601 | |
602 | static { |
603 | try { |
604 | Font font = Font.createFont(Font.TYPE1_FONT, ClassLoader.getSystemResourceAsStream("fonts/eurm10.pfb")); |
605 | - labelFont = font.deriveFont(0.5f); |
606 | + conditionFont = font.deriveFont(0.5f); |
607 | } catch (FontFormatException e) { |
608 | e.printStackTrace(); |
609 | } catch (IOException e) { |
610 | @@ -77,83 +70,71 @@ |
611 | super(vertex); |
612 | } |
613 | |
614 | - public void draw(DrawRequest r) |
615 | - { |
616 | + |
617 | + |
618 | + @Override |
619 | + public void draw(DrawRequest r) { |
620 | Graphics2D g = r.getGraphics(); |
621 | Color colorisation = r.getDecoration().getColorisation(); |
622 | Color background = r.getDecoration().getBackground(); |
623 | - |
624 | - Shape shape = new Ellipse2D.Double(-size / 2 + strokeWidth / 2, -size / 2 + strokeWidth / 2, |
625 | + Shape shape = new Ellipse2D.Double( |
626 | + -size / 2 + strokeWidth / 2, -size / 2 + strokeWidth / 2, |
627 | size - strokeWidth, size - strokeWidth); |
628 | |
629 | BooleanFormula value = evaluate(); |
630 | - |
631 | g.setColor(Coloriser.colorise(getFillColor(), background)); |
632 | g.fill(shape); |
633 | - |
634 | g.setColor(Coloriser.colorise(getForegroundColor(), colorisation)); |
635 | - if (value == Zero.instance()) |
636 | - { |
637 | - g.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_BUTT, |
638 | + if (value == Zero.instance()) { |
639 | + g.setStroke(new BasicStroke((float)strokeWidth, BasicStroke.CAP_BUTT, |
640 | BasicStroke.JOIN_MITER, 1.0f, new float[] {0.18f, 0.18f}, 0.00f)); |
641 | - } |
642 | - else |
643 | - { |
644 | - g.setStroke(new BasicStroke(strokeWidth)); |
645 | + } else { |
646 | + g.setStroke(new BasicStroke((float)strokeWidth)); |
647 | if (value != One.instance()) |
648 | g.setColor(Coloriser.colorise(Color.LIGHT_GRAY, colorisation)); |
649 | } |
650 | - |
651 | g.draw(shape); |
652 | - drawLabelInLocalSpace(r); |
653 | + drawConditionInLocalSpace(r); |
654 | } |
655 | - |
656 | - protected void drawLabelInLocalSpace(DrawRequest r) |
657 | - { |
658 | - Graphics2D g = r.getGraphics(); |
659 | - Color colorisation = r.getDecoration().getColorisation(); |
660 | - |
661 | + |
662 | + protected void cacheConditionRenderedFormula(DrawRequest r) { |
663 | String text = getLabel(); |
664 | - if (getCondition() != One.instance()) text += ": "; |
665 | - FormulaRenderingResult result = FormulaToGraphics.print(text, labelFont, g.getFontRenderContext()); |
666 | - if (getCondition() != One.instance()) result.add(FormulaToGraphics.render(getCondition(), g.getFontRenderContext(), labelFont)); |
667 | - |
668 | - Rectangle2D gbb = result.boundingBox; |
669 | - labelPosition = new Point2D.Double( |
670 | - -gbb.getCenterX() + 0.5 * getLabelPositioning().xOffset * (1.0 + gbb.getWidth() + 0.2), |
671 | - -gbb.getCenterY() + 0.5 * getLabelPositioning().yOffset * (1.0 + gbb.getHeight() + 0.2)); |
672 | - labelBoundingBox = new Rectangle2D.Double(gbb.getX() + labelPosition.getX(), gbb.getY() + labelPosition.getY(), |
673 | - gbb.getWidth(), gbb.getHeight()); |
674 | - |
675 | - AffineTransform oldTransform = g.getTransform(); |
676 | - g.translate(labelPosition.getX(), labelPosition.getY()); |
677 | - result.draw(g, Coloriser.colorise(getLabelColor(), colorisation)); |
678 | - g.setTransform(oldTransform); |
679 | - } |
680 | - |
681 | - public Rectangle2D getBoundingBoxInLocalSpace() |
682 | - { |
683 | - Rectangle2D bb = new Rectangle2D.Double(-size / 2, -size / 2, size, size); |
684 | - return BoundingBoxHelper.union(bb, labelBoundingBox); |
685 | - } |
686 | - |
687 | - public boolean hitTestInLocalSpace(Point2D pointInLocalSpace) |
688 | - { |
689 | - return pointInLocalSpace.distanceSq(0, 0) < size * size / 4; |
690 | - } |
691 | - |
692 | - public Vertex getMathVertex() |
693 | - { |
694 | + if (getCondition() != One.instance()) { |
695 | + text += ": "; |
696 | + } |
697 | + if (conditionRenderedFormula.isDifferent(text, getCondition(), conditionFont, getLabelPositioning(), getLabelOffset())) { |
698 | + conditionRenderedFormula = new RenderedFormula(text, getCondition(), conditionFont, getLabelPositioning(), getLabelOffset()); |
699 | + } |
700 | + } |
701 | + |
702 | + protected void drawConditionInLocalSpace(DrawRequest r) { |
703 | + if (getLabelVisibility()) { |
704 | + Graphics2D g = r.getGraphics(); |
705 | + Decoration d = r.getDecoration(); |
706 | + cacheConditionRenderedFormula(r); |
707 | + g.setColor(Coloriser.colorise(getLabelColor(), d.getColorisation())); |
708 | + conditionRenderedFormula.draw(g); |
709 | + } |
710 | + } |
711 | + |
712 | + @Override |
713 | + public Rectangle2D getBoundingBoxInLocalSpace() { |
714 | + Rectangle2D bb = super.getBoundingBoxInLocalSpace(); |
715 | + if (getLabelVisibility()) { |
716 | + bb = BoundingBoxHelper.union(bb, conditionRenderedFormula.getBoundingBox()); |
717 | + } |
718 | + return bb; |
719 | + } |
720 | + |
721 | + public Vertex getMathVertex() { |
722 | return (Vertex) getReferencedComponent(); |
723 | } |
724 | |
725 | - public BooleanFormula getCondition() |
726 | - { |
727 | + public BooleanFormula getCondition() { |
728 | return getMathVertex().getCondition(); |
729 | } |
730 | |
731 | - public void setCondition(BooleanFormula condition) |
732 | - { |
733 | + public void setCondition(BooleanFormula condition) { |
734 | getMathVertex().setCondition(condition); |
735 | sendNotification(new PropertyChangedEvent(this, "condition")); |
736 | } |
737 | @@ -181,4 +162,5 @@ |
738 | public <T> T accept(CpogVisitor<T> visitor) { |
739 | return visitor.visit(this); |
740 | } |
741 | + |
742 | } |
743 | |
744 | === modified file 'CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/booleanvisitors/FormulaRenderingResult.java' |
745 | --- CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/booleanvisitors/FormulaRenderingResult.java 2010-05-01 15:12:53 +0000 |
746 | +++ CpogsPlugin/src/org/workcraft/plugins/cpog/optimisation/booleanvisitors/FormulaRenderingResult.java 2014-04-09 17:15:15 +0000 |
747 | @@ -1,7 +1,6 @@ |
748 | package org.workcraft.plugins.cpog.optimisation.booleanvisitors; |
749 | |
750 | import java.awt.BasicStroke; |
751 | -import java.awt.Color; |
752 | import java.awt.Graphics2D; |
753 | import java.awt.font.GlyphVector; |
754 | import java.awt.geom.Line2D; |
755 | @@ -39,10 +38,8 @@ |
756 | visualTop = Math.min(visualTop, summand.visualTop); |
757 | } |
758 | |
759 | - public void draw(Graphics2D g, Color color) |
760 | + public void draw(Graphics2D g) |
761 | { |
762 | - g.setColor(color); |
763 | - |
764 | int k = 0; |
765 | for(GlyphVector glyph : glyphs) |
766 | { |
767 | |
768 | === modified file 'SONPlugin/src/org/workcraft/plugins/son/elements/VisualCondition.java' |
769 | --- SONPlugin/src/org/workcraft/plugins/son/elements/VisualCondition.java 2014-01-02 14:47:00 +0000 |
770 | +++ SONPlugin/src/org/workcraft/plugins/son/elements/VisualCondition.java 2014-04-09 17:15:15 +0000 |
771 | @@ -32,11 +32,11 @@ |
772 | @DisplayName("Condition") |
773 | @Hotkey(KeyEvent.VK_B) |
774 | @SVGIcon("images/icons/svg/place_empty.svg") |
775 | -public class VisualCondition extends VisualComponent{ |
776 | +public class VisualCondition extends VisualComponent { |
777 | |
778 | private Font errorFont = new Font("Sans-serif", Font.PLAIN, 1).deriveFont(0.45f); |
779 | private Positioning errLabelPositioning = SONSettings.getErrLabelPositioning(); |
780 | - private RenderedText errorRenderedText = new RenderedText("", errorFont, errLabelPositioning, 0.0); |
781 | + private RenderedText errorRenderedText = new RenderedText("", errorFont, errLabelPositioning, getErrLabelOffset()); |
782 | private Color errLabelColor = SONSettings.getErrLabelColor(); |
783 | |
784 | protected static double singleTokenSize = CommonVisualSettings.getBaseSize() / 1.9; |
785 | @@ -123,9 +123,19 @@ |
786 | } |
787 | } |
788 | |
789 | + private Point2D getErrLabelOffset() { |
790 | + Point2D result = getOffset(errLabelPositioning); |
791 | + if (errLabelPositioning.ySign < 0) { |
792 | + result.setLocation(result.getX(), result.getY() - 0.4); |
793 | + } else { |
794 | + result.setLocation(result.getX(), result.getY() + 0.4); |
795 | + } |
796 | + return result; |
797 | + } |
798 | + |
799 | private void cahceErrorRenderedText(DrawRequest r) { |
800 | String error = "Err = "+((Integer)this.getErrors()).toString(); |
801 | - double offset = 0.8 * size; |
802 | + Point2D offset = getErrLabelOffset(); |
803 | if (errorRenderedText.isDifferent(error, labelFont, errLabelPositioning, offset)) { |
804 | errorRenderedText = new RenderedText(error, labelFont, errLabelPositioning, offset); |
805 | } |
806 | |
807 | === modified file 'STGPlugin/src/org/workcraft/plugins/stg/VisualNamedTransition.java' |
808 | --- STGPlugin/src/org/workcraft/plugins/stg/VisualNamedTransition.java 2014-01-07 16:03:24 +0000 |
809 | +++ STGPlugin/src/org/workcraft/plugins/stg/VisualNamedTransition.java 2014-04-09 17:15:15 +0000 |
810 | @@ -41,7 +41,7 @@ |
811 | |
812 | public class VisualNamedTransition extends VisualTransition implements StateObserver { |
813 | public static Font font = new Font("Sans-serif", Font.PLAIN, 1).deriveFont(0.75f); |
814 | - private RenderedText renderedText = new RenderedText("", font, Positioning.CENTER, 0.0); |
815 | + private RenderedText renderedText = new RenderedText("", font, Positioning.CENTER, getRenderedTextOffset()); |
816 | |
817 | public VisualNamedTransition(Transition transition) { |
818 | super(transition, false, false, false); |
819 | @@ -49,14 +49,18 @@ |
820 | updateRenderedText(); |
821 | } |
822 | |
823 | + public Point2D getRenderedTextOffset() { |
824 | + return new Point2D.Double(0.0, 0.0); |
825 | + } |
826 | + |
827 | @Override |
828 | public boolean getLabelVisibility() { |
829 | return false; |
830 | } |
831 | |
832 | @Override |
833 | - public double getLabelOffset() { |
834 | - return 0.0; |
835 | + public Point2D getLabelOffset() { |
836 | + return new Point2D.Double(0.0, 0.0); |
837 | } |
838 | |
839 | @Override |
840 | @@ -65,8 +69,8 @@ |
841 | } |
842 | |
843 | @Override |
844 | - public double getNameOffset() { |
845 | - return 0.0; |
846 | + public Point2D getNameOffset() { |
847 | + return new Point2D.Double(0.0, 0.0); |
848 | } |
849 | |
850 | @Override |
851 | @@ -98,9 +102,10 @@ |
852 | } |
853 | |
854 | protected void updateRenderedText() { |
855 | - if (renderedText.isDifferent(getName(), font, Positioning.CENTER, 0.0)) { |
856 | + Point2D offset = getRenderedTextOffset(); |
857 | + if (renderedText.isDifferent(getName(), font, Positioning.CENTER, offset)) { |
858 | transformChanging(true); |
859 | - renderedText = new RenderedText(getName(), font, Positioning.CENTER, 0.0); |
860 | + renderedText = new RenderedText(getName(), font, Positioning.CENTER, offset); |
861 | transformChanged(true); |
862 | } |
863 | } |
864 | |
865 | === modified file 'WorkcraftCore/src/org/workcraft/dom/visual/Positioning.java' |
866 | --- WorkcraftCore/src/org/workcraft/dom/visual/Positioning.java 2013-12-16 12:01:22 +0000 |
867 | +++ WorkcraftCore/src/org/workcraft/dom/visual/Positioning.java 2014-04-09 17:15:15 +0000 |
868 | @@ -4,15 +4,15 @@ |
869 | import java.util.Map; |
870 | |
871 | public enum Positioning { |
872 | - TOP("Top", 0.0, -1.3), |
873 | - BOTTOM("Bottom", 0.0, 1.3), |
874 | - LEFT("Left", -1.3, 0.0), |
875 | - RIGHT("Right", 1.3, 0.0), |
876 | + TOP("Top", 0.0, -0.2), |
877 | + BOTTOM("Bottom", 0.0, 0.2), |
878 | + LEFT("Left", -0.2, 0.0), |
879 | + RIGHT("Right", 0.2, 0.0), |
880 | CENTER("Center", 0.0, 0.0), |
881 | - TOP_LEFT("Top-Left", -1.1, -1.3), |
882 | - TOP_RIGHT("Top-Right", 1.1, -1.3), |
883 | - BOTTOM_LEFT("Bottom-Left", -1.1, 1.3), |
884 | - BOTTOM_RIGHT("Bottom-Right", 1.1, 1.3); |
885 | + TOP_LEFT("Top-Left", -0.2, -0.2), |
886 | + TOP_RIGHT("Top-Right", 0.2, -0.2), |
887 | + BOTTOM_LEFT("Bottom-Left", -0.2, 0.2), |
888 | + BOTTOM_RIGHT("Bottom-Right", 0.2, 0.2); |
889 | |
890 | public final String name; |
891 | public final double xOffset; |
892 | |
893 | === modified file 'WorkcraftCore/src/org/workcraft/dom/visual/RenderedText.java' |
894 | --- WorkcraftCore/src/org/workcraft/dom/visual/RenderedText.java 2013-12-27 18:14:34 +0000 |
895 | +++ WorkcraftCore/src/org/workcraft/dom/visual/RenderedText.java 2014-04-09 17:15:15 +0000 |
896 | @@ -12,26 +12,31 @@ |
897 | final public String text; |
898 | final public Font font; |
899 | final public Positioning positioning; |
900 | - final public double offset; |
901 | + final public double xOffset; |
902 | + final public double yOffset; |
903 | final private GlyphVector glyphVector; |
904 | private Rectangle2D boundingBox; |
905 | |
906 | - public RenderedText(String text, Font font, Positioning positioning, double offset) { |
907 | + public RenderedText(String text, Font font, Positioning positioning, Point2D offset) { |
908 | this.text = text; |
909 | this.font = font; |
910 | this.positioning = positioning; |
911 | - this.offset = offset; |
912 | + this.xOffset = offset.getX(); |
913 | + this.yOffset = offset.getY(); |
914 | final FontRenderContext context = new FontRenderContext(AffineTransform.getScaleInstance(1000, 1000), true, true); |
915 | glyphVector = font.createGlyphVector(context, text); |
916 | - final Rectangle2D bb = BoundingBoxHelper.expand(glyphVector.getVisualBounds(), 0, 0); |
917 | - boundingBox = BoundingBoxHelper.move(bb, -bb.getCenterX(), -bb.getCenterY()); |
918 | - double x = offset * positioning.xOffset + 0.5 * positioning.xSign * boundingBox.getWidth(); |
919 | - double y = offset * positioning.yOffset + 0.5 * positioning.ySign * boundingBox.getHeight(); |
920 | + final Rectangle2D bb = glyphVector.getVisualBounds(); |
921 | + double x = xOffset + positioning.xOffset + 0.5 * positioning.xSign * bb.getWidth(); |
922 | + double y = yOffset + positioning.yOffset + 0.5 * positioning.ySign * bb.getHeight(); |
923 | boundingBox = BoundingBoxHelper.move(bb, x - bb.getCenterX(), y - bb.getCenterY()); |
924 | } |
925 | |
926 | - public boolean isDifferent(String text, Font font, Positioning positioning, double offset) { |
927 | - return (!text.equals(this.text) || font != this.font || positioning != this.positioning || offset != this.offset); |
928 | + public boolean isDifferent(String text, Font font, Positioning positioning, Point2D offset) { |
929 | + if (text == null) { |
930 | + text = ""; |
931 | + } |
932 | + return (!text.equals(this.text) || !font.equals(this.font) || positioning != this.positioning |
933 | + || offset.getX() != this.xOffset || offset.getY() != this.yOffset); |
934 | } |
935 | |
936 | public void draw (Graphics2D g) { |
937 | |
938 | === modified file 'WorkcraftCore/src/org/workcraft/dom/visual/VisualComment.java' |
939 | --- WorkcraftCore/src/org/workcraft/dom/visual/VisualComment.java 2014-01-03 16:49:50 +0000 |
940 | +++ WorkcraftCore/src/org/workcraft/dom/visual/VisualComment.java 2014-04-09 17:15:15 +0000 |
941 | @@ -50,8 +50,8 @@ |
942 | } |
943 | |
944 | @Override |
945 | - public double getLabelOffset() { |
946 | - return 0.0; |
947 | + public Point2D getLabelOffset() { |
948 | + return new Point2D.Double(0.0, 0.0); |
949 | } |
950 | |
951 | @Override |
952 | @@ -60,8 +60,8 @@ |
953 | } |
954 | |
955 | @Override |
956 | - public double getNameOffset() { |
957 | - return 0.0; |
958 | + public Point2D getNameOffset() { |
959 | + return new Point2D.Double(0.0, 0.0); |
960 | } |
961 | |
962 | @Override |
963 | |
964 | === modified file 'WorkcraftCore/src/org/workcraft/dom/visual/VisualComponent.java' |
965 | --- WorkcraftCore/src/org/workcraft/dom/visual/VisualComponent.java 2014-01-28 17:11:19 +0000 |
966 | +++ WorkcraftCore/src/org/workcraft/dom/visual/VisualComponent.java 2014-04-09 17:15:15 +0000 |
967 | @@ -244,11 +244,18 @@ |
968 | return CommonVisualSettings.getLabelVisibility(); |
969 | } |
970 | |
971 | - public double getLabelOffset() { |
972 | - return 0.5 * size; |
973 | + public Point2D getOffset(Positioning positioning) { |
974 | + Rectangle2D bb = getInternalBoundingBoxInLocalSpace(); |
975 | + double xOffset = (positioning.xSign<0) ? bb.getMinX() : (positioning.xSign>0) ? bb.getMaxX() : bb.getCenterX(); |
976 | + double yOffset = (positioning.ySign<0) ? bb.getMinY() : (positioning.ySign>0) ? bb.getMaxY() : bb.getCenterY(); |
977 | + return new Point2D.Double(xOffset, yOffset); |
978 | + } |
979 | + |
980 | + public Point2D getLabelOffset() { |
981 | + return getOffset(labelPositioning); |
982 | } |
983 | |
984 | - private void cacheLabelRenderedText(DrawRequest r) { |
985 | + protected void cacheLabelRenderedText(DrawRequest r) { |
986 | if (labelRenderedText.isDifferent(label, labelFont, labelPositioning, getLabelOffset())) { |
987 | labelRenderedText = new RenderedText(label, labelFont, labelPositioning, getLabelOffset()); |
988 | } |
989 | @@ -268,15 +275,12 @@ |
990 | return CommonVisualSettings.getNameVisibility(); |
991 | } |
992 | |
993 | - public double getNameOffset() { |
994 | - return 0.5 * size; |
995 | + public Point2D getNameOffset() { |
996 | + return getOffset(namePositioning); |
997 | } |
998 | |
999 | - private void cacheNameRenderedText(DrawRequest r) { |
1000 | + protected void cacheNameRenderedText(DrawRequest r) { |
1001 | String name = r.getModel().getMathModel().getNodeReference(getReferencedComponent()); |
1002 | - if (name == null) { |
1003 | - name = ""; |
1004 | - } |
1005 | if (nameRenderedText.isDifferent(name, nameFont, namePositioning, getNameOffset())) { |
1006 | nameRenderedText = new RenderedText(name, nameFont, namePositioning, getNameOffset()); |
1007 | } |
1008 | @@ -299,9 +303,17 @@ |
1009 | cacheNameRenderedText(r); |
1010 | } |
1011 | |
1012 | + /* |
1013 | + * The internal bounding box does not include the related label and name of the node |
1014 | + */ |
1015 | + public Rectangle2D getInternalBoundingBoxInLocalSpace() { |
1016 | + Rectangle2D bb = new Rectangle2D.Double(-size / 2, -size / 2, size, size); |
1017 | + return bb; |
1018 | + } |
1019 | + |
1020 | @Override |
1021 | public Rectangle2D getBoundingBoxInLocalSpace() { |
1022 | - Rectangle2D bb = new Rectangle2D.Double(-size / 2, -size / 2, size, size); |
1023 | + Rectangle2D bb = getInternalBoundingBoxInLocalSpace(); |
1024 | if (getLabelVisibility()) { |
1025 | bb = BoundingBoxHelper.union(bb, labelRenderedText.getBoundingBox()); |
1026 | } |
1027 | @@ -313,8 +325,7 @@ |
1028 | |
1029 | @Override |
1030 | public boolean hitTestInLocalSpace(Point2D pointInLocalSpace) { |
1031 | - return Math.abs(pointInLocalSpace.getX()) <= size / 2 |
1032 | - && Math.abs(pointInLocalSpace.getY()) <= size / 2; |
1033 | + return getInternalBoundingBoxInLocalSpace().contains(pointInLocalSpace); |
1034 | } |
1035 | |
1036 | } |
1037 | \ No newline at end of file |
1038 | |
1039 | === modified file 'WorkcraftCore/src/org/workcraft/dom/visual/VisualTransformableNode.java' |
1040 | --- WorkcraftCore/src/org/workcraft/dom/visual/VisualTransformableNode.java 2014-01-07 16:03:24 +0000 |
1041 | +++ WorkcraftCore/src/org/workcraft/dom/visual/VisualTransformableNode.java 2014-04-09 17:15:15 +0000 |
1042 | @@ -136,7 +136,7 @@ |
1043 | return hitTestInLocalSpace(parentToLocalTransform.transform(point, null)); |
1044 | } |
1045 | |
1046 | - public abstract Rectangle2D getBoundingBoxInLocalSpace(); |
1047 | + public abstract Rectangle2D getBoundingBoxInLocalSpace(); |
1048 | |
1049 | public final Rectangle2D getBoundingBox() { |
1050 | return transformToParentSpace(getBoundingBoxInLocalSpace()); |