Java Code Examples for java.awt.Graphics.drawPolyline()

The following are Jave code examples for showing how to use drawPolyline() of the java.awt.Graphics 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: jmt   File: DefaultIconsToolkit.java   View Source Code Vote up 7 votes
@Override
public Image getStationIcon(String type, Rectangle bounds) {
	int qLength = 60, height = 40, width = 100;
	BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics g = bi.getGraphics();
	for (int i = 0, monoChannel = 0; i < 10; i++, monoChannel = (int) ((1 - Math.exp(-i)) * 50)) {
		g.setColor(new Color(230 - monoChannel, 230 - monoChannel, 230 - monoChannel));
		g.drawPolyline(new int[] { i, i, qLength - i }, new int[] { height - i, i, i }, 3);
		g.fillArc(width - height + i, i, height - 2 * i, height - 2 * i, 45, 180);
		g.setColor(new Color(130 + monoChannel, 130 + monoChannel, 130 + monoChannel));
		g.drawPolyline(new int[] { i, qLength - i, qLength - i }, new int[] { height - i, height - i, i }, 3);
		g.fillArc(width - height + i, i, height - 2 * i, height - 2 * i, 225, 180);
	}
	g.fillRect(5, 5, qLength - 9, height - 9);
	g.fillOval(width - height + 5, 5, height - 10, height - 10);
	return bi.getScaledInstance(bounds.width, bounds.height, Image.SCALE_SMOOTH);
}
 
Example 2
Project: JDigitalSimulator   File: FlipFlop.java   View Source Code Vote up 6 votes
@Override public void paint(Graphics graphics) {
	graphics.setColor(Color.BLACK);
	graphics.drawRect(10, 0, size.width-20, size.height);
	Class<? extends FlipFlop> cls = this.getClass();
	if(cls.isAnnotationPresent(Clocked.class)) {
		if(tiggerType!=TiggerType.PULSE_TIGGERED) {
			graphics.drawLine(10, size.height/2-5, 20, size.height/2);
			graphics.drawLine(10, size.height/2+5, 20, size.height/2);
			if(tiggerType==TiggerType.NEGATIVE_EDGE_TIGGERED)
				graphics.drawOval(2, size.height/2-4, 8, 8);
		}
	}
	if(cls.isAnnotationPresent(MasterSlave.class)&&isMasterSlave) {
		Polygon polygon = new Polygon(new int[]{0, 8, 8},
				new int[]{0, 0, 8}, 3);
		polygon.translate(size.width-22, 5);
		graphics.drawPolyline(polygon.xpoints, polygon.ypoints, polygon.npoints);
		polygon.translate(0, size.height-17);
		graphics.drawPolyline(polygon.xpoints, polygon.ypoints, polygon.npoints);
	}
}
 
Example 3
Project: Logisim   File: ControlledBuffer.java   View Source Code Vote up 6 votes
@Override
public void paintIcon(InstancePainter painter) {
	Graphics g = painter.getGraphics();
	Icon icon = isInverter ? ICON_INVERTER : ICON_BUFFER;
	if (icon != null) {
		icon.paintIcon(painter.getDestination(), g, 2, 2);
	} else {
		int x = isInverter ? 0 : 2;
		g.setColor(Color.BLACK);
		int[] xp = new int[] { x + 15, x + 1, x + 1, x + 15 };
		int[] yp = new int[] { 10, 3, 17, 10 };
		g.drawPolyline(xp, yp, 4);
		if (isInverter)
			g.drawOval(x + 13, 8, 4, 4);
		g.setColor(Value.FALSE_COLOR);
		g.drawLine(x + 8, 14, x + 8, 18);
	}
}
 
