Java Code Examples for java.awt.Graphics2D.rotate()

The following are Jave code examples for showing how to use rotate() of the java.awt.Graphics2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: VASSAL-src   File: OrthoRotateOpBitmapImpl.java   View Source Code Vote up 6 votes
public BufferedImage eval() throws Exception {
  final BufferedImage src = sop.getImage(null);
  if (size == null) fixSize();

  // remain opaque if our parent image is
  final BufferedImage dst = ImageUtils.createCompatibleImage(
      size.width, size.height, src.getTransparency() != BufferedImage.OPAQUE
  );

  final Graphics2D g = dst.createGraphics();
  g.rotate(Math.PI/2.0*angle, src.getWidth()/2.0, src.getHeight()/2.0);
  g.drawImage(src, 0, 0, null);
  g.dispose();

  return dst;
}
 
Example 2
Project: Logisim   File: Icons.java   View Source Code Vote up 6 votes
public static void paintRotated(Graphics g, int x, int y, Direction dir, Icon icon, Component dest) {
	if (!(g instanceof Graphics2D) || dir == Direction.EAST) {
		icon.paintIcon(dest, g, x, y);
		return;
	}

	Graphics2D g2 = (Graphics2D) g.create();
	double cx = x + icon.getIconWidth() / 2.0;
	double cy = y + icon.getIconHeight() / 2.0;
	if (dir == Direction.WEST) {
		g2.rotate(Math.PI, cx, cy);
	} else if (dir == Direction.NORTH) {
		g2.rotate(-Math.PI / 2.0, cx, cy);
	} else if (dir == Direction.SOUTH) {
		g2.rotate(Math.PI / 2.0, cx, cy);
	} else {
		g2.translate(-x, -y);
	}
	icon.paintIcon(dest, g2, x, y);
	g2.dispose();
}
 
Example 3
Project: Logisim   File: Power.java   View Source Code Vote up 6 votes
private void drawInstance(InstancePainter painter, boolean isGhost) {
	Graphics2D g = (Graphics2D) painter.getGraphics().create();
	Location loc = painter.getLocation();
	g.translate(loc.getX(), loc.getY());

	Direction from = painter.getAttributeValue(StdAttr.FACING);
	int degrees = Direction.EAST.toDegrees() - from.toDegrees();
	double radians = Math.toRadians((degrees + 360) % 360);
	g.rotate(radians);

	GraphicsUtil.switchToWidth(g, Wire.WIDTH);
	if (!isGhost && painter.getShowState()) {
		g.setColor(painter.getPort(0).getColor());
	}
	g.drawLine(0, 0, 5, 0);

	GraphicsUtil.switchToWidth(g, 1);
	if (!isGhost && painter.shouldDrawColor()) {
		BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
		g.setColor(Value.repeat(Value.TRUE, width.getWidth()).getColor());
	}
	g.drawPolygon(new int[] { 6, 14, 6 }, new int[] { -8, 0, 8 }, 3);

	g.dispose();
}
 
Example 4
Project: MTG-Card-Recognizer   File: ImageUtil.java   View Source Code Vote up 6 votes
public static BufferedImage rotate(BufferedImage img, double angle)
{
	double sin = Math.abs(Math.sin(Math.toRadians(angle))),
			cos = Math.abs(Math.cos(Math.toRadians(angle)));

	int w = img.getWidth(null), h = img.getHeight(null);

	int neww = (int) Math.floor(w*cos + h*sin),
			newh = (int) Math.floor(h*cos + w*sin);

	BufferedImage bimg = new BufferedImage(neww, newh, BufferedImage.TYPE_3BYTE_BGR);
	Graphics2D g = bimg.createGraphics();

	g.translate((neww-w)/2, (newh-h)/2);
	g.rotate(Math.toRadians(angle), w/2, h/2);
	g.drawRenderedImage(img, null);
	g.dispose();

	return bimg;
}
 
