コード例 #1
0
ファイル: JImageObject.java プロジェクト: hashrock/JDrafter
 @Override
 public void paintPreview(JEnvironment env, JRequest req, Graphics2D g) {
   g.setColor(getPreviewColor());
   AffineTransform af = new AffineTransform(totalTransform);
   if (addingTransform != null) af.preConcatenate(addingTransform);
   Shape s = getShape();
   if (addingTransform != null) s = addingTransform.createTransformedShape(s);
   s = env.getToScreenTransform().createTransformedShape(s);
   g.draw(s);
   PathIterator path = s.getPathIterator(null);
   double radius = JEnvironment.PATH_SELECTOR_SIZE / 2;
   Rectangle2D.Double sr = new Rectangle2D.Double(0, 0, radius * 2, radius * 2);
   double[] coords = new double[6];
   while (!path.isDone()) {
     int type = path.currentSegment(coords);
     if (type == path.SEG_MOVETO || type == path.SEG_LINETO) {
       sr.x = coords[0] - radius;
       sr.y = coords[1] - radius;
       g.fill(sr);
     } else if (type == path.SEG_CUBICTO) {
       sr.x = coords[4] - radius;
       sr.y = coords[5] - radius;
       g.fill(sr);
     } else if (type == path.SEG_QUADTO) {
       sr.x = coords[2] - radius;
       sr.y = coords[3] - radius;
       g.fill(sr);
     }
     path.next();
   }
 }
コード例 #2
0
ファイル: JImageObject.java プロジェクト: hashrock/JDrafter
 @Override
 public int hitByPoint(JEnvironment env, JRequest req, Point2D point) {
   if (isLocked() || !isVisible()) return JRequest.HIT_NON;
   Shape s = getShape();
   if (s.contains(point)) {
     req.hitObjects.add(this);
     return (req.hitResult = JRequest.HIT_OBJECT);
   }
   double radius = JEnvironment.PATH_SELECTOR_SIZE / 2 / env.getToScreenRatio();
   Rectangle2D.Double sr = new Rectangle2D.Double(0, 0, radius * 2, radius * 2);
   PathIterator path = s.getPathIterator(null);
   double[] coords = new double[6];
   while (!path.isDone()) {
     int type = path.currentSegment(coords);
     if (type == path.SEG_LINETO || type == path.SEG_MOVETO) {
       sr.x = coords[0] - radius;
       sr.y = coords[1] - radius;
       if (sr.contains(point)) {
         req.hitObjects.add(this);
         return (req.hitResult = JRequest.HIT_OBJECT);
       }
     }
     path.next();
   }
   return JRequest.HIT_NON;
 }
コード例 #3
0
  public boolean checkWorldCollision(Shape s) {
    if (s == null) return false;
    Point area = Globals.findTile(s.getBounds().x, s.getBounds().y);

    int areaX = area.x;
    int areaY = area.y;
    areaX--;
    areaY--;
    if (areaX < 0) areaX = 0;
    if (areaY < 0) areaY = 0;
    int areaXEnd = areaX + 21;
    int areaYEnd = areaY + 21;
    if (areaXEnd > xLength) areaXEnd = xLength;
    if (areaYEnd > yHeight) areaYEnd = yHeight;

    for (int x = areaX; x < areaXEnd; x++) {
      for (int y = areaY; y < areaYEnd; y++) {
        if (walls[x][y] == null) continue;
        if (s.intersects(walls[x][y].getPhysicsShape())) {
          // walls[x][y].printName();
          return true;
        }
      }
    }
    return false;
  }
