@Override public void draw(DrawRequest r) { Graphics2D g = r.getGraphics(); Decoration d = r.getDecoration(); double s = size - strokeWidth; Shape shape = new Ellipse2D.Double(-s / 2, -s / 2, s, s); g.setColor(Coloriser.colorise(getFillColor(), d.getBackground())); g.fill(shape); g.setStroke(new BasicStroke(strokeWidth)); g.setColor(Coloriser.colorise(getForegroundColor(), d.getColorisation())); g.draw(shape); if (getReferencedState().isInitial()) { g.setStroke(new BasicStroke(strokeWidth)); g.setColor(Coloriser.colorise(getForegroundColor(), d.getColorisation())); g.draw(getInitialMarkerShape()); } if (getReferencedState().isFinal()) { g.setStroke(new BasicStroke(strokeWidth / 2)); g.setColor(Coloriser.colorise(getForegroundColor(), d.getColorisation())); g.draw(getFinalMarkerShape()); } drawLabelInLocalSpace(r); drawNameInLocalSpace(r); }
public void coloriseTokens(Transition t) { VisualStg visualStg = (VisualStg) getUnderlyingModel(); VisualTransition vt = visualStg.getVisualTransition(t); if (vt == null) return; Color tokenColor = Color.black; ColorGenerator tokenColorGenerator = vt.getTokenColorGenerator(); if (tokenColorGenerator != null) { // generate token colour tokenColor = tokenColorGenerator.updateColor(); } else { // combine preset token colours for (Connection c : visualStg.getConnections(vt)) { if ((c.getSecond() == vt) && (c instanceof VisualConnection)) { VisualConnection vc = (VisualConnection) c; if (vc.isTokenColorPropagator()) { if (vc.getFirst() instanceof VisualPlace) { VisualPlace vp = (VisualPlace) c.getFirst(); tokenColor = Coloriser.colorise(tokenColor, vp.getTokenColor()); } else if (vc instanceof VisualImplicitPlaceArc) { VisualImplicitPlaceArc vipa = (VisualImplicitPlaceArc) vc; tokenColor = Coloriser.colorise(tokenColor, vipa.getTokenColor()); } } } } } // propagate the colour to postset tokens for (Connection c : visualStg.getConnections(vt)) { if ((c.getFirst() == vt) && (c instanceof VisualConnection)) { VisualConnection vc = (VisualConnection) c; if (vc.isTokenColorPropagator()) { if (vc.getSecond() instanceof VisualPlace) { VisualPlace vp = (VisualPlace) c.getSecond(); vp.setTokenColor(tokenColor); } else if (vc instanceof VisualImplicitPlaceArc) { VisualImplicitPlaceArc vipa = (VisualImplicitPlaceArc) vc; vipa.setTokenColor(tokenColor); } } } } }
@Override public void draw(DrawRequest r) { Graphics2D g = r.getGraphics(); Color colorisation = r.getDecoration().getColorisation(); // Color background = r.getDecoration().getBackground(); Rectangle2D bb = getContentsBoundingBox(); if (bb != null && getParent() != null) { // g.setColor(Coloriser.colorise(Color.WHITE, background)); // g.fill(bb); g.setColor(Coloriser.colorise(Color.BLACK, colorisation)); g.setStroke(new BasicStroke(strokeWidth)); g.draw(bb); // draw label FormulaRenderingResult result = FormulaToGraphics.print(label, labelFont, g.getFontRenderContext()); labelBB = BoundingBoxHelper.expand(result.boundingBox, 0.4, 0.2); Point2D labelPosition = new Point2D.Double(bb.getMaxX() - labelBB.getMaxX(), bb.getMinY() - labelBB.getMaxY()); g.setColor(Coloriser.colorise(Color.WHITE, colorisation)); g.fill(getLabelBB()); g.setStroke(new BasicStroke(strokeWidth)); g.setColor(Coloriser.colorise(Color.BLACK, colorisation)); g.draw(getLabelBB()); AffineTransform transform = g.getTransform(); g.translate(labelPosition.getX(), labelPosition.getY()); g.setColor(Coloriser.colorise(Color.BLACK, colorisation)); result.draw(g); g.setTransform(transform); // draw encoding encodingBB = null; Set<Variable> sortedVariables = new TreeSet<>(new ReverseComparator()); sortedVariables.addAll(encoding.getStates().keySet()); double right = bb.getMaxX(); double top = bb.getMaxY(); variableBBs.clear(); boolean perfectMatch = true; for (Variable var : sortedVariables) { if (!var.getState().matches(encoding.getState(var))) perfectMatch = false; } for (Variable var : sortedVariables) { String text = var.getLabel(); result = FormulaToGraphics.print(text, labelFont, g.getFontRenderContext()); bb = result.boundingBox; bb = BoundingBoxHelper.expand(bb, 0.4, 0.2); if (bb.getWidth() < minVariableWidth) bb = BoundingBoxHelper.expand(bb, minVariableWidth - bb.getWidth(), 0); if (bb.getHeight() < minVariableHeight) bb = BoundingBoxHelper.expand(bb, 0, minVariableHeight - bb.getHeight()); labelPosition = new Point2D.Double(right - bb.getMaxX(), top - bb.getMinY()); double left = right - bb.getWidth(); double bottom = top + bb.getHeight(); Rectangle2D tmpBB = new Rectangle2D.Double(left, top, bb.getWidth(), bb.getHeight()); encodingBB = BoundingBoxHelper.union(encodingBB, tmpBB); g.setColor(Coloriser.colorise(Color.WHITE, colorisation)); g.fill(tmpBB); g.setStroke(new BasicStroke(strokeWidth)); g.setColor(Coloriser.colorise(Color.BLACK, colorisation)); g.draw(tmpBB); transform = g.getTransform(); g.translate(labelPosition.getX(), labelPosition.getY()); g.setColor(Coloriser.colorise(Color.BLACK, colorisation)); result.draw(g); g.setTransform(transform); variableBBs.put(tmpBB, var); text = encoding.getState(var).getValueAsString(); if (text.equals("?")) text = "\u2013"; result = FormulaToGraphics.print(text, labelFont, g.getFontRenderContext()); bb = result.boundingBox; bb = BoundingBoxHelper.expand( bb, tmpBB.getWidth() - bb.getWidth(), tmpBB.getHeight() - bb.getHeight()); labelPosition = new Point2D.Double(right - bb.getMaxX(), bottom - bb.getMinY()); tmpBB = new Rectangle2D.Double(left, bottom, bb.getWidth(), bb.getHeight()); encodingBB = BoundingBoxHelper.union(encodingBB, tmpBB); g.setColor(Coloriser.colorise(Color.WHITE, colorisation)); g.fill(tmpBB); g.setStroke(new BasicStroke(strokeWidth)); g.setColor(Coloriser.colorise(Color.BLACK, colorisation)); g.draw(tmpBB); transform = g.getTransform(); g.translate(labelPosition.getX(), labelPosition.getY()); Color color = Color.BLACK; if (!var.getState().matches(encoding.getState(var))) color = Color.RED; if (perfectMatch) color = Color.GREEN; g.setColor(Coloriser.colorise(color, colorisation)); result.draw(g); g.setTransform(transform); variableBBs.put(tmpBB, var); right = left; } } }