package causation.lab; import javax.swing.*; import java.awt.*; /** * This class displays an experimental setup. * * @see IndepInternalFrame * @version 0.9 Aug 18, 1999 * @author David Danks */ public class ExpSetupDisplay extends JComponent { /////////////////// Static Class Variables /////////////////// private static final String TEXT = "Experimental Setup"; private static final int LINE_THICKNESS = 3; private static final int LINE_SPACING = 5; private static final Color LABEL = new Color(102, 102, 102); private static final Color BACKGROUND = Color.white; private static final Font FONT = new Font("Dialog", Font.BOLD, 14); private static final Insets MARGIN = new Insets(10, 10, 10, 10); /////////////////// Instance Variables /////////////////// private Image display; /////////////////// Constructors /////////////////// /** * This creates an ExpSetupDisplay with the given Image * @param im The Image to display */ public ExpSetupDisplay(Image im) { display = im; setFont(FONT); } /////////////////// Instance Methods /////////////////// /** * @return The preferred size of this ExpSetupDisplay */ public Dimension getPreferredSize() { FontMetrics fm = getFontMetrics(getFont()); int width = 0; int height = 0; // account for text width = Math.max(width, fm.stringWidth(TEXT)); height += fm.getHeight(); // account for line height += 2*LINE_SPACING+LINE_THICKNESS; // account for image width = Math.max(width, display.getWidth(this)); height += display.getHeight(this); // account for borders width += MARGIN.left+MARGIN.right; height += MARGIN.top+MARGIN.bottom; return new Dimension(width, height); } /** * @return The minimum size of the ExpSetupDisplay (=preferred size) */ public Dimension getMinimumSize() { return getPreferredSize(); } /** * @return true, since we paint the background */ public boolean isOpaque() { return true; } /** * Does the painting of the display. * @param g The Graphics context in which to paint the ExpSetupDisplay */ public void paintComponent(Graphics g) { FontMetrics fm = getFontMetrics(getFont()); // fill in the background g.setColor(BACKGROUND); g.fillRect(0, 0, getWidth(), getHeight()); // draw the label g.setColor(LABEL); int xInset = (getWidth()-fm.stringWidth(TEXT))/2; g.drawString(TEXT, xInset, MARGIN.top+fm.getAscent()); // draw the line int yOffset = MARGIN.top+fm.getHeight()+LINE_SPACING; for (int i=0; i