コード例 #4
0
 /**
  * Get the bounding box of the shape when stroked. This method takes account of the thickness of
  * the stroke.
  */
 public Rectangle2D getBounds() {
   // FIXME: these bounds REALLY need to be cached.  But it's
   // painful because of the public members.
   if (stroke == null) {
     return shape.getBounds2D();
   } else if (stroke instanceof BasicStroke) {
     // For some reason (antialiasing?) the bounds returned by
     // BasicStroke is off by one.  This code works around it.
     // if all we want is the bounds, then we don't need to actually
     // stroke the shape.  We've had reports that this is no longer
     // necessary with JDK1.3.
     Rectangle2D rect = shape.getBounds2D();
     int width = (int) ((BasicStroke) stroke).getLineWidth() + 2;
     return new Rectangle2D.Double(
         rect.getX() - width,
         rect.getY() - width,
         rect.getWidth() + width + width,
         rect.getHeight() + width + width);
   } else {
     // For some reason (antialiasing?) the bounds returned by
     // BasicStroke is off by one.  This code works around it.
     // We've had reports that this is no longer
     // necessary with JDK1.3.
     Rectangle2D rect = stroke.createStrokedShape(shape).getBounds2D();
     return new Rectangle2D.Double(
         rect.getX() - 1, rect.getY() - 1, rect.getWidth() + 2, rect.getHeight() + 2);
   }
 }
コード例 #5
0
  @Override
  public boolean contains(Point2D position) {
    double flatness = 0.01;
    boolean intersect = false;
    PathIterator pit = path.getPathIterator(null, flatness);
    double[] coords = new double[6];
    double lastX = 0, lastY = 0;
    while (!intersect && !pit.isDone()) {
      int type = pit.currentSegment(coords);
      switch (type) {
        case PathIterator.SEG_MOVETO:
          lastX = coords[0];
          lastY = coords[1];
          break;
        case PathIterator.SEG_LINETO:
          BasicStroke stroke = new BasicStroke(10.0f);
          Line2D.Double line = new Line2D.Double(lastX, lastY, coords[0], coords[1]);
          Shape shape = stroke.createStrokedShape(line);
          if (shape.contains(position)) {
            intersect = true;
          }

          lastX = coords[0];
          lastY = coords[1];
      }
      pit.next();
    }
    return intersect;
  }
コード例 #6
0
  @Override
  public Shape getPointShape(PointData data) {
    Row row = data.row;
    int colLabel = getColumn();
    if (colLabel >= row.size()) {
      return null;
    }

    Comparable<?> labelValue = row.get(colLabel);
    if (labelValue == null) {
      return null;
    }

    Format format = getFormat();
    Font font = getFont();
    String text = format.format(labelValue);
    double alignment = getAlignmentX();
    Shape shape = GraphicsUtils.getOutline(text, font, 0f, alignment);

    double alignX = getAlignmentX();
    double alignY = getAlignmentY();
    Rectangle2D bounds = shape.getBounds2D();
    AffineTransform tx =
        AffineTransform.getTranslateInstance(
            -alignX * bounds.getWidth(), alignY * bounds.getHeight());
    shape = tx.createTransformedShape(shape);

    return shape;
  }
コード例 #7
0
  private double calculateWidth(V v) {
    double childrenWidthSum = 0;
    int childrenNum = graph.getSuccessors(v).size();
    if (childrenNum != 0) {
      boolean first = true;
      for (V element : graph.getSuccessors(v)) {
        if (!first) {
          childrenWidthSum += MARGIN;
        }
        childrenWidthSum += calculateWidth(element);
        first = false;
      }
    }

    double width = DEFAULT_WIDTH;
    if (this.shapeTransformer != null) {
      Shape shape = this.shapeTransformer.transform(v);
      if (shape != null) {
        width = shape.getBounds().getWidth();
      }
    }
    double size = Math.max(width, childrenWidthSum);
    size = Math.max(0, size);
    return size;
  }