Example 5
Project: ramus   File: TopTablePanel.java   View Source Code Vote up 6 votes
@Override
public void paint(Graphics gr) {
    panel.setSize(getSize().height, getSize().width);
    Graphics2D g = (Graphics2D) gr;
    g.translate(0, getHeight());
    g.rotate(Math.PI + Math.PI / 2);
    panel.paintMe(g);
}
 
Example 6
Project: geomapapp   File: FocalMechanismSolutionDB.java   View Source Code Vote up 6 votes
private void drawFMS(Graphics2D g, double zoom, EarthquakeItem eq) {
	g.scale(1. / zoom, 1. / zoom);
	BufferedImage img = eq.getFMSImage();

	switch (mapType) {
	case MapApp.SOUTH_POLAR_MAP:
		g.rotate( Math.toRadians( eq.eq.lon )) ;
		break;
	case MapApp.NORTH_POLAR_MAP:
		g.rotate( -Math.toRadians( eq.eq.lon )) ;
		break;
	default:
		break;
	}
	g.translate(-img.getWidth() / 2, -img.getHeight() / 2);
	g.drawImage(img, null, null);
}
 
Example 7
Project: litiengine   File: RenderEngine.java   View Source Code Vote up 5 votes
public static void drawRotatedText(final Graphics2D g, final double x, final double y, final int angle, final String text) {
  final Graphics2D g2 = (Graphics2D) g.create();
  g2.rotate(Math.toRadians(angle), x, y);
  RenderEngine.drawText(g2, text, x, y);
  g2.dispose();

}
 
Example 8
Project: javase   File: Sinx.java   View Source Code Vote up 5 votes
@SuppressWarnings("unused")
private void drawTanx(GeneralPath gp, Graphics2D g2d) {
	for (double i = 0.000001; i <= 8 * Math.PI; i += 0.0001 * Math.PI) {
		gp.lineTo(20 * i, 100 * -Math.tan(i));
	}
	g2d.draw(gp);

	// 将当前画笔以原点为中心,旋转180度,画奇函数(关于原点对称)
	g2d.rotate(Math.PI);
	g2d.draw(gp);
}
 
Example 9
Project: javase   File: Sinx.java   View Source Code Vote up 5 votes
private void drawSinx(GeneralPath gp, Graphics2D g2d) {
	for (double i = 0.000001; i <= 8 * Math.PI; i += 0.0001 * Math.PI) {
		gp.lineTo(20 * i, 100 * -Math.sin(i));
	}
	g2d.draw(gp);
	g2d.rotate(Math.PI);
	g2d.draw(gp);
}
 
Example 10
Project: openjdk-jdk10   File: IncorrectUnmanagedImageRotatedClip.java   View Source Code Vote up 5 votes
private static void draw(final BufferedImage from,final Image to) {
    final Graphics2D g2d = (Graphics2D) to.getGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(Color.ORANGE);
    g2d.fillRect(0, 0, to.getWidth(null), to.getHeight(null));
    g2d.rotate(Math.toRadians(45));
    g2d.clip(new Rectangle(41, 42, 43, 44));
    g2d.drawImage(from, 50, 50, Color.blue, null);
    g2d.dispose();
}
 
Example 11
Project: ramus   File: Diagram.java   View Source Code Vote up 5 votes
private void paint(Graphics2D g, Bounds[] filter, double scaleX,
                   double scaleY) {
    int k = 0;
    for (int i = 0; i < components.length; i++)
        if (components[i] != null) {
            if (filter.length <= k)
                return;
            Component component = components[i];
            Bounds bounds = this.bounds[i];
            if (bounds.equals(filter[k])) {
                if (bounds instanceof QBounds) {
                    QBounds qBounds = (QBounds) bounds;
                    k++;
                    Point2D point = qBounds.getLocation();
                    g.translate(point.getX(), point.getY());
                    if (qBounds.getRotation() != 0)
                        g.rotate(qBounds.getRotation());
                    g.scale(scaleX, scaleY);
                    component.paint(g, bounds, this);
                    g.scale(1 / scaleX, 1 / scaleY);
                    if (qBounds.getRotation() != 0)
                        g.rotate(-qBounds.getRotation());
                    g.translate(-point.getX(), -point.getY());
                }
            }
        }
}
 