Example 4
Project: QN-ACTR-Release   File: DefaultIconsToolkit.java   View Source Code Vote up 6 votes
@Override
public Image getStationIcon(String type, Rectangle bounds) {
	int qLength = 60, height = 40, width = 100;
	BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics g = bi.getGraphics();
	for (int i = 0, monoChannel = 0; i < 10; i++, monoChannel = (int) ((1 - Math.exp(-i)) * 50)) {
		g.setColor(new Color(230 - monoChannel, 230 - monoChannel, 230 - monoChannel));
		g.drawPolyline(new int[] { i, i, qLength - i }, new int[] { height - i, i, i }, 3);
		g.fillArc(width - height + i, i, height - 2 * i, height - 2 * i, 45, 180);
		g.setColor(new Color(130 + monoChannel, 130 + monoChannel, 130 + monoChannel));
		g.drawPolyline(new int[] { i, qLength - i, qLength - i }, new int[] { height - i, height - i, i }, 3);
		g.fillArc(width - height + i, i, height - 2 * i, height - 2 * i, 225, 180);
	}
	g.fillRect(5, 5, qLength - 9, height - 9);
	g.fillOval(width - height + 5, 5, height - 10, height - 10);
	return bi.getScaledInstance(bounds.width, bounds.height, Image.SCALE_SMOOTH);
}
 
Example 5
Project: QN-ACTR-Release   File: DefaultIcons.java   View Source Code Vote up 6 votes
public static Image getStationIcon(String type, Rectangle bounds) {
	BufferedImage bi = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics g = bi.getGraphics();
	int qLength = bounds.width * 3 / 5, height = bounds.height, width = bounds.width;
	for (int i = 0, monoChannel = 0; i < 5; i++, monoChannel = (int) ((1 - Math.exp(-i)) * 50)) {
		g.setColor(new Color(230 - monoChannel, 230 - monoChannel, 230 - monoChannel, 255));
		g.drawPolyline(new int[] { i, i, qLength - i }, new int[] { height - i, i, i }, 3);
		g.fillArc(width - height + i, i, height - 2 * i, height - 2 * i, 45, 180);
		g.setColor(new Color(130 + monoChannel, 130 + monoChannel, 130 + monoChannel, 255));
		g.drawPolyline(new int[] { i, qLength - i, qLength - i }, new int[] { height - i, height - i, i }, 3);
		g.fillArc(width - height + i, i, height - 2 * i, height - 2 * i, 225, 180);
	}
	g.fillRect(5, 5, qLength - 9, height - 9);
	g.fillOval(width - height + 5, 5, height - 10, height - 10);
	return bi;
}
 
Example 6
Project: QN-ACTR-Release   File: SampleQNAnimation.java   View Source Code Vote up 6 votes
private void createOverlayImage() {
	int height = getBounds().height * 2, width = getBounds().width * 2, qLength = width - (height * 4) / 5, qHeight = (height * 4) / 5, yOffs = (height - qHeight) / 2;
	overlayedShading = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
	Color[] shades = new Color[7], lights = new Color[7];
	for (int i = 0; i < shades.length; i++) {
		shades[i] = new Color(0, 0, 0, 160 - (i * 160) / shades.length);
		lights[i] = new Color(255, 255, 255, 200 - (i * 200) / lights.length);
	}
	Graphics g = overlayedShading.getGraphics();
	for (int i = 0; i < shades.length; i++) {
		g.setColor(lights[i]);
		g.drawPolyline(new int[] { i, i, qLength - i }, new int[] { height - i - yOffs, i + yOffs, i + yOffs }, 3);
		g.drawArc(width - height + i, i, height - 2 * i, height - 2 * i, 45 + 4 * i, 180 - 8 * i);
		g.setColor(shades[i]);
		g.drawPolyline(new int[] { i, qLength - i, qLength - i }, new int[] { height - i - yOffs, height - i - yOffs, i + yOffs }, 2);
		g.drawArc(width - height + i, i, height - 2 * i, height - 2 * i, 225 + 4 * i, 180 - 8 * i);
	}
	overlayedShading = overlayedShading.getScaledInstance(getBounds().width, getBounds().height, Image.SCALE_SMOOTH);
}
 
Example 7
Project: Logisim   File: Poly.java   View Source Code Vote up 6 votes
@Override
public void paint(Graphics g, HandleGesture gesture) {
	List<Handle> hs = getHandles(gesture);
	int[] xs = new int[hs.size()];
	int[] ys = new int[hs.size()];
	int i = -1;
	for (Handle h : hs) {
		i++;
		xs[i] = h.getX();
		ys[i] = h.getY();
	}

	if (setForFill(g)) {
		g.fillPolygon(xs, ys, xs.length);
	}
	if (setForStroke(g)) {
		if (closed)
			g.drawPolygon(xs, ys, xs.length);
		else
			g.drawPolyline(xs, ys, xs.length);
	}
}
 
