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

项目:jdk8u-jdk    文件:ScaleTest.java   
public static void main(String[] args) throws Exception {
  BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
  Graphics2D g = image.createGraphics();

  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g.setPaint(Color.WHITE);
  g.fill(new Rectangle(image.getWidth(), image.getHeight()));
  g.scale(.9, .9);
  g.setPaint(Color.BLACK);
  g.setStroke(new BasicStroke(0.5f));
  g.draw(new Ellipse2D.Double(25, 25, 150, 150));

  // To visually check it
  //ImageIO.write(image, "PNG", new File(args[0]));

  boolean nonWhitePixelFound = false;
  for (int x = 100; x < 200; ++x) {
    if (image.getRGB(x, 90) != Color.WHITE.getRGB()) {
      nonWhitePixelFound = true;
      break;
    }
  }
  if (!nonWhitePixelFound) {
    throw new RuntimeException("A circle is rendered like a 'C' shape.");
  }
}
项目:jdk8u-jdk    文件:RenderTests.java   
public void runTest(Object ctx, int numReps) {
    FillEllipse2Ds.Context cctx = (FillEllipse2Ds.Context) ctx;
    int size = cctx.size;
    int x = cctx.initX;
    int y = cctx.initY;
    Ellipse2D ellipse = cctx.ellipse;
    Graphics2D g2d = (Graphics2D) cctx.graphics;
    g2d.translate(cctx.orgX, cctx.orgY);
    Color rCArray[] = cctx.colorlist;
    int ci = cctx.colorindex;
    do {
        if (rCArray != null) {
            g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        ellipse.setFrame(x, y, size, size);
        g2d.fill(ellipse);
        if ((x -= 3) < 0) x += cctx.maxX;
        if ((y -= 1) < 0) y += cctx.maxY;
    } while (--numReps > 0);
    cctx.colorindex = ci;
    g2d.translate(-cctx.orgX, -cctx.orgY);
}
项目:cuttlefish    文件:Vertex.java   
/**
 * Creates the shape of the vertex given its description in a string
 * @param shapeString "square" or "circle"
 */
public void setShape(String shapeString) {
    Shape newShape;
    if (shapeString.startsWith("square")){
        Rectangle2D rectangle = new Rectangle2D.Float();
        rectangle.setFrameFromCenter(0,0,size,size);
        newShape = rectangle;
    }
    else
    {
        Ellipse2D ellipse = new Ellipse2D.Float();
        ellipse.setFrameFromCenter(0,0,size,size);
        newShape = ellipse; 
    }
    this.shape = newShape;
}
项目:jmt    文件:QueueDrawer.java   
public void changeDrawSettings(DrawConstrains dCst) {
    this.dCst = dCst;
    resize();
    // assigning the constant of panel
    f = dCst.getFont();
    stroke = dCst.getDrawStroke();
    START_GAP = dCst.getStartingGap();
    END_GAP = dCst.getStartingGap();
    ELEM_HEIGHT = dCst.getElementHeight();
    ELEM_WIDTH = dCst.getElementWidth();
    ELEMS_GAP = dCst.getElementsGap();
    PROC_RAD = dCst.getProcessorRadius();

    // initilazing the queue
    queue = new Rectangle2D.Double[queueLength()];
    processor = new Ellipse2D.Double();
    // repaint();
}
项目:jmt    文件:StatiDrawer.java   
public void drawStatus(int status, double probability, Graphics2D g2d, Color sc, Color pc, Color borderC, boolean bold) {
    double x = 2.0 * (2.0 * STATUS_RAD + ELEMS_GAP) * status + START_GAP;
    double y = panelH / 2.0 - STATUS_RAD;
    double pie = probability * 360;
    Color ctmp = g2d.getColor();
    if (bold) {
        g2d.setStroke(strokeB);
    }
    statusE[status] = new Ellipse2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0);
    statusP[status] = new Arc2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0, 0.0, pie, Arc2D.PIE);
    g2d.setPaint(sc);
    g2d.fill(statusE[status]);
    g2d.setPaint(pc);
    g2d.fill(statusP[status]);
    g2d.setPaint(borderC);
    g2d.draw(statusE[status]);
    drawCenteredText(probabilityToString(probability, 3), Color.BLACK, x + STATUS_RAD, y - STATUS_RAD, g2d, false);
    drawCenteredText("" + status, borderC, x + STATUS_RAD, panelH / 2.0, g2d, false);
    g2d.setColor(ctmp);
    g2d.setStroke(stroke);
}
项目:parabuild-ci    文件:DialCap.java   
/**
 * Draws the background to the specified graphics device.  If the dial
 * frame specifies a window, the clipping region will already have been 
 * set to this window before this method is called.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param plot  the plot (ignored here).
 * @param frame  the dial frame (ignored here).
 * @param view  the view rectangle (<code>null</code> not permitted). 
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {

    g2.setPaint(this.fillPaint);

    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, 
            this.radius);
    Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), 
            f.getHeight());
    g2.fill(e);
    g2.setPaint(this.outlinePaint);
    g2.setStroke(this.outlineStroke);
    g2.draw(e);

}
项目: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);
}
项目:openjdk-jdk10    文件:RenderTests.java   
public void runTest(Object ctx, int numReps) {
    FillEllipse2Ds.Context cctx = (FillEllipse2Ds.Context) ctx;
    int size = cctx.size;
    int x = cctx.initX;
    int y = cctx.initY;
    Ellipse2D ellipse = cctx.ellipse;
    Graphics2D g2d = (Graphics2D) cctx.graphics;
    g2d.translate(cctx.orgX, cctx.orgY);
    Color rCArray[] = cctx.colorlist;
    int ci = cctx.colorindex;
    do {
        if (rCArray != null) {
            g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        ellipse.setFrame(x, y, size, size);
        g2d.fill(ellipse);
        if ((x -= 3) < 0) x += cctx.maxX;
        if ((y -= 1) < 0) y += cctx.maxY;
    } while (--numReps > 0);
    cctx.colorindex = ci;
    g2d.translate(-cctx.orgX, -cctx.orgY);
}
项目:spacesettlers    文件:EMPGraphics.java   
@Override
public void draw(Graphics2D graphics) {
       float radius = emp.getRadius();
       float diameter = radius * 2;

       // inner ring
       graphics.setColor(outerColor);
       graphics.fill(new Ellipse2D.Double(drawLocation.getX() - radius,
               drawLocation.getY() - radius, diameter, diameter));

       radius = radius - 2;
       diameter = radius * 2;

       graphics.setColor(EMP_INNER_COLOR);
       graphics.fill(new Ellipse2D.Double(drawLocation.getX() - radius,
               drawLocation.getY() - radius, diameter, diameter));

}
项目:DIA-Umpire-Maven    文件:RTAlignedPepIonMapping.java   
private void GenerateRTMapPNG(XYSeriesCollection xySeriesCollection, XYSeries series, float R2) throws IOException {
    new File(Workfolder + "/RT_Mapping/").mkdir();
    String pngfile = Workfolder + "/RT_Mapping/" + FilenameUtils.getBaseName(LCMSA.mzXMLFileName).substring(0, Math.min(120, FilenameUtils.getBaseName(LCMSA.mzXMLFileName).length() - 1)) + "_" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName).substring(0, Math.min(120, FilenameUtils.getBaseName(LCMSB.mzXMLFileName).length() - 1)) + "_RT.png";

    XYSeries smoothline = new XYSeries("RT fitting curve");
    for (XYZData data : regression.PredictYList) {
        smoothline.add(data.getX(), data.getY());
    }
    xySeriesCollection.addSeries(smoothline);
    xySeriesCollection.addSeries(series);
    JFreeChart chart = ChartFactory.createScatterPlot("Retention time mapping: R2=" + R2, "RT:" + FilenameUtils.getBaseName(LCMSA.mzXMLFileName), "RT:" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName), xySeriesCollection,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);

    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesPaint(1, Color.blue);
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesShape(1, new Ellipse2D.Double(0, 0, 3, 3));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    xyPlot.setBackgroundPaint(Color.white);
    ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
}
项目:spacesettlers    文件:BeaconGraphics.java   
public void draw(Graphics2D g) {
      float radius = Beacon.BEACON_RADIUS;
      float diameter = Beacon.BEACON_RADIUS * 2;

      Ellipse2D.Double shape = new Ellipse2D.Double(drawLocation.getX() - radius,
            drawLocation.getY() - radius, diameter, diameter);

      g.setColor(BEACON_COLOR);
      g.fill(shape);

      g.setStroke(JSpaceSettlersComponent.THICK_STROKE);
      g.setColor(BEACON_LINE_COLOR);
      g.draw(shape);

      // add an E to make it clear it is an energy beacon
g.setPaint(Color.BLACK);
g.drawString("E", (int) drawLocation.getX()-3, (int) drawLocation.getY() + 4);

  }
项目:SE2017-Team1    文件:Place.java   
/**
 * Paints the Place
 * @param g - graphic object to contain the Place
 */