Example 12
Project: HawkEngine   File: Renderer.java   View Source Code Vote up 5 votes
public static synchronized void RenderEllipseRotated(Graphics g, Vector2 position, Vector2 size, float degrees, float rotation, Color c)
{
	Graphics2D g2d = (Graphics2D)g;
	AffineTransform old = g2d.getTransform();
	g2d.rotate(rotation, position.x + (size.x/2), position.y + (size.y/2));
	g2d.setColor(c);
	g2d.fillArc((int)position.x, (int)position.y, (int)size.x, (int)size.y, 0, (int)degrees);
	g2d.setTransform(old);
}
 
Example 13
Project: geomapapp   File: SurveyLine.java   View Source Code Vote up 4 votes
@Override
public void draw(Graphics2D g) {
	float wrap = (float)map.getWrap();
	
	//get the limits of the displayed map
	Rectangle2D rect = map.getClipRect2D();
	double xmin = rect.getMinX();
	double xmax = rect.getMaxX();
	
	Projection proj = map.getProjection();
	Point2D.Double pt = new Point2D.Double();
	pt.x = getStartLon();
	pt.y = getStartLat();
	Point2D.Double p_start = (Point2D.Double) proj.getMapXY(pt);

	if( wrap>0f ) {
		while( p_start.x <= xmin ){p_start.x+=wrap;}
		while( p_start.x >= xmax ){p_start.x-=wrap;}
	}
	
	pt.x = getEndLon();
	pt.y = getEndLat();
	Point2D.Double p_end = (Point2D.Double) proj.getMapXY(pt);

	if( wrap>0f ) {
		while( p_end.x <= xmin ){p_end.x+=wrap;}
		while( p_end.x > wrap + xmin ){p_end.x-=wrap;}
	}
	
	//draw the shortest line - either p_start.x to p_end.x or the x+wrap values. 
	if ( ((p_start.x - p_end.x) * (p_start.x - p_end.x)) > 
		((p_start.x - (p_end.x + wrap)) * (p_start.x - (p_end.x + wrap))) )  {p_end.x += wrap;}
	if ( ((p_start.x - p_end.x) * (p_start.x - p_end.x)) > 
	(((p_start.x + wrap) - p_end.x) * ((p_start.x + wrap) - p_end.x)) )  {p_start.x += wrap;}
	
	if (lineNum == 1) g.setColor( Color.RED ); 
	else g.setColor( Color.black );
	
	double zoom = map.getZoom();
	g.setStroke( new BasicStroke( 2f/(float)zoom ));

   	double arr_size = 6./zoom;
   	double sq_size = 6./zoom;
       double dx = p_end.x - p_start.x, dy = p_end.y - p_start.y;
       double angle = Math.atan2(dy, dx);
       double len = Math.sqrt(dx*dx + dy*dy);

       AffineTransform at = g.getTransform(); 
       g.translate(p_start.x, p_start.y);
       g.rotate(angle);

       //draw the line
       g.draw(new Line2D.Double(0, 0, len, 0));
       //draw the arrow
       Path2D arrow = new Path2D.Double();
       double xpts[] = {len/3d, len/3d-arr_size, len/3d-arr_size, len/3d};
       double ypts[] = {0, -arr_size, arr_size, 0};
       arrow.moveTo(xpts[0], ypts[0]);
       arrow.lineTo(xpts[1], ypts[1]);
       arrow.lineTo(xpts[2], ypts[2]);
       arrow.closePath();
	if (lineNum == 1) g.setColor( Color.ORANGE ); 
	else g.setColor( Color.ORANGE );
       g.fill(arrow);
	if (lineNum == 1) g.setColor( Color.RED ); 
	else g.setColor( Color.black );
       //draw squares at the end points
       Rectangle2D startSq = new Rectangle2D.Double(0d-sq_size/2d, 0d-sq_size/2d, sq_size, sq_size);
       Rectangle2D endSq = new Rectangle2D.Double(len-sq_size/2d, 0d-sq_size/2d,  sq_size, sq_size);
       g.fill(startSq);
       g.fill(endSq);

       g.setTransform(at);
       
}
 
