Java 类java.awt.geom.Area 实例源码

项目:jmt    文件:EngineConvex2D.java   
/**
 * Costructor of the life
 * @param allPoints All the point of the graph
 * @param sd3 The sector of saturation
 */
public EngineConvex2D(Vector<Point2D> allPoints, Vector<Object> sd3) {
    this.allPoints = (Vector<Point2D>) allPoints.clone();
    allConvex = new Vector<Point2D>();
    allImperant = (Vector<Point2D>) allPoints.clone();
    allDominates = new Vector<Point2D>();

    filtDominants = new Vector<Point2D>();
    filtDominates = new Vector<Point2D>();
    filtPoints = new Vector<DPoint>();
    filtConvex = new Vector<Point2D>();

    filtArea = new Area();

    separator();
    //calcConvex();
    calcConvex(sd3);

    dominates = (Vector<Point2D>) allDominates.clone();
    imperant = (Vector<Point2D>) allImperant.clone();
    convex = (Vector<Point2D>) allConvex.clone();
    points = (Vector<Point2D>) this.allPoints.clone();
}
项目:QN-ACTR-Release    文件:EngineConvex2D.java   
/**
 * Costructor of the life
 * @param allPoints All the point of the graph
 * @param sd3 The sector of saturation
 */
public EngineConvex2D(Vector<Point2D> allPoints, Vector<Object> sd3) {
    this.allPoints = (Vector<Point2D>) allPoints.clone();
    allConvex = new Vector<Point2D>();
    allImperant = (Vector<Point2D>) allPoints.clone();
    allDominates = new Vector<Point2D>();

    filtDominants = new Vector<Point2D>();
    filtDominates = new Vector<Point2D>();
    filtPoints = new Vector<DPoint>();
    filtConvex = new Vector<Point2D>();

    filtArea = new Area();

    separator();
    //calcConvex();
    calcConvex(sd3);

    dominates = (Vector<Point2D>) allDominates.clone();
    imperant = (Vector<Point2D>) allImperant.clone();
    convex = (Vector<Point2D>) allConvex.clone();
    points = (Vector<Point2D>) this.allPoints.clone();
}
项目:litiengine    文件:CombatEntityVision.java   
@Override
public void updateVisionShape() {
  final Path2D path = new Path2D.Float();
  final Path2D renderPath = new Path2D.Float();
  path.append(this.getMapVisionCircle(this.combatEntity), false);
  renderPath.append(this.getRenderVisionArc(this.combatEntity), false);

  for (final ICombatEntity entity : this.environment.getCombatEntities()) {
    if (entity.isFriendly(this.combatEntity) && !entity.equals(this.combatEntity)) {
      path.append(this.getMapVisionCircle(entity), false);
      renderPath.append(this.getRenderVisionArc(entity), false);
    }
  }

  this.renderVisionShape = renderPath;

  final float width = (float) this.environment.getMap().getSizeInPixels().getWidth();
  final float height = (float) this.environment.getMap().getSizeInPixels().getHeight();
  final Rectangle2D rect = new Rectangle2D.Float(0, 0, width, height);
  final Area rectangleArea = new Area(rect);
  rectangleArea.subtract(new Area(path));

  this.fogOfWar = rectangleArea;
}
项目:incubator-netbeans    文件:WinXPEditorTabCellRenderer.java   
private static final void paintTopLine(Graphics g,
                                       WinXPEditorTabCellRenderer ren,
                                       TabPainter p) {
    Polygon poly = p.getInteriorPolygon(ren);
    ((Graphics2D) g).setPaint(getHighlightColor());
    g.setColor(getHighlightColor());
    Shape clip = g.getClip();
    Insets ins = p.getBorderInsets(ren);
    try {
        if (clip != null) {
            Area a = new Area(clip);
            a.intersect(new Area(poly));
            g.setClip(a);
        } else {
            g.setClip(poly);
        }
        g.fillRect(0, ins.top, ren.getWidth(), 3);
    } finally {
        g.setClip(clip);
    }
}
项目:incubator-netbeans    文件:JTabbedPaneAdapter.java   
/**
 * Get a shape appropriate for drawing on the window's glass pane to
 * indicate where a component should appear in the tab order if it is
 * dropped here.
 *
 * @param dragged An object being dragged, or null. The object may be an
 * instance of
 * <code>TabData</code> or
 * <code>Component</code>, in which case a check will be done of whether the
 * dragged object is already in the data model, so that attempts to drop the
 * object over the place it already is in the model will always return the
 * exact indication of that tab's position.
 *
 * @param location A point
 * @return Drop indication drawing
 */
