Search in sources :

Example 1 with ImagePanel

use of annis.libgui.ImagePanel in project ANNIS by korpling.

the class AbstractImageVisualizer method createComponent.

@Override
public ImagePanel createComponent(final VisualizerInput visInput, VisualizationToggle visToggle) {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    writeOutput(visInput, out);
    String fileName = "vis_" + UUID.randomUUID().toString() + ".png";
    StreamResource resource = new StreamResource(new StreamResource.StreamSource() {

        @Override
        public InputStream getStream() {
            return new ByteArrayInputStream(out.toByteArray());
        }
    }, fileName);
    Embedded emb = new Embedded("", resource);
    emb.setMimeType(getContentType());
    emb.setSizeUndefined();
    emb.setStandby("loading image");
    emb.setAlternateText("Visualization of the result");
    return new ImagePanel(emb);
}
Also used : StreamResource(com.vaadin.server.StreamResource) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Embedded(com.vaadin.ui.Embedded) ImagePanel(annis.libgui.ImagePanel)

Example 2 with ImagePanel

use of annis.libgui.ImagePanel in project ANNIS by korpling.

the class AbstractDotVisualizer method createComponent.

@Override
public ImagePanel createComponent(final VisualizerInput visInput, VisualizationToggle visToggle) {
    try {
        final PipedOutputStream out = new PipedOutputStream();
        final PipedInputStream in = new PipedInputStream(out);
        new Thread(new Runnable() {

            @Override
            public void run() {
                writeOutput(visInput, out);
            }
        }).start();
        String fileName = "dotvis_" + new Random().nextInt(Integer.MAX_VALUE) + ".png";
        StreamResource resource = new StreamResource(new StreamResource.StreamSource() {

            @Override
            public InputStream getStream() {
                return in;
            }
        }, fileName);
        Embedded emb = new Embedded("", resource);
        emb.setMimeType("image/png");
        emb.setSizeFull();
        emb.setStandby("loading image");
        emb.setAlternateText("DOT graph visualization");
        return new ImagePanel(emb);
    } catch (IOException ex) {
        log.error(null, ex);
    }
    return new ImagePanel(new Embedded());
}
Also used : PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException) Random(java.util.Random) StreamResource(com.vaadin.server.StreamResource) Embedded(com.vaadin.ui.Embedded) ImagePanel(annis.libgui.ImagePanel)

Aggregations

ImagePanel (annis.libgui.ImagePanel)2 StreamResource (com.vaadin.server.StreamResource)2 Embedded (com.vaadin.ui.Embedded)2 InputStream (java.io.InputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 Random (java.util.Random)1