Java Code Examples for java.awt.geom.Area#add()

The following examples show how to use java.awt.geom.Area#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DBLoader.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
public Area fetchArea(long area_list_id, long layer_id) {
	synchronized(db_lock) {

		//connect if disconnected
		if (!connectToDatabase()) {
			return null;
		}

		releaseMemory2();

		Area area = new Area();
		try {
		ResultSet r = connection.createStatement().executeQuery(new StringBuffer("SELECT * from ab_area_paths WHERE area_list_id=").append(area_list_id).append(" AND layer_id=").append(layer_id).toString());
		while (r.next()) {
			PGpolygon pol = (PGpolygon)r.getObject("polygon");
			area.add(new Area(makePolygon(pol)));
		}
		r.close();
		} catch (Exception e) {
			IJError.print(e);
			return null;
		}

		return area;
	}
}
 
Example 2
Source File: FcgVertex.java    From ghidra with Apache License 2.0 6 votes vote down vote up
private void buildFullShape() {

		// Note: this method assumes all bounds have been set
		Area parent = new Area();

		Area v = new Area(vertexShape);
		Area name = new Area(nameLabel.getBounds());
		parent.add(v);
		parent.add(name);

		// for now, the buttons only appear on hover, but if we want to avoid clipping when 
		// painting, we need to account for them in the shape's overall bounds
		Area in = new Area(toggleInsButton.getBounds());
		Area out = new Area(toggleOutsButton.getBounds());
		parent.add(in);
		parent.add(out);

		fullShape = parent;
	}
 
Example 3
Source File: mxCylinderShape.java    From blog-codes with Apache License 2.0 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 4
Source File: SolidBasicStroke.java    From han3_ji7_tsoo1_kian3 with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Shape createStrokedShape(Shape p)
{
	Area area = new Area(p);
	area.add(new Area(basicStroke.createStrokedShape(p)));
	return area;
}
 