public Shape getDropIndication( Object dragged, Point location ) {
    int over = dropIndexOfPoint( location );
    Rectangle component = getSelectedComponent().getBounds();
    Area selectedComponent = new Area( component );

    Rectangle firstTab = null, secondTab = null;
    if( over > 0 && over < getTabCount() )
        firstTab = getBoundsAt( over-1 );
    if( over < getTabCount() )
        secondTab = getBoundsAt( over );
    if( over >= getTabCount() ) {
        firstTab = getBoundsAt( getTabCount()-1 );
        secondTab = null;
    }
    Rectangle joined = joinTabAreas( firstTab, secondTab );
    Area t = new Area( joined );
    selectedComponent.add( t );
    return selectedComponent;
}
项目:jmt    文件:QueueDrawer.java   
private void drawUtilizationMulti(double U, Color startC, Color border, boolean gradientFill, Graphics2D g2d, int cpu) {

        double x = getProcessorXY().x, y = getProcessorXY().y;
        try {
            occupiedRect = new Rectangle2D.Double(x + PROC_RAD / 2 + ELEMS_GAP / 2, y + cpu * (PROC_RAD - ELEMS_GAP) + ELEMS_GAP * cpu * 3
                    - ELEMS_GAP / 2, PROC_RAD - ELEMS_GAP, (PROC_RAD - ELEMS_GAP) * (1 - U / nCpu));
        } catch (Exception e) {
            occupiedRect = new Rectangle2D.Double(x + PROC_RAD / 2 + ELEMS_GAP / 2, y + cpu * (PROC_RAD - ELEMS_GAP) + ELEMS_GAP * cpu * 3
                    - ELEMS_GAP / 2, PROC_RAD - ELEMS_GAP, 0);
        }
        occupiedEll = new Ellipse2D.Double(x + PROC_RAD / 2 + ELEMS_GAP / 2, y + cpu * (PROC_RAD - ELEMS_GAP) + ELEMS_GAP * cpu * 3 - ELEMS_GAP / 2,
                PROC_RAD - ELEMS_GAP, PROC_RAD - ELEMS_GAP);
        if (gradientFill) {
            GradientPaint gp = new GradientPaint((float) x, (float) y, startC.brighter(), (float) x, (float) (y + 2 * PROC_RAD), startC.darker(),
                    false);
            g2d.setPaint(gp);
        } else {
            g2d.setPaint(startC);
        }
        occupiedArea = new Area(occupiedEll);
        occupiedArea.subtract(new Area(occupiedRect));
        g2d.fill(occupiedArea);
        g2d.setPaint(Color.BLACK);
        g2d.draw(occupiedArea);

    }
项目:jmt    文件:PainterConvex2D.java   
/**
 * Draw a semi-trasparent area that is the filtered area
 * @param g The graphic object
 * @param filteredArea The filtered area
 */
