All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.approvaltests.writers.PaintableApprovalWriter Maven / Gradle / Ivy

There is a newer version: 24.9.0
Show newest version
package org.approvaltests.writers;

import com.spun.swing.Paintable;
import org.approvaltests.core.ApprovalWriter;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;

public class PaintableApprovalWriter implements ApprovalWriter
{
  private ImageApprovalWriter image = null;
  public PaintableApprovalWriter(Paintable paintable)
  {
    BufferedImage image = drawComponent(paintable);
    this.image = new ImageApprovalWriter(image);
  }
  public static BufferedImage drawComponent(Paintable paintable)
  {
    final Dimension size = paintable.getSize();
    BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
    Graphics g = image.createGraphics();
    paintable.paint(g);
    g.dispose();
    return image;
  }
  @Override
  public File writeReceivedFile(File filename)
  {
    return image.writeReceivedFile(filename);
  }
  @Override
  public String getFileExtensionWithDot()
  {
    return image.getFileExtensionWithDot();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy