Search in sources :

Example 1 with AbstractImageGraphicsItem

use of annis.visualizers.component.tree.backends.staticimg.AbstractImageGraphicsItem in project ANNIS by korpling.

the class TigerTreeVisualizer method writeOutput.

@Override
public void writeOutput(VisualizerInput input, OutputStream outstream) {
    AnnisResult result = input.getResult();
    graphtools = new AnnisGraphTools(input);
    List<AbstractImageGraphicsItem> layouts = new LinkedList<AbstractImageGraphicsItem>();
    double width = 0;
    double maxheight = 0;
    for (DirectedGraph<AnnisNode, Edge> g : graphtools.getSyntaxGraphs()) {
        if (g.getEdgeCount() > 0 && g.getVertexCount() > 0) {
            ConstituentLayouter<AbstractImageGraphicsItem> cl = new ConstituentLayouter<AbstractImageGraphicsItem>(g, getBackend(), labeler, styler, input, graphtools);
            AbstractImageGraphicsItem item = cl.createLayout(new LayoutOptions(VerticalOrientation.TOP_ROOT, AnnisGraphTools.detectLayoutDirection(result.getGraph())));
            Rectangle2D treeSize = item.getBounds();
            maxheight = Math.max(maxheight, treeSize.getHeight());
            width += treeSize.getWidth();
            layouts.add(item);
        }
    }
    BufferedImage image;
    if (width == 0 || maxheight == 0) {
        Notification.show("Can't generate tree visualization.", Notification.Type.WARNING_MESSAGE);
        image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    } else {
        image = new BufferedImage((int) (width + (layouts.size() - 1) * TREE_DISTANCE + 2 * SIDE_MARGIN), (int) (maxheight + 2 * TOP_MARGIN), BufferedImage.TYPE_INT_ARGB);
        Graphics2D canvas = createCanvas(image);
        double xOffset = SIDE_MARGIN;
        for (AbstractImageGraphicsItem item : layouts) {
            AffineTransform t = canvas.getTransform();
            Rectangle2D bounds = item.getBounds();
            canvas.translate(xOffset, TOP_MARGIN + maxheight - bounds.getHeight());
            renderTree(item, canvas);
            xOffset += bounds.getWidth() + TREE_DISTANCE;
            canvas.setTransform(t);
        }
    }
    try {
        ImageIO.write(image, "png", outstream);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : AbstractImageGraphicsItem(annis.visualizers.component.tree.backends.staticimg.AbstractImageGraphicsItem) Rectangle2D(java.awt.geom.Rectangle2D) AnnisResult(annis.service.ifaces.AnnisResult) IOException(java.io.IOException) LinkedList(java.util.LinkedList) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) AnnisNode(annis.model.AnnisNode) AffineTransform(java.awt.geom.AffineTransform) Edge(annis.model.Edge)

Example 2 with AbstractImageGraphicsItem

use of annis.visualizers.component.tree.backends.staticimg.AbstractImageGraphicsItem in project ANNIS by korpling.

the class TigerTreeVisualizer method renderTree.

private void renderTree(AbstractImageGraphicsItem item, Graphics2D canvas) {
    List<AbstractImageGraphicsItem> allItems = new ArrayList<AbstractImageGraphicsItem>();
    item.getAllChildren(allItems);
    Collections.sort(allItems, new Comparator<AbstractImageGraphicsItem>() {

        @Override
        public int compare(AbstractImageGraphicsItem o1, AbstractImageGraphicsItem o2) {
            return o1.getZValue() - o2.getZValue();
        }
    });
    for (AbstractImageGraphicsItem c : allItems) {
        c.draw(canvas);
    }
}
Also used : AbstractImageGraphicsItem(annis.visualizers.component.tree.backends.staticimg.AbstractImageGraphicsItem) ArrayList(java.util.ArrayList)

Aggregations

AbstractImageGraphicsItem (annis.visualizers.component.tree.backends.staticimg.AbstractImageGraphicsItem)2 AnnisNode (annis.model.AnnisNode)1 Edge (annis.model.Edge)1 AnnisResult (annis.service.ifaces.AnnisResult)1 Graphics2D (java.awt.Graphics2D)1 AffineTransform (java.awt.geom.AffineTransform)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1