public void drawFiltArea(Graphics2D g, Area filtArea) {
    AffineTransform t = new AffineTransform();
    t.scale(scale / 100, scale / 100);
    AffineTransform t2 = new AffineTransform();
    t2.translate(tran_x, tran_y);

    filtArea.transform(t);
    filtArea.transform(t2);

    Stroke oldStro = g.getStroke();
    Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    g.setStroke(stroke);

    g.setColor(Color.GRAY);
    Composite oldComp = g.getComposite();
    Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
    g.setComposite(alphaComp);

    g.fill(filtArea);
    g.setComposite(oldComp);
    g.setStroke(oldStro);
}
项目:sumo    文件:InterpolatedVectorLayer.java   
public Area getShape() {
    Area maskArea = new Area();
    Rectangle rect = new Rectangle(0, 0, reader.getWidth(), reader.getHeight());
    GeometryFactory gf = new GeometryFactory();
    Coordinate[] coords = new Coordinate[]{
        new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),
        new Coordinate((int) rect.getMaxX(), (int) rect.getMinY()),
        new Coordinate((int) rect.getMaxX(), (int) rect.getMaxY()),
        new Coordinate((int) rect.getMinX(), (int) rect.getMaxY()),
        new Coordinate((int) rect.getMinX(), (int) rect.getMinY()),
    };
    Polygon geom = gf.createPolygon(gf.createLinearRing(coords), null);
    for (Geometry p : glayer.getGeometries()) {
        if (p.intersects(geom)) {
            int[] xPoints = new int[p.getNumPoints()];
            int[] yPoints = new int[p.getNumPoints()];
            int i = 0;
            for (Coordinate c : p.getCoordinates()) {
                xPoints[i] = (int) (c.x);
                yPoints[i++] = (int) (c.y);
            }
            maskArea.add(new Area(new java.awt.Polygon(xPoints, yPoints, p.getNumPoints())));
        }
    }
    return maskArea;
}
项目:VASSAL-src    文件:AreaOfEffect.java   
public Area getArea(MapShader shader) {
  Area a = null;
  final MapShader.ShadedPiece shaded = (MapShader.ShadedPiece) Decorator.getDecorator(piece,MapShader.ShadedPiece.class);
  if (shaded != null) {
    a = shaded.getArea(shader);
  }
  if (alwaysActive || active) {
    if (shader.getConfigureName().equals(mapShaderName)) {
      Area myArea = getArea();
      if (a == null) {
        a = myArea;
      }
      else {
        a.add(myArea);
      }
    }
  }
  return a;
}
项目:VASSAL-src    文件:MapShader.java   
protected void checkPiece(Area area, GamePiece piece) {
  if (piece instanceof Stack) {
    Stack s = (Stack) piece;
    for (int i = 0; i < s.getPieceCount(); i++) {
      checkPiece(area, s.getPieceAt(i));
    }
  }
  else {
    ShadedPiece shaded = (ShadedPiece) Decorator.getDecorator(piece,ShadedPiece.class);
    if (shaded != null) {
      Area shape = shaded.getArea(this);
      if (shape != null) {
        if (type.equals(FG_TYPE)) {
          area.add(shape);
        }
        else {
          area.subtract(shape);
        }
      }
    }
  }
}
项目:VASSAL-src    文件:Zone.java   
public void draw(Graphics g, Rectangle bounds, Rectangle visibleRect, double scale, boolean reversed) {
  if ((getGrid() != null && getGrid().isVisible()) || highlighter != null) {
    final Graphics2D g2d = (Graphics2D) g;
    final Shape oldClip = g2d.getClip();
    final Area newClip = new Area(visibleRect);
    final Shape s = getCachedShape(myPolygon, bounds.x, bounds.y, scale);
    newClip.intersect(new Area(s));
    g2d.setClip(newClip);
    if (getGrid() != null && getGrid().isVisible()) {
      getGrid().draw(g, bounds, visibleRect, scale, reversed);
    }
    if (highlighter != null) {
      highlighter.draw(g2d, s, scale);
    }
    g2d.setClip(oldClip);
  }
}
项目:QN-ACTR-Release    文件:QueueDrawer.java   
private void drawUtilizationMulti(double U, Color startC, Color border, boolean gradientFill, Graphics2D g2d, int cpu) {

        double x = getProcessorXY().x, y = getProcessorXY().y;
        try {
            occupiedRect = new Rectangle2D.Double(x + PROC_RAD / 2 + ELEMS_GAP / 2, y + cpu * (PROC_RAD - ELEMS_GAP) + ELEMS_GAP * cpu * 3
                    - ELEMS_GAP / 2, PROC_RAD - ELEMS_GAP, (PROC_RAD - ELEMS_GAP) * (1 - U / nCpu));
        } catch (Exception e) {
            occupiedRect = new Rectangle2D.Double(x + PROC_RAD / 2 + ELEMS_GAP / 2, y + cpu * (PROC_RAD - ELEMS_GAP) + ELEMS_GAP * cpu * 3
                    - ELEMS_GAP / 2, PROC_RAD - ELEMS_GAP, 0);
        }
        occupiedEll = new Ellipse2D.Double(x + PROC_RAD / 2 + ELEMS_GAP / 2, y + cpu * (PROC_RAD - ELEMS_GAP) + ELEMS_GAP * cpu * 3 - ELEMS_GAP / 2,
                PROC_RAD - ELEMS_GAP, PROC_RAD - ELEMS_GAP);
        if (gradientFill) {
            GradientPaint gp = new GradientPaint((float) x, (float) y, startC.brighter(), (float) x, (float) (y + 2 * PROC_RAD), startC.darker(),
                    false);
            g2d.setPaint(gp);
        } else {
            g2d.setPaint(startC);
        }
        occupiedArea = new Area(occupiedEll);
        occupiedArea.subtract(new Area(occupiedRect));
        g2d.fill(occupiedArea);
        g2d.setPaint(Color.BLACK);
        g2d.draw(occupiedArea);

    }
