public void paint(Graphics g) { Graphics2D g_2d = (Graphics2D) g; Ellipse2D ellipse = new Ellipse2D.Double(0, 2, 80, 80); Rectangle2D rect = new Rectangle2D.Double(40, 2, 80, 80); Area a1 = new Area(ellipse); Area a2 = new Area(rect); a1.intersect(a2); // "Óë" g_2d.fill(a1); ellipse.setFrame(130, 2, 80, 80); rect.setFrame(170, 2, 80, 80); a1 = new Area(ellipse); a2 = new Area(rect); a1.add(a2); // "»ò" g_2d.draw(a1); ellipse.setFrame(0, 90, 80, 80); rect.setFrame(40, 90, 80, 80); a1 = new Area(ellipse); a2 = new Area(rect); a1.subtract(a2); // "²î" g_2d.draw(a1); ellipse.setFrame(130, 90, 80, 80); rect.setFrame(170, 90, 80, 80); a1 = new Area(ellipse); a2 = new Area(rect); a1.exclusiveOr(a2); // "Òì»ò" g_2d.fill(a1); }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; // draw a rectangle double leftX = 100; double topY = 100; double width = 200; double height = 150; Rectangle2D rect = new Rectangle2D.Double(leftX, topY, width, height); g2.draw(rect); // draw a enclosed ellipse Ellipse2D ellipse = new Ellipse2D.Double(); ellipse.setFrame(rect); g2.draw(ellipse); // draw a diagonal line g2.draw(new Line2D.Double(leftX, topY, leftX + width, topY + height)); // draw a circle with the same center double centerX = rect.getCenterX(); double centerY = rect.getCenterY(); double radius = 150; Ellipse2D circle = new Ellipse2D.Double(); circle.setFrameFromCenter(centerX, centerY, centerX + radius, centerY + radius); g2.draw(circle); }
public void setCoordinate(Point currentP) { Ellipse2D tempEllipse = (Ellipse2D) myShape; tempEllipse.setFrame(startP.x, startP.y, currentP.x - startP.x, currentP.y - startP.y); if (anchorList != null) { anchorList.setPosition(myShape.getBounds()); } }
/** * Method paint. Paints the rings on the graph. * * @param g Graphics - the graphics to be painted. */ @Override public void paint(Graphics g) { Collection<Double> depths = getDepths(); g.setColor(Color.gray); Graphics2D g2d = (Graphics2D) g; Point2D center = radialLayout.getCenter(); Ellipse2D ellipse = new Ellipse2D.Double(); for (double d : depths) { ellipse.setFrameFromDiagonal( center.getX() - d, center.getY() - d, center.getX() + d, center.getY() + d); AffineTransform at = AffineTransform.getTranslateInstance(0, 0); Shape shape = at.createTransformedShape(ellipse); // Shape shape = // vv.getRenderContext().getMultiLayerTransformer().transform(ellipse); // // vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).transform(ellipse); MutableTransformer viewTransformer = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW); if (viewTransformer instanceof MutableTransformerDecorator) { shape = vv.getRenderContext().getMultiLayerTransformer().transform(shape); } else { shape = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, shape); } g2d.draw(shape); } }
public void paint(Graphics g) { g.setColor(Color.gray); Graphics2D g2d = (Graphics2D) g; Ellipse2D ellipse = new Ellipse2D.Double(); for (String v : layout.getGraph().getVertices()) { Double radius = layout.getRadii().get(v); if (radius == null) { continue; } Point2D p = layout.transform(v); ellipse.setFrame(-radius, -radius, 2 * radius, 2 * radius); AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY()); Shape shape = at.createTransformedShape(ellipse); MutableTransformer viewTransformer = vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW); if (viewTransformer instanceof MutableTransformerDecorator) { shape = vv.getRenderContext().getMultiLayerTransformer().transform(shape); } else { shape = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, shape); } g2d.draw(shape); } }
/** * Draws the waferedge, including the notch. * * @param g2 the graphics device. * @param plotArea the plot area. */ protected void drawWaferEdge(Graphics2D g2, Rectangle2D plotArea) { // draw the wafer Ellipse2D waferEdge = getWaferEdge(plotArea); g2.setColor(Color.black); g2.draw(waferEdge); // calculate and draw the notch // horizontal orientation is considered notch right // vertical orientation is considered notch down Arc2D notch; Rectangle2D waferFrame = waferEdge.getFrame(); double notchDiameter = waferFrame.getWidth() * 0.04; if (this.orientation == PlotOrientation.HORIZONTAL) { Rectangle2D notchFrame = new Rectangle2D.Double( waferFrame.getX() + waferFrame.getWidth() - (notchDiameter / 2), waferFrame.getY() + (waferFrame.getHeight() / 2) - (notchDiameter / 2), notchDiameter, notchDiameter); notch = new Arc2D.Double(notchFrame, 90d, 180d, Arc2D.OPEN); } else { Rectangle2D notchFrame = new Rectangle2D.Double( waferFrame.getX() + (waferFrame.getWidth() / 2) - (notchDiameter / 2), waferFrame.getY() + waferFrame.getHeight() - (notchDiameter / 2), notchDiameter, notchDiameter); notch = new Arc2D.Double(notchFrame, 0d, 180d, Arc2D.OPEN); } g2.setColor(Color.white); g2.fill(notch); g2.setColor(Color.black); g2.draw(notch); }
/** * Calculates the location of the waferedge. * * @param plotArea the plot area. * @return The wafer edge. */ public 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, minor; 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; }
protected void moveBall() { // System.out.println("I'm in the moveBall() function!"); int width = getWidth(); int height = getHeight(); int min, max, randomX, randomY; min = 0; max = 200; randomX = min + (int) (Math.random() * ((max - min) + 1)); randomY = min + (int) (Math.random() * ((max - min) + 1)); // System.out.println(randomX + ", " + randomY); Rectangle ballBounds = ball.getBounds(); // //System.out.println(ballBounds.x + ", " + ballBounds.y); // if (ballBounds.x + randomX < 0) { // randomX = 200; // } else if (ballBounds.x + ballBounds.width + randomX > width) { // randomX = -200; // } // if (ballBounds.y + randomY < 0) { // randomY = 200; // } else if (ballBounds.y + ballBounds.height + randomY > height) { // randomY = -200; // } ballBounds.x = randomX; ballBounds.y = randomY; _ballXpos = ballBounds.x; _ballYpos = ballBounds.y; ball.setFrame(ballBounds); thePlacebo.repaint(); }
/** * Compares two ellipses and returns <code>true</code> if they are equal or both <code>null</code> * . * * @param e1 the first ellipse (<code>null</code> permitted). * @param e2 the second ellipse (<code>null</code> permitted). * @return A boolean. */ public static boolean equal(final Ellipse2D e1, final Ellipse2D e2) { if (e1 == null) { return (e2 == null); } if (e2 == null) { return false; } if (!e1.getFrame().equals(e2.getFrame())) { return false; } return true; }
/** the paintComponent -- paints the board every repaint() call. */ public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; for (int i = 0; i < B_WIDTH; i++) { for (int j = 0; j < B_HEIGHT; j++) { Rectangle2D rect = new Rectangle2D.Double((i * 40) + 1, (j * 40) + 1, 38, 38); g2.setPaint(balls[i][j].getColor()); g2.fill(rect); Ellipse2D circle = new Ellipse2D.Double(); circle.setFrame(rect); g2.setPaint(balls[i][j].getcColor()); g2.fill(circle); } } }
private void setIndicators() { if (ellipseIndicator == null) ellipseIndicator = new Ellipse2D.Double(); if (arcIndicator == null) arcIndicator = new Arc2D.Double(); ellipseIndicator.setFrame(angle.x, angle.y, angle.width, angle.height); arcIndicator.setArc( angle.x, angle.y, angle.width, angle.height, angle.start, angle.extent, Arc2D.PIE); }
public void setFrame(int pivoX, int pivoY, int height, int width) { this.width = width; this.height = height; this.pivoX = pivoX; this.pivoY = pivoY; circle.setFrame(pivoX, pivoX, height, width); }
@Override protected void renderElement( StyleGroup group, Graphics2D g, Camera camera, GraphicElement element) { GraphicNode node = (GraphicNode) element; shape.setFrame(node.x - w2, node.y - h2, width, height); g.fill(shape); renderText(group, g, camera, element); }
@Override public void paint(Graphics g) { g.setColor(Color.lightGray); Graphics2D g2d = (Graphics2D) g; Point2D center = radialLayout.getCenter(); Ellipse2D ellipse = new Ellipse2D.Double(); for (double d : depths) { ellipse.setFrameFromDiagonal( center.getX() - d, center.getY() - d, center.getX() + d, center.getY() + d); Shape shape = vv.getRenderContext() .getMultiLayerTransformer() .getTransformer(Layer.LAYOUT) .transform(ellipse); g2d.draw(shape); } }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; // Desenarea Dreptunchiului double leftX = 100; double topY = 100; double width = 200; double height = 150; Rectangle2D rect = new Rectangle2D.Double(leftX, topY, width, height); g2.setPaint(Color.RED); g2.fill(rect); // Desenarea Elipsei, Inclusa in Dreptunghi Ellipse2D ellipse = new Ellipse2D.Double(); ellipse.setFrame(rect); // albastru-verde g2.setPaint(new Color(0, 128, 128)); g2.fill(ellipse); }
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; // draw a rectangle double leftX = 100; double topY = 100; double width = 200; double height = 150; Rectangle2D rect = new Rectangle2D.Double(leftX, topY, width, height); g2.setPaint(Color.BLACK); g2.draw(rect); g2.setPaint(Color.RED); g2.fill(rect); // Note that the right and bottom edge are not painted // over // draw the enclosed ellipse Ellipse2D ellipse = new Ellipse2D.Double(); ellipse.setFrame(rect); g2.setPaint(new Color(0, 128, 128)); // a dull blue-green g2.fill(ellipse); }
@Override public int getHeight() { return (int) circle.getHeight(); }
public void setHeight(int height) { this.height = height; circle.setFrame(pivoX, pivoX, this.height, width); }
public void setFrame(int height, int width) { this.width = width; circle.setFrame(pivoX, pivoX, height, width); }
@Override public boolean containsShape(Point p) { if (circle.contains(p)) return true; return false; }
@Override public boolean containsShape(int x, int y) { if (circle.contains(x, y)) return true; return false; }
public void setLocation(int x, int y) { nshape.setFrame(x, y, nshape.getWidth(), nshape.getHeight()); }
public void setBounds(int x, int y, int width, int height) { nshape.setFrame(x, y, width, height); }
public SDEllipse(Point p) { nshape = new Ellipse2D.Double(); nshape.setFrame(p.x, p.y, 0, 0); shape = nshape; setLocation(p); }
public Ellipse2D evaluate(Ellipse2D v0, Ellipse2D v1, float fraction) { double x = v0.getX() + ((v1.getX() - v0.getX()) * fraction); double y = v0.getY() + ((v1.getY() - v0.getY()) * fraction); double w = v0.getWidth() + ((v1.getWidth() - v0.getWidth()) * fraction); double h = v0.getHeight() + ((v1.getHeight() - v0.getHeight()) * fraction); Ellipse2D value = (Ellipse2D) v0.clone(); value.setFrame(x, y, w, h); return value; }
@Override public String getShapeDescription() { return circle.toString(); }
@Override public double getMinY() { return circle.getMinY(); }
@Override public int getWidth() { return (int) circle.getWidth(); }
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color information etc). * @param domainAxis the domain (horizontal) axis. * @param rangeAxis the range (vertical) axis. * @param dataset the dataset (an {@link XYZDataset} is expected). * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot (<code>null</code> permitted). * @param pass the pass index. */ public void drawItem( Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // return straight away if the item is not visible if (!getItemVisible(series, item)) { return; } PlotOrientation orientation = plot.getOrientation(); // get the data point... double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = Double.NaN; if (dataset instanceof XYZDataset) { XYZDataset xyzData = (XYZDataset) dataset; z = xyzData.getZValue(series, item); } if (!Double.isNaN(z)) { RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge(); double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation); double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation); double transDomain = 0.0; double transRange = 0.0; double zero; switch (getScaleType()) { case SCALE_ON_DOMAIN_AXIS: zero = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation); transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero; transRange = transDomain; break; case SCALE_ON_RANGE_AXIS: zero = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation); transRange = zero - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation); transDomain = transRange; break; default: double zero1 = domainAxis.valueToJava2D(0.0, dataArea, domainAxisLocation); double zero2 = rangeAxis.valueToJava2D(0.0, dataArea, rangeAxisLocation); transDomain = domainAxis.valueToJava2D(z, dataArea, domainAxisLocation) - zero1; transRange = zero2 - rangeAxis.valueToJava2D(z, dataArea, rangeAxisLocation); } transDomain = Math.abs(transDomain); transRange = Math.abs(transRange); Ellipse2D circle = null; if (orientation == PlotOrientation.VERTICAL) { circle = new Ellipse2D.Double( transX - transDomain / 2.0, transY - transRange / 2.0, transDomain, transRange); } else if (orientation == PlotOrientation.HORIZONTAL) { circle = new Ellipse2D.Double( transY - transRange / 2.0, transX - transDomain / 2.0, transRange, transDomain); } g2.setPaint(getItemPaint(series, item)); g2.fill(circle); g2.setStroke(getItemOutlineStroke(series, item)); g2.setPaint(getItemOutlinePaint(series, item)); g2.draw(circle); if (isItemLabelVisible(series, item)) { if (orientation == PlotOrientation.VERTICAL) { drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false); } else if (orientation == PlotOrientation.HORIZONTAL) { drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false); } } // add an entity if this info is being collected EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); if (entities != null && circle.intersects(dataArea)) { addEntity( entities, circle, dataset, series, item, circle.getCenterX(), circle.getCenterY()); } } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues( crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation); } }
public void setLocation(Point p) { nshape.setFrame(p.x, p.y, nshape.getWidth(), nshape.getHeight()); }