Example 14
Project: jmt   File: PainterConvex2D.java   View Source Code Vote up 4 votes
/**
 * When is select a Dominat point is draw an arrow from the dominant
 * @param g The graphic object
 * @param dominant The vector with the dominant points
 * @param dominates The vector with the dominates points
 */
public void drawDominantArrow(Graphics2D g, Vector<Point2D> dominant, Vector<Point2D> dominates) {
	DPoint p;
	DPoint p2;
	boolean first = true;

	for (int i = 0; i < dominates.size(); i++) {
		p = (DPoint) dominates.get(i);
		if (p.isSelect()) {
			for (int k = dominant.size() - 1; k >= 0; k--) {
				p2 = (DPoint) dominant.get(k);
				if (p2.isSelect()) {

					g.setColor(Color.MAGENTA);
					//Draw Arrow

					//The angle is calculete throw the rotator point
					DPoint rotator = new DPoint(p2.getX() - p.getX(), p2.getY() - p.getY());
					double angle = rotator.polarAngle();
					//The thestination point in not into the point but near the point
					int xPoint = (int) (p.getX() * scale) + tran_x + (int) (pointSize * Math.cos(angle));
					int yPoint = tran_y - (int) (p.getY() * scale) - (int) (pointSize * Math.sin(angle));

					g.drawLine(xPoint, yPoint, (int) (p2.getX() * scale) + tran_x, tran_y - (int) (p2.getY() * scale));
					//The rotation turn the arrow in the right position
					g.rotate(-angle, xPoint, yPoint);

					g.drawLine(xPoint, yPoint, xPoint + 4 + pointSize, yPoint - pointSize);
					g.drawLine(xPoint, yPoint, xPoint + 4 + pointSize, yPoint + pointSize);

					g.rotate((2 * Math.PI) + angle, xPoint, yPoint);

					//Draw Label on the first arrow (only)
					if (first) {
						first = false;

						g.setColor(new Color(152, 61, 168));
						int fontSize = 7 + pointSize;
						Font f = new Font("Arial", Font.PLAIN, fontSize);
						g.setFont(f);

						double x = (p.getX() + p2.getX()) / 2;
						double y = (p.getY() + p2.getY()) / 2;

						g.drawString("Dominating", (int) (x * scale) + tran_x + 7, tran_y - 3 - (int) (y * scale));
					}
				}
			}
		}
	}
}
 
Example 15
Project: Logisim   File: AbstractGate.java   View Source Code Vote up 4 votes
private void paintBase(InstancePainter painter) {
	GateAttributes attrs = (GateAttributes) painter.getAttributeSet();
	Direction facing = attrs.facing;
	int inputs = attrs.inputs;
	int negated = attrs.negated;

	Object shape = painter.getGateShape();
	Location loc = painter.getLocation();
	Bounds bds = painter.getOffsetBounds();
	int width = bds.getWidth();
	int height = bds.getHeight();
	if (facing == Direction.NORTH || facing == Direction.SOUTH) {
		int t = width;
		width = height;
		height = t;
	}
	if (negated != 0) {
		width -= 10;
	}

	Graphics g = painter.getGraphics();
	Color baseColor = g.getColor();
	if (shape == AppPreferences.SHAPE_SHAPED && paintInputLines) {
		PainterShaped.paintInputLines(painter, this);
	} else if (negated != 0) {
		for (int i = 0; i < inputs; i++) {
			int negatedBit = (negated >> i) & 1;
			if (negatedBit == 1) {
				Location in = getInputOffset(attrs, i);
				Location cen = in.translate(facing, 5);
				painter.drawDongle(loc.getX() + cen.getX(), loc.getY() + cen.getY());
			}
		}
	}

	g.setColor(baseColor);
	g.translate(loc.getX(), loc.getY());
	double rotate = 0.0;
	if (facing != Direction.EAST && g instanceof Graphics2D) {
		rotate = -facing.toRadians();
		Graphics2D g2 = (Graphics2D) g;
		g2.rotate(rotate);
	}

	if (shape == AppPreferences.SHAPE_RECTANGULAR) {
		paintRectangular(painter, width, height);
	} else if (shape == AppPreferences.SHAPE_DIN40700) {
		paintDinShape(painter, width, height, inputs);
	} else { // SHAPE_SHAPED
		if (negateOutput) {
			g.translate(-10, 0);
			paintShape(painter, width - 10, height);
			painter.drawDongle(5, 0);
			g.translate(10, 0);
		} else {
			paintShape(painter, width, height);
		}
	}

	if (rotate != 0.0) {
		((Graphics2D) g).rotate(-rotate);
	}
	g.translate(-loc.getX(), -loc.getY());
	painter.drawLabel();
}
 