项目:QN-ACTR-Release    文件:PainterConvex2D.java   
/**
 * Draw a semi-trasparent area that is the filtered area
 * @param g The graphic object
 * @param filteredArea The filtered area
 */
public void drawFiltArea(Graphics2D g, Area filtArea) {
    AffineTransform t = new AffineTransform();
    t.scale(scale / 100, scale / 100);
    AffineTransform t2 = new AffineTransform();
    t2.translate(tran_x, tran_y);

    filtArea.transform(t);
    filtArea.transform(t2);

    Stroke oldStro = g.getStroke();
    Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    g.setStroke(stroke);

    g.setColor(Color.gray);
    Composite oldComp = g.getComposite();
    Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
    g.setComposite(alphaComp);

    g.fill(filtArea);
    g.setComposite(oldComp);
    g.setStroke(oldStro);
}
项目:gemini.blueprint    文件:ServiceListenerSyntheticEvents.java   
private void registerMultipleServices() {
    area = new Area();
    rectangle = new Rectangle();
    polygon = new Polygon();

    Dictionary polygonProp = new Properties();
    polygonProp.put(Constants.SERVICE_RANKING, new Integer(1));
    // first register polygon
    polygonReg = bundleContext.registerService(Shape.class.getName(), polygon, polygonProp);

    // then rectangle
    Dictionary rectangleProp = new Properties();
    rectangleProp.put(Constants.SERVICE_RANKING, new Integer(10));
    rectangleReg = bundleContext.registerService(Shape.class.getName(), rectangle, rectangleProp);

    // then area
    Dictionary areaProp = new Properties();
    areaProp.put(Constants.SERVICE_RANKING, new Integer(100));
    areaReg = bundleContext.registerService(Shape.class.getName(), area, areaProp);

}
项目:gemini.blueprint    文件:AsyncNoWaitTest.java   
public void testBehaviour() throws Exception {
    String bundleId = "org.eclipse.gemini.blueprint.iandt, async-nowait-bundle,"
            + getSpringDMVersion();

    // start it
    Bundle bundle = installBundle(bundleId);
    bundle.start();

    // wait for the bundle to start and fail
    Thread.sleep(3000);

    // put service up
    registration = bundleContext.registerService(Shape.class.getName(), new Area(), null);

    assertTrue("bundle " + bundle + "hasn't been fully started", OsgiBundleUtils.isBundleActive(bundle));

    // check that the appCtx is *not* published 
    // TODO: this fails sometimes on the build server - find out why
    // assertContextServiceIs(bundle, false, 1000);
}
项目:gemini.blueprint    文件:AsyncWaitTest.java   
public void testBehaviour() throws Exception {

        String bundleId = "org.eclipse.gemini.blueprint.iandt, async-wait-bundle,"
                + getSpringDMVersion();

        // start it
        Bundle bundle = installBundle(bundleId);
        bundle.start();

        assertTrue("bundle " + bundle + "hasn't been fully started", OsgiBundleUtils.isBundleActive(bundle));

        // make sure the appCtx is not up
        // check that the appCtx is *not* published (it waits for the service to
        // appear)
        assertContextServiceIs(bundle, false, 500);

        // put service up
        registration = bundleContext.registerService(Shape.class.getName(), new Area(), null);

        // do wait a bit to let the appCtx to fully start
        // check the appCtx again (should be published)
        assertContextServiceIs(bundle, true, 4000);

    }
