private void paintContent()

in view/src/main/java/jetbrains/jetpad/projectional/view/toAwt/ViewContainerComponent.java [491:646]


  private void paintContent(final View view, final Graphics2D g) {
    final jetbrains.jetpad.geometry.Rectangle bounds = view.bounds().get();

    Color background = view.background().get();
    if (background != null) {
      g.setColor(toAwtColor(background));
      g.fillRect(bounds.origin.x, bounds.origin.y, bounds.dimension.x, bounds.dimension.y);
    }
    final Color border = view.border().get();
    if (border != null) {
      g.setColor(toAwtColor(border));
      g.drawRect(bounds.origin.x, bounds.origin.y, bounds.dimension.x - 1, bounds.dimension.y - 1);
    }

    if (view instanceof LineView) {
      LineView lineView = (LineView) view;
      g.setColor(toAwtColor(lineView.color().get()));
      g.setStroke(new BasicStroke(lineView.width().get()));
      Vector start = lineView.start().get();
      Vector end = lineView.end().get();
      g.drawLine(start.x, start.y, end.x, end.y);
    }

    if (view instanceof TextView) {
      TextView textView = (TextView) view;
      String text = textView.text().get();
      Vector origin = bounds.origin;

      java.awt.Font font = new java.awt.Font(toFontName(textView.fontFamily().get()), java.awt.Font.PLAIN, textView.fontSize().get());
      if (textView.bold().get()) {
        font = font.deriveFont(java.awt.Font.BOLD, font.getSize());
      }
      if (textView.italic().get()) {
        font = font.deriveFont(java.awt.Font.ITALIC, font.getSize());
      }
      g.setFont(font);

      g.setColor(toAwtColor(textView.textColor().get()));
      g.drawString(text, origin.x, origin.y + textView.baseLine());

      if (textView.selectionVisible().get()) {
        int start = textView.selectionStart().get();
        int end = textView.caretPosition().get();

        int left = Math.min(start, end);
        int xLeft = xOffset(g, text, left);
        int right = Math.max(start, end);
        int xRight = xOffset(g, text, right);
        g.setColor(toAwtColor(SELECTION_COLOR));
        g.fillRect(origin.x + xLeft, origin.y, xRight - xLeft - 1, bounds.dimension.y - 1);

        g.setColor(toAwtColor(Color.WHITE));
        g.drawString(text.substring(left, right), origin.x + xLeft, origin.y + textView.baseLine());
      }

      if (textView.caretVisible().get() && myCaretVisible && myFocused) {
        int xOffset = xOffset(g, text, textView.caretPosition().get());
        g.drawLine(origin.x + xOffset, origin.y, origin.x + xOffset, origin.y + bounds.dimension.y - 1);
      }
    }

    if (view instanceof ScrollView) {
      ScrollView scrollView = (ScrollView) view;
      jetbrains.jetpad.geometry.Rectangle additionalClip = scrollView.bounds().get();
      if (scrollView.isHorizontalScroller()) {
        paintScroller(g, scrollView, false);
        additionalClip = additionalClip.changeDimension(additionalClip.dimension.sub(new Vector(0, scrollView.xScrollWidth())));
      }

      if (scrollView.isVerticalScroller()) {
        paintScroller(g, scrollView, true);
        additionalClip = additionalClip.changeDimension(additionalClip.dimension.sub(new Vector(scrollView.yScrollWidth(), 0)));
      }

      g.clipRect(additionalClip.origin.x, additionalClip.origin.y, additionalClip.dimension.x, additionalClip.dimension.y);
    }

    if (view instanceof MultiPointView) {
      MultiPointView multiPoint = (MultiPointView) view;
      g.setColor(toAwtColor(multiPoint.color().get()));
      g.setStroke(new BasicStroke(multiPoint.width().get()));

      int n = multiPoint.points.size();
      int[] xs = new int[n];
      int[] ys = new int[n];

      for (int i = 0; i < n; i++) {
        Vector point = multiPoint.points.get(i);
        xs[i] = point.x;
        ys[i] = point.y;
      }

      if (!multiPoint.points.isEmpty()) {
        if (view instanceof PolyLineView) {
          g.drawPolyline(xs, ys, n);
        } else {
          g.fillPolygon(xs, ys, n);
        }
      }
    }

    if (view instanceof ImageView) {
      ImageView imageView = (ImageView) view;
      ImageData imageData = imageView.image.get();

      if (imageData instanceof ImageData.EmptyImageData) {
        //ignore
      } else if (imageData instanceof ImageData.BinaryImageData || imageData instanceof ImageData.UrlImageData) {
        BufferedImage image;
        try {
          if (imageData instanceof ImageData.BinaryImageData) {
            ImageData.BinaryImageData data = (ImageData.BinaryImageData) imageData;
            image = ImageIO.read(new ByteArrayInputStream(data.getData()));
          } else {
            String url = ((ImageData.UrlImageData) imageData).getUrl();
            String pngPrefix = "data:image/png;base64,";
            String jpgPrefix = "data:image/jpeg;base64,";
            if (url.startsWith(pngPrefix) || url.startsWith(jpgPrefix)) {
              String base64;
              if (url.startsWith(pngPrefix)) {
                base64 = url.substring(pngPrefix.length());
              } else {
                base64 = url.substring(jpgPrefix.length());
              }
              byte[] data = Base64Coder.decodeBytes(base64);
              image = ImageIO.read(new ByteArrayInputStream(data));
            } else {
              image = ImageIO.read(new URL(url));
            }
          }
        } catch (IOException e) {
          throw new RuntimeException(e);
        }

        g.drawImage(image, bounds.origin.x, bounds.origin.y, bounds.dimension.x, bounds.dimension.y, new ImageObserver() {
          @Override
          public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
            return true;
          }
        });
      } else {
        throw new UnsupportedOperationException("Unsupported Image : " + imageData);
      }
    }

    if (view instanceof SvgView) {
      if (myViewPaintHelpers.containsKey(view)) {
        ((PaintHelper<SvgView>) myViewPaintHelpers.get(view)).paint((SvgView) view, (Graphics2D) g.create());
      } else {
        SvgPaintHelper helper = new SvgPaintHelper((SvgView) view);
        myViewPaintHelpers.put(view, helper);

        helper.paint((SvgView) view, (Graphics2D) g.create());
      }
    }
  }