Java Code Examples for java.awt.geom.Ellipse2D

The following are top voted examples for showing how to use java.awt.geom.Ellipse2D. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: jdk8u-jdk   File: ScaleTest.java   View source code 6 votes vote down vote up
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.");
  }
}
 
Example 2
Project: jdk8u-jdk   File: RenderTests.java   View source code 6 votes vote down vote up
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);
}
 
Example 3
Project: cuttlefish   File: Vertex.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Project: jmt   File: QueueDrawer.java   View source code 6 votes vote down vote up
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();
}
 
Example 5
Project: jmt   File: StatiDrawer.java   View source code 6 votes vote down vote up
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);
}
 
Example 6
Project: parabuild-ci   File: DialCap.java   View source code 6 votes vote down vote up
/**
 * 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);
    
}
 
Example 7
Project: parabuild-ci   File: SimpleDialFrame.java   View source code 6 votes vote down vote up
/**
 * 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);
}
 
Example 8
Project: openjdk-jdk10   File: RenderTests.java   View source code 6 votes vote down vote up
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);
}
 
Example 9
Project: spacesettlers   File: EMPGraphics.java   View source code 6 votes vote down vote up
@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));
       
}
 
Example 10
Project: DIA-Umpire-Maven   File: RTAlignedPepIonMapping.java   View source code 6 votes vote down vote up
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);
}
 
Example 11
Project: spacesettlers   File: BeaconGraphics.java   View source code 6 votes vote down vote up
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);

  }
 
Example 12
Project: SE2017-Team1   File: Place.java   View source code 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 13
Project: parabuild-ci   File: AbstractXYItemRenderer.java   View source code 6 votes vote down vote up
/**
 * 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);
}
 
Example 14
Project: SE2017-Team1   File: PetriPlace.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 15
Project: QN-ACTR-Release   File: QueueDrawer.java   View source code 6 votes vote down vote up
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();
}
 
Example 16
Project: QN-ACTR-Release   File: QueueDrawer.java   View source code 6 votes vote down vote up
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);

	}
 
Example 17
Project: QN-ACTR-Release   File: StatiDrawer.java   View source code 6 votes vote down vote up
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);
}
 
Example 18
Project: ramus   File: GEFComponent.java   View source code 6 votes vote down vote up
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);

}
 
Example 19
Project: parabuild-ci   File: CompassPlot.java   View source code 6 votes vote down vote up
/**
 * 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);

}
 
Example 20
Project: cuttlefish   File: IntersectingShapePickSupport.java   View source code 6 votes vote down vote up
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);
}
 
Example 21
Project: jdk8u-jdk   File: RenderTests.java   View source code 6 votes vote down vote up
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);
}
 
Example 22
Project: litiengine   File: LightSource.java   View source code 5 votes vote down vote up
@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;
  }
}
 
Example 23
Project: litiengine   File: LightSource.java   View source code 5 votes vote down vote up
/**
 * 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);
}
 
Example 24
Project: TrabalhoFinalEDA2   File: mxGraphicsCanvas2D.java   View source code 5 votes vote down vote up
/**
 * 
 */
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);
}
 
Example 25
Project: hearthstone   File: Img.java   View source code 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 26
Project: jdk8u-jdk   File: ThinLineTest.java   View source code 5 votes vote down vote up
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.");
  }
}
 
Example 27
Project: parabuild-ci   File: WaferMapPlot.java   View source code 5 votes vote down vote up
/**
 * 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;        
}
 
Example 28
Project: rapidminer   File: RoundTitledBorder.java   View source code 5 votes vote down vote up
@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();
}
 
Example 29
Project: jmt   File: QueueDrawer.java   View source code 5 votes vote down vote up
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);
	}
 
Example 30
Project: TrabalhoFinalEDA2   File: mxCylinderShape.java   View source code 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example 31
Project: jmt   File: QueueDrawer.java   View source code 5 votes vote down vote up
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);
		}
	}
 
Example 32
Project: jmt   File: QueueDrawer.java   View source code 5 votes vote down vote up
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);

	//		}
}
 
Example 33
Project: snake_classic   File: ButtonBack.java   View source code 5 votes vote down vote up
@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);
}
 
Example 34
Project: snake_classic   File: JRadialEllipseButton.java   View source code 5 votes vote down vote up
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();
}
 
Example 35
Project: snake_classic   File: JRadialEllipseButton.java   View source code 5 votes vote down vote up
@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));
	}
}
 
Example 36
Project: Java-Algorithms-Learning   File: StdDraw.java   View source code 5 votes vote down vote up
/**
 * 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();
}
 
Example 37
Project: openjdk-jdk10   File: ThinLineTest.java   View source code 5 votes vote down vote up
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.");
  }
}
 
Example 38
Project: Java-Algorithms-Learning   File: StdDraw.java   View source code 5 votes vote down vote up
/**
 * 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();
}
 
Example 39
Project: spacesettlers   File: TargetGraphics.java   View source code 5 votes vote down vote up
@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);
}
 
Example 40
Project: spacesettlers   File: CircleGraphics.java   View source code 5 votes vote down vote up
/**
 * 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);

}