项目:ramus    文件:ScrollPanePreview.java   
protected void paintComponent(Graphics g1D) {
    if (theImage == null || theRectangle == null)
        return;
    Graphics2D g = (Graphics2D) g1D;
    Insets insets = getInsets();
    int xOffset = insets.left;
    int yOffset = insets.top;
    int availableWidth = getWidth() - insets.left - insets.right;
    int availableHeight = getHeight() - insets.top - insets.bottom;
    g.drawImage(theImage, xOffset, yOffset, null);
    Color tmpColor = g.getColor();
    Area area = new Area(new Rectangle(xOffset, yOffset, availableWidth,
            availableHeight));
    area.subtract(new Area(theRectangle));
    g.setColor(new Color(200, 200, 200, 128));
    g.fill(area);
    g.setColor(Color.BLACK);
    g.draw(theRectangle);
    g.setColor(tmpColor);
}
项目:WordnetLoom    文件:ViwnVertexRenderer.java   
private void drawFrame(GraphicsDecorator g, Shape shape, Color color, Point2D.Float pos) {
    Shape old_clip = g.getClip();
    AffineTransform old = g.getTransform();
    AffineTransform t = g.getTransform();
    t.concatenate(AffineTransform.getTranslateInstance(pos.x, pos.y));
    g.setTransform(t);
    g.setColor(color);
    Stroke old_stroke = g.getStroke();
    g.setStroke(new BasicStroke(10.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    Area a = new Area(g.getClip());
    a.subtract(new Area(shape));
    g.setClip(a);
    g.draw(shape);
    g.setTransform(old);
    g.setStroke(old_stroke);
    g.setClip(old_clip);
}
项目:WordnetLoom    文件:ViwnVertexRenderer.java   
private void drawFrame(GraphicsDecorator g, Shape shape, Color color, Point2D.Float pos) {
    Shape old_clip = g.getClip();
    AffineTransform old = g.getTransform();
    AffineTransform t = g.getTransform();
    t.concatenate(AffineTransform.getTranslateInstance(pos.x, pos.y));
    g.setTransform(t);
    g.setColor(color);
    Stroke old_stroke = g.getStroke();
    g.setStroke(new BasicStroke(10.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    Area a = new Area(g.getClip());
    a.subtract(new Area(shape));
    g.setClip(a);
    g.draw(shape);
    g.setTransform(old);
    g.setStroke(old_stroke);
    g.setClip(old_clip);
}
项目:recruitervision    文件:JapePlusIcon.java   
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.translate(x, y);

    Area clip = new Area(new Rectangle(0, 0, this.width, this.height));     
    if (g2d.getClip() != null) clip.intersect(new Area(g2d.getClip()));     
    g2d.setClip(clip);

    double coef1 = (double) this.width / (double) getOrigWidth();
    double coef2 = (double) this.height / (double) getOrigHeight();
    double coef = Math.min(coef1, coef2);
    g2d.scale(coef, coef);
    paint(g2d);
    g2d.dispose();
}
项目:recruitervision    文件:JapePlusIcon.java   
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.translate(x, y);

    Area clip = new Area(new Rectangle(0, 0, this.width, this.height));     
    if (g2d.getClip() != null) clip.intersect(new Area(g2d.getClip()));     
    g2d.setClip(clip);

    double coef1 = (double) this.width / (double) getOrigWidth();
    double coef2 = (double) this.height / (double) getOrigHeight();
    double coef = Math.min(coef1, coef2);
    g2d.scale(coef, coef);
    paint(g2d);
    g2d.dispose();
}
项目:parabuild-ci    文件:PlumNeedle.java   
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {

    Arc2D shape = new Arc2D.Double(Arc2D.PIE);
    double radius = plotArea.getHeight();
    double halfX = plotArea.getWidth() / 2;
    double diameter = 2 * radius;

    shape.setFrame(plotArea.getMinX() + halfX - radius ,
                   plotArea.getMinY() - radius,
                   diameter, diameter);
    radius = Math.toDegrees(Math.asin(halfX / radius));
    shape.setAngleStart(270 - radius);
    shape.setAngleExtent(2 * radius);

    Area s = new Area(shape);

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation houston, please spin me
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        s.transform(getTransform());
    }

    defaultDisplay(g2, s);
}
项目:parabuild-ci    文件:StandardDialFrame.java   
/**
 * Draws the frame.
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view rectangle.
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {

    Shape window = getWindow(frame);
    Shape outerWindow = getOuterWindow(frame);

    Area area1 = new Area(outerWindow);
    Area area2 = new Area(window);
    area1.subtract(area2);
    g2.setPaint(Color.lightGray);
    g2.fill(area1);

    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    g2.draw(outerWindow);


}
项目:parabuild-ci    文件:SimpleDialFrame.java   
/**
 * Draws the frame.  This method is called by the {@link DialPlot} class,
 * you shouldn't need to call it directly.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param frame  the frame (<code>null</code> not permitted).
 * @param view  the view (<code>null</code> not permitted).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {

    Shape window = getWindow(frame);

    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius + 0.02, 
            this.radius + 0.02);
    Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), 
            f.getHeight());

    Area area = new Area(e);
    Area area2 = new Area(window);
    area.subtract(area2);
    g2.setPaint(this.backgroundPaint);
    g2.fill(area);

    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    g2.draw(e);
}
项目:parabuild-ci    文件:PlumNeedle.java   
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, 
                          Point2D rotate, double angle) {

    Arc2D shape = new Arc2D.Double(Arc2D.PIE);
    double radius = plotArea.getHeight();
    double halfX = plotArea.getWidth() / 2;
    double diameter = 2 * radius;

    shape.setFrame(plotArea.getMinX() + halfX - radius ,
                   plotArea.getMinY() - radius,
                   diameter, diameter);
    radius = Math.toDegrees(Math.asin(halfX / radius));
    shape.setAngleStart(270 - radius);
    shape.setAngleExtent(2 * radius);

    Area s = new Area(shape);

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation houston, please spin me
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        s.transform(getTransform());
    }

    defaultDisplay(g2, s);
}
项目:openjdk-jdk10    文件:SetShapeTest.java   
private static void createUI() throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            background = new Frame();
            background.setUndecorated(true);
            background.setBackground(Color.blue);
            background.setSize(300, 300);
            background.setLocation(100, 100);
            background.setVisible(true);
            window = new Window(background);
            window.setBackground(Color.red);
            window.add(new Panel(), BorderLayout.CENTER);
            window.setLocation(200, 200);
            window.setSize(100, 100);
            Area a = new Area();
            a.add(new Area(new Rectangle2D.Double(0, 0, 100, 100)));
            window.setShape(a);
            window.setVisible(true);
            window.toFront();
        }
    });
}
项目:PhET    文件:TrapezoidPool.java   
public TrapezoidPool() {
    this.waterShape = new CompositeProperty<Shape>( new Function0<Shape>() {
        public Shape apply() {
            final Shape containerShape = getContainerShape();
            double height = getWaterHeight();
            Rectangle2D whole = containerShape.getBounds2D();

            //just keep the bottom part that is occupied by water
            final Rectangle2D part = new Rectangle2D.Double( whole.getX(), whole.getY(), whole.getWidth(), height );
            return new Area( containerShape ) {{
                intersect( new Area( part ) );
            }};
        }
    }, waterVolume );
    inputFaucetEnabled = new CompositeBooleanProperty( new Function0<Boolean>() {
        public Boolean apply() {
            return getWaterHeight() < height;
        }
    }, waterVolume );
    drainFaucetEnabled = new CompositeBooleanProperty( new Function0<Boolean>() {
        public Boolean apply() {
            return waterVolume.get() > 0.0;
        }
    }, waterVolume );
}
项目:openjdk9    文件:SetShapeDynamicallyAndClick.java   
@Override
public void applyShape() {
    Area shape = new Area(new Rectangle2D.Float(0, 0, 200, 200));
    GeneralPath gp;
    gp = new GeneralPath();
    gp.moveTo(190, 0);
    gp.lineTo(200, 0);
    gp.lineTo(200, 10);
    gp.lineTo(10, 200);
    gp.lineTo(0, 200);
    gp.lineTo(0, 190);
    gp.closePath();
    shape.subtract(new Area(gp));

    window.setShape(shape);
}
项目:pumpernickel    文件:AbstractGraphics2D.java   
@Override
public Shape getClip() {
    if(clipping==null)
        return null;

    try {
        Area area = new Area(clipping);
        area.transform(transform.createInverse());
        if(area.isRectangular())
            return area.getBounds2D();
        return area;
    } catch(NoninvertibleTransformException t) {
        RuntimeException e2 = new RuntimeException();
        e2.initCause(t);
        throw e2;
    }
}
项目:PhET    文件:DipoleNode.java   
private void updateNode() {
    final double y = 0;
    if ( dipole.get().magnitude() == 0 ) {
        setPathTo( new Rectangle2D.Double() ); // because Arrow doesn't handle zero-length arrows
    }
    else {
        // arrow, in angle=0 orientation (pointing right), so we can easily add cross
        Arrow arrow = new Arrow( new Point2D.Double( 0, 0 ), new Point2D.Double( getDipoleViewLength(), y ),
                                 HEAD_SIZE.height, HEAD_SIZE.width, TAIL_WIDTH, FRACTIONAL_HEAD_HEIGHT, true /* scaleTailToo */ );
        // cross
        Shape cross = createCross( arrow );

        // Combine arrow and cross using constructive area geometry.
        Area area = new Area( arrow.getShape() );
        area.add( new Area( cross ) );
        setPathTo( area );

        // rotate into dipole orientation
        setRotation( dipole.get().getAngle() );
    }
}
项目:audiveris    文件:SIGraph.java   
/**
 * Lookup the sig collection of interpretations for those which contain the provided
 * point.
 *
 * @param point provided point
 * @return the containing interpretations
 */