コード例 #8
0
ファイル: Subtree.java プロジェクト: siwells/monkeypuzzle
  /**
   * Build a shape for the entire subtree by joining together the shapes for each of its edges.
   * Vertices included since needed for FullTextPanel.
   */
  public Shape constructInternalShape(DiagramBase diagram, boolean includeVertices) {
    GeneralPath shape = new GeneralPath();
    Enumeration edges = m_edgeList.elements();
    while (edges.hasMoreElements()) {
      TreeEdge edge = (TreeEdge) edges.nextElement();
      Shape edgeShape = edge.getSchemeShape(diagram);
      PathIterator path = edgeShape.getPathIterator(null);
      shape.append(path, false);

      if (includeVertices) {
        Shape vertexShape;
        if (!edge.getSourceVertex().isVirtual()) {
          vertexShape = edge.getSourceVertex().getShape(diagram);
          path = vertexShape.getPathIterator(null);
          shape.append(path, false);
        }
        if (!edge.getDestVertex().isVirtual()) {
          vertexShape = edge.getDestVertex().getShape(diagram);
          path = vertexShape.getPathIterator(null);
          shape.append(path, false);
        }
      }
    }
    BasicStroke stroke =
        new BasicStroke(
            diagram.getSubtreeLineWidth() - DiagramBase.EDGE_OUTLINE_WIDTH + 1,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_MITER);
    internalShapeTable.put(diagram, stroke.createStrokedShape(shape));
    return (Shape) internalShapeTable.get(diagram);
  }
コード例 #9
0
ファイル: ShapeGroup.java プロジェクト: pombredanne/STuneLite
  /** @return the shapes contained in this group container */
  public Shape[] getShapes() {
    // Out escher container record should contain serveral
    //  SpContainers, the first of which is the group shape itself
    List lst = _escherContainer.getChildRecords();

    ArrayList shapeList = new ArrayList();
    // Don't include the first SpContainer, it is always NotPrimitive
    for (int i = 1; i < lst.size(); i++) {
      EscherRecord r = (EscherRecord) lst.get(i);
      if (r instanceof EscherContainerRecord) {
        // Create the Shape for it
        EscherContainerRecord container = (EscherContainerRecord) r;
        Shape shape = ShapeFactory.createShape(container, this);
        shape.setSheet(getSheet());
        shapeList.add(shape);
      } else {
        // Should we do anything special with these non
        //  Container records?
        logger.log(
            POILogger.ERROR,
            "Shape contained non container escher record, was " + r.getClass().getName());
      }
    }

    // Put the shapes into an array, and return
    Shape[] shapes = (Shape[]) shapeList.toArray(new Shape[shapeList.size()]);
    return shapes;
  }
コード例 #10
0
ファイル: Drawing.java プロジェクト: zacharimoncef93/POOA
 /** RedŽfinition de la mŽthode paintComponent() de JComponent */
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   for (Shape s : shapes) {
     s.paint(g);
   }
   notifyObservers();
 }
コード例 #11
0
 @Override
 public boolean contains(int x, int y) {
   if (shape == null || !shape.getBounds().equals(getBounds())) {
     shape = new Area(makeStarDesign(5, new Point(50, 50), 50, 30));
   }
   return shape.contains(x, y);
 }
コード例 #12
0
ファイル: TextViewHybrid.java プロジェクト: zukov/Jpicedt
  /**
   * This implementation calls <code>super.hitTest</code> and returns the result if non-null (this
   * should be a HitInfo.Point), then returns a HitInfo.Interior if the mouse-click occured inside
   * the text bound (as defined by text layout)
   *
   * @return a HitInfo corresponding to the given mouse-event
   */
  public HitInfo hitTest(PEMouseEvent e) {

    // from Bitmap:
    if (image != null) {
      if (getBounds().contains(e.getPicPoint())) {
        return new HitInfo.Interior((PicText) element, e);
      }
      return null;
    }

    // from TextLayout:
    if (!getBounds().contains(e.getPicPoint())) return null;

    PicText te = (PicText) element;
    // recompute textlayout b-box, but store it in a temporary field !
    Rectangle2D tb = textLayout.getBounds();
    Shape text_bounds = text2ModelTr.createTransformedShape(tb);
    if (text_bounds.contains(e.getPicPoint())) {
      // [SR:pending] for the hitInfo to be reliable, getPicPoint() should first be transformed by
      //              inverse text2ModelTr ! (especially when rotationAngle != 0)
      TextHitInfo thi =
          textLayout.hitTestChar(
              (float) (e.getPicPoint().x - strx),
              (float) (e.getPicPoint().y - stry)); // guaranteed to return a non-null thi
      return new HitInfo.Text((PicText) element, thi, e);
    }
    // test hit on textlayout's bounding rectangle :
    // else if (bounds.contains(e.getPicPoint())) return new HitInfo.Interior(element,e);
    return null;
  }
