/* LollipopCellVobFactory.java * * Copyright (c) 1999-2002, Ted Nelson and Tuomas Lukka * * 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 Tuomas Lukka and Asko Soukka */ package gzz.view; import gzz.client.*; import gzz.*; import gzz.errors.*; import gzz.vob.*; import gzz.client.*; import gzz.impl.*; import java.awt.Font; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Color; import java.util.*; /** A factory for making ball-and-stick aka lollipop cell vobs. */ public class LollipopCellVobFactory extends CellVobFactory { public static final String rcsid = "$Id: LollipopCellVobFactory.java,v 1.1 2002/10/18 09:03:53 humppake Exp $"; /** Add the vobs that make up an image of a cell * into the given coordinate * system of the given vobscene. * @param c The cell * @param v The vobscene to add to * @param box The box in which the cell should be. * @param context The view context, for querying cursors, marks etc. */ public void place(final Cell c, final VobScene v, final Box box, final ViewContext context) { setCenter(context.getAccursed()); if(d_clone == null) throw new NullPointerException("clone dim not set in LollipopCellVobFactory"); final CellContentView ccv = cellContentView != null ? cellContentView : context.getCellContentView(); /** Uses OvalBgVob as the ball. */ final OvalBgVob bg = new OvalBgVob(); List cursorColors = context.getCursorColors(c); if(cursorColors != null) for(Iterator i = cursorColors.iterator(); i.hasNext();) bg.addColor((Color)i.next()); if (c.s(d_clone, -1) != null) // if clone bg.addColor(Color.yellow); else if (c.s(d_clone, 1) != null) // if rootclone bg.addColor(new Color(0xffff8c)); if (context.isMarked(c)) // if marked bg.addColor(new Color(0xff0000)); Object sliceId2 = getSliceId(c); if((sliceId==null && sliceId2!=null) || (sliceId != null && !sliceId.equals(sliceId2)) ) { // if different slice bg.setBg(bg.getBg().darker().darker()); } final Box contentBox = new Box(); float pad = 5; /** Coordsys to make OvalBgVob look circle and at * right place of cell's Box. Currently "right place" * is in the middle. */ final int cs = v.orthoCS(box.getWHCoordsys(), "cs", 0, box.getWidth()/2-box.getHeight()/2, 0, box.getHeight(), box.getHeight()); /** Cell's content will be drawn next to OvalBgVob */ contentBox.setSubWH(box, "CO", box.getWidth()/2+box.getHeight()/2+pad, pad, box.getWidth()-2*pad, box.getHeight()-2*pad); if(!(GraphicsAPI.getInstance() instanceof gzz.client.gl.GLAPI)) { ccv.place(c, v, contentBox, context, 1); v.map.put(bg, cs); } else { v.map.put(bg, cs); gzz.gfx.gl.Stencil.drawStenciled( v, new Runnable() { public void run() { v.map.put(bg, cs); }}, null, null, new Runnable() { public void run() { ccv.place(c, v, contentBox, context, 1); }}, false ); } } }