/** 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();
 }