Example 16
Project: Logisim   File: TransmissionGate.java   View Source Code Vote up 4 votes
private void drawInstance(InstancePainter painter, boolean isGhost) {
	Bounds bds = painter.getBounds();
	Object powerLoc = painter.getAttributeValue(Wiring.ATTR_GATE);
	Direction facing = painter.getAttributeValue(StdAttr.FACING);
	boolean flip = (facing == Direction.SOUTH || facing == Direction.WEST) == (powerLoc == Wiring.GATE_TOP_LEFT);

	int degrees = Direction.WEST.toDegrees() - facing.toDegrees();
	if (flip)
		degrees += 180;
	double radians = Math.toRadians((degrees + 360) % 360);

	Graphics2D g = (Graphics2D) painter.getGraphics().create();
	g.rotate(radians, bds.getX() + 20, bds.getY() + 20);
	g.translate(bds.getX(), bds.getY());
	GraphicsUtil.switchToWidth(g, Wire.WIDTH);

	Color gate0 = g.getColor();
	Color gate1 = gate0;
	Color input = gate0;
	Color output = gate0;
	Color platform = gate0;
	if (!isGhost && painter.getShowState()) {
		gate0 = painter.getPort(GATE0).getColor();
		gate1 = painter.getPort(GATE0).getColor();
		input = painter.getPort(INPUT).getColor();
		output = painter.getPort(OUTPUT).getColor();
		platform = computeOutput(painter).getColor();
	}

	g.setColor(flip ? input : output);
	g.drawLine(0, 20, 11, 20);
	g.drawLine(11, 13, 11, 27);

	g.setColor(flip ? output : input);
	g.drawLine(29, 20, 40, 20);
	g.drawLine(29, 13, 29, 27);

	g.setColor(gate0);
	g.drawLine(20, 35, 20, 40);
	GraphicsUtil.switchToWidth(g, 1);
	g.drawOval(18, 30, 4, 4);
	g.drawLine(10, 30, 30, 30);
	GraphicsUtil.switchToWidth(g, Wire.WIDTH);

	g.setColor(gate1);
	g.drawLine(20, 9, 20, 0);
	GraphicsUtil.switchToWidth(g, 1);
	g.drawLine(10, 10, 30, 10);

	g.setColor(platform);
	g.drawLine(9, 12, 31, 12);
	g.drawLine(9, 28, 31, 28);
	if (flip) { // arrow
		g.drawLine(18, 17, 21, 20);
		g.drawLine(18, 23, 21, 20);
	} else {
		g.drawLine(22, 17, 19, 20);
		g.drawLine(22, 23, 19, 20);
	}

	g.dispose();
}
 
Example 17
Project: Tarski   File: mxHtmlTextShape.java   View Source Code Vote up 4 votes
/**
 * 
 */
