package causation.lab; import javax.swing.*; import java.awt.*; import java.util.*; /** * This JInternalFrame holds the various displays needed to show the * independencies for a particular experimental setup in the CausalityLab. * * @see ExpSetupDisplay * @see DataIndepDisplay * @see HypIndepDisplay * @version 0.9 Aug 18, 1999 * @author David Danks */ public class IndepInternalFrame extends JInternalFrame { /////////////////// Static Class Variables /////////////////// // it would be nice to have these set to reasonable values // automatically when we first start private static final int INITIAL_X = 400; private static final int INITIAL_Y = 400; /////////////////// Instance Variables /////////////////// private JScrollPane dataScroll; private JScrollPane hypScroll; private Vector dataIndeps; private Vector hypIndeps; /////////////////// Constructors /////////////////// /** * Creates an IndepInternalFrame with given Image of the experimental * setup, and one DataIndepDisplay with given parameters. No * HypIndepDisplays are created. * @param expSetup The Image of the experimental setup * @param datasetName The name of the dataset * @param datasetSize The size of the dataset (or <0, if infinite) * @param dsf The DSeparationFacts for the dataset */ public IndepInternalFrame(Image expSetup, String datasetName, int datasetSize, DSeparationFacts dsf) { this (expSetup, new DataIndepDisplay(datasetName, datasetSize, dsf)); } /** * Creates an IndepInternalFrame with given Image of the experimental * setup, and given DataIndepDisplay. No HypIndepDisplays are created. * @param expSetup The Image of the experimental setup * @param did The DataIndepDisplay to display */ public IndepInternalFrame(Image expSetup, DataIndepDisplay did) { super("Independencies", true, true, true, true); init(expSetup); addDataIndeps(did); } /** * Creates an IndepInternalFrame with given Image of the experimental * setup, and one HypIndepDisplay with given parameters. No * DataIndepDisplays are created. * @param expSetup The Image of the experimental setup * @param hypDisplay The Image of the hypothesis * @param dsf The DSeparationFacts for the dataset */ public IndepInternalFrame(Image expSetup, Image hypDisplay, DSeparationFacts dsf) { this(expSetup, new HypIndepDisplay(hypDisplay, dsf)); } /** * Creates an IndepInternalFrame with given Image of the experimental * setup, and one HypIndepDisplay with given parameters. No * DataIndepDisplays are created. * @param expSetup The Image of the experimental setup * @param hypDisplay The Image of the hypothesis * @param dsf The DSeparationFacts for the dataset * @param count The hypothesis number (for the title) */ public IndepInternalFrame(Image expSetup, Image hypDisplay, DSeparationFacts dsf, int count) { this(expSetup, new HypIndepDisplay(hypDisplay, dsf, count)); } /** * Creates an IndepInternalFrame with given Image of the experimental * setup, and given HypIndepDisplay. No DataIndepDisplays are created. * @param expSetup The Image of the experimental setup * @param hid The HypIndepDisplay to display */ public IndepInternalFrame(Image expSetup, HypIndepDisplay hid) { super("Independencies", true, true, true, true); init(expSetup); addHypIndeps(hid); } /** * This method is a helper method that creates and sets up the * IndepInternalFrame with only the ExpSetupDisplay. This method allows * the constructors to be quite simple. * @param expSetup The Image of the experimental setup */ private void init(Image expSetup) { // create the Vectors to hold the displays dataIndeps = new Vector(); hypIndeps = new Vector(); // first, create the left-hand Components and JSplitPane ExpSetupDisplay esd = new ExpSetupDisplay(expSetup); dataScroll = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); dataScroll.setColumnHeaderView(new JLabel("Data Independencies", SwingConstants.CENTER)); JSplitPane lhs = new JSplitPane(JSplitPane.VERTICAL_SPLIT, esd, dataScroll); lhs.setDividerLocation(esd.getPreferredSize().height); // now, create the right-hand side, and combine them hypScroll = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); hypScroll.setColumnHeaderView(new JLabel("Hypothesis Independencies", SwingConstants.CENTER)); hypScroll.setPreferredSize(new Dimension(INITIAL_X-esd.getPreferredSize().width, INITIAL_Y)); JSplitPane total = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, lhs, hypScroll); // and set the content pane to the whole thing // right now, I'm just picking setSize numbers. Getting the // actual ones would be nice setSize(INITIAL_X, INITIAL_Y); getContentPane().add(total, "Center"); } /////////////////// Instance Methods /////////////////// /** * Add a data independence display with given parameters * @param dataName The name of the dataset * @param dataSize The size of the dataset (or <0, if infinite) * @param dsf The DSeparationFacts for the dataset */ public void addDataIndeps(String dataName, int dataSize, DSeparationFacts dsf) { addDataIndeps(new DataIndepDisplay(dataName, dataSize, dsf)); } /** * Add the given data independence display * @param did The DataIndepDisplay to add */ public void addDataIndeps(DataIndepDisplay did) { dataIndeps.addElement(did); JPanel panel = new JPanel(new GridLayout(dataIndeps.size(), 1)); for (int i=0; i<=dataIndeps.size()-1; i++) { panel.add((DataIndepDisplay)dataIndeps.elementAt(i)); } dataScroll.setViewportView(panel); } /** * Add a hypothesis independence display with given parameters * @param display The Image of the hypothesis * @param dsep The DSeparationFacts for the hypothesis */ public void addHypIndeps(Image display, DSeparationFacts dsep) { addHypIndeps(new HypIndepDisplay(display, dsep)); } /** * Add a hypothesis independence display with given parameters * @param display The Image of the hypothesis * @param dsep The DSeparationFacts for the hypothesis * @param count The hypothesis number (for the title) */ public void addHypIndeps(Image display, DSeparationFacts dsep, int count) { addHypIndeps(new HypIndepDisplay(display, dsep, count)); } /** * Add the given hypothesis independence display * @param hid The HypIndepDisplay to add */ public void addHypIndeps(HypIndepDisplay hid) { // for the hypothesis indeps, we need ceiling(sqrt(number)) // rows and columns to lay them out appropriately. hypIndeps.addElement(hid); int side = (int)Math.ceil(Math.sqrt((double)hypIndeps.size())); JPanel panel = new JPanel(new GridLayout(side, side)); for (int i=0; i<=hypIndeps.size()-1; i++) { panel.add((HypIndepDisplay)hypIndeps.elementAt(i)); } hypScroll.setViewportView(panel); } /** * @return The number of HypIndepDisplays */ public int getNumberHypIndeps() { return hypIndeps.size(); } }