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 Rectangle2D convertImage2PDFCoord(Rectangle2D r) { if (currentImage == null) return null; int imwid = currentImage.getWidth(null); int imhgt = currentImage.getHeight(null); AffineTransform t; try { t = currentPage.getInitialTransform(imwid, imhgt, prevClip).createInverse(); r.setFrame(r.getX(), r.getY(), 1, 1); Rectangle2D tr = t.createTransformedShape(r).getBounds2D(); tr.setFrame(tr.getX(), tr.getY(), tr.getWidth(), tr.getHeight()); return tr; } catch (NoninvertibleTransformException e) { return null; } }
public void paintComponent(Graphics g) { super.paintComponent(g); int centerX = getWidth() / 2; int centerY = getHeight() / 2; Graphics2D g2d = (Graphics2D) g.create(); g2d.translate(centerX, centerY); // Set Graphics2D transform origin to center of panel g2d.setColor(fgColor); bar.setFrame(-barWidth / 2, -barHeight / 2 + barHeight * barPosition, barWidth, barHeight); g2d.fill(bar); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (Spike spike : spikes) { if (spike != null) { double opacity = 255; if (spike.getDirection() == 0) { opacity = getWidth() * 0.5 - 70 - spike.getPosition().getX(); } else { opacity = spike.getPosition().getX() + getWidth() * 0.5 - 70; } g2d.setColor(new Color(0, 0, 0, (int) clamp(opacity * 10, 0, 255))); g2d.fill(spike); } } g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2d.setColor(Color.BLACK); g2d.draw(barCross); g2d.setStroke(new BasicStroke(2)); g2d.draw(barFrame); g2d.dispose(); }
/** @see prefuse.render.AbstractShapeRenderer#getRawShape(prefuse.visual.VisualItem) */ @Override protected Shape getRawShape(VisualItem item) { double x1 = item.getDouble(VisualItem.X); double y1 = item.getDouble(VisualItem.Y); double x2 = item.getDouble(VisualItem.X2); double y2 = item.getDouble(VisualItem.Y2); boolean isX = item.getBoolean(DocumentGridAxisLayout.IS_X); double midPoint = item.getDouble(DocumentGridAxisLayout.MID_POINT); // horizontal or vertical coords should be manually held constant so that fisheye works // properly if (isX) { // vertical line m_line.setLine(x1, y1, x1, y2); } else { // horizontal line m_line.setLine(x1, y1, x2, y1); } if (!item.canGetString(VisualItem.LABEL)) { return m_line; } String label = item.getString(VisualItem.LABEL); if (label == null) { return m_line; } FontMetrics fm = DEFAULT_GRAPHICS.getFontMetrics(item.getFont()); m_ascent = fm.getAscent(); int h = fm.getHeight(); int w = fm.stringWidth(label); double tx, ty; int labelOffset = 10; if (isX) { // vertical axis // get text x-coord, center at midPoint // tx = x1 + (x2-x1)/2 - w/2; // tx = midPoint + (x1+midPoint)/2 - w/2; // tx = x1 + midPoint/2 - w/2; // simpler approach: just add a fixed distance tx = x1 + labelOffset; // get text y-coord ty = y2 - h; } else { // horiz axis // get text x-coord tx = x1 - w - 2; // get text y-coord, center at midPoint // ty = y1 + (y2-y1)/2 - h/2; // ty = y1 + midPoint/2 - h/2; // simpler approach: just add a fixed distance ty = y1 + labelOffset; } m_box.setFrame(tx, ty, w, h); return m_box; }
public void addTriggerToParking(TaxiwayParkingModel model) { Rectangle2D square = ((java.awt.geom.Ellipse2D.Float) model.getParkingCircle()).getBounds2D(); square.setFrame( square.getX() - (double) (20F * scale), square.getY() - (double) (20F * scale), square.getWidth() + (double) (40F * scale), square.getHeight() + (double) (40F * scale)); TriggerModel triggerModel = new TriggerModel(); triggerModel.setShouldNotify(false); triggerModel.setType73("YES"); triggerModel.setTypeJet("YES"); triggerModel.setShouldNotify(true); java.awt.geom.Point2D.Float point = new java.awt.geom.Point2D.Float( (float) (square.getX() + square.getWidth() / 2D), (float) (square.getY() + square.getHeight() / 2D)); java.awt.geom.Point2D.Float vertexPoints[] = new java.awt.geom.Point2D.Float[4]; vertexPoints[0] = Utilities.rotatePoint( point, new java.awt.geom.Point2D.Float((float) square.getX(), (float) square.getY()), model.getHeading()); vertexPoints[1] = Utilities.rotatePoint( point, new java.awt.geom.Point2D.Float( (float) square.getX(), (float) (square.getY() + square.getHeight())), model.getHeading()); vertexPoints[2] = Utilities.rotatePoint( point, new java.awt.geom.Point2D.Float( (float) (square.getX() + square.getWidth()), (float) (square.getY() + square.getHeight())), model.getHeading()); vertexPoints[3] = Utilities.rotatePoint( point, new java.awt.geom.Point2D.Float( (float) (square.getX() + square.getWidth()), (float) square.getY()), model.getHeading()); for (int i = 0; i < 4; i++) { VertexModel vertexModel = new VertexModel(); vertexModel.setShouldNotify(false); vertexModel.setLatLon( Utilities.getLatLonForPixel( model.getCenterPoint().getLat(), model.getCenterPoint().getLon(), vertexPoints[i].getX(), vertexPoints[i].getY(), scale)); vertexModel.setShouldNotify(true); triggerModel.addVertexModel(vertexModel); } addTriggerModel(triggerModel); }
private static boolean _collision(Shape shp1, Shape shp2) { // Get shape bounds ... Rectangle2D bounds1 = shp1.getBounds2D(); Rectangle2D bounds2 = shp2.getBounds2D(); // ... and extend by eps bounds1.setFrame( bounds1.getX() - mEps, bounds1.getY() - mEps, bounds1.getWidth() + mEps + mEps, bounds1.getHeight() + mEps + mEps); bounds2.setFrame( bounds2.getX() - mEps, bounds2.getY() - mEps, bounds2.getWidth() + mEps + mEps, bounds2.getHeight() + mEps + mEps); return bounds1.intersects(bounds2); }
public Rectangle2D convertPDF2ImageCoord(Rectangle2D r) { if (currentImage == null) return null; int imwid = currentImage.getWidth(null); int imhgt = currentImage.getHeight(null); AffineTransform t = currentPage.getInitialTransform(imwid, imhgt, prevClip); Rectangle2D tr = t.createTransformedShape(r).getBounds2D(); tr.setFrame(tr.getX(), tr.getY(), tr.getWidth(), tr.getHeight()); return tr; }
/** Confirm that cloning works. */ public void testCloning() { EmptyBlock b1 = new EmptyBlock(1.0, 2.0); Rectangle2D bounds1 = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0); b1.setBounds(bounds1); EmptyBlock b2 = null; try { b2 = (EmptyBlock) b1.clone(); } catch (CloneNotSupportedException e) { fail(e.toString()); } assertTrue(b1 != b2); assertTrue(b1.getClass() == b2.getClass()); assertTrue(b1.equals(b2)); bounds1.setFrame(2.0, 4.0, 6.0, 8.0); assertFalse(b1.equals(b2)); b2.setBounds(new Rectangle2D.Double(2.0, 4.0, 6.0, 8.0)); assertTrue(b1.equals(b2)); }
/** Process mouse dragged event. */ public void mouseDragged(MouseEvent event) { if (firstDrag && graph.isDoubleBuffered() && cachedBounds == null) { initOffscreen(); firstDrag = false; } Rectangle2D dirty = null; Graphics g = (offgraphics != null) ? offgraphics : graph.getGraphics(); if (index == -1) return; if (offgraphics != null || !graph.isXorEnabled()) { dirty = graph.toScreen((Rectangle2D) vertex.getBounds().clone()); Rectangle2D t = graph.toScreen(AbstractCellView.getBounds(contextViews)); if (t != null) dirty.add(t); } Rectangle2D newBounds = computeBounds(event); if (graph.isXorEnabled()) { g.setColor(graph.getForeground()); g.setXORMode(graph.getBackground().darker()); overlay(g); } else { firstOverlayInvocation = false; } if (cachedBounds != null) cachedBounds = newBounds; else { // Reset old Bounds CellView[] all = AbstractCellView.getDescendantViews(new CellView[] {vertex}); for (int i = 0; i < all.length; i++) { CellView orig = graph.getGraphLayoutCache().getMapping(all[i].getCell(), false); if (orig != null) { AttributeMap origAttr = (AttributeMap) orig.getAllAttributes().clone(); all[i].changeAttributes(graph.getGraphLayoutCache(), origAttr); all[i].refresh(graph.getGraphLayoutCache(), context, false); } } vertex.setBounds(newBounds); if (vertex != null) graph.getGraphLayoutCache().update(vertex); if (contextViews != null) graph.getGraphLayoutCache().update(contextViews); } if (graph.isXorEnabled()) { overlay(g); } if (offgraphics != null || !graph.isXorEnabled()) { dirty.add(graph.toScreen((Rectangle2D) vertex.getBounds().clone())); Rectangle2D t = graph.toScreen(AbstractCellView.getBounds(contextViews)); if (t != null) dirty.add(t); int border = PortView.SIZE + 10; if (graph.isPortsScaled()) border = (int) (graph.getScale() * border); int border2 = border / 2; dirty.setFrame( dirty.getX() - border2, dirty.getY() - border2, dirty.getWidth() + border, dirty.getHeight() + border); double sx1 = Math.max(0, dirty.getX()); double sy1 = Math.max(0, dirty.getY()); double sx2 = sx1 + dirty.getWidth(); double sy2 = sy1 + dirty.getHeight(); if (offgraphics != null) { graph.drawImage( (int) sx1, (int) sy1, (int) sx2, (int) sy2, (int) sx1, (int) sy1, (int) sx2, (int) sy2); } else { graph.repaint( (int) dirty.getX(), (int) dirty.getY(), (int) dirty.getWidth(), (int) dirty.getHeight()); } } }
// <editor-fold defaultstate="collapsed" desc="Visualization"> @Override protected void paintComponent(Graphics g) { final Graphics2D G2 = (Graphics2D) g.create(); G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); G2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); G2.translate(getInnerBounds().x, getInnerBounds().y); if (lcdBackgroundVisible) { G2.drawImage(lcdImage, 0, 0, null); } // Draw lcd text if (lcdColor == LcdColor.CUSTOM) { G2.setColor(customLcdForeground); } else { G2.setColor(lcdColor.TEXT_COLOR); } G2.setFont(lcdUnitFont); final double UNIT_STRING_WIDTH; if (lcdUnitStringVisible && !lcdUnitString.isEmpty()) { unitLayout = new TextLayout(lcdUnitString, G2.getFont(), RENDER_CONTEXT); UNIT_BOUNDARY.setFrame(unitLayout.getBounds()); if (lcdTextVisible) { G2.drawString( lcdUnitString, (float) ((lcdImage.getWidth() - UNIT_BOUNDARY.getWidth()) - lcdImage.getHeight() * 0.15f), (lcdImage.getHeight() * 0.6f)); } UNIT_STRING_WIDTH = UNIT_BOUNDARY.getWidth(); } else { UNIT_STRING_WIDTH = 0; } // Draw value and oldValue switch (numberSystem) { case DEC: default: G2.setFont(lcdValueFont); valueLayout = new TextLayout(formatLcdValue(lcdValue), G2.getFont(), RENDER_CONTEXT); VALUE_BOUNDARY.setFrame(valueLayout.getBounds()); if (lcdTextVisible) { G2.drawString( formatLcdValue(lcdValue), (float) ((lcdImage.getMinX() + (lcdImage.getWidth() - UNIT_STRING_WIDTH - VALUE_BOUNDARY.getWidth()) - lcdImage.getHeight() * 0.3)), (lcdImage.getHeight() * 0.6f)); } G2.setFont(lcdFormerValueFont); oldValueLayout = new TextLayout(formatLcdValue(oldValue), G2.getFont(), RENDER_CONTEXT); OLD_VALUE_BOUNDARY.setFrame(oldValueLayout.getBounds()); if (lcdTextVisible) { G2.drawString( formatLcdValue(oldValue), (float) ((lcdImage.getWidth() - OLD_VALUE_BOUNDARY.getWidth()) / 2f), (lcdImage.getHeight() * 0.9f)); } break; case HEX: G2.setFont(lcdValueFont); valueLayout = new TextLayout( Integer.toHexString((int) lcdValue).toUpperCase(), G2.getFont(), RENDER_CONTEXT); VALUE_BOUNDARY.setFrame(valueLayout.getBounds()); if (lcdTextVisible) { G2.drawString( Integer.toHexString((int) lcdValue).toUpperCase(), (float) ((lcdImage.getMinX() + (lcdImage.getWidth() - UNIT_STRING_WIDTH - VALUE_BOUNDARY.getWidth()) - lcdImage.getHeight() * 0.3)), (lcdImage.getHeight() * 0.6f)); } G2.setFont(lcdFormerValueFont); oldValueLayout = new TextLayout( Integer.toHexString((int) oldValue).toUpperCase(), G2.getFont(), RENDER_CONTEXT); OLD_VALUE_BOUNDARY.setFrame(oldValueLayout.getBounds()); if (lcdTextVisible) { G2.drawString( Integer.toHexString((int) oldValue).toUpperCase(), (float) ((lcdImage.getWidth() - OLD_VALUE_BOUNDARY.getWidth()) / 2f), (lcdImage.getHeight() * 0.9f)); } break; case OCT: G2.setFont(lcdValueFont); valueLayout = new TextLayout(Integer.toOctalString((int) lcdValue), G2.getFont(), RENDER_CONTEXT); VALUE_BOUNDARY.setFrame(valueLayout.getBounds()); if (lcdTextVisible) { G2.drawString( Integer.toOctalString((int) lcdValue), (float) ((lcdImage.getMinX() + (lcdImage.getWidth() - UNIT_STRING_WIDTH - VALUE_BOUNDARY.getWidth()) - lcdImage.getHeight() * 0.3)), (lcdImage.getHeight() * 0.6f)); } G2.setFont(lcdFormerValueFont); oldValueLayout = new TextLayout(Integer.toOctalString((int) oldValue), G2.getFont(), RENDER_CONTEXT); OLD_VALUE_BOUNDARY.setFrame(oldValueLayout.getBounds()); if (lcdTextVisible) { G2.drawString( Integer.toOctalString((int) oldValue), (float) ((lcdImage.getWidth() - OLD_VALUE_BOUNDARY.getWidth()) / 2f), (lcdImage.getHeight() * 0.9f)); } break; } // Draw lcd info string if (!lcdInfoString.isEmpty()) { G2.setFont(lcdInfoFont); infoLayout = new TextLayout(lcdInfoString, G2.getFont(), RENDER_CONTEXT); INFO_BOUNDARY.setFrame(infoLayout.getBounds()); G2.drawString(lcdInfoString, 5f, (float) INFO_BOUNDARY.getHeight() + 5f); } // Draw lcd threshold indicator if (numberSystem == NumberSystem.DEC && lcdThresholdVisible && lcdValue >= lcdThreshold) { if (!lcdThresholdBehaviourInverted) { if (lcdValue >= lcdThreshold) { G2.drawImage(lcdThresholdImage, 5, getHeight() - lcdThresholdImage.getHeight() - 5, null); } } else { if (lcdValue <= lcdThreshold) { G2.drawImage(lcdThresholdImage, 5, getHeight() - lcdThresholdImage.getHeight() - 5, null); } } } if (glowVisible && glowing) { G2.drawImage(glowImageOn, 0, 0, null); } if (!isEnabled()) { G2.setColor(DISABLED_COLOR); G2.fill(disabledShape); } G2.translate(-getInnerBounds().x, -getInnerBounds().y); G2.dispose(); }
public Rectangle2D getOutLine(Line2D l) { Rectangle2D r = l.getBounds2D(); r.setFrame(r.getX() - 1.0, r.getY() - 1.0, r.getWidth() + 2.0, r.getHeight() + 2.0); return r; }
/** * Getter. * * @param rect When the position is in animation the resulting frame is the destination * bounding-box of the render pass. Otherwise the current bounding box is used. */ public void getPredictBBox(final Rectangle2D rect) { pass.getBoundingBox(rect); final Point2D pred = getPredict(); rect.setFrame( rect.getX() + pred.getX(), rect.getY() + pred.getY(), rect.getWidth(), rect.getHeight()); }
@Override protected void paintControls(Graphics2D g, ShapeCreationPanel scp) { g = (Graphics2D) g.create(); Rectangle2D r = new Rectangle2D.Float(); Ellipse2D e = new Ellipse2D.Float(); Line2D line = new Line2D.Float(); double z = ((double) scp.getHandleSize()) / 2.0; AffineTransform tx = scp.getTransform(); try { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.black); g.setStroke(new BasicStroke(1)); CubicPath[] paths = getCubicPaths(scp); Selection selection = scp.getSelectionModel().getSelection(); Selection indication = scp.getSelectionModel().getIndication(); for (int shapeIndex = 0; shapeIndex < paths.length; shapeIndex++) { if (scp.getHandlesActive().supports(scp, shapeIndex)) { CubicPath path = paths[shapeIndex]; if (path != null && path.isEmpty() == false) { for (int nodeIndex = 0; nodeIndex < path.getNodeCount(); nodeIndex++) { Point2D nodePoint = path.getNode(nodeIndex, null); nodePoint = tx.transform(nodePoint, null); Point2D p = path.getPrevControlForNode(nodeIndex, null); if (p != null) { p = tx.transform(p, null); g.setColor(Color.lightGray); line.setLine(nodePoint, p); g.draw(line); e.setFrame(p.getX() - z, p.getY() - z, 2 * z, 2 * z); if (selection.getShapeIndex() == shapeIndex && selection.getNodeIndex() == nodeIndex && Handle.PREVIOUS_CONTROL.equals(selection.getHandle())) { g.setColor(Color.black); } else if (indication.getShapeIndex() == shapeIndex && indication.getNodeIndex() == nodeIndex && Handle.PREVIOUS_CONTROL.equals(indication.getHandle())) { g.setColor(Color.gray); } else { g.setColor(Color.white); } g.fill(e); g.setColor(Color.black); g.draw(e); } p = path.getNextControlForNode(nodeIndex, null); if (p != null) { p = tx.transform(p, null); g.setColor(Color.lightGray); line.setLine(nodePoint, p); g.draw(line); e.setFrame(p.getX() - z, p.getY() - z, 2 * z, 2 * z); if (selection.getShapeIndex() == shapeIndex && selection.getNodeIndex() == nodeIndex && Handle.NEXT_CONTROL.equals(selection.getHandle())) { g.setColor(Color.black); } else if (indication.getShapeIndex() == shapeIndex && indication.getNodeIndex() == nodeIndex && Handle.NEXT_CONTROL.equals(indication.getHandle())) { } else { g.setColor(Color.white); } g.fill(e); g.setColor(Color.black); g.draw(e); } r.setFrame(nodePoint.getX() - z, nodePoint.getY() - z, 2 * z, 2 * z); if (selection.getShapeIndex() == shapeIndex && selection.getNodeIndex() == nodeIndex && Handle.PRIMARY.equals(selection.getHandle())) { g.setColor(Color.black); } else if (indication.getShapeIndex() == shapeIndex && indication.getNodeIndex() == nodeIndex && Handle.PRIMARY.equals(indication.getHandle())) { g.setColor(Color.gray); } else { g.setColor(Color.white); } g.fill(r); g.setColor(Color.black); g.draw(r); } } } } } finally { g.dispose(); } }