public void paintPlace(Graphics g){
    int diameter = 30;

    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(Color.WHITE);
    Ellipse2D.Double circle = new Ellipse2D.Double((position.x - (diameter / 2)), (position.y - (diameter / 2)),
            diameter, diameter);
    g2d.fill(circle);

    g2d.setColor(Color.GREEN);
    g2d.fill(circle);
    if (token){
        g2d.setColor(Color.DARK_GRAY);
        Ellipse2D.Double t = new Ellipse2D.Double((position.x - (diameter / 4)),
                (position.y - (diameter / 4)),
                (diameter / 2), (diameter / 2));
        g2d.fill(t);
    }
}
项目:parabuild-ci    文件:AbstractXYItemRenderer.java   
/**
 * Adds an entity to the collection.
 * 
 * @param entities  the entity collection being populated.
 * @param area  the entity area (if <code>null</code> a default will be used).
 * @param entityX  the entity's center x-coordinate in user space.
 * @param entityY  the entity's center y-coordinate in user space.
 * @param dataset  the dataset.
 * @param series  the series.
 * @param item  the item.
 */
protected void addEntity(EntityCollection entities, Shape area, 
                         XYDataset dataset, int series, int item,
                         double entityX, double entityY) {

    if (area == null) {
        area = new Ellipse2D.Double(
            entityX - this.defaultEntityRadius, entityY - this.defaultEntityRadius, 
            this.defaultEntityRadius * 2, this.defaultEntityRadius * 2
        );
    }
    String tip = null;
    XYToolTipGenerator generator = getToolTipGenerator(series, item);
    if (generator != null) {
        tip = generator.generateToolTip(dataset, series, item);
    }
    String url = null;
    if (getURLGenerator() != null) {
        url = getURLGenerator().generateURL(dataset, series, item);
    }
    XYItemEntity entity = new XYItemEntity(area, dataset, series, item, tip, url);
    entities.addEntity(entity);
}
项目:SE2017-Team1    文件:PetriPlace.java   
public void paintPlace(Graphics g){
    int diameter = 30;

    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(Color.WHITE);
    Ellipse2D.Double circle = new Ellipse2D.Double((position.x - (diameter / 2)), (position.y - (diameter / 2)),
            diameter, diameter);
    g2d.fill(circle);

    g2d.setColor(Color.GREEN);
    g2d.fill(circle);
    if (token){
        g2d.setColor(Color.DARK_GRAY);
        Ellipse2D.Double t = new Ellipse2D.Double((position.x - (diameter / 4)),
                (position.y - (diameter / 4)),
                (diameter / 2), (diameter / 2));
        g2d.fill(t);
    }
}
项目:QN-ACTR-Release    文件:QueueDrawer.java   
public void changeDrawSettings(DrawConstrains dCst) {
    this.dCst = dCst;
    resize();
    // assigning the constant of panel
    f = dCst.getFont();
    stroke = dCst.getDrawStroke();
    START_GAP = dCst.getStartingGap();
    END_GAP = dCst.getStartingGap();
    ELEM_HEIGHT = dCst.getElementHeight();
    ELEM_WIDTH = dCst.getElementWidth();
    ELEMS_GAP = dCst.getElementsGap();
    PROC_RAD = dCst.getProcessorRadius();

    // initilazing the queue
    queue = new Rectangle2D.Double[queueLenght()];
    processor = new Ellipse2D.Double();
    // repaint();
}
项目: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    文件:StatiDrawer.java   
public void drawLastStatus(String jobStr, double probability, Graphics2D g2d, Color sc, Color pc) {
    double x = 2.0 * (2.0 * STATUS_RAD + ELEMS_GAP) * (queueLenght() - 1) + START_GAP;
    double y = panelH / 2.0 - STATUS_RAD;
    Color ctmp = g2d.getColor();
    lastStatusE = new Ellipse2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0);
    g2d.setPaint(sc);
    g2d.fill(lastStatusE);
    //if(queueMax != 0){
    double pie = probability * 360;
    lastStatusP = new Arc2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0, 0.0, pie, Arc2D.PIE);
    g2d.setPaint(pc);
    g2d.fill(lastStatusP);
    g2d.setPaint(Color.BLACK);
    drawCenteredText(probabilityToString(probability, 3), Color.BLACK, x + STATUS_RAD, y - STATUS_RAD, g2d, false);
    //drawCenteredText("" + queueMax, Color.BLACK, x + STATUS_RAD, panelH/2.0, g2d, false);
    drawCenteredText(jobStr, Color.BLACK, x + STATUS_RAD, panelH / 2.0, g2d, false);
    //}
    g2d.setPaint(Color.BLACK);
    g2d.draw(lastStatusE);
    g2d.setColor(ctmp);
}
项目:ramus    文件:GEFComponent.java   
protected void paintSelection(Graphics2D g) {
    Rectangle2D rect = translate(selection.getRectangle(), selection);
    double plus = 0;
    if (selection.getBounds().length > 1) {
        plus = GROUP_SELECTION_ADD;
        g.draw(new Rectangle2D.Double(rect.getX() - plus, rect.getY()
                - plus, rect.getWidth() + plus * 2, rect.getHeight() + plus
                * 2));
    }
    if (drag)
        return;
    if (!drag)
        return;
    double x = rect.getCenterX();
    double y1 = rect.getMinY() - plus;
    double y2 = y1 - ROTATE_LINE_LENGTH;
    g.draw(new Line2D.Double(x, y1, x, y2));
    Ellipse2D.Double ellipse = new Ellipse2D.Double(x - ROTATE_SPOT_WIDTH
            / 2, y2 - ROTATE_SPOT_WIDTH, ROTATE_SPOT_WIDTH,
            ROTATE_SPOT_WIDTH);
    g.setColor(ROTATE_SPOT_COLOR);
    g.fill(ellipse);
    g.setColor(Color.black);
    g.draw(ellipse);

}
项目:parabuild-ci    文件:CompassPlot.java   
/**
 * Constructs a new compass plot.
 *
 * @param dataset  the dataset for the plot.
 */
