예제 #1
0
  public static void main(String[] args) {

    // collection List<>
    List<Figure> figures = new ArrayList<Figure>();
    Disque d1 = new Disque(5, 6, 3);
    Rectangle r1 = new Rectangle(2, 3, 5, 3);
    Carre s1 = new Carre(1, 1, 4);

    figures.add(d1);
    figures.add(r1);
    figures.add(s1);
    double totArea = 0;
    Iterator<Figure> iterator = figures.iterator();
    while (iterator.hasNext()) {
      totArea = totArea + iterator.next().getArea();
    }

    totArea = 0;

    // tableau
    Figure tableau[] = {d1, r1, s1};
    for (Figure e : tableau) {
      totArea = totArea + e.getArea();
    }

    System.out.println("L'aire totale est " + totArea);
  }
 protected void updateHoverHandles(@Nullable DrawingView view, @Nullable Figure f) {
   if (f != hoverFigure) {
     Rectangle r = null;
     if (hoverFigure != null && hoverFigure.isSelectable()) {
       for (Handle h : hoverHandles) {
         if (r == null) {
           r = h.getDrawingArea();
         } else {
           r.add(h.getDrawingArea());
         }
         h.setView(null);
         h.dispose();
       }
       hoverHandles.clear();
     }
     hoverFigure = f;
     if (hoverFigure != null) {
       hoverHandles.addAll(hoverFigure.createHandles(-1));
       for (Handle h : hoverHandles) {
         h.setView(view);
         if (r == null) {
           r = h.getDrawingArea();
         } else {
           r.add(h.getDrawingArea());
         }
       }
     }
     if (r != null) {
       r.grow(1, 1);
       fireAreaInvalidated(r);
     }
   }
 }
예제 #3
0
  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);
    }
  }
예제 #4
0
 private void setupAttributes() {
   Color frameColor =
       (Color) AttributeFigure.getDefaultAttribute(FigureAttributeConstant.FRAME_COLOR);
   Color fillColor =
       (Color) AttributeFigure.getDefaultAttribute(FigureAttributeConstant.FILL_COLOR);
   Integer arrowMode =
       (Integer) AttributeFigure.getDefaultAttribute(FigureAttributeConstant.ARROW_MODE);
   String fontName =
       (String) AttributeFigure.getDefaultAttribute(FigureAttributeConstant.FONT_NAME);
   FigureEnumeration fe = view().selection();
   while (fe.hasNextFigure()) {
     Figure f = fe.nextFigure();
     frameColor = (Color) f.getAttribute(FigureAttributeConstant.FRAME_COLOR);
     fillColor = (Color) f.getAttribute(FigureAttributeConstant.FILL_COLOR);
     arrowMode = (Integer) f.getAttribute(FigureAttributeConstant.ARROW_MODE);
     fontName = (String) f.getAttribute(FigureAttributeConstant.FONT_NAME);
   }
   fFrameColor.setSelectedIndex(ColorMap.colorIndex(frameColor));
   fFillColor.setSelectedIndex(ColorMap.colorIndex(fillColor));
   if (arrowMode != null) {
     fArrowChoice.setSelectedIndex(arrowMode.intValue());
   }
   if (fontName != null) {
     fFontChoice.setSelectedItem(fontName);
   }
 }
  @Override
  public void mouseMoved(MouseEvent evt) {
    Point point = evt.getPoint();
    updateCursor(editor.findView((Container) evt.getSource()), point);
    DrawingView view = editor.findView((Container) evt.getSource());
    updateCursor(view, point);
    if (view == null || editor.getActiveView() != view) {
      clearHoverHandles();
    } else {
      // Search first, if one of the selected figures contains
      // the current mouse location. Only then search for other
      // figures. This search sequence is consistent with the
      // search sequence of the SelectionTool.
      Figure figure = null;
      Point2D.Double p = view.viewToDrawing(point);
      for (Figure f : view.getSelectedFigures()) {
        if (f.contains(p)) {
          figure = f;
        }
      }
      if (figure == null) {
        figure = view.findFigure(point);
        Drawing drawing = view.getDrawing();
        while (figure != null && !figure.isSelectable()) {
          figure = drawing.findFigureBehind(p, figure);
        }
      }

      updateHoverHandles(view, figure);
    }
  }
예제 #6
0
  public Rectangle2D.Double calculateLayout(
      CompositeFigure compositeFigure, Point2D.Double anchor, Point2D.Double lead) {
    Rectangle2D.Double bounds = null;

    for (Figure child : compositeFigure.getChildren()) {
      Locator locator = getLocator(child);
      Rectangle2D.Double r;
      if (locator == null) {
        r = child.getBounds();
      } else {
        Point2D.Double p = locator.locate(compositeFigure);
        Dimension2DDouble d = child.getPreferredSize();
        r = new Rectangle2D.Double(p.x, p.y, d.width, d.height);
      }
      if (!r.isEmpty()) {
        if (bounds == null) {
          bounds = r;
        } else {
          bounds.add(r);
        }
      }
    }

    return (bounds == null) ? new Rectangle2D.Double() : bounds;
  }
예제 #7
0
  @Override
  public void keyPressed(KeyEvent evt) {
    Figure f = getOwner();
    if (f.isTransformable()) {
      AffineTransform tx = new AffineTransform();

      switch (evt.getKeyCode()) {
        case KeyEvent.VK_UP:
          tx.translate(0, -1);
          evt.consume();
          break;
        case KeyEvent.VK_DOWN:
          tx.translate(0, +1);
          evt.consume();
          break;
        case KeyEvent.VK_LEFT:
          tx.translate(-1, 0);
          evt.consume();
          break;
        case KeyEvent.VK_RIGHT:
          tx.translate(+1, 0);
          evt.consume();
          break;
      }
      f.willChange();
      f.transform(tx);
      f.changed();
      fireUndoableEditHappened(new TransformEdit(f, tx));
    }
  }
 private Figure findConnectableFigure(Point2D.Double p, Drawing drawing) {
   for (Figure f : drawing.getFiguresFrontToBack()) {
     if (!f.includes(getOwner()) && f.canConnect() && f.contains(p)) {
       return f;
     }
   }
   return null;
 }
