/* LastOpDecorator.java * * Copyright (c) 2002 by Benja Fallenstein * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software 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 README * file for more details. * */ /* * Written by Benja Fallenstein */ package gzz.view; import gzz.client.*; import gzz.*; import gzz.potion.*; import gzz.errors.*; import gzz.vob.*; import gzz.vob.linebreaking.*; import gzz.vob.vobs.*; import java.awt.*; import java.util.*; /** A Fallback scene decorator showing the last (currently pending) * potion op entered. */ public class PendingPotionDecorator implements FallbackSceneDecorator { String rcsid = "$Id: PendingPotionDecorator.java,v 1.1 2003/01/03 18:05:07 benja Exp $"; public static boolean dbg = false; private static void pa(String s) { System.err.println(s); } static TextStyle style = GraphicsAPI.getInstance().getTextStyle("SansSerif", Font.PLAIN, 16); static Object key = new Object(); static SimpleLinebreaker breaker = new SimpleLinebreaker(); int padding = 15; public void render(VobScene sc, int into, Fallback fallback, Fallback.Win win) { if(!(fallback.binder instanceof PotionFallbackBinder)) return; PotionFallbackBinder binder = (PotionFallbackBinder)fallback.binder; if(dbg) pa("Next potion action: "+binder.currentAction); if(binder.currentAction == null) return; Dimension size = sc.getSize(); HChain ch = new LinebreakableChain(); Map context = binder.getContext(win); String text = binder.currentAction.getString(context); if(dbg) pa("Potion action text: "+text); ch.addBox(text(text)); // XXX linebreaking! (only breaks *between* boxes...) float w = size.width - 2*padding; HBroken br = breaker.breakLines(ch, w, 1.0f); float h = br.getHeight(); float x = padding; float y = size.height - padding - h; int cs = sc.orthoBoxCS(into, key, 0, x, y, 1, 1, w, h); br.put(sc, cs); if(dbg) pa("Put "+br+" "+ch.length()+" in cs "+cs+" @ "+x+" "+y+" "+w+" "+h+" ("+size+")"); } /** Get the HBox for some text. */ HBox text(String s, int i) { return new TextVob(style, s, true, new Integer(i)); } HBox text(String s) { return text(s, 1); } /** Get the HBox for a cell (as part of the cell's opstring). */ HBox cell(Cell c, ViewContext context) { if(c == null) return text("[which cell?]"); return new CellHBox(c, context.getCellView(), context); } }