public CompassPlot(ValueDataset dataset) {

    super();

    if (dataset != null) {
        this.datasets[0] = dataset;
        dataset.addChangeListener(this);
    }


    this.circle1 = new Ellipse2D.Double();
    this.circle2 = new Ellipse2D.Double();
    this.rect1   = new Rectangle2D.Double();
    setSeriesNeedle(0);

}
项目:cuttlefish    文件:IntersectingShapePickSupport.java   
public static boolean containsPoint(Vertex vertex, Point2D p,
        double scaleFactor) {
    Shape vertexShape = null;
    double size = vertex.getSize() / scaleFactor;
    double x = vertex.getPosition().getX() - size;
    double y = vertex.getPosition().getY() - size;

    if (vertex.getShape().equals(Constants.SHAPE_DISK)) {
        vertexShape = new Ellipse2D.Double(x, y, 2 * size, 2 * size);

    } else if (vertex.getShape().equals(Constants.SHAPE_SQUARE)) {
        vertexShape = new Rectangle2D.Double(x, y, 2 * size, 2 * size);
    }

    return vertexShape.contains(p);
}
项目:jdk8u-jdk    文件:RenderTests.java   
public void runTest(Object ctx, int numReps) {
    DrawEllipse2Ds.Context cctx = (DrawEllipse2Ds.Context) ctx;
    int size = cctx.size;
    int x = cctx.initX;
    int y = cctx.initY;
    Ellipse2D ellipse = cctx.ellipse;
    Graphics2D g2d = (Graphics2D) cctx.graphics;
    g2d.translate(cctx.orgX, cctx.orgY);
    Color rCArray[] = cctx.colorlist;
    int ci = cctx.colorindex;
    do {
        if (rCArray != null) {
            g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        ellipse.setFrame(x, y, size, size);
        g2d.draw(ellipse);
        if ((x -= 3) < 0) x += cctx.maxX;
        if ((y -= 1) < 0) y += cctx.maxY;
    } while (--numReps > 0);
    cctx.colorindex = ci;
    g2d.translate(-cctx.orgX, -cctx.orgY);
}
项目:litiengine    文件:LightSource.java   
@Override
public void setLocation(final Point2D location) {
  super.setLocation(location);
  switch (this.getLightShapeType()) {
  case LightSource.ELLIPSE:
    this.lightShape = new Ellipse2D.Double(location.getX(), location.getY(), this.getWidth(), this.getHeight());
    break;
  case LightSource.RECTANGLE:
    this.lightShape = new Rectangle2D.Double(location.getX(), location.getY(), this.getWidth(), this.getHeight());
    break;
  default:
    this.lightShape = new Ellipse2D.Double(location.getX(), location.getY(), this.getWidth(), this.getHeight());
    break;
  }
}
项目:litiengine    文件:LightSource.java   
/**
 * Gets the shadow ellipse.
 *
 * @param mob
 *          the mob
 * @return the shadow ellipse
 */
private static Ellipse2D getShadowEllipse(final IEntity mob) {
  final int shadowHeight = (int) (mob.getHeight() / 4);
  final int shadowWidth = (int) (mob.getWidth() / 3);

  final int yOffset = (int) mob.getHeight();
  final double x = mob.getLocation().getX() + (mob.getWidth() - shadowWidth) / 2;
  final double y = mob.getLocation().getY() + yOffset - shadowHeight / 2.0;
  return new Ellipse2D.Double(x, y, shadowWidth, shadowHeight);
}
项目:TrabalhoFinalEDA2    文件:mxGraphicsCanvas2D.java   
/**
 * 
 */
public void ellipse(double x, double y, double w, double h)
{
    currentPath = new GeneralPath();
    currentPath.append(new Ellipse2D.Double((state.dx + x) * state.scale,
            (state.dy + y) * state.scale, w * state.scale, h * state.scale),
            false);
}
项目:hearthstone    文件:Img.java   
/**
 * Retorna um recorte cirular da imagem passada por parâmetro
 *
 * @param imagem imagem a ser recortada
 * @param x início do corte na horizontal
 * @param y início do corte na vertical
 * @param w largura do corte
 * @param h altura do corte
 * @return imagem recortada ou a mesma imagem para valores inválidos
 */
public static ImageIcon getCirculo(ImageIcon imagem, int x, int y, int w, int h) {
    try {
        BufferedImage other = new BufferedImage(imagem.getIconWidth(), imagem.getIconHeight(), TYPE_INT_ARGB);
        Graphics2D g2d = other.createGraphics();
        g2d.setClip(new Ellipse2D.Double(x, y, w, h));
        g2d.drawImage(imagem.getImage(), 0, 0, null);
        g2d.dispose();
        other = other.getSubimage(x, y, w, h);
        return new ImageIcon(other);
    } catch (Exception ex) {
        return imagem;
    }
}
项目:jdk8u-jdk    文件:ThinLineTest.java   
public static void main(String[] args) throws Exception {
  BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
  Graphics2D g = image.createGraphics();

  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g.setPaint(Color.WHITE);
  g.fill(new Rectangle(image.getWidth(), image.getHeight()));

  g.scale(0.5 / PIXEL, 0.5 / PIXEL);
  g.setPaint(Color.BLACK);
  g.setStroke(new BasicStroke(PIXEL));
  g.draw(new Ellipse2D.Double(PIXEL * 50, PIXEL * 50, PIXEL * 300, PIXEL * 300));

  // To visually check it
  //ImageIO.write(image, "PNG", new File(args[0]));

  boolean nonWhitePixelFound = false;
  for (int x = 0; x < 200; ++x) {
    if (image.getRGB(x, 100) != Color.WHITE.getRGB()) {
      nonWhitePixelFound = true;
      break;
    }
  }
  if (!nonWhitePixelFound) {
    throw new RuntimeException("The thin line disappeared.");
  }
}
项目:parabuild-ci    文件:WaferMapPlot.java   
/**
 * Calculates the location of the waferedge.
 * 
 * @param plotArea  the plot area.
 * 
 * @return The wafer edge.
 */
protected Ellipse2D getWaferEdge(Rectangle2D plotArea) {
    Ellipse2D edge = new Ellipse2D.Double();
    double diameter = plotArea.getWidth();
    double upperLeftX = plotArea.getX();
    double upperLeftY = plotArea.getY();
    //get major dimension
    if (plotArea.getWidth() != plotArea.getHeight()) {
        double major = 0d;
        double minor = 0d;
        if (plotArea.getWidth() > plotArea.getHeight()) {
            major = plotArea.getWidth();
            minor = plotArea.getHeight();
        } 
        else {
            major = plotArea.getHeight();
            minor = plotArea.getWidth();
        } 
        //ellipse diameter is the minor dimension
        diameter = minor;
        //set upperLeft point
        if (plotArea.getWidth() == minor) { // x is minor
            upperLeftY = plotArea.getY() + (major - minor) / 2;
        }
        else { // y is minor
            upperLeftX = plotArea.getX() + (major - minor) / 2;
        }
    }
    edge.setFrame(upperLeftX, upperLeftY, diameter, diameter); 
    return edge;        
}
项目:rapidminer    文件:RoundTitledBorder.java   
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setRenderingHints(ProcessDrawer.HI_QUALITY_HINTS);
    g2d.setStroke(new BasicStroke(2f));

    // clear edges, otherwise they will be in the color of the component background
    if (drawRoundFrame && !c.getBackground().equals(c.getParent().getBackground())) {
        Shape frame = new Rectangle2D.Float(x + 2, y + 2, width - 4, height - 4);
        g2d.setPaint(c.getParent().getBackground());
        g2d.draw(frame);
    }

    g2d.setPaint(paint);
    g2d.setFont(new Font("Dialog", Font.BOLD, 21));

    if (drawRoundFrame) {
        Shape roundFrame = new RoundRectangle2D.Float(x + 2, y + 2, width - 4, height - 4, 10, 10);
        g2d.draw(roundFrame);
    }

    if (number > 0) {
        Shape circle = new Ellipse2D.Float(20, 20, 34, 34);
        g2d.fill(circle);
        g2d.setPaint(Color.WHITE);
        g2d.drawString(String.valueOf(number), 29, 44);
    }

    if (key != null) {
        g2d.setPaint(paint);
        g2d.drawString(key, 60, 44);
    }

    g2d.dispose();
}
项目:jmt    文件:QueueDrawer.java   
private void drawUtilization(double U, Color startC, Color border, boolean gradientFill, Graphics2D g2d) {

        double x = getProcessorXY().x, y = getProcessorXY().y;
        try {
            occupiedRect = new Rectangle2D.Double(x, y, 2 * PROC_RAD, 2 * PROC_RAD * (1 - U));
        } catch (Exception e) {
            occupiedRect = new Rectangle2D.Double(x, y, 2 * PROC_RAD, 0.0);
        }
        occupiedEll = new Ellipse2D.Double(x, y, 2 * PROC_RAD, 2 * PROC_RAD);
        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);

        // //draw informations about processes
        // txtBounds = drawCenteredText("job n.:" + donejobs, Color.BLACK, x +
        // PROC_RAD,y + PROC_RAD * 2 + 4 * ELEMS_GAP,g2d, false);
        // //draw orizontal line parallel to occupation
        //          
        // //draw box around text
        // txtBounds.setFrame(
        // x + PROC_RAD - txtBounds.getWidth() / 2,
        // y + 2 * PROC_RAD + 4 * ELEMS_GAP - txtBounds.getHeight() / 2,
        // txtBounds.getWidth(),
        // txtBounds.getHeight());
        //          
        // g2d.draw(txtBounds);
    }
