/* Loom.java * * Copyright (c) 2003 by 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.loom; import org.nongnu.libvob.*; import org.nongnu.libvob.impl.DefaultVobMatcher; import org.nongnu.libvob.vobs.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import java.util.List; import com.hp.hpl.mesa.rdf.jena.model.*; import com.hp.hpl.mesa.rdf.jena.mem.*; /** The default node view for Loom. * Not tested at this time [XXX fix!!!]. */ public class DefaultNodeView implements NodeView { protected Loom loom; protected TextStyle style; public DefaultNodeView(Loom loom) { this.loom = loom; style = GraphicsAPI.getInstance() .getTextStyle("Serif", 0, 12); } public void render(VobScene sc, int into, Nodespec spec) { RDFNode node = spec.node; Property prop = spec.prop; int dir = spec.dir; boolean selected = spec.equals(loom.cursor.getRotationNodespec(dir)); if(node instanceof Resource) { OvalBgVob bg = new OvalBgVob(new Color(102, 255, 102), selected, loom.colors.getCursorBorderColor()); sc.map.put(bg, into); } else { RectBgVob bg = new RectBgVob(new Color(255, 204, 51), selected, loom.colors.getCursorBorderColor()); sc.map.put(bg, into); } String s; boolean isByClass = false; if(node instanceof Literal) { try { s = ((Literal)node).getString(); } catch(RDFException e) { System.out.println(e); s = ""; } } else { s = ((Resource)node).getURI(); if(s != null) s = loom.cursor.names.getAbbrev(s); else s = ""; String t = s; try { Property by; try { Statement typeStmt = ((Resource)node).getProperty(loom.rdf.type); RDFNode type = typeStmt.getObject(); by = (Property)loom.showClassBy.get(type); } catch(RDFException _) { by = loom.showNoClassBy; } if(by != null) { Statement byStmt = ((Resource)node).getProperty(by); if(byStmt.getObject() instanceof Literal) s = byStmt.getString(); else s = loom.cursor.names.getAbbrev(byStmt.getObject().toString()); isByClass = true; } } catch(RDFException e) { s = t; } } if(s.length() > 17) { if(node instanceof Literal || isByClass) s = s.substring(0, 14) + "..."; else s = "..." + s.substring(s.length()-14); } float w = style.getWidth(s, 1); float h = style.getHeight(1); float x = 75-w/2; float y = 10-h/2; int textCs = sc.orthoCS(into, "text", 0, x, y, h, h); sc.map.put(new TextVob(style, s), textCs); if(prop != null) { s = prop.toString(); s = loom.cursor.names.getAbbrev(s); if(s.length() > 15) s = s.substring(s.length()-15); if(dir > 0) x = 0; else x = 150 - style.getWidth(s, .8f); h = style.getHeight(.8f); int propCs = sc.orthoCS(into, "property", 0, x, -h, h, h); sc.map.put(new TextVob(style, s), propCs); } } }