public void paintShape(mxGraphics2DCanvas canvas, String text, mxCellState state,
    Map<String, Object> style) {
  mxLightweightLabel textRenderer = mxLightweightLabel.getSharedInstance();
  CellRendererPane rendererPane = canvas.getRendererPane();
  Rectangle rect = state.getLabelBounds().getRectangle();
  Graphics2D g = canvas.getGraphics();

  if (textRenderer != null && rendererPane != null
      && (g.getClipBounds() == null || g.getClipBounds().intersects(rect))) {
    double scale = canvas.getScale();
    int x = rect.x;
    int y = rect.y;
    int w = rect.width;
    int h = rect.height;

    if (!mxUtils.isTrue(style, mxConstants.STYLE_HORIZONTAL, true)) {
      g.rotate(-Math.PI / 2, x + w / 2, y + h / 2);
      g.translate(w / 2 - h / 2, h / 2 - w / 2);

      int tmp = w;
      w = h;
      h = tmp;
    }

    // Replaces the linefeeds with BR tags
    if (isReplaceHtmlLinefeeds()) {
      text = text.replaceAll("\n", "<br>");
    }

    // Renders the scaled text
    textRenderer
        .setText(createHtmlDocument(style, text, (int) Math.round(w / state.getView().getScale()),
            (int) Math.round(h / state.getView().getScale())));
    textRenderer.setFont(mxUtils.getFont(style, canvas.getScale()));
    g.scale(scale, scale);
    rendererPane.paintComponent(g, textRenderer, rendererPane,
        (int) (x / scale) + mxConstants.LABEL_INSET, (int) (y / scale) + mxConstants.LABEL_INSET,
        (int) (w / scale), (int) (h / scale), true);
  }
}
 
Example 18
Project: openjdk-jdk10   File: CrashNaNTest.java   View Source Code Vote up 4 votes
private static void testDrawComplexAt() {
    final int width = 400;
    final int height = 400;

    final BufferedImage image = new BufferedImage(width, height,
                                        BufferedImage.TYPE_INT_ARGB);

    final Graphics2D g2d = (Graphics2D) image.getGraphics();
    try {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
                             RenderingHints.VALUE_STROKE_PURE);

        g2d.setBackground(Color.WHITE);
        g2d.clearRect(0, 0, width, height);

        final Path2D.Double path = new Path2D.Double();
        path.moveTo(100, 100);

        for (int i = 0; i < 20000; i++) {
            path.lineTo(110 + 0.01 * i, 110);
            path.lineTo(111 + 0.01 * i, 100);
        }

        path.lineTo(NaN, 200);
        path.lineTo(200, 200);
        path.lineTo(200, NaN);
        path.lineTo(300, 300);
        path.lineTo(NaN, NaN);
        path.lineTo(100, 200);
        path.closePath();

        final Path2D.Double path2 = new Path2D.Double();
        path2.moveTo(0, 0);
        path2.lineTo(100, height);
        path2.lineTo(0, 200);
        path2.closePath();

        // Define an non-uniform transform:
        g2d.scale(0.5, 1.0);
        g2d.rotate(Math.PI / 31);

        g2d.setColor(Color.BLACK);
        g2d.draw(path);
        g2d.draw(path2);

        if (SAVE_IMAGE) {
            try {
                final File file = new File("CrashNaNTest-draw.png");
                System.out.println("Writing file: "
                                   + file.getAbsolutePath());
                ImageIO.write(image, "PNG", file);
            } catch (IOException ex) {
                System.out.println("Writing file failure:");
                ex.printStackTrace();
            }
        }

        // Check image on few pixels:
        final Raster raster = image.getData();

        checkPixelNotWhite(raster, 40, 210);
        checkPixelNotWhite(raster, 44, 110);
        checkPixelNotWhite(raster, 60, 120);
        checkPixelNotWhite(raster, 89, 219);
        checkPixelNotWhite(raster, 28, 399);
        checkPixelNotWhite(raster, 134, 329);

    } finally {
        g2d.dispose();
    }
}
 