项目:TrabalhoFinalEDA2    文件:mxCylinderShape.java   
/**
 * Draws a cylinder for the given parameters.
 */
public void paintShape(mxGraphics2DCanvas canvas, mxCellState state)
{
    Rectangle rect = state.getRectangle();
    int x = rect.x;
    int y = rect.y;
    int w = rect.width;
    int h = rect.height;
    int h4 = h / 4;
    int h2 = h4 / 2;
    int r = w;

    // Paints the background
    if (configureGraphics(canvas, state, true))
    {
        Area area = new Area(new Rectangle(x, y + h4 / 2, r, h - h4));
        area.add(new Area(new Rectangle(x, y + h4 / 2, r, h - h4)));
        area.add(new Area(new Ellipse2D.Float(x, y, r, h4)));
        area.add(new Area(new Ellipse2D.Float(x, y + h - h4, r, h4)));

        canvas.fillShape(area, hasShadow(canvas, state));
    }

    // Paints the foreground
    if (configureGraphics(canvas, state, false))
    {
        canvas.getGraphics().drawOval(x, y, r, h4);
        canvas.getGraphics().drawLine(x, y + h2, x, y + h - h2);
        canvas.getGraphics().drawLine(x + w, y + h2, x + w, y + h - h2);
        // TODO: Use QuadCurve2D.Float() for painting the arc
        canvas.getGraphics().drawArc(x, y + h - h4, r, h4, 0, -180);
    }
}
项目:jmt    文件:QueueDrawer.java   
private void drawOccupiedPercentage(Color startC, Color border, boolean gradientFill, Graphics2D g2d) {

        if (remainingTime[0] != 0) {
            double x = getProcessorXY().x, y = getProcessorXY().y;
            occupiedRect = new Rectangle2D.Double(x, y, 2 * PROC_RAD, 2 * PROC_RAD * (1 - (double) remainingTime[0] / (double) totTime[0]));
            occupiedEll = new Ellipse2D.Double(x, y, 2 * PROC_RAD, 2 * PROC_RAD);
            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);

            // draw orizontal line parallel to occupation
            Line2D.Double l = new Line2D.Double(x + PROC_RAD * 2 + ELEMS_GAP, y + PROC_RAD * 2
                    * (1 - (double) remainingTime[0] / (double) totTime[0]), x + PROC_RAD * 2 + 2 * ELEMS_GAP, y + PROC_RAD * 2
                    * (1 - (double) remainingTime[0] / (double) totTime[0]));
            g2d.draw(l);

            // draw vertical line
            l = new Line2D.Double(x + PROC_RAD * 2 + 2 * ELEMS_GAP, y + PROC_RAD * 2 * (1 - (double) remainingTime[0] / (double) totTime[0]), x
                    + PROC_RAD * 2 + 2 * ELEMS_GAP, y + 2 * PROC_RAD + 4 * ELEMS_GAP - txtBounds.getHeight() / 2);
            g2d.draw(l);

            // draw horizontal line under text
            txtBounds.setFrame(x + PROC_RAD - txtBounds.getWidth() / 2, y + 2 * PROC_RAD + 4 * ELEMS_GAP - txtBounds.getHeight() / 2, txtBounds
                    .getWidth(), txtBounds.getHeight());

            g2d.draw(txtBounds);
        }
    }
