package causation.lab; // packages import javax.swing.*; import javax.swing.plaf.*; import java.awt.*; import java.net.*; // custom classes import causation.lab.WorkbenchObject; import causation.lab.WBVariable; import causation.lab.WorkbenchEdge; import causation.lab.plaf.RandomizerUI; /** *

* This object encodes the information about a Randomizer, that can be * attached to a WBVariable on a Workbench. The default icon for the * Randomizer is currently a die showing a '3'. Setting the codebase to * something other than null tells the Randomizer to use an Image from a * file. The default file names are currently correct for the * CausalityLab. Note that there is currently no support for dynamically * changing the file names. These is always an WorkbenchEdge between the Randomizer * and its WBVariable, and a reference to that WorkbenchEdge is kept in the * Randomizer. * Copyright 1999 by David Danks. All rights reserved. *

* * @see RandomizerUI * @see WorkbenchObject * @see WorkbenchEdge * @version 1.0 June 23, 1999 * @author David Danks */ public class Randomizer extends WorkbenchObject { /////////////////// Class Variables /////////////////// private static final String UIClassID = "causation.lab.plaf.RandomizerUI"; /////////////////// Instance Variables /////////////////// private WBVariable target; private WorkbenchEdge edge; private boolean selected = false; private boolean experimenting = true; /////////////////// Constructors /////////////////// /** * This is the only constructor. It creates a Randomizer attached to the * WBVariable target. * @param target The WBVariable the Randomizer is attached to */ public Randomizer(WBVariable target) { this.target = target; edge = new WorkbenchEdge(this, target); updateUI(); } /////////////////// Instance Methods /////////////////// /** * This method is used to set the codebase for loading icons. If it is * set to null, then the Randomizer uses its default image. * @param codebase The new codebase for loading icons. */ public void setCodebase(URL codebase) { ((RandomizerUI)ui).setCodebase(codebase); } /** * @return The URL used as the codebase for loading Icons */ public URL getCodebase() { return ((RandomizerUI)ui).getCodebase(); } /** * @return The disabled Randomizer image (for painting independence * graphs). As of now, it can't return null. */ public Icon getDisabledRandomizerIcon() { return ((RandomizerUI)ui).getDisabledRandomizerIcon(); } /** * @return The WorkbenchEdge connecting this Randomizer to its WBVariable */ public WorkbenchEdge getEdge() { return edge; } /** * @param newEdge The new WorkbenchEdge connecting this Randomizer to a WBVariable. * The target WBVariable is automatically updated. */ public void setEdge(WorkbenchEdge newEdge) { this.edge = newEdge; setTarget((WBVariable)newEdge.getToObject()); } /** * @return The WBVariable this Randomizer is attached to */ public WBVariable getTarget() { return target; } /** * @param newTarget The new WBVariable the Randomizer should attach to. * Note that the WorkbenchEdge is automatically updated. */ public void setTarget(WBVariable newTarget) { this.target = newTarget; setEdge(new WorkbenchEdge(this, newTarget)); } /** * @return Whether the Randomizer is currently selected */ public boolean isSelected() { return selected; } /** * @param b Whether the Randomizer is actually selected */ public void setSelected(boolean b) { this.selected = b; edge.setSelected(b); } /** * @return Whether the Randomizer can currently be used in an experiment. */ public boolean isExperimenting() { return experimenting; } /** * @param b Whether the Randomzier can be used in an experiment. */ public void setExperimenting(boolean b) { this.experimenting = b; edge.setEnabled(b); } /** * This method returns the outline of the Randomizer. It is required since * we are subclassing WorkbenchObject, and is used by WorkbenchEdges. * @return The outline of the Randomizer. */ public Shape getPerimeter() { return getBounds(); } /** * Note: this method will (if appropriate) load the icons * @return The preferred size of the Randomizer */ public Dimension getPreferredSize() { return ((RandomizerUI)ui).getPreferredSize(this); } /** * Note: this method will (if appropriate) load the icons * @return The minimum size of the Randomizer */ public Dimension getMinimumSize() { return ((RandomizerUI)ui).getMinimumSize(this); } /** * @return false always (to avoid covering the Workbench) */ public boolean isOpaque() { return false; } // UI Methods /** * @param ui The RandomizerUI to attach to this Randomizer */ public void setUI(RandomizerUI ui) { super.setUI(ui); } /** * Sets up the UI appropriately */ public void updateUI() { setUI((RandomizerUI)UIManager.getUI(this)); invalidate(); } /** * @return The String identifying the UI for this Class */ public String getUIClassID() { return UIClassID; } }