Example 5
Source File: WindowUtilities.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a shape that represents the visible portion of the virtual screen bounds
 * returned from {@link #getVirtualScreenBounds()}
 * 
 * @return the visible shape of all screen devices
 */
public static Shape getVisibleScreenBounds() {

	Area area = new Area();
	GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
	GraphicsDevice[] gs = ge.getScreenDevices();
	for (GraphicsDevice gd : gs) {
		GraphicsConfiguration gc = gd.getDefaultConfiguration();
		Rectangle gcBounds = gc.getBounds();
		area.add(new Area(gcBounds));
	}

	return area;
}
 
Example 6
Source File: InfiniteProgressPanel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private Area buildPrimitive() {
    Rectangle2D.Double body = new Rectangle2D.Double( 6, 0, 30, 12 ); // location and size
    Ellipse2D.Double head = new Ellipse2D.Double( 0, 0, 12, 12 );
    Ellipse2D.Double tail = new Ellipse2D.Double( 30, 0, 12, 12 );
    
    Area tick = new Area(body);
    tick.add( new Area( head ) );
    tick.add( new Area( tail ) );
    
    return tick;
}
 
Example 7
Source File: Dissector.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
synchronized public Area getAreaAt(final Layer layer) {
	final Area a = new Area();
	for (final Item item : al_items) {
		for (int i=0; i<item.n_points; i++) {
			if (item.p_layer[i] != layer.getId()) continue;
			a.add(new Area(new Rectangle2D.Float((float)(item.p[0][i] - item.radius), (float)(item.p[1][i] - item.radius), item.radius, item.radius)));
		}
	}
	a.transform(this.at);
	return a;
}
 
Example 8
Source File: ScreenUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static Shape getAllScreensShape() {
  GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
  if (devices.length == 0) {
    return new Rectangle();
  }
  if (devices.length == 1) {
    return getScreenRectangle(devices[0]);
  }
  Area area = new Area();
  for (GraphicsDevice device : devices) {
    area.add(new Area(getScreenRectangle(device)));
  }
  return area;
}
 
Example 9
Source File: Common.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void applyDynamicShape() {
    final Area a = new Area();
    Dimension size = window.getSize();
    for (int x = 0; x < 3; x++) {
        for (int y = 0; y < 3; y++) {
            a.add(new Area(new Rectangle2D.Double(
                    x * size.getWidth() / 17*6, y * size.getHeight() / 17*6,
                    size.getWidth() / 17*5, size.getHeight() / 17*5)));
        }
    }
    window.setShape(a);
}
 
Example 10
Source File: Common.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void applyStaticShape() {
    final Area a = new Area();
    for (int x = 0; x < STATIC_BLOCKS; x++) {
        for (int y = 0; y < STATIC_BLOCKS; y++) {
            a.add(new Area(new Rectangle2D.Float(
                    x*STATIC_STEP, y*STATIC_STEP,
                    STATIC_WIDTH, STATIC_WIDTH)));
        }
    }
    window.setShape(a);
}
 
Example 11
Source File: Tree.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** In world coordinates. Returns an empty area when there aren't any nodes in @param layer. */
@Override
public Area getAreaAt(final Layer layer) {
	synchronized (node_layer_map) {
		final Area a = new Area();
		final Set<Node<T>> nodes = node_layer_map.get(layer);
		if (null == nodes) return a; // empty
		for (final Node<T> nd : nodes) a.add(nd.getArea()); // all local
		a.transform(this.at);
		return a;
	}
}
 
Example 12
Source File: Layer.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** Returns an Area in world coordinates that represents the inside of all Patches. */
public Area getPatchArea(final boolean visible_only) {
	final Area area = new Area(); // with width,height zero
	for (final Patch p: getAll(Patch.class)) {
		if (visible_only && p.isVisible()) {
			area.add(p.getArea());
		}
	}
	return area;
}
 
Example 13
Source File: Compass.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
private BufferedImage create_SMALL_ROSE_POINTER_Image(final int WIDTH) {
    final BufferedImage IMAGE = UTIL.createImage((int) (WIDTH * 0.0546875f), (int) (WIDTH * 0.2f), java.awt.Transparency.TRANSLUCENT);
    final Graphics2D G2 = IMAGE.createGraphics();


    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    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();

    G2.setStroke(new BasicStroke(0.75f));

    // Define arrow shape of pointer
    final GeneralPath POINTER_WHITE_LEFT = new GeneralPath();
    final GeneralPath POINTER_WHITE_RIGHT = new GeneralPath();

    POINTER_WHITE_LEFT.moveTo(IMAGE_WIDTH - IMAGE_WIDTH * 0.75f, IMAGE_HEIGHT);
    POINTER_WHITE_LEFT.lineTo(IMAGE_WIDTH / 2.0f, IMAGE_HEIGHT / 2.0f);
    POINTER_WHITE_LEFT.lineTo(IMAGE_WIDTH / 2.0f, IMAGE_HEIGHT);
    POINTER_WHITE_LEFT.closePath();

    POINTER_WHITE_RIGHT.moveTo(IMAGE_WIDTH * 0.75f, IMAGE_HEIGHT);
    POINTER_WHITE_RIGHT.lineTo(IMAGE_WIDTH / 2.0f, IMAGE_HEIGHT / 2.0f);
    POINTER_WHITE_RIGHT.lineTo(IMAGE_WIDTH / 2.0f, IMAGE_HEIGHT);
    POINTER_WHITE_RIGHT.closePath();

    final Area POINTER_FRAME_WHITE = new Area(POINTER_WHITE_LEFT);
    POINTER_FRAME_WHITE.add(new Area(POINTER_WHITE_RIGHT));

    final Color STROKE_COLOR = getBackgroundColor().SYMBOL_COLOR.darker();
    final Color FILL_COLOR = getBackgroundColor().SYMBOL_COLOR;

    G2.setColor(FILL_COLOR);
    G2.fill(POINTER_FRAME_WHITE);
    G2.setColor(STROKE_COLOR);
    G2.draw(POINTER_FRAME_WHITE);

    G2.dispose();

    return IMAGE;
}
 
Example 14
Source File: StackedLayout.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
private void layout( NodeItem node, double x, double y )
{
    Dimension minSize = getItemMinSize( node, null );
    node.setBounds( x, y, minSize.width, minSize.height );

    int depth = node.getDepth();

    if( depth > zoom )
    {
        node.setBounds( x, y, 0, 0 );
        node.setVisible( false );
    }
    else
    {
        node.setVisible( true );
    }

    double cx = x + INSET;
    double cy = y + minSize.height;

    Area area = new Area( node.getBounds() );

    boolean hasChild = false;
    for( int i = 0; i < node.getChildCount(); i++ )
    {
        hasChild = true;
        NodeItem child = (NodeItem) node.getChild( i );

        layout( child, cx, cy );
        area.add( new Area( child.getBounds() ) );

        // shifting location calculation
        Rectangle2D nodeRect = child.getBounds();
        if( depth == 0 )
        {
            // layer
            cy = cy + ( INSET * 2 ) + nodeRect.getHeight();
        }
        if( depth == 1 )
        {
            // module
            cx = cx + INSET + nodeRect.getWidth();
        }
        else if( depth == 2 )
        {
            // type container
            cx = cx + INSET + nodeRect.getWidth();
        }
        else if( depth == 3 )
        {
            // type
            cy = cy + INSET + nodeRect.getHeight();
        }
    }

    Rectangle2D bounds = area.getBounds2D();
    if( hasChild && depth <= zoom )
    {
        bounds.setRect( x, y, bounds.getWidth() + INSET, bounds.getHeight() + INSET );
    }

    node.setBounds( x, y, bounds.getWidth(), bounds.getHeight() );

    // relayout the child so it have consistent width or height
    //int depth = parent.getDepth();
    if( depth == 0 )
    {
        arrangeChildVertically( node );
    }
    else if( depth == 1 )
    {
        arrangeChildHorizontally( node );
    }
    else if( depth == 2 )
    {
        arrangeChildHorizontally( node );
    }
    else if( depth == 3 )
    {
        arrangeChildVertically( node );
    }
}
 
Example 15
Source File: LocalAreaUtil.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
	 * Checks if a path collides with an existing building, construction site, or
	 * vehicle at a location.
	 * 
	 * @param object      the object being checked (may be null if no object).
	 * @param path        the path to check.
	 * @param coordinates the global coordinate location to check.
	 * @param useCache    true if caching should be used.
	 * @return true if path doesn't collide with anything.
	 */
	private static boolean isPathCollisionFree(Object object, Path2D path, Coordinates coordinates, boolean useCache) {

		boolean result = true;

		// Check if obstacle area has been cached for this coordinate location if using
		// cache.
		boolean cached = false;
		Area obstacleArea = null;
		if (useCache && obstacleAreaCache.containsKey(coordinates)) {
			if (marsClock == null)
				marsClock = Simulation.instance().getMasterClock().getMarsClock();
			String currentTimestamp = marsClock.getDateTimeStamp();
			String cachedTimestamp = obstacleAreaTimestamps.get(coordinates);
			if (currentTimestamp.equals(cachedTimestamp)) {
				cached = true;
				obstacleArea = obstacleAreaCache.get(coordinates);
			}
		}

		if (!cached) {
			// Add all obstacle areas at location together to create a total obstacle area.
			Iterator<LocalBoundedObject> i = getAllLocalBoundedObjectsAtLocation(coordinates).iterator();
			while (i.hasNext()) {
				LocalBoundedObject lbo = i.next();
				if (lbo != object) {
					Rectangle2D objectRect = new Rectangle2D.Double(lbo.getXLocation() - (lbo.getWidth() / 2D),
							lbo.getYLocation() - (lbo.getLength() / 2D), lbo.getWidth(), lbo.getLength());
					Path2D objectPath = getPathFromRectangleRotation(objectRect, lbo.getFacing());
					Area objectArea = new Area(objectPath);
					if (obstacleArea == null) {
						obstacleArea = objectArea;
					} else {
						obstacleArea.add(objectArea);
					}
				}
			}
		}

		if (obstacleArea != null) {
			// Check for intersection of obstacle and path bounding rectangles first
			// (faster).
			Rectangle2D pathBounds = path.getBounds2D();
			Rectangle2D obstacleBounds = obstacleArea.getBounds2D();
			if (pathBounds.intersects(obstacleBounds)) {
				// If rectangles intersect, check for collision of path and obstacle areas
				// (slower).
				Area pathArea = new Area(path);
				result = !doAreasCollide(pathArea, obstacleArea);
			}
		}

		// Store cached obstacle area for location with current timestamp if needed.
		if (useCache && !cached && (obstacleArea != null)) {
			obstacleAreaCache.put(coordinates, obstacleArea);
//			String currentTimestamp = marsClock.getDateTimeStamp();
			obstacleAreaTimestamps.put(coordinates, marsClock.getDateTimeStamp());
		}

		return result;
	}
 
Example 16
Source File: ArrowFootprint.java    From tracker with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets the shape of this footprint.
 *
 * @param points an array of Points
 * @return the shape
 */
public synchronized Shape getShape(Point[] points) {
  Point p1 = points[0];
  Point p2 = points[1];
  if (points.length>3) {
  	p1 = points[3]; // (possibly stretched) visible tip
  }
  double theta = Math.atan2(p1.y - p2.y, p1.x - p2.x);
  
  transform.setToRotation(theta, p1.x, p1.y);
  transform.translate(p1.x, p1.y);
  int scale = FontSizer.getIntegerFactor();
  if (scale>1) {
  	transform.scale(scale, scale);
  }
  highlight = transform.createTransformedShape(HIGHLIGHT);
  
  transform.setToRotation(theta, p2.x, p2.y);
  transform.translate(p2.x, p2.y);
  float d = (float)(p1.distance(p2)); // length of the arrow
  // set arrowhead dimensions and stroke
  int tiplen = tipLength*scale;
  int tipL = Math.min(tiplen, Math.round(d-4));
  tipL = Math.max(8, tipL);
  int tipW = Math.max(tipL/4, 2);
  float f = scale*baseStroke.getLineWidth();
  float lineWidth = f < tipL/4? f: Math.max(tipL/4, 0.8f);
	if (stroke==null || stroke.getLineWidth()!=lineWidth) {
		stroke = new BasicStroke(lineWidth,
        BasicStroke.CAP_BUTT,
        BasicStroke.JOIN_MITER,
        8,
        baseStroke.getDashArray(),
        baseStroke.getDashPhase());
    headStroke = new BasicStroke(lineWidth,
        BasicStroke.CAP_BUTT,
        BasicStroke.JOIN_MITER,
        8,
        null,
        stroke.getDashPhase());
	}
  try {
	// set up tip hitShape using full length
	path.reset();
	path.moveTo(d-4, 0);
	path.lineTo(d-6, -2);
	path.lineTo(d, 0);
	path.lineTo(d-6, 2);
	path.closePath();
	hitShapes[0] = transform.createTransformedShape(path); // for tip
	// shorten d to account for the width of the stroke
	// see Java 2D API Graphics, by VJ Hardy (Sun, 2000) page 147
	d = d - (float)(stroke.getLineWidth()*1.58) + 1;
	// set up shaft hitShape
	path.reset();
	path.moveTo(0, 0);
	path.lineTo(d-tipL, 0);
	hitShapes[2] = transform.createTransformedShape(path); // for shaft
	hitShapes[1] = new Rectangle(p2.x-1, p2.y-1, 2, 2);    // for tail
	// set up draw shape
	path.reset();
	path.moveTo(0, 0);
	path.lineTo(d-tipL+tipW, 0);
	Shape shaft = transform.createTransformedShape(path);
	shaft = stroke.createStrokedShape(shaft);
	Area area = new Area(shaft);
	path.reset();
	path.moveTo(d-tipL+tipW, 0);
	path.lineTo(d-tipL, -tipW);
	path.lineTo(d, 0);
	path.lineTo(d-tipL, tipW);
	path.closePath();
	Shape head = transform.createTransformedShape(path);
	if (openHead) {
		head = headStroke.createStrokedShape(head);
	}
	area.add(new Area(head));
	if (!openHead) {
		area.add(new Area(headStroke.createStrokedShape(head)));
	}
	return area;
} catch (Exception e) { // occasionally throws path exception for reasons unknown!
   d = (float)(p1.distance(p2));
	java.awt.geom.Line2D line = new java.awt.geom.Line2D.Double(0, 0, d, 0); 
	return stroke.createStrokedShape(transform.createTransformedShape(line));
}
}
 
Example 17
Source File: Compass.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
private BufferedImage create_BIG_ROSE_POINTER_Image(final int WIDTH) {
    final BufferedImage IMAGE = UTIL.createImage((int) (WIDTH * 0.0546875f), (int) (WIDTH * 0.2f), java.awt.Transparency.TRANSLUCENT);
    final Graphics2D G2 = IMAGE.createGraphics();

    G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    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();

    G2.setStroke(new BasicStroke(0.75f));

    // Define arrow shape of pointer
    final GeneralPath POINTER_WHITE_LEFT = new GeneralPath();
    final GeneralPath POINTER_WHITE_RIGHT = new GeneralPath();

    POINTER_WHITE_LEFT.moveTo(IMAGE_WIDTH - IMAGE_WIDTH * 0.95f, IMAGE_HEIGHT);
    POINTER_WHITE_LEFT.lineTo(IMAGE_WIDTH / 2.0f, 0);
    POINTER_WHITE_LEFT.lineTo(IMAGE_WIDTH / 2.0f, IMAGE_HEIGHT);
    POINTER_WHITE_LEFT.closePath();

    POINTER_WHITE_RIGHT.moveTo(IMAGE_WIDTH * 0.95f, IMAGE_HEIGHT);
    POINTER_WHITE_RIGHT.lineTo(IMAGE_WIDTH / 2.0f, 0);
    POINTER_WHITE_RIGHT.lineTo(IMAGE_WIDTH / 2.0f, IMAGE_HEIGHT);
    POINTER_WHITE_RIGHT.closePath();

    final Area POINTER_FRAME_WHITE = new Area(POINTER_WHITE_LEFT);
    POINTER_FRAME_WHITE.add(new Area(POINTER_WHITE_RIGHT));

    final Color STROKE_COLOR = getBackgroundColor().SYMBOL_COLOR.darker();
    final Color FILL_COLOR = getBackgroundColor().SYMBOL_COLOR;

    G2.setColor(STROKE_COLOR);
    G2.fill(POINTER_WHITE_RIGHT);
    G2.setColor(FILL_COLOR);
    G2.fill(POINTER_WHITE_LEFT);
    G2.setColor(STROKE_COLOR);
    G2.draw(POINTER_FRAME_WHITE);

    G2.dispose();

    return IMAGE;
}
 
Example 18
Source File: RegionOps.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public RectListImpl getUnion(RectListImpl rli) {
    Area a2 = new Area(theArea);
    a2.add(((AreaImpl) rli).theArea);
    return new AreaImpl(a2);
}
 
Example 19
Source File: GlassPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void paintSpotlight(final Graphics g, final JComponent surfaceComponent) {
  Dimension size = surfaceComponent.getSize();
  if (myLightComponents.size() > 0) {
    int width = size.width - 1;
    int height = size.height - 1;

    Rectangle2D screen = new Rectangle2D.Double(0, 0, width, height);
    final Rectangle visibleRect = myPanel.getVisibleRect();
    final Point leftPoint = SwingUtilities.convertPoint(myPanel, new Point(visibleRect.x, visibleRect.y), surfaceComponent);
    Area innerPanel = new Area(new Rectangle2D.Double(leftPoint.x, leftPoint.y, visibleRect.width, visibleRect.height));
    Area mask = new Area(screen);

    for (JComponent lightComponent : myLightComponents) {
      final Area area = getComponentArea(surfaceComponent, lightComponent);
      if (area == null) continue;

      if (lightComponent instanceof JLabel) {
        final JLabel label = (JLabel)lightComponent;
        final Component labelFor = label.getLabelFor();
        if (labelFor instanceof JComponent) {
          final Area labelForArea = getComponentArea(surfaceComponent, (JComponent)labelFor);
          if (labelForArea != null) {
            area.add(labelForArea);
          }
        }
      }

      area.intersect(innerPanel);
      mask.subtract(area);
    }

    Graphics2D g2 = (Graphics2D)g;

    Color shieldColor = new Color(0.0f, 0.0f, 0.0f, 0.15f);
    Color boundsColor = Color.gray;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(shieldColor);
    g2.fill(mask);

    g2.setColor(boundsColor);
    g2.draw(mask);
  }
}
 
Example 20
Source File: DoubleCrosshairFootprint.java    From tracker with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets the shape of this footprint.
 *
 * @param points an array of Points
 * @return the shape
 */
public Shape getShape(Point[] points) {
  Point p1 = points[0];
  Point p2 = points[1];
  
  // set up end shapes
  transform.setToTranslation(p1.x, p1.y);
  int scale = FontSizer.getIntegerFactor();
  if (scale>1) {
  	transform.scale(scale, scale);
  }
  Shape target1 = transform.createTransformedShape(targetShape);
  hitShapes[0] = transform.createTransformedShape(hitShape); // end1
  transform.setToTranslation(p2.x, p2.y);
  if (scale>1) {
  	transform.scale(scale, scale);
  }
  Shape target2 = transform.createTransformedShape(targetShape);
  hitShapes[1] = transform.createTransformedShape(hitShape); // end2
  
  // set up line shapes
  float d = (float)p1.distance(p2); // distance between ends
  float center = d/2; // center point
  float l = Math.max(d - scale*2*(size+3), size); // line length
  float f = 0.45f; // hit shape is 90% of line length
  path.reset();
  path.moveTo(center - f*l, 0);
  path.lineTo(center + f*l, 0);
  double theta = Math.atan2(p1.y - p2.y, p1.x - p2.x);
  if (Double.isNaN(theta)) {
  	theta = 0;
  }
  transform.setToRotation(theta, p2.x, p2.y);
  transform.translate(p2.x, p2.y);
  hitShapes[2] = transform.createTransformedShape(path); // line    
  path.reset();
  path.moveTo(center - l/2, 0);
  path.lineTo(center + l/2, 0);
  Shape line = transform.createTransformedShape(path);
  
  // set up drawing area
	if (stroke==null || stroke.getLineWidth()!=scale*baseStroke.getLineWidth()) {
		stroke = new BasicStroke(scale*baseStroke.getLineWidth());
	}
  Area area = new Area(stroke.createStrokedShape(target1));
  area.add(new Area(stroke.createStrokedShape(target2)));
  area.add(new Area(stroke.createStrokedShape(line)));
  return area;
}