/* * Moonlight|3D Copyright (C) 2006 The Moonlight|3D team * * This library 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.1 of the License, or (at your option) * any later version. * * This library 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 this library; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Feb 10, 2006 */ package eu.moonlight3d.graph; import com.trolltech.qt.gui.QGraphicsLineItem; import com.trolltech.qt.gui.QLineF; /** * A graph model class that represents a link between two slots on two * different nodes. Links are directed from the output slot on one node * towards the input slot on another node. This is important as it affects * the way the graph is laid out by some algorithms. * * @author gregor */ public class Link { /** * The output slot to which this link is connected on the input side. */ private Slot startSlot; /** * The input slot to which this link is connected on the output side. */ private Slot endSlot; /** * The Qt GraphicsView item for this link. */ private QGraphicsLineItem item; /** * Default constructor for a link between two slots. * * @param startSlot the slot from where this link connects * @param endSlot the slot that this link connects to */ public Link(Slot startSlot, Slot endSlot) { this.startSlot=startSlot; this.endSlot=endSlot; } /** * Get the slot this link is connected to on the input side * * @return the slot to which this link is connected */ public Slot getStartSlot() { return startSlot; } /** * Get the slot that this link is connected to on the output side * * @return the slot to which this link is connected */ public Slot getEndSlot() { return endSlot; } /** * Internal method to pass a reference to the Qt Graphics View item * that represents this node. * * @param item the Graphics View item that represents this node */ void setItem(QGraphicsLineItem item) { this.item=item; } /** * Internal method to get the Qt Graphics View item that represents * this node. * * @return the Graphics View item that represents the node */ QGraphicsLineItem getItem() { return item; } void setStartPoint(double x, double y) { if(item!=null) { QLineF line=item.line(); item.setLine(x, y, line.x2(), line.y2()); } } void setEndPoint(double x, double y) { if(item!=null) { QLineF line=item.line(); item.setLine(line.x1(), line.y1(), x, y); } } }