/* WheelView.java * * Copyright (c) 2003 by Asko Soukka * * 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 Asko Soukka */ package org.fenfire.loom; import org.nongnu.libvob.*; import org.nongnu.libvob.vobs.*; import java.lang.Math; import java.util.*; import org.fenfire.util.Pair; import com.hp.hpl.mesa.rdf.jena.model.*; /** A sundew like simple wheel view. */ public class SundewWheelView extends WheelView { public static boolean dbg = false; private static void p(String s) { System.out.println(s); } public SundewWheelView(NodeView nodeView) { super(nodeView); radius = (sizex + gapx) * 2; depth = 2; } protected void renderDepth(VobScene sc, int into, Cursor c, Resource focus, Pair current, Collection nodes, int dir, double cura, double rota, float r, int focusCs, int depth, int midx, int midy) { RDFNode newFocus = (RDFNode)current.first; if (newFocus != null && newFocus instanceof Resource) { Vector removal = new Vector(); Pair focusPair = new Pair(focus, (Property)current.second); removal.add(focusPair); Collection posNodes, negNodes; if (dir > 0) { posNodes = getNodes(c, (Resource)newFocus, 1); negNodes = getNodes(c, (Resource)newFocus, -1, removal); } else { posNodes = getNodes(c, (Resource)newFocus, 1, removal); negNodes = getNodes(c, (Resource)newFocus, -1); } double posRota = getRotationAngle(c, (Resource)newFocus, posNodes, Math.PI, depth-1); double negRota = getRotationAngle(c, (Resource)newFocus, negNodes, Math.PI, depth-1); double newRota = (posRota < negRota) ? posRota : negRota; if (posRota < 0) newRota = negRota; else if (negRota < 0) newRota = posRota; int position = (posNodes.size() > negNodes.size()) ? posNodes.size() / 2: negNodes.size() / 2; int x = midx+x(cura, r); int y = midy+y(cura, r); renderSomewardConnections(sc, into, c, (Resource)newFocus, posNodes, position, 1, newRota/2, newRota, r/2, focusCs, depth-1, x, y); renderSomewardConnections(sc, into, c, (Resource)newFocus, negNodes, position, -1, Math.PI+newRota/2, newRota, r/2, focusCs, depth-1, x, y); } } private int x(double angle, float radius) { return (int)(Math.cos(angle) * radius); } private int y(double angle, float radius) { return (int)(Math.sin(angle) * radius); } }