/**
  * Adds the specified component to the container.
  *
  * @param c The component to add.
  */
 private void addComponent(JComponent c) {
   Container container = window.getContentPane();
   Component[] comps = container.getComponents();
   boolean in = false;
   for (int i = 0; i < comps.length; i++) {
     if (comps[i].equals(c)) {
       in = true;
       break;
     }
   }
   if (!in) {
     container.add(c, BorderLayout.CENTER);
     window.repaint();
   }
 }
 /** Repaints the window according to whether the window is currently collapsed or expanded. */
 void updateCollapsedState() {
   SizeButton button = (SizeButton) titleBar.getButton(TitleBar.SIZE_BUTTON);
   if (window.isCollapsed()) {
     removeComponent(canvas);
     Dimension d = new Dimension(window.getWidth(), TitleBar.HEIGHT + 2 * BORDER_THICKNESS);
     titleBar.setPreferredSize(d);
     button.setActionType(SizeButton.EXPAND);
     window.setSize(d.width, d.height);
   } else {
     addComponent(canvas);
     button.setActionType(SizeButton.COLLAPSE);
     Dimension dT = titleBar.getPreferredSize();
     Dimension dW = window.getRestoreSize();
     window.setSize(dT.width, dW.height);
   }
   window.validate();
   window.repaint();
 }