コード例 #13
0
ファイル: GraphicsClipTest.java プロジェクト: aaime/jaitools
  /**
   * Draw some graphics into an Graphics2D object.
   *
   * @param image the image to draw into
   * @throws NoninvertibleTransformException in transform errors.
   */
  private void draw(Graphics2D gr) throws NoninvertibleTransformException {
    gr.setPaint(Color.WHITE);
    gr.fill(new Rectangle(0, 0, tileWidth, tileHeight));

    // AffineTransform[[0.318755336305853, 0.0, 420.03106689453125],
    //                 [0.0, 0.318755336305853, 245.5029296875]]
    AffineTransform transform =
        new AffineTransform(
            0.318755336305853, 0.0, 0.0, 0.318755336305853, 420.03106689453125, 245.5029296875);
    gr.setTransform(transform);

    Shape s = new Rectangle(0, 0, 96, 83);

    // create an enbedded graphics
    Graphics2D grr = (Graphics2D) gr.create();
    // AffineTransform[[1.0, 0.0, -343.9285583496093],
    //                 [0.0, 1.0, -502.5158386230469]]
    grr.clip(s.getBounds());
    transform = new AffineTransform(1.0, 0.0, 0.0, 1.0, -343.9285583496093, -502.5158386230469);
    grr.transform(transform);

    AffineTransform t = transform.createInverse();
    s = t.createTransformedShape(s);

    assertTrue(s.getBounds().intersects(grr.getClip().getBounds2D()));

    grr.setPaint(Color.BLUE);
    grr.draw(s);

    grr.dispose();
    gr.dispose();
  }
コード例 #14
0
 private static LegendTitle createLegend(String legend1Text, String legend2Text) {
   final LegendItemCollection legendItems = new LegendItemCollection();
   FontRenderContext frc = new FontRenderContext(null, true, true);
   Font legenfont = new Font(Font.SANS_SERIF, Font.BOLD, 12);
   GlyphVector gv = legenfont.createGlyphVector(frc, new char[] {'X', 'X'});
   Shape shape = gv.getVisualBounds();
   Rectangle2D bounds = shape.getBounds2D();
   HatchedRectangle hatchShape =
       new HatchedRectangle(
           bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), 5, 5);
   {
     LegendItem li = new LegendItem(legend1Text, null, null, null, hatchShape, Color.black);
     li.setLabelFont(legenfont);
     legendItems.add(li);
   }
   {
     LegendItem li = new LegendItem(legend2Text, null, null, null, shape, Color.black);
     li.setLabelFont(legenfont);
     legendItems.add(li);
   }
   LegendTitle legend =
       new LegendTitle(
           new LegendItemSource() {
             @Override
             public LegendItemCollection getLegendItems() {
               return legendItems;
             }
           });
   legend.setPosition(RectangleEdge.BOTTOM);
   legend.setMargin(new RectangleInsets(0, 30, 0, 0));
   legend.setPadding(RectangleInsets.ZERO_INSETS);
   legend.setLegendItemGraphicPadding(new RectangleInsets(0, 20, 0, 0));
   return legend;
 }
コード例 #15
0
ファイル: Board.java プロジェクト: Redrazors/GameFrame
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(Color.white);
    g2d.fillRect(0, 0, 500, 500);
    g2d.setColor(Color.red);
    g2d.drawString(Double.toString(fpsCounter.fps()), 50, 50);
    // g2d.fillRect(0, 0, 50, 50);

    Rectangle2D.Double testRect = new Rectangle2D.Double(200, 170, 100, 100);
    Ellipse2D.Double testEllipse = new Ellipse2D.Double(200, 0, 50, 50);

    Shape testShape = testRect;
    // g2d.fill(testShape);
    switch (testShape.getClass().getCanonicalName()) {
      case "java.awt.geom.Rectangle2D.Double":
        Rectangle2D.Double newRect = (Rectangle2D.Double) testShape;

        g2d.fill(newRect);
        // System.out.println(testShape.getBounds().x + testShape.getBounds().y);
        break;
      case "java.awt.geom.Ellipse2D.Double":
        Ellipse2D.Double newEllipse = (Ellipse2D.Double) testShape;
        g2d.fill(newEllipse);
        break;
    }

    // System.out.println(testShape.getClass().getCanonicalName());

  }