项目:jmt    文件:QueueDrawer.java   
private void drawOccupiedPercentage2(Color startC, Color border, boolean gradientFill, Graphics2D g2d, int cpu) {
    //processor.setFrame(x+PROC_RAD/2 , y + cpu*PROC_RAD, 2 * PROC_RAD /2, 2 * PROC_RAD /2);

    //      if (remainingTime[cpu] != 0) {
    double x = getProcessorXY().x, y = getProcessorXY().y;
    occupiedRect = new Rectangle2D.Double(x + PROC_RAD / 2, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2, 2 * PROC_RAD / 2, 2 * PROC_RAD
            * (1 - (double) remainingTime[cpu] / (double) totTime[cpu]) / 2);
    occupiedEll = new Ellipse2D.Double(x + PROC_RAD / 2, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2, 2 * PROC_RAD / 2, 2 * PROC_RAD / 2);
    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);

    // draw orizontal line parallel to occupation
    Line2D.Double l = new Line2D.Double(x + PROC_RAD * 2 + ELEMS_GAP, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2 + 2 * PROC_RAD
            * (1 - (double) remainingTime[cpu] / (double) totTime[cpu]) / 2,//y + PROC_RAD * 2 * (1 - (double) remainingTime / (double) totTime) /2 + ELEMS_GAP * cpu -  ELEMS_GAP /2  , 
            x + PROC_RAD * 2 + 2 * ELEMS_GAP, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2 + 2 * PROC_RAD
                    * (1 - (double) remainingTime[cpu] / (double) totTime[cpu]) / 2);//y + PROC_RAD * 2 * (1 - (double) remainingTime / (double) totTime) /2 + ELEMS_GAP * cpu -  ELEMS_GAP /2 );
    g2d.draw(l);

    // draw vertical line
    l = new Line2D.Double(x + PROC_RAD * 2 + 2 * ELEMS_GAP, y + cpu * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2 + 2 * PROC_RAD
            * (1 - (double) remainingTime[cpu] / (double) totTime[cpu]) / 2, x + PROC_RAD * 2 + 2 * ELEMS_GAP, y + PROC_RAD * 2 / 2 + cpu
            * PROC_RAD + ELEMS_GAP * cpu - ELEMS_GAP / 2);
    g2d.draw(l);

    //      }
}
项目:snake_classic    文件:ButtonBack.java   
@Override
public boolean contains(int x, int y) {
    // TODO Auto-generated method stub
    if(shape == null || shape.getBounds().equals(getBounds()))
        shape = new Ellipse2D.Float(0,0,getWidth(),getHeight());
    return super.contains(x, y);
}
项目:snake_classic    文件:JRadialEllipseButton.java   
public JRadialEllipseButton(){
    isPressed = false;
    this.addMouseListener(new CustomMouseListener());
    region = new Ellipse2D.Double();
    radius = 0;
    radioColors = DEFAULT_RADIO_COLORS;
    disOfColors = DEFAULT_DISTANCE_COLORS;
    reversalRadioColors = DEFAULT_RADIO_COLORS;
    reversalDisOfColors = DEFAULT_DISTANCE_COLORS;
    thisButton = this;
    recalcuteReverse();
}
项目:snake_classic    文件:JRadialEllipseButton.java   
@Override
public void mousePressed(MouseEvent e){
    if(e.getButton() == MouseEvent.BUTTON1 && 
            new Ellipse2D.Double(0.0, 0.0, region.width, region.height).contains(e.getPoint())){
        isPressed = true;
        repaint();
        fireActionPerformed(new ActionEvent(thisButton, 0, null));
    }
}
项目:Java-Algorithms-Learning    文件:StdDraw.java   
/**
 * Draws a point centered at (<em>x</em>, <em>y</em>).
 * The point is a filled circle whose radius is equal to the pen radius.
 * To draw a single-pixel point, first set the pen radius to 0.
 *
 * @param x the <em>x</em>-coordinate of the point
 * @param y the <em>y</em>-coordinate of the point
 */
