/* * Moonlight|3D Copyright (C) 2005 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 Jan 5, 2005 */ package ml.backend.og; import java.util.ArrayList; import ml.core.exceptions.Exception; /** * This class represents a link between an output slot and an input slot of two * different operator graph nodes * * @author gregor */ public class Link { ArrayList inputs; ArrayList outputs; public Link() { inputs=new ArrayList(); outputs=new ArrayList(); } /** * sets the Slot that is expected to deliver the input * for this Link. The Slot has to be an Output Slot of * a Node. */ public void setInput(Slot slot) throws ml.core.exceptions.Exception { if(slot.getType()==Slot.Type.Input) { throw new ml.core.exceptions.Exception("unable to assign an input slot to a link input"); } slot.setCurrentLink(this); if(inputs.size()>0) { inputs.remove(inputs.size()-1); } inputs.add(slot); } /** * returns the current Input Slot for this Link. */ public Slot getInput() { return inputs.get(inputs.size()-1); } /** * sets the Slot that is expected to recieve the output * of this Link. The Slot has to be an Input Slot of a * Node. * @throws Exception */ public void setOutput(Slot slot) throws Exception { if(slot.getType()==Slot.Type.Output) { throw new ml.core.exceptions.Exception("unable to assign an output slot to a link output"); } slot.setCurrentLink(this); if(outputs.size()>0) { outputs.remove(outputs.size()-1); } outputs.add(slot); } /** * returns the current Output Slot for this link. */ public Slot getOutput() { return outputs.get(outputs.size()-1); } /** * This function passes a recursive update request on to * this Link's output slot. * @throws Exception */ public void recursiveUpdate(Manager manager) throws Exception { getOutput().recursiveUpdate(manager); } /** * Creates a snapshot of the current Input and Output Slots * that are assigned to this link in order to allow for an * undo operation lateron. */ public void createUndoSnapshot() { inputs.add(inputs.get(inputs.size()-1)); outputs.add(outputs.get(outputs.size()-1)); if(inputs.size()>10) { inputs.remove(0); } if(outputs.size()>10) { outputs.remove(0); } } /** * Reverts the state of this Link to the latest undo snapshot * taken using createUndoSnapshot. */ public void undo() { inputs.remove(inputs.size()-1); outputs.remove(outputs.size()-1); } }