private void setupAttributes() {
    Color frameColor = (Color) AttributeFigure.getDefaultAttribute("FrameColor");
    Color fillColor = (Color) AttributeFigure.getDefaultAttribute("FillColor");
    Color textColor = (Color) AttributeFigure.getDefaultAttribute("TextColor");
    Integer arrowMode = (Integer) AttributeFigure.getDefaultAttribute("ArrowMode");
    String fontName = (String) AttributeFigure.getDefaultAttribute("FontName");

    FigureEnumeration k = view().selectionElements();
    while (k.hasMoreElements()) {
      Figure f = k.nextFigure();
      frameColor = (Color) f.getAttribute("FrameColor");
      fillColor = (Color) f.getAttribute("FillColor");
      textColor = (Color) f.getAttribute("TextColor");
      arrowMode = (Integer) f.getAttribute("ArrowMode");
      fontName = (String) f.getAttribute("FontName");
    }

    fFrameColor.setSelectedIndex(ColorMap.colorIndex(frameColor));
    fFillColor.setSelectedIndex(ColorMap.colorIndex(fillColor));
    // fTextColor.select(ColorMap.colorIndex(textColor));
    if (arrowMode != null) {
      fArrowChoice.setSelectedIndex(arrowMode.intValue());
    }
    if (fontName != null) {
      fFontChoice.setSelectedItem(fontName);
    }
  }
  /** Deletes the selection from the drawing. */
  protected void deleteFigures(FigureEnumeration fe) {
    while (fe.hasMoreElements()) {
      view().drawing().orphan(fe.nextFigure());
    }

    view().clearSelection();
  }
 protected void rememberFigures(FigureEnumeration toBeRemembered) {
   myAffectedFigures = new Vector();
   myAffectedFiguresCount = 0;
   while (toBeRemembered.hasMoreElements()) {
     myAffectedFigures.addElement(toBeRemembered.nextElement());
     myAffectedFiguresCount++;
   }
 }
 /** Releases all resources related to an undoable activity */
 public void release() {
   FigureEnumeration fe = getAffectedFigures();
   while (fe.hasMoreElements()) {
     fe.nextFigure().release();
   }
   myAffectedFiguresCount = 0;
   setAffectedFigures(FigureEnumerator.getEmptyEnumeration());
 }
 /**
  * Removes all children.
  *
  * @see #remove
  */
 public void removeAll() {
   FigureEnumeration k = figures();
   while (k.hasMoreElements()) {
     Figure figure = k.nextFigure();
     figure.removeFromContainer(this);
   }
   fFigures.removeAllElements();
 }
 /** Releases the figure and all its children. */
 public void release() {
   super.release();
   FigureEnumeration k = figures();
   while (k.hasMoreElements()) {
     Figure figure = k.nextFigure();
     figure.release();
   }
 }
 /**
  * Finds a figure but descends into a figure's children. Use this method to implement
  * <i>click-through</i> hit detection, that is, you want to detect the inner most figure
  * containing the given point.
  */
 public Figure findFigureInside(int x, int y) {
   FigureEnumeration k = figuresReverse();
   while (k.hasMoreElements()) {
     Figure figure = k.nextFigure().findFigureInside(x, y);
     if (figure != null) return figure;
   }
   return null;
 }
 /**
  * Finds a top level Figure. Use this call for hit detection that should not descend into the
  * figure's children.
  */
 public Figure findFigure(int x, int y) {
   FigureEnumeration k = figuresReverse();
   while (k.hasMoreElements()) {
     Figure figure = k.nextFigure();
     if (figure.containsPoint(x, y)) return figure;
   }
   return null;
 }
 /** Finds a top level Figure that intersects the given rectangle. */
 public Figure findFigure(Rectangle r) {
   FigureEnumeration k = figuresReverse();
   while (k.hasMoreElements()) {
     Figure figure = k.nextFigure();
     Rectangle fr = figure.displayBox();
     if (r.intersects(fr)) return figure;
   }
   return null;
 }
 /**
  * Finds a top level Figure, but supresses the passed in figure. Use this method to ignore a
  * figure that is temporarily inserted into the drawing.
  *
  * @param x the x coordinate
  * @param y the y coordinate
  * @param without the figure to be ignored during the find.
  */
 public Figure findFigureWithout(int x, int y, Figure without) {
   if (without == null) return findFigure(x, y);
   FigureEnumeration k = figuresReverse();
   while (k.hasMoreElements()) {
     Figure figure = k.nextFigure();
     if (figure.containsPoint(x, y) && !figure.includes(without)) return figure;
   }
   return null;
 }
 /** Inserts a vector of figures and translates them by the given offset. */
 protected void insertFigures(Vector figures, int dx, int dy) {
   FigureEnumeration e = new FigureEnumerator(figures);
   while (e.hasMoreElements()) {
     Figure figure = e.nextFigure();
     figure.moveBy(dx, dy);
     figure = fView.add(figure);
     fView.addToSelection(figure);
   }
 }
  private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {

    s.defaultReadObject();

    FigureEnumeration k = figures();
    while (k.hasMoreElements()) {
      Figure figure = k.nextFigure();
      figure.addToContainer(this);
    }
  }
 /**
  * Moves all the given figures by x and y. Doesn't announce any changes. Subclassers override
  * basicMoveBy. Clients usually call moveBy.
  *
  * @see moveBy
  */
 protected void basicMoveBy(int x, int y) {
   FigureEnumeration k = figures();
   while (k.hasMoreElements()) {
     Figure fig = k.nextFigure();
     Figure obsrvd = (Figure) fig.getAttribute("observed.figure");
     if (obsrvd == null || !includes(obsrvd)) {
       fig.moveBy(x, y);
     }
   }
 }
  /** Checks if the composite figure has the argument as one of its children. */
  public boolean includes(Figure figure) {
    if (super.includes(figure)) return true;

    FigureEnumeration k = figures();
    while (k.hasMoreElements()) {
      Figure f = k.nextFigure();
      if (f.includes(figure)) return true;
    }
    return false;
  }
 /**
  * Finds a top level Figure that intersects the given rectangle. It supresses the passed in
  * figure. Use this method to ignore a figure that is temporarily inserted into the drawing.
  */
 public Figure findFigure(Rectangle r, Figure without) {
   if (without == null) return findFigure(r);
   FigureEnumeration k = figuresReverse();
   while (k.hasMoreElements()) {
     Figure figure = k.nextFigure();
     Rectangle fr = figure.displayBox();
     if (r.intersects(fr) && !figure.includes(without)) return figure;
   }
   return null;
 }
 /**
  * Finds a figure but descends into a figure's children. It supresses the passed in figure. Use
  * this method to ignore a figure that is temporarily inserted into the drawing.
  */
 public Figure findFigureInsideWithout(int x, int y, Figure without) {
   FigureEnumeration k = figuresReverse();
   while (k.hasMoreElements()) {
     Figure figure = k.nextFigure();
     if (figure != without) {
       Figure found = figure.findFigureInside(x, y);
       if (found != null) return found;
     }
   }
   return null;
 }
  public void mouseDrag(MouseEvent e, int x, int y) {
    super.mouseDrag(e, x, y);
    fMoved = (Math.abs(x - fAnchorX) > 4) || (Math.abs(y - fAnchorY) > 4);

    if (fMoved) {
      FigureEnumeration figures = getUndoActivity().getAffectedFigures();
      while (figures.hasMoreElements()) {
        figures.nextFigure().moveBy(x - fLastX, y - fLastY);
      }
    }
    fLastX = x;
    fLastY = y;
  }
 public void moveAffectedFigures(Point startPoint, Point endPoint) {
   FigureEnumeration figures = getAffectedFigures();
   while (figures.hasMoreElements()) {
     figures.nextFigure().moveBy(endPoint.x - startPoint.x, endPoint.y - startPoint.y);
   }
 }
 /**
  * Draws all the contained figures
  *
  * @see Figure#draw
  */
 public void draw(Graphics g, boolean showGuides) {
   FigureEnumeration k = figures();
   while (k.hasMoreElements()) k.nextFigure().draw(g, showGuides);
 }