public List<Inter> containingInters (Point point)
{
    List<Inter> found = new ArrayList<Inter>();

    for (Inter inter : vertexSet()) {
        Rectangle bounds = inter.getBounds();

        if ((bounds != null) && bounds.contains(point)) {
            // More precise test if we know inter area
            Area area = inter.getArea();

            if ((area == null) || area.contains(point)) {
                found.add(inter);
            }
        }
    }

    return found;
}
项目:PhET    文件:PHProbeNode.java   
public TipNode() {
    super();

    // rounded corners at top
    Shape roundRect = new RoundRectangle2D.Float( 0f, 0f, 1f, 1.5f, 0.4f, 0.4f );

    // mask out rounded corners at bottom
    Shape rect = new Rectangle2D.Float( 0f, 0.5f, 1f, 1f );

    // point at the bottom
    GeneralPath triangle = new GeneralPath();
    triangle.moveTo( 0f, 1.5f );
    triangle.lineTo( 0.5f, 2.5f );
    triangle.lineTo( 1f, 1.5f );
    triangle.closePath();

    // constructive area geometry
    Area area = new Area( roundRect );
    area.add( new Area( rect ) );
    area.add( new Area( triangle ) );

    setPathTo( area );
    setPaint( TIP_COLOR );
    setStroke( null );
}
项目:PhET    文件:PressureSliceGraphic.java   
public void update() {
    if( pressureReadingSource == box ) {
        pressure = box.getPressure();
    }
    else {
        pressure = pressureSlice.getPressure();
    }
    temperature = pressureSlice.getTemperature();

    // Clear the drawing area and rebuild it
    drawingArea.exclusiveOr( drawingArea );
    drawingArea.add( new Area( boundingRect ) );
    drawingArea.add( new Area( new Rectangle( (int)readoutRectangle.getX() - 2, (int)readoutRectangle.getY() - 2,
                                              (int)readoutRectangle.getWidth() + 4, (int)readoutRectangle.getHeight() + 4 ) ) );
    setBoundsDirty();
    repaint();
}
项目:audiveris    文件:CurveGap.java   
private Area computeArea ()
{
    final GeoPath path;

    if (p2.x > p1.x) {
        path = new GeoPath(new Line2D.Double(p1.x + 1, p1.y - MARGIN, p2.x, p2.y - MARGIN));
        path.append(new Line2D.Double(p2.x, p2.y + MARGIN, p1.x + 1, p1.y + MARGIN), true);
    } else {
        path = new GeoPath(new Line2D.Double(p1.x, p1.y - MARGIN, p2.x + 1, p2.y - MARGIN));
        path.append(new Line2D.Double(p2.x + 1, p2.y + MARGIN, p1.x, p1.y + MARGIN), true);
    }

    path.closePath();

    return new Area(path);
}
项目:pumpernickel    文件:AbstractShapeTransition2D.java   
/** Calculating the scaling ratio for the shape to fit the dimensions provided. */
protected float calculateMultiplier(Dimension size) {
    Shape shape = getShape();
    Area base = new Area(shape);
    AffineTransform transform = new AffineTransform();
    Rectangle2D r = ShapeBounds.getBounds(base);
    transform.translate(size.width/2f-r.getCenterX(),size.height/2f-r.getCenterY());
    base.transform(transform);
    r = ShapeBounds.getBounds(base,r);
    float min = 0;
    float max = 1;
    Rectangle2D boundsRect = new Rectangle2D.Float(0,0,size.width,size.height);
    while(isOK(base,r,boundsRect,max)==false) {
        min = max;
        max*=1.2;
    }
    float f = calculateMultiplier(base,r,boundsRect,min,max);
    isOK(base,r,boundsRect,f);
    return f;
}
项目:SweetHome3D    文件:ModelManager.java   
/**
 * Adds to <code>nodePath</code> the quadrilateral joining vertices at 
 * vertexIndex1, vertexIndex2, vertexIndex3, vertexIndex4 indices, 
 * only if the quadrilateral has a positive orientation. 
 */
