package causation.lab; // packages import java.util.*; import java.awt.*; // custom classes import causation.lab.Workbench; import causation.lab.WBVariable; import causation.lab.Latent; import causation.lab.WorkbenchObject; import causation.lab.WorkbenchEdge; /** * This object encodes all of the information about the Workbench that we need * to set the Workbench to a particular state. * * @see Workbench * @version 1.0 June 10, 1999 * @author David Danks */ public class ScreenShot { /////////////////// Class Variables /////////////////// public static final String RANDOMIZED = "*****RANDOMIZED*****"; public static final String LATENT = "*****LATENT*****"; /////////////////// Instance Variables /////////////////// private Point[] varLocats; private String[] varSetups; private Vector edges; private Hashtable latents; private Vector latentEdges; /////////////////// Constructors /////////////////// /** * When the ScreenShot is created, it encodes all of the needed information * about the current state of the Workbench. * @param wb The Workbench for which the ScreenShot encodes info. */ public ScreenShot(Workbench wb) { WBVariable[] vars = wb.getVariables(); varLocats = new Point[vars.length]; varSetups = new String[vars.length]; for (int i=0; i=0; i--) { WorkbenchObject from = ((WorkbenchEdge)edges.elementAt(i)).getFromObject(); WorkbenchObject to = ((WorkbenchEdge)edges.elementAt(i)).getToObject(); if ((from instanceof Latent) && (to instanceof Latent)) { latentEdges.add(LATENT+from.getName() + "->" + LATENT+to.getName()); edges.removeElementAt(i); } else if (from instanceof Latent) { latentEdges.add(LATENT+from.getName() + "->" + to.getName()); edges.removeElementAt(i); } else if (to instanceof Latent) { latentEdges.add(from.getName() + "->" + LATENT+to.getName()); edges.removeElementAt(i); } } // store the latents, and their locations latents = new Hashtable(); Vector wbLatents = wb.getLatents(); for (int i=wbLatents.size()-1; i>=0; i--) { Latent l = (Latent)wbLatents.elementAt(i); latents.put(l.getName(), l.getBounds()); } } /** * @param index The index of the WBVariable whose location is to be returned * @return The location of the WBVariable at index */ public Point getVariableLocation(int index) { return varLocats[index]; } /** * @param index The index of the WBVariable whose setup is to be returned * @return The setup of the WBVariable at index */ public String getVariableSetup(int index) { return varSetups[index]; } /** * @return A Vector containing all of the WBVariable-to-WBVariable WorkbenchEdges. */ public Vector getEdgesVector() { return edges; } /** * @return A Vector of Strings encoding the WBVariable-to-Latent (and vice versa) * WorkbenchEdges. They are encoded as name_of_from->name_of_to. */ public Vector getLatentEdgesVector() { return latentEdges; } /** * @return A Hashtable whose keys are the names of the Latents on the Workbench, * and whose associated values are the bounds of the Latent. */ public Hashtable getLatents() { return latents; } }