コード例 #16
0
ファイル: ShapeGroup.java プロジェクト: pombredanne/STuneLite
  /**
   * Add a shape to this group.
   *
   * @param shape - the Shape to add
   */
  public void addShape(Shape shape) {
    _escherContainer.addChildRecord(shape.getSpContainer());

    Sheet sheet = getSheet();
    shape.setSheet(sheet);
    shape.setShapeId(sheet.allocateShapeId());
    shape.afterInsert(sheet);
  }
コード例 #17
0
 public boolean contains(int x, int y) {
   // If the button has changed size,
   // make a new shape object.
   if (shape == null || !shape.getBounds().equals(getBounds())) {
     shape = new Ellipse2D.Float(0, 0, getWidth(), getHeight());
   }
   return shape.contains(x, y);
 }
コード例 #18
0
ファイル: JImageObject.java プロジェクト: hashrock/JDrafter
 @Override
 public void hitByRect(JEnvironment env, JRequest req, Rectangle2D rect) {
   if (isLocked() || !isVisible()) return;
   Shape s = getShape();
   if (s.intersects(rect)) {
     req.hitObjects.add(this);
   }
 }
コード例 #19
0
  /**
   * Check if teleporting from a location is allowed.
   *
   * @param x x coordinate
   * @param y y coordinate
   * @return <code>true</code> if teleporting to the point is allowed, <code>false</code> otherwise
   */
  public boolean isOutAllowed(int x, int y) {
    for (Shape r : leavingBarriers) {
      if (r.contains(x, y)) {
        return false;
      }
    }

    return true;
  }
コード例 #20
0
ファイル: ShapePickSupport.java プロジェクト: RomaKoks/jung
  /**
   * Returns an edge whose shape intersects the 'pickArea' footprint of the passed x,y, coordinates.
   *
   * @param layout the context in which the location is defined
   * @param x the x coordinate of the location
   * @param y the y coordinate of the location
   * @return an edge whose shape intersects the pick area centered on the location {@code (x,y)}
   */
  public E getEdge(Layout<V, E> layout, double x, double y) {

    Point2D ip =
        vv.getRenderContext()
            .getMultiLayerTransformer()
            .inverseTransform(Layer.VIEW, new Point2D.Double(x, y));
    x = ip.getX();
    y = ip.getY();

    // as a Line has no area, we can't always use edgeshape.contains(point) so we
    // make a small rectangular pickArea around the point and check if the
    // edgeshape.intersects(pickArea)
    Rectangle2D pickArea =
        new Rectangle2D.Float(
            (float) x - pickSize / 2, (float) y - pickSize / 2, pickSize, pickSize);
    E closest = null;
    double minDistance = Double.MAX_VALUE;
    while (true) {
      try {
        for (E e : getFilteredEdges(layout)) {

          Shape edgeShape = getTransformedEdgeShape(layout, e);
          if (edgeShape == null) continue;

          // because of the transform, the edgeShape is now a GeneralPath
          // see if this edge is the closest of any that intersect
          if (edgeShape.intersects(pickArea)) {
            float cx = 0;
            float cy = 0;
            float[] f = new float[6];
            PathIterator pi = new GeneralPath(edgeShape).getPathIterator(null);
            if (pi.isDone() == false) {
              pi.next();
              pi.currentSegment(f);
              cx = f[0];
              cy = f[1];
              if (pi.isDone() == false) {
                pi.currentSegment(f);
                cx = f[0];
                cy = f[1];
              }
            }
            float dx = (float) (cx - x);
            float dy = (float) (cy - y);
            float dist = dx * dx + dy * dy;
            if (dist < minDistance) {
              minDistance = dist;
              closest = e;
            }
          }
        }
        break;
      } catch (ConcurrentModificationException cme) {
      }
    }
    return closest;
  }
