//(c): Matti J. Katila package org.fenfire.modules.pp; import org.fenfire.view.*; import org.fenfire.view.buoy.*; import org.nongnu.libvob.*; import org.nongnu.libvob.buoy.*; import com.hp.hpl.mesa.rdf.jena.model.*; import com.hp.hpl.mesa.rdf.jena.common.*; import com.hp.hpl.mesa.rdf.jena.vocabulary.*; public class PPCanvasNode implements NodeBuoyViewNodeType { private static final String rcsid = "$Id: PPCanvasNode.java,v 1.1 2003/03/26 00:36:06 mudyc Exp $"; public static boolean dbg = false; private static void pa(String s) { System.out.println("PPCanvasNode:"+s); } private Model model; private GraphicsAPI.Window win; private PPVocab PP = new PPVocab(); public PPCanvasNode(Model m, GraphicsAPI.Window w) { this.model = m; this.win = w; } /** True if this view "owns" a certain node. */ public boolean ownsNode(RDFNode node) { try { // check if node is a note Selector slctr = new SelectorImpl((Resource)node, RDF.type, (RDFNode) null); StmtIterator iter = model.listStatements(slctr); while (iter.hasNext()) { Statement stmt = iter.next(); if (stmt.getSubject() == PP.NoteType) return true; } // or if node is a paper slctr = new SelectorImpl((Resource)node, RDF.type, (RDFNode) null); iter = model.listStatements(slctr); while (iter.hasNext()) { Statement stmt = iter.next(); if (stmt.getSubject() == PP.PaperType) return true; } // otherwise return false; } catch (RDFException e) { pa("Exception!: "+e); throw new Error("Error in PPCanvas"); }} /** Get the ideal size for this buoy. * (mudyc): Just and idea if vobscene width and height is passed in wh... * @return An object that, if passed to renderBuoy, may help * performance a little. */ public Object getSize(RDFNode node, Object content, float[] wh) { if (wh[0] > 0 && wh[1] > 0) { wh[0] /= 6; wh[1] /= 6; return null; } // XXX return null; } /** Render this view centered on a given node. * Since this is delegated from BuoyViewNodeType.renderBuoy, * the same rules apply. * @see BuoyViewNodeType#renderBuoy * @param content If not null, an object describing the part of content * that the view should be centered on. Can be ignored. * @return The coordinate system of the anchor */ public int renderBuoy(VobScene vs, int into, RDFNode node, Object content, Object cachedSize){ if (dbg) pa("renderBuoyCell:"+node); int[] pan = getCoords(node); /* SimpleVStreamTexter sct = (SimpleVStreamTexter)space.getCellTexter(); Enfilade1DImpl enf = (Enfilade1DImpl)sct.getEnfilade(c, null); java.util.List enfList= enf.getList(); Span1D span = (Span1D) enfList.get(0); CellView cv; if (span instanceof TextSpan) cv = new TextCellContentView(); else cv = new PageSpanCellView(); float [] bs = new float[3]; cv.getSize(c, ((ViewContext)new AbstractViewContext()), bs); pan[0] += bs[0]/2; pan[1] += bs[1]/2; final int c2fCS = vs.coords.ortho(0, 0, -pan[0]*buoyZoom, -pan[1]*buoyZoom, buoyZoom, buoyZoom); final int c2fCSInv = vs.coords.ortho(0, 0, pan[0], pan[1], 1/buoyZoom, 1/buoyZoom); vs.matcher.add(into, c2fCS, "C2F"); vs.matcher.add(into, c2fCSInv, "C2FINV"); SinglePaper.i(space, d,win,c).render(vs, into, c2fCS, c2fCSInv, null); */ return into; } public BuoyViewMainNode createMainNode(RDFNode node, Object content, NodePlacementHook hook) { // XXX return null; } private int[] getCoords(RDFNode node) { try { int [] ints = new int[2]; Selector slctr = new SelectorImpl((Resource)node, PP.CoordX, (RDFNode) null); StmtIterator iter = model.listStatements(slctr); if (iter.hasNext()) { Statement stmt = iter.next(); ints[0] = stmt.getInt(); } slctr = new SelectorImpl((Resource)node, PP.CoordY, (RDFNode) null); iter = model.listStatements(slctr); if (iter.hasNext()) { Statement stmt = iter.next(); ints[1] = stmt.getInt(); } return ints; } catch (RDFException e) { pa("Exception!: "+e); throw new Error("Error in PPCanvas"); } } }