public static void point(double x, double y) {
    double xs = scaleX(x);
    double ys = scaleY(y);
    double r = penRadius;
    float scaledPenRadius = (float) (r * DEFAULT_SIZE);

    // double ws = factorX(2*r);
    // double hs = factorY(2*r);
    // if (ws <= 1 && hs <= 1) pixel(x, y);
    if (scaledPenRadius <= 1) pixel(x, y);
    else offscreen.fill(new Ellipse2D.Double(xs - scaledPenRadius/2, ys - scaledPenRadius/2,
                                             scaledPenRadius, scaledPenRadius));
    draw();
}
项目:openjdk-jdk10    文件:ThinLineTest.java   
public static void main(String[] args) throws Exception {
  BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
  Graphics2D g = image.createGraphics();

  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g.setPaint(Color.WHITE);
  g.fill(new Rectangle(image.getWidth(), image.getHeight()));

  g.scale(0.5 / PIXEL, 0.5 / PIXEL);
  g.setPaint(Color.BLACK);
  g.setStroke(new BasicStroke(PIXEL));
  g.draw(new Ellipse2D.Double(PIXEL * 50, PIXEL * 50, PIXEL * 300, PIXEL * 300));

  // To visually check it
  //ImageIO.write(image, "PNG", new File(args[0]));

  boolean nonWhitePixelFound = false;
  for (int x = 0; x < 200; ++x) {
    if (image.getRGB(x, 100) != Color.WHITE.getRGB()) {
      nonWhitePixelFound = true;
      break;
    }
  }
  if (!nonWhitePixelFound) {
    throw new RuntimeException("The thin line disappeared.");
  }
}
项目:Java-Algorithms-Learning    文件:StdDraw.java   
/**
 * Draws an ellipse with the specified semimajor and semiminor axes,
 * centered at (<em>x</em>, <em>y</em>).
 *
 * @param  x the <em>x</em>-coordinate of the center of the ellipse
 * @param  y the <em>y</em>-coordinate of the center of the ellipse
 * @param  semiMajorAxis is the semimajor axis of the ellipse
 * @param  semiMinorAxis is the semiminor axis of the ellipse
 * @throws IllegalArgumentException if either {@code semiMajorAxis}
 *         or {@code semiMinorAxis} is negative
 */
