import javax.swing.*; import java.awt.*; import java.beans.*; /** This class can draw a rectangle within a specified area of an outer {@link JPanel}. * The rectagle changes color based on the signals and colors provided. */ public class RectViz implements Scribbler { private JPanel outer; private Color color; private double dx, dy, dwidth, dheight; /** Constructor with parameters as follows * @param pcs This class must register as a {@link PropertyChangeListener} for each signal provided * @param dx fraction of outer.getWidth() for x coordinate * @param dy fraction of outer.getHeight() for y coordinate * @param dwidth fraction of outer.getWidth() for width * @param dheight fraction of outer.getHeight() for height * @param signals array of Strings, names of signals to be received * @param colors array of Colors, one for each signal, the color to set the rectagle * @param initColor the starting Color for the rectangle */ public RectViz(PropertyChangeSupport pcs, double dx, double dy, double dwidth, double dheight, JPanel outer, String[] signals, Color[] colors, Color initColor) { // I'll capture the instance vars for you this.color = initColor; this.dx = dx; this.dy = dy; this.dwidth = dwidth; this.dheight = dheight; this.outer = outer; // below, arrange for each signal to be registered with code that // calls setColor with the appropriate color // do this by calling the register helper method } /** A useful helper method that can be called from an inner class {@link PropertyChangeListener} from * the register method. * Set the instance variable for the color and call outer.repaint(). That in turn will call * draw in this class, because paintComponent is overriden in the outer {@link JPanel}. */ protected void setColor(Color c) { // FILL IN } /** Can be overriden to change the way the color is chosen */ protected Color getColor() { return color; } /** A very useful helper method. Implement it, thus simplifying registration of PropertyChangeListeners * from the constructor. This method is protected only so it will show up in the JavaDoc. * Using the pcs, add a ProeprtyChangeListener that simply calls setColor(c) (another helper method). */ protected final void register(PropertyChangeSupport pcs, final String s, final Color c) { } /** Given the supplied {@link Graphics} object *
g a setColor command for the appropriate color,
*