コード例 #21
0
 void addShape(Shape shape) {
   // Add the shape to the canvas, and set its size/position and color.
   // The shape is added at the top-left corner, with size 80-by-50.
   // Then redraw the canvas to show the newly added shape.
   shape.setColor(currentColor);
   shape.reshape(3, 3, 80, 50);
   shapes.add(shape);
   repaint();
 }
コード例 #22
0
ファイル: Drawing.java プロジェクト: DracZakk/tpAdapter
 /** Redefinition de la methode paintComponent() de JComponent */
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   for (Shape s : shapes) {
     s.paint(g);
   }
   for (Shape s : shapesCloneList) {
     s.paint(g);
   }
 }
コード例 #23
0
ファイル: Font3DState.java プロジェクト: kephale/java3d-utils
  @Override
  public void writeConstructorParams(DataOutput out) throws IOException {
    super.writeConstructorParams(out);

    // issue 483: init the node
    Font3D font3D = (Font3D) node;
    font = font3D.getFont();

    out.writeUTF(font.getFontName());
    out.writeInt(font.getStyle());
    out.writeInt(font.getSize());
    out.writeDouble(font3D.getTessellationTolerance());

    // issue 483
    extrudePath = new FontExtrusion();
    font3D.getFontExtrusion(extrudePath);
    if (extrudePath.getExtrusionShape() == null) {
      extrudePath = null;
    }

    if (extrudePath != null) {
      Shape shape = extrudePath.getExtrusionShape();
      if (shape != null) {
        PathIterator shapePath = shape.getPathIterator(null);
        float[] coords = new float[6];
        int segType;
        int points;
        while (!(shapePath.isDone())) {
          // Get type of current path segment and associated
          // coordinates
          segType = shapePath.currentSegment(coords);
          out.writeInt(segType);

          // Write out relevant coordinates
          points = 0;
          if (segType == PathIterator.SEG_MOVETO) points = 1;
          else if (segType == PathIterator.SEG_LINETO) points = 1;
          else if (segType == PathIterator.SEG_QUADTO) points = 2;
          else if (segType == PathIterator.SEG_CUBICTO) points = 3;

          for (int i = 0; i < points; i++) {
            out.writeFloat(coords[i * 2 + 0]);
            out.writeFloat(coords[i * 2 + 1]);
          }

          // Next segment
          if (!(shapePath.isDone())) shapePath.next();
        }
      }
      // Flag for end of path definition
      out.writeInt(Integer.MIN_VALUE);
      out.writeDouble(extrudePath.getTessellationTolerance());

    } else {
      out.writeInt(Integer.MIN_VALUE);
    }
  }
コード例 #24
0
  /**
   * @param shape
   * @param rotation
   * @return
   */
  public static Shape getRotatedShape(Shape shape, double rotation) {
    AffineTransform localAT = null;
    Shape localShape = null;
    localAT =
        AffineTransform.getRotateInstance(
            Math.toRadians(rotation), shape.getBounds().getX(), shape.getBounds().getY());
    localShape = localAT.createTransformedShape(shape);

    return localShape;
  }
コード例 #25
0
ファイル: ShapeIcon.java プロジェクト: feldmarshall/tracker
 /**
  * Constructs a ShapeIcon.
  *
  * @param shape the shape to draw
  * @param decoration a decorating shape to draw
  * @param width width of the icon
  * @param height height of the icon
  */
 public ShapeIcon(Shape shape, Shape decoration, int width, int height) {
   w = width;
   h = height;
   this.shape = shape;
   this.decoration = decoration;
   Rectangle rect = shape == null ? new Rectangle() : shape.getBounds();
   if (decoration != null) rect = rect.union(decoration.getBounds());
   offsetX = w / 2 - rect.width / 2 - rect.x;
   offsetY = h / 2 - rect.height / 2 - rect.y;
 }