Example 8
Project: Logisim   File: PolyTool.java   View Source Code Vote up 6 votes
@Override
public void draw(Canvas canvas, Graphics g) {
	if (active) {
		g.setColor(Color.GRAY);
		int size = locations.size();
		int[] xs = new int[size];
		int[] ys = new int[size];
		for (int i = 0; i < size; i++) {
			Location loc = locations.get(i);
			xs[i] = loc.getX();
			ys[i] = loc.getY();
		}
		g.drawPolyline(xs, ys, size);
		int lastX = xs[xs.length - 1];
		int lastY = ys[ys.length - 1];
		g.fillOval(lastX - 2, lastY - 2, 4, 4);
	}
}
 
Example 9
Project: Logisim   File: Drawgates.java   View Source Code Vote up 5 votes
static void paintNot(Graphics g, int x, int y, int width, int height) {
	int[] xp = new int[4];
	int[] yp = new int[4];
	xp[0] = x - 4;
	yp[0] = y;
	xp[1] = x - width;
	yp[1] = y - height / 2;
	xp[2] = x - width;
	yp[2] = y + height / 2;
	xp[3] = x - 4;
	yp[3] = y;
	g.drawPolyline(xp, yp, 4);
	g.drawOval(x - 4, y - 2, 4, 4);
}
 
Example 10
Project: Logisim   File: ProgrammableGenerator.java   View Source Code Vote up 5 votes
@Override
public void paintInstance(InstancePainter painter) {
	Graphics g = painter.getGraphics();
	Bounds bds = painter.getInstance().getBounds();
	int x = bds.getX();
	int y = bds.getY();
	g.setColor(painter.getAttributeValue(StdAttr.ATTR_LABEL_COLOR));
	painter.drawLabel();
	g.setColor(Color.BLACK);
	boolean drawUp;
	if (painter.getShowState()) {
		ProgrammableGeneratorState state = getState(painter);
		painter.drawBounds(state.sending.getColor());
		drawUp = state.sending == Value.TRUE;
	} else {
		painter.drawBounds(Color.BLACK);
		drawUp = true;
	}
	g.setColor(Color.WHITE);
	x += 10;
	y += 10;
	int[] xs = { x + 1, x + 1, x + 4, x + 4, x + 7, x + 7 };
	int[] ys;
	if (drawUp) {
		ys = new int[] { y + 5, y + 3, y + 3, y + 7, y + 7, y + 5 };
	} else {
		ys = new int[] { y + 5, y + 7, y + 7, y + 3, y + 3, y + 5 };
	}
	g.drawPolyline(xs, ys, xs.length);
	GraphicsUtil.switchToWidth(g, 2);
	xs = new int[] { x - 6, x - 6, x + 1, x + 1, x - 5 };
	ys = new int[] { y + 6, y - 6, y - 6, y, y };
	g.drawPolyline(xs, ys, xs.length);
	painter.drawPorts();
}
 
Example 11
Project: Logisim   File: NotGate.java   View Source Code Vote up 5 votes
@Override
public void paintIcon(InstancePainter painter) {
	Graphics g = painter.getGraphics();
	g.setColor(Color.black);
	if (painter.getGateShape() == AppPreferences.SHAPE_RECTANGULAR) {
		if (toolIconRect != null) {
			toolIconRect.paintIcon(painter.getDestination(), g, 2, 2);
		} else {
			g.drawRect(0, 2, 16, 16);
			GraphicsUtil.drawCenteredText(g, RECT_LABEL, 8, 8);
			g.drawOval(16, 8, 4, 4);
		}
	} else if (painter.getGateShape() == AppPreferences.SHAPE_DIN40700) {
		if (toolIconDin != null) {
			toolIconDin.paintIcon(painter.getDestination(), g, 2, 2);
		} else {
			g.drawRect(0, 2, 16, 16);
			GraphicsUtil.drawCenteredText(g, RECT_LABEL, 8, 8);
			g.drawOval(16, 8, 4, 4);
		}
	} else {
		if (toolIcon != null) {
			toolIcon.paintIcon(painter.getDestination(), g, 2, 2);
		} else {
			int[] xp = new int[4];
			int[] yp = new int[4];
			xp[0] = 15;
			yp[0] = 10;
			xp[1] = 1;
			yp[1] = 3;
			xp[2] = 1;
			yp[2] = 17;
			xp[3] = 15;
			yp[3] = 10;
			g.drawPolyline(xp, yp, 4);
			g.drawOval(15, 8, 4, 4);
		}
	}
}
 
