Search in sources :

Example 1 with ActivitiImageException

use of org.activiti.image.exception.ActivitiImageException in project Activiti by Activiti.

the class DefaultProcessDiagramCanvas method generateBufferedImage.

/**
   * Generates an image of what currently is drawn on the canvas.
   * 
   * Throws an {@link ActivitiException} when {@link #close()} is already
   * called.
   */
public BufferedImage generateBufferedImage(String imageType) {
    if (closed) {
        throw new ActivitiImageException("ProcessDiagramGenerator already closed");
    }
    // Try to remove white space
    minX = (minX <= 5) ? 5 : minX;
    minY = (minY <= 5) ? 5 : minY;
    BufferedImage imageToSerialize = processDiagram;
    if (minX >= 0 && minY >= 0) {
        imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
    }
    return imageToSerialize;
}
Also used : ActivitiImageException(org.activiti.image.exception.ActivitiImageException) BufferedImage(java.awt.image.BufferedImage)

Example 2 with ActivitiImageException

use of org.activiti.image.exception.ActivitiImageException in project Activiti by Activiti.

the class DefaultProcessDiagramGenerator method getDefaultDiagram.

/**
 * Get default diagram image as bytes array
 * @return the default diagram image
 */
protected InputStream getDefaultDiagram(String diagramImageFileName) {
    String imageFileName = diagramImageFileName != null ? diagramImageFileName : getDefaultDiagramImageFileName();
    InputStream imageStream = getClass().getResourceAsStream(imageFileName);
    if (imageStream == null) {
        throw new ActivitiImageException("Error occurred while getting default diagram image from file: " + imageFileName);
    }
    return imageStream;
}
Also used : InputStream(java.io.InputStream) ActivitiImageException(org.activiti.image.exception.ActivitiImageException)

Example 3 with ActivitiImageException

use of org.activiti.image.exception.ActivitiImageException in project my_curd by qinyou.

the class CustomProcessDiagramCanvas method generateImage.

/**
 * Generates an image of what currently is drawn on the canvas. Throws an {@link ActivitiException} when {@link #close()} is already called.
 */
public InputStream generateImage(String imageType) {
    if (closed) {
        throw new ActivitiImageException("ProcessDiagramGenerator already closed");
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        // Try to remove white space
        minX = (minX <= 5) ? 5 : minX;
        minY = (minY <= 5) ? 5 : minY;
        BufferedImage imageToSerialize = processDiagram;
        if (minX >= 0 && minY >= 0) {
            imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
        }
        ImageIO.write(imageToSerialize, imageType, out);
    } catch (IOException e) {
        throw new ActivitiImageException("Error while generating process image", e);
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException ignore) {
        // Exception is silently ignored
        }
    }
    return new ByteArrayInputStream(out.toByteArray());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ActivitiImageException(org.activiti.image.exception.ActivitiImageException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage)

Example 4 with ActivitiImageException

use of org.activiti.image.exception.ActivitiImageException in project Activiti by Activiti.

the class DefaultProcessDiagramCanvas method generateImage.

/**
 * Generates an image of what currently is drawn on the canvas.
 * <p>
 * Throws an {@link ActivitiImageException} when {@link #close()} is already
 * called.
 */
public InputStream generateImage() {
    if (closed) {
        throw new ActivitiImageException("ProcessDiagramGenerator already closed");
    }
    try {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        Writer out;
        out = new OutputStreamWriter(stream, "UTF-8");
        g.stream(out, true);
        return new ByteArrayInputStream(stream.toByteArray());
    } catch (UnsupportedEncodingException | SVGGraphics2DIOException e) {
        throw new ActivitiImageException("Error while generating process image", e);
    }
}
Also used : SVGGraphics2DIOException(org.apache.batik.svggen.SVGGraphics2DIOException) ByteArrayInputStream(java.io.ByteArrayInputStream) ActivitiImageException(org.activiti.image.exception.ActivitiImageException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 5 with ActivitiImageException

use of org.activiti.image.exception.ActivitiImageException in project my_curd by qinyou.

the class CustomProcessDiagramCanvas method generateBufferedImage.

/**
 * Generates an image of what currently is drawn on the canvas. Throws an {@link ActivitiException} when {@link #close()} is already called.
 */
public BufferedImage generateBufferedImage(String imageType) {
    if (closed) {
        throw new ActivitiImageException("ProcessDiagramGenerator already closed");
    }
    // Try to remove white space
    minX = (minX <= 5) ? 5 : minX;
    minY = (minY <= 5) ? 5 : minY;
    BufferedImage imageToSerialize = processDiagram;
    if (minX >= 0 && minY >= 0) {
        imageToSerialize = processDiagram.getSubimage(minX - 5, minY - 5, canvasWidth - minX + 5, canvasHeight - minY + 5);
    }
    return imageToSerialize;
}
Also used : ActivitiImageException(org.activiti.image.exception.ActivitiImageException) BufferedImage(java.awt.image.BufferedImage)

Aggregations

ActivitiImageException (org.activiti.image.exception.ActivitiImageException)5 BufferedImage (java.awt.image.BufferedImage)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Writer (java.io.Writer)1 SVGGraphics2DIOException (org.apache.batik.svggen.SVGGraphics2DIOException)1