public static void ellipse(double x, double y, double semiMajorAxis, double semiMinorAxis) {
    if (!(semiMajorAxis >= 0)) throw new IllegalArgumentException("ellipse semimajor axis must be nonnegative");
    if (!(semiMinorAxis >= 0)) throw new IllegalArgumentException("ellipse semiminor axis must be nonnegative");
    double xs = scaleX(x);
    double ys = scaleY(y);
    double ws = factorX(2*semiMajorAxis);
    double hs = factorY(2*semiMinorAxis);
    if (ws <= 1 && hs <= 1) pixel(x, y);
    else offscreen.draw(new Ellipse2D.Double(xs - ws/2, ys - hs/2, ws, hs));
    draw();
}
项目:spacesettlers    文件:TargetGraphics.java   
@Override
public void draw(Graphics2D graphics) {
    double[] radii = {.8 * radius, .5 * radius, .2 * radius};
    Color color = new Color(1f, 0f, 0f, 1f);
    graphics.setColor(color);
    graphics.setStroke(new BasicStroke((float)(radius/6), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    Ellipse2D.Double circle = null;
    for (double drawRadius : radii) {           
        circle = new Ellipse2D.Double(currentPosition.getX() - drawRadius,
                    currentPosition.getY() - drawRadius, 2 * drawRadius, 2 * drawRadius);
        graphics.draw(circle);
    }
    graphics.fill(circle);
    Line2D.Double line = new Line2D.Double(
            currentPosition.getX() - radius,
            currentPosition.getY(),
            currentPosition.getX() + radius,
            currentPosition.getY());
    graphics.setStroke(JSpaceSettlersComponent.THIN_STROKE);
    graphics.draw(line);
    line = new Line2D.Double(
            currentPosition.getX(),
            currentPosition.getY() - radius,
            currentPosition.getX(),
            currentPosition.getY() + radius);
    graphics.draw(line);
}
项目:spacesettlers    文件:CircleGraphics.java   
/**
 * Drawing code from the old CircleShadow in spacewar1
 */
public void draw(Graphics2D graphics) {
       Ellipse2D.Double shape = new Ellipse2D.Double(drawLocation.getX() - radius,
            drawLocation.getY() - radius, 2 * radius, 2 * radius);

       graphics.setColor(color);
       graphics.fill(shape);
       graphics.setStroke(JSpaceSettlersComponent.THICK_STROKE);
       graphics.draw(shape);

}