예제 #9
0
 public void initMoves() {
   for (Figure f : this.BlackFigures) {
     f.addMoves();
   }
   for (Figure f : this.WhiteFigures) {
     f.addMoves();
   }
 }
 public Figure basicRemoveChild(int index) {
   Figure figure = children.get(index);
   children.remove(index);
   quadTree.remove(figure);
   figure.removeFigureListener(figureHandler);
   needsSorting = true;
   return figure;
 }
예제 #11
0
 /**
  * Removes all children.
  *
  * @see #remove
  */
 public void removeAll() {
   FigureEnumeration k = figures();
   while (k.hasMoreElements()) {
     Figure figure = k.nextFigure();
     figure.removeFromContainer(this);
   }
   fFigures.removeAllElements();
 }
예제 #12
0
 /**
  * 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;
 }
예제 #13
0
 /** Releases the figure and all its children. */
 public void release() {
   super.release();
   FigureEnumeration k = figures();
   while (k.hasMoreElements()) {
     Figure figure = k.nextFigure();
     figure.release();
   }
 }
예제 #14
0
 /** Replaces a figure in the drawing without removing it from the drawing. */
 public synchronized void replace(Figure figure, Figure replacement) {
   int index = fFigures.indexOf(figure);
   if (index != -1) {
     replacement.addToContainer(this); // will invalidate figure
     figure.changed();
     fFigures.setElementAt(replacement, index);
   }
 }
예제 #15
0
 /**
  * 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;
 }
예제 #16
0
 /** 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;
 }
 /** 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);
   }
 }
예제 #18
0
  private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {

    s.defaultReadObject();

    FigureEnumeration k = figures();
    while (k.hasMoreElements()) {
      Figure figure = k.nextFigure();
      figure.addToContainer(this);
    }
  }
예제 #19
0
 /**
  * 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);
     }
   }
 }
예제 #20
0
  /** 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;
  }
예제 #21
0
 /**
  * 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;
 }
 @Override
 public Figure findFigureInside(Point2D.Double p) {
   Collection<Figure> c = quadTree.findContains(p);
   for (Figure f : getFiguresFrontToBack()) {
     if (c.contains(f) && f.contains(p)) {
       return f.findFigureInside(p);
     }
   }
   return null;
 }
 private Figure findConnectableFigure(int x, int y, Drawing drawing) {
   FigureEnumeration fe = drawing.figuresReverse();
   while (fe.hasNextFigure()) {
     Figure figure = fe.nextFigure();
     if (!figure.includes(getConnection()) && figure.canConnect() && figure.containsPoint(x, y)) {
       return figure;
     }
   }
   return null;
 }
 /** Finds a connection end figure. */
 protected Connector findConnectionTarget(int x, int y, Drawing drawing) {
   Figure target = findConnectableFigure(x, y, drawing);
   if ((target != null)
       && target.canConnect()
       && !target.includes(owner())
       && getConnection().canConnect(owner(), target)) {
     return findConnector(x, y, target);
   }
   return null;
 }
예제 #25
0
 /**
  * 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;
 }
예제 #26
0
  /** Check existance of figure in the drawing */
  public boolean figureExists(Figure inf, FigureEnumeration fe) {
    while (fe.hasNextFigure()) {
      Figure figure = fe.nextFigure();

      if (figure.includes(inf)) {
        return true;
      }
    }

    return false;
  }
 /** Since this is an add operation, figures can only be released if it has been undone. */
 public void release() {
   if (undone == true) {
     FigureEnumeration fe = getAffectedFigures();
     while (fe.hasNextFigure()) {
       Figure f = fe.nextFigure();
       getDrawingView().drawing().remove(f);
       f.release();
     }
   }
   setAffectedFigures(CH.ifa.draw.standard.FigureEnumerator.getEmptyEnumeration());
 }
  private Connector findConnectionTarget(int x, int y, Drawing drawing) {
    Figure target = findConnectableFigure(x, y, drawing);

    if ((target != null)
        && target.canConnect()
        && target != fOriginalTarget
        && !target.includes(owner())
        && getConnection().canConnect(source().owner(), target)) {
      return findConnector(x, y, target);
    }
    return null;
  }
 private Figure findConnectableFigure(int x, int y, Drawing drawing) {
   FigureEnumeration k = drawing.figuresReverse();
   while (k.hasMoreElements()) {
     Figure figure = k.nextFigure();
     if (!figure.includes(getConnection()) && figure.canConnect()) {
       if (figure.containsPoint(x, y)) {
         return figure;
       }
     }
   }
   return null;
 }
 /**
  * Hook method which can be overriden by subclasses to provide specialised behaviour in the event
  * of a popup trigger.
  */
 protected void handlePopupMenu(MouseEvent e, int x, int y) {
   Figure figure = drawing().findFigure(e.getX(), e.getY());
   if (figure != null) {
     Object attribute = figure.getAttribute(Figure.POPUP_MENU);
     if (attribute == null) {
       figure = drawing().findFigureInside(e.getX(), e.getY());
     }
     if (figure != null) {
       showPopupMenu(figure, e.getX(), e.getY(), e.getComponent());
     }
   }
 }