Example #1
0
  @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);
  }
Example #2
0
 @Override
 public void draw(DrawRequest r) {
   Graphics2D g = r.getGraphics();
   g.setColor(Color.LIGHT_GRAY);
   g.setStroke(new BasicStroke(0.02f));
   Line2D l = new Line2D.Double(0, 0, origin.getX(), origin.getY());
   g.draw(l);
   super.draw(r);
 }
Example #3
0
  @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;
      }
    }
  }