Example 19
Project: Logisim   File: Transistor.java   View Source Code Vote up 4 votes
private void drawInstance(InstancePainter painter, boolean isGhost) {
	Object type = painter.getAttributeValue(ATTR_TYPE);
	Object powerLoc = painter.getAttributeValue(Wiring.ATTR_GATE);
	Direction from = painter.getAttributeValue(StdAttr.FACING);
	Direction facing = painter.getAttributeValue(StdAttr.FACING);
	boolean flip = (facing == Direction.SOUTH || facing == Direction.WEST) == (powerLoc == Wiring.GATE_TOP_LEFT);

	int degrees = Direction.EAST.toDegrees() - from.toDegrees();
	double radians = Math.toRadians((degrees + 360) % 360);
	int m = flip ? 1 : -1;

	Graphics2D g = (Graphics2D) painter.getGraphics();
	Location loc = painter.getLocation();
	g.translate(loc.getX(), loc.getY());
	g.rotate(radians);

	Color gate;
	Color input;
	Color output;
	Color platform;
	if (!isGhost && painter.getShowState()) {
		gate = painter.getPort(GATE).getColor();
		input = painter.getPort(INPUT).getColor();
		output = painter.getPort(OUTPUT).getColor();
		Value out = computeOutput(painter);
		platform = out.isUnknown() ? Value.UNKNOWN.getColor() : out.getColor();
	} else {
		Color base = g.getColor();
		gate = base;
		input = base;
		output = base;
		platform = base;
	}

	// input and output lines
	GraphicsUtil.switchToWidth(g, Wire.WIDTH);
	g.setColor(output);
	g.drawLine(0, 0, -11, 0);
	g.drawLine(-11, m * 7, -11, 0);

	g.setColor(input);
	g.drawLine(-40, 0, -29, 0);
	g.drawLine(-29, m * 7, -29, 0);

	// gate line
	g.setColor(gate);
	if (type == TYPE_P) {
		g.drawLine(-20, m * 20, -20, m * 15);
		GraphicsUtil.switchToWidth(g, 1);
		g.drawOval(-22, m * 12 - 2, 4, 4);
	} else {
		g.drawLine(-20, m * 20, -20, m * 11);
		GraphicsUtil.switchToWidth(g, 1);
	}

	// draw platforms
	g.drawLine(-10, m * 10, -30, m * 10); // gate platform
	g.setColor(platform);
	g.drawLine(-9, m * 8, -31, m * 8); // input/output platform

	// arrow (same color as platform)
	g.drawLine(-21, m * 6, -18, m * 3);
	g.drawLine(-21, 0, -18, m * 3);

	g.rotate(-radians);
	g.translate(-loc.getX(), -loc.getY());
}
 
Example 20
Project: OpenJSharp   File: CSSBorder.java   View Source Code Vote up 4 votes
public void paintBorder(Component c, Graphics g,
                                    int x, int y, int width, int height) {
    if (!(g instanceof Graphics2D)) {
        return;
    }

    Graphics2D g2 = (Graphics2D) g.create();

    int[] widths = getWidths();

    // Position and size of the border interior.
    int intX = x + widths[LEFT];
    int intY = y + widths[TOP];
    int intWidth = width - (widths[RIGHT] + widths[LEFT]);
    int intHeight = height - (widths[TOP] + widths[BOTTOM]);

    // Coordinates of the interior corners, from NW clockwise.
    int[][] intCorners = {
        { intX, intY },
        { intX + intWidth, intY },
        { intX + intWidth, intY + intHeight },
        { intX, intY + intHeight, },
    };

    // Draw the borders for all sides.
    for (int i = 0; i < 4; i++) {
        Value style = getBorderStyle(i);
        Polygon shape = getBorderShape(i);
        if ((style != Value.NONE) && (shape != null)) {
            int sideLength = (i % 2 == 0 ? intWidth : intHeight);

            // "stretch" the border shape by the interior area dimension
            shape.xpoints[2] += sideLength;
            shape.xpoints[3] += sideLength;
            Color color = getBorderColor(i);
            BorderPainter painter = getBorderPainter(i);

            double angle = i * Math.PI / 2;
            g2.setClip(g.getClip()); // Restore initial clip
            g2.translate(intCorners[i][0], intCorners[i][1]);
            g2.rotate(angle);
            g2.clip(shape);
            painter.paint(shape, g2, color, i);
            g2.rotate(-angle);
            g2.translate(-intCorners[i][0], -intCorners[i][1]);
        }
    }
    g2.dispose();
}