package causation.lab; // packages import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.net.*; // no custom classes /** *
* This class contains the code for the two bars in the CausalityLab.
* Its primary function is to lay out the buttons correctly, disable them
* when the bar is disabled, and fire PropertyChangeEvent
s
* when buttons are pressed.
*
* The following PropertyChangeEvent
s are sent by this class:
*
* Copyright 1999 by David Danks. All rights reserved.
* * @version 1.0 May 15, 1999 * @author David Danks */ public class ButtonBar extends JPanel implements ActionListener, LayoutManager { /////////////////// Class Variables /////////////////// // types of ButtonBars public static final int SETUP_GATHER_DATA_BAR = 0; public static final int HYPOTHESIZE_PREDICT_BAR = 1; // Label text private static final String[] SGD_LABEL = {"Setup Experiment", "& Gather Data"}; private static final String[] HP_LABEL = {"Hypothesize &", "Make Predictions"}; private static final Font FONT = new Font("Dialog", Font.BOLD, 11); // Tooltip text private static final String LOCK_TOOLTIP = "Lock a variable"; private static final String RAND_TOOLTIP = "Randomize a variable"; private static final String DATA_TOOLTIP = "Collect a dataset"; private static final String ARROW_TOOLTIP = "Draw an arrow"; private static final String LATENT_TOOLTIP = "Add a latent variable"; private static final String INDEP_TOOLTIP = "Get independence facts"; // icon directory private static final String DIR = "icons/"; // SGD Button icons private static final String LOCK_ENABLED = "lockup.gif"; private static final String LOCK_SELECTED = "lockdown.gif"; private static final String LOCK_ROLLOVER = "lockroll.gif"; private static final String LOCK_DISABLED = "lockoff.gif"; private static final String RAND_ENABLED = "randup.gif"; private static final String RAND_SELECTED = "randdown.gif"; private static final String RAND_ROLLOVER = "randroll.gif"; private static final String RAND_DISABLED = "randoff.gif"; private static final String DATA_ENABLED = "dataup.gif"; private static final String DATA_SELECTED = "datadown.gif"; private static final String DATA_ROLLOVER = "dataroll.gif"; private static final String DATA_DISABLED = "dataoff.gif"; // HP Button icons private static final String ARROW_ENABLED = "arrowup.gif"; private static final String ARROW_SELECTED = "arrowdown.gif"; private static final String ARROW_ROLLOVER = "arrowroll.gif"; private static final String ARROW_DISABLED = "arrowoff.gif"; private static final String LATENT_ENABLED = "latentup.gif"; private static final String LATENT_SELECTED = "latentdown.gif"; private static final String LATENT_ROLLOVER = "latentroll.gif"; private static final String LATENT_DISABLED = "latentoff.gif"; private static final String INDEP_ENABLED = "indepup.gif"; private static final String INDEP_SELECTED = "indepdown.gif"; private static final String INDEP_ROLLOVER = "indeproll.gif"; private static final String INDEP_DISABLED = "indepoff.gif"; // Background info private static final Color ENABLED_BACKGROUND = new Color(153, 204, 153); private static final Color DISABLED_BACKGROUND = new Color(204, 204, 204); private static final Color LABEL = new Color(102, 102, 102); private static final Insets MARGIN = new Insets(3, 3, 3, 3); private static final int UPPER_PIXEL_GAP = 15; private static final int LOWER_PIXEL_GAP = UPPER_PIXEL_GAP; /////////////////// Instance Variables /////////////////// // barEnabled tells us whether the bar is enabled; buttonActivated // tells us whether we can use the button or not. private boolean barEnabled = true; private boolean[] buttonActivated = new boolean[4]; private String[] label = null; private JToggleButton toggled = null; private int type; private URL codebase; /////////////////// Constructors /////////////////// // public ButtonBar() { this(SETUP_GATHER_DATA_BAR, new URL()); } // public ButtonBar(int type) { this(type, new URL()); } /** * This constructor creates a ButtonBar of typetype
, and
* loads images from codebase
* @param type The type of ButtonBar
* @param codebase The codebase for loading images
*/
public ButtonBar(int type, URL codebase) {
this.type = type;
this.codebase = codebase;
setLayout(this);
setFont(FONT);
for (int i=0; i