コード例 #26
0
  /**
   * A utility method for determining the height of a text block.
   *
   * @param block the text block.
   * @param position the label position.
   * @param g2 the graphics device.
   * @return The height.
   */
  protected double calculateTextBlockHeight(
      TextBlock block, CategoryLabelPosition position, Graphics2D g2) {

    RectangleInsets insets = getTickLabelInsets();
    Size2D size = block.calculateDimensions(g2);
    Rectangle2D box = new Rectangle2D.Double(0.0, 0.0, size.getWidth(), size.getHeight());
    Shape rotatedBox = ShapeUtilities.rotateShape(box, position.getAngle(), 0.0f, 0.0f);
    double h = rotatedBox.getBounds2D().getHeight() + insets.getTop() + insets.getBottom();
    return h;
  }
コード例 #27
0
 public void selectAllWithin(BaseObject boundary) {
   BaseObject[] list = list();
   for (int i = 0; i < list.length; i++) {
     java.awt.Shape s1 = boundary.getShape();
     java.awt.Shape s2 = list[i].getShape();
     if (s1.contains(s2.getBounds2D())) {
       grab(list[i]);
     }
   }
 }
コード例 #28
0
ファイル: fxtest.java プロジェクト: sormaz/implanner-fx
  public static Path getFXShape(LinkedList swingShapeList) {

    Path sfx = new Path();

    for (Object s : swingShapeList) {
      java.awt.Shape ss = (java.awt.Shape) s;
      if (ss instanceof java.awt.Shape) {
        double[] coords = new double[6];
        ArrayList<double[]> areaPoints = new ArrayList<double[]>();

        for (PathIterator pi = ss.getPathIterator(null); !pi.isDone(); pi.next()) {
          int type = pi.currentSegment(coords);

          double[] pathIteratorCoords = {
            type, coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]
          };
          areaPoints.add(pathIteratorCoords);
        }

        for (double[] d : areaPoints) {
          if (d[0] == PathIterator.SEG_MOVETO) {

            MoveTo moveTo = new MoveTo();
            moveTo.setX(d[1]);
            moveTo.setY(d[2]);
            sfx.getElements().add(moveTo);

          } else if (d[0] == PathIterator.SEG_LINETO) {

            LineTo lineTo = new LineTo();
            lineTo.setX(d[1]);
            lineTo.setY(d[2]);
            sfx.getElements().add(lineTo);

          } else if (d[0] == PathIterator.SEG_CUBICTO) {

            CubicCurveTo ccTo = new CubicCurveTo(d[1], d[2], d[3], d[4], d[5], d[6]);
            sfx.getElements().add(ccTo);

          } else if (d[0] == PathIterator.SEG_QUADTO) {

            QuadCurveTo qcTo = new QuadCurveTo(d[1], d[2], d[3], d[4]);
            sfx.getElements().add(qcTo);

          } else if (d[0] == PathIterator.SEG_CLOSE) {

            ClosePath cp = new ClosePath();
            sfx.getElements().add(cp);
          }
        }
      }
    }
    return sfx;
  }
コード例 #29
0
ファイル: Manager.java プロジェクト: Tadimsky/vooga
 /**
  * Selects all the entities in provided rectangle. Allows a user to drag around the desired
  * entities.
  *
  * @param area The area to select the entities in.
  */
 public void select(Shape area) {
   deselectAll();
   boolean multi = myMultiSelect;
   setMultiSelect(true);
   for (InteractiveEntity ie : myEntities) {
     if (area.intersects(ie.getBounds()) || area.contains(ie.getBounds())) {
       select(ie);
     }
   }
   setMultiSelect(multi);
 }
コード例 #30
0
ファイル: EdgeRenderer.java プロジェクト: mongkie/mongkie
 /** @see prefuse.render.Renderer#locatePoint(java.awt.geom.Point2D, prefuse.visual.VisualItem) */
 @Override
 public boolean locatePoint(Point2D p, VisualItem item) {
   Shape s = getShape(item);
   if (s == null) {
     return false;
   } else {
     double width = Math.max(2, getLineWidth(item));
     double halfWidth = width / 2.0;
     return s.intersects(p.getX() - halfWidth, p.getY() - halfWidth, width, width);
   }
 }