@Override public void paint(Graphics g) { Area a = new Area(); Shape orejad = new Ellipse2D.Double(450, 100, 300, 300); Shape orejai = new Ellipse2D.Double(950, 100, 300, 300); a.add(new Area(orejai)); a.add(new Area(orejad)); Shape cabeza = new Ellipse2D.Double(600, 200, 500, 500); a.add(new Area(cabeza)); Shape ojoi = new Ellipse2D.Double(675, 300, 100, 100); a.subtract(new Area(ojoi)); Shape ojod = new Ellipse2D.Double(925, 300, 100, 100); a.subtract(new Area(ojod)); Shape clip4 = new Ellipse2D.Double(0, 0, 400, 200); // super.paint(g); Area b = new Area(new Rectangle2D.Double(0, 0, 4000, 4000)); b.subtract(a); g.setClip(b); g.setColor(c); g.fillRect((int) x, (int) y, (int) (Math.random() * 200), (int) (Math.random() * 200)); g.fillRect((int) x + 9, (int) y + 9, (int) (Math.random() * 200), (int) (Math.random() * 200)); g.fillRect( (int) x + 18, (int) y + 18, (int) (Math.random() * 200), (int) (Math.random() * 200)); g.fillRect( (int) x + 27, (int) y + 27, (int) (Math.random() * 200), (int) (Math.random() * 200)); g.setClip(a); g.setColor(new Color(255, 123, 0, 5)); g.fillRect( (int) x + 27, (int) y + 27, (int) (Math.random() * 200), (int) (Math.random() * 200)); x = x + vx; y = y + vy; if (x < 0) { vx = 5.6689f; // setBackground(getColorRandom()); c = getColorRandom(); } if (y < 0) { vy = 0.5f; // setBackground(getColorRandom()); c = getColorRandom(); } if (x > 1900) { vx = -5.6689f; // setBackground(getColorRandom()); c = getColorRandom(); } if (y > 900) { vy = -0.5f; // setBackground(getColorRandom()); c = getColorRandom(); } repaint(); }
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); }
private static final Shape createMask(int width, int height) { Shape outside = new Rectangle2D.Double(0, 0, width, height); Shape inside = new RoundRectangle2D.Double(10, 10, width - 20, height - 20, 50, 50); Area area = new Area(outside); area.subtract(new Area(inside)); return area; }
public void paintBorder(final Graphics g, final int x, final int y, final int w, final int h) { ((Graphics2D) g) .setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(focusColor); rect.setRoundRect(x + 0.6, y + 0.6, w - 1.2, h - 1.2, outsideRadius, outsideRadius); area.reset(); area.add(new Area(rect)); rect.setRoundRect(x + 2, y + 2, w - 4, h - 4, insideRadius, insideRadius); area.subtract(new Area(rect)); ((Graphics2D) g).fill(area); }
public void actionPerformed(ActionEvent ae) { Area area = null; List<Attribute> attrs = new ArrayList<Attribute>(); boolean fill = false; for (Vector v : shapes) { Primitive vv = v; while (vv instanceof Proxy && !(vv instanceof PaintedPrimitive)) { vv = ((Proxy) vv).getProxiedPrimitive(); } if (vv instanceof PaintedPrimitive) { PaintedPrimitive pp = (PaintedPrimitive) vv; List<Attribute> atts = pp.allAttributes(); System.err.println(" include attributes " + atts); attrs.addAll(pp.allAttributes()); } fill |= v instanceof Fillable && ((Fillable) v).isFill(); if (area == null) { area = new Area(v.toShape()); } else { Area other = new Area(v.toShape()); switch (kind) { case UNION: area.add(other); break; case INTERSECTION: area.intersect(other); break; case SUBTRACTION: area.subtract(other); break; case XOR: area.exclusiveOr(other); break; default: throw new AssertionError(); } } } if (area != null) { PathIteratorWrapper wrap = new PathIteratorWrapper( area.getPathIterator(AffineTransform.getTranslateInstance(0, 0)), fill); // XXX probably don't want all attributes, they may be // redundant PaintedPrimitive pp = PaintedPrimitive.create(wrap, attrs); stack.replace(shapes, pp); if (repainter != null) { repainter.requestRepaint(); ; } } }
/** * Draw all primitives in this layer but do not draw modified ones (they are drawn by the edit * layer). Draw nodes last to overlap the ways they belong to. */ @Override public void paint(final Graphics g, final MapView mv) { boolean active = true; boolean inactive = false; boolean virtual = false; // draw the hatched area for non-downloaded region. only draw if we're // the active // and bounds are defined; don't draw for inactive layers or loaded GPX // files etc if (active && Main.pref.getBoolean("draw.data.downloaded_area", true) && !data.dataSources.isEmpty()) { // initialize area with current viewport Rectangle b = Main.map.mapView.getBounds(); // on some platforms viewport bounds seem to be offset from the // left, // over-grow it just to be sure b.grow(100, 100); Area a = new Area(b); // now succesively subtract downloaded areas for (DataSource src : data.dataSources) { if (src.bounds != null && !src.bounds.min.equals(src.bounds.max)) { EastNorth en1 = Main.proj.latlon2eastNorth(src.bounds.min); EastNorth en2 = Main.proj.latlon2eastNorth(src.bounds.max); Point p1 = mv.getPoint(en1); Point p2 = mv.getPoint(en2); Rectangle r = new Rectangle( Math.min(p1.x, p2.x), Math.min(p1.y, p2.y), Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y)); a.subtract(new Area(r)); } } // paint remainder ((Graphics2D) g).setPaint(hatched); ((Graphics2D) g).fill(a); } SimplePaintVisitor painter; if (Main.pref.getBoolean("draw.wireframe")) painter = new SimplePaintVisitor(); else painter = new MapPaintVisitor(); painter.setGraphics(g); painter.setNavigatableComponent(mv); painter.inactive = inactive; painter.visitAll(data, virtual); // Main.map.conflictDialog.paintConflicts(g, mv); }
@Override public Dialog show() { Dialog picker = super.show(); myTimer.start(); // it seems like it's the lowest value for opacity for mouse events to be processed correctly WindowManager.getInstance().setAlphaModeRatio(picker, SystemInfo.isMac ? 0.95f : 0.99f); if (SystemInfo.isJavaVersionAtLeast("1.7")) { Area area = new Area(new Rectangle(0, 0, DIALOG_SIZE, DIALOG_SIZE)); area.subtract(new Area(new Rectangle(SIZE / 2 - 1, SIZE / 2 - 1, 3, 3))); picker.setShape(area); } return picker; }
public final void paintShadow(FGEShapeGraphics g) { double deep = getGraphicalRepresentation().getShadowStyle().getShadowDepth(); int blur = getGraphicalRepresentation().getShadowStyle().getShadowBlur(); double viewWidth = getGraphicalRepresentation().getViewWidth(1.0); double viewHeight = getGraphicalRepresentation().getViewHeight(1.0); AffineTransform shadowTranslation = AffineTransform.getTranslateInstance(deep / viewWidth, deep / viewHeight); int darkness = getGraphicalRepresentation().getShadowStyle().getShadowDarkness(); Graphics2D oldGraphics = g.cloneGraphics(); Area clipArea = new Area( new java.awt.Rectangle( 0, 0, getGraphicalRepresentation().getViewWidth(g.getScale()), getGraphicalRepresentation().getViewHeight(g.getScale()))); Area a = new Area(getGraphicalRepresentation().getShape().getShape()); a.transform( getGraphicalRepresentation().convertNormalizedPointToViewCoordinatesAT(g.getScale())); clipArea.subtract(a); g.getGraphics().clip(clipArea); Color shadowColor = new Color(darkness, darkness, darkness); ForegroundStyle foreground = ForegroundStyle.makeStyle(shadowColor); foreground.setUseTransparency(true); foreground.setTransparencyLevel(0.5f); BackgroundStyle background = BackgroundStyle.makeColoredBackground(shadowColor); background.setUseTransparency(true); background.setTransparencyLevel(0.5f); g.setDefaultForeground(foreground); g.setDefaultBackground(background); for (int i = blur - 1; i >= 0; i--) { float transparency = 0.4f - i * 0.4f / blur; foreground.setTransparencyLevel(transparency); background.setTransparencyLevel(transparency); AffineTransform at = AffineTransform.getScaleInstance( (i + 1 + viewWidth) / viewWidth, (i + 1 + viewHeight) / viewHeight); at.concatenate(shadowTranslation); getShape().transform(at).paint(g); } g.releaseClonedGraphics(oldGraphics); }
private void paintGenome(Graphics2D g) { g.setColor(Color.WHITE); g.fillRect(0, 0, viewRect.width, viewRect.height); g.setColor(new Color(0.9f, 0.9f, 1f)); g.fill( new Ellipse2D.Double( context.getCenterX() - getRadiusInt(), context.getCenterY() - getRadiusInt(), getRadiusInt() * 2, getRadiusInt() * 2)); for (int i = 0; i < this.context.getDictionary().getSequences().size(); ++i) { SAMSequenceRecord rec = this.context.getDictionary().getSequence(i); Arc2D outer = context.getArc(rec, 0, rec.getSequenceLength(), getRadiusExt(), Arc2D.PIE); if (outer.getAngleExtent() == 0) continue; Area area = new Area(outer); Ellipse2D.Double ed = new Ellipse2D.Double( context.getCenter().getX() - getRadiusInt(), context.getCenter().getY() - getRadiusInt(), getRadiusInt() * 2, getRadiusInt() * 2); area.subtract(new Area(ed)); g.setColor(i % 2 == 0 ? Color.LIGHT_GRAY : Color.WHITE); g.fill(area); g.setColor(Color.BLACK); g.draw(area); if ((rec.getSequenceLength() / (double) this.context.getDictionary().getReferenceLength()) < 0.01) continue; String title = rec.getSequenceName(); double midangle = context.convertPositionToRadian(rec, rec.getSequenceLength() / 2); AffineTransform old = g.getTransform(); AffineTransform tr = new AffineTransform(old); g.translate(context.getCenterX(), context.getCenterY()); g.rotate(midangle); g.translate(getRadiusExt(), 0); g.drawString(title, 0, 0); g.setTransform(tr); g.setTransform(old); } }
@Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D graph = (Graphics2D) g.create(); RoundRectangle2D round = new RoundRectangle2D.Float(x, y, width - 1, height - 1, 30, 30); Container parent = c.getParent(); if (parent != null) { graph.setColor(parent.getBackground()); Area canto = new Area(new Rectangle2D.Float(x, y, width, height)); canto.subtract(new Area(round)); graph.fill(canto); } graph.draw(round); graph.dispose(); }
public Shape createStrokedShape(Shape shape) { Area area1 = new Area(stroke1.createStrokedShape(shape)); Area area2 = new Area(stroke2.createStrokedShape(shape)); switch (operation) { case ADD: area1.add(area2); break; case SUBSTRACT: area1.subtract(area2); break; case INTERSECT: area1.intersect(area2); break; case DIFFERENCE: area1.exclusiveOr(area2); break; } return area1; }
@Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int r = 6; RoundRectangle2D round = new RoundRectangle2D.Float(x, y, width - 1, height - 1, r, r); Container parent = c.getParent(); if (parent != null) { g2.setColor(parent.getBackground()); Area corner = new Area(new Rectangle2D.Float(x, y, width, height)); corner.subtract(new Area(round)); g2.fill(corner); } if (isVisible) { g2.setColor(this.color); } g2.draw(round); g2.dispose(); }
public RoundedBorders( Insets aMargin, Insets aPadding, int aRadii, boolean aNoTopBevel, boolean aNoBottomBevel) { radii = aRadii; margin = aMargin; insets = new Insets( margin.top + aPadding.top, margin.left + aPadding.left, margin.bottom + aPadding.bottom, margin.right + aPadding.right); hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED)); noTopBevel = aNoTopBevel; noBottomBevel = aNoBottomBevel; clipFull = new Area(new Rectangle(0, 0, 2 * radii, 2 * radii)); clipFull.subtract(new Area(new Ellipse2D.Float(0, 0, 2 * radii, 2 * radii))); }
@Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Shape window = getWindow(frame); Rectangle2D f = DialPlot.rectangleByRadius(frame, getRadius() + 0.02, getRadius() + 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(getBackgroundPaint()); g2.fill(area); g2.setStroke(getStroke()); g2.setPaint(getInnerForegroundPaint()); g2.draw(window); g2.setPaint(getForegroundPaint()); g2.draw(e); }
@Override public void draw( Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, IDrawingObserver drawingObserver) { if (checkPointsClipped(g2d.getClip())) { return; } Area mainArea = getBody()[0]; Composite oldComposite = g2d.getComposite(); if (alpha < MAX_ALPHA) { g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA)); } g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : getBodyColor()); g2d.fill(mainArea); g2d.setComposite(oldComposite); if (!outlineMode) { int pinSize = (int) PIN_SIZE.convertToPixels() / 2 * 2; for (Point point : controlPoints) { g2d.setColor(PIN_COLOR); g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize); g2d.setColor(PIN_BORDER_COLOR); g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize); } } Color finalBorderColor; if (outlineMode) { Theme theme = (Theme) ConfigurationManager.getInstance() .readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); finalBorderColor = componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme.getOutlineColor(); } else { finalBorderColor = componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR : getBorderColor(); } g2d.setColor(finalBorderColor); g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); if (outlineMode) { Area area = new Area(mainArea); area.subtract(getBody()[1]); g2d.draw(area); } else { g2d.draw(mainArea); if (getBody()[1] != null) { g2d.setColor(getIndentColor()); g2d.fill(getBody()[1]); } } // Draw label. g2d.setFont(LABEL_FONT); Color finalLabelColor; if (outlineMode) { Theme theme = (Theme) ConfigurationManager.getInstance() .readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); finalLabelColor = componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : theme.getOutlineColor(); } else { finalLabelColor = componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED : getLabelColor(); } g2d.setColor(finalLabelColor); FontMetrics fontMetrics = g2d.getFontMetrics(g2d.getFont()); String label = display == Display.NAME ? getName() : getValue(); Rectangle2D rect = fontMetrics.getStringBounds(label, g2d); int textHeight = (int) (rect.getHeight()); int textWidth = (int) (rect.getWidth()); // Center text horizontally and vertically Rectangle bounds = mainArea.getBounds(); int x = bounds.x + (bounds.width - textWidth) / 2; int y = bounds.y + (bounds.height - textHeight) / 2 + fontMetrics.getAscent(); g2d.drawString(label, x, y); }
@Override public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; int pad = 5; Polygon polyLeft = new Polygon( new int[] {pad, getWidth() / 2, getWidth() / 2, pad}, new int[] {pad, pad, getHeight() - pad, getHeight() - pad}, 4); Polygon polyRight = new Polygon( new int[] {getWidth() / 2, getWidth() - pad, getWidth() - pad, getWidth() / 2}, new int[] {pad, pad, getHeight() - pad, getHeight() - pad}, 4); g2d.setColor(Color.red.darker()); if (isSelected()) g2d.setColor(new Color(172, 225, 175)); else g2d.setColor(Color.gray); g2d.fill(polyLeft); if (isSelected()) g2d.setColor(Color.gray); else g2d.setColor(new Color(172, 225, 175)); g2d.fill(polyRight); Area round1 = new Area(new RoundRectangle2D.Double(0, 0, getWidth() - 1, getHeight() - 1, 8, 8)); Area round2 = new Area(new RoundRectangle2D.Double(4, 4, getWidth() - 1 - 8, getHeight() - 1 - 8, 6, 6)); Area round3 = new Area( new RoundRectangle2D.Double(6, 6, getWidth() - 1 - 12, getHeight() - 1 - 12, 5, 5)); Area round4 = new Area( new Ellipse2D.Float( -getWidth() / 2, -getHeight(), getWidth() * 2, getHeight() * 3 / 2)); round4.intersect(round2); round1.exclusiveOr(round2); round2.exclusiveOr(round3); int width = getWidth(); int height = getHeight(); int d1 = 6; int d2 = 8; Area outBorder = new Area( new Polygon( new int[] { d1, width - 1 - d1, width - 1 - d1, width - 1, width - 1, width - 1 - d1, width - 1 - d1, d1, d1, 0, 0, d1 }, new int[] { 0, 0, d1, d1, height - 1 - d1, height - 1 - d1, height - 1, height - 1, height - 1 - d1, height - 1 - d1, d1, d1 }, 12)); outBorder.subtract( new Area( new Polygon( new int[] { d2, width - 1 - d2, width - 1 - d2, width - 1 - (d2 - d1), width - 1 - (d2 - d1), width - 1 - d2, width - 1 - d2, d2, d2, d2 - d1, d2 - d1, d2 }, new int[] { d2 - d1, d2 - d1, d2, d2, height - 1 - d2, height - 1 - d2, height - 1 - (d2 - d1), height - 1 - (d2 - d1), height - 1 - d2, height - 1 - d2, d2, d2 }, 12))); g2d.setColor(new Color(0x993333)); g2d.fill(outBorder); int d3 = 3; int d4 = 5; Area midBorder = new Area(new Rectangle2D.Double(d3, d3, width - 1 - d3 * 2, height - 1 - d3 * 2)); midBorder.subtract( new Area(new Rectangle2D.Double(d4, d4, width - 1 - d4 * 2, height - 1 - d4 * 2))); g2d.fill(midBorder); GlyphVector glyphVectorLeft = new Font("宋体", Font.PLAIN, fontsize) .createGlyphVector(new FontRenderContext(null, true, true), onText); Shape shapeTextLeft = glyphVectorLeft.getOutline( -(float) (glyphVectorLeft.getVisualBounds().getMinX() - d3 - (getWidth() / 2 - glyphVectorLeft.getVisualBounds().getWidth()) / 2 + 1), -(float) (glyphVectorLeft.getVisualBounds().getMinY() - (getHeight() - glyphVectorLeft.getVisualBounds().getHeight()) / 2) - 1); GlyphVector glyphVectorRight = new Font("宋体", Font.PLAIN, fontsize) .createGlyphVector(new FontRenderContext(null, true, true), offText); Shape shapeTextRight = glyphVectorRight.getOutline( -(float) (glyphVectorRight.getVisualBounds().getMinX() + d3 - (getWidth() * 3 / 2 - glyphVectorRight.getVisualBounds().getWidth()) / 2 + 1), -(float) (glyphVectorRight.getVisualBounds().getMinY() - (getHeight() - glyphVectorRight.getVisualBounds().getHeight()) / 2) - 1); g2d.setColor(new Color(23, 54, 93)); g2d.draw(shapeTextLeft); g2d.setColor(new Color(23, 54, 93)); g2d.draw(shapeTextRight); }
/** * Returns the bargraph track image with the given with and height. * * @param WIDTH * @param START_ANGLE * @param ANGLE_EXTEND * @param APEX_ANGLE * @param BARGRAPH_OFFSET * @param image * @return buffered image containing the bargraph track image */ protected BufferedImage create_BARGRAPH_TRACK_Image( final int WIDTH, final double START_ANGLE, final double ANGLE_EXTEND, final double APEX_ANGLE, final double BARGRAPH_OFFSET, BufferedImage image) { if (WIDTH <= 0) { return null; } if (image == null) { image = UTIL.createImage(WIDTH, WIDTH, Transparency.TRANSLUCENT); } final Graphics2D G2 = image.createGraphics(); G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // G2.setRenderingHint(RenderingHints.KEY_RENDERING, // RenderingHints.VALUE_RENDER_QUALITY); // G2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); // G2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, // RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); // G2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, // RenderingHints.VALUE_COLOR_RENDER_QUALITY); // G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, // RenderingHints.VALUE_STROKE_NORMALIZE); final int IMAGE_WIDTH = image.getWidth(); final int IMAGE_HEIGHT = image.getHeight(); // Create led track final java.awt.geom.Arc2D BACK = new java.awt.geom.Arc2D.Double(java.awt.geom.Arc2D.PIE); BACK.setFrame( IMAGE_WIDTH * 0.1074766355, IMAGE_HEIGHT * 0.1074766355, IMAGE_WIDTH * 0.785046729, IMAGE_HEIGHT * 0.785046729); BACK.setAngleStart(START_ANGLE + 2); BACK.setAngleExtent(ANGLE_EXTEND - 5); final Ellipse2D BACK_SUB = new Ellipse2D.Double( IMAGE_WIDTH * 0.1822429907, IMAGE_HEIGHT * 0.1822429907, IMAGE_WIDTH * 0.6355140187, IMAGE_HEIGHT * 0.6355140187); final java.awt.geom.Area LED_TRACK_FRAME = new java.awt.geom.Area(BACK); LED_TRACK_FRAME.subtract(new java.awt.geom.Area(BACK_SUB)); final Point2D LED_TRACK_FRAME_START = new Point2D.Double(0, LED_TRACK_FRAME.getBounds2D().getMinY()); final Point2D LED_TRACK_FRAME_STOP = new Point2D.Double(0, LED_TRACK_FRAME.getBounds2D().getMaxY()); final float[] LED_TRACK_FRAME_FRACTIONS = {0.0f, 0.22f, 0.76f, 1.0f}; final Color[] LED_TRACK_FRAME_COLORS = { new Color(0, 0, 0, 255), new Color(51, 51, 51, 255), new Color(51, 51, 51, 255), new Color(100, 100, 100, 255) }; final LinearGradientPaint LED_TRACK_FRAME_GRADIENT = new LinearGradientPaint( LED_TRACK_FRAME_START, LED_TRACK_FRAME_STOP, LED_TRACK_FRAME_FRACTIONS, LED_TRACK_FRAME_COLORS); G2.setPaint(LED_TRACK_FRAME_GRADIENT); G2.fill(LED_TRACK_FRAME); final java.awt.geom.Arc2D FRONT = new java.awt.geom.Arc2D.Double(java.awt.geom.Arc2D.PIE); FRONT.setFrame( IMAGE_WIDTH * 0.1121495327, IMAGE_HEIGHT * 0.1121495327, IMAGE_WIDTH * 0.7803738318, IMAGE_HEIGHT * 0.7803738318); FRONT.setAngleStart(START_ANGLE); FRONT.setAngleExtent(ANGLE_EXTEND); final Ellipse2D FRONT_SUB = new Ellipse2D.Double( IMAGE_WIDTH * 0.1822429907, IMAGE_HEIGHT * 0.1822429907, IMAGE_WIDTH * 0.6448598131, IMAGE_HEIGHT * 0.6448598131); final java.awt.geom.Area LED_TRACK_MAIN = new java.awt.geom.Area(BACK); LED_TRACK_MAIN.subtract(new java.awt.geom.Area(FRONT_SUB)); final Point2D LED_TRACK_MAIN_START = new Point2D.Double(0, LED_TRACK_MAIN.getBounds2D().getMinY()); final Point2D LED_TRACK_MAIN_STOP = new Point2D.Double(0, LED_TRACK_MAIN.getBounds2D().getMaxY()); final float[] LED_TRACK_MAIN_FRACTIONS = {0.0f, 1.0f}; final Color[] LED_TRACK_MAIN_COLORS = {new Color(17, 17, 17, 255), new Color(51, 51, 51, 255)}; final LinearGradientPaint LED_TRACK_MAIN_GRADIENT = new LinearGradientPaint( LED_TRACK_MAIN_START, LED_TRACK_MAIN_STOP, LED_TRACK_MAIN_FRACTIONS, LED_TRACK_MAIN_COLORS); G2.setPaint(LED_TRACK_MAIN_GRADIENT); G2.fill(LED_TRACK_MAIN); // Draw the inactive leds final Point2D CENTER = new Point2D.Double(WIDTH / 2.0, WIDTH / 2.0); final Rectangle2D LED = new Rectangle2D.Double( WIDTH * 0.1168224299, WIDTH * 0.4859813084, WIDTH * 0.06074766355140187, WIDTH * 0.023364486); final Point2D LED_CENTER = new Point2D.Double(LED.getCenterX(), LED.getCenterY()); final Color[] LED_COLORS = new Color[] {new Color(60, 60, 60, 255), new Color(50, 50, 50, 255)}; final RadialGradientPaint LED_GRADIENT = new RadialGradientPaint( LED_CENTER, (float) (0.030373831775700934 * IMAGE_WIDTH), LED_FRACTIONS, LED_COLORS); G2.setPaint(LED_GRADIENT); final AffineTransform OLD_TRANSFORM = G2.getTransform(); for (double angle = 0; angle <= APEX_ANGLE; angle += 5.0) { G2.rotate(Math.toRadians(angle + BARGRAPH_OFFSET), CENTER.getX(), CENTER.getY()); G2.fill(LED); G2.setTransform(OLD_TRANSFORM); } G2.dispose(); return image; }
protected void cutTheArea(ArrayList<Point2D> sawtooth) { // TODO Auto-generated method stub int x = (int) pointList.get(0).getX() - (int) pointList.get(pointList.size() - 1).getX(); int y = (int) pointList.get(0).getY() - (int) pointList.get(pointList.size() - 1).getY(); int formerX = (int) pointList.get(pointList.size() - 1).getX(); int formerY = (int) pointList.get(pointList.size() - 1).getY(); // 切割添加的第一个点,为水滴离开时的点,延切割方向平移一大段距离 Point2D firstPoint = new Point(formerX - 10 * x, formerY - 10 * y); sawtooth.add(firstPoint); // 假如方向为从左上穿过到右下, 先右移一个很大的值,再上移一个很大的值 int xDirection = 1; int yDirection = 1; if (x < 0) { // 使其与x,y同号 xDirection = -1; } sawtooth.add(new Point((int) firstPoint.getX() - xDirection * 1000, (int) firstPoint.getY())); sawtooth.add( new Point( (int) firstPoint.getX() - xDirection * 1000, (int) firstPoint.getY() - yDirection * 5000)); sawtooth.add( new Point( (int) firstPoint.getX() + xDirection * 2000, (int) firstPoint.getY() - yDirection * 5000)); formerX = (int) pointList.get(0).getX(); formerY = (int) pointList.get(0).getY(); // 切割添加的最后一个点,为水滴离开时的点,延切割反方向平移一大段距离 Point2D lastPoint = new Point(formerX + 10 * x, formerY + 10 * y); sawtooth.add(lastPoint); xList = new int[sawtooth.size()]; yList = new int[sawtooth.size()]; // 为了多边形的声明,将x,y坐标都变成一个int[] for (int i = 0; i < sawtooth.size(); i++) { xList[i] = (int) sawtooth.get(i).getX(); yList[i] = (int) sawtooth.get(i).getY(); } // 开始切割 Polygon cutPolygon = new Polygon(xList, yList, sawtooth.size()); Area cutArea = new Area(cutPolygon); cutArea.intersect(area); // 这里cutArea是切下来的部分,永远靠上 area.subtract(cutArea); // 这里area是剩下的部分,靠下 // 如果被切下来部分的面积大于原面积的0.75,那么把cutArea1变为另一部分 // ,把原area变为该area,假如两个都不大于原来面积的0.75,那么都变为cutArea(即将消失的部分) // 顺便把每一部分的速度改一下,速度是将水滴的速度方向向上旋转30°,和向下旋转30°,生成两个新的速度向量,叠加到原来的速度上。 // 生成两个新向量,式子是通过方程推导出来的,index 0为靠下部分速度,1为靠上部分速度 double[] deltavx = { Math.sqrt(3) * waterDrop_vx * 0.5 - 0.5 * (Math.abs(waterDrop_vx) / waterDrop_vx) * waterDrop_vy, Math.sqrt(3) * waterDrop_vx * 0.5 + 0.5 * (Math.abs(waterDrop_vx) / waterDrop_vx) * waterDrop_vy }; double[] deltavy = { Math.sqrt(3) * waterDrop_vy * 0.5 + 0.5 * (Math.abs(waterDrop_vx)), Math.sqrt(3) * waterDrop_vy * 0.5 - 0.5 * (Math.abs(waterDrop_vx)) }; if ((computeArea(area.getBounds()) < formerArea * 0.3) && (computeArea(cutArea.getBounds())) > formerArea * 0.8) { cutArea1 = area; area = cutArea; vx[0] = vx[0] + deltavx[1]; vy[0] = vy[0] + deltavy[1]; vx[1] = vx[1] + deltavx[0]; vy[1] = vy[1] + deltavy[0]; } else if ((computeArea(cutArea.getBounds()) < formerArea * 0.3) && (computeArea(area.getBounds())) > formerArea * 0.8) { cutArea1 = cutArea; vx[1] = vx[1] + deltavx[1]; vy[1] = vy[1] + deltavy[1]; vx[0] = vx[0] + deltavx[0]; vy[0] = vy[0] + deltavy[0]; } else { cutArea1 = cutArea; cutArea2 = area; area = new Area(); vx[1] = vx[1] + deltavx[1]; vy[1] = vy[1] + deltavy[1]; vx[2] = vx[2] + deltavx[0]; vy[2] = vy[2] + deltavy[0]; } pointList = new ArrayList<Point2D>(); this.sawtooth = new ArrayList<Point2D>(); isPassed = false; sawtoothIndex = 0; }
protected final void compute() { ArrayList<Double> xcoord = new ArrayList<Double>(); ArrayList<Double> ycoord = new ArrayList<Double>(); double[] coords = new double[6]; double[] oldCoords = new double[6]; // Convert input polygons to Area objects Area a1 = getArea(inPoly0.getPoints()); Area a2 = getArea(inPoly1.getPoints()); // test for empty intersection Area testArea = getArea(inPoly0.getPoints()); testArea.intersect(a2); if (testArea.isEmpty()) { poly.setUndefined(); } // if intersection is non-empty perform operation else { switch (operationType) { case TYPE_INTERSECTION: a1.intersect(a2); break; case TYPE_UNION: a1.add(a2); break; case TYPE_DIFFERENCE: a1.subtract(a2); break; } // Iterate through the path of the result // and recover the polygon vertices. PathIterator it = a1.getPathIterator(null); int type = it.currentSegment(coords); it.next(); oldCoords = coords.clone(); double epsilon = 1E-10; while (!it.isDone()) { type = it.currentSegment(coords); if (type == PathIterator.SEG_CLOSE) { break; } // Sometimes the Path iterator gives two almost identical points and // we only want one of them. // TODO: Why does this happen??? if ((double) Math.abs(oldCoords[0] - coords[0]) > epsilon || (double) Math.abs(oldCoords[1] - coords[1]) > epsilon) { xcoord.add(coords[0]); ycoord.add(coords[1]); } oldCoords = coords.clone(); it.next(); } } // Update the points array to the correct size int n = xcoord.size(); // System.out.println("number of points: " + n); int oldPointNumber = points.length; if (n != oldPointNumber) { updatePointsArray(n); poly.setPoints(points); setOutput(); } // Set the points to the new polygon vertices for (int k = 0; k < n; k++) { points[k].setCoords(xcoord.get(k), ycoord.get(k), 1); // System.out.println("vertices: " + xcoord.get(k) + " , " + ycoord.get(k)); } // Compute area of poly (this will also set our poly geo to be defined) poly.calcArea(); // update new points and segments if (n != oldPointNumber) { updateSegmentsAndPointsLabels(oldPointNumber); } }
/** * Builds an Area configured with the polygon information defined in the file. * * @return A fully configured area. */ public Area loadPolygon() { try { Area resultArea; BufferedReader bufferedReader; // Create a new area. resultArea = new Area(); // Open the polygon file. bufferedReader = new BufferedReader(fileReader); // Read the file header. myPolygonName = bufferedReader.readLine(); if (myPolygonName == null || myPolygonName.trim().length() == 0) { throw new OsmosisRuntimeException( "The file must begin with a header naming the polygon file."); } // We now loop until no more sections are available. while (true) { String sectionHeader; boolean positivePolygon; Area sectionArea; // Read until a non-empty line is obtained. do { // Read the section header. sectionHeader = bufferedReader.readLine(); // It is invalid for the file to end without a global "END" record. if (sectionHeader == null) { throw new OsmosisRuntimeException( "File terminated prematurely without a section END record."); } // Remove any whitespace. sectionHeader = sectionHeader.trim(); } while (sectionHeader.length() == 0); // Stop reading when the global END record is reached. if ("END".equals(sectionHeader)) { break; } // If the section header begins with a ! then the polygon is to // be subtracted from the result area. positivePolygon = (sectionHeader.charAt(0) != '!'); // Create an area for this polygon. sectionArea = loadSectionPolygon(bufferedReader); // Add or subtract the section area from the overall area as // appropriate. if (positivePolygon) { resultArea.add(sectionArea); } else { resultArea.subtract(sectionArea); } } return resultArea; } catch (IOException e) { throw new OsmosisRuntimeException("Unable to read from polygon file " + polygonFile + ".", e); } finally { cleanup(); } }
public void paint(Graphics2D g) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setPaint(Color.black); // Rectangle g.drawString("Rectangle", 10, 20); Rectangle rect = new Rectangle(10, 30, 50, 40); g.draw(rect); g.translate(0, 90); // Round Rectangle g.drawString("RoundRectangle", 10, 20); RoundRectangle2D roundRect = new RoundRectangle2D.Double(10, 30, 50, 40, 10, 10); g.draw(roundRect); g.translate(0, 90); // Circle g.drawString("Circle", 10, 20); Ellipse2D circle = new Ellipse2D.Float(10, 30, 50, 50); g.draw(circle); g.translate(0, 90); // CubicCurve2D g.drawString("CubicCurve2D", 10, 20); CubicCurve2D curve = new CubicCurve2D.Float(10, 55, 22.5f, 00, 38.5f, 110, 60, 55); g.draw(curve); g.translate(150, -270); // Polygon g.drawString("Polygon", 10, 20); Polygon polygon = new Polygon(new int[] {30, 50, 10}, new int[] {30, 60, 60}, 3); g.draw(polygon); g.translate(0, 90); // General Path g.drawString("GeneralPath", 10, 20); GeneralPath path = new GeneralPath(); path.moveTo(30, 30); path.quadTo(30, 50, 50, 60); path.quadTo(30, 50, 10, 60); path.quadTo(30, 50, 30, 30); path.closePath(); g.draw(path); g.translate(0, 90); // Area g.drawString("Area", 10, 20); Area area = new Area(new Rectangle(10, 30, 50, 50)); area.subtract(new Area(new Ellipse2D.Double(12, 32, 46, 46))); g.fill(area); g.translate(0, 90); // QuadCurve 2D g.drawString("QuadCurve2D", 10, 20); QuadCurve2D quad = new QuadCurve2D.Float(10, 55, 35, 105, 60, 55); g.draw(quad); g.translate(-75, 70); // Line g.drawString("Line2D", 10, 20); g.draw(new Line2D.Float(10, 30, 60, 30)); }
public Area createSelection() { Area res = new Area(getBorder().getShape()); res.subtract(new Area(timerEvent.getShape())); return res; }