/** Remove all trees from this figure. */
 public void removeAllTrees() {
   for (FigureElement figEl : treeElements) {
     super.removeElement(figEl);
     FigureElement scale = scaleElements.get(figEl);
     if (scale != null) super.removeElement(scale);
   }
   treeElements.clear();
   scaleElements.clear();
 }
 /**
  * Remove the tree element and associated scale element from this figure.
  *
  * @param treeToRemove
  */
 public void removeTree(TreeElement treeToRemove) {
   FigureElement scale = scaleElements.get(treeToRemove);
   if (scale != null) {
     scaleElements.remove(treeToRemove);
     super.removeElement(scale);
   }
   super.removeElement(treeToRemove);
   treeElements.remove(treeToRemove);
   layoutTrees();
 }
 /**
  * Remove the scale element associated with the given tree element
  *
  * @param tel
  */
 private void removeScaleForTree(TreeElement tel) {
   FigureElement el = scaleElements.get(tel);
   if (el != null) {
     scaleElements.remove(tel);
     super.removeElement(el);
   }
 }
  public void componentResized(ComponentEvent arg0) {
    boundsRect.width = getWidth();
    boundsRect.height = getHeight();

    for (TreeElement treeElement : treeElements) {
      treeElement.setDrawBounds();
    }

    super.componentResized(arg0);

    repaint();
  }
  public void addTree(DrawableTree newTree) {
    TreeElement newElement = new TreeElement(this);
    newTree.setScaleType(DrawableTree.NO_SCALE_BAR);
    newElement.setScale(getWidth(), getHeight(), null);
    newElement.setTree(newTree);
    treeElements.add(newElement);
    super.addElement(newElement);

    FigureElement scaleElement = null;
    if (currentScaleType == DrawableTree.SCALE_AXIS) {
      scaleElement = new ScaleAxisElement(this);

      scaleElement.setZPosition(-5); // draw underneath the tree so grid lines aren't on top
      ((ScaleAxisElement) scaleElement).setTreeDrawer(newElement.getTreeDrawer());
      addElement(scaleElement);
      scaleElements.put(newElement, scaleElement);
    }

    if (currentScaleType == DrawableTree.SCALE_BAR) {
      scaleElement = new ScaleBarElement(this);
      scaleElement.setMobile(true);
      ((ScaleBarElement) scaleElement).setTreeDrawer(newElement.getTreeDrawer());
      addElement(scaleElement);
      scaleElements.put(newElement, scaleElement);
    }

    layoutTrees();

    if (currentScaleType == DrawableTree.SCALE_AXIS && scaleElement != null) {
      scaleElement.setBounds(
          newElement.getX(), 0.9, 0.1, 0.01); // Width and height parts are ignored
    }

    if (currentScaleType == DrawableTree.SCALE_BAR && scaleElement != null) {
      scaleElement.setBounds(
          Math.max(0, newElement.getX() + newElement.getWidth() / 2.0 - 0.05),
          0.9,
          0.1,
          0.1); // Width and height parts are ignored
    }
  }