private void addQuadrilateralToPath(GeometryArray geometryArray, int vertexIndex1, int vertexIndex2,
        int vertexIndex3, int vertexIndex4, float[] vertices, GeneralPath geometryPath, int quadrilateralIndex,
        Area nodeArea)
{
    float xVertex1 = vertices[2 * vertexIndex1];
    float yVertex1 = vertices[2 * vertexIndex1 + 1];
    float xVertex2 = vertices[2 * vertexIndex2];
    float yVertex2 = vertices[2 * vertexIndex2 + 1];
    float xVertex3 = vertices[2 * vertexIndex3];
    float yVertex3 = vertices[2 * vertexIndex3 + 1];
    if ((xVertex2 - xVertex1) * (yVertex3 - yVertex2) - (yVertex2 - yVertex1) * (xVertex3 - xVertex2) > 0)
    {
        if (quadrilateralIndex > 0 && quadrilateralIndex % 1000 == 0)
        {
            // Add now current path to area otherwise area gets too slow
            nodeArea.add(new Area(geometryPath));
            geometryPath.reset();
        }
        geometryPath.moveTo(xVertex1, yVertex1);
        geometryPath.lineTo(xVertex2, yVertex2);
        geometryPath.lineTo(xVertex3, yVertex3);
        geometryPath.lineTo(vertices[2 * vertexIndex4], vertices[2 * vertexIndex4 + 1]);
        geometryPath.closePath();
    }
}
项目:SweetHome3D    文件:PlanController.java   
/**
 * Returns the list of closed paths that may define rooms from 
 * the current set of home walls.
 */