Example 12
Project: Logisim   File: Drawgates.java   View Source Code Vote up 5 votes
static void paintSingleInputgate(Graphics g, int xpin, int y, int xinput, int youtput, boolean up) {
	int[] yPoints, xPoints;
	xPoints = new int[] { xpin, xpin, xinput };
	if (!up)
		yPoints = new int[] { y + AbstractTtlGate.height - AbstractTtlGate.pinheight, youtput, youtput };
	else
		yPoints = new int[] { y + AbstractTtlGate.pinheight, youtput, youtput };
	g.drawPolyline(xPoints, yPoints, 3);
}
 
Example 13
Project: JDigitalSimulator   File: SevenSegmentDisplay.java   View Source Code Vote up 5 votes
@Override public void paint(Graphics graphics) {
	graphics.setColor(Color.BLACK);
	graphics.drawRect(10, 0, size.width-10, size.height);
	for(int input=0;input<inputs.length;input++) {
		Polygon polygon = new Polygon(POLYGONS_X[input], POLYGONS_Y[input], 7);
		polygon.translate(15, 4);
		if(inputs[input].isCharged()) {
			graphics.setColor(Color.RED);
			graphics.fillPolygon(polygon);
		}
		graphics.setColor(Color.BLACK);
		graphics.drawPolyline(polygon.xpoints, polygon.ypoints, polygon.npoints);
	}
	ContactUtilities.paintSolderingJoints(graphics, 10, 0, inputs);
}
 
Example 14
Project: JDigitalSimulator   File: Clock.java   View Source Code Vote up 5 votes
@Override public void paint(Graphics graphics) {
	graphics.setColor(Color.BLACK);
	graphics.drawRect(0, 0, size.width-5, size.height);
	int x=size.width-28, yt=size.height/2-2, yb=size.height/2;
	graphics.drawPolyline(new int[]{x , x+=2, x , x+=3, x , x+=3, x , x+=2, x , x+=2, x , x+=2},
			new int[]{yt, yt  , yb, yb  , yt, yt  , yb, yb  , yt, yt  , yb, yb  }, 12);
	ContactUtilities.paintSolderingJoints(graphics, contacts);
}
 
Example 15
Project: Logisim   File: Drawgates.java   View Source Code Vote up 5 votes
public static void paintAnd(Graphics g, int x, int y, int width, int height, boolean negated) {
	if (negated)
		paintNegatedOutput(g, x, y);
	int[] xp = new int[] { x - width / 2, x - width, x - width, x - width / 2 };
	int[] yp = new int[] { y - width / 2, y - width / 2, y + width / 2, y + width / 2 };
	GraphicsUtil.drawCenteredArc(g, x - width / 2, y, width / 2, -90, 180);

	g.drawPolyline(xp, yp, 4);
	if (height > width) {
		g.drawLine(x - width, y - height / 2, x - width, y + height / 2);
	}
}
 
Example 16
Project: Logisim   File: GraphicsUtil.java   View Source Code Vote up 5 votes
static public void drawArrow(Graphics g, int x0, int y0, int x1, int y1, int headLength, int headAngle) {
	double offs = headAngle * Math.PI / 180.0;
	double angle = Math.atan2(y0 - y1, x0 - x1);
	int[] xs = { x1 + (int) (headLength * Math.cos(angle + offs)), x1,
			x1 + (int) (headLength * Math.cos(angle - offs)) };
	int[] ys = { y1 + (int) (headLength * Math.sin(angle + offs)), y1,
			y1 + (int) (headLength * Math.sin(angle - offs)) };
	g.drawLine(x0, y0, x1, y1);
	g.drawPolyline(xs, ys, 3);
}
 
