/* TextNodeView.java * * Copyright (c) 2003, Benja Fallenstein * * This file is part of Fenfire. * * Fenfire is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Fenfire is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General * Public License for more details. * * You should have received a copy of the GNU Lesser General * Public License along with Fenfire; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * */ /* * Written by Benja Fallenstein */ package org.fenfire.view; import org.fenfire.swamp.*; import org.nongnu.alph.*; import org.nongnu.libvob.*; import org.nongnu.libvob.vobs.*; /** A node function returning a vob that shows * the given node as text. * Should take a width and do linebreaking; * currently, places text as a single very long line. */ public class TextNodeView implements NodeFunction { final NodeFunction nodeContent; final TextStyle style; final float scale; public TextNodeView(NodeFunction nodeContent, TextStyle style, float scale) { this.nodeContent = nodeContent; this.style = style; this.scale = scale; } public Object f(ConstGraph g, Object node) { Enfilade1D enf = (Enfilade1D)nodeContent.f(g, node); String s = enf.makeString(); final TextVob vob = new TextVob(style, s, false); final float width = style.getWidth(s, scale); final float height = style.getHeight(scale); return new org.nongnu.libvob.lava.placeable.Placeable() { public void place(VobScene scene, int into) { int scaled = scene.orthoCS(into, "Scaled", 0, 0, 0, scale, scale); scene.put(vob, scaled); } public float getWidth() { return width; } public float getHeight() { return height; } }; } }