Ejemplo n.º 1
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);
   }
 }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
0
 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;
 }
 public Figure basicRemoveChild(int index) {
   Figure figure = children.get(index);
   children.remove(index);
   quadTree.remove(figure);
   figure.removeFigureListener(figureHandler);
   needsSorting = true;
   return figure;
 }
 @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;
 }
 public java.util.List<Figure> findFiguresWithin(Rectangle2D.Double bounds) {
   LinkedList<Figure> contained = new LinkedList<Figure>();
   for (Figure f : children) {
     Rectangle2D r = f.getBounds();
     if (AttributeKeys.TRANSFORM.get(f) != null) {
       r = AttributeKeys.TRANSFORM.get(f).createTransformedShape(r).getBounds2D();
     }
     if (f.isVisible() && bounds.contains(r)) {
       contained.add(f);
     }
   }
   return contained;
 }
 public Figure findFigureBehind(Point2D.Double p, Figure figure) {
   boolean isBehind = false;
   for (Figure f : getFiguresFrontToBack()) {
     if (isBehind) {
       if (f.isVisible() && f.contains(p)) {
         return f;
       }
     } else {
       isBehind = figure == f;
     }
   }
   return null;
 }
 public Figure findFigureBehind(Point2D.Double p, Collection<Figure> figures) {
   int inFrontOf = figures.size();
   for (Figure f : getFiguresFrontToBack()) {
     if (inFrontOf == 0) {
       if (f.isVisible() && f.contains(p)) {
         return f;
       }
     } else {
       if (figures.contains(f)) {
         inFrontOf--;
       }
     }
   }
   return null;
 }
 public void sendToBack(Figure figure) {
   if (children.remove(figure)) {
     children.add(0, figure);
     needsSorting = true;
     fireAreaInvalidated(figure.getDrawingArea());
   }
 }
Ejemplo n.º 10
0
 public void bringToFront(Figure figure) {
   if (children.remove(figure)) {
     children.add(figure);
     needsSorting = true;
     fireAreaInvalidated(figure.getDrawingArea());
   }
 }
Ejemplo n.º 11
0
  private Connector findConnectionTarget(Point2D.Double p, Drawing drawing) {
    Figure targetFigure = findConnectableFigure(p, drawing);

    if (getSource() == null && targetFigure != null) {
      return findConnector(p, targetFigure, getOwner());
    } else if (targetFigure != null) {
      Connector target = findConnector(p, targetFigure, getOwner());
      if ((targetFigure != null)
          && targetFigure.canConnect()
          && targetFigure != savedTarget
          && !targetFigure.includes(getOwner())
          && (canConnect(getSource(), target)
              || getTarget() != null && getTarget().getOwner() == targetFigure)) {
        return target;
      }
    }
    return null;
  }
Ejemplo n.º 12
0
 public Figure findFigure(Point2D.Double p) {
   Collection<Figure> c = quadTree.findContains(p);
   switch (c.size()) {
     case 0:
       return null;
     case 1:
       {
         Figure f = c.iterator().next();
         return (f.contains(p)) ? f : null;
       }
     default:
       {
         for (Figure f : getFiguresFrontToBack()) {
           if (c.contains(f) && f.contains(p)) return f;
         }
         return null;
       }
   }
 }
Ejemplo n.º 13
0
 public Figure findFigureExcept(Point2D.Double p, Collection ignore) {
   Collection<Figure> c = quadTree.findContains(p);
   switch (c.size()) {
     case 0:
       {
         return null;
       }
     case 1:
       {
         Figure f = c.iterator().next();
         return (!ignore.contains(f) || !f.contains(p)) ? null : f;
       }
     default:
       {
         for (Figure f : getFiguresFrontToBack()) {
           if (!ignore.contains(f) && f.contains(p)) return f;
         }
         return null;
       }
   }
 }
Ejemplo n.º 14
0
  public Rectangle2D.Double layout(
      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, child);
        Dimension2DDouble d = child.getPreferredSize();
        r = new Rectangle2D.Double(p.x, p.y, d.width, d.height);
      }
      child.willChange();
      child.setBounds(
          new Point2D.Double(r.getMinX(), r.getMinY()),
          new Point2D.Double(r.getMaxX(), r.getMaxY()));
      child.changed();
      if (!r.isEmpty()) {
        if (bounds == null) {
          bounds = r;
        } else {
          bounds.add(r);
        }
      }
    }

    return (bounds == null) ? new Rectangle2D.Double() : bounds;
  }
Ejemplo n.º 15
0
 protected Point2D.Double chop(Figure target, Point2D.Double from) {
   target = getConnectorTarget(target);
   Rectangle2D.Double r = target.getBounds();
   if (STROKE_COLOR.get(target) != null) {
     double grow;
     switch (STROKE_PLACEMENT.get(target)) {
       case CENTER:
       default:
         grow = AttributeKeys.getStrokeTotalWidth(target) / 2d;
         break;
       case OUTSIDE:
         grow = AttributeKeys.getStrokeTotalWidth(target);
         break;
       case INSIDE:
         grow = 0d;
         break;
     }
     Geom.grow(r, grow, grow);
   }
   return Geom.angleToPoint(r, Geom.pointToAngle(r, from));
 }
Ejemplo n.º 16
0
 /**
  * Updates the list of connectors that we draw when the user moves or drags the mouse over a
  * figure to which can connect.
  */
 public void repaintConnectors() {
   Rectangle2D.Double invalidArea = null;
   for (Connector c : connectors) {
     if (invalidArea == null) {
       invalidArea = c.getDrawingArea();
     } else {
       invalidArea.add(c.getDrawingArea());
     }
   }
   connectors =
       (connectableFigure == null)
           ? new java.util.LinkedList<Connector>()
           : connectableFigure.getConnectors(getOwner());
   for (Connector c : connectors) {
     if (invalidArea == null) {
       invalidArea = c.getDrawingArea();
     } else {
       invalidArea.add(c.getDrawingArea());
     }
   }
   if (invalidArea != null) {
     view.getComponent().repaint(view.drawingToView(invalidArea));
   }
 }
Ejemplo n.º 17
0
 public void basicAdd(int index, Figure figure) {
   children.add(index, figure);
   quadTree.add(figure, figure.getDrawingArea());
   figure.addFigureListener(figureHandler);
   needsSorting = true;
 }
Ejemplo n.º 18
0
 public void draw(Graphics2D g, Collection<Figure> c) {
   for (Figure f : c) {
     f.draw(g);
   }
 }
Ejemplo n.º 19
0
 protected Connector findConnector(Point2D.Double p, Figure f, ConnectionFigure prototype) {
   return f.findConnector(p, prototype);
 }