Example 17
Project: jaer   File: PanTiltAimerGUI.java   View Source Code Vote up 5 votes
private void paintPath(Color LineColor,int NumberPoints) {
    if (isEmpty()) return;
    
    int n = size();
    int[] x = new int[n], y = new int[n];
    //If there are more than X points, only draw the newest X ones so that the screen is not all cluttered.
    for (int i = 0; i < Math.min(n,NumberPoints); i++) { 
        x[i] = get(i+Math.max(0,n-NumberPoints)).x;
        y[i] = get(i+Math.max(0,n-NumberPoints)).y;
    }
    Graphics g = calibrationPanel.getGraphics();
    g.setColor(LineColor);
    g.drawPolyline(x, y, Math.min(n,NumberPoints));
}
 
Example 18
Project: Logisim   File: PlaRomPanel.java   View Source Code Vote up 5 votes
private void drawNot(Graphics g, int x, int y) {
	int[] xp = new int[4];
	int[] yp = new int[4];
	xp[0] = x - 6;
	yp[0] = y;
	xp[1] = x;
	yp[1] = y + 13;
	xp[2] = x + 6;
	yp[2] = y;
	xp[3] = x - 6;
	yp[3] = y;
	g.drawPolyline(xp, yp, 4);
	g.drawOval(x - 3, y + 14, 6, 6);
}
 
Example 19
Project: Logisim   File: PainterShaped.java   View Source Code Vote up 5 votes
static void paintAnd(InstancePainter painter, int width, int height) {
	Graphics g = painter.getGraphics();
	GraphicsUtil.switchToWidth(g, 2);
	int[] xp = new int[] { -width / 2, -width + 1, -width + 1, -width / 2 };
	int[] yp = new int[] { -width / 2, -width / 2, width / 2, width / 2 };
	GraphicsUtil.drawCenteredArc(g, -width / 2, 0, width / 2, -90, 180);

	g.drawPolyline(xp, yp, 4);
	if (height > width) {
		g.drawLine(-width + 1, -height / 2, -width + 1, height / 2);
	}
}
 
Example 20
Project: Logisim   File: PullResistor.java   View Source Code Vote up 4 votes
private void paintBase(InstancePainter painter, Value pullValue, Color inColor, Color outColor) {
	boolean color = painter.shouldDrawColor();
	Direction facing = painter.getAttributeValue(StdAttr.FACING);
	Graphics g = painter.getGraphics();
	Color baseColor = g.getColor();
	GraphicsUtil.switchToWidth(g, 3);
	if (color && inColor != null)
		g.setColor(inColor);
	if (facing == Direction.EAST) {
		GraphicsUtil.drawText(g, pullValue.toDisplayString(), -32, 0, GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
	} else if (facing == Direction.WEST) {
		GraphicsUtil.drawText(g, pullValue.toDisplayString(), 32, 0, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
	} else if (facing == Direction.NORTH) {
		GraphicsUtil.drawText(g, pullValue.toDisplayString(), 0, 32, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
	} else {
		GraphicsUtil.drawText(g, pullValue.toDisplayString(), 0, -32, GraphicsUtil.H_CENTER,
				GraphicsUtil.V_BASELINE);
	}

	double rotate = 0.0;
	if (g instanceof Graphics2D) {
		rotate = Direction.SOUTH.toRadians() - facing.toRadians();
		if (rotate != 0.0)
			((Graphics2D) g).rotate(rotate);
	}
	g.drawLine(0, -30, 0, -26);
	g.drawLine(-6, -30, 6, -30);
	if (color && outColor != null)
		g.setColor(outColor);
	g.drawLine(0, -4, 0, 0);
	g.setColor(baseColor);
	GraphicsUtil.switchToWidth(g, 2);
	if (painter.getGateShape() == AppPreferences.SHAPE_SHAPED) {
		int[] xp = { 0, -5, 5, -5, 5, -5, 0 };
		int[] yp = { -25, -23, -19, -15, -11, -7, -5 };
		g.drawPolyline(xp, yp, xp.length);
	} else {
		g.drawRect(-5, -25, 10, 20);
	}
	if (rotate != 0.0) {
		((Graphics2D) g).rotate(-rotate);
	}
}