private List<GeneralPath> getRoomPathsFromWalls()
{
    if (this.roomPathsCache == null)
    {
        // Iterate over all the paths the walls area contains
        Area wallsArea = getWallsArea(false);
        List<GeneralPath> roomPaths = getAreaPaths(wallsArea);
        Area insideWallsArea = new Area(wallsArea);
        for (GeneralPath roomPath : roomPaths)
        {
            insideWallsArea.add(new Area(roomPath));
        }

        this.roomPathsCache = roomPaths;
        this.insideWallsAreaCache = insideWallsArea;
    }
    return this.roomPathsCache;
}
项目:aya-lang    文件:FXGraphics2D.java   
/**
 * Clips to the intersection of the current clipping region and the
 * specified shape. 
 * 
 * According to the Oracle API specification, this method will accept a 
 * {@code null} argument, but there is an open bug report (since 2004) 
 * that suggests this is wrong:
 * <p>
 * <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6206189">
 * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6206189</a>
 * 
 * In this implementation, a {@code null} argument is not permitted.
 * 
 * @param s  the clip shape ({@code null} not permitted). 
 */
@Override
public void clip(Shape s) {
    if (this.clip == null) {
        setClip(s);
        return;
    }
    Shape ts = this.transform.createTransformedShape(s);
    Shape clipNew;
    if (!ts.intersects(this.clip.getBounds2D())) {
        clipNew = new Rectangle2D.Double();
    } else {
        Area a1 = new Area(ts);
        Area a2 = new Area(this.clip);
        a1.intersect(a2);
        clipNew = new Path2D.Double(a1);
    }
    this.clip = clipNew;
    if (!this.clippingDisabled) {
        this.gc.save();
        this.saveCount++;
        shapeToPath(this.clip);
        this.gc.clip();
    }
}
项目:audiveris    文件:BeamItem.java   
public Area getBeltArea (Area coreArea,
                         int dx,
                         int topDy,
                         int bottomDy)
{
    final double shiftY = (bottomDy - topDy) / 2;
    final double beltHeight = height + topDy + bottomDy;

    Point2D p1 = LineUtil.intersectionAtX(median, median.getX1() - dx);
    p1.setLocation(p1.getX(), p1.getY() + shiftY);

    Point2D p2 = LineUtil.intersectionAtX(median, median.getX2() + dx);
    p2.setLocation(p2.getX(), p2.getY() + shiftY);

    Area beltArea = AreaUtil.horizontalParallelogram(p1, p2, beltHeight);
    beltArea.subtract(coreArea);

    return beltArea;
}
项目:pumpernickel    文件:BasicQOptionPaneUI.java   
@SuppressWarnings("unused")
public void paintBorder(Component c, Graphics g0, int x, int y,
        int width, int height) {
    Graphics2D g = (Graphics2D)g0;
    Area area = new Area(new Rectangle(x, y, width, height));
    area.subtract(new Area(new Rectangle(
            x+insets.left, y+insets.top,
            width-insets.left-insets.right,
            height-insets.top-insets.bottom
    )));
    if(c.isOpaque()) {
        Color bkgnd = c.getBackground();
        g.setColor(bkgnd);
        g.fill(area);
    }
    if(false) {
        g.setColor(debugColor);
        g.fill(area);
    }
}